Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# XFuConfiguration.h

Go to the documentation of this file.

    00001 /*! \file
    00002  * X-Forge Util <br>
    00003  * Copyright 2000-2003 Fathammer Ltd
    00004  *
    00005  * \brief XFuConfiguration.h is the header file for the XFuConfiguration class.
    00006  *
    00007  * $Id: XFuConfiguration.h,v 1.15 2003/08/12 13:33:52 lars Exp $
    00008  * $Date: 2003/08/12 13:33:52 $
    00009  * $Revision: 1.15 $
    00010  */
    00011
    00012 #ifndef XFUCONFIGURATION_H_INCLUDED
    00013 #define XFUCONFIGURATION_H_INCLUDED
    00014
    00015
    00016
    00017 #include <xfutil/XFuStringKey.h>
    00018 #include <xfcore/XFcHashtable.h>
    00019
    00020
    00021 //! Configuration container.
    00022 /*!
    00023  * Reads and parses a set of configuration keys from a file.
    00024  * The format of the configuration file is such that there is one property
    00025  * on each row in a text file. Each property is a pair of a key and a value,
    00026  * delimited by a '=' char, for example: fileName=HelloWorld.xff. Leading and
    00027  * trailing spaces are trimmed. Lines starting with character '#' are treated
    00028  * as comment lines and are ignored.
    00029  */
    00030 class XFuConfiguration
    00031 {
    00032
    00033 public:
    00034
    00035     //! Constructor.
    00036     XFuConfiguration();
    00037
    00038     //! Static constructor.
    00039     /*! \return new configuration data object if successful, or NULL if unsuccessful.
    00040      */
    00041     static XFuConfiguration * create();
    00042
    00043     //! Static constructor.
    00044     /*! \param aFilename filename of configuration data to load.
    00045      * \return new configuration data object if successful, or NULL if unsuccessful.
    00046      */
    00047     static XFuConfiguration * create(const CHAR *aFilename);
    00048
    00049     //! Static constructor.
    00050     /*! \param aFile open file pointing to configuration data to load.
    00051      * \return new configuration data object if successful, or NULL if unsuccessful.
    00052      * \note Configuration data is assumed to continue to end of the file.
    00053      */
    00054     static XFuConfiguration * create(XFcFile *aFile);
    00055
    00056     //! Destructor.
    00057     virtual ~XFuConfiguration();
    00058
    00059     //! Returns the value of the property (NULL if none).
    00060     virtual CHAR * get(const CHAR *aKey);
    00061
    00062     //! Returns the value of a property as an INT32, or 0 if not found.
    00063     virtual INT32 getINT32(const CHAR *aKey);
    00064
    00065     //! Returns the value of a property as a FLOAT32, or 0 if not found.
    00066     virtual FLOAT32 getFLOAT32(const CHAR *aKey);
    00067
    00068     //! Sets the value of a property.
    00069     virtual void put(const CHAR *aKey, const CHAR *aValue);
    00070
    00071     //! Clears the current properties.
    00072     virtual void clear();
    00073
    00074     //! Loads new configuration file and merges its data to the current set.
    00075     /*! \param aFilename filename of the configuration data file to load.
    00076      * \return 1 if successful, 0 if unsuccessful (e.g. file not found).
    00077      */
    00078     virtual INT load(const CHAR *aFilename);
    00079
    00080     //! Loads new configuration file and merges its data to the current set.
    00081     /*! \param aFile open file pointing to the configuration data to load.
    00082      * \return 1 if successful, 0 if unsuccessful (e.g. file not found).
    00083      * \note Configuration data is assumed to continue to end of the file.
    00084      */
    00085     virtual INT load(XFcFile *aFile);
    00086
    00087 protected:
    00088
    00089     //! Parses a line of the config file.
    00090     /*! Extracts the property key and value from it and adds these to the property hashtable.
    00091      */
    00092     virtual void processLine(const CHAR *aStr);
    00093
    00094     //! Reads a line from a file.
    00095     CHAR8 * readLine(XFcFile *aFile);
    00096
    00097     //! Returns a new string where the leading and trailing spaces are removed.
    00098     CHAR * strDupTrim(const CHAR *aStr);
    00099
    00100     //! Properties hashtable.
    00101     XFcHashtable<XFuStringKey, void *> *mProperties;
    00102
    00103 };
    00104
    00105
    00106 #endif // !XFUCONFIGURATION_H_INCLUDED
    00107

|  | X-Forge Documentation Confidential Copyright © 2002-2003 Fathammer |  | Documentation generated with doxygen by Dimitri van Heesch