# config.h

Go to the documentation of this file.

    00001 /*
    00002  * config.h
    00003  *
    00004  * Application/System configuration access class.
    00005  *
    00006  * Portable Windows Library
    00007  *
    00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
    00009  *
    00010  * The contents of this file are subject to the Mozilla Public License
    00011  * Version 1.0 (the "License"); you may not use this file except in
    00012  * compliance with the License. You may obtain a copy of the License at
    00013  * http://www.mozilla.org/MPL/
    00014  *
    00015  * Software distributed under the License is distributed on an "AS IS"
    00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00017  * the License for the specific language governing rights and limitations
    00018  * under the License.
    00019  *
    00020  * The Original Code is Portable Windows Library.
    00021  *
    00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
    00023  *
    00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
    00025  * All Rights Reserved.
    00026  *
    00027  * Contributor(s): ______________________________________.
    00028  *
    00029  * $Revision: 24177 $
    00030  * $Author: rjongbloed $
    00031  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
    00032  */
    00033
    00034
    00035 #ifndef PTLIB_CONFIG_H
    00036 #define PTLIB_CONFIG_H
    00037
    00038 #ifdef P_USE_PRAGMA
    00039 #pragma interface
    00040 #endif
    00041
    00042 #include "ptbuildopts.h"
    00043 #ifdef P_CONFIG_FILE
    00044
    00045 class PXConfig;
    00046
    00067 class PConfig : public PObject
    00068 {
    00069   PCLASSINFO(PConfig, PObject);
    00070
    00071   public:
    00076     enum Source {
    00081       Environment,
    00087       System,
    00096       Application,
    00097       NumSources
    00098     };
    00099
    00105     PConfig(
    00106       Source src = Application
    00107     );
    00109     PConfig(
    00110       Source src,
    00111       const PString & appname
    00112     );
    00114     PConfig(
    00115       Source src,
    00116       const PString & appname,
    00117       const PString & manuf
    00118     );
    00120     PConfig(
    00121       const PString & section,
    00122       Source src = Application
    00123     );
    00125     PConfig(
    00126       const PString & section,
    00127       Source src,
    00128       const PString & appname
    00129     );
    00131     PConfig(
    00132       const PString & section,
    00133       Source src,
    00134       const PString & appname,
    00135       const PString & manuf
    00136     );
    00138     PConfig(
    00139       const PFilePath & filename,
    00140       const PString & section
    00141     );
    00143
    00153     virtual void SetDefaultSection(
    00154       const PString & section
    00155     );
    00156
    00166     virtual PString GetDefaultSection() const;
    00167
    00176     virtual PStringArray GetSections() const;
    00177
    00183     virtual PStringArray GetKeys() const;
    00185     virtual PStringArray GetKeys(
    00186       const PString & section
    00187     ) const;
    00188
    00194     virtual PStringToString GetAllKeyValues() const;
    00196     virtual PStringToString GetAllKeyValues(
    00197       const PString & section
    00198     ) const;
    00199
    00200
    00207     virtual void DeleteSection();
    00209     virtual void DeleteSection(
    00210       const PString & section
    00211     );
    00212
    00221     virtual void DeleteKey(
    00222       const PString & key
    00223     );
    00225     virtual void DeleteKey(
    00226       const PString & section,
    00227       const PString & key
    00228     );
    00229
    00238     virtual PBoolean HasKey(
    00239       const PString & key
    00240     ) const;
    00242     virtual PBoolean HasKey(
    00243       const PString & section,
    00244       const PString & key
    00245     ) const;
    00247
    00260     virtual PString GetString(
    00261       const PString & key
    00262     ) const;
    00264     virtual PString GetString(
    00265       const PString & key,
    00266       const PString & dflt
    00267     ) const;
    00269     virtual PString GetString(
    00270       const PString & section,
    00271       const PString & key,
    00272       const PString & dflt
    00273     ) const;
    00274
    00278     virtual void SetString(
    00279       const PString & key,
    00280       const PString & value
    00281     );
    00283     virtual void SetString(
    00284       const PString & section,
    00285       const PString & key,
    00286       const PString & value
    00287     );
    00288
    00289
    00306     virtual PBoolean GetBoolean(
    00307       const PString & key,
    00308       PBoolean dflt = false
    00309     ) const;
    00311     virtual PBoolean GetBoolean(
    00312       const PString & section,
    00313       const PString & key,
    00314       PBoolean dflt = false
    00315     ) const;
    00316
    00323     virtual void SetBoolean(
    00324       const PString & key,
    00325       PBoolean value
    00326     );
    00328     virtual void SetBoolean(
    00329       const PString & section,
    00330       const PString & key,
    00331       PBoolean value
    00332     );
    00333
    00334
    00335     /* Get an integer variable determined by the key in the section. If the
    00336        section name is not specified then the default section is used.
    00337
    00338        If the key is not present the value returned is the that provided by
    00339        the <code>dlft</code> parameter. Note that this is different from the
    00340        key being present but having no value, in which case zero is returned.
    00341
    00342        @return integer value of the variable.
    00343      */
    00344     virtual long GetInteger(
    00345       const PString & key,
    00346       long dflt = 0
    00347     ) const;
    00348     /* Get an integer variable determined by the key in the section. */
    00349     virtual long GetInteger(
    00350       const PString & section,
    00351       const PString & key,
    00352       long dflt = 0
    00353     ) const;
    00354
    00361     virtual void SetInteger(
    00362       const PString & key,
    00363       long value
    00364     );
    00366     virtual void SetInteger(
    00367       const PString & section,
    00368       const PString & key,
    00369       long value
    00370     );
    00371
    00372
    00382     virtual PInt64 GetInt64(
    00383       const PString & key,
    00384       PInt64 dflt = 0
    00385     ) const;
    00387     virtual PInt64 GetInt64(
    00388       const PString & section,
    00389       const PString & key,
    00390       PInt64 dflt = 0
    00391     ) const;
    00392
    00399     virtual void SetInt64(
    00400       const PString & key,
    00401       PInt64 value
    00402     );
    00404     virtual void SetInt64(
    00405       const PString & section,
    00406       const PString & key,
    00407       PInt64 value
    00408     );
    00409
    00410
    00420     virtual double GetReal(
    00421       const PString & key,
    00422       double dflt = 0
    00423     ) const;
    00425     virtual double GetReal(
    00426       const PString & section,
    00427       const PString & key,
    00428       double dflt = 0
    00429     ) const;
    00430
    00438     virtual void SetReal(
    00439       const PString & key,
    00440       double value
    00441     );
    00443     virtual void SetReal(
    00444       const PString & section,
    00445       const PString & key,
    00446       double value
    00447     );
    00448
    00458     virtual PTime GetTime(
    00459       const PString & key
    00460     ) const;
    00462     virtual PTime GetTime(
    00463       const PString & key,
    00464       const PTime & dflt
    00465     ) const;
    00467     virtual PTime GetTime(
    00468       const PString & section,
    00469       const PString & key
    00470     ) const;
    00472     virtual PTime GetTime(
    00473       const PString & section,
    00474       const PString & key,
    00475       const PTime & dflt
    00476     ) const;
    00477
    00481     virtual void SetTime(
    00482       const PString & key,
    00483       const PTime & value
    00484     );
    00486     virtual void SetTime(
    00487       const PString & section,
    00488       const PString & key,
    00489       const PTime & value
    00490     );
    00492
    00493
    00494   protected:
    00495     // Member variables
    00497     PString defaultSection;
    00498
    00499
    00500   private:
    00501     // Do common construction code.
    00502     void Construct(
    00503       Source src,
    00504       const PString & appname,
    00505       const PString & manuf
    00506     );
    00507     void Construct(
    00508       const PFilePath & filename
    00509     );
    00510
    00511
    00512 // Include platform dependent part of class
    00513 #ifdef _WIN32
    00514 #include "msos/ptlib/config.h"
    00515 #else
    00516 #include "unix/ptlib/config.h"
    00517 #endif
    00518 };
    00519
    00520 #endif // P_CONFIG_FILE
    00521
    00522 #endif // PTLIB_CONFIG_H
    00523
    00524 // End Of File ///////////////////////////////////////////////////////////////