00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __PROPERTY_LIST_H__
00022 #define __PROPERTY_LIST_H__
00023 #include <boost/any.hpp>
00024 #include <map>
00025 #include <miniXml/ustring.h>
00026
00027 namespace Spm
00028 {
00029 namespace Util
00030 {
00036 class PropertyList
00037 {
00038 public:
00039 typedef enum
00040 {
00041 TYPE_STRING,
00042 TYPE_INTEGER,
00043 TYPE_BOOLEAN
00044 } propertyType_e;
00045 typedef std::map<miniXml::ustring,
00046 std::pair<propertyType_e, boost::any> >::iterator iterator;
00047 typedef std::map<miniXml::ustring,
00048 std::pair<propertyType_e,boost::any> >::const_iterator const_iterator;
00049 typedef std::map<miniXml::ustring,
00050 std::pair<propertyType_e,boost::any> >::reverse_iterator reverse_iterator;
00051 typedef std::map<miniXml::ustring,
00052 std::pair<propertyType_e,boost::any> >::const_reverse_iterator const_reverse_iterator;
00053
00054 protected:
00055 std::map<miniXml::ustring,
00056 std::pair<propertyType_e, boost::any> > properties_;
00057 public:
00058 PropertyList ()
00059 {
00060 }
00066 void add (const miniXml::ustring & key,
00067 boost::any & value);
00073 void set (const miniXml::ustring & key,
00074 boost::any & value);
00079 void remove (const miniXml::ustring & key);
00080
00084 inline iterator begin ()
00085 {
00086 return properties_.begin ();
00087 }
00088
00089 inline iterator end ()
00090 {
00091 return properties_.end ();
00092 }
00093
00094 inline const_iterator begin () const
00095 {
00096 return properties_.begin ();
00097 }
00098
00099 inline const_iterator end () const
00100 {
00101 return properties_.end ();
00102 }
00103
00104 inline reverse_iterator rbegin ()
00105 {
00106 return properties_.rbegin ();
00107 }
00108
00109 inline reverse_iterator rend ()
00110 {
00111 return properties_.rend ();
00112 }
00113
00114 inline const_reverse_iterator rbegin () const
00115 {
00116 return properties_.rbegin ();
00117 }
00118
00119 inline const_reverse_iterator rend () const
00120 {
00121 return properties_.rend ();
00122 }
00123
00129 bool exist (const miniXml::ustring & key) const;
00130
00135 boost::any & get (const miniXml::ustring & key);
00140 const boost::any & get (const miniXml::ustring & key) const;
00141
00146 propertyType_e & getPropertyType (const miniXml::ustring & key);
00151 const propertyType_e & getPropertyType (const miniXml::ustring & key) const;
00152
00158 miniXml::ustring getString (const miniXml::ustring & key) const;
00159
00165 int getInteger (const miniXml::ustring & key) const;
00166
00172 bool getBoolean (const miniXml::ustring & key) const;
00173
00179 inline void add (const miniXml::ustring & key,
00180 const miniXml::ustring & str)
00181 {
00182 boost::any value = str;
00183 add (key,
00184 value);
00185 }
00186
00192 inline void add (const miniXml::ustring & key,
00193 int i)
00194 {
00195 boost::any value = i;
00196 add (key,
00197 value);
00198 }
00199
00205 inline void add (const miniXml::ustring & key,
00206 bool boolean)
00207 {
00208 boost::any value = boolean;
00209 add (key,
00210 value);
00211 }
00212
00218 inline void set (const miniXml::ustring & key,
00219 const miniXml::ustring & value)
00220 {
00221 boost::any val = value;
00222 set(key,
00223 val);
00224 }
00225
00231 inline void set (const miniXml::ustring & key,
00232 int value)
00233 {
00234 boost::any val = value;
00235 set(key,
00236 val);
00237 }
00238
00244 inline void set (const miniXml::ustring & key,
00245 bool value)
00246 {
00247 boost::any val = value;
00248 set(key,
00249 val);
00250 }
00251
00252 inline boost::any & operator[] (const miniXml::ustring & key)
00253 {
00254 if (!exist(key))
00255 add(key,
00256 "");
00257 return get(key);
00258 }
00259
00260 inline const boost::any & operator[] (const miniXml::ustring & key) const
00261 {
00262 return get(key);
00263 }
00264
00268 inline std::size_t size () const
00269 {
00270 return properties_.size ();
00271 }
00272 };
00273 }
00274 }
00275
00276 #endif