vcfrttiimpl.h
来自「这是VCF框架的代码」· C头文件 代码 · 共 2,696 行 · 第 1/5 页
H
2,696 行
typedef ARG4_TYPE Argument4; typedef ARG5_TYPE Argument5; typedef RETURN_TYPE (SOURCE_TYPE::*MemberFunc)(ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5); typedef TypedMethodArg5Return<SOURCE_TYPE,RETURN_TYPE,ARG1_TYPE, ARG2_TYPE,ARG3_TYPE,ARG4_TYPE,ARG5_TYPE> TypedMethodArg5ReturnType; TypedMethodArg5Return( MemberFunc methodPtr=NULL, const String& argTypes="", SOURCE_TYPE* source=NULL ): TypedMethodReturn<SOURCE_TYPE,RETURN_TYPE>( argTypes, source ){ argCount_ = 5; methodPtr_ = methodPtr; } TypedMethodArg5Return( const TypedMethodArg5ReturnType& method ) { *this = method; } TypedMethodArg5ReturnType& operator=( const TypedMethodArg5ReturnType& rhs ) { TypedMethodReturn<SOURCE_TYPE,RETURN_TYPE>::operator =( rhs ); methodPtr_ = rhs.methodPtr_; return *this; } virtual Method* clone() { return new TypedMethodArg5ReturnType( *this ); } virtual ~TypedMethodArg5Return(){ } virtual VariantData* invoke( VariantData** arguments, Object* source=NULL ){ if ( NULL != source ) { source_ = dynamic_cast<SOURCE_TYPE*>( source ); } if ( (NULL != source_) && (NULL != methodPtr_) ){ if ( 5 == argCount_ ) { returnVal_ = (source_->*methodPtr_)( (Argument1)*(arguments[0]), (Argument2)*(arguments[1]), (Argument3)*(arguments[2]), (Argument4)*(arguments[3]), (Argument5)*(arguments[4]) ); } } return &returnVal_; }protected: MemberFunc methodPtr_;};/**\class TypedMethodArg6Return VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*Method template for methods with 6 arguments and a return value*/template <typename SOURCE_TYPE, typename RETURN_TYPE, typename ARG1_TYPE, typename ARG2_TYPE, typename ARG3_TYPE, typename ARG4_TYPE, typename ARG5_TYPE, typename ARG6_TYPE>class TypedMethodArg6Return : public TypedMethodReturn<SOURCE_TYPE,RETURN_TYPE> {public: #if defined(VCF_MINGW) || defined(VCF_GCC) using TypedMethod<SOURCE_TYPE>::hasReturnValue_; using TypedMethod<SOURCE_TYPE>::argCount_; using TypedMethod<SOURCE_TYPE>::objSource_; using TypedMethod<SOURCE_TYPE>::source_; using TypedMethodReturn<SOURCE_TYPE,RETURN_TYPE>::returnVal_; #endif typedef ARG1_TYPE Argument1; typedef ARG2_TYPE Argument2; typedef ARG3_TYPE Argument3; typedef ARG4_TYPE Argument4; typedef ARG5_TYPE Argument5; typedef ARG6_TYPE Argument6; typedef RETURN_TYPE (SOURCE_TYPE::*MemberFunc)(ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5, ARG6_TYPE arg6); typedef TypedMethodArg6Return<SOURCE_TYPE,RETURN_TYPE,ARG1_TYPE, ARG2_TYPE,ARG3_TYPE,ARG4_TYPE,ARG5_TYPE,ARG6_TYPE> TypedMethodArg6ReturnType; TypedMethodArg6Return( MemberFunc methodPtr=NULL, const String& argTypes="", SOURCE_TYPE* source=NULL ): TypedMethodReturn<SOURCE_TYPE,RETURN_TYPE>( argTypes, source ){ argCount_ = 6; methodPtr_ = methodPtr; } TypedMethodArg6Return( const TypedMethodArg6ReturnType& method ) { *this = method; } TypedMethodArg6ReturnType& operator=( const TypedMethodArg6ReturnType& rhs ) { TypedMethodReturn<SOURCE_TYPE,RETURN_TYPE>::operator =( rhs ); methodPtr_ = rhs.methodPtr_; return *this; } virtual Method* clone() { return new TypedMethodArg6ReturnType( *this ); } virtual ~TypedMethodArg6Return(){ } virtual VariantData* invoke( VariantData** arguments, Object* source=NULL ){ if ( NULL != source ) { source_ = dynamic_cast<SOURCE_TYPE*>( source ); } if ( (NULL != source_) && (NULL != methodPtr_) ){ if ( 6 == argCount_ ) { returnVal_ = (source_->*methodPtr_)( (Argument1)*(arguments[0]), (Argument2)*(arguments[1]), (Argument3)*(arguments[2]), (Argument4)*(arguments[3]), (Argument5)*(arguments[4]), (Argument6)*(arguments[5]) ); } } return &returnVal_; }protected: MemberFunc methodPtr_;};template <typename FieldType>class TypedField : public Field {public: typedef FieldType Type; typedef FieldType* TypePtr; TypedField():field_(NULL),fieldOffset_(0) { } TypedField( const String& name, ulong32 fieldOffset ):field_(NULL),fieldOffset_(fieldOffset) { setName( name ); } TypedField( const TypedField& rhs ):Field(rhs),field_(NULL),fieldOffset_(rhs.fieldOffset_) { } virtual Field* clone() { return new TypedField( *this ); } virtual ulong32 getFieldSize() { return sizeof( Type ); } virtual String getFieldTypeName() { return typeid( Type ).name(); } virtual VariantData* get( Object* source ) { if ( NULL == source ) { return NULL; } field_ = (TypePtr)(((char*)source) + fieldOffset_); val_ = *field_; return &val_; } virtual void set( Object* source, VariantData* data ) { if ( NULL == source ) { return; } field_ = (TypePtr)(((char*)source) + fieldOffset_); val_ = *data; *field_ = val_; } VariantData val_; TypePtr field_; ulong32 fieldOffset_;};/**\class TypedObjectField VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*/template <typename FieldType>class TypedObjectField : public Field {public: typedef FieldType Type; typedef FieldType* TypePtr; TypedObjectField():field_(NULL),fieldOffset_(0) { } TypedObjectField( const String& name, ulong32 fieldOffset ):field_(NULL),fieldOffset_(fieldOffset) { setName( name ); } TypedObjectField( const TypedObjectField& rhs ):Field(rhs),field_(NULL),fieldOffset_(rhs.fieldOffset_) { } virtual Field* clone() { return new TypedObjectField( *this ); } virtual ulong32 getFieldSize() { return sizeof( Type ); } virtual String getFieldTypeName() { return typeid( Type ).name(); } virtual VariantData* get( Object* source ) { if ( NULL == source ) { return NULL; } field_ = (TypePtr)(((char*)source) + fieldOffset_); val_ = *field_; return &val_; } virtual void set( Object* source, VariantData* data ) { if ( NULL == source ) { return; } field_ = (TypePtr)(((char*)source) + fieldOffset_); val_ = *data; *field_ = (Type)(Object*)val_; } VariantData val_; TypePtr field_; ulong32 fieldOffset_;};/**\class TypedInterfaceClass VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*TypedInterfaceClass documentation*/template<class INTERFACE_TYPE>class TypedInterfaceClass : public InterfaceClass {public: TypedInterfaceClass( const String& interfaceName, const String& interfaceID, const String& superInterfaceName ) : InterfaceClass( interfaceName, interfaceID, superInterfaceName ) { } virtual ~TypedInterfaceClass(){}; virtual bool compareObject( Object* object )const{ bool result = false; try { if ( typeid(*object) == typeid(INTERFACE_TYPE) ){ result = true; } } catch (...){ throw ClassNotFound(); } return result; };};/**\class TypedImplementedInterfaceClass VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*TypedImplementedInterfaceClass documentation*/template<class INTERFACE_TYPE, class IMPLEMENTER_TYPE>class TypedImplementedInterfaceClass : public ImplementedInterfaceClass {public: TypedImplementedInterfaceClass( const String& interfaceName, const String& interfaceID, const String& superInterfaceName ) : ImplementedInterfaceClass( interfaceName, interfaceID, superInterfaceName ) { } virtual ~TypedImplementedInterfaceClass(){}; virtual Object* createImplementingInstance() { return new IMPLEMENTER_TYPE(); } virtual void* createInterfaceInstance() { void* result = NULL; IMPLEMENTER_TYPE* implementerInstance = new IMPLEMENTER_TYPE(); INTERFACE_TYPE* interfaceInstance = dynamic_cast<INTERFACE_TYPE*>( implementerInstance ); result = (void*)interfaceInstance; return result; } virtual bool compareObject( Object* object )const{ bool result = false; try { if ( typeid(*object) == typeid(INTERFACE_TYPE) ){ result = true; } } catch (...){ throw ClassNotFound(); } return result; };};/**\class TypedClass VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*TypedClass represents a specific instance of a Class. The CLASS_TYPEis used to specify the Object the Class represents. So TypedClass<Rect> is*used to represent the Class for a Rect instance.**@author Jim Crafton*@version 1.0*/template <class CLASS_TYPE>class TypedClass : public Class{public: TypedClass( const String& className, const String& classID, const String& superClass ): Class( className, classID, superClass ){ }; virtual ~TypedClass(){ }; static TypedClass<CLASS_TYPE>* create(const String& className, const String& classID, const String& superClass) { TypedClass<CLASS_TYPE>* result = new TypedClass<CLASS_TYPE>(className, classID, superClass); return result; } /** *creates a new instance of type CLASS_TYPE and assigns it to the *pointer represented by the objectInstance argument. *@param Object the pointer to the newly created instance. */ virtual Object* createInstance() const { return new CLASS_TYPE(); }; virtual bool compareObject( Object* object )const{ bool result = false; try { if ( typeid(*object) == typeid(CLASS_TYPE) ){ result = true; } } catch (...){ throw ClassNotFound(); } return result; };};/**\class TypedAbstractClass VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*TypedAbstractClass is used to represent abstract classes that cannot be instantiated*due to virtual pure methods, but must be represented in the class hierarchy because*they are derived from by other child classes.**@author Jim Crafton*@version 1.0*/template <class CLASS_TYPE>class TypedAbstractClass : public Class{public: TypedAbstractClass( const String& className, const String& classID, const String& superClass ): Class( className, classID, superClass ){ }; virtual ~TypedAbstractClass(){ }; virtual Object* createInstance() const{ return NULL; //this should probably throw an exception ! }; virtual bool compareObject( Object* object )const{ bool result = false; if ( typeid(*object) == typeid(CLASS_TYPE) ){ result = true; } return result; };};/*pdUndefined = 0, pdInt, pdLong, pdShort, pdULong, pdFloat, pdChar, pdDouble, pdObject, pdBool, pdString, pdEnum, pdInterface, pdEnumMask*/static PropertyDescriptorType getDescriptor( const std::type_info& typeInfo ){ PropertyDescriptorType result = pdUndefined; String typeName = StringUtils::toString(typeInfo);/*#ifdef WIN32 //don't know if we really need this here //strip out the preceding "class" or "enum" or whatever std::string::size_type idx = typeName.find( " " ); if ( idx != typeName.npos ) { typeName = typeName.substr( idx+1 ); }#endif*/ if ( typeName.find( "basic_string" ) != String::npos ) { result = pdString; } else if ( typeName.find( "UnicodeString" ) != String::npos ) { result = pdString; } else if ( typeName.find( "AnsiString" ) != String::npos ) { result = pdString; } else if ( typeName.find( "int" ) != String::npos ) { result = pdInt; } else if ( typeName.find( "unsigned" ) != String::npos ) { if ( typeName.find( "long" ) != String::npos ) { result = pdULong; } else if ( typeName.find( "int" ) != String::npos ) { result = pdUInt; } else if ( typeName.find( "short" ) != String::npos ) { result = pdUShort; } else if ( typeName.find( "char" ) != String::npos ) { result = pdChar; } } else if ( typeName.find( "long" ) != String::npos ) { result = pdLong; } else if ( typeName.find( "short" ) != String::npos ) { result = pdShort; } else if ( typeName.find( "char" ) != String::npos ) { result = pdChar; } else if ( typeName.find( "double" ) != String::npos ) { result = pdDouble; } else if ( typeName.find( "float" ) != String::npos ) { result = pdFloat; } else if ( typeName.find( "bool" ) != String::npos ) { result = pdBool; } else if ( !typeName.empty() ) { result = pdObject; } return result;}/***this function registers a property with a class, where the PROPERTY_TYPE is defined as some*type like int, double, bool, Object*, etc.**@param PROPERTY_TYPE initialValue is used partly for an initial value for the*property, but mainly to make sure thr template func
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?