00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_PROPERTY_HPP
00017 #define TORC_GENERIC_OM_PROPERTY_HPP
00018
00019 #include "torc/generic/om/PointerTypes.hpp"
00020 #include "torc/generic/om/DumpRestoreConfig.hpp"
00021
00022
00023 #ifdef GENOM_SERIALIZATION
00024 #include <boost/serialization/access.hpp>
00025 #endif //GENOM_SERIALIZATION
00026
00027 #include "torc/generic/om/Commentable.hpp"
00028 #include "torc/generic/util/Error.hpp"
00029 #include "torc/generic/om/FactoryType.hpp"
00030 #include "torc/generic/om/Nameable.hpp"
00031 #include "torc/generic/om/Renamable.hpp"
00032 #include "torc/generic/om/SelfReferencing.hpp"
00033 #include "torc/generic/om/SymTab.hpp"
00034 #include "torc/generic/om/Unit.hpp"
00035 #include "torc/generic/om/Value.hpp"
00036 #include "torc/generic/om/VisitorType.hpp"
00037 #include "torc/generic/om/Visitable.hpp"
00038 #include "torc/generic/om/PropertyContainer.hpp"
00039 #include <boost/shared_ptr.hpp>
00040
00041 namespace torc { namespace generic { class BaseVisitor; } }
00042
00043 namespace torc {
00044
00045 namespace generic {
00046
00047
00048
00049
00050 class Property :
00051 public Commentable,
00052 public Nameable,
00053 public Renamable,
00054 public SelfReferencing<Property>,
00055 public Visitable
00056 {
00057 #ifdef GENOM_SERIALIZATION
00058 friend class boost::serialization::access;
00059 #endif
00060
00061 friend class FactoryType<Property>;
00062
00063 public:
00064
00065 typedef VisitorType<Property> Visitor;
00066
00067
00068
00069
00070 class Factory: public FactoryType<Property>
00071 {
00072 public:
00073 using FactoryType<Property>::create;
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 inline PropertySharedPtr
00085 virtual newPropertyPtr( const std::string &inName,
00086 const PropertyContainerSharedPtr &inContainer,
00087 const Value &inValue,
00088 const Unit &inUnit = eUnitUndefined,
00089 const PropertySharedPtr &inParentProperty = PropertySharedPtr(),
00090 const std::string &inOriginalName = std::string()) throw(Error);
00091 };
00092
00093 virtual void
00094 accept(BaseVisitor & inoutVisitor) throw(Error);
00095
00096 virtual
00097 ~Property() throw();
00098
00099
00100
00101
00102
00103
00104 inline const Value
00105 getValue() const throw();
00106
00107
00108
00109
00110
00111
00112 void
00113 setValue(const Value & inSource) throw();
00114
00115
00116
00117
00118
00119
00120 inline const Unit
00121 getUnit() const throw();
00122
00123
00124
00125
00126
00127
00128 void
00129 setUnit(const Unit & inSource) throw();
00130
00131
00132
00133
00134
00135
00136 inline const std::string
00137 getOwner() const throw();
00138
00139
00140
00141
00142
00143
00144 void
00145 setOwner(const std::string & inSource) throw();
00146
00147
00148
00149
00150
00151
00152 inline void
00153 getChildren(
00154 std::map< std::string,
00155 PropertySharedPtr > &outValues) const throw();
00156
00157
00158
00159
00160
00161
00162 template<typename _Action>
00163 inline void
00164 applyOnAllChildren( const _Action &action ) throw(Error);
00165
00166
00167
00168
00169
00170
00171 void
00172 setChildren(const std::map< std::string,
00173 PropertySharedPtr > & inSource) throw();
00174
00175
00176
00177
00178
00179
00180
00181 bool
00182 addChildProperty(const std::string &inName,
00183 const PropertySharedPtr &inProperty) throw();
00184
00185 protected:
00186 Property();
00187
00188 private:
00189 #ifdef GENOM_SERIALIZATION
00190 template<class Archive> void
00191 serialize( Archive &ar, unsigned int );
00192 #endif //GENOM_SERIALIZATION
00193
00194 std::string mOwner;
00195 Unit mUnit;
00196 Value mValue;
00197 SymTab<std::string, PropertySharedPtr > mChildren;
00198 };
00199
00200
00201
00202
00203
00204
00205 inline const Value
00206 Property::getValue() const throw() {
00207 return mValue;
00208 }
00209
00210
00211
00212
00213
00214
00215 inline const Unit
00216 Property::getUnit() const throw() {
00217 return mUnit;
00218 }
00219
00220
00221
00222
00223
00224
00225 inline const std::string
00226 Property::getOwner() const throw() {
00227 return mOwner;
00228 }
00229
00230
00231
00232
00233
00234
00235 inline void
00236 Property::getChildren(
00237 std::map< std::string, PropertySharedPtr > &outValues) const throw() {
00238 mChildren.getValueMap( outValues );
00239 }
00240
00241 template<typename _Action>
00242 inline void
00243 Property::applyOnAllChildren( const _Action &action ) throw(Error)
00244 {
00245 try
00246 {
00247 mChildren.applyOnAll( action );
00248 }
00249 catch(Error &e)
00250 {
00251 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00252 throw;
00253 }
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 inline PropertySharedPtr
00268 Property::Factory::newPropertyPtr( const std::string &inName,
00269 const PropertyContainerSharedPtr &inContainer,
00270 const Value &inValue,
00271 const Unit &inUnit,
00272 const PropertySharedPtr &inParentProperty,
00273 const std::string &inOriginalName ) throw(Error) {
00274 try
00275 {
00276 PropertySharedPtr newProperty;
00277 create( newProperty );
00278 newProperty->setName( inName );
00279 newProperty->setValue( inValue );
00280 newProperty->setUnit( inUnit );
00281 newProperty->setOriginalName( inOriginalName );
00282 if( inParentProperty )
00283 {
00284 inParentProperty->addChildProperty( inName, newProperty );
00285 }
00286 else
00287 {
00288 inContainer->setProperty( inName, newProperty );
00289 }
00290 return newProperty;
00291 }
00292 catch( Error &e )
00293 {
00294 e.setCurrentLocation(
00295 __FUNCTION__, __FILE__, __LINE__ );
00296 throw;
00297 }
00298 }
00299 }
00300
00301 }
00302 #endif // TORC_GENERIC_OM_PROPERTY_HPP