diff -r 6ec9d491ec1e -r db914129ae01 core/sourcehook/sourcehook_impl_ciface.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/sourcehook/sourcehook_impl_ciface.h Fri Nov 14 04:04:02 2008 -0600 @@ -0,0 +1,96 @@ +/* ======== SourceHook ======== +* Copyright (C) 2004-2008 Metamod:Source Development Team +* No warranties of any kind +* +* License: zlib/libpng +* +* Author(s): Pavol "PM OnoTo" Marko +* ============================ +*/ + +#ifndef __SOURCEHOOK_IMPL_CIFACE_H__ +#define __SOURCEHOOK_IMPL_CIFACE_H__ + +#include "sh_list.h" + +namespace SourceHook +{ + namespace Impl + { + class CIface + { + // *** Data *** + void *m_Ptr; + + List m_PreHooks; + List m_PostHooks; + public: + + // *** Descriptor *** + typedef void* Descriptor; + + // *** Interface *** + inline CIface(void *ptr); + inline ~CIface(); + inline bool operator==(const Descriptor &other); + inline void *GetPtr() const; + inline List &GetPreHookList(); + inline List &GetPostHookList(); + inline const List &GetPreHookList() const; + inline const List &GetPostHookList() const; + }; + + // *** Implementation *** + inline CIface::CIface(void *ptr) + : m_Ptr(ptr) + { + } + + inline CIface::~CIface() + { + // Before getting deleted, delete all remaining hook handlers + for (List::iterator iter = m_PreHooks.begin(); iter != m_PreHooks.end(); ++iter) + { + iter->GetHandler()->DeleteThis(); + } + + for (List::iterator iter = m_PostHooks.begin(); iter != m_PostHooks.end(); ++iter) + { + iter->GetHandler()->DeleteThis(); + } + } + + inline bool CIface::operator==(const Descriptor &other) + { + return m_Ptr == other; + } + + inline void *CIface::GetPtr() const + { + return m_Ptr; + } + + inline List &CIface::GetPreHookList() + { + return m_PreHooks; + } + + inline List &CIface::GetPostHookList() + { + return m_PostHooks; + } + + inline const List &CIface::GetPreHookList() const + { + return m_PreHooks; + } + + inline const List &CIface::GetPostHookList() const + { + return m_PostHooks; + } + } +} + +#endif +