ConfigFile Class Reference

#include <halcyon.h>

Collaboration diagram for ConfigFile:

Collaboration graph
[legend]

List of all members.

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


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

Parameters:
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.

Parameters:
key name of value to set to true.

void ConfigFile::setval ( string  key,
string  val 
)

Set a variable to a specified value.

Parameters:
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.

Parameters:
key name of variable
ival value to assign to variable.

void ConfigFile::setboolval ( string  key,
bool  bval 
)

Set a value to a boolean.

Parameters:
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.

Parameters:
key name of variable to unset

string ConfigFile::getval ( string  key  ) 

Get the value for a variable.

Parameters:
key name of variable to get value for
Returns:
the value of that variable

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.

Parameters:
key the variable to get the value of
Returns:
the int value of that variable

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.

Parameters:
key the variable to get the value of
Returns:
the boolean value of that variable

void ConfigFile::setconfigfile ( string  cfname  ) 

Specify the file to use as a config file for reading and writing.

Parameters:
cfname name of config file

void ConfigFile::setverbose ( bool  verbosity  ) 

Set the verbosity level for debugging output.

Parameters:
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.

Parameters:
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.

Parameters:
cfname name of the config file we write to.
Returns:
true if the file was written to okay

bool ConfigFile::saveconfig (  ) 

Save the config file to the current config file name.

Returns:
false if the file could not be written.

vector< string > ConfigFile::getcommands (  ) 

Get all the commands passed on to us in a single vector.

Returns:
vector of all the commands in the queue.

int ConfigFile::getcommandsize (  ) 

Get the size of the command queue.

Returns:
the number of commands in the queue

string ConfigFile::getnextcommand (  ) 

Get the next command in the command queue.

Returns:
the next command


Member Data Documentation

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]


The documentation for this class was generated from the following files:
Generated on Sun Apr 6 01:13:23 2008 for HDRadioController by  doxygen 1.5.3