00001
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef Properties_h
00049 #define Properties_h
00050
00051
00052 #include <string>
00053 #include <vector>
00054 #include <map>
00055
00056
00057 namespace RTC
00058 {
00115 class Properties
00116 {
00117 public:
00134 Properties(const char* key = "", const char* value = "");
00135
00136
00153 Properties(std::map<std::string, std::string>& defaults);
00154
00155
00202 Properties(const char* defaults[], long num = LONG_MAX);
00203
00204
00221 Properties(const Properties& prop);
00222
00223
00239 Properties& operator=(const Properties& prop);
00240
00241
00253 virtual ~Properties();
00254
00255
00256
00257
00258
00259
00260
00261 inline const char* getName() const {return name.c_str();}
00262 inline const char* getVlue() const {return value.c_str();}
00263 inline const char* getDefaultValue() const {return default_value.c_str();}
00264 inline const std::vector<Properties*>& getLeaf() const {return leaf;}
00265 inline const Properties* getRoot() const {return root;}
00266
00294 const std::string& getProperty(const std::string& key) const;
00295
00296
00326 const std::string& getProperty(const std::string& key,
00327 const std::string& def) const;
00328
00356 const std::string& operator[](const std::string& key) const;
00357
00358
00388 std::string& operator[](const std::string& key);
00389
00390
00398 const std::string& getDefault(const std::string& key) const;
00399
00400
00427 std::string setProperty(const std::string& key, const std::string& value);
00428
00429
00437 std::string setDefault(const std::string& key, const std::string& value);
00438
00439
00447 void setDefaults(const char* defaults[], long num = LONG_MAX);
00448
00449
00450
00451
00452
00474 void list(std::ostream& out);
00475
00476
00635 void load(std::istream& inStream);
00636
00637
00661 void save(std::ostream& out, const std::string& header);
00662
00663
00744 void store(std::ostream& out, const std::string& header);
00745
00746
00747
00748
00749
00775 std::vector<std::string> propertyNames() const;
00776
00777
00785 int size() const;
00786
00787
00795 Properties* getNode(const std::string& key) const;
00796 bool createNode(const char* key)
00797 {
00798 Properties* p(getNode(key));
00799 if (p != NULL) return false;
00800 (*this)[key] = "";
00801 return true;
00802 }
00803
00811 Properties* removeNode(const char* leaf_name);
00812
00813
00821 Properties* hasKey(const char* key) const;
00822
00823
00831 void clear();
00832
00833
00841 Properties& operator<<(const Properties& prop);
00842
00843
00844 protected:
00845 static void splitKeyValue(const std::string& str, std::string& key,
00846 std::string& value);
00847
00848 static bool split(const std::string& str, const char delim,
00849 std::vector<std::string>& value);
00850
00851 static Properties* _getNode(std::vector<std::string>& keys,
00852 std::vector<Properties*>::size_type index,
00853 const Properties* curr);
00854
00855 static void _propertiyNames(std::vector<std::string>& names,
00856 std::string curr_name,
00857 const Properties* curr);
00858
00859 static void _store(std::ostream& out, std::string curr_name,
00860 Properties* curr);
00861
00862 static std::ostream& _dump(std::ostream& out, const Properties& curr,
00863 int index);
00864
00865 static std::string indent(int index);
00866
00867 private:
00868 std::string name;
00869 std::string value;
00870 std::string default_value;
00871 Properties* root;
00872 std::vector<Properties*> leaf;
00873 const std::string m_empty;
00874 friend std::ostream& operator<<(std::ostream& lhs, const Properties& rhs);
00875
00876 };
00877 };
00878 #endif // Properties_h
00879