sourcehook/sourcehook_impl_chookmancont.h
author Pavol Marko <pavolmarko@gmail.com>
Sun Oct 07 22:10:07 2007 +0000 (2007-10-07)
changeset 380 f9e21a2ac558
child 381 8eded451c936
permissions -rw-r--r--
New auto-hookfunc-gen friendly interface
! breaks binary compatibility !
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2007 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): Pavol "PM OnoTo" Marko
     8 * ============================
     9 */
    10 
    11 #ifndef __SOURCEHOOK_IMPL_CHOOKMANICONT_H__
    12 #define __SOURCEHOOK_IMPL_CHOOKMANICONT_H__
    13 
    14 #include "sh_list.h"
    15 
    16 namespace SourceHook
    17 {
    18 	namespace Impl
    19 	{
    20 		class CHookManagerContainer : public List<CHookManager>
    21 		{
    22 			// *** Data ***
    23 			int m_VtblOffs;
    24 			int m_VtblIdx;
    25 			CProto m_Proto;
    26 		public:
    27 			// *** Descriptor ***
    28 			struct Descriptor
    29 			{
    30 				int m_VtblOffs;
    31 				int m_VtblIdx;
    32 				const CProto &m_Proto;		// we can assume that a Descriptor won't live for a long time
    33 
    34 				Descriptor(int vtblOffs, int vtblIdx, const CProto &proto)
    35 					: m_VtblOffs(vtblOffs), m_VtblIdx(vtblIdx), m_Proto(proto)
    36 				{
    37 				}
    38 			};
    39 
    40 			// *** Interface ***
    41 			inline CHookManagerContainer(int vtblOffs, int vtblIdx, const CProto &proto);
    42 			inline CHookManagerContainer(const CHookManager &hookMan);
    43 
    44 			inline bool operator==(const Descriptor &other) const;
    45 			inline operator bool() const;
    46 
    47 			inline int GetVtblOffs() const;
    48 			inline int GetVtblIdx() const;
    49 			inline const CProto &GetProto() const;
    50 
    51 			bool AddHookManager(const CHookManager &hookMan);
    52 			inline CHookManager &GetActiveHookManager();
    53 			inline const CHookManager &GetActiveHookManager() const;
    54 
    55 			void RemoveHookMans(Plugin plug, HookManagerPubFunc pubFunc = NULL);
    56 		};
    57 
    58 		// *** Implementation ***
    59 		inline CHookManagerContainer::CHookManagerContainer(int vtblOffs, int vtblIdx, const CProto &proto)
    60 			: m_VtblOffs(vtblOffs), m_VtblIdx(vtblIdx), m_Proto(proto)
    61 		{
    62 		}
    63 
    64 		inline CHookManagerContainer::CHookManagerContainer(const CHookManager &hookMan)
    65 			: m_VtblOffs(hookMan.GetVtblOffs()), m_VtblIdx(hookMan.GetVtblIdx()), m_Proto(hookMan.GetProto())
    66 		{
    67 			push_back(hookMan);
    68 		}
    69 
    70 		inline bool CHookManagerContainer::operator==(const Descriptor &other) const
    71 		{
    72 			return m_VtblOffs == other.m_VtblOffs
    73 				&& m_VtblIdx == other.m_VtblIdx
    74 				&& m_Proto == other.m_Proto;
    75 		}
    76 
    77 		inline CHookManagerContainer::operator bool() const
    78 		{
    79 			return !empty();
    80 		}
    81 
    82 		inline int CHookManagerContainer::GetVtblOffs() const
    83 		{
    84 			return m_VtblOffs;
    85 		}
    86 
    87 		inline int CHookManagerContainer::GetVtblIdx() const
    88 		{
    89 			return m_VtblIdx;
    90 		}
    91 
    92 		inline const CProto &CHookManagerContainer::GetProto() const
    93 		{
    94 			return m_Proto;
    95 		}
    96 
    97 		inline CHookManager &CHookManagerContainer::GetActiveHookManager()
    98 		{
    99 			begin()->Register();
   100 			return *begin();
   101 		}
   102 
   103 		const CHookManager &CHookManagerContainer::GetActiveHookManager() const
   104 		{
   105 			begin()->Register();
   106 			return *begin();
   107 		}
   108 	}
   109 }
   110 
   111 #endif