20 #include <coil/Properties.h> 21 #include <coil/stringutil.h> 38 : name(key), value(value), default_value(
""), root(NULL), m_empty(
"")
54 std::map<std::string, std::string>::iterator it(defaults.begin());
55 std::map<std::string, std::string>::iterator it_end(defaults.end());
59 setDefault(it->first.c_str(), it->second.c_str());
89 std::vector<std::string>
keys;
91 for (
size_t i(0), len(keys.size()); i < len; ++i)
94 if ((node = prop.
findNode(keys[i])) != NULL)
116 std::vector<std::string>
keys;
118 for (
size_t i(0), len(keys.size()); i < len; ++i)
162 std::vector<std::string>
keys;
163 split(key,
'.', keys);
165 if ((node =
_getNode(keys, 0,
this)) != NULL)
180 const std::string& def)
const 182 const std::string&
value((*
this)[key]);
184 return value.empty() ? def :
value;
223 std::vector<std::string>
keys;
224 split(key,
'.', keys);
226 if ((node =
_getNode(keys, 0,
this)) != NULL)
241 const std::string&
value)
243 std::vector<std::string>
keys;
244 split(key,
'.', keys);
247 for (
size_t i(0), len(keys.size()); i < len; ++i)
254 curr->
leaf.push_back(next);
258 std::string retval(curr->
value);
271 const std::string&
value)
273 std::vector<std::string>
keys;
274 split(key,
'.', keys);
277 for (
size_t i(0), len(keys.size()); i < len; ++i)
284 curr->
leaf.push_back(next);
301 for (
long i = 0; i < num && defaults[i][0] !=
'\0' ; i += 2)
303 std::string key(defaults[i]);
304 std::string
value(defaults[i + 1]);
342 while(!inStream.eof())
349 if (tmp.empty()) {
continue; }
350 if (tmp[0] ==
'#' || tmp[0] ==
'!') {
continue; }
353 if (tmp[tmp.size() - 1] ==
'\\' && !
coil::isEscaped(tmp, tmp.size() - 1))
355 tmp.erase(tmp.size() - 1);
362 if (pline.empty()) {
continue; }
364 std::string key,
value;
401 out <<
"# " << header << std::endl;
417 std::vector<std::string> names;
418 for (
size_t i(0), len(
leaf.size()); i < len; ++i)
446 if (key.empty()) {
return 0; }
447 std::vector<std::string>
keys;
449 split(key,
'.', keys);
462 if (key.empty()) {
return *
this; }
481 if (key.empty()) {
return false; }
500 std::vector<Properties*>::iterator it(
leaf.begin()), it_end(
leaf.end());
504 if ((*it)->name == leaf_name)
524 for (
size_t i(0), len(
leaf.size()); i < len; ++i)
541 while (!
leaf.empty())
543 if (
leaf.back() != NULL)
557 std::vector<std::string>
keys;
559 for (
size_t i(0), len(prop.
size()); i < len; ++i)
561 (*this)[keys[i]] = prop[keys[i]];
579 std::string::size_type i(0);
580 std::string::size_type len(str.size());
586 key = str.substr(0, i);
589 value = str.substr(i + 1);
603 key = str.substr(0, i);
606 value = str.substr(i + 1);
627 std::vector<std::string>&
value)
629 if (str.empty())
return false;
631 std::string::size_type begin_it(0), end_it(0);
632 std::string::size_type len(str.size());
639 value.push_back(str.substr(begin_it, end_it - begin_it));
640 begin_it = end_it + 1;
644 value.push_back(str.substr(begin_it, end_it));
657 std::vector<Properties*>::size_type
index,
667 if (index < keys.size() - 1)
669 return next->
_getNode(keys, ++index, next);
687 std::string curr_name,
690 if (!curr->
leaf.empty())
692 for (
size_t i(0), len(curr->
leaf.size()); i < len; ++i)
694 std::string next_name;
696 next_name = curr_name +
"." + curr->
leaf[i]->name;
702 names.push_back(curr_name);
718 if (!curr->
leaf.empty())
721 for (
size_t i(0), len(curr->
leaf.size()); i < len; ++i)
723 std::string next_name;
726 next_name = curr->
leaf[i]->name;
730 next_name = curr_name +
"." + curr->
leaf[i]->name;
736 if (curr->
root != NULL)
738 if (curr->
value.length() > 0)
755 if (index != 0) out <<
indent(index) <<
"- " << curr.
name;
756 if (curr.
leaf.empty())
758 if (curr.
value.empty())
764 out <<
": " << curr.
value << std::endl;
768 if (index != 0) out << std::endl;
769 for (
size_t i(0), len(curr.
leaf.size()); i < len ;++i)
786 for (
int i(0); i < index - 1; ++i)
803 for (
int i(0); i < index - 1; ++i)
819 return rhs.
_dump(lhs, rhs, 0);
const std::string & getDefault(const std::string &key) const
Get the default values with specified key.
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.
static std::string indent(int index)
Create indents.
Properties(const char *key="", const char *value="")
Constructor(Create only root node)
void clear(void)
Clear the children.
void store(std::ostream &out, const std::string &header)
Stores property list to the output stream.
void eraseHeadBlank(std::string &str)
Erase the head blank characters of string.
static void _propertiyNames(std::vector< std::string > &names, std::string curr_name, const Properties *curr)
Get property name list.
std::vector< std::string > propertyNames(void) const
Return an vector of all the keys in this property.
static bool split(const std::string &str, const char delim, std::vector< std::string > &value)
Split the string.
void list(std::ostream &out)
Prints this property list out to the specified output stream.
Properties * hasKey(const char *key) const
Check whether key exists in the children.
std::string default_value
void eraseTailBlank(std::string &str)
Erase the tail blank characters of string.
void setDefaults(const char *defaults[], long num=LONG_MAX)
Set a default value together in the property list.
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
const std::string m_empty
Properties *const findNode(const std::string &key) const
Get node of properties.
virtual ~Properties(void)
Destructor.
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
bool createNode(const std::string &key)
Create newly node of Properties.
Properties * removeNode(const char *leaf_name)
Remove node of Properties.
void load(std::istream &inStream)
Loads property list that consists of key:value from input stream.
static Properties * _getNode(std::vector< std::string > &keys, std::vector< Properties *>::size_type index, const Properties *curr)
Get properties.
prop
Organization::get_organization_property ();.
const std::string & operator[](const std::string &key) const
Search for the property with the specified key in property list.
static std::ostream & _dump(std::ostream &out, const Properties &curr, int index)
Save property's contents.
static void _store(std::ostream &out, std::string curr_name, Properties *curr)
Store the property name list.
std::vector< Properties * > leaf
Properties & operator=(const Properties &prop)
Assignment operator.
int getlinePortable(std::istream &istr, std::string &line)
Read a line from input stream.
int size(void) const
Get the number of Properties.
bool isEscaped(const std::string &str, std::string::size_type pos)
Check whether the character is escaped or not.
Properties & getNode(const std::string &key)
Get node of properties.
void save(std::ostream &out, const std::string &header)
Save the property list to the specified stream.
std::string unescape(const std::string str)
Unescape string.
std::string escape(const std::string str)
Escape string.
Properties & operator<<(const Properties &prop)
Merge properties.
std::string setDefault(const std::string &key, const std::string &value)
Set a default value associated with key in the property list.
Common Object Interface Layer.