BALL  1.4.1
property.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: property.h,v 1.40 2005/12/23 17:01:41 amoll Exp $
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     /*  The default constructor
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 
00191     NamedProperty(const NamedProperty&, const string& name);
00192 
00197     ~NamedProperty();
00198 
00201     virtual void clear();
00202     
00204 
00207       
00211     virtual void persistentWrite(PersistenceManager& pm, const char* name = "") const;
00212 
00216     virtual void persistentRead(PersistenceManager& pm);
00217     
00219 
00222 
00224     Type getType() const;
00225     
00227     const string& getName() const;
00228 
00233     bool getBool() const;
00234 
00239     int getInt() const;
00240       
00245     float getFloat() const;
00246       
00251     double getDouble() const;
00252       
00257     unsigned int getUnsignedInt() const;
00258 
00263     PersistentObject* getObject() const;
00264 
00269     boost::shared_ptr<PersistentObject> getSmartObject() const;
00270 
00275     String getString() const;
00276     
00279     String toString() const;
00280 
00282 
00285 
00289     bool operator == (const NamedProperty& np) const;
00290 
00294     bool operator != (const NamedProperty& np) const;
00295 
00297     void operator = (const NamedProperty& np);
00298 
00300 
00301     private:
00302 
00303     /*_ The kind of information contained in the NamedProperty
00304     */
00305     Type type_;
00306 
00307     /*_ The name of the property object 
00308     */
00309     string name_;
00310     
00311     /*_ The data
00312     */
00313     boost::any data_;
00314 
00315   };
00316 
00317   typedef std::vector<NamedProperty>::iterator NamedPropertyIterator;
00318 
00343   class BALL_EXPORT PropertyManager
00344   {
00345     public:
00346     
00347     BALL_CREATE(PropertyManager)
00348 
00349     
00351 
00352     BALL_INLINE 
00353 
00355     PropertyManager();
00356 
00357     BALL_INLINE
00359     PropertyManager(const PropertyManager& property_manager);
00360 
00362     virtual ~PropertyManager();
00363 
00365     virtual void clear();
00366 
00368     virtual void destroy();
00369 
00371 
00374 
00378     void set(const PropertyManager& property_manager);
00379 
00386     const PropertyManager& operator = (const PropertyManager& property_manager);
00387 
00393     void get(PropertyManager& property_manager) const;
00394 
00398     void swap(PropertyManager& property_manager);
00399 
00401 
00404        
00411     BitVector& getBitVector();
00412 
00419     const BitVector& getBitVector() const;
00420       
00422 
00425 
00432     operator BitVector& ();
00433 
00435 
00438 
00444     void setProperty(Property property);
00445 
00451     void clearProperty(Property property);
00452 
00458     void toggleProperty(Property property);
00459 
00465     Size countProperties() const;
00466   
00468 
00477 
00481     const NamedProperty& getNamedProperty(Position index) const;
00482 
00486     NamedProperty& getNamedProperty(Position index);
00487 
00495     void setProperty(const NamedProperty& property);
00496 
00503     void setProperty(const string& name);
00504 
00512     void setProperty(const string& name, bool value);
00513 
00521     void setProperty(const string& name, int value);
00522 
00530     void setProperty(const string& name, unsigned int value);
00531 
00539     void setProperty(const string& name, float value);
00540 
00548     void setProperty(const string& name, double value);
00549 
00557     void setProperty(const string& name, const string& value);
00558 
00566     void setProperty(const string& name, const PersistentObject& value);
00567 
00574     const NamedProperty& getProperty(const string& name) const;
00575 
00577     NamedPropertyIterator beginNamedProperty();
00578 
00580     NamedPropertyIterator endNamedProperty();
00581 
00587     void clearProperty(const string& name);
00588 
00592     Size countNamedProperties() const;
00594 
00598 
00599     bool hasProperty(Property property) const;
00600 
00602     bool hasProperty(const string& name) const;
00603 
00607     bool operator == (const PropertyManager& pm) const;
00608 
00610     bool operator != (const PropertyManager& pm) const;
00611 
00613 
00614 
00618 
00619     void write(PersistenceManager& pm) const;
00620 
00622     bool read(PersistenceManager& pm);
00624 
00628 
00633     bool isValid() const;
00634   
00641     void dump(std::ostream& s = std::cout, Size depth = 0) const;
00642     
00644 
00645     private:
00646 
00647     BitVector bitvector_;
00648     std::vector<NamedProperty> named_properties_;
00649   };
00650 
00652 
00653 # ifndef BALL_NO_INLINE_FUNCTIONS
00654 #   include <BALL/CONCEPT/property.iC>
00655 # endif
00656 
00657 } // namespace BALL
00658 
00659 #endif // BALL_CONCEPT_PROPERTY_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines