PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
config.h
Go to the documentation of this file.
1 /*
2  * config.h
3  *
4  * Application/System configuration access class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 32469 $
30  * $Author: rjongbloed $
31  * $Date: 2014-08-09 12:00:52 +1000 (Sat, 09 Aug 2014) $
32  */
33 
34 
35 #ifndef PTLIB_CONFIG_H
36 #define PTLIB_CONFIG_H
37 
38 #ifdef P_USE_PRAGMA
39 #pragma interface
40 #endif
41 
42 #include "ptlib.h"
43 #ifdef P_CONFIG_FILE
44 
45 
66 class PConfig : public PObject
67 {
68  PCLASSINFO(PConfig, PObject);
69 
70  public:
75  enum Source {
97  };
98 
104  PConfig(
105  Source src = Application
106  );
108  PConfig(
109  Source src,
110  const PString & appname
111  );
113  PConfig(
114  Source src,
115  const PString & appname,
116  const PString & manuf
117  );
119  PConfig(
120  const PString & section,
121  Source src = Application
122  );
124  PConfig(
125  const PString & section,
126  Source src,
127  const PString & appname
128  );
130  PConfig(
131  const PString & section,
132  Source src,
133  const PString & appname,
134  const PString & manuf
135  );
137  PConfig(
138  const PFilePath & filename,
139  const PString & section
140  );
142 
152  virtual void SetDefaultSection(
153  const PString & section
154  );
155 
165  virtual PString GetDefaultSection() const;
166 
175  virtual PStringArray GetSections() const;
176 
182  virtual PStringArray GetKeys() const;
184  virtual PStringArray GetKeys(
185  const PString & section
186  ) const;
187 
193  virtual PStringToString GetAllKeyValues() const;
196  const PString & section
197  ) const;
198 
199 
206  virtual void DeleteSection();
208  virtual void DeleteSection(
209  const PString & section
210  );
211 
220  virtual void DeleteKey(
221  const PString & key
222  );
224  virtual void DeleteKey(
225  const PString & section,
226  const PString & key
227  );
228 
237  virtual PBoolean HasKey(
238  const PString & key
239  ) const;
241  virtual PBoolean HasKey(
242  const PString & section,
243  const PString & key
244  ) const;
246 
259  virtual PString GetString(
260  const PString & key
261  ) const;
263  virtual PString GetString(
264  const PString & key,
265  const PString & dflt
266  ) const;
268  virtual PString GetString(
269  const PString & section,
270  const PString & key,
271  const PString & dflt
272  ) const;
273 
277  virtual void SetString(
278  const PString & key,
279  const PString & value
280  );
282  virtual void SetString(
283  const PString & section,
284  const PString & key,
285  const PString & value
286  );
287 
288 
305  virtual PBoolean GetBoolean(
306  const PString & key,
307  PBoolean dflt = false
308  ) const;
310  virtual PBoolean GetBoolean(
311  const PString & section,
312  const PString & key,
313  PBoolean dflt = false
314  ) const;
315 
322  virtual void SetBoolean(
323  const PString & key,
324  PBoolean value
325  );
327  virtual void SetBoolean(
328  const PString & section,
329  const PString & key,
330  PBoolean value
331  );
332 
333 
334  /* Get an integer variable determined by the key in the section. If the
335  section name is not specified then the default section is used.
336 
337  If the key is not present the value returned is the that provided by
338  the <code>dlft</code> parameter. Note that this is different from the
339  key being present but having no value, in which case zero is returned.
340 
341  @return integer value of the variable.
342  */
343  virtual long GetInteger(
344  const PString & key,
345  long dflt = 0
346  ) const;
347  /* Get an integer variable determined by the key in the section. */
348  virtual long GetInteger(
349  const PString & section,
350  const PString & key,
351  long dflt = 0
352  ) const;
353 
360  virtual void SetInteger(
361  const PString & key,
362  long value
363  );
365  virtual void SetInteger(
366  const PString & section,
367  const PString & key,
368  long value
369  );
370 
371 
372  /* Get an enum variable determined by the key in the section. If the
373  section name is not specified then the default section is used.
374 
375  @return enum value of the variable.
376  */
377  template <typename Enumeration>
378  Enumeration GetEnum(
379  const PString & key,
380  Enumeration dflt
381  ) const { return (Enumeration)GetInteger(key, dflt); }
382  /* Get an enum variable determined by the key in the section. */
383  template <typename Enumeration>
384  Enumeration GetEnum(
385  const PString & section,
386  const PString & key,
387  Enumeration dflt
388  ) const { return (Enumeration)GetInteger(section, key, dflt); }
389 
396  template <typename Enumeration>
397  void SetEnum(
398  const PString & key,
399  Enumeration value
400  ) { SetInteger(key, value); }
402  template <typename Enumeration>
403  void SetEnum(
404  const PString & section,
405  const PString & key,
406  Enumeration value
407  ) { SetInteger(section, key, value); }
408 
409 
419  virtual PInt64 GetInt64(
420  const PString & key,
421  PInt64 dflt = 0
422  ) const;
424  virtual PInt64 GetInt64(
425  const PString & section,
426  const PString & key,
427  PInt64 dflt = 0
428  ) const;
429 
436  virtual void SetInt64(
437  const PString & key,
438  PInt64 value
439  );
441  virtual void SetInt64(
442  const PString & section,
443  const PString & key,
444  PInt64 value
445  );
446 
447 
457  virtual double GetReal(
458  const PString & key,
459  double dflt = 0
460  ) const;
462  virtual double GetReal(
463  const PString & section,
464  const PString & key,
465  double dflt = 0
466  ) const;
467 
475  virtual void SetReal(
476  const PString & key,
477  double value
478  );
480  virtual void SetReal(
481  const PString & section,
482  const PString & key,
483  double value
484  );
485 
495  virtual PTime GetTime(
496  const PString & key
497  ) const;
499  virtual PTime GetTime(
500  const PString & key,
501  const PTime & dflt
502  ) const;
504  virtual PTime GetTime(
505  const PString & section,
506  const PString & key
507  ) const;
509  virtual PTime GetTime(
510  const PString & section,
511  const PString & key,
512  const PTime & dflt
513  ) const;
514 
518  virtual void SetTime(
519  const PString & key,
520  const PTime & value
521  );
523  virtual void SetTime(
524  const PString & section,
525  const PString & key,
526  const PTime & value
527  );
529 
530 
531  static const PString & DefaultSectionName();
532 
533  protected:
534  // Member variables
537 
538 
539  private:
540  // Do common construction code.
541  void Construct(
542  Source src,
543  const PString & appname,
544  const PString & manuf
545  );
546  void Construct(
547  const PFilePath & filename
548  );
549 
550 
551 // Include platform dependent part of class
552 #ifdef _WIN32
553 #include "msos/ptlib/config.h"
554 #else
555 #include "unix/ptlib/config.h"
556 #endif
557 };
558 
559 #endif // P_CONFIG_FILE
560 
561 #endif // PTLIB_CONFIG_H
562 
563 // End Of File ///////////////////////////////////////////////////////////////