diff options
Diffstat (limited to '')
-rw-r--r-- | lib/libconfigcpp.c++ | 441 |
1 files changed, 362 insertions, 79 deletions
diff --git a/lib/libconfigcpp.c++ b/lib/libconfigcpp.c++ index 6d196e7..af06fc5 100644 --- a/lib/libconfigcpp.c++ +++ b/lib/libconfigcpp.c++ @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- libconfig - A library for processing structured configuration files - Copyright (C) 2005-2010 Mark A Lindner + Copyright (C) 2005-2014 Mark A Lindner This file is part of libconfig. @@ -327,6 +327,20 @@ void Config::setAutoConvert(bool flag) // --------------------------------------------------------------------------- +void Config::setOptions(int options) +{ + config_set_options(_config, options); +} + +// --------------------------------------------------------------------------- + +int Config::getOptions() const +{ + return(config_get_options(_config)); +} + +// --------------------------------------------------------------------------- + bool Config::getAutoConvert() const { return(config_get_auto_convert(_config) != CONFIG_FALSE); @@ -346,28 +360,28 @@ void Config::setDefaultFormat(Setting::Format format) // --------------------------------------------------------------------------- -void Config::setTabWidth(unsigned short width) throw() +void Config::setTabWidth(unsigned short width) { config_set_tab_width(_config, width); } // --------------------------------------------------------------------------- -unsigned short Config::getTabWidth() const throw() +unsigned short Config::getTabWidth() const { return(config_get_tab_width(_config)); } // --------------------------------------------------------------------------- -void Config::setIncludeDir(const char *includeDir) throw() +void Config::setIncludeDir(const char *includeDir) { config_set_include_dir(_config, includeDir); } // --------------------------------------------------------------------------- -const char *Config::getIncludeDir() const throw() +const char *Config::getIncludeDir() const { return(config_get_include_dir(_config)); } @@ -395,7 +409,7 @@ void Config::handleError() const // --------------------------------------------------------------------------- -void Config::read(FILE *stream) throw(ParseException) +void Config::read(FILE *stream) { if(! config_read(_config, stream)) handleError(); @@ -403,7 +417,7 @@ void Config::read(FILE *stream) throw(ParseException) // --------------------------------------------------------------------------- -void Config::readString(const char *str) throw(ParseException) +void Config::readString(const char *str) { if(! config_read_string(_config, str)) handleError(); @@ -418,8 +432,7 @@ void Config::write(FILE *stream) const // --------------------------------------------------------------------------- -void Config::readFile(const char *filename) throw(FileIOException, - ParseException) +void Config::readFile(const char *filename) { if(! config_read_file(_config, filename)) handleError(); @@ -427,7 +440,7 @@ void Config::readFile(const char *filename) throw(FileIOException, // --------------------------------------------------------------------------- -void Config::writeFile(const char *filename) throw(FileIOException) +void Config::writeFile(const char *filename) { if(! config_write_file(_config, filename)) handleError(); @@ -436,7 +449,6 @@ void Config::writeFile(const char *filename) throw(FileIOException) // --------------------------------------------------------------------------- Setting & Config::lookup(const char *path) const - throw(SettingNotFoundException) { config_setting_t *s = config_lookup(_config, path); if(! s) @@ -447,7 +459,7 @@ Setting & Config::lookup(const char *path) const // --------------------------------------------------------------------------- -bool Config::exists(const char *path) const throw() +bool Config::exists(const char *path) const { config_setting_t *s = config_lookup(_config, path); @@ -470,64 +482,63 @@ bool Config::exists(const char *path) const throw() // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, bool &value) const throw() +bool Config::lookupValue(const char *path, bool &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, bool, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, int &value) const throw() +bool Config::lookupValue(const char *path, int &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, int, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, unsigned int &value) const throw() +bool Config::lookupValue(const char *path, unsigned int &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, unsigned int, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, long long &value) const throw() +bool Config::lookupValue(const char *path, long long &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, long long, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, unsigned long long &value) - const throw() +bool Config::lookupValue(const char *path, unsigned long long &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, unsigned long long, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, double &value) const throw() +bool Config::lookupValue(const char *path, double &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, double, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, float &value) const throw() +bool Config::lookupValue(const char *path, float &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, float, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, const char *&value) const throw() +bool Config::lookupValue(const char *path, const char *&value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, const char *, value); } // --------------------------------------------------------------------------- -bool Config::lookupValue(const char *path, std::string &value) const throw() +bool Config::lookupValue(const char *path, std::string &value) const { CONFIG_LOOKUP_NO_EXCEPTIONS(path, const char *, value); } @@ -599,14 +610,14 @@ Setting::Setting(config_setting_t *setting) // --------------------------------------------------------------------------- -Setting::~Setting() throw() +Setting::~Setting() { _setting = NULL; } // --------------------------------------------------------------------------- -void Setting::setFormat(Format format) throw() +void Setting::setFormat(Format format) { if((_type == TypeInt) || (_type == TypeInt64)) { @@ -623,7 +634,7 @@ void Setting::setFormat(Format format) throw() // --------------------------------------------------------------------------- -Setting::operator bool() const throw(SettingTypeException) +Setting::operator bool() const { assertType(TypeBoolean); @@ -632,7 +643,7 @@ Setting::operator bool() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator int() const throw(SettingTypeException) +Setting::operator int() const { assertType(TypeInt); @@ -641,7 +652,7 @@ Setting::operator int() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator unsigned int() const throw(SettingTypeException) +Setting::operator unsigned int() const { assertType(TypeInt); @@ -655,7 +666,7 @@ Setting::operator unsigned int() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator long() const throw(SettingTypeException) +Setting::operator long() const { if(sizeof(long) == sizeof(long long)) return operator long long(); @@ -665,7 +676,7 @@ Setting::operator long() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator unsigned long() const throw(SettingTypeException) +Setting::operator unsigned long() const { if(sizeof(long) == sizeof(long long)) return operator unsigned long long(); @@ -675,7 +686,7 @@ Setting::operator unsigned long() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator long long() const throw(SettingTypeException) +Setting::operator long long() const { assertType(TypeInt64); @@ -684,7 +695,7 @@ Setting::operator long long() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator unsigned long long() const throw(SettingTypeException) +Setting::operator unsigned long long() const { assertType(TypeInt64); @@ -698,7 +709,7 @@ Setting::operator unsigned long long() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator double() const throw(SettingTypeException) +Setting::operator double() const { assertType(TypeFloat); @@ -707,7 +718,7 @@ Setting::operator double() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator float() const throw(SettingTypeException) +Setting::operator float() const { assertType(TypeFloat); @@ -717,7 +728,7 @@ Setting::operator float() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator const char *() const throw(SettingTypeException) +Setting::operator const char *() const { assertType(TypeString); @@ -726,7 +737,7 @@ Setting::operator const char *() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting::operator std::string() const throw(SettingTypeException) +Setting::operator std::string() const { assertType(TypeString); @@ -741,7 +752,7 @@ Setting::operator std::string() const throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting & Setting::operator=(bool value) throw(SettingTypeException) +Setting & Setting::operator=(bool value) { assertType(TypeBoolean); @@ -752,7 +763,7 @@ Setting & Setting::operator=(bool value) throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting & Setting::operator=(int value) throw(SettingTypeException) +Setting & Setting::operator=(int value) { assertType(TypeInt); @@ -763,7 +774,7 @@ Setting & Setting::operator=(int value) throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting & Setting::operator=(long value) throw(SettingTypeException) +Setting & Setting::operator=(long value) { if(sizeof(long) == sizeof(long long)) return(operator=(static_cast<long long>(value))); @@ -774,7 +785,6 @@ Setting & Setting::operator=(long value) throw(SettingTypeException) // --------------------------------------------------------------------------- Setting & Setting::operator=(const long long &value) - throw(SettingTypeException) { assertType(TypeInt64); @@ -785,7 +795,7 @@ Setting & Setting::operator=(const long long &value) // --------------------------------------------------------------------------- -Setting & Setting::operator=(const double &value) throw(SettingTypeException) +Setting & Setting::operator=(const double &value) { assertType(TypeFloat); @@ -796,7 +806,7 @@ Setting & Setting::operator=(const double &value) throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting & Setting::operator=(float value) throw(SettingTypeException) +Setting & Setting::operator=(float value) { assertType(TypeFloat); @@ -809,7 +819,7 @@ Setting & Setting::operator=(float value) throw(SettingTypeException) // --------------------------------------------------------------------------- -Setting & Setting::operator=(const char *value) throw(SettingTypeException) +Setting & Setting::operator=(const char *value) { assertType(TypeString); @@ -821,7 +831,6 @@ Setting & Setting::operator=(const char *value) throw(SettingTypeException) // --------------------------------------------------------------------------- Setting & Setting::operator=(const std::string &value) - throw(SettingTypeException) { assertType(TypeString); @@ -832,31 +841,43 @@ Setting & Setting::operator=(const std::string &value) // --------------------------------------------------------------------------- -Setting & Setting::operator[](int i) const - throw(SettingTypeException, SettingNotFoundException) +Setting & Setting::lookup(const char *path) 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_lookup(_setting, path); if(! setting) - throw SettingNotFoundException(*this, i); + throw SettingNotFoundException(*this, path); return(wrapSetting(setting)); } // --------------------------------------------------------------------------- -Setting & Setting::operator[](const char *key) const - throw(SettingTypeException, SettingNotFoundException) +Setting & Setting::operator[](const char *name) const { assertType(TypeGroup); - config_setting_t *setting = config_setting_get_member(_setting, key); + config_setting_t *setting = config_setting_get_member(_setting, name); if(! setting) - throw SettingNotFoundException(*this, key); + throw SettingNotFoundException(*this, name); + + return(wrapSetting(setting)); +} + +// --------------------------------------------------------------------------- + +Setting & Setting::operator[](int i) const +{ + if((_type != TypeArray) && (_type != TypeGroup) && (_type != TypeList)) + throw SettingTypeException(*this, i); + + config_setting_t *setting = config_setting_get_elem(_setting, i); + + if(! setting) + throw SettingNotFoundException(*this, i); return(wrapSetting(setting)); } @@ -877,72 +898,70 @@ Setting & Setting::operator[](const char *key) const // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, bool &value) const throw() +bool Setting::lookupValue(const char *name, bool &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, bool, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, int &value) const throw() +bool Setting::lookupValue(const char *name, int &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, int, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, unsigned int &value) - const throw() +bool Setting::lookupValue(const char *name, unsigned int &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, unsigned int, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, long long &value) const throw() +bool Setting::lookupValue(const char *name, long long &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, long long, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, unsigned long long &value) - const throw() +bool Setting::lookupValue(const char *name, unsigned long long &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, unsigned long long, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, double &value) const throw() +bool Setting::lookupValue(const char *name, double &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, double, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, float &value) const throw() +bool Setting::lookupValue(const char *name, float &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, float, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, const char *&value) const throw() +bool Setting::lookupValue(const char *name, const char *&value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, const char *, value); } // --------------------------------------------------------------------------- -bool Setting::lookupValue(const char *name, std::string &value) const throw() +bool Setting::lookupValue(const char *name, std::string &value) const { SETTING_LOOKUP_NO_EXCEPTIONS(name, const char *, value); } // --------------------------------------------------------------------------- -bool Setting::exists(const char *name) const throw() +bool Setting::exists(const char *name) const { if(_type != TypeGroup) return(false); @@ -954,14 +973,14 @@ bool Setting::exists(const char *name) const throw() // --------------------------------------------------------------------------- -int Setting::getLength() const throw() +int Setting::getLength() const { return(config_setting_length(_setting)); } // --------------------------------------------------------------------------- -const char * Setting::getName() const throw() +const char * Setting::getName() const { return(config_setting_name(_setting)); } @@ -979,7 +998,7 @@ std::string Setting::getPath() const // --------------------------------------------------------------------------- -const Setting & Setting::getParent() const throw(SettingNotFoundException) +const Setting & Setting::getParent() const { config_setting_t *setting = config_setting_parent(_setting); @@ -991,7 +1010,7 @@ const Setting & Setting::getParent() const throw(SettingNotFoundException) // --------------------------------------------------------------------------- -Setting & Setting::getParent() throw(SettingNotFoundException) +Setting & Setting::getParent() { config_setting_t *setting = config_setting_parent(_setting); @@ -1003,28 +1022,28 @@ Setting & Setting::getParent() throw(SettingNotFoundException) // --------------------------------------------------------------------------- -unsigned int Setting::getSourceLine() const throw() +unsigned int Setting::getSourceLine() const { return(config_setting_source_line(_setting)); } // --------------------------------------------------------------------------- -const char *Setting::getSourceFile() const throw() +const char *Setting::getSourceFile() const { return(config_setting_source_file(_setting)); } // --------------------------------------------------------------------------- -bool Setting::isRoot() const throw() +bool Setting::isRoot() const { return(config_setting_is_root(_setting)); } // --------------------------------------------------------------------------- -int Setting::getIndex() const throw() +int Setting::getIndex() const { return(config_setting_index(_setting)); } @@ -1032,7 +1051,6 @@ int Setting::getIndex() const throw() // --------------------------------------------------------------------------- void Setting::remove(const char *name) - throw(SettingTypeException, SettingNotFoundException) { assertType(TypeGroup); @@ -1043,7 +1061,6 @@ void Setting::remove(const char *name) // --------------------------------------------------------------------------- void Setting::remove(unsigned int idx) - throw(SettingTypeException, SettingNotFoundException) { if((_type != TypeArray) && (_type != TypeGroup) && (_type != TypeList)) throw SettingTypeException(*this, idx); @@ -1055,7 +1072,6 @@ void Setting::remove(unsigned int idx) // --------------------------------------------------------------------------- Setting & Setting::add(const char *name, Setting::Type type) - throw(SettingNameException, SettingTypeException) { assertType(TypeGroup); @@ -1074,7 +1090,7 @@ Setting & Setting::add(const char *name, Setting::Type type) // --------------------------------------------------------------------------- -Setting & Setting::add(Setting::Type type) throw(SettingTypeException) +Setting & Setting::add(Setting::Type type) { if((_type != TypeArray) && (_type != TypeList)) throw SettingTypeException(*this); @@ -1134,7 +1150,7 @@ Setting & Setting::add(Setting::Type type) throw(SettingTypeException) // --------------------------------------------------------------------------- -void Setting::assertType(Setting::Type type) const throw(SettingTypeException) +void Setting::assertType(Setting::Type type) const { if(type != _type) { @@ -1164,6 +1180,273 @@ Setting & Setting::wrapSetting(config_setting_t *s) // --------------------------------------------------------------------------- +Setting::iterator Setting::begin() +{ return(iterator(*this)); } + +// --------------------------------------------------------------------------- + +Setting::iterator Setting::end() +{ return(iterator(*this, true)); } + +// --------------------------------------------------------------------------- + +Setting::const_iterator Setting::begin() const +{ return(const_iterator(*this)); } + +// --------------------------------------------------------------------------- + +Setting::const_iterator Setting::end() const +{ return(const_iterator(*this, true)); } + +// --------------------------------------------------------------------------- + +SettingIterator::SettingIterator(Setting& setting, bool endIterator) + : _setting(&setting), + _count(setting.getLength()), + _idx(endIterator ? _count : 0) +{ + if(!setting.isAggregate()) + throw SettingTypeException(setting); +} + +// --------------------------------------------------------------------------- + +SettingIterator::SettingIterator(const SettingIterator &other) + : _setting(other._setting), + _count(other._count), + _idx(other._idx) +{ +} + +// --------------------------------------------------------------------------- + +SettingIterator& SettingIterator::operator=(const SettingIterator &other) +{ + _setting = other._setting; + _count = other._count; + _idx = other._idx; + + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingIterator& SettingIterator::operator++() +{ + ++_idx; + + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingIterator SettingIterator::operator++(int) +{ + SettingIterator tmp(*this); + ++_idx; + + return(tmp); +} + +// --------------------------------------------------------------------------- + +SettingIterator& SettingIterator::operator--() +{ + --_idx; + + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingIterator SettingIterator::operator--(int) +{ + SettingIterator tmp(*this); + --_idx; + + return(tmp); +} + +// --------------------------------------------------------------------------- + +SettingIterator SettingIterator::operator+(int offset) const +{ + SettingIterator copy(*this); + copy += offset; + + return(copy); +} + +// --------------------------------------------------------------------------- + +SettingIterator& SettingIterator::operator+=(int offset) +{ + _idx += offset; + + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingIterator operator+(int offset, SettingIterator& si) +{ + SettingIterator copy(si); + copy += offset; + + return(copy); +} + +// --------------------------------------------------------------------------- + +SettingIterator SettingIterator::operator-(int offset) const +{ + SettingIterator copy(*this); + copy._idx -= offset; + + return(copy); +} + +// --------------------------------------------------------------------------- + +SettingIterator& SettingIterator::operator-=(int offset) +{ + _idx -= offset; + + return(*this); +} + +// --------------------------------------------------------------------------- + +int SettingIterator::operator-(SettingIterator const &other) const +{ + return(_idx - other._idx); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator::SettingConstIterator(const Setting &setting, + bool endIterator) + : _setting(&setting), + _count(setting.getLength()), + _idx(endIterator ? _count : 0) +{ + if(!setting.isAggregate()) + throw SettingTypeException(setting); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator::SettingConstIterator(const SettingConstIterator &other) + : _setting(other._setting), + _count(other._count), + _idx(other._idx) +{ +} + +// --------------------------------------------------------------------------- + +SettingConstIterator& SettingConstIterator::operator=( + const SettingConstIterator &other) +{ + _setting = other._setting; + _count = other._count; + _idx = other._idx; + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator& SettingConstIterator::operator++() +{ + ++_idx; + + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator SettingConstIterator::operator++(int) +{ + SettingConstIterator tmp(*this); + ++_idx; + + return(tmp); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator& SettingConstIterator::operator--() +{ + --_idx; + + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator SettingConstIterator::operator--(int) +{ + SettingConstIterator tmp(*this); + --_idx; + + return(tmp); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator SettingConstIterator::operator+(int offset) const +{ + SettingConstIterator copy(*this); + copy += offset; + + return(copy); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator& SettingConstIterator::operator+=(int offset) +{ + _idx += offset; + + return(*this); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator operator+(int offset, SettingConstIterator &si) +{ + SettingConstIterator copy(si); + copy += offset; + + return(copy); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator SettingConstIterator::operator-(int offset) const +{ + SettingConstIterator copy(*this); + copy -= offset; + + return(copy); +} + +// --------------------------------------------------------------------------- + +SettingConstIterator& SettingConstIterator::operator-=(int offset) +{ + _idx -= offset; + + return(*this); +} + +// --------------------------------------------------------------------------- + +int SettingConstIterator::operator-(SettingConstIterator const &other) const +{ + return(_idx - other._idx); +} + + } // namespace libconfig -// eof |