Commit 1ff9b7f9 authored by Matt Renaud's avatar Matt Renaud

Unified lookup interface for Config and Setting.

To address hyperrealm/libconfig#4, `Config::operator[](const char*)` and
`Setting::lookup(const std::string& key)` have been added.

Note: `operator[]` had to remain as `const char*` to avoid ambiguities
      in some situations.
parent 6af19564
......@@ -234,15 +234,12 @@ class LIBCONFIGXX_API Setting
Setting & operator=(const char *value) throw(SettingTypeException);
Setting & operator=(const std::string &value) throw(SettingTypeException);
Setting & operator[](const char *key) const
throw(SettingTypeException, SettingNotFoundException);
Setting & lookup(const std::string &key) const;
inline Setting & operator[](const std::string &key) const
throw(SettingTypeException, SettingNotFoundException)
{ return(operator[](key.c_str())); }
inline Setting & operator[](const char *key) const
{ return(lookup(key)); }
Setting & operator[](int index) const
throw(SettingTypeException, SettingNotFoundException);
Setting & operator[](int index) const;
bool lookupValue(const char *name, bool &value) const throw();
bool lookupValue(const char *name, int &value) const throw();
......@@ -388,11 +385,10 @@ class LIBCONFIGXX_API Config
void readFile(const char *filename) throw(FileIOException, ParseException);
void writeFile(const char *filename) throw(FileIOException);
inline Setting & lookup(const std::string &path) const
throw(SettingNotFoundException)
{ return(lookup(path.c_str())); }
Setting & lookup(const std::string &path) const;
Setting & lookup(const char *path) const throw(SettingNotFoundException);
inline Setting & operator[](const char *path) const
{ return(lookup(path)); }
inline bool exists(const std::string & path) const throw()
{ return(exists(path.c_str())); }
......
......@@ -446,12 +446,11 @@ void Config::writeFile(const char *filename) throw(FileIOException)
// ---------------------------------------------------------------------------
Setting & Config::lookup(const char *path) const
throw(SettingNotFoundException)
Setting & Config::lookup(const std::string &path) const
{
config_setting_t *s = config_lookup(_config, path);
config_setting_t *s = config_lookup(_config, path.c_str());
if(! s)
throw SettingNotFoundException(path);
throw SettingNotFoundException(path.c_str());
return(Setting::wrapSetting(s));
}
......@@ -834,31 +833,29 @@ Setting & Setting::operator=(const std::string &value)
// ---------------------------------------------------------------------------
Setting & Setting::operator[](int i) const
throw(SettingTypeException, SettingNotFoundException)
Setting & Setting::lookup(const std::string &key) const
{
if((_type != TypeArray) && (_type != TypeGroup) && (_type != TypeList))
throw SettingTypeException(*this, i);
assertType(TypeGroup);
config_setting_t *setting = config_setting_get_elem(_setting, i);
config_setting_t *setting = config_setting_get_member(_setting, key.c_str());
if(! setting)
throw SettingNotFoundException(*this, i);
throw SettingNotFoundException(*this, key.c_str());
return(wrapSetting(setting));
}
// ---------------------------------------------------------------------------
Setting & Setting::operator[](const char *key) const
throw(SettingTypeException, SettingNotFoundException)
Setting & Setting::operator[](int i) const
{
assertType(TypeGroup);
if((_type != TypeArray) && (_type != TypeGroup) && (_type != TypeList))
throw SettingTypeException(*this, i);
config_setting_t *setting = config_setting_get_member(_setting, key);
config_setting_t *setting = config_setting_get_elem(_setting, i);
if(! setting)
throw SettingNotFoundException(*this, key);
throw SettingNotFoundException(*this, i);
return(wrapSetting(setting));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment