No more STL! Imported TinyHash
authorDavid Anderson <dvander@alliedmods.net>
Tue Sep 13 16:47:42 2005 +0000 (2005-09-13)
changeset 1017d93aa4d2bf3
parent 100 022428df37c9
child 102 894e7be6c431
No more STL! Imported TinyHash
sourcehook/generate/sourcehook.hxx
sourcehook/sh_list.h
sourcehook/sourcehook.cpp
sourcehook/sourcehook.h
     1.1 --- a/sourcehook/generate/sourcehook.hxx	Tue Sep 13 16:47:42 2005 +0000
     1.2 +++ b/sourcehook/generate/sourcehook.hxx	Tue Sep 13 16:47:42 2005 +0000
     1.3 @@ -185,8 +185,8 @@
     1.4  					int thisptr_offs;				//!< This pointer offset
     1.5  				};
     1.6  				void *ptr;							//!< Pointer to the interface instance
     1.7 -				std::list<Hook> hooks_pre;			//!< A list of pre-hooks
     1.8 -				std::list<Hook> hooks_post;			//!< A list of post-hooks
     1.9 +				SourceHook::List<Hook> hooks_pre;			//!< A list of pre-hooks
    1.10 +				SourceHook::List<Hook> hooks_post;			//!< A list of post-hooks
    1.11  				bool operator ==(void *other) const
    1.12  				{
    1.13  					return ptr == other;
    1.14 @@ -196,7 +196,7 @@
    1.15  			void *vfnptr;							//!< Pointer to the function
    1.16  			void *orig_entry;						//!< The original vtable entry
    1.17  
    1.18 -			typedef std::list<Iface> IfaceList;
    1.19 +			typedef SourceHook::List<Iface> IfaceList;
    1.20  			typedef IfaceList::iterator IfaceListIter;
    1.21  			IfaceList ifaces;						//!< List of interface pointers
    1.22  
    1.23 @@ -214,13 +214,13 @@
    1.24  
    1.25  		void *hookfunc_vfnptr;					//!< Pointer to the hookfunc impl
    1.26  		
    1.27 -		typedef std::list<VfnPtr> VfnPtrList;
    1.28 +		typedef SourceHook::List<VfnPtr> VfnPtrList;
    1.29  		typedef VfnPtrList::iterator VfnPtrListIter;
    1.30  		VfnPtrList vfnptrs;				//!< List of hooked interfaces
    1.31  	};
    1.32  
    1.33 -	typedef std::vector<void*> OrigFuncs;
    1.34 -	typedef std::map<int, OrigFuncs> OrigVTables;
    1.35 +	typedef SourceHook::CVector<void*> OrigFuncs;
    1.36 +	typedef SourceHook::THash<int, OrigFuncs> OrigVTables;
    1.37  
    1.38  	template<class B> struct CallClass
    1.39  	{
    1.40 @@ -467,7 +467,7 @@
    1.41  	void *ourvfnptr = reinterpret_cast<void*>( \
    1.42  		*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_HI->vtbl_offs) + ms_HI->vtbl_idx); \
    1.43  	\
    1.44 -	HookManagerInfo::VfnPtrListIter vfptriter = std::find(ms_HI->vfnptrs.begin(), \
    1.45 +	HookManagerInfo::VfnPtrListIter vfptriter = ms_HI->find(ms_HI->vfnptrs.begin(), \
    1.46  		ms_HI->vfnptrs.end(), ourvfnptr); \
    1.47  	if (vfptriter == ms_HI->vfnptrs.end()) \
    1.48  	{ \
    1.49 @@ -476,7 +476,7 @@
    1.50  	} \
    1.51  	HookManagerInfo::VfnPtr &vfnptr = *vfptriter; \
    1.52  	/* 2) Find the iface */ \
    1.53 -	HookManagerInfo::VfnPtr::IfaceListIter ifiter = std::find(vfnptr.ifaces.begin(), vfnptr.ifaces.end(), this); \
    1.54 +	HookManagerInfo::VfnPtr::IfaceListIter ifiter = ms_HI->find(vfnptr.ifaces.begin(), vfnptr.ifaces.end(), this); \
    1.55  	if (ifiter == vfnptr.ifaces.end()) \
    1.56  	{ \
    1.57  		/* The iface info was not found. Redirect the call to the original function. */ \
    1.58 @@ -486,8 +486,8 @@
    1.59  	} \
    1.60  	HookManagerInfo::VfnPtr::Iface &ci = *ifiter; \
    1.61  	/* 2) Declare some vars and set it up */ \
    1.62 -	std::list<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
    1.63 -	std::list<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
    1.64 +	SourceHook::List<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
    1.65 +	SourceHook::List<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
    1.66  	rettype orig_ret; \
    1.67  	rettype override_ret; \
    1.68  	rettype plugin_ret; \
    1.69 @@ -501,7 +501,7 @@
    1.70  
    1.71  #define SH_CALL_HOOKS(post, params) \
    1.72  	prev_res = MRES_IGNORED; \
    1.73 -	for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
    1.74 +	for (SourceHook::List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
    1.75  	{ \
    1.76  		if (hiter->paused) continue; \
    1.77  		cur_res = MRES_IGNORED; \
    1.78 @@ -544,7 +544,7 @@
    1.79  	void *ourvfnptr = reinterpret_cast<void*>( \
    1.80  		*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_HI->vtbl_offs) + ms_HI->vtbl_idx); \
    1.81  	\
    1.82 -	HookManagerInfo::VfnPtrListIter vfptriter = std::find(ms_HI->vfnptrs.begin(), \
    1.83 +	HookManagerInfo::VfnPtrListIter vfptriter = ms_HI->find(ms_HI->vfnptrs.begin(), \
    1.84  		ms_HI->vfnptrs.end(), ourvfnptr); \
    1.85  	if (vfptriter == ms_HI->vfnptrs.end()) \
    1.86  	{ \
    1.87 @@ -553,7 +553,7 @@
    1.88  	} \
    1.89  	HookManagerInfo::VfnPtr &vfnptr = *vfptriter; \
    1.90  	/* 2) Find the iface */ \
    1.91 -	HookManagerInfo::VfnPtr::IfaceListIter ifiter = std::find(vfnptr.ifaces.begin(), vfnptr.ifaces.end(), this); \
    1.92 +	HookManagerInfo::VfnPtr::IfaceListIter ifiter = ms_HI->find(vfnptr.ifaces.begin(), vfnptr.ifaces.end(), this); \
    1.93  	if (ifiter == vfnptr.ifaces.end()) \
    1.94  	{ \
    1.95  		/* The iface info was not found. Redirect the call to the original function. */ \
    1.96 @@ -564,8 +564,8 @@
    1.97  	} \
    1.98  	HookManagerInfo::VfnPtr::Iface &ci = *ifiter; \
    1.99  	/* 2) Declare some vars and set it up */ \
   1.100 -	std::list<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
   1.101 -	std::list<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
   1.102 +	SourceHook::List<HookManagerInfo::VfnPtr::Iface::Hook> &prelist = ci.hooks_pre; \
   1.103 +	SourceHook::List<HookManagerInfo::VfnPtr::Iface::Hook> &postlist = ci.hooks_post; \
   1.104  	META_RES &cur_res = SH_GLOB_SHPTR->GetCurResRef(); \
   1.105  	META_RES &prev_res = SH_GLOB_SHPTR->GetPrevResRef(); \
   1.106  	META_RES &status = SH_GLOB_SHPTR->GetStatusRef(); \
   1.107 @@ -575,7 +575,7 @@
   1.108  
   1.109  #define SH_CALL_HOOKS_void(post, params) \
   1.110  	prev_res = MRES_IGNORED; \
   1.111 -	for (std::list<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.112 +	for (SourceHook::List<HookManagerInfo::VfnPtr::Iface::Hook>::iterator hiter = post##list.begin(); hiter != post##list.end(); ++hiter) \
   1.113  	{ \
   1.114  		if (hiter->paused) continue; \
   1.115  		cur_res = MRES_IGNORED; \
   1.116 @@ -686,8 +686,8 @@
   1.117  	using namespace ::SourceHook; \
   1.118  	MemFuncInfo mfi; \
   1.119  	GetFuncInfo(m_CC->ptr, m_MFP, mfi); \
   1.120 -	OrigVTables::const_iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
   1.121 -	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->second.size() || iter->second[mfi.vtblindex] == NULL) \
   1.122 +	OrigVTables::iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
   1.123 +	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->val.size() || iter->val[mfi.vtblindex] == NULL) \
   1.124  		return (m_CC->ptr->*m_MFP)call; \
   1.125  	\
   1.126  	/* It's hooked. Call the original function. */ \
   1.127 @@ -696,7 +696,7 @@
   1.128  		RetType(EmptyClass::*mfpnew)prms; \
   1.129  		void *addr; \
   1.130  	} u; \
   1.131 -	u.addr = iter->second[mfi.vtblindex]; \
   1.132 +	u.addr = iter->val[mfi.vtblindex]; \
   1.133  	\
   1.134  	void *adjustedthisptr = reinterpret_cast<void*>(reinterpret_cast<char*>(m_CC->ptr) + mfi.thisptroffs); \
   1.135  	return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
   1.136 @@ -709,8 +709,8 @@
   1.137  	using namespace ::SourceHook; \
   1.138  	MemFuncInfo mfi; \
   1.139  	GetFuncInfo(m_CC->ptr, m_MFP, mfi); \
   1.140 -	OrigVTables::const_iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
   1.141 -	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->second.size() || iter->second[mfi.vtblindex] == NULL) \
   1.142 +	OrigVTables::iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
   1.143 +	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->val.size() || iter->val[mfi.vtblindex] == NULL) \
   1.144  		return (m_CC->ptr->*m_MFP)call; \
   1.145  	\
   1.146  	/* It's hooked. Call the original function. */ \
   1.147 @@ -723,7 +723,7 @@
   1.148  			intptr_t adjustor; \
   1.149  		} s; \
   1.150  	} u; \
   1.151 -	u.s.addr = iter->second[mfi.vtblindex]; \
   1.152 +	u.s.addr = iter->val[mfi.vtblindex]; \
   1.153  	u.s.adjustor = mfi.thisptroffs; \
   1.154  	\
   1.155  	return (reinterpret_cast<EmptyClass*>(m_CC->ptr)->*u.mfpnew)call; \
     2.1 --- a/sourcehook/sh_list.h	Tue Sep 13 16:47:42 2005 +0000
     2.2 +++ b/sourcehook/sh_list.h	Tue Sep 13 16:47:42 2005 +0000
     2.3 @@ -137,6 +137,7 @@
     2.4  				m_This = m_This->next;
     2.5  			return *this;
     2.6  		}
     2.7 +		//post increment
     2.8  		iterator operator++(int)
     2.9  		{
    2.10  			iterator old(*this);
    2.11 @@ -164,6 +165,10 @@
    2.12  		{
    2.13  			return (m_This == where.m_This);
    2.14  		}
    2.15 +		bool operator ==(const iterator &where) const
    2.16 +		{
    2.17 +			return (m_This == where.m_This);
    2.18 +		}
    2.19  	private:
    2.20  		ListNode *m_This;
    2.21  	};
     3.1 --- a/sourcehook/sourcehook.cpp	Tue Sep 13 16:47:42 2005 +0000
     3.2 +++ b/sourcehook/sourcehook.cpp	Tue Sep 13 16:47:42 2005 +0000
     3.3 @@ -454,9 +454,9 @@
     3.4  		OrigVTables::iterator iter = cc.cc.vt.find(vtbl_offs);
     3.5  		if (iter != cc.cc.vt.end())
     3.6  		{
     3.7 -			if (iter->second.size() > (size_t)vtbl_idx)
     3.8 +			if (iter->val.size() > (size_t)vtbl_idx)
     3.9  			{
    3.10 -				iter->second[vtbl_idx] = 0;
    3.11 +				iter->val[vtbl_idx] = 0;
    3.12  				// Free some memory if possible
    3.13  				// :TODO: add this back in!
    3.14  				/*
     4.1 --- a/sourcehook/sourcehook.h	Tue Sep 13 16:47:42 2005 +0000
     4.2 +++ b/sourcehook/sourcehook.h	Tue Sep 13 16:47:42 2005 +0000
     4.3 @@ -70,7 +70,7 @@
     4.4  #include "sh_memory.h"
     4.5  #include "sh_list.h"
     4.6  #include "sh_vector.h"
     4.7 -#include <map>
     4.8 +#include "sh_tinyhash.h"
     4.9  
    4.10  // Good old metamod!
    4.11  
    4.12 @@ -219,7 +219,7 @@
    4.13  	};
    4.14  
    4.15  	typedef SourceHook::CVector<void*> OrigFuncs;
    4.16 -	typedef std::map<int, OrigFuncs> OrigVTables;
    4.17 +	typedef SourceHook::THash<int, OrigFuncs> OrigVTables;
    4.18  
    4.19  	template<class B> struct CallClass
    4.20  	{
    4.21 @@ -1497,8 +1497,8 @@
    4.22  	using namespace ::SourceHook; \
    4.23  	MemFuncInfo mfi; \
    4.24  	GetFuncInfo(m_CC->ptr, m_MFP, mfi); \
    4.25 -	OrigVTables::const_iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
    4.26 -	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->second.size() || iter->second[mfi.vtblindex] == NULL) \
    4.27 +	OrigVTables::iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
    4.28 +	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->val.size() || iter->val[mfi.vtblindex] == NULL) \
    4.29  		return (m_CC->ptr->*m_MFP)call; \
    4.30  	\
    4.31  	/* It's hooked. Call the original function. */ \
    4.32 @@ -1507,7 +1507,7 @@
    4.33  		RetType(EmptyClass::*mfpnew)prms; \
    4.34  		void *addr; \
    4.35  	} u; \
    4.36 -	u.addr = iter->second[mfi.vtblindex]; \
    4.37 +	u.addr = iter->val[mfi.vtblindex]; \
    4.38  	\
    4.39  	void *adjustedthisptr = reinterpret_cast<void*>(reinterpret_cast<char*>(m_CC->ptr) + mfi.thisptroffs); \
    4.40  	return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
    4.41 @@ -1520,8 +1520,8 @@
    4.42  	using namespace ::SourceHook; \
    4.43  	MemFuncInfo mfi; \
    4.44  	GetFuncInfo(m_CC->ptr, m_MFP, mfi); \
    4.45 -	OrigVTables::const_iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
    4.46 -	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->second.size() || iter->second[mfi.vtblindex] == NULL) \
    4.47 +	OrigVTables::iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
    4.48 +	if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->val.size() || iter->val[mfi.vtblindex] == NULL) \
    4.49  		return (m_CC->ptr->*m_MFP)call; \
    4.50  	\
    4.51  	/* It's hooked. Call the original function. */ \
    4.52 @@ -1534,7 +1534,7 @@
    4.53  			intptr_t adjustor; \
    4.54  		} s; \
    4.55  	} u; \
    4.56 -	u.s.addr = iter->second[mfi.vtblindex]; \
    4.57 +	u.s.addr = iter->val[mfi.vtblindex]; \
    4.58  	u.s.adjustor = mfi.thisptroffs; \
    4.59  	\
    4.60  	return (reinterpret_cast<EmptyClass*>(m_CC->ptr)->*u.mfpnew)call; \