core/NativeOwner.h
author Matt Woodrow <pred@alliedmods.net>
Fri Aug 08 00:17:37 2008 +0000 (2008-08-08)
changeset 2224 676c3b826f13
parent 2088 c84cd855ca10
child 2226 d10b38524be3
permissions -rw-r--r--
Initial Import of beta structs extension.
     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 	virtual void DropEverything();
    35 public:
    36 	void AddNatives(const sp_nativeinfo_t *info);
    37 public:
    38 	void SetMarkSerial(unsigned int serial);
    39 	unsigned int GetMarkSerial();
    40 	void PropogateMarkSerial(unsigned int serial);
    41 public:
    42 	void AddDependent(CPlugin *pPlugin);
    43 	void AddWeakRef(const WeakNative & ref);
    44 	void DropRefsTo(CPlugin *pPlugin);
    45 	void AddReplacedNative(NativeEntry *pEntry);
    46 private:
    47 	void DropWeakRefsTo(CPlugin *pPlugin);
    48 	void UnbindWeakRef(const WeakNative & ref);
    49 protected:
    50 	List<CPlugin *> m_Dependents;
    51 	unsigned int m_nMarkSerial;
    52 	List<WeakNative> m_WeakRefs;
    53 	List<NativeEntry *> m_Natives;
    54 	List<NativeEntry *> m_ReplacedNatives;
    55 };
    56 
    57 #endif //_INCLUDE_SOURCEMOD_NATIVE_OWNER_H_