#include <halcyon.h>
Public Member Functions | |
ConfigFile () | |
void | parseargs (int, char **) |
void | parseline (string) |
void | setval (string) |
void | setval (string, string) |
void | setval (string, int) |
void | setboolval (string, bool) |
void | unset (string) |
string | getval (string) |
int | getintval (string) |
bool | getboolval (string) |
void | setconfigfile (string) |
void | setverbose (bool) |
void | loadconfig () |
void | loadconfig (string) |
bool | saveconfig (string) |
bool | saveconfig () |
vector< string > | getcommands () |
int | getcommandsize () |
string | getnextcommand () |
Private Attributes | |
bool | verbose |
bool | argsparsed |
bool | configparsed |
unsigned int | cmdpoint |
string | configFile |
map< string, string > | configVals |
vector< string > | cmdvals |
halcyon | utillib |
ConfigFile::ConfigFile | ( | ) |
Create a ConfigFile object. A ConfigFile can read in a config file made up of key=value pairs and parse the lines, including trimming the quotation marks (single and double) and whitespace out of the way. It then keeps the key/value pairs stored so they can be easily accessed by a program. Command line arguments can also be passed in. The intent is to read in a config file, then read the command line args so they can override settings in the config file. It is also possible to read in a sequence of config files, with each one overriding the settings of the previous. If a program has a system config file in /etc, then other config files for users, then the system one could be read first, then the user files so each user is able to have their own settings. We ignore any blank lines or lines starting with // or #. We do not store them, though, so they are not written back out if we write the config file back out.
Also commands can be stored from the command line arguments, since many programs can act on them. The difference is that settings have "--" in front of them and commands don't. Any argument parsed from the command line without the double-dash in front of it will be stored as a command so the program can read them in order and act on them if desired.
Files are also written back out, with the values in alphabetical order (a feature of map<string,string>, not of this class!) to one or more config files.
void ConfigFile::parseargs | ( | int | count, | |
char ** | args | |||
) |
Parse the arguments from the command line as if they were actually in a config file and store their values. This can be called directly from main() with argc and argv.
count | same as argc | |
args | same as argv |
void ConfigFile::parseline | ( | string | arg | ) |
Parse a line of data and store the values. This can be an argument from the command line or a line of data in a config file.
void ConfigFile::setval | ( | string | key | ) |
Set a value. Since no argument is give, it is taken that the value needs to be specified, so it will be set as true.
key | name of value to set to true. |
void ConfigFile::setval | ( | string | key, | |
string | val | |||
) |
Set a variable to a specified value.
key | name of variable to set | |
val | value to assign to the variable |
void ConfigFile::setval | ( | string | key, | |
int | ival | |||
) |
Set a variable to an integer value. Since all values are stored as strings, the int will be converted to a string for storage.
key | name of variable | |
ival | value to assign to variable. |
void ConfigFile::setboolval | ( | string | key, | |
bool | bval | |||
) |
Set a value to a boolean.
key | name of variable | |
bval | value to set variable to |
void ConfigFile::unset | ( | string | key | ) |
Unset or remove a variable so it's not stored or written back out to a config file.
key | name of variable to unset |
string ConfigFile::getval | ( | string | key | ) |
Get the value for a variable.
key | name of variable to get value for |
int ConfigFile::getintval | ( | string | key | ) |
Get an integer value of a variable. Does not do any checking to be sure the variable is an int when converting it from a string.
key | the variable to get the value of |
bool ConfigFile::getboolval | ( | string | key | ) |
Get the boolean value of a variable. Does not do any checking to be sure the variable is a boolean when converting it from a string.
key | the variable to get the value of |
void ConfigFile::setconfigfile | ( | string | cfname | ) |
Specify the file to use as a config file for reading and writing.
cfname | name of config file |
void ConfigFile::setverbose | ( | bool | verbosity | ) |
Set the verbosity level for debugging output.
verbosity | true for debugging output |
void ConfigFile::loadconfig | ( | ) |
Read in the already set config file and parse it.
void ConfigFile::loadconfig | ( | string | cfname | ) |
Load the specified config file and parse it.
cfname | name of config file to load |
bool ConfigFile::saveconfig | ( | string | cfname | ) |
Save the config file to the given file name. This clobbers any existing file of the same name.
cfname | name of the config file we write to. |
bool ConfigFile::saveconfig | ( | ) |
Save the config file to the current config file name.
vector< string > ConfigFile::getcommands | ( | ) |
Get all the commands passed on to us in a single vector.
int ConfigFile::getcommandsize | ( | ) |
Get the size of the command queue.
string ConfigFile::getnextcommand | ( | ) |
Get the next command in the command queue.
bool ConfigFile::verbose [private] |
bool ConfigFile::argsparsed [private] |
bool ConfigFile::configparsed [private] |
unsigned int ConfigFile::cmdpoint [private] |
string ConfigFile::configFile [private] |
map<string, string> ConfigFile::configVals [private] |
vector<string> ConfigFile::cmdvals [private] |
halcyon ConfigFile::utillib [private] |