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
00289 private:
00290
00291
00292
00293 Type type_;
00294
00295
00296
00297 string name_;
00298
00299
00300
00301 boost::any data_;
00302
00303 };
00304
00329 class BALL_EXPORT PropertyManager
00330 {
00331 public:
00332
00333 BALL_CREATE(PropertyManager)
00334
00335
00337
00338 BALL_INLINE
00339
00341 PropertyManager();
00342
00343 BALL_INLINE
00345 PropertyManager(const PropertyManager& property_manager);
00346
00348 virtual ~PropertyManager();
00349
00351 virtual void clear();
00352
00354 virtual void destroy();
00355
00357
00360
00364 void set(const PropertyManager& property_manager);
00365
00372 const PropertyManager& operator = (const PropertyManager& property_manager);
00373
00379 void get(PropertyManager& property_manager) const;
00380
00384 void swap(PropertyManager& property_manager);
00385
00387
00390
00397 BitVector& getBitVector();
00398
00405 const BitVector& getBitVector() const;
00406
00408
00411
00418 operator BitVector& ();
00419
00421
00424
00430 void setProperty(Property property);
00431
00437 void clearProperty(Property property);
00438
00444 void toggleProperty(Property property);
00445
00451 Size countProperties() const;
00452
00454
00463
00466 const NamedProperty& getNamedProperty(Position index) const
00467 throw(Exception::IndexOverflow);
00468
00471 NamedProperty& getNamedProperty(Position index)
00472 throw(Exception::IndexOverflow);
00473
00481 void setProperty(const NamedProperty& property);
00482
00489 void setProperty(const string& name);
00490
00498 void setProperty(const string& name, bool value);
00499
00507 void setProperty(const string& name, int value);
00508
00516 void setProperty(const string& name, unsigned int value);
00517
00525 void setProperty(const string& name, float value);
00526
00534 void setProperty(const string& name, double value);
00535
00543 void setProperty(const string& name, const string& value);
00544
00552 void setProperty(const string& name, const PersistentObject& value);
00553
00560 const NamedProperty& getProperty(const string& name) const;
00561
00567 void clearProperty(const string& name);
00568
00572 Size countNamedProperties() const;
00574
00578
00579 bool hasProperty(Property property) const;
00580
00582 bool hasProperty(const string& name) const;
00583
00587 bool operator == (const PropertyManager& pm) const;
00588
00590 bool operator != (const PropertyManager& pm) const;
00591
00593
00594
00598
00599 void write(PersistenceManager& pm) const;
00600
00602 bool read(PersistenceManager& pm);
00604
00608
00613 bool isValid() const;
00614
00621 void dump(std::ostream& s = std::cout, Size depth = 0) const;
00622
00624
00625 private:
00626
00627 BitVector bitvector_;
00628 std::vector<NamedProperty> named_properties_;
00629 };
00630
00632
00633 # ifndef BALL_NO_INLINE_FUNCTIONS
00634 # include <BALL/CONCEPT/property.iC>
00635 # endif
00636
00637 }
00638
00639 #endif // BALL_CONCEPT_PROPERTY_H