00001 #ifndef property_h
00002 #define property_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "propertyref.h"
00017 #include "factory.h"
00018
00019 class PropertySet;
00020
00021
00030 mClass Property
00031 {
00032 public:
00033
00034 Property( const PropertyRef& pr )
00035 : ref_(pr) {}
00036 virtual ~Property() {}
00037
00038 inline const PropertyRef& ref() const { return ref_; }
00039 const char* name() const;
00040
00041 virtual bool init(const PropertySet&) const { return true; }
00043 virtual const char* errMsg() const { return 0; }
00044
00045 virtual bool isUdf() const = 0;
00046 virtual bool dependsOn(const Property&) const { return false; }
00047
00048 virtual const char* type() const = 0;
00049 virtual const char* def() const = 0;
00050 virtual void setDef(const char*) = 0;
00051 mDefineFactory1ParamInClass(Property,const PropertyRef&,factory);
00052
00053 mClass EvalOpts
00054 {
00055 public:
00056 EvalOpts( bool avg=false, float relpos=0 )
00057 : average_(avg)
00058 , relpos_(relpos) {}
00059 bool average_;
00060 float relpos_;
00061 };
00062 virtual float value(EvalOpts eo=EvalOpts()) const = 0;
00063
00064 protected:
00065
00066 const PropertyRef& ref_;
00067
00068 };
00069
00070
00071 #define mDefPropertyFns(clss,typstr) \
00072 static const char* typeStr() { return typstr; } \
00073 virtual const char* type() const { return typeStr(); } \
00074 virtual const char* factoryKeyword() const { return type(); } \
00075 static Property* create( const PropertyRef& r ) { return new clss(r); } \
00076 static void initClass() { factory().addCreator(create,typeStr());} \
00077 virtual const char* def() const; \
00078 virtual void setDef(const char*); \
00079 virtual bool isUdf() const; \
00080 virtual float value(EvalOpts eo=EvalOpts()) const
00081
00082
00083 mClass PropertySet
00084 {
00085 public:
00086
00087 PropertySet() {}
00088 PropertySet(const PropertyRefSelection&);
00090 virtual ~PropertySet() { erase(); }
00091
00092 inline int size() const { return props_.size(); }
00093 inline bool isEmpty() const { return props_.isEmpty(); }
00094 int indexOf(const char*,bool matchaliases=false) const;
00095 inline bool isPresent( const char* nm, bool ma=false ) const
00096 { return indexOf(nm,ma) >= 0; }
00097 Property& get( int idx ) { return *props_[idx]; }
00098 const Property& get( int idx ) const { return *props_[idx]; }
00099 inline const Property* find( const char* nm, bool ma=false ) const
00100 { return fnd(nm,ma); }
00101 inline Property* find( const char* nm, bool ma=false )
00102 { return fnd(nm,ma); }
00103 int indexOf( const PropertyRef& pr ) const
00104 { return indexOf(pr.name()); }
00105 int indexOf(PropertyRef::StdType,int occ=0) const;
00106
00107 bool add(Property*);
00108 int set(Property*);
00109 void remove(int);
00110 void replace(int,Property*);
00111 void erase() { deepErase(props_); }
00112
00113 bool prepareUsage() const;
00114 inline const char* errMsg() const { return errmsg_; }
00115
00116
00117 protected:
00118
00119 ObjectSet<Property> props_;
00120 mutable BufferString errmsg_;
00121
00122 Property* fnd(const char*,bool) const;
00123
00124 };
00125
00126
00127 #endif