sourcehook/sourcehook_impl_cproto.h
author David Anderson <dvander@alliedmods.net>
Tue Oct 30 18:22:12 2007 +0000 (2007-10-30)
changeset 434 c36e37d6aadf
parent 418 109309ff6350
child 436 41f21d77c3c1
child 480 d096210677d4
permissions -rw-r--r--
now builds on ep1
     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_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 
    31 		class CProto
    32 		{
    33 			int m_Version;				// -1 = invalid
    34 			int m_NumOfParams;
    35 			IntPassInfo m_RetPassInfo;
    36 			CVector<IntPassInfo> m_ParamsPassInfo;
    37 			int m_Convention;
    38 
    39 			void Fill(const ProtoInfo *pProto);
    40 
    41 			// For old sourcehook.h: flags 0 -> assume ByVal
    42 			static unsigned int GetRealFlags(const PassInfo &info)
    43 			{
    44 				return (info.flags == 0) ? PassInfo::PassFlag_ByVal : info.flags;
    45 			}
    46 
    47 		public:
    48 			CProto() : m_Version(-1)
    49 			{
    50 			}
    51 
    52 			CProto(const ProtoInfo *pProto)
    53 			{
    54 				Fill(pProto);
    55 			}
    56 
    57 			CProto(const CProto &other) : m_Version(other.m_Version), m_NumOfParams(other.m_NumOfParams),
    58 				m_RetPassInfo(other.m_RetPassInfo), m_ParamsPassInfo(other.m_ParamsPassInfo),
    59 				m_Convention(other.m_Convention)
    60 			{
    61 
    62 			}
    63 
    64 			~CProto()
    65 			{
    66 			}
    67 
    68 			void operator = (const ProtoInfo *pProto)
    69 			{
    70 				Fill (pProto);
    71 			}
    72 
    73 			bool operator == (const CProto &other) const;
    74 
    75 			int GetVersion() const
    76 			{
    77 				return m_Version;
    78 			}
    79 
    80 			int GetNumOfParams() const
    81 			{
    82 				return m_NumOfParams;
    83 			}
    84 
    85 			const IntPassInfo & GetParam(int i) const
    86 			{
    87 				return m_ParamsPassInfo[i];
    88 			}
    89 
    90 			const IntPassInfo & GetRet() const
    91 			{
    92 				return m_RetPassInfo;
    93 			}
    94 
    95 			int GetConvention() const
    96 			{
    97 				return m_Convention;
    98 			}
    99 
   100 			static size_t GetRealSize(const IntPassInfo &info)
   101 			{
   102 				if (info.flags & PassInfo::PassFlag_ByRef)
   103 				{
   104 					return sizeof(void*);
   105 				}
   106 
   107 				return info.size;
   108 			}
   109 		};
   110 	}
   111 }
   112 
   113 #endif
   114