mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2024-12-23 01:59:43 +08:00
update keyvalues (#103)
This commit is contained in:
parent
e78c6fda9f
commit
325244bdeb
@ -1,4 +1,4 @@
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
@ -20,6 +20,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <vstdlib/IKeyValuesSystem.h>
|
||||
|
||||
#include "utlvector.h"
|
||||
#include "Color.h"
|
||||
#include "exprevaluator.h"
|
||||
@ -29,7 +31,6 @@ class CUtlBuffer;
|
||||
class Color;
|
||||
class KeyValues;
|
||||
class IKeyValuesDumpContext;
|
||||
class IKeyValuesSystem;
|
||||
typedef void * FileHandle_t;
|
||||
|
||||
// single byte identifies a xbox kv file in binary format
|
||||
@ -71,7 +72,7 @@ typedef void * FileHandle_t;
|
||||
class KeyValues
|
||||
{
|
||||
public:
|
||||
KeyValues( const char *setName );
|
||||
KeyValues( const char *setName, IKeyValuesSystem *customSystem = NULL, bool ownsCustomSystem = false );
|
||||
|
||||
//
|
||||
// AutoDelete class to automatically free the keyvalues.
|
||||
@ -312,7 +313,7 @@ private:
|
||||
// If filesystem is null, it'll ignore f.
|
||||
void InternalWrite( IBaseFileSystem *filesystem, FileHandle_t f, CUtlBuffer *pBuf, const void *pData, int len );
|
||||
|
||||
void Init();
|
||||
void Init(IKeyValuesSystem *customSystem = NULL, bool ownsCustomSystem = false);
|
||||
const char * ReadToken( CUtlBuffer &buf, bool &wasQuoted, bool &wasConditional );
|
||||
void WriteIndents( IBaseFileSystem *filesystem, FileHandle_t f, CUtlBuffer *pBuf, int indentLevel );
|
||||
|
||||
@ -323,6 +324,14 @@ private:
|
||||
|
||||
bool EvaluateConditional( const char *pExpressionString, GetSymbolProc_t pfnEvaluateSymbolProc );
|
||||
|
||||
inline IKeyValuesSystem *GetKeyValuesSystem() const {
|
||||
if (m_pKeyValuesSystem) {
|
||||
return m_pKeyValuesSystem;
|
||||
}
|
||||
|
||||
return KeyValuesSystem();
|
||||
}
|
||||
|
||||
uint32 m_iKeyName : 24; // keyname is a symbol defined in KeyValuesSystem
|
||||
uint32 m_iKeyNameCaseSensitive1 : 8; // 1st part of case sensitive symbol defined in KeyValueSystem
|
||||
|
||||
@ -344,8 +353,7 @@ private:
|
||||
uint16 m_iKeyNameCaseSensitive2; // 2nd part of case sensitive symbol defined in KeyValueSystem;
|
||||
|
||||
IKeyValuesSystem *m_pKeyValuesSystem;
|
||||
char m_bOwnsCustomKeyValuesSystem;
|
||||
char unused[3];
|
||||
bool m_bOwnsCustomKeyValuesSystem;
|
||||
|
||||
KeyValues *m_pPeer; // pointer to next key in list
|
||||
KeyValues *m_pSub; // pointer to Start of a new sub key list
|
||||
|
@ -1,4 +1,4 @@
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
@ -211,11 +211,11 @@ static CLeakTrack track;
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
KeyValues::KeyValues( const char *setName )
|
||||
KeyValues::KeyValues( const char *setName, IKeyValuesSystem *customSystem, bool ownsCustomSystem )
|
||||
{
|
||||
TRACK_KV_ADD( this, setName );
|
||||
|
||||
Init();
|
||||
Init( customSystem, ownsCustomSystem );
|
||||
SetName ( setName );
|
||||
}
|
||||
|
||||
@ -284,7 +284,7 @@ KeyValues::KeyValues( const char *setName, const char *firstKey, int firstValue,
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Initialize member variables
|
||||
//-----------------------------------------------------------------------------
|
||||
void KeyValues::Init()
|
||||
void KeyValues::Init(IKeyValuesSystem *customSystem, bool ownsCustomSystem)
|
||||
{
|
||||
m_iKeyName = 0;
|
||||
m_iKeyNameCaseSensitive1 = 0;
|
||||
@ -301,11 +301,8 @@ void KeyValues::Init()
|
||||
|
||||
m_bHasEscapeSequences = false;
|
||||
|
||||
m_pKeyValuesSystem = 0;
|
||||
m_bOwnsCustomKeyValuesSystem = 0;
|
||||
|
||||
// for future proof
|
||||
memset( unused, 0, sizeof(unused) );
|
||||
m_pKeyValuesSystem = customSystem;
|
||||
m_bOwnsCustomKeyValuesSystem = ownsCustomSystem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -316,6 +313,11 @@ KeyValues::~KeyValues()
|
||||
TRACK_KV_REMOVE( this );
|
||||
|
||||
RemoveEverything();
|
||||
|
||||
if (m_pKeyValuesSystem && m_bOwnsCustomKeyValuesSystem) {
|
||||
delete m_pKeyValuesSystem;
|
||||
m_pKeyValuesSystem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -370,7 +372,7 @@ void KeyValues::ChainKeyValue( KeyValues* pChain )
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *KeyValues::GetName( void ) const
|
||||
{
|
||||
return KeyValuesSystem()->GetStringForSymbol(m_iKeyName);
|
||||
return GetKeyValuesSystem()->GetStringForSymbol(m_iKeyName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -768,7 +770,7 @@ KeyValues *KeyValues::FindKey(const char *keyName, bool bCreate)
|
||||
}
|
||||
|
||||
// lookup the symbol for the search string
|
||||
HKeySymbol iSearchStr = KeyValuesSystem()->GetSymbolForString( searchStr, bCreate );
|
||||
HKeySymbol iSearchStr = GetKeyValuesSystem()->GetSymbolForString( searchStr, bCreate );
|
||||
if ( iSearchStr == INVALID_KEY_SYMBOL )
|
||||
{
|
||||
// not found, couldn't possibly be in key value list
|
||||
@ -800,7 +802,7 @@ KeyValues *KeyValues::FindKey(const char *keyName, bool bCreate)
|
||||
if (bCreate)
|
||||
{
|
||||
// we need to create a new key
|
||||
dat = new KeyValues( searchStr );
|
||||
dat = new KeyValues( searchStr, m_pKeyValuesSystem );
|
||||
// Assert(dat != NULL);
|
||||
|
||||
// insert new key at end of list
|
||||
@ -867,7 +869,7 @@ KeyValues *KeyValues::CreateNewKey()
|
||||
KeyValues* KeyValues::CreateKey( const char *keyName )
|
||||
{
|
||||
// key wasn't found so just create a new one
|
||||
KeyValues* dat = new KeyValues( keyName );
|
||||
KeyValues* dat = new KeyValues( keyName, m_pKeyValuesSystem );
|
||||
|
||||
dat->UsesEscapeSequences( m_bHasEscapeSequences != 0 ); // use same format as parent does
|
||||
|
||||
@ -1425,7 +1427,7 @@ void KeyValues::SetFloat( const char *keyName, float value )
|
||||
|
||||
void KeyValues::SetName( const char * setName )
|
||||
{
|
||||
m_iKeyName = KeyValuesSystem()->GetSymbolForString( setName );
|
||||
m_iKeyName = GetKeyValuesSystem()->GetSymbolForString( setName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1534,14 +1536,14 @@ void KeyValues::RecursiveCopyKeyValues( KeyValues& src )
|
||||
// Handle the immediate child
|
||||
if( src.m_pSub )
|
||||
{
|
||||
m_pSub = new KeyValues( NULL );
|
||||
m_pSub = new KeyValues( NULL, m_pKeyValuesSystem );
|
||||
m_pSub->RecursiveCopyKeyValues( *src.m_pSub );
|
||||
}
|
||||
|
||||
// Handle the immediate peer
|
||||
if( src.m_pPeer )
|
||||
{
|
||||
m_pPeer = new KeyValues( NULL );
|
||||
m_pPeer = new KeyValues( NULL, m_pKeyValuesSystem );
|
||||
m_pPeer->RecursiveCopyKeyValues( *src.m_pPeer );
|
||||
}
|
||||
}
|
||||
@ -1758,7 +1760,7 @@ void KeyValues::ParseIncludedKeys( char const *resourceName, const char *filetoi
|
||||
// Append included file
|
||||
Q_strncat( fullpath, filetoinclude, sizeof( fullpath ), COPY_ALL_CHARACTERS );
|
||||
|
||||
KeyValues *newKV = new KeyValues( fullpath );
|
||||
KeyValues *newKV = new KeyValues( fullpath, m_pKeyValuesSystem );
|
||||
|
||||
// CUtlSymbol save = s_CurrentFileSymbol; // did that had any use ???
|
||||
|
||||
@ -1909,7 +1911,7 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase
|
||||
|
||||
if ( !pCurrentKey )
|
||||
{
|
||||
pCurrentKey = new KeyValues( s );
|
||||
pCurrentKey = new KeyValues( s, m_pKeyValuesSystem );
|
||||
Assert( pCurrentKey );
|
||||
|
||||
pCurrentKey->UsesEscapeSequences( m_bHasEscapeSequences != 0 ); // same format has parent use
|
||||
@ -2281,7 +2283,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer )
|
||||
{
|
||||
case TYPE_NONE:
|
||||
{
|
||||
dat->m_pSub = new KeyValues("");
|
||||
dat->m_pSub = new KeyValues("", m_pKeyValuesSystem);
|
||||
dat->m_pSub->ReadAsBinary( buffer );
|
||||
break;
|
||||
}
|
||||
@ -2345,7 +2347,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer )
|
||||
break;
|
||||
|
||||
// new peer follows
|
||||
dat->m_pPeer = new KeyValues("");
|
||||
dat->m_pPeer = new KeyValues("", m_pKeyValuesSystem);
|
||||
dat = dat->m_pPeer;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user