Properties.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef COIL_PROPERTIES_H
21 #define COIL_PROPERTIES_H
22 
23 
24 #include <string>
25 #include <vector>
26 #include <map>
27 #include <climits>
28 
29 
45 namespace coil
46 {
102  {
103  public:
127  Properties(const char* key = "", const char* value = "");
128 
150  Properties(std::map<std::string, std::string>& defaults);
151 
210  Properties(const char* defaults[], long num = LONG_MAX);
211 
228  Properties(const Properties& prop);
229 
247  Properties& operator=(const Properties& prop);
248 
260  virtual ~Properties(void);
261 
262  //============================================================
263  // public functions
264  //============================================================
265 
283  inline const char* getName(void) const {return name.c_str();}
284 
302  inline const char* getValue(void) const {return value.c_str();}
303 
321  inline const char* getDefaultValue(void) const {return default_value.c_str();}
322 
340  inline const std::vector<Properties*>& getLeaf(void) const {return leaf;}
341 
359  inline const Properties* getRoot(void) const {return root;}
360 
390  const std::string& getProperty(const std::string& key) const;
391 
420  const std::string& getProperty(const std::string& key,
421  const std::string& def) const;
422 
451  const std::string& operator[](const std::string& key) const;
452 
485  std::string& operator[](const std::string& key);
486 
511  const std::string& getDefault(const std::string& key) const;
512 
541  std::string setProperty(const std::string& key, const std::string& value);
542 
566  std::string setDefault(const std::string& key, const std::string& value);
567 
595  void setDefaults(const char* defaults[], long num = LONG_MAX);
596 
597  //============================================================
598  // load and save functions
599  //============================================================
621  void list(std::ostream& out);
622 
749  void load(std::istream& inStream);
750 
776  void save(std::ostream& out, const std::string& header);
777 
860  void store(std::ostream& out, const std::string& header);
861 
862  //============================================================
863  // other util functions
864  //============================================================
890  std::vector<std::string> propertyNames(void) const;
891 
909  int size(void) const;
910 
933  Properties* const findNode(const std::string& key) const;
956  Properties& getNode(const std::string& key);
957 
984  bool createNode(const std::string& key);
985 
1009  Properties* removeNode(const char* leaf_name);
1010 
1034  Properties* hasKey(const char* key) const;
1035 
1043  void clear(void);
1044 
1066  Properties& operator<<(const Properties& prop);
1067 
1068  protected:
1105  static void splitKeyValue(const std::string& str, std::string& key,
1106  std::string& value);
1107 
1139  static bool split(const std::string& str, const char delim,
1140  std::vector<std::string>& value);
1141 
1174  static Properties* _getNode(std::vector<std::string>& keys,
1175  std::vector<Properties*>::size_type index,
1176  const Properties* curr);
1177 
1199  static void _propertiyNames(std::vector<std::string>& names,
1200  std::string curr_name,
1201  const Properties* curr);
1202 
1224  static void _store(std::ostream& out, std::string curr_name,
1225  Properties* curr);
1226 
1254  static std::ostream& _dump(std::ostream& out, const Properties& curr,
1255  int index);
1256 
1280  static std::string indent(int index);
1281 
1282  private:
1283  std::string name;
1284  std::string value;
1285  std::string default_value;
1287  std::vector<Properties*> leaf;
1288  const std::string m_empty;
1289 
1313  friend std::ostream& operator<<(std::ostream& lhs, const Properties& rhs);
1314 
1315  }; // class Properties
1316 }; // namespace coil
1317 #endif // COIL_PROPERTIES_H
1318 
const std::vector< Properties * > & getLeaf(void) const
Get elements of leaf.
Definition: Properties.h:340
static void splitKeyValue(const std::string &str, std::string &key, std::string &value)
Split the string into a pair of the key and the value.
Definition: Properties.cpp:571
static std::string indent(int index)
Create indents.
Definition: Properties.cpp:778
const char * getName(void) const
Get Names.
Definition: Properties.h:283
const char * getDefaultValue(void) const
Get default values.
Definition: Properties.h:321
Properties(const char *key="", const char *value="")
Constructor(Create only root node)
Definition: Properties.cpp:33
void clear(void)
Clear the children.
Definition: Properties.cpp:534
void store(std::ostream &out, const std::string &header)
Stores property list to the output stream.
Definition: Properties.cpp:394
static void _propertiyNames(std::vector< std::string > &names, std::string curr_name, const Properties *curr)
Get property name list.
Definition: Properties.cpp:681
static bool split(const std::string &str, const char delim, std::vector< std::string > &value)
Split the string.
Definition: Properties.cpp:621
Properties * hasKey(const char *key) const
Check whether key exists in the children.
Definition: Properties.cpp:517
void list(std::ostream &out)
Prints this property list out to the specified output stream.
Definition: Properties.cpp:322
Properties * root
Definition: Properties.h:1286
std::string default_value
Definition: Properties.h:1285
void setDefaults(const char *defaults[], long num=LONG_MAX)
Set a default value together in the property list.
Definition: Properties.cpp:295
const std::string m_empty
Definition: Properties.h:1288
list index
Definition: rtimages.py:10
virtual ~Properties(void)
Destructor.
Definition: Properties.cpp:134
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
Definition: Properties.cpp:236
bool createNode(const std::string &key)
Create newly node of Properties.
Definition: Properties.cpp:474
Properties * removeNode(const char *leaf_name)
Remove node of Properties.
Definition: Properties.cpp:493
Properties *const findNode(const std::string &key) const
Get node of properties.
Definition: Properties.cpp:439
void load(std::istream &inStream)
Loads property list that consists of key:value from input stream.
Definition: Properties.cpp:334
prop
Organization::get_organization_property ();.
static std::ostream & _dump(std::ostream &out, const Properties &curr, int index)
Save property&#39;s contents.
Definition: Properties.cpp:748
static void _store(std::ostream &out, std::string curr_name, Properties *curr)
Store the property name list.
Definition: Properties.cpp:710
std::vector< Properties * > leaf
Definition: Properties.h:1287
Properties & operator=(const Properties &prop)
Assignment operator.
Definition: Properties.cpp:105
const char * getValue(void) const
Get values.
Definition: Properties.h:302
int size(void) const
Get the number of Properties.
Definition: Properties.cpp:427
const std::string & operator[](const std::string &key) const
Search for the property with the specified key in property list.
Definition: Properties.cpp:190
std::string value
Definition: Properties.h:1284
std::vector< std::string > propertyNames(void) const
Return an vector of all the keys in this property.
Definition: Properties.cpp:410
Properties & getNode(const std::string &key)
Get node of properties.
Definition: Properties.cpp:455
void save(std::ostream &out, const std::string &header)
Save the property list to the specified stream.
Definition: Properties.cpp:381
std::string name
Definition: Properties.h:1283
const std::string & getDefault(const std::string &key) const
Get the default values with specified key.
Definition: Properties.cpp:217
Properties & operator<<(const Properties &prop)
Merge properties.
Definition: Properties.cpp:550
static Properties * _getNode(std::vector< std::string > &keys, std::vector< Properties * >::size_type index, const Properties *curr)
Get properties.
Definition: Properties.cpp:651
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
Definition: Properties.cpp:156
std::string setDefault(const std::string &key, const std::string &value)
Set a default value associated with key in the property list.
Definition: Properties.cpp:266
Common Object Interface Layer.
const Properties * getRoot(void) const
Get root element.
Definition: Properties.h:359


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:59