core/sourcehook/sourcehook_impl_cproto.h
author Scott Ehlert <ds@alliedmods.net>
Mon Apr 22 21:54:21 2013 -0500 (2013-04-22)
changeset 834 3cabb288e70a
parent 733 2365240861a2
permissions -rw-r--r--
Triggering a build.
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2010 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_CPROTO_H__
    12 #define __SOURCEHOOK_IMPL_CPROTO_H__
    13 
    14 namespace SourceHook
    15 {
    16 	namespace Impl
    17 	{
    18 		// Internal representation
    19 		struct IntPassInfo
    20 		{
    21 			size_t size;
    22 			int type;
    23 			unsigned int flags;
    24 
    25 			void *pNormalCtor;
    26 			void *pCopyCtor;
    27 			void *pDtor;
    28 			void *pAssignOperator;
    29 
    30 			bool operator == (const IntPassInfo &other) const
    31 			{
    32 				return size == other.size
    33 					&& type == other.type
    34 					&& flags == other.flags
    35 					&& pNormalCtor == other.pNormalCtor
    36 					&& pDtor == other.pDtor
    37 					&& pAssignOperator == other.pAssignOperator;
    38 			}
    39 
    40 			bool operator != (const IntPassInfo &other) const
    41 			{
    42 				return !(*this == other);
    43 			}
    44 		};
    45 
    46 		class CProto
    47 		{
    48 			int m_Version;				// -1 = invalid
    49 			int m_NumOfParams;
    50 			IntPassInfo m_RetPassInfo;
    51 			CVector<IntPassInfo> m_ParamsPassInfo;
    52 			int m_Convention;
    53 
    54 			void Fill(const ProtoInfo *pProto);
    55 
    56 			// For old sourcehook.h: flags 0 -> assume ByVal
    57 			static unsigned int GetRealFlags(const PassInfo &info)
    58 			{
    59 				return (info.flags == 0) ? PassInfo::PassFlag_ByVal : info.flags;
    60 			}
    61 
    62 		public:
    63 			CProto() : m_Version(-1)
    64 			{
    65 			}
    66 
    67 			CProto(const ProtoInfo *pProto)
    68 			{
    69 				Fill(pProto);
    70 			}
    71 
    72 			CProto(const CProto &other) : m_Version(other.m_Version), m_NumOfParams(other.m_NumOfParams),
    73 				m_RetPassInfo(other.m_RetPassInfo), m_ParamsPassInfo(other.m_ParamsPassInfo),
    74 				m_Convention(other.m_Convention)
    75 			{
    76 
    77 			}
    78 
    79 			~CProto()
    80 			{
    81 			}
    82 
    83 			void operator = (const ProtoInfo *pProto)
    84 			{
    85 				Fill (pProto);
    86 			}
    87 
    88 			bool operator == (const CProto &other) const;
    89 
    90 			bool ExactlyEqual(const CProto &other) const;
    91 
    92 			int GetVersion() const
    93 			{
    94 				return m_Version;
    95 			}
    96 
    97 			int GetNumOfParams() const
    98 			{
    99 				return m_NumOfParams;
   100 			}
   101 
   102 			const IntPassInfo & GetParam(int i) const
   103 			{
   104 				return m_ParamsPassInfo[i];
   105 			}
   106 
   107 			IntPassInfo & GetParam(int i)
   108 			{
   109 				return m_ParamsPassInfo[i];
   110 			}
   111 
   112 			const IntPassInfo & GetRet() const
   113 			{
   114 				return m_RetPassInfo;
   115 			}
   116 
   117 			IntPassInfo & GetRet()
   118 			{
   119 				return m_RetPassInfo;
   120 			}
   121 
   122 			int GetConvention() const
   123 			{
   124 				return m_Convention;
   125 			}
   126 
   127 			static size_t GetRealSize(const IntPassInfo &info)
   128 			{
   129 				if (info.flags & PassInfo::PassFlag_ByRef)
   130 				{
   131 					return sizeof(void*);
   132 				}
   133 
   134 				return info.size;
   135 			}
   136 		};
   137 	}
   138 }
   139 
   140 #endif
   141