added plugin properties
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40492
This commit is contained in:
parent
3b151e1790
commit
20441b70d3
@ -40,6 +40,7 @@ CPlugin::CPlugin(const char *file)
|
||||
snprintf(m_filename, sizeof(m_filename), "%s", file);
|
||||
m_handle = 0;
|
||||
m_ident = NULL;
|
||||
m_pProps = sm_trie_create();
|
||||
}
|
||||
|
||||
CPlugin::~CPlugin()
|
||||
@ -75,6 +76,10 @@ CPlugin::~CPlugin()
|
||||
g_pSourcePawn->FreeFromMemory(m_plugin);
|
||||
m_plugin = NULL;
|
||||
}
|
||||
if (!m_pProps)
|
||||
{
|
||||
sm_trie_destroy(m_pProps);
|
||||
}
|
||||
}
|
||||
|
||||
void CPlugin::InitIdentity()
|
||||
@ -125,6 +130,23 @@ CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
|
||||
return pPlugin;
|
||||
}
|
||||
|
||||
bool CPlugin::GetProperty(const char *prop, void **ptr, bool remove/* =false */)
|
||||
{
|
||||
bool exists = sm_trie_retrieve(m_pProps, prop, ptr);
|
||||
|
||||
if (exists && remove)
|
||||
{
|
||||
sm_trie_delete(m_pProps, prop);
|
||||
}
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
bool CPlugin::SetProperty(const char *prop, void *ptr)
|
||||
{
|
||||
return sm_trie_insert(m_pProps, prop, ptr);
|
||||
}
|
||||
|
||||
ICompilation *CPlugin::StartMyCompile(IVirtualMachine *vm)
|
||||
{
|
||||
if (!m_plugin)
|
||||
|
@ -117,6 +117,8 @@ public:
|
||||
virtual unsigned int GetSerial() const;
|
||||
virtual const sp_plugin_t *GetPluginStructure() const;
|
||||
virtual IdentityToken_t *GetIdentity() const;
|
||||
virtual bool SetProperty(const char *prop, void *ptr);
|
||||
virtual bool GetProperty(const char *prop, void **ptr, bool remove=false);
|
||||
public:
|
||||
/**
|
||||
* Creates a plugin object with default values.
|
||||
@ -241,6 +243,7 @@ private:
|
||||
bool m_WasRunning;
|
||||
CVector<unsigned int> m_PhraseFiles;
|
||||
CVector<ConVar *> m_ConVarList;
|
||||
Trie *m_pProps;
|
||||
};
|
||||
|
||||
class CPluginManager :
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <sp_vm_api.h>
|
||||
|
||||
#define SMINTERFACE_PLUGINSYSTEM_NAME "IPluginManager"
|
||||
#define SMINTERFACE_PLUGINSYSTEM_VERSION 1
|
||||
#define SMINTERFACE_PLUGINSYSTEM_VERSION 2
|
||||
|
||||
/** Context user slot 3 is used Core for holding an IPluginContext pointer. */
|
||||
#define SM_CONTEXTVAR_USER 3
|
||||
@ -154,6 +154,28 @@ namespace SourceMod
|
||||
* @brief Returns a plugin's identity token.
|
||||
*/
|
||||
virtual IdentityToken_t *GetIdentity() const =0;
|
||||
|
||||
/**
|
||||
* @brief Sets a property on this plugin. This is used for per-plugin
|
||||
* data from extensions or other parts of core. The property's value must
|
||||
* be manually destructed when the plugin is destroyed.
|
||||
*
|
||||
* @param prop String containing name of the property.
|
||||
* @param ptr Generic pointer to set.
|
||||
* @return True on success, false if the property is already set.
|
||||
*/
|
||||
virtual bool SetProperty(const char *prop, void *ptr) =0;
|
||||
|
||||
/**
|
||||
* @brief Gets a property from a plugin.
|
||||
*
|
||||
* @param prop String containing the property's name.
|
||||
* @param ptr Optional pointer to the generic pointer.
|
||||
* @param remove Optional boolean value; if true, property is removed
|
||||
* (so it can be set again).
|
||||
* @return True if the property existed, false otherwise.
|
||||
*/
|
||||
virtual bool GetProperty(const char *prop, void **ptr, bool remove=false) =0;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user