00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef APP_PROPERTYCONTAINER_H
00025 #define APP_PROPERTYCONTAINER_H
00026
00027 #include <map>
00028 #include <Base/Persistence.h>
00029
00030 namespace Base {
00031 class Writer;
00032 }
00033
00034
00035 namespace App
00036 {
00037 class Property;
00038 class PropertyContainer;
00039 class DocumentObject;
00040
00041 enum PropertyType
00042 {
00043 Prop_None = 0,
00044 Prop_ReadOnly = 1,
00045 Prop_Transient= 2,
00046 Prop_Hidden = 4,
00047 Prop_Output = 8
00048 };
00049
00050 struct AppExport PropertyData
00051 {
00052 struct PropertySpec
00053 {
00054 const char* Name;
00055 const char * Group;
00056 const char * Docu;
00057 short Offset,Type;
00058 };
00059
00060 std::vector<PropertySpec> propertyData;
00061 const PropertyData *parentPropertyData;
00062
00063 void addProperty(const PropertyContainer *container,const char* PropName, Property *Prop, const char* PropertyGroup= 0, PropertyType = Prop_None, const char* PropertyDocu= 0 );
00064
00065 const PropertySpec *findProperty(const PropertyContainer *container,const char* PropName) const;
00066 const PropertySpec *findProperty(const PropertyContainer *container,const Property* prop) const;
00067
00068 const char* getName (const PropertyContainer *container,const Property* prop) const;
00069 short getType (const PropertyContainer *container,const Property* prop) const;
00070 short getType (const PropertyContainer *container,const char* name) const;
00071 const char* getGroup (const PropertyContainer *container,const char* name) const;
00072 const char* getGroup (const PropertyContainer *container,const Property* prop) const;
00073 const char* getDocumentation(const PropertyContainer *container,const char* name) const;
00074 const char* getDocumentation(const PropertyContainer *container,const Property* prop) const;
00075
00076 Property *getPropertyByName(const PropertyContainer *container,const char* name) const;
00077 void getPropertyMap(const PropertyContainer *container,std::map<std::string,Property*> &Map) const;
00078 void getPropertyList(const PropertyContainer *container,std::vector<Property*> &List) const;
00079 };
00080
00081
00084 class AppExport PropertyContainer: public Base::Persistence
00085 {
00086
00087 TYPESYSTEM_HEADER();
00088
00089 public:
00094 PropertyContainer();
00095
00100 virtual ~PropertyContainer();
00101
00102 virtual unsigned int getMemSize (void) const;
00103
00105 virtual Property *getPropertyByName(const char* name) const;
00107 virtual const char* getName(const Property* prop) const;
00109 virtual void getPropertyMap(std::map<std::string,Property*> &Map) const;
00111 virtual void getPropertyList(std::vector<Property*> &List) const;
00113 void setPropertyStatus(unsigned char bit,bool value);
00114
00116 virtual short getPropertyType(const Property* prop) const;
00118 virtual short getPropertyType(const char *name) const;
00120 virtual const char* getPropertyGroup(const Property* prop) const;
00122 virtual const char* getPropertyGroup(const char *name) const;
00124 virtual const char* getPropertyDocumentation(const Property* prop) const;
00126 virtual const char* getPropertyDocumentation(const char *name) const;
00128 virtual bool isReadOnly(const Property* prop) const;
00130 virtual bool isReadOnly(const char *name) const;
00132 virtual bool isHidden(const Property* prop) const;
00134 virtual bool isHidden(const char *name) const;
00135 virtual App::Property* addDynamicProperty(
00136 const char* type, const char* name=0,
00137 const char* group=0, const char* doc=0,
00138 short attr=0, bool ro=false, bool hidden=false){
00139 return 0;
00140 }
00141 virtual std::vector<std::string> getDynamicPropertyNames() const {
00142 return std::vector<std::string>();
00143 }
00144 virtual App::Property *getDynamicPropertyByName(const char* name) const {
00145 return 0;
00146 }
00147 virtual void addDynamicProperties(const PropertyContainer*) {
00148 }
00149
00150 virtual void Save (Base::Writer &writer) const;
00151 virtual void Restore(Base::XMLReader &reader);
00152
00153
00154 friend class Property;
00155
00156
00157 protected:
00159 virtual void onChanged(const Property* ){};
00161 virtual void onBeforeChange(const Property* ){};
00162
00163
00164 static const PropertyData * getPropertyDataPtr(void);
00165 virtual const PropertyData& getPropertyData(void) const;
00166
00167 private:
00168
00169 PropertyContainer(const PropertyContainer&);
00170 PropertyContainer& operator = (const PropertyContainer&);
00171
00172 private:
00173 static PropertyData propertyData;
00174 };
00175
00177 #define ADD_PROPERTY(_prop_, _defaultval_) \
00178 do { \
00179 this->_prop_.setValue _defaultval_;\
00180 this->_prop_.setContainer(this); \
00181 propertyData.addProperty(this, #_prop_, &this->_prop_); \
00182 } while (0)
00183
00184 #define ADD_PROPERTY_TYPE(_prop_, _defaultval_, _group_,_type_,_Docu_) \
00185 do { \
00186 this->_prop_.setValue _defaultval_;\
00187 this->_prop_.setContainer(this); \
00188 propertyData.addProperty(this, #_prop_, &this->_prop_, (_group_),(_type_),(_Docu_)); \
00189 } while (0)
00190
00191
00192
00193 #define PROPERTY_HEADER(_class_) \
00194 TYPESYSTEM_HEADER(); \
00195 protected: \
00196 static const App::PropertyData * getPropertyDataPtr(void); \
00197 virtual const App::PropertyData &getPropertyData(void) const; \
00198 private: \
00199 static App::PropertyData propertyData
00200
00202 #define PROPERTY_SOURCE(_class_, _parentclass_) \
00203 TYPESYSTEM_SOURCE_P(_class_);\
00204 const App::PropertyData * _class_::getPropertyDataPtr(void){return &propertyData;} \
00205 const App::PropertyData & _class_::getPropertyData(void) const{return propertyData;} \
00206 App::PropertyData _class_::propertyData; \
00207 void _class_::init(void){\
00208 initSubclass(_class_::classTypeId, #_class_ , #_parentclass_, &(_class_::create) ); \
00209 _class_::propertyData.parentPropertyData = _parentclass_::getPropertyDataPtr();\
00210 }
00211
00212 #define PROPERTY_SOURCE_ABSTRACT(_class_, _parentclass_) \
00213 TYPESYSTEM_SOURCE_ABSTRACT_P(_class_);\
00214 const App::PropertyData * _class_::getPropertyDataPtr(void){return &propertyData;} \
00215 const App::PropertyData & _class_::getPropertyData(void) const{return propertyData;} \
00216 App::PropertyData _class_::propertyData; \
00217 void _class_::init(void){\
00218 initSubclass(_class_::classTypeId, #_class_ , #_parentclass_, &(_class_::create) ); \
00219 _class_::propertyData.parentPropertyData = _parentclass_::getPropertyDataPtr();\
00220 }
00221
00222 #define TYPESYSTEM_SOURCE_TEMPLATE(_class_) \
00223 template<> Base::Type _class_::getClassTypeId(void) { return _class_::classTypeId; } \
00224 template<> Base::Type _class_::getTypeId(void) const { return _class_::classTypeId; } \
00225 template<> Base::Type _class_::classTypeId = Base::Type::badType(); \
00226 template<> void * _class_::create(void){\
00227 return new _class_ ();\
00228 }
00229
00230 #define PROPERTY_SOURCE_TEMPLATE(_class_, _parentclass_) \
00231 TYPESYSTEM_SOURCE_TEMPLATE(_class_);\
00232 template<> const App::PropertyData * _class_::getPropertyDataPtr(void){return &propertyData;} \
00233 template<> const App::PropertyData & _class_::getPropertyData(void) const{return propertyData;} \
00234 template<> App::PropertyData _class_::propertyData = App::PropertyData(); \
00235 template<> void _class_::init(void){\
00236 initSubclass(_class_::classTypeId, #_class_ , #_parentclass_, &(_class_::create) ); \
00237 _class_::propertyData.parentPropertyData = _parentclass_::getPropertyDataPtr();\
00238 }
00239
00240
00241 }
00242
00243 #endif // APP_PROPERTYCONTAINER_H