Configuration Manager


Topics

Overview

Config Class


Overview

The configuration manager class is used to load program parameters from a text based (ASCII) configuration file. This allows specified program parameters to be changed without having to recompile the program. Users or the program itself can customize the application simply by modifying the text based configuration file named within the application.

Each configurable parameter is assigned a case-sensitive name in the file followed by an equal sign, then a value. The first character of a parameter name must be alphanumeric. If the first character is not alphanumeric the line will be ignored. Version 1031 and prior will not allow any spaces on either side of the equal sign. The configuration manager can read strings, integer, or floating point values from the text file. A number sign or a semicolon precedes comments in the configuration file. The following is an example of a program configuration file:

# Define a signed long integer value 
Long=2147483647 # This comment will be ignored
                                                            
# Define a signed short integer value 
Int = 32768                                

# Define a double precision floating point value
Float= 1.12345
                                                                 
# Define a character string value
String=YES                                                  

There can only be one instance of a parameter name in the file. If a parameter is named two or more times, the configuration manager will use the first one it finds and ignore all others. Limits and default values for each parameter must be defined within the application itself. The application is responsible for creating the configurable parameters in the file. This version of the configuration manager allows you to update any changes to existing values. If the parameter you are changing does not exist, the parameter name and value will be written to the configuration file.


Configuration Manager Class

The Config class is a singly linked list that uses user-defined strings as nodes. It is derives from the vConfigList class and SLListBase class. The actual parameter names and values are represented as vConfigListNode objects.

Config::Config() - Default class constructor used to construct a new singly linked list.

Config::Config(const UString &fname) - Class constructor used to construct a new singly linked list and name the configuration file. Use the Config::Load() function before processing any of the configuration values. Includes overloads for const char * and char * types.

Config::~Config() - Class destructor responsible for clearing the list and de-allocating all the nodes when a Config object is destroyed.

Config::Config(const Config &ob) - Private class copy constructor used to disallow copying.

void Config::operator=(const Config &ob) - Private overloaded assignment operator used to disallow assignment.

int Config::Load() - Public member function used to load all the configurable names and values after the configuration has been named by the Config class constructor or a call to the Config::SetFileName() function. Returns false if the file cannot be opened or a memory allocation error occurred.

int Config::Load(const UString &fname) - Public member function used to load all the configurable names and values from the specified file. Returns false if the file cannot be opened or a memory allocation error occurred. Includes overloads for char * and const char * types.

int Config::ReLoad() - Public member function used to reload the configurable names and values after the configuration has been named by the Config class constructor or a call to the Config::SetFileName() function. Returns false if the file cannot be opened or a memory allocation error occurred.

int Config::ReLoad(const UString &fname) - Public member function used to reload configurable names and values from the specified file. Returns false if the file cannot be opened or a memory allocation error occurred. Includes overloads for char * and const char * types.

char *Config::GetFileName() - Public member function that returns the name of the configuration file.

void Config::SetFileName(const UString &fname) - Public member function used to set the name of the configuration file. Includes overloads for char * and const char * types.

void Config::UnLoad() - Public member function used to unload all the configurable names and values from memory.

char* Config::GetStrValue(const UString &Name) - Public member function used to read a string value from the configurable parameters loaded in memory by the Config::Load() function. Returns a null value if the parameter name is not found. Includes overloads for char * and const char * types.

int Config::GetIntValue(const UString &Name) - Public member function used to read a signed short integer value from the configurable parameters loaded in memory by the Config::Load() function. Returns zero if the parameter name is not found. Includes overloads for char * and const char * types.

double Config::GetFloatValue(const UString &Name) - Public member function used to read a double precision floating point value from the configurable parameters loaded in memory by the Config::Load() function. Returns zero if the parameter name is not found. Includes overloads for char * and const char * types.

long Config::GetLongValue(const UString &Name) - Public member function used to read a signed long integer value from the configurable parameters loaded in memory by the Config::Load() function. Returns zero if the parameter name is not found. Includes overloads for char * and const char * types.

int WriteConfigLine(const UString &parm, const UString &value) - Public member function used to write a parameter name and value to the configuration file. NOTE: Parameter names should not contain an equal sign at the end of the string. The equal sign will be added to mark it as a config file parameter. Returns true if successful or false if an error occurs. Includes overloads for char * and const char * types.

int ChangeConfigValue (const UString &parm, const UString &value) - Public member function used change a string value in the configuration file. NOTE: Parameter values should not contain an equal sign at the end of the string. Returns true if successful or false if an error occurs. Includes overloads for char * and const char * types.

int ChangeConfigValue (const UString &parm, int value) - Public member function used change an integer value in the configuration file. NOTE: Parameter values should not contain an equal sign at the end of the string. Returns true if successful or false if an error occurs. Includes overloads for char * and const char * types.

int ChangeConfigValue (const UString &parm, long value) - Public member function used change a long integer value in the configuration file. NOTE: Parameter values should not contain an equal sign at the end of the string. Returns true if successful or false if an error occurs. Includes overloads for char * and const char * types.

int ChangeConfigValue (const UString &parm, double value) - Public member function used change a floating point value in the configuration file. NOTE: Parameter values should not contain an equal sign at the end of the string. Returns true if successful or false if an error occurs. Includes overloads for char * and const char * types.

int Config::StoreCfgData(const Ustring &str) - Private member function used to by the Config::Load() function to load the configurable names and values into memory. Returns false if memory allocation fails.

int ChangeConfigLine(const UString &string_to_replace, const UString &string_to_insert, int check_case, int append_lines) - Private member function used to replace strings in the configuration file. If the "check_case" variable is true, upper and lower case values will be checked. If the "append_lines" variable is true, all lines appended together by a backslash will be treated as one line. Returns true if successful or false if an error occurs.


End Of Document