core/sourcehook/sourcehook_impl_cproto.h
changeset 539 db914129ae01
parent 523 6f1630519b81
child 733 2365240861a2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/sourcehook/sourcehook_impl_cproto.h	Fri Nov 14 04:04:02 2008 -0600
     1.3 @@ -0,0 +1,141 @@
     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_CPROTO_H__
    1.15 +#define __SOURCEHOOK_IMPL_CPROTO_H__
    1.16 +
    1.17 +namespace SourceHook
    1.18 +{
    1.19 +	namespace Impl
    1.20 +	{
    1.21 +		// Internal representation
    1.22 +		struct IntPassInfo
    1.23 +		{
    1.24 +			size_t size;
    1.25 +			int type;
    1.26 +			unsigned int flags;
    1.27 +
    1.28 +			void *pNormalCtor;
    1.29 +			void *pCopyCtor;
    1.30 +			void *pDtor;
    1.31 +			void *pAssignOperator;
    1.32 +
    1.33 +			bool operator == (const IntPassInfo &other) const
    1.34 +			{
    1.35 +				return size == other.size
    1.36 +					&& type == other.type
    1.37 +					&& flags == other.flags
    1.38 +					&& pNormalCtor == other.pNormalCtor
    1.39 +					&& pDtor == other.pDtor
    1.40 +					&& pAssignOperator == other.pAssignOperator;
    1.41 +			}
    1.42 +
    1.43 +			bool operator != (const IntPassInfo &other) const
    1.44 +			{
    1.45 +				return !(*this == other);
    1.46 +			}
    1.47 +		};
    1.48 +
    1.49 +		class CProto
    1.50 +		{
    1.51 +			int m_Version;				// -1 = invalid
    1.52 +			int m_NumOfParams;
    1.53 +			IntPassInfo m_RetPassInfo;
    1.54 +			CVector<IntPassInfo> m_ParamsPassInfo;
    1.55 +			int m_Convention;
    1.56 +
    1.57 +			void Fill(const ProtoInfo *pProto);
    1.58 +
    1.59 +			// For old sourcehook.h: flags 0 -> assume ByVal
    1.60 +			static unsigned int GetRealFlags(const PassInfo &info)
    1.61 +			{
    1.62 +				return (info.flags == 0) ? PassInfo::PassFlag_ByVal : info.flags;
    1.63 +			}
    1.64 +
    1.65 +		public:
    1.66 +			CProto() : m_Version(-1)
    1.67 +			{
    1.68 +			}
    1.69 +
    1.70 +			CProto(const ProtoInfo *pProto)
    1.71 +			{
    1.72 +				Fill(pProto);
    1.73 +			}
    1.74 +
    1.75 +			CProto(const CProto &other) : m_Version(other.m_Version), m_NumOfParams(other.m_NumOfParams),
    1.76 +				m_RetPassInfo(other.m_RetPassInfo), m_ParamsPassInfo(other.m_ParamsPassInfo),
    1.77 +				m_Convention(other.m_Convention)
    1.78 +			{
    1.79 +
    1.80 +			}
    1.81 +
    1.82 +			~CProto()
    1.83 +			{
    1.84 +			}
    1.85 +
    1.86 +			void operator = (const ProtoInfo *pProto)
    1.87 +			{
    1.88 +				Fill (pProto);
    1.89 +			}
    1.90 +
    1.91 +			bool operator == (const CProto &other) const;
    1.92 +
    1.93 +			bool ExactlyEqual(const CProto &other) const;
    1.94 +
    1.95 +			int GetVersion() const
    1.96 +			{
    1.97 +				return m_Version;
    1.98 +			}
    1.99 +
   1.100 +			int GetNumOfParams() const
   1.101 +			{
   1.102 +				return m_NumOfParams;
   1.103 +			}
   1.104 +
   1.105 +			const IntPassInfo & GetParam(int i) const
   1.106 +			{
   1.107 +				return m_ParamsPassInfo[i];
   1.108 +			}
   1.109 +
   1.110 +			IntPassInfo & GetParam(int i)
   1.111 +			{
   1.112 +				return m_ParamsPassInfo[i];
   1.113 +			}
   1.114 +
   1.115 +			const IntPassInfo & GetRet() const
   1.116 +			{
   1.117 +				return m_RetPassInfo;
   1.118 +			}
   1.119 +
   1.120 +			IntPassInfo & GetRet()
   1.121 +			{
   1.122 +				return m_RetPassInfo;
   1.123 +			}
   1.124 +
   1.125 +			int GetConvention() const
   1.126 +			{
   1.127 +				return m_Convention;
   1.128 +			}
   1.129 +
   1.130 +			static size_t GetRealSize(const IntPassInfo &info)
   1.131 +			{
   1.132 +				if (info.flags & PassInfo::PassFlag_ByRef)
   1.133 +				{
   1.134 +					return sizeof(void*);
   1.135 +				}
   1.136 +
   1.137 +				return info.size;
   1.138 +			}
   1.139 +		};
   1.140 +	}
   1.141 +}
   1.142 +
   1.143 +#endif
   1.144 +