In file appconf.h:

class FileConfig : public BaseConfig

FileConfig derives from BaseConfig and implements file based config class, i

Inheritance:

FileConfig < BaseConfig


Public Methods

void readFile(const char *szFileName)
Like reading from a local configuration file, but takes a whole path as argument

Public

Constructors and destructor
FileConfig(const char *szFileName, Bool bLocalOnly = FALSE, Bool bUseSubDir = FALSE)
Ctor for FileConfig takes file name argument.
FileConfig(istream *iStream)
Ctor for FileConfig for reading from a stream
FileConfig(void)
Another constructor, creating an empty object
~FileConfig()
Dtor will save unsaved data.
Implementation of inherited pure virtual functions
const char* readEntry(const char *szKey, const char *szDefault = NULL) const
long int readEntry(const char *szKey, long int Default) const
double readEntry(const char *szKey, double Default) const
Bool writeEntry(const char *szKey, const char *szValue)
Bool writeEntry(const char *szKey, long int Value)
Bool writeEntry(const char *szKey, double Value)
Bool deleteEntry(const char *szKey)
Bool flush(Bool bCurrentOnly = FALSE)
Bool flush(ostream *oStream, Bool = FALSE)
writes changes to ostream, returns TRUE on success
Bool parseLine(const char *psz)
parses one line of config file
void changeCurrentPath(const char *szPath = "")
Enumeration
Enumerator* enumSubgroups() const
Enumerate subgroups of the current group
Enumerator* enumEntries() const
Enumerate entries of the current group

Protected Methods

void Init()
trivial initialization of member variables (common to all ctors)

Inherited from BaseConfig:

Public Methods

void recordDefaults(Bool enable = TRUE)

Public

Set and retrieve current path

virtual void setCurrentPath(const char *szPath = "")
Specify the new current path by its absolute name
virtual void changeCurrentPath(const char *szPath = "")
Change the current path
const char* getCurrentPath() const
Query the current path
static char* normalizePath(const char *szStartPath, const char *szPath)
Resolve "

Enumeration of subgroups/entries

class Enumerator
Class that supports enumeration.
size_t Count() const
return number of elements
const char* operator[](size_t nIndex) const
return the element #nIndex
virtual Enumerator* enumSubgroups() const
Enumerate subgroups of the current group
virtual Enumerator* enumEntries() const
Enumerate entries of the current group

Key access

virtual const char* readEntry(const char *szKey, const char *szDefault = NULL) const
Get the value of an entry, or the default value
long int readEntry(const char *szKey, long int Default) const
Get the value of an entry, or the default value, interpreted as a long integer
double readEntry(const char *szKey, double Default) const
Get the value of an entry, or the default value, interpreted as a double value
virtual Bool writeEntry(const char *szKey, const char *szValue)
Set the value of an entry
Bool writeEntry(const char *szKey, long int Value)
Set the value of an entry to a long int value
Bool writeEntry(const char *szKey, double Value)
Set the value of an entry to a double value
virtual Bool deleteEntry(const char *szKey)
Deletes the entry.

Other functions

virtual Bool flush(Bool = FALSE)
permanently writes changes, returns TRUE on success
Bool isInitialized() const
returns TRUE if object was correctly initialized

Filter functions.

static char* filterOut(const char *szValue)
should be called from writeEntry, returns pointer to dynamic buffer
static char* filterIn(const char *szValue)
should be called from readEntry, returns pointer to dynamic buffer
void expandVariables(Bool bExpand = TRUE)
should environment variables be automatically expanded?
Bool doesExpandVariables(void) const
do environment variables get automatically expanded?

Protected Fields

Bool m_bOk
Bool m_bExpandVariables
Bool m_bRecordDefaults

Documentation

FileConfig derives from BaseConfig and implements file based config class, i.e. it uses ASCII disk files to store the information. These files are alternatively called INI, .conf or .rc in the documentation. They are organized in groups or sections, which can nest (i.e. a group contains subgroups, which contain their own subgroups &c). Each group has some number of entries, which are "key = value" pairs. More precisely, the format is:
# comments are allowed after either ';' or '#' (Win/UNIX standard)
# blank lines (as above) are ignored
# global entries are members of special (no name) top group
written_for = wxWindows
platform    = Linux
# the start of the group 'Foo'
[Foo]                           # may put comments like this also
# following 3 lines are entries
key = value
another_key = "  strings with spaces in the beginning should be quoted, \
otherwise the spaces are lost"
last_key = but you don't have to put " normally (nor quote them, like here)
# subgroup of the group 'Foo'
# (order is not important, only the name is: separator is '/', as in paths)
[Foo/Bar]
# entries prefixed with "!" are immutable, i.e. can't be changed if they are
# set in the system wide .conf file
!special_key = value
bar_entry = whatever
[Foo/Bar/Fubar]   # depth is (theoretically :-) unlimited
# may have the same name as key in another section
bar_entry = whatever not
You {have read/write/delete}Entry functions (guess what they do) and also setCurrentPath to select current group. enum{Subgroups/Entries} allow you to get all entries in the config file (in the current group). Finally, flush() writes immediately all changed entries to disk (otherwise it would be done automatically in dtor) FileConfig manages not less than 2 config files for each program: global and local (or system and user if you prefer). Entries are read from both of them and the local entries override the global ones unless the latter is immutable (prefixed with '!') in which case a warning message is generated and local value is ignored. Of course, the changes are always written to local file only.
Constructors and destructor

FileConfig(const char *szFileName, Bool bLocalOnly = FALSE, Bool bUseSubDir = FALSE)
FileConfig will
  • 1) read global config file (/etc/appname.conf under UNIX or windir\.ini under Windows) unless bLocalOnly is TRUE
  • 2) read user's config file ($HOME/.appname or $HOME/.appname/config or %USERPROFILE%/file.ini under NT, same as global otherwise)
  • 3) write changed entries to user's file, never to the system one.
    Parameters:
    szFileName - Config file, default extension appended if not given
    bLocalOnly - TRUE => don't look for system-wide config file
    bUseSubDir - TRUE => filename is not called $HOME/. but $HOME/./config

    FileConfig(istream *iStream)
    Ctor for FileConfig for reading from a stream
    Parameters:
    input - stream to read from

    FileConfig(void)
    Another constructor, creating an empty object. For use with the readFile() method.

    ~FileConfig()
    Notice that if you're interested in error code, you should use flush() function.

  • void readFile(const char *szFileName)
    Like reading from a local configuration file, but takes a whole path as argument. No default configuration files used. Use with FileConfig() constructor.

    Implementation of inherited pure virtual functions

    const char* readEntry(const char *szKey, const char *szDefault = NULL) const

    long int readEntry(const char *szKey, long int Default) const

    double readEntry(const char *szKey, double Default) const

    Bool writeEntry(const char *szKey, const char *szValue)

    Bool writeEntry(const char *szKey, long int Value)

    Bool writeEntry(const char *szKey, double Value)

    Bool deleteEntry(const char *szKey)

    Bool flush(Bool bCurrentOnly = FALSE)

    Bool flush(ostream *oStream, Bool = FALSE)
    writes changes to ostream, returns TRUE on success

    Bool parseLine(const char *psz)
    parses one line of config file

    void changeCurrentPath(const char *szPath = "")

    Enumeration
    See Also:
    BaseConfig::enumSubgroups, BaseConfig::enumEntries

    Enumerator* enumSubgroups() const
    Enumerate subgroups of the current group

    Enumerator* enumEntries() const
    Enumerate entries of the current group

    void Init()
    trivial initialization of member variables (common to all ctors)


    This class has no child classes.

    alphabetic index hierarchy of classes


    this page has been generated automatically by doc++

    (c)opyright by Malte Zöckler, Roland Wunderling
    contact: doc++@zib.de