gameconfs can now inherit properly with a new trie replace function
authorDavid Anderson <dvander@alliedmods.net>
Sun Jul 08 03:17:29 2007 +0000 (2007-07-08)
changeset 1057de136462a416
parent 1056 78c16f695f24
child 1058 3248bc6dbf60
gameconfs can now inherit properly with a new trie replace function
core/ADTFactory.cpp
core/ADTFactory.h
core/GameConfigs.cpp
core/sm_trie.cpp
core/sm_trie.h
public/IADTFactory.h
     1.1 --- a/core/ADTFactory.cpp	Sun Jul 08 02:59:08 2007 +0000
     1.2 +++ b/core/ADTFactory.cpp	Sun Jul 08 03:17:29 2007 +0000
     1.3 @@ -58,3 +58,8 @@
     1.4  {
     1.5  	delete this;
     1.6  }
     1.7 +
     1.8 +bool BaseTrie::Replace(const char *key, void *value)
     1.9 +{
    1.10 +	return sm_trie_replace(m_pTrie, key, value);
    1.11 +}
     2.1 --- a/core/ADTFactory.h	Sun Jul 08 02:59:08 2007 +0000
     2.2 +++ b/core/ADTFactory.h	Sun Jul 08 03:17:29 2007 +0000
     2.3 @@ -10,6 +10,7 @@
     2.4  	BaseTrie();
     2.5  	virtual ~BaseTrie();
     2.6  	virtual bool Insert(const char *key, void *value);
     2.7 +	virtual bool Replace(const char *key, void *value);
     2.8  	virtual bool Retrieve(const char *key, void **value);
     2.9  	virtual bool Delete(const char *key);
    2.10  	virtual void Clear();
     3.1 --- a/core/GameConfigs.cpp	Sun Jul 08 02:59:08 2007 +0000
     3.2 +++ b/core/GameConfigs.cpp	Sun Jul 08 03:17:29 2007 +0000
     3.3 @@ -190,11 +190,11 @@
     3.4  			strncopy(m_prop, value, sizeof(m_prop));
     3.5  		} else if (strcmp(key, PLATFORM_NAME) == 0) {
     3.6  			int val = atoi(value);
     3.7 -			sm_trie_insert(m_pOffsets, m_offset, (void *)val);
     3.8 +			sm_trie_replace(m_pOffsets, m_offset, (void *)val);
     3.9  		}
    3.10  	} else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
    3.11  		int id = m_pStrings->AddString(value);
    3.12 -		sm_trie_insert(m_pKeys, key, (void *)id);
    3.13 +		sm_trie_replace(m_pKeys, key, (void *)id);
    3.14  	} else if (m_ParseState == PSTATE_GAMEDEFS_SUPPORTED) {
    3.15  		if (strcmp(key, "game") == 0
    3.16  			&& strcmp(value, g_mod) == 0)
    3.17 @@ -249,8 +249,8 @@
    3.18  				if (pProp)
    3.19  				{
    3.20  					int val = pProp->GetOffset();
    3.21 -					sm_trie_insert(m_pOffsets, m_offset, (void *)val);
    3.22 -					sm_trie_insert(m_pProps, m_offset, pProp);
    3.23 +					sm_trie_replace(m_pOffsets, m_offset, (void *)val);
    3.24 +					sm_trie_replace(m_pProps, m_offset, pProp);
    3.25  				} else {
    3.26  					/* Check if it's a non-default game and no offsets exist */
    3.27  					if (((strcmp(m_mod, "*") != 0) && strcmp(m_mod, "#default") != 0)
    3.28 @@ -383,7 +383,7 @@
    3.29  #if defined PLATFORM_LINUX
    3.30  skip_find:
    3.31  #endif
    3.32 -			sm_trie_insert(m_pSigs, m_offset, final_addr);
    3.33 +			sm_trie_replace(m_pSigs, m_offset, final_addr);
    3.34  			m_ParseState = PSTATE_GAMEDEFS_SIGNATURES;
    3.35  
    3.36  			break;
     4.1 --- a/core/sm_trie.cpp	Sun Jul 08 02:59:08 2007 +0000
     4.2 +++ b/core/sm_trie.cpp	Sun Jul 08 03:17:29 2007 +0000
     4.3 @@ -388,7 +388,7 @@
     4.4  	return true;
     4.5  }
     4.6  
     4.7 -bool sm_trie_insert(Trie *trie, const char *key, void *value)
     4.8 +bool sm_trie_add(Trie *trie, const char *key, void *value, bool replace_allowed)
     4.9  {
    4.10  	unsigned int lastidx = 1;		/* the last node index */
    4.11  	unsigned int curidx;			/* current node index */
    4.12 @@ -803,7 +803,7 @@
    4.13  	 */
    4.14  	assert(node->mode == Node_Arc);
    4.15  
    4.16 -	if (!node->valset)
    4.17 +	if (!node->valset || replace_allowed)
    4.18  	{
    4.19  		/* Insert is only possible if we have no production */
    4.20  		node->valset = true;
    4.21 @@ -813,3 +813,13 @@
    4.22  
    4.23  	return false;
    4.24  }
    4.25 +
    4.26 +bool sm_trie_insert(Trie *trie, const char *key, void *value)
    4.27 +{
    4.28 +	return sm_trie_add(trie, key, value, false);
    4.29 +}
    4.30 +
    4.31 +bool sm_trie_replace(Trie *trie, const char *key, void *value)
    4.32 +{
    4.33 +	return sm_trie_add(trie, key, value, true);
    4.34 +}
     5.1 --- a/core/sm_trie.h	Sun Jul 08 02:59:08 2007 +0000
     5.2 +++ b/core/sm_trie.h	Sun Jul 08 03:17:29 2007 +0000
     5.3 @@ -20,6 +20,7 @@
     5.4  Trie *sm_trie_create();
     5.5  void sm_trie_destroy(Trie *trie);
     5.6  bool sm_trie_insert(Trie *trie, const char *key, void *value);
     5.7 +bool sm_trie_replace(Trie *trie, const char *key, void *value);
     5.8  bool sm_trie_retrieve(Trie *trie, const char *key, void **value);
     5.9  bool sm_trie_delete(Trie *trie, const char *key);
    5.10  void sm_trie_clear(Trie *trie);
     6.1 --- a/public/IADTFactory.h	Sun Jul 08 02:59:08 2007 +0000
     6.2 +++ b/public/IADTFactory.h	Sun Jul 08 03:17:29 2007 +0000
     6.3 @@ -4,7 +4,7 @@
     6.4  #include <IShareSys.h>
     6.5  
     6.6  #define SMINTERFACE_ADTFACTORY_NAME		"IADTFactory"
     6.7 -#define SMINTERFACE_ADTFACTORY_VERSION	1
     6.8 +#define SMINTERFACE_ADTFACTORY_VERSION	2
     6.9  
    6.10  /**
    6.11  * @file IADTFactory.h
    6.12 @@ -55,6 +55,16 @@
    6.13  		 * memory.
    6.14  		 */
    6.15  		virtual void Destroy() =0;
    6.16 +
    6.17 +		/**
    6.18 +		 * @brief Inserts a key/value pair, replacing an old inserted
    6.19 +		 * value if it already exists.
    6.20 +		 *
    6.21 +		 * @param key		Key string (null terminated).
    6.22 +		 * @param value		Value pointer (may be anything).
    6.23 +		 * @return			True on success, false on failure.
    6.24 +		 */
    6.25 +		virtual bool Replace(const char *key, void *value) =0;
    6.26  	};
    6.27  
    6.28  	class IADTFactory : public SMInterface