Configuration class. More...
#include <libppbase/base/Config.h>
Classes | |
class | Item |
A Configuration Item. More... | |
Public Types | |
enum | configFlags { flagNone = 0x00, flagKeep = 0x01, flagNeedNotExist = 0x02 } |
Config flags. More... | |
Public Member Functions | |
std::map< String, Item >::iterator | begin () |
Gets an iterator to the first configuration variable. | |
std::map< String, Item > ::const_iterator | begin () const |
Gets an iterator to the first configuration variable. | |
void | clear () |
Deletes the entire configuration. | |
void | clear (const String &var) |
Clears an array configuration variable. | |
std::map< String, Item >::iterator | end () |
Gets an iterator that points after the last configuration variable. | |
std::map< String, Item > ::const_iterator | end () const |
Gets an iterator that points after the last configuration variable. | |
void | erase (const String &var) |
Erases a configuration variable. | |
bool | exists (const String &var) const |
Check if a configuration variable exists. | |
const std::vector< String > & | getAll (const String &var) const |
Gets all items for an array variable. | |
bool | getBool (const String &var, size_t pos=0) const |
Returns a configuration variable as a boolean. | |
bool | getBool (const String &var, bool defval, size_t pos=0) const |
Returns a configuration variable as a boolean, returning a default value if it does not exist. | |
size_t | getCount (const String &var) const |
Returns the number of array items of a configuration variable. | |
const String & | getFileName () const |
Gets the file name of the last read configuration file. | |
int | getInt (const String &var, size_t pos=0) const |
Returns a configuration variable as an integer. | |
int | getInt (const String &var, int defval, size_t pos=0) const |
Returns a configuration variable as an integer, returning a default value if it does not exist. | |
const String & | getString (const String &var, size_t pos=0) const |
Returns a configuration variable as string. | |
const String & | getString (const String &var, const String &defval, size_t pos=0) const |
Returns a configuration variable as string, returning a default value if it does not exist. | |
std::vector< String > | getVectorOfStrings (const String &var, char delim= ',', size_t pos=0) const |
Returns a configuration variable as a vector of strings. | |
void | read (const String &fname, configFlags flags=flagNone) |
Reads a configuration file and stores all variables. | |
void | readUser (const String &company, const String &product, const String &id, configFlags flags=flagNone) |
Reads a configuration file from the user area and stores all variables. | |
void | setAll (const String &var, const std::vector< String > &val) |
Sets all items for an array variable. | |
void | setBool (const String &var, bool val, size_t pos=0) |
Sets a configuration variable. | |
void | setInt (const String &var, int val, size_t pos=0) |
Sets a configuration variable. | |
void | setString (const String &var, const String &val, size_t pos=0) |
Sets a configuration variable. | |
void | write () const |
Writes a configuration to the same file it was read from. | |
void | write (const String &fname) const |
Writes a configuration file. | |
void | writeUser (const String &company, const String &product, const String &id) const |
Writes a configuration file to the user area. | |
Static Public Member Functions | |
static bool | fileExists (const String &fname) |
Checks if a configuration file exists. | |
static bool | fileExistsUser (const String &company, const String &product, const String &id) |
Checks if a configuration file exists. | |
static String | mkFileName (const String &fname) |
Gets the filename of a configuration file. | |
static String | mkFileNameUser (const String &company, const String &product, const String &id) |
Gets the filename of a configuration file in the user area. |
Configuration class.
Config flags.
Gets an iterator to the first configuration variable.
Gets an iterator to the first configuration variable.
Gets an iterator that points after the last configuration variable.
Gets an iterator that points after the last configuration variable.
bool base::Config::exists | ( | const String & | var | ) | const |
Check if a configuration variable exists.
var | the name of the configuration variable |
bool base::Config::getBool | ( | const String & | var, | |
size_t | pos = 0 | |||
) | const |
Returns a configuration variable as a boolean.
var | the name of the configuration variable | |
pos | the array position |
bool base::Config::getBool | ( | const String & | var, | |
bool | defval, | |||
size_t | pos = 0 | |||
) | const |
Returns a configuration variable as a boolean, returning a default value if it does not exist.
var | the name of the configuration variable | |
defval | the defval value to return if the configuration variable does not exist | |
pos | the array position |
size_t base::Config::getCount | ( | const String & | var | ) | const |
Returns the number of array items of a configuration variable.
var | the name of the configuration variable |
const String& base::Config::getFileName | ( | ) | const |
Gets the file name of the last read configuration file.
int base::Config::getInt | ( | const String & | var, | |
size_t | pos = 0 | |||
) | const |
Returns a configuration variable as an integer.
var | the name of the configuration variable | |
pos | the array position |
int base::Config::getInt | ( | const String & | var, | |
int | defval, | |||
size_t | pos = 0 | |||
) | const |
Returns a configuration variable as an integer, returning a default value if it does not exist.
var | the name of the configuration variable | |
defval | the defval value to return if the configuration variable does not exist | |
pos | the array position |
Returns a configuration variable as string.
var | the name of the configuration variable | |
pos | the array position |
const String& base::Config::getString | ( | const String & | var, | |
const String & | defval, | |||
size_t | pos = 0 | |||
) | const |
Returns a configuration variable as string, returning a default value if it does not exist.
var | the name of the configuration variable | |
defval | the defval value to return if the configuration variable does not exist | |
pos | the array position |
std::vector<String> base::Config::getVectorOfStrings | ( | const String & | var, | |
char | delim = ',' , |
|||
size_t | pos = 0 | |||
) | const |
Returns a configuration variable as a vector of strings.
var | the name of the configuration variable | |
delim | the delimiter that separates the elements | |
pos | the array position |
static String base::Config::mkFileNameUser | ( | const String & | company, | |
const String & | product, | |||
const String & | id | |||
) | [static] |
Gets the filename of a configuration file in the user area.
The file name is created depending on the platform:
company | company name | |
product | product name | |
id | identifier from which the file name is built |
void base::Config::read | ( | const String & | fname, | |
configFlags | flags = flagNone | |||
) |
Reads a configuration file and stores all variables.
fname | the file name, absolute or relative to the global base directory | |
flags | keep/override settings |
void base::Config::readUser | ( | const String & | company, | |
const String & | product, | |||
const String & | id, | |||
configFlags | flags = flagNone | |||
) |
Reads a configuration file from the user area and stores all variables.
company | company name | |
product | product name | |
id | identifier from which the file name is built | |
flags | keep/override settings |
void base::Config::write | ( | const String & | fname | ) | const |
Writes a configuration file.
fname | the file name, absolute or relative to the global base directory |
void base::Config::writeUser | ( | const String & | company, | |
const String & | product, | |||
const String & | id | |||
) | const |
Writes a configuration file to the user area.
company | company name | |
product | product name | |
id | identifier from which the file name is built |