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.

86 lines
2.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "isaverestore.h"
  7. #ifndef STDSTRING_H
  8. #define STDSTRING_H
  9. #if defined( _WIN32 )
  10. #pragma once
  11. #endif
  12. #ifdef _WIN32
  13. #pragma warning(push)
  14. #include <yvals.h> // warnings get enabled in yvals.h
  15. #pragma warning(disable:4663)
  16. #pragma warning(disable:4530)
  17. #pragma warning(disable:4245)
  18. #pragma warning(disable:4018)
  19. #pragma warning(disable:4511)
  20. #endif
  21. #include <string>
  22. #ifdef _WIN32
  23. #pragma warning(pop)
  24. #endif
  25. class CStdStringSaveRestoreOps : public CDefSaveRestoreOps
  26. {
  27. public:
  28. enum
  29. {
  30. MAX_SAVE_LEN = 4096,
  31. };
  32. // save data type interface
  33. virtual void Save( const SaveRestoreFieldInfo_t &fieldInfo, ISave *pSave )
  34. {
  35. std::string *pString = (std::string *)fieldInfo.pField;
  36. Assert( pString->length() < MAX_SAVE_LEN - 1 );
  37. if ( pString->length() < MAX_SAVE_LEN - 1 )
  38. pSave->WriteString( pString->c_str() );
  39. else
  40. pSave->WriteString( "<<invalid>>" );
  41. }
  42. virtual void Restore( const SaveRestoreFieldInfo_t &fieldInfo, IRestore *pRestore )
  43. {
  44. std::string *pString = (std::string *)fieldInfo.pField;
  45. char szString[MAX_SAVE_LEN];
  46. pRestore->ReadString( szString, sizeof(szString), 0 );
  47. szString[MAX_SAVE_LEN - 1] = 0;
  48. pString->assign( szString );
  49. }
  50. virtual void MakeEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
  51. {
  52. std::string *pString = (std::string *)fieldInfo.pField;
  53. pString->erase();
  54. }
  55. virtual bool IsEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
  56. {
  57. std::string *pString = (std::string *)fieldInfo.pField;
  58. return pString->empty();
  59. }
  60. };
  61. //-------------------------------------
  62. inline ISaveRestoreOps *GetStdStringDataOps()
  63. {
  64. static CStdStringSaveRestoreOps ops;
  65. return &ops;
  66. }
  67. //-------------------------------------
  68. #define DEFINE_STDSTRING(name) \
  69. { FIELD_CUSTOM, #name, offsetof(classNameTypedef,name), 1, FTYPEDESC_SAVE, NULL, GetStdStringDataOps(), NULL }
  70. #endif // STDSTRING_H