00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00029 #if ! defined( PROPERTY_HH )
00030 #define PROPERTY_HH
00031
00032
00033 #include <iostream>
00034 #include <string>
00035 #include <vector>
00036 #include <map>
00037
00038
00039 namespace PIAVE {
00040
00041 class PropertyNode;
00042 typedef std::vector< PropertyNode* > PropertyNodeList;
00043 typedef std::pair< std::string, std::string > Attribute;
00044 typedef std::map< std::string, std::string > AttrMap;
00045
00046
00047 class PropertyNode
00048 {
00049 public:
00050 PropertyNode( const std::string & n = std::string("") );
00051 PropertyNode( const PropertyNode & o );
00052 virtual ~PropertyNode();
00053
00054 bool operator==( const PropertyNode & o ) const {
00055 return _name==o._name;
00056 }
00057 void operator=( const PropertyNode & o );
00058
00059
00060
00061 std::string getName() const { return _name; }
00062 std::string getContent() const { return (*_content); }
00063 PropertyNode * getDaughter( const std::string & n, int w=0, bool recurse = false );
00064 const PropertyNode * getDaughter( const std::string & n, int w=0, bool recurse = false ) const;
00065 PropertyNode * getDaughter( unsigned int w=0 );
00066 const PropertyNode * getDaughter( unsigned int w=0 ) const;
00067 int getNDaughters() const {
00068 return _daughters?_daughters->size():0;}
00069
00070 bool getAttr( const std::string & a, std::string & v ) const;
00071 bool getAttr( const std::string & a, double & v ) const;
00072 bool getAttrRec( const std::string & a, std::string & v ) const;
00073 bool getAttrRec( const std::string & a, double & v ) const;
00074
00075
00076
00077 void setName( const std::string & c );
00078 void setContent( const std::string & c );
00079 void addAttr( const std::string & n, const std::string & v );
00080 void addAttr( const std::string & n, const double & v );
00081 void addAttr( const std::string & n, const int & v );
00082 PropertyNode* addDaughter( const std::string & n );
00083 void addDaughter( PropertyNode* );
00084
00085 void toXML( std::ostream & o, int indent = 2 ) const ;
00086 std::string toXML() const ;
00087
00088 bool provides( PropertyNode * caps, bool recurse = true ) const;
00089
00090 private:
00091 std::string _name;
00092 std::string * _content;
00093 AttrMap * _attrMap;
00094 PropertyNodeList * _daughters;
00095 };
00096
00097 }
00098
00099
00100 #endif