20 #include <coil/Properties.h> 21 #include <coil/stringutil.h> 34 : name(key), value(value), default_value(
""), root(NULL), m_empty(
"")
50 std::map<std::string, std::string>::iterator it(defaults.begin());
51 std::map<std::string, std::string>::iterator it_end(defaults.end());
55 setDefault(it->first.c_str(), it->second.c_str());
85 std::vector<std::string>
keys;
87 for (
size_t i(0), len(keys.size()); i < len; ++i)
90 if ((node = prop.
findNode(keys[i])) != NULL)
112 std::vector<std::string>
keys;
114 for (
size_t i(0), len(keys.size()); i < len; ++i)
158 std::vector<std::string>
keys;
159 split(key,
'.', keys);
161 if ((node =
_getNode(keys, 0,
this)) != NULL)
176 const std::string& def)
const 178 const std::string&
value((*
this)[key]);
180 return value.empty() ? def :
value;
219 std::vector<std::string>
keys;
220 split(key,
'.', keys);
222 if ((node =
_getNode(keys, 0,
this)) != NULL)
237 const std::string&
value)
239 std::vector<std::string>
keys;
240 split(key,
'.', keys);
243 for (
size_t i(0), len(keys.size()); i < len; ++i)
250 curr->
leaf.push_back(next);
254 std::string retval(curr->
value);
267 const std::string&
value)
269 std::vector<std::string>
keys;
270 split(key,
'.', keys);
273 for (
size_t i(0), len(keys.size()); i < len; ++i)
280 curr->
leaf.push_back(next);
297 for (
long i = 0; i < num && defaults[i][0] !=
'\0' ; i += 2)
299 std::string key(defaults[i]);
300 std::string
value(defaults[i + 1]);
338 while(!inStream.eof())
345 if (tmp[0] ==
'#' || tmp[0] ==
'!' || tmp ==
"")
continue;
348 if (tmp[tmp.size() - 1] ==
'\\' && !
coil::isEscaped(tmp, tmp.size() - 1))
350 tmp.erase(tmp.size() - 1);
357 if (pline ==
"")
continue;
359 std::string key,
value;
396 out <<
"# " << header << std::endl;
412 std::vector<std::string> names;
413 for (
size_t i(0), len(
leaf.size()); i < len; ++i)
441 if (key.empty()) {
return 0; }
442 std::vector<std::string>
keys;
444 split(key,
'.', keys);
457 if (key.empty()) {
return *
this; }
476 if (key.empty()) {
return false; }
495 std::vector<Properties*>::iterator it(
leaf.begin()), it_end(
leaf.end());
499 if ((*it)->name == leaf_name)
519 for (
size_t i(0), len(
leaf.size()); i < len; ++i)
536 while (!
leaf.empty())
538 if (
leaf.back() != NULL)
552 std::vector<std::string>
keys;
554 for (
size_t i(0), len(prop.
size()); i < len; ++i)
556 (*this)[keys[i]] = prop[keys[i]];
574 std::string::size_type i(0);
575 std::string::size_type len(str.size());
581 key = str.substr(0, i);
584 value = str.substr(i + 1);
598 key = str.substr(0, i);
601 value = str.substr(i + 1);
622 std::vector<std::string>&
value)
624 if (str.empty())
return false;
626 std::string::size_type begin_it(0), end_it(0);
627 std::string::size_type len(str.size());
634 value.push_back(str.substr(begin_it, end_it - begin_it));
635 begin_it = end_it + 1;
639 value.push_back(str.substr(begin_it, end_it));
652 std::vector<Properties*>::size_type
index,
662 if (index < keys.size() - 1)
664 return next->
_getNode(keys, ++index, next);
682 std::string curr_name,
685 if (!curr->
leaf.empty())
687 for (
size_t i(0), len(curr->
leaf.size()); i < len; ++i)
689 std::string next_name;
691 next_name = curr_name +
"." + curr->
leaf[i]->name;
697 names.push_back(curr_name);
713 if (!curr->
leaf.empty())
716 for (
size_t i(0), len(curr->
leaf.size()); i < len; ++i)
718 std::string next_name;
721 next_name = curr->
leaf[i]->name;
725 next_name = curr_name +
"." + curr->
leaf[i]->name;
731 if (curr->
root != NULL)
733 if (curr->
value.length() > 0)
750 if (index != 0) out <<
indent(index) <<
"- " << curr.
name;
751 if (curr.
leaf.empty())
753 if (curr.
value.empty())
759 out <<
": " << curr.
value << std::endl;
763 if (index != 0) out << std::endl;
764 for (
size_t i(0), len(curr.
leaf.size()); i < len ;++i)
781 for (
int i(0); i < index - 1; ++i)
798 for (
int i(0); i < index - 1; ++i)
814 return rhs.
_dump(lhs, rhs, 0);
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.
static bool split(const std::string &str, const char delim, std::vector< std::string > &value)
Split the string.
Properties * hasKey(const char *key) const
Check whether key exists in the children.
void list(std::ostream &out)
Prints this property list out to the specified output stream.
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 m_empty
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.
Properties *const findNode(const std::string &key) const
Get node of properties.
void load(std::istream &inStream)
Loads property list that consists of key:value from input stream.
prop
Organization::get_organization_property ();.
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.
const std::string & operator[](const std::string &key) const
Search for the property with the specified key in property list.
bool isEscaped(const std::string &str, std::string::size_type pos)
Check whether the character is escaped or not.
std::vector< std::string > propertyNames(void) const
Return an vector of all the keys in this property.
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.
const std::string & getDefault(const std::string &key) const
Get the default values with specified key.
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.
static Properties * _getNode(std::vector< std::string > &keys, std::vector< Properties * >::size_type index, const Properties *curr)
Get properties.
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
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.