| libconfig.h++ | | libconfig.h++ | |
| /* ------------------------------------------------------------------------
---- | | /* ------------------------------------------------------------------------
---- | |
|
| libconfig - A structured configuration file parsing library | | libconfig - A library for processing structured configuration files | |
| Copyright (C) 2005-2007 Mark A Lindner | | Copyright (C) 2005-2008 Mark A Lindner | |
| | | | |
| This file is part of libconfig. | | This file is part of libconfig. | |
| | | | |
| This library is free software; you can redistribute it and/or | | This library is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Lesser General Public License | | modify it under the terms of the GNU Lesser General Public License | |
| as published by the Free Software Foundation; either version 2.1 of | | as published by the Free Software Foundation; either version 2.1 of | |
| the License, or (at your option) any later version. | | the License, or (at your option) any later version. | |
| | | | |
| This library is distributed in the hope that it will be useful, but | | This library is distributed in the hope that it will be useful, but | |
| WITHOUT ANY WARRANTY; without even the implied warranty of | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| Lesser General Public License for more details. | | Lesser General Public License for more details. | |
| | | | |
|
| You should have received a copy of the GNU Lesser General Public | | You should have received a copy of the GNU Library General Public | |
| License along with this library; if not, write to the Free Software | | License along with this library; if not, see | |
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | | <http://www.gnu.org/licenses/>. | |
| ------------------------------------------------------------------------
---- | | ------------------------------------------------------------------------
---- | |
| */ | | */ | |
| | | | |
| #ifndef __libconfig_hpp | | #ifndef __libconfig_hpp | |
| #define __libconfig_hpp | | #define __libconfig_hpp | |
| | | | |
| #include <stdio.h> | | #include <stdio.h> | |
| #include <string> | | #include <string> | |
| #include <map> | | #include <map> | |
| | | | |
| namespace libconfig | | namespace libconfig | |
| { | | { | |
| | | | |
|
| #include "libconfig.h" | | #include <libconfig.h> | |
| | | | |
|
| class LIBCONFIG_API ConfigException { }; | | class LIBCONFIG_API ConfigException : public std::exception { }; | |
| | | | |
|
| class LIBCONFIG_API SettingTypeException : public ConfigException { }; | | class Setting; // fwd decl | |
| | | | |
|
| class LIBCONFIG_API SettingNotFoundException : public ConfigException { }
; | | class LIBCONFIG_API SettingException : public ConfigException | |
| | | { | |
| | | friend class Config; | |
| | | | |
|
| class LIBCONFIG_API SettingExistsException : public ConfigException { }; | | public: | |
| | | | |
|
| class LIBCONFIG_API FileIOException : public ConfigException { }; | | SettingException(const SettingException &other); | |
| | | SettingException& operator=(const SettingException &other); | |
| | | | |
|
| class LIBCONFIG_API ParseException : public ConfigException | | virtual ~SettingException() throw(); | |
| | | | |
| | | const char *getPath() const; | |
| | | | |
| | | virtual const char *what() const throw(); | |
| | | | |
| | | protected: | |
| | | | |
| | | SettingException(const Setting &setting); | |
| | | SettingException(const Setting &setting, int idx); | |
| | | SettingException(const Setting &setting, const char *name); | |
| | | SettingException(const char *path); | |
| | | | |
| | | private: | |
| | | | |
| | | char *_path; | |
| | | }; | |
| | | | |
| | | class LIBCONFIG_API SettingTypeException : public SettingException | |
| { | | { | |
| friend class Config; | | friend class Config; | |
|
| | | friend class Setting; | |
| | | | |
| | | const char *what() const throw(); | |
| | | | |
| private: | | private: | |
| | | | |
|
| int _line; | | SettingTypeException(const Setting &setting); | |
| const char *_error; | | SettingTypeException(const Setting &setting, int idx); | |
| | | SettingTypeException(const Setting &setting, const char *name); | |
| | | }; | |
| | | | |
|
| ParseException(int line, const char *error) | | class LIBCONFIG_API SettingNotFoundException : public SettingException | |
| : _line(line), _error(error) {} | | { | |
| | | friend class Config; | |
| | | friend class Setting; | |
| | | | |
| | | const char *what() const throw(); | |
| | | | |
| | | private: | |
| | | | |
| | | SettingNotFoundException(const Setting &setting, int idx); | |
| | | SettingNotFoundException(const Setting &setting, const char *name); | |
| | | SettingNotFoundException(const char *path); | |
| | | }; | |
| | | | |
| | | class LIBCONFIG_API SettingNameException : public SettingException | |
| | | { | |
| | | friend class Config; | |
| | | friend class Setting; | |
| | | | |
| | | const char *what() const throw(); | |
| | | | |
| | | private: | |
| | | | |
| | | SettingNameException(const Setting &setting, const char *name); | |
| | | }; | |
| | | | |
| | | class LIBCONFIG_API FileIOException : public ConfigException | |
| | | { | |
| | | const char *what() const throw(); | |
| | | }; | |
| | | | |
| | | class LIBCONFIG_API ParseException : public ConfigException | |
| | | { | |
| | | friend class Config; | |
| | | | |
| public: | | public: | |
| | | | |
|
| virtual ~ParseException() { } | | virtual ~ParseException() throw(); | |
| | | | |
|
| inline int getLine() throw() { return(_line); } | | inline int getLine() throw() | |
| inline const char *getError() throw() { return(_error); } | | { return(_line); } | |
| | | | |
| | | inline const char *getError() throw() | |
| | | { return(_error); } | |
| | | | |
| | | const char *what() const throw(); | |
| | | | |
| | | private: | |
| | | | |
| | | ParseException(int line, const char *error); | |
| | | | |
| | | int _line; | |
| | | const char *_error; | |
| }; | | }; | |
| | | | |
| class LIBCONFIG_API Setting | | class LIBCONFIG_API Setting | |
| { | | { | |
| friend class Config; | | friend class Config; | |
| | | | |
| public: | | public: | |
| | | | |
| enum Type | | enum Type | |
| { | | { | |
| TypeNone = 0, | | TypeNone = 0, | |
| // scalar types | | // scalar types | |
| TypeInt, | | TypeInt, | |
|
| | | TypeInt64, | |
| TypeFloat, | | TypeFloat, | |
| TypeString, | | TypeString, | |
| TypeBoolean, | | TypeBoolean, | |
| // aggregate types | | // aggregate types | |
| TypeGroup, | | TypeGroup, | |
| TypeArray, | | TypeArray, | |
| TypeList | | TypeList | |
| }; | | }; | |
| | | | |
| enum Format | | enum Format | |
| | | | |
| skipping to change at line 120 | | skipping to change at line 191 | |
| inline Type getType() const throw() { return(_type); } | | inline Type getType() const throw() { return(_type); } | |
| | | | |
| inline Format getFormat() const throw() { return(_format); } | | inline Format getFormat() const throw() { return(_format); } | |
| void setFormat(Format format) throw(); | | void setFormat(Format format) throw(); | |
| | | | |
| operator bool() const throw(SettingTypeException); | | operator bool() const throw(SettingTypeException); | |
| operator long() const throw(SettingTypeException); | | operator long() const throw(SettingTypeException); | |
| operator unsigned long() const throw(SettingTypeException); | | operator unsigned long() const throw(SettingTypeException); | |
| operator int() const throw(SettingTypeException); | | operator int() const throw(SettingTypeException); | |
| operator unsigned int() const throw(SettingTypeException); | | operator unsigned int() const throw(SettingTypeException); | |
|
| | | operator long long() const throw(SettingTypeException); | |
| | | operator unsigned long long() const throw(SettingTypeException); | |
| operator double() const throw(SettingTypeException); | | operator double() const throw(SettingTypeException); | |
| operator float() const throw(SettingTypeException); | | operator float() const throw(SettingTypeException); | |
| operator const char *() const throw(SettingTypeException); | | operator const char *() const throw(SettingTypeException); | |
| operator std::string() const throw(SettingTypeException); | | operator std::string() const throw(SettingTypeException); | |
| | | | |
| Setting & operator=(bool value) throw(SettingTypeException); | | Setting & operator=(bool value) throw(SettingTypeException); | |
| Setting & operator=(long value) throw(SettingTypeException); | | Setting & operator=(long value) throw(SettingTypeException); | |
| Setting & operator=(int value) throw(SettingTypeException); | | Setting & operator=(int value) throw(SettingTypeException); | |
|
| | | Setting & operator=(const long long &value) throw(SettingTypeException)
; | |
| Setting & operator=(const double &value) throw(SettingTypeException); | | Setting & operator=(const double &value) throw(SettingTypeException); | |
| Setting & operator=(float value) throw(SettingTypeException); | | Setting & operator=(float value) throw(SettingTypeException); | |
| Setting & operator=(const char *value) throw(SettingTypeException); | | Setting & operator=(const char *value) throw(SettingTypeException); | |
| Setting & operator=(const std::string &value) throw(SettingTypeExceptio
n); | | Setting & operator=(const std::string &value) throw(SettingTypeExceptio
n); | |
| | | | |
| Setting & operator[](const char * key) const | | Setting & operator[](const char * key) const | |
| throw(SettingTypeException, SettingNotFoundException); | | throw(SettingTypeException, SettingNotFoundException); | |
| | | | |
| inline Setting & operator[](const std::string & key) const | | inline Setting & operator[](const std::string & key) const | |
| throw(SettingTypeException, SettingNotFoundException) | | throw(SettingTypeException, SettingNotFoundException) | |
| { return(operator[](key.c_str())); } | | { return(operator[](key.c_str())); } | |
| | | | |
| Setting & operator[](int index) const | | Setting & operator[](int index) const | |
| throw(SettingTypeException, SettingNotFoundException); | | throw(SettingTypeException, SettingNotFoundException); | |
| | | | |
| bool lookupValue(const char *name, bool &value) const throw(); | | bool lookupValue(const char *name, bool &value) const throw(); | |
| bool lookupValue(const char *name, long &value) const throw(); | | bool lookupValue(const char *name, long &value) const throw(); | |
| bool lookupValue(const char *name, unsigned long &value) const throw(); | | bool lookupValue(const char *name, unsigned long &value) const throw(); | |
| bool lookupValue(const char *name, int &value) const throw(); | | bool lookupValue(const char *name, int &value) const throw(); | |
| bool lookupValue(const char *name, unsigned int &value) const throw(); | | bool lookupValue(const char *name, unsigned int &value) const throw(); | |
|
| | | bool lookupValue(const char *name, long long &value) const throw(); | |
| | | bool lookupValue(const char *name, unsigned long long &value) | |
| | | const throw(); | |
| bool lookupValue(const char *name, double &value) const throw(); | | bool lookupValue(const char *name, double &value) const throw(); | |
| bool lookupValue(const char *name, float &value) const throw(); | | bool lookupValue(const char *name, float &value) const throw(); | |
| bool lookupValue(const char *name, const char *&value) const throw(); | | bool lookupValue(const char *name, const char *&value) const throw(); | |
| bool lookupValue(const char *name, std::string &value) const throw(); | | bool lookupValue(const char *name, std::string &value) const throw(); | |
| | | | |
| inline bool lookupValue(const std::string &name, bool &value) | | inline bool lookupValue(const std::string &name, bool &value) | |
| const throw() | | const throw() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
|
| inline bool lookupValue(const std::string &name, long &value) const thr
ow() | | inline bool lookupValue(const std::string &name, long &value) | |
| | | const throw() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &name, unsigned long &value) | | inline bool lookupValue(const std::string &name, unsigned long &value) | |
| const throw() | | const throw() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &name, int &value) const thro
w() | | inline bool lookupValue(const std::string &name, int &value) const thro
w() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &name, unsigned int &value) | | inline bool lookupValue(const std::string &name, unsigned int &value) | |
| const throw() | | const throw() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
|
| | | inline bool lookupValue(const std::string &name, long long &value) | |
| | | const throw() | |
| | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| | | inline bool lookupValue(const std::string &name, | |
| | | unsigned long long &value) const throw() | |
| | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &name, double &value) const | | inline bool lookupValue(const std::string &name, double &value) const | |
| throw() | | throw() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &name, float &value) const | | inline bool lookupValue(const std::string &name, float &value) const | |
| throw() | | throw() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &name, const char *&value) co
nst | | inline bool lookupValue(const std::string &name, const char *&value) co
nst | |
| throw() | | throw() | |
| | | | |
| skipping to change at line 194 | | skipping to change at line 280 | |
| throw() | | throw() | |
| { return(lookupValue(name.c_str(), value)); } | | { return(lookupValue(name.c_str(), value)); } | |
| | | | |
| void remove(const char *name) | | void remove(const char *name) | |
| throw(SettingTypeException, SettingNotFoundException); | | throw(SettingTypeException, SettingNotFoundException); | |
| | | | |
| inline void remove(const std::string & name) | | inline void remove(const std::string & name) | |
| throw(SettingTypeException, SettingNotFoundException) | | throw(SettingTypeException, SettingNotFoundException) | |
| { remove(name.c_str()); } | | { remove(name.c_str()); } | |
| | | | |
|
| | | void remove(unsigned int idx) | |
| | | throw(SettingTypeException, SettingNotFoundException); | |
| | | | |
| inline Setting & add(const std::string & name, Type type) | | inline Setting & add(const std::string & name, Type type) | |
|
| throw(SettingTypeException, SettingExistsException) | | throw(SettingNameException, SettingTypeException) | |
| { return(add(name.c_str(), type)); } | | { return(add(name.c_str(), type)); } | |
| | | | |
| Setting & add(const char *name, Type type) | | Setting & add(const char *name, Type type) | |
|
| throw(SettingTypeException, SettingExistsException); | | throw(SettingNameException, SettingTypeException); | |
| | | | |
| Setting & add(Type type) | | Setting & add(Type type) | |
| throw(SettingTypeException); | | throw(SettingTypeException); | |
| | | | |
| inline bool exists(const std::string & name) const throw() | | inline bool exists(const std::string & name) const throw() | |
| { return(exists(name.c_str())); } | | { return(exists(name.c_str())); } | |
| | | | |
| bool exists(const char *name) const throw(); | | bool exists(const char *name) const throw(); | |
| | | | |
| int getLength() const throw(); | | int getLength() const throw(); | |
| const char *getName() const throw(); | | const char *getName() const throw(); | |
|
| | | std::string getPath() const; | |
| | | int getIndex() const throw(); | |
| | | | |
| | | const Setting & getParent() const throw(SettingNotFoundException); | |
| | | Setting & getParent() throw(SettingNotFoundException); | |
| | | | |
| | | bool isRoot() const throw(); | |
| | | | |
| inline bool isGroup() const throw() | | inline bool isGroup() const throw() | |
| { return(_type == TypeGroup); } | | { return(_type == TypeGroup); } | |
| | | | |
| inline bool isArray() const throw() | | inline bool isArray() const throw() | |
| { return(_type == TypeArray); } | | { return(_type == TypeArray); } | |
| | | | |
| inline bool isList() const throw() | | inline bool isList() const throw() | |
| { return(_type == TypeList); } | | { return(_type == TypeList); } | |
| | | | |
| inline bool isAggregate() const throw() | | inline bool isAggregate() const throw() | |
| { return(_type >= TypeGroup); } | | { return(_type >= TypeGroup); } | |
| | | | |
| inline bool isScalar() const throw() | | inline bool isScalar() const throw() | |
| { return((_type > TypeNone) && (_type < TypeGroup)); } | | { return((_type > TypeNone) && (_type < TypeGroup)); } | |
| | | | |
| inline bool isNumber() const throw() | | inline bool isNumber() const throw() | |
|
| { return((_type == TypeInt) || (_type == TypeFloat)); } | | { return((_type == TypeInt) || (_type == TypeInt64) | |
| | | || (_type == TypeFloat)); } | |
| | | | |
| inline unsigned int getSourceLine() const throw() | | inline unsigned int getSourceLine() const throw() | |
| { return(config_setting_source_line(_setting)); } | | { return(config_setting_source_line(_setting)); } | |
| }; | | }; | |
| | | | |
| class LIBCONFIG_API Config | | class LIBCONFIG_API Config | |
| { | | { | |
| private: | | private: | |
| | | | |
| config_t _config; | | config_t _config; | |
| | | | |
| skipping to change at line 275 | | skipping to change at line 372 | |
| inline bool exists(const std::string & path) const throw() | | inline bool exists(const std::string & path) const throw() | |
| { return(exists(path.c_str())); } | | { return(exists(path.c_str())); } | |
| | | | |
| bool exists(const char *path) const throw(); | | bool exists(const char *path) const throw(); | |
| | | | |
| bool lookupValue(const char *path, bool &value) const throw(); | | bool lookupValue(const char *path, bool &value) const throw(); | |
| bool lookupValue(const char *path, long &value) const throw(); | | bool lookupValue(const char *path, long &value) const throw(); | |
| bool lookupValue(const char *path, unsigned long &value) const throw(); | | bool lookupValue(const char *path, unsigned long &value) const throw(); | |
| bool lookupValue(const char *path, int &value) const throw(); | | bool lookupValue(const char *path, int &value) const throw(); | |
| bool lookupValue(const char *path, unsigned int &value) const throw(); | | bool lookupValue(const char *path, unsigned int &value) const throw(); | |
|
| | | bool lookupValue(const char *path, long long &value) const throw(); | |
| | | bool lookupValue(const char *path, unsigned long long &value) | |
| | | const throw(); | |
| bool lookupValue(const char *path, double &value) const throw(); | | bool lookupValue(const char *path, double &value) const throw(); | |
| bool lookupValue(const char *path, float &value) const throw(); | | bool lookupValue(const char *path, float &value) const throw(); | |
| bool lookupValue(const char *path, const char *&value) const throw(); | | bool lookupValue(const char *path, const char *&value) const throw(); | |
| bool lookupValue(const char *path, std::string &value) const throw(); | | bool lookupValue(const char *path, std::string &value) const throw(); | |
| | | | |
| inline bool lookupValue(const std::string &path, bool &value) | | inline bool lookupValue(const std::string &path, bool &value) | |
| const throw() | | const throw() | |
| { return(lookupValue(path.c_str(), value)); } | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
|
| inline bool lookupValue(const std::string &path, long &value) const thr
ow() | | inline bool lookupValue(const std::string &path, long &value) | |
| | | const throw() | |
| { return(lookupValue(path.c_str(), value)); } | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &path, unsigned long &value) | | inline bool lookupValue(const std::string &path, unsigned long &value) | |
| const throw() | | const throw() | |
| { return(lookupValue(path.c_str(), value)); } | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &path, int &value) const thro
w() | | inline bool lookupValue(const std::string &path, int &value) const thro
w() | |
| { return(lookupValue(path.c_str(), value)); } | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &path, unsigned int &value) | | inline bool lookupValue(const std::string &path, unsigned int &value) | |
| const throw() | | const throw() | |
| { return(lookupValue(path.c_str(), value)); } | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
|
| | | inline bool lookupValue(const std::string &path, long long &value) | |
| | | const throw() | |
| | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
| | | inline bool lookupValue(const std::string &path, | |
| | | unsigned long long &value) const throw() | |
| | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &path, double &value) const | | inline bool lookupValue(const std::string &path, double &value) const | |
| throw() | | throw() | |
| { return(lookupValue(path.c_str(), value)); } | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &path, float &value) const | | inline bool lookupValue(const std::string &path, float &value) const | |
| throw() | | throw() | |
| { return(lookupValue(path.c_str(), value)); } | | { return(lookupValue(path.c_str(), value)); } | |
| | | | |
| inline bool lookupValue(const std::string &path, const char *&value) co
nst | | inline bool lookupValue(const std::string &path, const char *&value) co
nst | |
| throw() | | throw() | |
| | | | |
End of changes. 28 change blocks. |
| 24 lines changed or deleted | | 133 lines changed or added | |
|