Add helper functions to handle backward compatible keys.
This commit is contained in:
parent
f6fab3788f
commit
ffe6d898d6
2 changed files with 31 additions and 0 deletions
|
@ -201,6 +201,13 @@ bool config::has_attribute(const std::string &key) const
|
|||
return values.find(key) != values.end();
|
||||
}
|
||||
|
||||
bool config::has_old_attribute(const std::string &key, const std::string &old_key) const
|
||||
{
|
||||
check_valid();
|
||||
return values.find(key) != values.end() || values.find(old_key) != values.end();
|
||||
}
|
||||
|
||||
|
||||
void config::remove_attribute(const std::string &key)
|
||||
{
|
||||
check_valid();
|
||||
|
@ -477,6 +484,19 @@ const config::attribute_value &config::operator[](const std::string &key) const
|
|||
return empty_attribute;
|
||||
}
|
||||
|
||||
const config::attribute_value &config::get_old_attribute(const std::string &key, const std::string &old_key) const
|
||||
{
|
||||
check_valid();
|
||||
|
||||
attribute_map::const_iterator i = values.find(key);
|
||||
if (i != values.end()) return i->second;
|
||||
i = values.find(old_key);
|
||||
if (i != values.end()) return i->second;
|
||||
static const attribute_value empty_attribute;
|
||||
return empty_attribute;
|
||||
}
|
||||
|
||||
|
||||
void config::merge_attributes(const config &cfg)
|
||||
{
|
||||
check_valid(cfg);
|
||||
|
|
|
@ -254,6 +254,11 @@ public:
|
|||
{ return values[key]; }
|
||||
const attribute_value &operator[](const std::string &key) const;
|
||||
|
||||
/**
|
||||
* Function to handle backward compatibility
|
||||
* Get the value of key and if missing try old_key
|
||||
*/
|
||||
const attribute_value &get_old_attribute(const std::string &key, const std::string &old_key) const;
|
||||
/**
|
||||
* Returns a reference to the first child with the given @a key.
|
||||
* Creates the child if it does not yet exist.
|
||||
|
@ -261,6 +266,12 @@ public:
|
|||
config &child_or_add(const std::string &key);
|
||||
|
||||
bool has_attribute(const std::string &key) const;
|
||||
/**
|
||||
* Function to handle backward compatibility
|
||||
* Check if has key or old_key
|
||||
*/
|
||||
bool has_old_attribute(const std::string &key, const std::string &old_key) const;
|
||||
|
||||
void remove_attribute(const std::string &key);
|
||||
void merge_attributes(const config &);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue