vcfrttiimpl.h
来自「这是VCF框架的代码」· C头文件 代码 · 共 2,696 行 · 第 1/5 页
H
2,696 行
catch ( PropertyChangeException ){ //do not call the set method //re-throw the exception ? } } else { (source->*setFunction_)( *value ); } } };protected: GetFunction getFunction_; SetFunction setFunction_;};/**\class TypeDefProperty VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*/template <class PROPERTY>class TypeDefProperty : public TypedProperty<PROPERTY> {public: TypeDefProperty( _typename_ TypedProperty<PROPERTY>::GetFunction propGetFunction, const PropertyDescriptorType& propertyType, const String& typeDefClassName ): TypedProperty<PROPERTY>( propGetFunction, propertyType ) { typeDefClassName_ = typeDefClassName; } TypeDefProperty( _typename_ TypedProperty<PROPERTY>::GetFunction propGetFunction, _typename_ TypedProperty<PROPERTY>::SetFunction propSetFunction, const PropertyDescriptorType& propertyType, const String& typeDefClassName ): TypedProperty<PROPERTY>( propGetFunction, propSetFunction, propertyType ) { typeDefClassName_ = typeDefClassName; } TypeDefProperty( const TypeDefProperty<PROPERTY>& prop ): TypedProperty<PROPERTY>( prop ){ typeDefClassName_ = prop.typeDefClassName_; }; virtual ~TypeDefProperty(){}; virtual String getTypeClassName() { return typeDefClassName_; } virtual Property* clone(){ return new TypeDefProperty<PROPERTY>(*this); };protected: String typeDefClassName_;};template <class PROPERTY>class TypedObjectProperty : public Property {public: typedef PROPERTY* (Object::*GetFunction)(void); typedef void (Object::*SetFunction)( PROPERTY* ); TypedObjectProperty( GetFunction propGetFunction ){ init(); getFunction_ = propGetFunction; setType( pdObject ); isReadOnly_ = true; }; TypedObjectProperty( GetFunction propGetFunction, SetFunction propSetFunction ){ init(); getFunction_ = propGetFunction; setFunction_ = propSetFunction; setType( pdObject ); }; TypedObjectProperty( const TypedObjectProperty<PROPERTY>& prop ): Property( prop ){ init(); getFunction_ = prop.getFunction_; setFunction_ = prop.setFunction_; }; virtual ~TypedObjectProperty(){}; virtual String getTypeClassName() { return StringUtils::getClassNameFromTypeInfo( typeid(PROPERTY) ); } virtual Property* clone(){ return new TypedObjectProperty<PROPERTY>(*this); }; void init(){ getFunction_ = NULL; setFunction_ = NULL; setType( pdObject ); }; virtual VariantData* get( Object* source ){ if ( (NULL != getFunction_) && (NULL != source) ){ PROPERTY* propVal = (source->*getFunction_)(); if ( NULL != propVal ) { value_ = dynamic_cast<Object*>( propVal ); } else { value_ = NULL; } value_.type = getType(); return &value_; } else { return NULL; } }; void set( Object* source, VariantData* value ){ if ( (NULL != setFunction_) && (NULL != source) ){ Object* object = *value; PROPERTY* propVal = NULL; if ( NULL != object ) { propVal = dynamic_cast<PROPERTY*>(object); } if ( true == isBound() ){ VariantData* originalValue = get( source ); PropertyChangeEvent changeEvent( source, originalValue, value ); try { PropertyChanged.fireEvent( &changeEvent ); (source->*setFunction_)( propVal ); } catch ( PropertyChangeException ){ //do not call the set method //re-throw the exception ? } } else { (source->*setFunction_)( propVal ); } } };protected: GetFunction getFunction_; SetFunction setFunction_;};/**\class TypedObjectRefProperty VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*/template <class PROPERTY>class TypedObjectRefProperty : public Property {public: typedef PROPERTY& (Object::*GetFunction)(void); typedef void (Object::*SetFunction)( const PROPERTY& ); TypedObjectRefProperty( GetFunction propGetFunction ){ init(); getFunction_ = propGetFunction; setType( pdObject ); isReadOnly_ = true; }; TypedObjectRefProperty( GetFunction propGetFunction, SetFunction propSetFunction ){ init(); getFunction_ = propGetFunction; setFunction_ = propSetFunction; setType( pdObject ); }; TypedObjectRefProperty( const TypedObjectProperty<PROPERTY>& prop ): Property( prop ){ init(); getFunction_ = prop.getFunction_; setFunction_ = prop.setFunction_; }; virtual ~TypedObjectRefProperty(){}; virtual String getTypeClassName() { return StringUtils::getClassNameFromTypeInfo( typeid(PROPERTY) ); } virtual Property* clone(){ return new TypedObjectRefProperty<PROPERTY>(*this); }; void init(){ getFunction_ = NULL; setFunction_ = NULL; setType( pdObject ); }; virtual VariantData* get( Object* source ){ if ( (NULL != getFunction_) && (NULL != source) ){ value_ = (source->*getFunction_)(); value_.type = getType(); return &value_; } else { return NULL; } }; void set( Object* source, VariantData* value ){ if ( (NULL != setFunction_) ){ Object* object = *value; if ( true == isBound() ){ VariantData* originalValue = get( source ); PropertyChangeEvent changeEvent( source, originalValue, value ); try { PropertyChanged.fireEvent( &changeEvent ); (source->*setFunction_)( (PROPERTY&)*object ); } catch ( PropertyChangeException ){ //do not call the set method //re-throw the exception ? } } else { (source->*setFunction_)( (PROPERTY&)*object ); } } };protected: GetFunction getFunction_; SetFunction setFunction_;};/**\class TypedEnumProperty VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*/template <class ENUM_PROPERTY>class TypedEnumProperty : public Property {public: typedef ENUM_PROPERTY (Object::*GetFunction)(void); typedef void (Object::*SetFunction)( const ENUM_PROPERTY& ); TypedEnumProperty( GetFunction propGetFunction, const ENUM_PROPERTY& lower, const ENUM_PROPERTY& upper ){ init(); getFunction_ = propGetFunction; enum_ = new TypedEnum<ENUM_PROPERTY>(lower,upper); lower_ = lower; upper_ = upper; setType( pdEnum ); isReadOnly_ = true; }; TypedEnumProperty( GetFunction propGetFunction, SetFunction propSetFunction, const ENUM_PROPERTY& lower, const ENUM_PROPERTY& upper ){ init(); lower_ = lower; upper_ = upper; getFunction_ = propGetFunction; setFunction_ = propSetFunction; enum_ = new TypedEnum<ENUM_PROPERTY>(lower,upper); setType( pdEnum ); }; TypedEnumProperty( GetFunction propGetFunction, SetFunction propSetFunction, const ENUM_PROPERTY& lower, const ENUM_PROPERTY& upper, const unsigned long& enumNameCount, String* enumNames ){ init(); lower_ = lower; upper_ = upper; getFunction_ = propGetFunction; setFunction_ = propSetFunction; enumNameCount_ = enumNameCount; enumNames_ = enumNames; enum_ = new TypedEnum<ENUM_PROPERTY>(lower,upper, enumNameCount, enumNames ); setType( pdEnum ); }; TypedEnumProperty( const TypedEnumProperty<ENUM_PROPERTY>& prop ): Property( prop ){ init(); getFunction_ = prop.getFunction_; setFunction_ = prop.setFunction_; enumNameCount_ = prop.enumNameCount_; enumNames_ = prop.enumNames_; lower_ = prop.lower_; upper_ = prop.upper_; if ( 0 < enumNameCount_ ){ enum_ = new TypedEnum<ENUM_PROPERTY>( lower_,upper_, enumNameCount_, enumNames_ ); } else{ enum_ = new TypedEnum<ENUM_PROPERTY>( lower_,upper_ ); } setType( pdEnum ); setName( prop.getName() ); setDisplayName( prop.getDisplayName() ); setDescription( prop.getDescription() ); }; virtual ~TypedEnumProperty(){ delete enum_; }; virtual String getTypeClassName() { return StringUtils::getClassNameFromTypeInfo( typeid(ENUM_PROPERTY) ); } virtual Property* clone(){ return new TypedEnumProperty<ENUM_PROPERTY>(*this); }; void init(){ getFunction_ = NULL; setFunction_ = NULL; setType( pdEnum ); enumNameCount_ = 0; }; virtual VariantData* get( Object* source ){ if ( (NULL != getFunction_) && (NULL != source) ){ enum_->set( (source->*getFunction_)() ); value_ = enum_; value_.type = getType(); return &value_; } else { return NULL; } }; virtual void set( Object* source, VariantData* value ){ if ( (NULL != setFunction_) && (NULL != source) ){ Enum* e = *value; ENUM_PROPERTY enumVal = (ENUM_PROPERTY)e->get(); if ( true == isBound() ){ VariantData* originalValue = get( source ); PropertyChangeEvent changeEvent( source, originalValue, value ); try { PropertyChanged.fireEvent( &changeEvent ); (source->*setFunction_)( enumVal ); } catch ( PropertyChangeException ){ //do not call the set method //re-throw the exception ? } } else { (source->*setFunction_)( enumVal ); } } };protected: GetFunction getFunction_; SetFunction setFunction_; TypedEnum<ENUM_PROPERTY>* enum_; ENUM_PROPERTY lower_; ENUM_PROPERTY upper_; unsigned long enumNameCount_; String* enumNames_;};/**\class TypedCollectionProperty VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*TypedCollectionProperty represents a type safe wrapper around properties that*are enumerations of items.*/template <class ITEM_TYPE>class TypedCollectionProperty : public Property {public: typedef Enumerator<ITEM_TYPE>* (Object::*GetFunction)(void); typedef void (Object::*AddFunction)( ITEM_TYPE ); typedef void (Object::*InsertFunction)( const unsigned long&, ITEM_TYPE ); typedef void (Object::*DeleteFunction1)( ITEM_TYPE ); typedef void (Object::*DeleteFunction2)( const unsigned long& ); TypedCollectionProperty( GetFunction getFunc, AddFunction addFunc, InsertFunction insertFunc, DeleteFunction1 deleteFunc1, DeleteFunction2 deleteFunc2, const PropertyDescriptorType& propertyType ){ init(); getFunction_ = getFunc; addFunc_ = addFunc; insertFunc_ = insertFunc; deleteFunc1_ = deleteFunc1; deleteFunc2_ = deleteFunc2; setType( propertyType ); }; TypedCollectionProperty( const TypedCollectionProperty<ITEM_TYPE>& prop ): Property( prop ){ init(); getFunction_ = prop.getFunction_; enumeration_ = prop.enumeration_; addFunc_ = prop.addFunc_; insertFunc_ = prop.insertFunc_; deleteFunc1_ = prop.deleteFunc1_; deleteFunc2_ = prop.deleteFunc2_; }; void init(){ getFunction_ = NULL; isCollection_ = true; enumeration_ = NULL; isReadOnly_ = true; addFunc_ = NULL; insertFunc_ = NULL; deleteFunc1_ = NULL; deleteFunc2_ = NULL; }; virtual ~TypedCollectionProperty(){}; virtual String getTypeClassName() { return StringUtils::getClassNameFromTypeInfo( typeid(ITEM_TYPE) ); } virtual VariantData* get( Object* source ){ return NULL; }; virtual void set( Object* source, VariantData* value ){ //no-op }; virtual bool hasMoreElements( Object* source ){ if ( NULL != enumeration_ ){ return enumeration_->hasMoreElements(); } else { return false; } }; virtual VariantData* nextElement( Object* source ){ VariantData* element = NULL; if ( NULL != enumeration_ ){ if ( true == enumeration_->hasMoreElements() ){ value_ = enumeration_->nextElement(); element = &value_; } } return element; }; virtual void startCollection( Object* source ){ enumeration_ = NULL; if ( NULL != source ){ enumeration_ = (source->*getFunction_)(); } }; virtual Property* clone(){ return new TypedCollectionProperty<ITEM_TYPE>(*this); }; virtual void add( Object* source, VariantData* value ){ if ( (NULL != value) && (NULL != addFunc_) ){ ITEM_TYPE valToAdd = (ITEM_TYPE)(*value); (source->*addFunc_)( valToAdd ); } }; virtual void insert( Object* source, const unsigned long& index, VariantData* value ){ if ( (NULL != value) && (NULL != source) && (NULL != insertFunc_) ){ ITEM_TYPE valToInsert = (ITEM_TYPE)(*value); (source->*insertFunc_)( index, valToInsert ); } }; virtual void remove( Object* source, VariantData* value ){ if ( (NULL != value) && (NULL != source) && (NULL != deleteFunc1_) ){ ITEM_TYPE valToRemove = (ITEM_TYPE)(*value); (source->*deleteFunc1_)( valToRemove ); } }; virtual void remove( Object* source, const unsigned long& index ){ if ( (NULL != source) && (NULL != deleteFunc2_) ){ (source->*deleteFunc2_)( index ); } }; virtual bool collectionSupportsEditing(){ if ( NULL != enumeration_ ){ return enumeration_->supportsEditing(); } else{ return false; } };private: GetFunction getFunction_; Enumerator<ITEM_TYPE>* enumeration_; AddFunction addFunc_; InsertFunction insertFunc_; DeleteFunction1 deleteFunc1_; DeleteFunction2 deleteFunc2_;};/**\class TypedObjectCollectionProperty VCFRTTIImpl.h "vcf/FoundationKit/VCFRTTIImpl.h"*TypedCollectionProperty represents a type safe wrapper around properties that*are enumerations of Object* derived items.*/template <class ITEM_TYPE>class TypedObjectCollectionProperty : public Property {public: typedef Enumerator<ITEM_TYPE>* (Object::*GetFunction)(void); typedef void (Object::*AddFunction)( ITEM_TYPE ); typedef void (Object::*InsertFunction)( const unsigned long&, ITEM_TYPE ); typedef void (Object::*DeleteFunction1)( ITEM_TYPE ); typedef void (Object::*DeleteFunction2)( const unsigned long& ); TypedObjectCollectionProperty( GetFunction getFunc, AddFunction addFunc, InsertFunction insertFunc, DeleteFunction1 deleteFunc1, DeleteFunction2 deleteFunc2 ){ init(); getFunction_ = getFunc; addFunc_ = addFunc; insertFunc_ = insertFunc; deleteFunc1_ = deleteFunc1; deleteFunc2_ = deleteFunc2; }; TypedObjectCollectionProperty( const TypedObjectCollectionProperty& prop ): Property( prop ){ init(); getFunction_ = prop.getFunction_; enumeration_ = prop.enumeration_; addFunc_ = prop.addFunc_; insertFunc_ = prop.insertFunc_;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?