Add config::has_child().

This allows to easily query whether a certain child exists.
This commit is contained in:
Mark de Wever 2012-05-20 09:56:13 +00:00
parent 018ff27c62
commit 9ebb260d01
2 changed files with 16 additions and 0 deletions

View File

@ -374,6 +374,13 @@ unsigned config::child_count(const std::string &key) const
return 0;
}
bool config::has_child(const std::string &key) const
{
check_valid();
return children.find(key) != children.end();
}
config &config::child(const std::string& key, int n)
{
check_valid();

View File

@ -252,6 +252,15 @@ public:
const_child_itors child_range(const std::string& key) const;
unsigned child_count(const std::string &key) const;
/**
* Determine whether a config has a child or not.
*
* @param key The key of the child to find.
*
* @returns Whether a child is available.
*/
bool has_child(const std::string& key) const;
/**
* Copies the first child with the given @a key, or an empty config if there is none.
*/