PTLib  Version 2.18.8
 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 
30 
31 #ifndef PTLIB_CONFIG_H
32 #define PTLIB_CONFIG_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include "ptlib.h"
39 #ifdef P_CONFIG_FILE
40 
41 
62 class PConfig : public PObject
63 {
64  PCLASSINFO(PConfig, PObject);
65 
66  public:
71  enum Source {
93  };
94 
100  PConfig(
101  Source src = Application
102  );
104  PConfig(
105  Source src,
106  const PString & appname
107  );
109  PConfig(
110  Source src,
111  const PString & appname,
112  const PString & manuf
113  );
115  PConfig(
116  const PString & section,
117  Source src = Application
118  );
120  PConfig(
121  const PString & section,
122  Source src,
123  const PString & appname
124  );
126  PConfig(
127  const PString & section,
128  Source src,
129  const PString & appname,
130  const PString & manuf
131  );
133  PConfig(
134  const PFilePath & filename,
135  const PString & section
136  );
138 
148  virtual void SetDefaultSection(
149  const PString & section
150  );
151 
161  virtual PString GetDefaultSection() const;
162 
171  virtual PStringArray GetSections() const;
172 
178  virtual PStringArray GetKeys() const;
180  virtual PStringArray GetKeys(
181  const PString & section
182  ) const;
183 
189  virtual PStringToString GetAllKeyValues() const;
192  const PString & section
193  ) const;
194 
195 
202  virtual void DeleteSection();
204  virtual void DeleteSection(
205  const PString & section
206  );
207 
216  virtual void DeleteKey(
217  const PString & key
218  );
220  virtual void DeleteKey(
221  const PString & section,
222  const PString & key
223  );
224 
233  virtual PBoolean HasKey(
234  const PString & key
235  ) const;
237  virtual PBoolean HasKey(
238  const PString & section,
239  const PString & key
240  ) const;
242 
255  virtual PString GetString(
256  const PString & key
257  ) const;
259  virtual PString GetString(
260  const PString & key,
261  const PString & dflt
262  ) const;
264  virtual PString GetString(
265  const PString & section,
266  const PString & key,
267  const PString & dflt
268  ) const;
269 
273  virtual void SetString(
274  const PString & key,
275  const PString & value
276  );
278  virtual void SetString(
279  const PString & section,
280  const PString & key,
281  const PString & value
282  );
283 
284 
301  virtual PBoolean GetBoolean(
302  const PString & key,
303  PBoolean dflt = false
304  ) const;
306  virtual PBoolean GetBoolean(
307  const PString & section,
308  const PString & key,
309  PBoolean dflt = false
310  ) const;
311 
318  virtual void SetBoolean(
319  const PString & key,
320  PBoolean value
321  );
323  virtual void SetBoolean(
324  const PString & section,
325  const PString & key,
326  PBoolean value
327  );
328 
329 
330  /* Get an integer variable determined by the key in the section. If the
331  section name is not specified then the default section is used.
332 
333  If the key is not present the value returned is the that provided by
334  the <code>dlft</code> parameter. Note that this is different from the
335  key being present but having no value, in which case zero is returned.
336 
337  @return integer value of the variable.
338  */
339  virtual long GetInteger(
340  const PString & key,
341  long dflt = 0
342  ) const;
343  /* Get an integer variable determined by the key in the section. */
344  virtual long GetInteger(
345  const PString & section,
346  const PString & key,
347  long dflt = 0
348  ) const;
349 
356  virtual void SetInteger(
357  const PString & key,
358  long value
359  );
361  virtual void SetInteger(
362  const PString & section,
363  const PString & key,
364  long value
365  );
366 
367 
368  /* Get an enum variable determined by the key in the section. If the
369  section name is not specified then the default section is used.
370 
371  @return enum value of the variable.
372  */
373  template <typename Enumeration>
374  Enumeration GetEnum(
375  const PString & key,
376  Enumeration dflt
377  ) const { return (Enumeration)GetInteger(key, dflt); }
378  /* Get an enum variable determined by the key in the section. */
379  template <typename Enumeration>
380  Enumeration GetEnum(
381  const PString & section,
382  const PString & key,
383  Enumeration dflt
384  ) const { return (Enumeration)GetInteger(section, key, dflt); }
385 
392  template <typename Enumeration>
393  void SetEnum(
394  const PString & key,
395  Enumeration value
396  ) { SetInteger(key, value); }
398  template <typename Enumeration>
399  void SetEnum(
400  const PString & section,
401  const PString & key,
402  Enumeration value
403  ) { SetInteger(section, key, value); }
404 
405 
415  virtual PInt64 GetInt64(
416  const PString & key,
417  PInt64 dflt = 0
418  ) const;
420  virtual PInt64 GetInt64(
421  const PString & section,
422  const PString & key,
423  PInt64 dflt = 0
424  ) const;
425 
432  virtual void SetInt64(
433  const PString & key,
434  PInt64 value
435  );
437  virtual void SetInt64(
438  const PString & section,
439  const PString & key,
440  PInt64 value
441  );
442 
443 
453  virtual double GetReal(
454  const PString & key,
455  double dflt = 0
456  ) const;
458  virtual double GetReal(
459  const PString & section,
460  const PString & key,
461  double dflt = 0
462  ) const;
463 
471  virtual void SetReal(
472  const PString & key,
473  double value
474  );
476  virtual void SetReal(
477  const PString & section,
478  const PString & key,
479  double value
480  );
481 
491  virtual PTime GetTime(
492  const PString & key
493  ) const;
495  virtual PTime GetTime(
496  const PString & key,
497  const PTime & dflt
498  ) const;
500  virtual PTime GetTime(
501  const PString & section,
502  const PString & key
503  ) const;
505  virtual PTime GetTime(
506  const PString & section,
507  const PString & key,
508  const PTime & dflt
509  ) const;
510 
514  virtual void SetTime(
515  const PString & key,
516  const PTime & value
517  );
519  virtual void SetTime(
520  const PString & section,
521  const PString & key,
522  const PTime & value
523  );
525 
526 
527  static const PString & DefaultSectionName();
528 
529  protected:
530  // Member variables
533 
534 
535  private:
536  // Do common construction code.
537  void Construct(
538  Source src,
539  const PString & appname,
540  const PString & manuf
541  );
542  void Construct(
543  const PFilePath & filename
544  );
545 
546 
547 // Include platform dependent part of class
548 #ifdef _WIN32
549 #include "msos/ptlib/config.h"
550 #else
551 #include "unix/ptlib/config.h"
552 #endif
553 };
554 
555 #endif // P_CONFIG_FILE
556 
557 #endif // PTLIB_CONFIG_H
558 
559 // End Of File ///////////////////////////////////////////////////////////////
virtual void DeleteKey(const PString &key)
Delete the particular variable in the specified section.
virtual PBoolean GetBoolean(const PString &key, PBoolean dflt=false) const
Get a boolean variable determined by the key in the section.
virtual void SetReal(const PString &key, double value)
Set a floating point variable determined by the key in the section.
virtual void SetString(const PString &key, const PString &value)
Set a string variable determined by the key in the section.
This class defines an absolute time and date.
Definition: ptime.h:49
Enumeration GetEnum(const PString &key, Enumeration dflt) const
Definition: config.h:374
A class representing a configuration for the application.
Definition: config.h:62
virtual PStringToString GetAllKeyValues() const
Get all of the keys in the section and their values.
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:3151
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
virtual void SetBoolean(const PString &key, PBoolean value)
Set a boolean variable determined by the key in the section.
virtual PBoolean HasKey(const PString &key) const
Determine if the particular variable in the section is actually present.
PConfig(Source src=Application)
Create a new configuration object.
virtual void SetDefaultSection(const PString &section)
Set the default section for variable operations.
This is an array collection class of PString objects.
Definition: pstring.h:2365
The application specific configuration file.
Definition: config.h:91
virtual PString GetString(const PString &key) const
Get a string variable determined by the key in the section.
virtual PStringArray GetSections() const
Get all of the section names currently specified in the file.
The platform specific environment.
Definition: config.h:76
virtual void SetInteger(const PString &key, long value)
Set an integer variable determined by the key in the section.
Source
Description of the standard source for configuration information.
Definition: config.h:71
Definition: config.h:92
virtual PTime GetTime(const PString &key) const
Get a PTime variable determined by the key in the section.
virtual void SetInt64(const PString &key, PInt64 value)
Set a 64 bit integer variable determined by the key in the section.
bool PBoolean
Definition: object.h:174
void SetEnum(const PString &section, const PString &key, Enumeration value)
Set an enum variable determined by the key in the section.
Definition: config.h:399
The character string class.
Definition: pstring.h:108
The platform specific system wide configuration file.
Definition: config.h:82
static const PString & DefaultSectionName()
virtual void DeleteSection()
Delete all variables in the specified section.
virtual PString GetDefaultSection() const
Get the default section for variable operations.
PString defaultSection
The current section for variable values.
Definition: config.h:532
Enumeration GetEnum(const PString &section, const PString &key, Enumeration dflt) const
Definition: config.h:380
virtual PInt64 GetInt64(const PString &key, PInt64 dflt=0) const
Get a 64 bit integer variable determined by the key in the section.
virtual void SetTime(const PString &key, const PTime &value)
Set a PTime variable determined by the key in the section.
virtual double GetReal(const PString &key, double dflt=0) const
Get a floating point variable determined by the key in the section.
void SetEnum(const PString &key, Enumeration value)
Set an enum variable determined by the key in the section.
Definition: config.h:393
virtual PStringArray GetKeys() const
Get a list of all the keys in the section.
virtual long GetInteger(const PString &key, long dflt=0) const
Ultimate parent class for all objects in the class library.
Definition: object.h:2204