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
00274 string toString() const;
00275
00277
00280
00284 bool operator == (const NamedProperty& np) const;
00285
00289 bool operator != (const NamedProperty& np) const;
00290
00292 void operator = (const NamedProperty& np);
00293
00295
00296 private:
00297
00298
00299
00300 Type type_;
00301
00302
00303
00304 string name_;
00305
00306
00307
00308 boost::any data_;
00309
00310 };
00311
00312 typedef std::vector<NamedProperty>::iterator NamedPropertyIterator;
00313
00338 class BALL_EXPORT PropertyManager
00339 {
00340 public:
00341
00342 BALL_CREATE(PropertyManager)
00343
00344
00346
00347 BALL_INLINE
00348
00350 PropertyManager();
00351
00352 BALL_INLINE
00354 PropertyManager(const PropertyManager& property_manager);
00355
00357 virtual ~PropertyManager();
00358
00360 virtual void clear();
00361
00363 virtual void destroy();
00364
00366
00369
00373 void set(const PropertyManager& property_manager);
00374
00381 const PropertyManager& operator = (const PropertyManager& property_manager);
00382
00388 void get(PropertyManager& property_manager) const;
00389
00393 void swap(PropertyManager& property_manager);
00394
00396
00399
00406 BitVector& getBitVector();
00407
00414 const BitVector& getBitVector() const;
00415
00417
00420
00427 operator BitVector& ();
00428
00430
00433
00439 void setProperty(Property property);
00440
00446 void clearProperty(Property property);
00447
00453 void toggleProperty(Property property);
00454
00460 Size countProperties() const;
00461
00463
00472
00475 const NamedProperty& getNamedProperty(Position index) const
00476 throw(Exception::IndexOverflow);
00477
00480 NamedProperty& getNamedProperty(Position index)
00481 throw(Exception::IndexOverflow);
00482
00490 void setProperty(const NamedProperty& property);
00491
00498 void setProperty(const string& name);
00499
00507 void setProperty(const string& name, bool value);
00508
00516 void setProperty(const string& name, int value);
00517
00525 void setProperty(const string& name, unsigned int value);
00526
00534 void setProperty(const string& name, float value);
00535
00543 void setProperty(const string& name, double value);
00544
00552 void setProperty(const string& name, const string& value);
00553
00561 void setProperty(const string& name, const PersistentObject& value);
00562
00569 const NamedProperty& getProperty(const string& name) const;
00570
00572 NamedPropertyIterator beginNamedProperty();
00573
00575 NamedPropertyIterator endNamedProperty();
00576
00582 void clearProperty(const string& name);
00583
00587 Size countNamedProperties() const;
00589
00593
00594 bool hasProperty(Property property) const;
00595
00597 bool hasProperty(const string& name) const;
00598
00602 bool operator == (const PropertyManager& pm) const;
00603
00605 bool operator != (const PropertyManager& pm) const;
00606
00608
00609
00613
00614 void write(PersistenceManager& pm) const;
00615
00617 bool read(PersistenceManager& pm);
00619
00623
00628 bool isValid() const;
00629
00636 void dump(std::ostream& s = std::cout, Size depth = 0) const;
00637
00639
00640 private:
00641
00642 BitVector bitvector_;
00643 std::vector<NamedProperty> named_properties_;
00644 };
00645
00647
00648 # ifndef BALL_NO_INLINE_FUNCTIONS
00649 # include <BALL/CONCEPT/property.iC>
00650 # endif
00651
00652 }
00653
00654 #endif // BALL_CONCEPT_PROPERTY_H