mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2026-10-10 03:43:06 +08:00
Update KeyValues
This commit is contained in:
@@ -93,6 +93,8 @@ class SDKConfig(object):
|
||||
'-Wno-tautological-overlap-compare',
|
||||
'-Wno-tautological-constant-out-of-range-compare',
|
||||
'-Wno-undefined-bool-conversion',
|
||||
'-Wno-nontrivial-memcall',
|
||||
'-Wno-sync-alignment',
|
||||
'-msse',
|
||||
'-fPIC'
|
||||
]
|
||||
|
||||
@@ -109,11 +109,14 @@ public:
|
||||
KeyValues( const char *setName, const char *firstKey, int firstValue );
|
||||
KeyValues( const char *setName, const char *firstKey, const char *firstValue, const char *secondKey, const char *secondValue );
|
||||
KeyValues( const char *setName, const char *firstKey, int firstValue, const char *secondKey, int secondValue );
|
||||
KeyValues( const char *setName, bool bUsesLocalStorage );
|
||||
|
||||
// Section name
|
||||
const char *GetName() const;
|
||||
void SetName( const char *setName);
|
||||
|
||||
bool IsUsingLocalStorage() const { return m_bIsUsingLocalStringTable != 0; }
|
||||
|
||||
// gets the name as a unique int
|
||||
int GetNameSymbol() const { return m_iKeyName; }
|
||||
|
||||
@@ -330,12 +333,14 @@ private:
|
||||
char m_iDataType;
|
||||
char m_bHasEscapeSequences; // true, if while parsing this KeyValue, Escape Sequences are used (default false)
|
||||
char m_bEvaluateConditionals; // true, if while parsing this KeyValue, conditionals blocks are evaluated (default true)
|
||||
char unused[1];
|
||||
char m_bIsUsingLocalStringTable; // true if this node uses a per-instance growable string table
|
||||
|
||||
KeyValues *m_pPeer; // pointer to next key in list
|
||||
KeyValues *m_pSub; // pointer to Start of a new sub key list
|
||||
KeyValues *m_pChain;// Search here if it's not in our list
|
||||
|
||||
CKeyValuesGrowableStringTable *m_pLocalStringTable;
|
||||
|
||||
private:
|
||||
// Statics to implement the optional growable string table
|
||||
// Function pointers that will determine which mode we are in
|
||||
|
||||
+34
-4
@@ -229,7 +229,7 @@ static CLeakTrack track;
|
||||
class CKeyValuesGrowableStringTable
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
// Constructor for global singleton string table
|
||||
CKeyValuesGrowableStringTable() :
|
||||
m_hashLookup( 2048, 0, 0, m_Functor, m_Functor ),
|
||||
#ifdef PLATFORM_64BITS
|
||||
@@ -241,6 +241,14 @@ public:
|
||||
m_vecStrings.AddToTail( '\0' );
|
||||
}
|
||||
|
||||
// Constructor for per-instance string table
|
||||
CKeyValuesGrowableStringTable( int nInitialStringCapacity ) :
|
||||
m_hashLookup( 16, 0, 0, m_Functor, m_Functor ),
|
||||
m_vecStrings( 0, nInitialStringCapacity )
|
||||
{
|
||||
m_vecStrings.AddToTail( '\0' );
|
||||
}
|
||||
|
||||
// Translates a string to an index
|
||||
int GetSymbolForString( const char *name, bool bCreate = true )
|
||||
{
|
||||
@@ -381,6 +389,22 @@ KeyValues::KeyValues( const char *setName )
|
||||
SetName ( setName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor with optional per-instance string table
|
||||
//-----------------------------------------------------------------------------
|
||||
KeyValues::KeyValues( const char *setName, bool bUsesLocalStorage )
|
||||
{
|
||||
TRACK_KV_ADD( this, setName );
|
||||
|
||||
Init();
|
||||
if ( bUsesLocalStorage )
|
||||
{
|
||||
m_pLocalStringTable = new CKeyValuesGrowableStringTable( 256 );
|
||||
m_bIsUsingLocalStringTable = true;
|
||||
}
|
||||
SetName( setName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -461,9 +485,8 @@ void KeyValues::Init()
|
||||
|
||||
m_bHasEscapeSequences = false;
|
||||
m_bEvaluateConditionals = true;
|
||||
|
||||
// for future proof
|
||||
memset( unused, 0, sizeof(unused) );
|
||||
m_bIsUsingLocalStringTable = false;
|
||||
m_pLocalStringTable = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -501,6 +524,8 @@ void KeyValues::RemoveEverything()
|
||||
m_sValue = NULL;
|
||||
delete [] m_wsValue;
|
||||
m_wsValue = NULL;
|
||||
delete m_pLocalStringTable;
|
||||
m_pLocalStringTable = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -528,6 +553,11 @@ void KeyValues::ChainKeyValue( KeyValues* pChain )
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *KeyValues::GetName( void ) const
|
||||
{
|
||||
if ( m_bIsUsingLocalStringTable )
|
||||
{
|
||||
Assert( m_pLocalStringTable );
|
||||
return m_pLocalStringTable->GetStringForSymbol( m_iKeyName );
|
||||
}
|
||||
return s_pfGetStringForSymbol( m_iKeyName );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user