00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_CONCEPT_PROPERTY_H
00008 #define BALL_CONCEPT_PROPERTY_H
00009
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013
00014 #ifndef BALL_DATATYPE_BITVECTOR_H
00015 # include <BALL/DATATYPE/bitVector.h>
00016 #endif
00017
00018 #ifndef BALL_CONCEPT_PERSISTENTOBJECT_H
00019 # include <BALL/CONCEPT/persistentObject.h>
00020 #endif
00021
00022 #include <iostream>
00023
00024 #include <boost/shared_ptr.hpp>
00025 #include <boost/any.hpp>
00026
00027 namespace BALL
00028 {
00029
00034
00038 class BALL_EXPORT NamedProperty
00039 : public PersistentObject
00040 {
00041 public:
00042
00043 BALL_CREATE(NamedProperty)
00044
00045
00051 enum Type
00052 {
00056 BOOL,
00057
00060 INT,
00061
00065 UNSIGNED_INT,
00066
00069 FLOAT,
00070
00073 DOUBLE,
00074
00078 STRING,
00079
00084 OBJECT,
00085
00091 NONE,
00092
00097 SMART_OBJECT
00098 };
00099
00101
00104
00105
00106
00107 NamedProperty();
00108
00115 NamedProperty(const string& name);
00116
00123 NamedProperty(const string& name, bool value);
00124
00131 NamedProperty(const string& name, int value);
00132
00139 NamedProperty(const string& name, unsigned int value);
00140
00147 NamedProperty(const string& name, float value);
00148
00155 NamedProperty(const string& name, double value);
00156
00164 NamedProperty(const string& name, const string& str);
00165
00173 NamedProperty(const string& name, PersistentObject& po);
00174
00182 NamedProperty(const string& name, boost::shared_ptr<PersistentObject>& po);
00183
00186 NamedProperty(const NamedProperty&);
00187
00192 ~NamedProperty();
00193
00196 virtual void clear();
00197
00199
00202
00205 virtual void persistentWrite(PersistenceManager& pm, const char* name = "") const
00206 throw(Exception::GeneralException);
00207
00210 virtual void persistentRead(PersistenceManager& pm)
00211 throw(Exception::GeneralException);
00212
00214
00217
00219 Type getType() const;
00220
00222 string getName() const;
00223
00228 bool getBool() const;
00229
00234 int getInt() const;
00235
00240 float getFloat() const;
00241
00246 double getDouble() const;
00247
00252 unsigned int getUnsignedInt() const;
00253
00258 PersistentObject* getObject() const;
00259
00264 boost::shared_ptr<PersistentObject> getSmartObject() const;
00265
00270 string getString() const;
00271
00273
00276
00280 bool operator == (const NamedProperty& np) const;
00281
00285 bool operator != (const NamedProperty& np) const;
00286
00288 void operator = (const NamedProperty& np);
00289
00291
00292 private:
00293
00294
00295
00296 Type type_;
00297
00298
00299
00300 string name_;
00301
00302
00303
00304 boost::any data_;
00305
00306 };
00307
00332 class BALL_EXPORT PropertyManager
00333 {
00334 public:
00335
00336 BALL_CREATE(PropertyManager)
00337
00338
00340
00341 BALL_INLINE
00342
00344 PropertyManager();
00345
00346 BALL_INLINE
00348 PropertyManager(const PropertyManager& property_manager);
00349
00351 virtual ~PropertyManager();
00352
00354 virtual void clear();
00355
00357 virtual void destroy();
00358
00360
00363
00367 void set(const PropertyManager& property_manager);
00368
00375 const PropertyManager& operator = (const PropertyManager& property_manager);
00376
00382 void get(PropertyManager& property_manager) const;
00383
00387 void swap(PropertyManager& property_manager);
00388
00390
00393
00400 BitVector& getBitVector();
00401
00408 const BitVector& getBitVector() const;
00409
00411
00414
00421 operator BitVector& ();
00422
00424
00427
00433 void setProperty(Property property);
00434
00440 void clearProperty(Property property);
00441
00447 void toggleProperty(Property property);
00448
00454 Size countProperties() const;
00455
00457
00466
00469 const NamedProperty& getNamedProperty(Position index) const
00470 throw(Exception::IndexOverflow);
00471
00474 NamedProperty& getNamedProperty(Position index)
00475 throw(Exception::IndexOverflow);
00476
00484 void setProperty(const NamedProperty& property);
00485
00492 void setProperty(const string& name);
00493
00501 void setProperty(const string& name, bool value);
00502
00510 void setProperty(const string& name, int value);
00511
00519 void setProperty(const string& name, unsigned int value);
00520
00528 void setProperty(const string& name, float value);
00529
00537 void setProperty(const string& name, double value);
00538
00546 void setProperty(const string& name, const string& value);
00547
00555 void setProperty(const string& name, const PersistentObject& value);
00556
00563 const NamedProperty& getProperty(const string& name) const;
00564
00570 void clearProperty(const string& name);
00571
00575 Size countNamedProperties() const;
00577
00581
00582 bool hasProperty(Property property) const;
00583
00585 bool hasProperty(const string& name) const;
00586
00590 bool operator == (const PropertyManager& pm) const;
00591
00593 bool operator != (const PropertyManager& pm) const;
00594
00596
00597
00601
00602 void write(PersistenceManager& pm) const;
00603
00605 bool read(PersistenceManager& pm);
00607
00611
00616 bool isValid() const;
00617
00624 void dump(std::ostream& s = std::cout, Size depth = 0) const;
00625
00627
00628 private:
00629
00630 BitVector bitvector_;
00631 std::vector<NamedProperty> named_properties_;
00632 };
00633
00635
00636 # ifndef BALL_NO_INLINE_FUNCTIONS
00637 # include <BALL/CONCEPT/property.iC>
00638 # endif
00639
00640 }
00641
00642 #endif // BALL_CONCEPT_PROPERTY_H