Classes |
struct | ConversionError |
struct | Exception |
| Base class for Config exceptions. More...
|
struct | FileNotFound |
struct | KeyNotFound |
Public Member Functions |
| Config (const string &delimiter="=", const string &comment="#") |
| Construct an empty Config.
|
| Config (const std::map< string, string > &options) |
| Construct a Config from the given map of options.
|
void | readFile (const string &filename) |
| Load a Config from a file.
|
template<class T = string> |
T | read (const string &key) const |
| Read the value corresponding to a key.
|
template<class T = string> |
T | read (const string &key, const T &value) const |
| Return the value corresponding to key or given default value if key is not found.
|
bool | keyExists (const string &key) const |
| Check whether key exists in configuration.
|
template<class T > |
void | set (const string &key, const T &value) |
| Set a key to the given value.
|
void | set (const string &key, const string &value) |
| Set a key to the given string value.
|
void | remove (const string &key) |
| Remove a key and its value.
|
Private Types |
typedef std::string | string |
Private Member Functions |
std::string | readLine (std::istream &is) const |
| Read a line, strip comments, and trim it.
|
Static Private Member Functions |
template<class T > |
static string | toString (const T &t) |
| Convert from a T to a string.
|
template<class T > |
static T | fromString (const string &key, const string &s) |
| Convert from a string to a T.
|
Private Attributes |
const string | delimiter |
| Separator between key and value, usually "=".
|
const string | comment |
| Starts a comment, usually "#".
|
std::map< string, string > | contents |
| Extracted keys and values.
|
Friends |
std::istream & | operator>> (std::istream &is, Config &cf) |
| Read configuration.
|
std::ostream & | operator<< (std::ostream &os, const Config &cf) |
| Write configuration.
|
Reads and writes configuration files.
Definition at line 61 of file Config.h.
Convert from a string to a T.
Type T must support >> operator.
For boolean conversions, "false", "f", "no", "n", "0" are false, and "true", "t", "yes", "y", "1" are true.
- Exceptions:
-
Definition at line 264 of file Config.cc.