Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SAVERESTORE_STRINGTABLE_H
  8. #define SAVERESTORE_STRINGTABLE_H
  9. #if defined( _WIN32 )
  10. #pragma once
  11. #endif
  12. #include "isaverestore.h"
  13. #include "networkstringtabledefs.h"
  14. //-------------------------------------
  15. class CStringTableSaveRestoreOps : public CDefSaveRestoreOps
  16. {
  17. public:
  18. void Init( INetworkStringTable* pNetworkStringTable )
  19. {
  20. m_pStringTable = pNetworkStringTable;
  21. }
  22. // save data type interface
  23. virtual void Save( const SaveRestoreFieldInfo_t &fieldInfo, ISave *pSave )
  24. {
  25. int *pStringIndex = (int *)fieldInfo.pField;
  26. const char *pString = m_pStringTable->GetString( *pStringIndex );
  27. int nLen = Q_strlen( pString ) + 1;
  28. pSave->WriteInt( &nLen );
  29. pSave->WriteString( pString );
  30. }
  31. virtual void Restore( const SaveRestoreFieldInfo_t &fieldInfo, IRestore *pRestore )
  32. {
  33. int *pStringIndex = (int *)fieldInfo.pField;
  34. int nLen = pRestore->ReadInt();
  35. char *pTemp = (char *)stackalloc( nLen );
  36. pRestore->ReadString( pTemp, nLen, nLen );
  37. *pStringIndex = m_pStringTable->AddString( CBaseEntity::IsServer(), pTemp );
  38. }
  39. virtual void MakeEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
  40. {
  41. int *pStringIndex = (int *)fieldInfo.pField;
  42. *pStringIndex = INVALID_STRING_INDEX;
  43. }
  44. virtual bool IsEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
  45. {
  46. int *pStringIndex = (int *)fieldInfo.pField;
  47. return *pStringIndex == INVALID_STRING_INDEX;
  48. }
  49. private:
  50. INetworkStringTable *m_pStringTable;
  51. };
  52. #endif // SAVERESTORE_STRINGTABLE_H