forked from shokunin000/te120
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdstring.h
88 lines (72 loc) · 2.15 KB
/
stdstring.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "isaverestore.h"
#ifndef STDSTRING_H
#define STDSTRING_H
#if defined( _WIN32 )
#pragma once
#endif
#ifdef _WIN32
#pragma warning(push)
#include <yvals.h> // warnings get enabled in yvals.h
#pragma warning(disable:4663)
#pragma warning(disable:4530)
#pragma warning(disable:4245)
#pragma warning(disable:4018)
#pragma warning(disable:4511)
#endif
#include "tier0/valve_minmax_off.h" // GCC 4.2.2 headers screw up our min/max defs.
#include <string>
#include "tier0/valve_minmax_on.h" // GCC 4.2.2 headers screw up our min/max defs.
#ifdef _WIN32
#pragma warning(pop)
#endif
class CStdStringSaveRestoreOps : public CDefSaveRestoreOps
{
public:
enum
{
MAX_SAVE_LEN = 4096,
};
// save data type interface
virtual void Save( const SaveRestoreFieldInfo_t &fieldInfo, ISave *pSave )
{
std::string *pString = (std::string *)fieldInfo.pField;
Assert( pString->length() < MAX_SAVE_LEN - 1 );
if ( pString->length() < MAX_SAVE_LEN - 1 )
pSave->WriteString( pString->c_str() );
else
pSave->WriteString( "<<invalid>>" );
}
virtual void Restore( const SaveRestoreFieldInfo_t &fieldInfo, IRestore *pRestore )
{
std::string *pString = (std::string *)fieldInfo.pField;
char szString[MAX_SAVE_LEN];
pRestore->ReadString( szString, sizeof(szString), 0 );
szString[MAX_SAVE_LEN - 1] = 0;
pString->assign( szString );
}
virtual void MakeEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
{
std::string *pString = (std::string *)fieldInfo.pField;
pString->erase();
}
virtual bool IsEmpty( const SaveRestoreFieldInfo_t &fieldInfo )
{
std::string *pString = (std::string *)fieldInfo.pField;
return pString->empty();
}
};
//-------------------------------------
inline ISaveRestoreOps *GetStdStringDataOps()
{
static CStdStringSaveRestoreOps ops;
return &ops;
}
//-------------------------------------
#define DEFINE_STDSTRING(name) \
{ FIELD_CUSTOM, #name, { offsetof(classNameTypedef,name), 0 }, 1, FTYPEDESC_SAVE, NULL, GetStdStringDataOps(), NULL }
#endif // STDSTRING_H