Properties.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef COIL_PROPERTIES_H
00021 #define COIL_PROPERTIES_H
00022 
00023 
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 #include <climits>
00028 
00029 
00045 namespace coil
00046 {
00101   class Properties
00102   {
00103   public:
00127     Properties(const char* key = "", const char* value = "");
00128     
00150     Properties(std::map<std::string, std::string>& defaults);
00151     
00210     Properties(const char* defaults[], long num = LONG_MAX);
00211     
00228     Properties(const Properties& prop);
00229     
00247     Properties& operator=(const Properties& prop);
00248     
00260     virtual ~Properties(void);
00261     
00262     //============================================================
00263     // public functions
00264     //============================================================
00265     
00283     inline const char* getName(void) const          {return name.c_str();}
00284     
00302     inline const char* getValue(void) const         {return value.c_str();}
00303     
00321     inline const char* getDefaultValue(void) const {return default_value.c_str();}
00322     
00340     inline const std::vector<Properties*>& getLeaf(void) const {return leaf;}
00341     
00359     inline const Properties* getRoot(void) const    {return root;}
00360     
00390     const std::string& getProperty(const std::string& key) const;
00391     
00420     const std::string& getProperty(const std::string& key,
00421                                    const std::string& def) const;
00422     
00451     const std::string& operator[](const std::string& key) const;
00452     
00485     std::string& operator[](const std::string& key);
00486     
00511     const std::string& getDefault(const std::string& key) const;
00512     
00541     std::string setProperty(const std::string& key, const std::string& value);
00542     
00566     std::string setDefault(const std::string& key, const std::string& value);
00567     
00595     void setDefaults(const char* defaults[], long num = LONG_MAX);
00596     
00597     //============================================================
00598     // load and save functions
00599     //============================================================
00621     void list(std::ostream& out);
00622     
00749     void load(std::istream& inStream);
00750     
00776     void save(std::ostream& out, const std::string& header);
00777     
00860     void store(std::ostream& out, const std::string& header);
00861     
00862     //============================================================
00863     // other util functions
00864     //============================================================
00890     std::vector<std::string> propertyNames(void) const;
00891     
00909     int size(void) const;
00910     
00933     Properties* const findNode(const std::string& key) const;
00956     Properties& getNode(const std::string& key);
00957     
00984     bool createNode(const std::string& key);
00985     
01009     Properties* removeNode(const char* leaf_name);
01010     
01034     Properties* hasKey(const char* key) const;
01035     
01043     void clear(void);
01044     
01066     Properties& operator<<(const Properties& prop);
01067     
01068   protected:
01105     static void splitKeyValue(const std::string& str, std::string& key,
01106                               std::string& value);
01107     
01139     static bool split(const std::string& str, const char delim,
01140                       std::vector<std::string>& value);
01141     
01174     static Properties* _getNode(std::vector<std::string>& keys,
01175                                 std::vector<Properties*>::size_type index,
01176                                 const Properties* curr);
01177     
01199     static void _propertiyNames(std::vector<std::string>& names,
01200                                 std::string curr_name,
01201                                 const Properties* curr);
01202     
01224     static void _store(std::ostream& out, std::string curr_name,
01225                        Properties* curr);
01226     
01254     static std::ostream& _dump(std::ostream& out, const Properties& curr,
01255                                int index);
01256     
01280     static std::string indent(int index);
01281     
01282   private:
01283     std::string name;
01284     std::string value;
01285     std::string default_value;
01286     Properties* root;
01287     std::vector<Properties*> leaf;
01288     const std::string m_empty;
01289 
01313     friend std::ostream& operator<<(std::ostream& lhs, const Properties& rhs);
01314 
01315   };   // class Properties
01316 };     // namespace coil  
01317 #endif // COIL_PROPERTIES_H
01318 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:06