core/NativeOwner.h
author David Anderson <dvander@alliedmods.net>
Thu Oct 29 01:33:57 2009 -0700 (2009-10-29)
changeset 2846 5e176efe7927
parent 2226 d10b38524be3
permissions -rw-r--r--
Use GetSourceEngineBuild() from MM:S 1.8 legacy API (bug 4083, r=ds).
     1 #ifndef _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
     2 #define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
     3 
     4 #include <sp_vm_types.h>
     5 #include <sh_list.h>
     6 
     7 class CPlugin;
     8 struct NativeEntry;
     9 
    10 struct WeakNative
    11 {
    12 	WeakNative(CPlugin *plugin, uint32_t index) : 
    13 		pl(plugin), idx(index), entry(NULL)
    14 	{
    15 		pl = plugin;
    16 		idx = index;
    17 	}
    18 	WeakNative(CPlugin *plugin, uint32_t index, NativeEntry *pEntry) : 
    19 		pl(plugin), idx(index), entry(pEntry)
    20 	{
    21 		pl = plugin;
    22 		idx = index;
    23 	}
    24 	CPlugin *pl;
    25 	uint32_t idx;
    26 	NativeEntry *entry;
    27 };
    28 
    29 using namespace SourceHook;
    30 
    31 class CNativeOwner
    32 {
    33 public:
    34 	CNativeOwner();
    35 public:
    36 	virtual void DropEverything();
    37 public:
    38 	void AddNatives(const sp_nativeinfo_t *info);
    39 public:
    40 	void SetMarkSerial(unsigned int serial);
    41 	unsigned int GetMarkSerial();
    42 	void PropogateMarkSerial(unsigned int serial);
    43 public:
    44 	void AddDependent(CPlugin *pPlugin);
    45 	void AddWeakRef(const WeakNative & ref);
    46 	void DropRefsTo(CPlugin *pPlugin);
    47 	void AddReplacedNative(NativeEntry *pEntry);
    48 private:
    49 	void DropWeakRefsTo(CPlugin *pPlugin);
    50 	void UnbindWeakRef(const WeakNative & ref);
    51 protected:
    52 	List<CPlugin *> m_Dependents;
    53 	unsigned int m_nMarkSerial;
    54 	List<WeakNative> m_WeakRefs;
    55 	List<NativeEntry *> m_Natives;
    56 	List<NativeEntry *> m_ReplacedNatives;
    57 };
    58 
    59 #endif //_INCLUDE_SOURCEMOD_NATIVE_OWNER_H_