- added IADTFactory for sdktools
- updated sample extension and sdktools sdks --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401034
This commit is contained in:
parent
761890b470
commit
b649d60cb0
60
core/ADTFactory.cpp
Normal file
60
core/ADTFactory.cpp
Normal file
@ -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;
|
||||
}
|
33
core/ADTFactory.h
Normal file
33
core/ADTFactory.h
Normal file
@ -0,0 +1,33 @@
|
||||
#include <IADTFactory.h>
|
||||
#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();
|
||||
};
|
||||
|
@ -185,6 +185,10 @@
|
||||
RelativePath="..\AdminCache.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ADTFactory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\CDataPack.cpp"
|
||||
>
|
||||
@ -307,6 +311,10 @@
|
||||
RelativePath="..\AdminCache.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ADTFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\CDataPack.h"
|
||||
>
|
||||
@ -452,6 +460,10 @@
|
||||
RelativePath="..\..\public\IAdminSystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\IADTFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\IDataPack.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_
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -45,6 +45,15 @@
|
||||
#if defined SMEXT_ENABLE_MEMUTILS
|
||||
#include <IMemoryUtils.h>
|
||||
#endif
|
||||
#if defined SMEXT_ENABLE_GAMEHELPERS
|
||||
#include <IGameHelpers.h>
|
||||
#endif
|
||||
#if defined SMEXT_ENABLE_TIMERSYS
|
||||
#include <ITimerSystem.h>
|
||||
#endif
|
||||
#if defined SMEXT_ENABLE_ADTFACTORY
|
||||
#include <IADTFactory.h>
|
||||
#endif
|
||||
|
||||
#if defined SMEXT_CONF_METAMOD
|
||||
#include <ISmmPlugin.h>
|
||||
@ -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();
|
||||
|
73
public/IADTFactory.h
Normal file
73
public/IADTFactory.h
Normal file
@ -0,0 +1,73 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_ADT_FACTORY_H_
|
||||
#define _INCLUDE_SOURCEMOD_ADT_FACTORY_H_
|
||||
|
||||
#include <IShareSys.h>
|
||||
|
||||
#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_
|
@ -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))
|
||||
{
|
||||
|
@ -51,6 +51,9 @@
|
||||
#if defined SMEXT_ENABLE_TIMERSYS
|
||||
#include <ITimerSystem.h>
|
||||
#endif
|
||||
#if defined SMEXT_ENABLE_ADTFACTORY
|
||||
#include <IADTFactory.h>
|
||||
#endif
|
||||
|
||||
#if defined SMEXT_CONF_METAMOD
|
||||
#include <ISmmPlugin.h>
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user