#include <mcs.hh>
This class can be used to read and write configuration files like those known as INI files in the Windows world.
Supported files can have sections (using the "[]" characters) and comments (from the "#" character to the new line).
Once the file have been parsed (by the constructor) values can be retrieved as STRING Data objects, as well as string or integers.
Definition at line 4858 of file mcs.hh.
Public Member Functions | |
Conf (string filename="") | |
Constructor, parse a configuration file. | |
Conf (const Conf &) | |
Declared to avoid using of default copy constructor. | |
int | ival (string section, string key, int defval) |
Search for the specified section/key value and return it as an integer. | |
int | ival (string section, string key) |
Search for the specified section/key value and return it as an integer. | |
long long int | lval (string section, string key, int defval) |
Search for the specified section/key value and return it as a long integer. | |
long long int | lval (string section, string key) |
Search for the specified section/key value and return it as a long integer. | |
void | open (string filename) |
Conf & | operator= (const Conf &) |
Declared to avoid using of default assignment operator. | |
void | save (string filename="") |
Save all the values in a configuration file. | |
bool | search (string section, string key, enum ThrowExceptions throwexc=DONT_THROW) |
Search for the specified section/key value. | |
void | setval (string section, string key, Data *val, string comment="") |
Set a new value for the specified section/key pair. | |
void | setval (string section, string key, int val, string comment="") |
Set a new value for the specified section/key pair. | |
void | setval (string section, string key, long long int val, string comment="") |
Set a new value for the specified section/key pair. | |
void | setval (string section, string key, string val, string comment="") |
Set a new value for the specified section/key pair. | |
string | sval (string section, string key, string defval) |
Search for the specified section/key value and return it as a string. | |
string | sval (string section, string key) |
Search for the specified section/key value and return it as a string. | |
Data & | val (string section="", string key="") |
Return a Data object containing the last value found. | |
~Conf () | |
Destructor. | |
Private Member Functions | |
int | index (string section, string key) |
Search the index at which section and key are found. | |
Private Attributes | |
vector< string > | comments |
Internal vector containing comments, this is used in the save() method. | |
string | filename |
Path to the configuration file. | |
vector< string > | keys |
Internal vector containing keys names. | |
Data | lastval |
vector< string > | sections |
Internal vector containing section names. | |
vector< string > | values |
Internal vector containing values names. |
mcs::Conf::Conf | ( | const Conf & | ) |
Declared to avoid using of default copy constructor.
mcs::Conf::Conf | ( | string | filename = "" |
) |
int mcs::Conf::index | ( | string | section, | |
string | key | |||
) | [private] |
int mcs::Conf::ival | ( | string | section, | |
string | key, | |||
int | defval | |||
) |
Search for the specified section/key value and return it as an integer.
Return the containing the requested value as an integer if found, the default value passed in the last parameter otherwise.
section | Section to search for; | |
key | Key to search for; | |
defval | Default value. |
int mcs::Conf::ival | ( | string | section, | |
string | key | |||
) |
Search for the specified section/key value and return it as an integer.
If the value is not found an exception will be thrown.
section | Section to search for; | |
key | Key to search for. |
ERROR | MSG_ENTRY_UNAVAILABLE. |
long long int mcs::Conf::lval | ( | string | section, | |
string | key, | |||
int | defval | |||
) |
Search for the specified section/key value and return it as a long integer.
Return the containing the requested value as an integer if found, the default value passed in the last parameter otherwise.
section | Section to search for; | |
key | Key to search for; | |
defval | Default value. |
long long int mcs::Conf::lval | ( | string | section, | |
string | key | |||
) |
Search for the specified section/key value and return it as a long integer.
If the value is not found an exception will be thrown.
section | Section to search for; | |
key | Key to search for. |
ERROR | MSG_ENTRY_UNAVAILABLE. |
Declared to avoid using of default assignment operator.
void mcs::Conf::save | ( | string | filename = "" |
) |
bool mcs::Conf::search | ( | string | section, | |
string | key, | |||
enum ThrowExceptions | throwexc = DONT_THROW | |||
) |
Search for the specified section/key value.
section | Section to search for; | |
key | Key to search for. | |
throwexc | If THROW will throw an exception instead of returning an empty string. |
ERROR | MSG_ENTRY_UNAVAILABLE. |
void mcs::Conf::setval | ( | string | section, | |
string | key, | |||
Data * | val, | |||
string | comment = "" | |||
) |
Set a new value for the specified section/key pair.
If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.
The changes you made to the values won't be written to the configuration file until you call the save() method.
section | Section you wish to write to; | |
key | Key you wish to write to; | |
val | New value for the section/key pair; | |
comment | Optional comment to the value. |
void mcs::Conf::setval | ( | string | section, | |
string | key, | |||
int | val, | |||
string | comment = "" | |||
) |
Set a new value for the specified section/key pair.
If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.
The changes you made to the values won't be written to the configuration file until you call the save() method.
section | Section you wish to write to; | |
key | Key you wish to write to; | |
val | New value for the section/key pair; | |
comment | Optional comment to the value. |
void mcs::Conf::setval | ( | string | section, | |
string | key, | |||
long long int | val, | |||
string | comment = "" | |||
) |
Set a new value for the specified section/key pair.
If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.
The changes you made to the values won't be written to the configuration file until you call the save() method.
section | Section you wish to write to; | |
key | Key you wish to write to; | |
val | New value for the section/key pair; | |
comment | Optional comment to the value. |
void mcs::Conf::setval | ( | string | section, | |
string | key, | |||
string | val, | |||
string | comment = "" | |||
) |
Set a new value for the specified section/key pair.
If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.
The changes you made to the values won't be written to the configuration file until you call the save() method.
section | Section you wish to write to; | |
key | Key you wish to write to; | |
val | New value for the section/key pair; | |
comment | Optional comment to the value. |
string mcs::Conf::sval | ( | string | section, | |
string | key, | |||
string | defval | |||
) |
Search for the specified section/key value and return it as a string.
Return a string containing the requested value if found, the default value passed in the last parameter otherwise.
section | Section to search for; | |
key | Key to search for; | |
defval | Default value. |
string mcs::Conf::sval | ( | string | section, | |
string | key | |||
) |
Search for the specified section/key value and return it as a string.
If the value is not found an exception will be thrown.
section | Section to search for; | |
key | Key to search for. |
ERROR | MSG_ENTRY_UNAVAILABLE. |
Data & mcs::Conf::val | ( | string | section = "" , |
|
string | key = "" | |||
) |
Return a Data object containing the last value found.
Search for the specified section/key value and return it in a Data object.
If the value is not found an exception will be thrown. If both parameters are empty string the retunred Data object contain the last requested value.
section | Section to search for; | |
key | Key to search for. |
ERROR | MSG_ENTRY_UNAVAILABLE. |
vector<string> mcs::Conf::comments [private] |
string mcs::Conf::filename [private] |
vector<string> mcs::Conf::keys [private] |
vector<string> mcs::Conf::sections [private] |
vector<string> mcs::Conf::values [private] |
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha3
|