Class ConfigParser¶

Class Documentation¶

class ConfigParser

Stores and parses configuration options from the command line and config files.

Public Functions

ConfigParser()

default construtor for ConfigOption

void setConfig(const string &file, bool main, bool full_parse = false)

Sets the config file the specified string. A boolean is also provided, set equal to true if this is the main command line import. This causes the deletion of the first few command line options after import.

Parameters
• file: the target config file (in .txt format).
• main: boolean of if this is the main command line import.
• full_parse: sets bFullParse to provided value

void parseConfig()

Reads a config file of a specific configuration. Each section begins with ‘[section_name]’. Each variable is defined as ‘key=value’, and must be one per line Each key’s variable will be read as a string into a KeyOption structure.

void parseConfig(istream &istream1)

Reads a config stream of a specific configuration. Each section begins with ‘[section_name]’. Each variable is defined as ‘key=value’, and must be one per line Each key’s variable will be read as a string into a KeyOption structure.

vector<SectionOption> getSectionOptions()

Returns the vector of key options imported from the file.

Return
vector of key options

void setSectionOption(string section, string reference, string value)

Sets the section option with the provided section, key and value.

Parameters
• section: the section name
• reference: the reference key for the parameter
• value: the value of the key

SectionOption operator[](unsigned long index)

Gets the SectionOption at the provided index.

Return
the section option at the index
Parameters
• index: the index of the SectionOption to obtain, must be less than configs.size()

unsigned long getSectionOptionsSize()

Gets the size of the key options vector.

Return
the size of the configuration vector.

vector<string> getSections()

Gets the sections contained in the SectionOptions object.

Return
A vector of the section names.

bool hasSection(const string &sec)

Checks whether the config option has the specified section.

Return
true if the section has been found
Parameters
• sec: the section name to check for

vector<string> getSectionValues(string sec)

Gets all values within a section.

Throws a Config_Exception if the section is not found.

Return
a vector of the section’s values.
Parameters
• sec: the section to find values for

string getSectionOptions(string section, string ref)

Returns a specific value for a particular key options and reference.

Return
the string at the correct place in KeyOptions.val
Parameters
• section: the section to match
• ref: the reference to match

string getSectionOptions(string section, string ref, string def)

Returns a specific value for a particular key options and reference. This overloaded version of the function returns the default value def when no match is found.

Return
the string at the correct place in KeyOptions.val
Parameters
• section: the section to match
• ref: the reference to match
• def: the default value to return if no match is found

int importConfig(vector<string> &comargs)

Imports the parameters from the config file and returns an integer of the number of arguments.

Return
a count of the number of arguments (should also be the size of comargs).
Parameters
• comargs: a vector of command line arguments to import to from file.

Friends

ostream &operator<<(ostream &os, const ConfigParser &c)

Overloading the << operator for outputting to the output stream.

Return
os the output stream.
Parameters
• os: the output stream.
• c: the ConfigOption object.

istream &operator>>(istream &is, ConfigParser &c)

Overloading the >> operator for inputting from an input stream. Note that the config file must still exist for re-inport and parsing.

Return
is the input stream
Parameters
• is: the input stream
• c: the ConfigOption object