Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

FileConfig Class Reference

#include <appconf.h>

Inheritance diagram for FileConfig:

Inheritance graph
[legend]
Collaboration diagram for FileConfig:

Collaboration graph
[legend]
List of all members.

Public Methods

void readFile (const char *szFileName)
Constructors and destructor
 FileConfig (const char *szFileName, Bool bLocalOnly=FALSE, Bool bUseSubDir=FALSE)
 FileConfig (std::istream *iStream)
 FileConfig (void)
 ~FileConfig ()
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)
 permanently writes changes, returns TRUE on success.

Bool flush (std::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

Bool DeleteIfEmpty ()
Bool readStream (std::istream *istr, ConfigGroup *pRootGroup=NULL)
const char* GlobalConfigFile () const
const char* LocalConfigFile () const
void Init ()
 trivial initialization of member variables (common to all ctors).


Protected Attributes

ConfigGroupm_pRootGroup
ConfigGroupm_pCurGroup

Private Methods

void AppendCommentLine (const char *psz=NULL)

Private Attributes

char* m_szFileName
const char* m_szFullFileName
unsigned m_uiLine
Bool m_bParsingLocal
Bool m_bUseSubDir
char* m_szComment

Detailed Description

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.

Definition at line 436 of file appconf.h.


Constructor & Destructor Documentation

FileConfig::FileConfig ( const char * szFileName,
Bool bLocalOnly = FALSE,
Bool bUseSubDir = FALSE )
 

FileConfig will <ll>

  • 1) read global config file (/etc/appname.conf under UNIX or windir<file>.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. </ll> @memo Ctor for FileConfig takes file name argument.
    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::FileConfig ( std::istream * iStream )
     

    @memo Ctor for FileConfig for reading from a stream

    Parameters:
    input   stream to read from

    FileConfig::FileConfig ( void )
     

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

    FileConfig::~FileConfig ( )
     

    Notice that if you're interested in error code, you should use flush() function. @memo Dtor will save unsaved data.


    Member Function Documentation

    void FileConfig::AppendCommentLine ( const char * psz = NULL ) [private]
     

    Bool FileConfig::DeleteIfEmpty ( ) [protected]
     

    const char* FileConfig::GlobalConfigFile ( ) const [protected]
     

    void FileConfig::Init ( ) [protected]
     

    trivial initialization of member variables (common to all ctors).

    const char* FileConfig::LocalConfigFile ( ) const [protected]
     

    void FileConfig::changeCurrentPath ( const char * szPath = "" ) [virtual]
     

    Change the current path. Works like 'cd' and supports "..".

    Parameters:
    szPath   name of the group to search by default (created if !exists)

    Reimplemented from BaseConfig.

    Bool FileConfig::deleteEntry ( const char * szKey ) [virtual]
     

    Delets the entry. Notice that there is intentionally no such function as deleteGroup: the group is automatically deleted when it's last entry is deleted.

    @memo Deletes the entry.

    Parameters:
    szKey   The key to delete
    Returns:
    TRUE on success, FALSE on failure

    Reimplemented from BaseConfig.

    Enumerator * FileConfig::enumEntries ( ) const [virtual]
     

    Enumerate entries of the current group.

    Reimplemented from BaseConfig.

    Enumerator * FileConfig::enumSubgroups ( ) const [virtual]
     

    Enumerate subgroups of the current group.

    Reimplemented from BaseConfig.

    Bool FileConfig::flush ( std::ostream * oStream,
    Bool = FALSE )
     

    writes changes to ostream, returns TRUE on success.

    Bool FileConfig::flush ( Bool bCurrentOnly = FALSE ) [virtual]
     

    permanently writes changes, returns TRUE on success.

    Reimplemented from BaseConfig.

    Bool FileConfig::parseLine ( const char * psz )
     

    parses one line of config file.

    double FileConfig::readEntry ( const char * szKey,
    double Default ) const [inline]
     

    Get the value of an entry, or the default value, interpreted as a double value.

    Parameters:
    szKey   The key to search for.
    Default   The default value to return if not found.
    Returns:
    The value of the key converted to double or the default value.

    Reimplemented from BaseConfig.

    Definition at line 492 of file appconf.h.

    long int FileConfig::readEntry ( const char * szKey,
    long int Default ) const [inline]
     

    Get the value of an entry, or the default value, interpreted as a long integer.

    Parameters:
    szKey   The key to search for.
    Default   The default value to return if not found.
    Returns:
    The value of the key converted to long int or the default value.

    Reimplemented from BaseConfig.

    Definition at line 489 of file appconf.h.

    const char * FileConfig::readEntry ( const char * szKey,
    const char * szDefault = NULL ) const [virtual]
     

    Get the value of an entry, or the default value.

    Parameters:
    szKey   The key to search for.
    szDefault   The default value to return if not found.
    Returns:
    The value of the key, or defval if not found

    Reimplemented from BaseConfig.

    void FileConfig::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.

    Bool FileConfig::readStream ( std::istream * istr,
    ConfigGroup * pRootGroup = NULL ) [protected]
     

    Bool FileConfig::writeEntry ( const char * szKey,
    double Value ) [inline]
     

    Set the value of an entry to a double value.

    Parameters:
    szKey   The key whose value to change.
    Value   The new value.
    Returns:
    TRUE on success, FALSE on failure

    Reimplemented from BaseConfig.

    Definition at line 500 of file appconf.h.

    Bool FileConfig::writeEntry ( const char * szKey,
    long int Value ) [inline]
     

    Set the value of an entry to a long int value.

    Parameters:
    szKey   The key whose value to change.
    Value   The new value.
    Returns:
    TRUE on success, FALSE on failure

    Reimplemented from BaseConfig.

    Definition at line 497 of file appconf.h.

    Bool FileConfig::writeEntry ( const char * szKey,
    const char * szValue ) [virtual]
     

    Set the value of an entry.

    Parameters:
    szKey   The key whose value to change.
    szValue   The new value.
    Returns:
    TRUE on success, FALSE on failure

    Reimplemented from BaseConfig.


    Member Data Documentation

    Bool FileConfig::m_bParsingLocal [private]
     

    Definition at line 650 of file appconf.h.

    Bool FileConfig::m_bUseSubDir [private]
     

    Definition at line 651 of file appconf.h.

    ConfigGroup * FileConfig::m_pCurGroup [protected]
     

    Definition at line 627 of file appconf.h.

    ConfigGroup* FileConfig::m_pRootGroup [protected]
     

    Definition at line 627 of file appconf.h.

    char* FileConfig::m_szComment [private]
     

    Definition at line 655 of file appconf.h.

    char* FileConfig::m_szFileName [private]
     

    Definition at line 646 of file appconf.h.

    const char* FileConfig::m_szFullFileName [private]
     

    Definition at line 648 of file appconf.h.

    unsigned FileConfig::m_uiLine [private]
     

    Definition at line 649 of file appconf.h.


    The documentation for this class was generated from the following file:
    Generated at Wed Apr 4 19:57:40 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001