diff --git a/core/ADTFactory.cpp b/core/ADTFactory.cpp new file mode 100644 index 00000000..4a41ddae --- /dev/null +++ b/core/ADTFactory.cpp @@ -0,0 +1,60 @@ +#include "ADTFactory.h" +#include "sm_globals.h" +#include "ShareSys.h" + +ADTFactory g_AdtFactory; + +const char *ADTFactory::GetInterfaceName() +{ + return SMINTERFACE_ADTFACTORY_NAME; +} + +unsigned int ADTFactory::GetInterfaceVersion() +{ + return SMINTERFACE_ADTFACTORY_VERSION; +} + +void ADTFactory::OnSourceModAllInitialized() +{ + g_ShareSys.AddInterface(NULL, this); +} + +IBasicTrie *ADTFactory::CreateBasicTrie() +{ + return new BaseTrie(); +} + +BaseTrie::BaseTrie() +{ + m_pTrie = sm_trie_create(); +} + +BaseTrie::~BaseTrie() +{ + sm_trie_destroy(m_pTrie); +} + +bool BaseTrie::Insert(const char *key, void *value) +{ + return sm_trie_insert(m_pTrie, key, value); +} + +bool BaseTrie::Retrieve(const char *key, void **value) +{ + return sm_trie_retrieve(m_pTrie, key, value); +} + +bool BaseTrie::Delete(const char *key) +{ + return sm_trie_delete(m_pTrie, key); +} + +void BaseTrie::Clear() +{ + sm_trie_clear(m_pTrie); +} + +void BaseTrie::Destroy() +{ + delete this; +} diff --git a/core/ADTFactory.h b/core/ADTFactory.h new file mode 100644 index 00000000..08d8b83a --- /dev/null +++ b/core/ADTFactory.h @@ -0,0 +1,33 @@ +#include +#include "sm_globals.h" +#include "sm_trie.h" + +using namespace SourceMod; + +class BaseTrie : public IBasicTrie +{ +public: + BaseTrie(); + virtual ~BaseTrie(); + virtual bool Insert(const char *key, void *value); + virtual bool Retrieve(const char *key, void **value); + virtual bool Delete(const char *key); + virtual void Clear(); + virtual void Destroy(); +private: + Trie *m_pTrie; +}; + +class ADTFactory : + public SMGlobalClass, + public IADTFactory +{ +public: //SMInterface + const char *GetInterfaceName(); + unsigned int GetInterfaceVersion(); +public: //SMGlobalClass + void OnSourceModAllInitialized(); +public: //IADTFactory + IBasicTrie *CreateBasicTrie(); +}; + diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index 0896b941..ac982567 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -185,6 +185,10 @@ RelativePath="..\AdminCache.cpp" > + + @@ -307,6 +311,10 @@ RelativePath="..\AdminCache.h" > + + @@ -452,6 +460,10 @@ RelativePath="..\..\public\IAdminSystem.h" > + + diff --git a/extensions/sdktools/sdk/smsdk_config.h b/extensions/sdktools/sdk/smsdk_config.h index 83c1d6ec..402d3022 100644 --- a/extensions/sdktools/sdk/smsdk_config.h +++ b/extensions/sdktools/sdk/smsdk_config.h @@ -54,5 +54,8 @@ //#define SMEXT_ENABLE_DBMANAGER #define SMEXT_ENABLE_GAMECONF #define SMEXT_ENABLE_MEMUTILS +//#define SMEXT_ENABLE_GAMEHELPERS +//#define SMEXT_ENABLE_TIMERSYS +//#define SMEXT_ENABLE_ADTFACTORY #endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ diff --git a/extensions/sdktools/sdk/smsdk_ext.cpp b/extensions/sdktools/sdk/smsdk_ext.cpp index 2de94f19..8c86441f 100644 --- a/extensions/sdktools/sdk/smsdk_ext.cpp +++ b/extensions/sdktools/sdk/smsdk_ext.cpp @@ -51,6 +51,15 @@ IGameConfigManager *gameconfs = NULL; /**< Game config manager */ #if defined SMEXT_ENABLE_MEMUTILS IMemoryUtils *memutils = NULL; #endif +#if defined SMEXT_ENABLE_GAMEHELPERS +IGameHelpers *gamehelpers = NULL; +#endif +#if defined SMEXT_ENABLE_TIMERSYS +ITimerSystem *timersys = NULL; +#endif +#if defined SMEXT_ENABLE_ADTFACTORY +IADTFactory *adtfactory = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -106,6 +115,15 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_MEMUTILS SM_GET_IFACE(MEMORYUTILS, memutils); #endif +#if defined SMEXT_ENABLE_GAMEHELPERS + SM_GET_IFACE(GAMEHELPERS, gamehelpers); +#endif +#if defined SMEXT_ENABLE_TIMERSYS + SM_GET_IFACE(TIMERSYS, timersys); +#endif +#if defined SMEXT_ENABLE_ADTFACTORY + SM_GET_IFACE(ADTFACTORY, adtfactory); +#endif if (SDK_OnLoad(error, maxlength, late)) { diff --git a/extensions/sdktools/sdk/smsdk_ext.h b/extensions/sdktools/sdk/smsdk_ext.h index a4a3de3f..7d647fd2 100644 --- a/extensions/sdktools/sdk/smsdk_ext.h +++ b/extensions/sdktools/sdk/smsdk_ext.h @@ -45,6 +45,15 @@ #if defined SMEXT_ENABLE_MEMUTILS #include #endif +#if defined SMEXT_ENABLE_GAMEHELPERS +#include +#endif +#if defined SMEXT_ENABLE_TIMERSYS +#include +#endif +#if defined SMEXT_ENABLE_ADTFACTORY +#include +#endif #if defined SMEXT_CONF_METAMOD #include @@ -213,6 +222,15 @@ extern IGameConfigManager *gameconfs; #if defined SMEXT_ENABLE_MEMUTILS extern IMemoryUtils *memutils; #endif +#if defined SMEXT_ENABLE_GAMEHELPERS +extern IGameHelpers *gamehelpers; +#endif +#if defined SMEXT_ENABLE_TIMERSYS +extern ITimerSystem *timersys; +#endif +#if defined SMEXT_ENABLE_ADTFACTORY +extern IADTFactory *adtfactory; +#endif #if defined SMEXT_CONF_METAMOD PLUGIN_GLOBALVARS(); diff --git a/public/IADTFactory.h b/public/IADTFactory.h new file mode 100644 index 00000000..ce03c223 --- /dev/null +++ b/public/IADTFactory.h @@ -0,0 +1,73 @@ +#ifndef _INCLUDE_SOURCEMOD_ADT_FACTORY_H_ +#define _INCLUDE_SOURCEMOD_ADT_FACTORY_H_ + +#include + +#define SMINTERFACE_ADTFACTORY_NAME "IADTFactory" +#define SMINTERFACE_ADTFACTORY_VERSION 1 + +/** +* @file IADTFactory.h +* @brief Creates abstract data types. +*/ + +namespace SourceMod +{ + /** + * @brief A "Trie" data type. + */ + class IBasicTrie + { + public: + /** + * @brief Inserts a key/value pair. + * + * @param key Key string (null terminated). + * @param value Value pointer (may be anything). + * @return True on success, false if key already exists. + */ + virtual bool Insert(const char *key, void *value) =0; + + /** + * @brief Retrieves the value of a key. + * + * @param key Key string (null terminated). + * @param value Optional pointer to store value pointer. + * @return True on success, false if key was not found. + */ + virtual bool Retrieve(const char *key, void **value) =0; + + /** + * @brief Deletes a key. + * + * @param key Key string (null terminated). + * @return True on success, false if key was not found. + */ + virtual bool Delete(const char *key) =0; + + /** + * @brief Flushes the entire trie of all keys. + */ + virtual void Clear() =0; + + /** + * @brief Destroys the IBasicTrie object and frees all associated + * memory. + */ + virtual void Destroy() =0; + }; + + class IADTFactory : public SMInterface + { + public: + /** + * @brief Creates a basic Trie object. + * + * @return A new IBasicTrie object which must be destroyed + * via IBasicTrie::Destroy(). + */ + virtual IBasicTrie *CreateBasicTrie() =0; + }; +} + +#endif //_INCLUDE_SOURCEMOD_ADT_FACTORY_H_ diff --git a/public/sample_ext/sdk/smsdk_ext.cpp b/public/sample_ext/sdk/smsdk_ext.cpp index b6dd7283..83046dcc 100644 --- a/public/sample_ext/sdk/smsdk_ext.cpp +++ b/public/sample_ext/sdk/smsdk_ext.cpp @@ -57,6 +57,9 @@ IGameHelpers *gamehelpers = NULL; #if defined SMEXT_ENABLE_TIMERSYS ITimerSystem *timersys = NULL; #endif +#if defined SMEXT_ENABLE_ADTFACTORY +IADTFactory *adtfactory = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -118,6 +121,9 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_TIMERSYS SM_GET_IFACE(TIMERSYS, timersys); #endif +#if defined SMEXT_ENABLE_ADTFACTORY + SM_GET_IFACE(ADTFACTORY, adtfactory); +#endif if (SDK_OnLoad(error, maxlength, late)) { diff --git a/public/sample_ext/sdk/smsdk_ext.h b/public/sample_ext/sdk/smsdk_ext.h index 250fffc7..ebb60277 100644 --- a/public/sample_ext/sdk/smsdk_ext.h +++ b/public/sample_ext/sdk/smsdk_ext.h @@ -51,6 +51,9 @@ #if defined SMEXT_ENABLE_TIMERSYS #include #endif +#if defined SMEXT_ENABLE_ADTFACTORY +#include +#endif #if defined SMEXT_CONF_METAMOD #include @@ -225,6 +228,9 @@ extern IGameHelpers *gamehelpers; #if defined SMEXT_ENABLE_TIMERSYS extern ITimerSystem *timersys; #endif +#if defined SMEXT_ENABLE_ADTFACTORY +extern IADTFactory *adtfactory; +#endif #if defined SMEXT_CONF_METAMOD PLUGIN_GLOBALVARS();