Team Fortress 2 Source Code as on 22/4/2020
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.

88 lines
2.2 KiB

  1. //========= Copyright 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 "tier0/valve_minmax_off.h" // GCC 4.2.2 headers screw up our min/max defs.
  22. #include <string>
  23. #include "tier0/valve_minmax_on.h" // GCC 4.2.2 headers screw up our min/max defs.
  24. #ifdef _WIN32
  25. #pragma warning(pop)
  26. #endif
  27. class CStdStringSaveRestoreOps : public CDefSaveRestoreOps
  28. {
  29. public:
  30. enum
  31. {
  32. MAX_SAVE_LEN = 4096,
  33. };
  34. // save data type interface
  35. virtual void Save( const SaveRestoreFieldInfo_t &fieldInfo, ISave *pSave )
  36. {
  37. std::string *pString = (std::string *)fieldInfo.pField;
  38. Assert( pString->length() < MAX_SAVE_LEN - 1 );
  39. if ( pString->length() < MAX_SAVE_LEN - 1 )
  40. pSave->WriteString( pString->c_str() );
  41. else
  42. pSave->WriteString( "<<invalid>>" );
  43. }
  44. virtual void Restore( const SaveRestoreFieldInfo_t &fieldInfo, IRestore *pRestore )
  45. {
  46. std::string *pString = (std::string *)fieldInfo.pField;
  47. char szString[MAX_SAVE_LEN];
  48. pRestore->ReadString( szString, sizeof(szString), 0 );
  49. szString[MAX_SAVE_LEN - 1] = 0;
  50. pString->assign( szString );
  51. }
  52. virtual void MakeEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
  53. {
  54. std::string *pString = (std::string *)fieldInfo.pField;
  55. pString->erase();
  56. }
  57. virtual bool IsEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
  58. {
  59. std::string *pString = (std::string *)fieldInfo.pField;
  60. return pString->empty();
  61. }
  62. };
  63. //-------------------------------------
  64. inline ISaveRestoreOps *GetStdStringDataOps()
  65. {
  66. static CStdStringSaveRestoreOps ops;
  67. return &ops;
  68. }
  69. //-------------------------------------
  70. #define DEFINE_STDSTRING(name) \
  71. { FIELD_CUSTOM, #name, { offsetof(classNameTypedef,name), 0 }, 1, FTYPEDESC_SAVE, NULL, GetStdStringDataOps(), NULL }
  72. #endif // STDSTRING_H