PWLib
1.10.10
|
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 * $Log: config.h,v $ 00030 * Revision 1.28 2005/11/25 03:43:47 csoutheren 00031 * Fixed function argument comments to be compatible with Doxygen 00032 * 00033 * Revision 1.27 2005/01/26 05:37:44 csoutheren 00034 * Added ability to remove config file support 00035 * 00036 * Revision 1.26 2004/01/06 21:16:38 csoutheren 00037 * Added "virtual" keyword to methods to allow descendant classes. 00038 * Thanks to Cristian Bullokles for pointing out this issue 00039 * 00040 * Revision 1.25 2003/09/17 05:41:58 csoutheren 00041 * Removed recursive includes 00042 * 00043 * Revision 1.24 2003/09/17 01:18:02 csoutheren 00044 * Removed recursive include file system and removed all references 00045 * to deprecated coooperative threading support 00046 * 00047 * Revision 1.23 2002/09/16 01:08:59 robertj 00048 * Added #define so can select if #pragma interface/implementation is used on 00049 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00050 * 00051 * Revision 1.22 2001/05/22 12:49:32 robertj 00052 * Did some seriously wierd rewrite of platform headers to eliminate the 00053 * stupid GNU compiler warning about braces not matching. 00054 * 00055 * Revision 1.21 2000/05/25 11:07:26 robertj 00056 * Added PConfig::HasKey() function to determine if value actually set. 00057 * 00058 * Revision 1.20 1999/03/09 02:59:49 robertj 00059 * Changed comments to doc++ compatible documentation. 00060 * 00061 * Revision 1.19 1999/02/16 08:07:11 robertj 00062 * MSVC 6.0 compatibility changes. 00063 * 00064 * Revision 1.18 1998/10/30 12:23:55 robertj 00065 * Added ability to get all key values as a dictionary. 00066 * 00067 * Revision 1.17 1998/09/23 06:20:21 robertj 00068 * Added open source copyright license. 00069 * 00070 * Revision 1.16 1998/01/26 00:29:26 robertj 00071 * Added functions to get/set 64bit integers from a PConfig. 00072 * 00073 * Revision 1.15 1997/08/07 11:58:01 robertj 00074 * Added ability to get registry data from other applications and anywhere in system registry. 00075 * 00076 * Revision 1.14 1996/02/25 02:50:33 robertj 00077 * Added consts to all GetXxxx functions. 00078 * 00079 * Revision 1.13 1996/01/28 14:10:10 robertj 00080 * Added time functions to PConfig. 00081 * 00082 * Revision 1.12 1995/12/10 11:54:30 robertj 00083 * Added WIN32 registry support for PConfig objects. 00084 * 00085 * Revision 1.11 1995/03/14 12:41:12 robertj 00086 * Updated documentation to use HTML codes. 00087 * 00088 * Revision 1.10 1995/01/27 11:06:20 robertj 00089 * Changed single string default constructor to be section name not file name. 00090 * 00091 * Revision 1.9 1994/12/12 10:11:59 robertj 00092 * Documentation. 00093 * 00094 * Revision 1.8 1994/08/23 11:32:52 robertj 00095 * Oops 00096 * 00097 * Revision 1.7 1994/08/22 00:46:48 robertj 00098 * Added pragma fro GNU C++ compiler. 00099 * 00100 * Revision 1.6 1994/08/21 23:43:02 robertj 00101 * Removed default argument when of PString type (MSC crashes). 00102 * 00103 * Revision 1.5 1994/07/27 05:58:07 robertj 00104 * Synchronisation. 00105 * 00106 * Revision 1.4 1994/06/25 11:55:15 robertj 00107 * Unix version synchronisation. 00108 * 00109 * Revision 1.3 1994/01/03 04:42:23 robertj 00110 * Mass changes to common container classes and interactors etc etc etc. 00111 * 00112 * Revision 1.2 1993/07/14 12:49:16 robertj 00113 * Fixed RCS keywords. 00114 * 00115 */ 00116 00117 00118 #ifndef _PCONFIG 00119 #define _PCONFIG 00120 00121 #ifdef P_USE_PRAGMA 00122 #pragma interface 00123 #endif 00124 00125 #include "ptbuildopts.h" 00126 #ifdef P_CONFIG_FILE 00127 00128 class PXConfig; 00129 00150 class PConfig : public PObject 00151 { 00152 PCLASSINFO(PConfig, PObject); 00153 00154 public: 00159 enum Source { 00164 Environment, 00170 System, 00179 Application, 00180 NumSources 00181 }; 00182 00188 PConfig( 00189 Source src = Application 00190 ); 00192 PConfig( 00193 Source src, 00194 const PString & appname 00195 ); 00197 PConfig( 00198 Source src, 00199 const PString & appname, 00200 const PString & manuf 00201 ); 00203 PConfig( 00204 const PString & section, 00205 Source src = Application 00206 ); 00208 PConfig( 00209 const PString & section, 00210 Source src, 00211 const PString & appname 00212 ); 00214 PConfig( 00215 const PString & section, 00216 Source src, 00217 const PString & appname, 00218 const PString & manuf 00219 ); 00221 PConfig( 00222 const PFilePath & filename, 00223 const PString & section 00224 ); 00226 00236 virtual void SetDefaultSection( 00237 const PString & section 00238 ); 00239 00249 virtual PString GetDefaultSection() const; 00250 00259 virtual PStringList GetSections() const; 00260 00266 virtual PStringList GetKeys() const; 00268 virtual PStringList GetKeys( 00269 const PString & section 00270 ) const; 00271 00277 virtual PStringToString GetAllKeyValues() const; 00279 virtual PStringToString GetAllKeyValues( 00280 const PString & section 00281 ) const; 00282 00283 00290 virtual void DeleteSection(); 00292 virtual void DeleteSection( 00293 const PString & section 00294 ); 00295 00304 virtual void DeleteKey( 00305 const PString & key 00306 ); 00308 virtual void DeleteKey( 00309 const PString & section, 00310 const PString & key 00311 ); 00312 00321 virtual BOOL HasKey( 00322 const PString & key 00323 ) const; 00325 virtual BOOL HasKey( 00326 const PString & section, 00327 const PString & key 00328 ) const; 00330 00343 virtual PString GetString( 00344 const PString & key 00345 ) const; 00347 virtual PString GetString( 00348 const PString & key, 00349 const PString & dflt 00350 ) const; 00352 virtual PString GetString( 00353 const PString & section, 00354 const PString & key, 00355 const PString & dflt 00356 ) const; 00357 00361 virtual void SetString( 00362 const PString & key, 00363 const PString & value 00364 ); 00366 virtual void SetString( 00367 const PString & section, 00368 const PString & key, 00369 const PString & value 00370 ); 00371 00372 00389 virtual BOOL GetBoolean( 00390 const PString & key, 00391 BOOL dflt = FALSE 00392 ) const; 00394 virtual BOOL GetBoolean( 00395 const PString & section, 00396 const PString & key, 00397 BOOL dflt = FALSE 00398 ) const; 00399 00406 virtual void SetBoolean( 00407 const PString & key, 00408 BOOL value 00409 ); 00411 virtual void SetBoolean( 00412 const PString & section, 00413 const PString & key, 00414 BOOL value 00415 ); 00416 00417 00418 /* Get an integer variable determined by the key in the section. If the 00419 section name is not specified then the default section is used. 00420 00421 If the key is not present the value returned is the that provided by 00422 the #dlft# parameter. Note that this is different from the 00423 key being present but having no value, in which case zero is returned. 00424 00425 @return integer value of the variable. 00426 */ 00427 virtual long GetInteger( 00428 const PString & key, 00429 long dflt = 0 00430 ) const; 00431 /* Get an integer variable determined by the key in the section. */ 00432 virtual long GetInteger( 00433 const PString & section, 00434 const PString & key, 00435 long dflt = 0 00436 ) const; 00437 00444 virtual void SetInteger( 00445 const PString & key, 00446 long value 00447 ); 00449 virtual void SetInteger( 00450 const PString & section, 00451 const PString & key, 00452 long value 00453 ); 00454 00455 00465 virtual PInt64 GetInt64( 00466 const PString & key, 00467 PInt64 dflt = 0 00468 ) const; 00470 virtual PInt64 GetInt64( 00471 const PString & section, 00472 const PString & key, 00473 PInt64 dflt = 0 00474 ) const; 00475 00482 virtual void SetInt64( 00483 const PString & key, 00484 PInt64 value 00485 ); 00487 virtual void SetInt64( 00488 const PString & section, 00489 const PString & key, 00490 PInt64 value 00491 ); 00492 00493 00503 virtual double GetReal( 00504 const PString & key, 00505 double dflt = 0 00506 ) const; 00508 virtual double GetReal( 00509 const PString & section, 00510 const PString & key, 00511 double dflt = 0 00512 ) const; 00513 00521 virtual void SetReal( 00522 const PString & key, 00523 double value 00524 ); 00526 virtual void SetReal( 00527 const PString & section, 00528 const PString & key, 00529 double value 00530 ); 00531 00541 virtual PTime GetTime( 00542 const PString & key 00543 ) const; 00545 virtual PTime GetTime( 00546 const PString & key, 00547 const PTime & dflt 00548 ) const; 00550 virtual PTime GetTime( 00551 const PString & section, 00552 const PString & key 00553 ) const; 00555 virtual PTime GetTime( 00556 const PString & section, 00557 const PString & key, 00558 const PTime & dflt 00559 ) const; 00560 00564 virtual void SetTime( 00565 const PString & key, 00566 const PTime & value 00567 ); 00569 virtual void SetTime( 00570 const PString & section, 00571 const PString & key, 00572 const PTime & value 00573 ); 00575 00576 00577 protected: 00578 // Member variables 00580 PString defaultSection; 00581 00582 00583 private: 00584 // Do common construction code. 00585 void Construct( 00586 Source src, 00587 const PString & appname, 00588 const PString & manuf 00589 ); 00590 void Construct( 00591 const PFilePath & filename 00592 ); 00593 00594 00595 // Include platform dependent part of class 00596 #ifdef _WIN32 00597 #include "msos/ptlib/config.h" 00598 #else 00599 #include "unix/ptlib/config.h" 00600 #endif 00601 }; 00602 00603 #endif // P_CONFIG_FILE 00604 00605 #endif 00606 00607 // End Of File ///////////////////////////////////////////////////////////////