#include <configuration.h>
Public Types | |
typedef std::vector< Option > | OptionList |
typedef std::vector< OptionEntry > | EntryList |
Public Member Functions | |
Configuration () | |
~Configuration () | |
void | addOption (const Option &) |
Add an option to the internal list. | |
bool | setCommandLine (int argc, char **argv) |
Add an option to the internal list. | |
bool | hasKey (const std::string &key) const |
Check if key is in the parsed options. | |
std::string | value (const std::string &key) const |
Returns string representation of correponding value. | |
int | intValue (const std::string &key) const |
Returns correponding value as int. | |
bool | loadFile (const std::string &filename) |
Load a file. | |
void | setHelpText (const std::string &text) |
Set an additional help text. | |
std::string | helpText () const |
Return helptext containing all options. | |
void | printEntries () const |
Helper: Print commandline entries to stdout. | |
Protected Member Functions | |
int | findOption (const std::string &optionText) const |
Return index of given option. | |
int | findShort (const std::string &optionText) const |
Return index of given short option. | |
int | findLong (const std::string &optionText) const |
Return index of given long option. | |
int | findEntry (const std::string &key) const |
Return index in entries of given key. | |
void | insertEntry (const std::string &key, const std::string &value) |
Insert (or replace existing) key in entries. | |
Protected Attributes | |
OptionList | m_option |
List of known options. | |
EntryList | m_entry |
List of found options. | |
std::string | m_helpText |
Additional help text. | |
Classes | |
class | Option |
Description of a command line option. More... | |
class | OptionEntry |
Description of a given commandline option. More... |
Parse commandline parameters with setCommandLine. The parameter have to be in the GNU style short: -s or long: --long-parameter. The parameter are read from left to right. A key can only exist once. Duplicate keys override the previously defined. This class also can read configuration files containing key, value pairs separated with '='. The files my also contain comments. Lines beginning with '#' are treated as comments. Load files with loadFile.
Example:
##################################
# This is a comment
#
long-value = 2
string = "this is a string"
Definition at line 46 of file configuration.h.
|
Definition at line 110 of file configuration.h. |
|
Definition at line 109 of file configuration.h. |
|
Definition at line 25 of file configuration.cpp. |
|
Definition at line 29 of file configuration.cpp. |
|
Add an option to the internal list. Only options added through this function will be accepted by readFile and setCommandLine.
Definition at line 33 of file configuration.cpp. References m_option. Referenced by create_config(). |
|
Return index in entries of given key.
Definition at line 165 of file configuration.cpp. References m_entry. Referenced by insertEntry(). |
|
Return index of given long option.
Definition at line 148 of file configuration.cpp. References m_option. Referenced by findOption(). |
|
Return index of given option.
Definition at line 123 of file configuration.cpp. References findLong(), and findShort(). Referenced by loadFile(), and setCommandLine(). |
|
Return index of given short option.
Definition at line 131 of file configuration.cpp. References m_option. Referenced by findOption(). |
|
Check if key is in the parsed options.
Definition at line 177 of file configuration.cpp. References m_entry. |
|
Return helptext containing all options.
Definition at line 278 of file configuration.cpp. References m_option. |
|
Insert (or replace existing) key in entries.
Definition at line 109 of file configuration.cpp. References findEntry(), and m_entry. Referenced by loadFile(), and setCommandLine(). |
|
Returns correponding value as int.
Definition at line 202 of file configuration.cpp. References Util::fromString(), and value(). |
|
Load a file. Load a configuration file containing key, value pairs (or single keys). The keys must have been added with addOption before.
Definition at line 211 of file configuration.cpp. References findOption(), insertEntry(), m_option, Util::strip_whitespace(), and Util::tokenize(). |
|
Helper: Print commandline entries to stdout.
Definition at line 268 of file configuration.cpp. References m_entry. |
|
Add an option to the internal list. Only options added through this function will be accepted by readFile and setCommandLine.
Definition at line 38 of file configuration.cpp. References findOption(), insertEntry(), m_option, and Util::tokenize(). Referenced by main(). |
|
Set an additional help text.
Definition at line 139 of file configuration.h. References m_helpText. Referenced by create_config(). |
|
Returns string representation of correponding value.
Definition at line 188 of file configuration.cpp. References m_entry. Referenced by intValue(). |
|
List of found options.
Definition at line 151 of file configuration.h. Referenced by findEntry(), hasKey(), insertEntry(), printEntries(), and value(). |
|
Additional help text.
Definition at line 153 of file configuration.h. Referenced by setHelpText(). |
|
List of known options.
Definition at line 149 of file configuration.h. Referenced by addOption(), findLong(), findShort(), helpText(), loadFile(), and setCommandLine(). |