# 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 can customize the application simply by editing 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. Parameter names can only be alphanumeric characters and there cannot be 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

    # 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. Also, the application is responsible for creating the configurable parameters in the file and updating any changes to existing values.

Configuration Manager Classes

The ConfigData class is used to represent the name of the configurable parameter and the value of the configurable parameter.

    class ConfigData
    {
    private:
      friend class Config;

    private:
      char *Name;
      char *Value;
    };

The Config class is a character string based singly linked list. This class uses the non-template version of the SLList class, ChSlist, as a base class. The non-template version was used when this class was first developed on a C++ compiler that did not support templates and was not re-coded to use the template version of the SLList class.

Config::Config()

- Default class constructor used to construct a new singly linked list.

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(char *Fname)

- Public member function use 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.

void Config::UnLoad()

- Public member function used to unload all the configurable names and values from memory.

char* Config::GetStrValue(char *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.

int Config::GetIntValue(char *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.

double Config::GetDFPValue(char *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.

long Config::GetLongValue(char *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.

int Config::StoreCfgData(char *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.

End Of Document