00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PROPERTIES_H
00023 #define PROPERTIES_H
00024
00025 #include <map>
00026 #include <sstream>
00027 #include <string>
00028
00032 class Properties
00033 {
00034 public:
00038 virtual ~Properties() {}
00039
00048 const std::string &getProperty(const std::string &name,
00049 const std::string &def = "") const
00050 {
00051 PropertyMap::const_iterator i = mProperties.find(name);
00052 return (i != mProperties.end()) ? i->second : def;
00053 }
00054
00063 float getFloatProperty(const std::string &name, float def = 0.0f) const
00064 {
00065 PropertyMap::const_iterator i = mProperties.find(name);
00066 float ret = def;
00067 if (i != mProperties.end())
00068 {
00069 std::stringstream ss;
00070 ss.str(i->second);
00071 ss >> ret;
00072 }
00073 return ret;
00074 }
00075
00083 bool hasProperty(const std::string &name) const
00084 {
00085 return (mProperties.find(name) != mProperties.end());
00086 }
00087
00094 void setProperty(const std::string &name, const std::string &value)
00095 {
00096 mProperties[name] = value;
00097 }
00098
00099 private:
00100 typedef std::map<std::string, std::string> PropertyMap;
00101 PropertyMap mProperties;
00102 };
00103
00104 #endif