#include "stdafx.h"
#include "GTemplateCode.h"
#define new VNEW
namespace reflect
{
ObjBase VReflectBase::ReturnTemp;
#define DYNAMIC_REFLECT virtual VClassType* GetClassType();
#define DEF_REFLECT_DYN( classname ,parentclass , assemblyname ) template<> \
struct ClassExporter<classname>\
{\
static VClassType* ClassType;\
static VClassType* GetClassType(){\
return ClassType;\
}\
static void BuildClass()\
{\
ClassType = new VClassType;\
ClassType->Type = OT_ObjectPtr;\
ClassType->FullName = _T(#classname);\
ClassType->Super = ClassExporter<parentclass>::ClassType;\
VAssemblyProvider<assemblyname>::GetAssembly()->RegClassType( _T(#classname) , ClassType );\
};\
static void BuildMethod();\
}; \
VClassType* ClassExporter<classname>::ClassType = NULL;\
VClassType* classname::GetClassType()\
{\
return ClassExporter<classname>::ClassType;\
}
#define DEF_REFLECT( classname ,parentclass , assemblyname ) template<> \
struct ClassExporter<classname>\
{\
static VClassType* ClassType;\
static VClassType* GetClassType(){\
return ClassType;\
}\
static void BuildClass()\
{\
ClassType = new VClassType;\
ClassType->Type = OT_ObjectPtr;\
ClassType->FullName = _T(#classname);\
ClassType->Super = ClassExporter<parentclass>::ClassType;\
VAssemblyProvider<assemblyname>::GetAssembly()->RegClassType( _T(#classname) , ClassType );\
};\
static void BuildMethod();\
}; \
VClassType* ClassExporter<classname>::ClassType = NULL;\
#define BEGIN_REFLECT_METHOD( classname ) void ClassExporter< classname >::BuildMethod() {
#define REF_MEMBER( classname , membertype , membername ) ClassType->Members.push_back( VClassType::VMember( ClassExporter< membertype >::ClassType , _T(#membername) , offsetof(classname,membername) ) );
#define REF_PTR_MEMBER( classname , membertype , membername ) ClassType->PtrMembers.push_back( VClassType::VMember( ClassExporter< membertype >::ClassType , _T(#membername) , offsetof(classname,membername) ) );
#define REF_METHOD0(classname,funname,_ret) { VMethod0<_ret>* p_fun = new VMethod0<_ret>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD1(classname,funname,_ret,_arg1) { VMethod1<_ret,_arg1>* p_fun = new VMethod1<_ret,_arg1>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD2(classname,funname,_ret,_arg1,_arg2) { VMethod2<_ret,_arg1,_arg2>* p_fun = new VMethod2<_ret,_arg1,_arg2>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD3(classname,funname,_ret,_arg1,_arg2,_arg3) { VMethod3<_ret,_arg1,_arg2,_arg3>* p_fun = new VMethod3<_ret,_arg1,_arg2,_arg3>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD4(classname,funname,_ret,_arg1,_arg2,_arg3,_arg4) { VMethod4<_ret,_arg1,_arg2,_arg3,_arg4>* p_fun = new VMethod4<_ret,_arg1,_arg2,_arg3,_arg4>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD5(classname,funname,_ret,_arg1,_arg2,_arg3,_arg4,_arg5) { VMethod5<_ret,_arg1,_arg2,_arg3,_arg4,_arg5>* p_fun = new VMethod5<_ret,_arg1,_arg2,_arg3,_arg4,_arg5>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD6(classname,funname,_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6) { VMethod6<_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6>* p_fun = new VMethod6<_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD7(classname,funname,_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7) { VMethod7<_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7>* p_fun = new VMethod7<_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define REF_METHOD8(classname,funname,_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7,_arg8) { VMethod8<_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7,_arg8>* p_fun = new VMethod8<_ret,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7,_arg8>;\
p_fun->Name = _T(#funname);\
p_fun->Initialize( &##classname::##funname );\
ClassType->Methods.push_back(p_fun); }
#define END_REFLECT_METHOD }
/////////////////////////////////////////////////////////////////////
///<ReflectExport name="MyTestClass"/>
class testclass : public VReflectBase
{
public:
DYNAMIC_REFLECT
int mem1;
///<ReflectExport/>
void fun0()
{
return;
}
///<ReflectExport/>
int fun1(float a)
{
return 0;
};
int fun2(float a,int b)
{
return 0;
};
int fun3(float a,int b,float c)
{
return 0;
};
int fun4(float a,int b,float c,int d)
{
return 0;
};
int fun5(float a,int b,float c,int d,float e)
{
return 0;
};
int fun6(float a,int b,float c,int d,float e,int f)
{
return 0;
};
int fun7(float a,int b,float c,int d,float e,int f,float g)
{
return 0;
};
int fun8(float a,int b,float c,int d,float e,int f,float g,int h)
{
return 0;
};
};
///<ReflectExport name="MyTestClass"/>
class testclass2 : public testclass
{
public:
DYNAMIC_REFLECT
testclass2()
: objptr(NULL)
{
objptr = new testclass;
}
~testclass2()
{
delete objptr;
}
testclass* objptr;
///<ReflectExport/>
float fun3(int a)
{
return 0;
};
};
const int assembly_victory3d = 1;
template<>
struct VAssemblyProvider< assembly_victory3d >
{
static VAssembly* GetAssembly(){
static VAssembly asmobj;
return &asmobj;
}
};
DEF_REFLECT_DYN(reflect::testclass,NullObject, assembly_victory3d )
BEGIN_REFLECT_METHOD(reflect::testclass)
REF_MEMBER(reflect::testclass,int,mem1)
REF_METHOD0(reflect::testclass,fun0,void)
REF_METHOD1(reflect::testclass,fun1,int,float)
REF_METHOD2(reflect::testclass,fun2,int,float,int)
REF_METHOD3(reflect::testclass,fun3,int,float,int,float)
REF_METHOD4(reflect::testclass,fun4,int,float,int,float,int)
REF_METHOD5(reflect::testclass,fun5,int,float,int,float,int,float)
REF_METHOD6(reflect::testclass,fun6,int,float,int,float,int,float,int)
REF_METHOD7(reflect::testclass,fun7,int,float,int,float,int,float,int,float)
REF_METHOD8(reflect::testclass,fun8,int,float,int,float,int,float,int,float,int)
END_REFLECT_METHOD
DEF_REFLECT_DYN(reflect::testclass2,testclass, assembly_victory3d )
BEGIN_REFLECT_METHOD(reflect::testclass2)
REF_PTR_MEMBER(reflect::testclass2,testclass,objptr)
REF_METHOD1(reflect::testclass2,fun3,float,int)
END_REFLECT_METHOD
void reflect_test()
{
//创建ClassType信息
ClassExporter<reflect::testclass>::BuildClass();
ClassExporter<reflect::testclass2>::BuildClass();
ClassExporter<reflect::testclass>::BuildMethod();
ClassExporter<reflect::testclass2>::BuildMethod();
//获得testclass的ClassType
VClassType* pp = ClassExporter<reflect::testclass>::ClassType;
VClassType* pp2 = ClassExporter<reflect::testclass2>::ClassType;
testclass obj;
testclass2 obj2;
VReflectBase* objptr = pp2->AsReflectPointer( &obj2 , 0 );
VClassType* pPtrMemType = objptr->GetClassType();
if( pPtrMemType->CanConvertTo( ClassExporter<reflect::testclass>::ClassType ) )
{
reflect::testclass* pClass2 = (reflect::testclass*)objptr;
}
VAssembly* pasm = VAssemblyProvider<assembly_victory3d>::GetAssembly();
std::
- 1
- 2
- 3
- 4
前往页