diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/shared/saverestore_stringtable.h | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/shared/saverestore_stringtable.h')
| -rw-r--r-- | mp/src/game/shared/saverestore_stringtable.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/mp/src/game/shared/saverestore_stringtable.h b/mp/src/game/shared/saverestore_stringtable.h new file mode 100644 index 00000000..ca17d52b --- /dev/null +++ b/mp/src/game/shared/saverestore_stringtable.h @@ -0,0 +1,65 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef SAVERESTORE_STRINGTABLE_H
+#define SAVERESTORE_STRINGTABLE_H
+
+#if defined( _WIN32 )
+#pragma once
+#endif
+
+
+#include "isaverestore.h"
+#include "networkstringtabledefs.h"
+
+
+//-------------------------------------
+
+class CStringTableSaveRestoreOps : public CDefSaveRestoreOps
+{
+public:
+ void Init( INetworkStringTable* pNetworkStringTable )
+ {
+ m_pStringTable = pNetworkStringTable;
+ }
+
+ // save data type interface
+ virtual void Save( const SaveRestoreFieldInfo_t &fieldInfo, ISave *pSave )
+ {
+ int *pStringIndex = (int *)fieldInfo.pField;
+ const char *pString = m_pStringTable->GetString( *pStringIndex );
+ int nLen = Q_strlen( pString ) + 1;
+ pSave->WriteInt( &nLen );
+ pSave->WriteString( pString );
+ }
+
+ virtual void Restore( const SaveRestoreFieldInfo_t &fieldInfo, IRestore *pRestore )
+ {
+ int *pStringIndex = (int *)fieldInfo.pField;
+ int nLen = pRestore->ReadInt();
+ char *pTemp = (char *)stackalloc( nLen );
+ pRestore->ReadString( pTemp, nLen, nLen );
+ *pStringIndex = m_pStringTable->AddString( CBaseEntity::IsServer(), pTemp );
+ }
+
+ virtual void MakeEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
+ {
+ int *pStringIndex = (int *)fieldInfo.pField;
+ *pStringIndex = INVALID_STRING_INDEX;
+ }
+
+ virtual bool IsEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
+ {
+ int *pStringIndex = (int *)fieldInfo.pField;
+ return *pStringIndex == INVALID_STRING_INDEX;
+ }
+
+private:
+ INetworkStringTable *m_pStringTable;
+};
+
+#endif // SAVERESTORE_STRINGTABLE_H
|