1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/sourcehook/sourcehook_impl_ciface.h Fri Nov 14 04:04:02 2008 -0600
1.3 @@ -0,0 +1,96 @@
1.4 +/* ======== SourceHook ========
1.5 +* Copyright (C) 2004-2008 Metamod:Source Development Team
1.6 +* No warranties of any kind
1.7 +*
1.8 +* License: zlib/libpng
1.9 +*
1.10 +* Author(s): Pavol "PM OnoTo" Marko
1.11 +* ============================
1.12 +*/
1.13 +
1.14 +#ifndef __SOURCEHOOK_IMPL_CIFACE_H__
1.15 +#define __SOURCEHOOK_IMPL_CIFACE_H__
1.16 +
1.17 +#include "sh_list.h"
1.18 +
1.19 +namespace SourceHook
1.20 +{
1.21 + namespace Impl
1.22 + {
1.23 + class CIface
1.24 + {
1.25 + // *** Data ***
1.26 + void *m_Ptr;
1.27 +
1.28 + List<CHook> m_PreHooks;
1.29 + List<CHook> m_PostHooks;
1.30 + public:
1.31 +
1.32 + // *** Descriptor ***
1.33 + typedef void* Descriptor;
1.34 +
1.35 + // *** Interface ***
1.36 + inline CIface(void *ptr);
1.37 + inline ~CIface();
1.38 + inline bool operator==(const Descriptor &other);
1.39 + inline void *GetPtr() const;
1.40 + inline List<CHook> &GetPreHookList();
1.41 + inline List<CHook> &GetPostHookList();
1.42 + inline const List<CHook> &GetPreHookList() const;
1.43 + inline const List<CHook> &GetPostHookList() const;
1.44 + };
1.45 +
1.46 + // *** Implementation ***
1.47 + inline CIface::CIface(void *ptr)
1.48 + : m_Ptr(ptr)
1.49 + {
1.50 + }
1.51 +
1.52 + inline CIface::~CIface()
1.53 + {
1.54 + // Before getting deleted, delete all remaining hook handlers
1.55 + for (List<CHook>::iterator iter = m_PreHooks.begin(); iter != m_PreHooks.end(); ++iter)
1.56 + {
1.57 + iter->GetHandler()->DeleteThis();
1.58 + }
1.59 +
1.60 + for (List<CHook>::iterator iter = m_PostHooks.begin(); iter != m_PostHooks.end(); ++iter)
1.61 + {
1.62 + iter->GetHandler()->DeleteThis();
1.63 + }
1.64 + }
1.65 +
1.66 + inline bool CIface::operator==(const Descriptor &other)
1.67 + {
1.68 + return m_Ptr == other;
1.69 + }
1.70 +
1.71 + inline void *CIface::GetPtr() const
1.72 + {
1.73 + return m_Ptr;
1.74 + }
1.75 +
1.76 + inline List<CHook> &CIface::GetPreHookList()
1.77 + {
1.78 + return m_PreHooks;
1.79 + }
1.80 +
1.81 + inline List<CHook> &CIface::GetPostHookList()
1.82 + {
1.83 + return m_PostHooks;
1.84 + }
1.85 +
1.86 + inline const List<CHook> &CIface::GetPreHookList() const
1.87 + {
1.88 + return m_PreHooks;
1.89 + }
1.90 +
1.91 + inline const List<CHook> &CIface::GetPostHookList() const
1.92 + {
1.93 + return m_PostHooks;
1.94 + }
1.95 + }
1.96 +}
1.97 +
1.98 +#endif
1.99 +