PTLib  Version 2.10.4
 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: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
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 "ptbuildopts.h"
43 #ifdef P_CONFIG_FILE
44 
45 class PXConfig;
46 
67 class PConfig : public PObject
68 {
69  PCLASSINFO(PConfig, PObject);
70 
71  public:
76  enum Source {
98  };
99 
105  PConfig(
106  Source src = Application
107  );
109  PConfig(
110  Source src,
111  const PString & appname
112  );
114  PConfig(
115  Source src,
116  const PString & appname,
117  const PString & manuf
118  );
120  PConfig(
121  const PString & section,
122  Source src = Application
123  );
125  PConfig(
126  const PString & section,
127  Source src,
128  const PString & appname
129  );
131  PConfig(
132  const PString & section,
133  Source src,
134  const PString & appname,
135  const PString & manuf
136  );
138  PConfig(
139  const PFilePath & filename,
140  const PString & section
141  );
143 
153  virtual void SetDefaultSection(
154  const PString & section
155  );
156 
166  virtual PString GetDefaultSection() const;
167 
176  virtual PStringArray GetSections() const;
177 
183  virtual PStringArray GetKeys() const;
185  virtual PStringArray GetKeys(
186  const PString & section
187  ) const;
188 
194  virtual PStringToString GetAllKeyValues() const;
197  const PString & section
198  ) const;
199 
200 
207  virtual void DeleteSection();
209  virtual void DeleteSection(
210  const PString & section
211  );
212 
221  virtual void DeleteKey(
222  const PString & key
223  );
225  virtual void DeleteKey(
226  const PString & section,
227  const PString & key
228  );
229 
238  virtual PBoolean HasKey(
239  const PString & key
240  ) const;
242  virtual PBoolean HasKey(
243  const PString & section,
244  const PString & key
245  ) const;
247 
260  virtual PString GetString(
261  const PString & key
262  ) const;
264  virtual PString GetString(
265  const PString & key,
266  const PString & dflt
267  ) const;
269  virtual PString GetString(
270  const PString & section,
271  const PString & key,
272  const PString & dflt
273  ) const;
274 
278  virtual void SetString(
279  const PString & key,
280  const PString & value
281  );
283  virtual void SetString(
284  const PString & section,
285  const PString & key,
286  const PString & value
287  );
288 
289 
306  virtual PBoolean GetBoolean(
307  const PString & key,
308  PBoolean dflt = false
309  ) const;
311  virtual PBoolean GetBoolean(
312  const PString & section,
313  const PString & key,
314  PBoolean dflt = false
315  ) const;
316 
323  virtual void SetBoolean(
324  const PString & key,
325  PBoolean value
326  );
328  virtual void SetBoolean(
329  const PString & section,
330  const PString & key,
331  PBoolean value
332  );
333 
334 
335  /* Get an integer variable determined by the key in the section. If the
336  section name is not specified then the default section is used.
337 
338  If the key is not present the value returned is the that provided by
339  the <code>dlft</code> parameter. Note that this is different from the
340  key being present but having no value, in which case zero is returned.
341 
342  @return integer value of the variable.
343  */
344  virtual long GetInteger(
345  const PString & key,
346  long dflt = 0
347  ) const;
348  /* Get an integer variable determined by the key in the section. */
349  virtual long GetInteger(
350  const PString & section,
351  const PString & key,
352  long dflt = 0
353  ) const;
354 
361  virtual void SetInteger(
362  const PString & key,
363  long value
364  );
366  virtual void SetInteger(
367  const PString & section,
368  const PString & key,
369  long value
370  );
371 
372 
382  virtual PInt64 GetInt64(
383  const PString & key,
384  PInt64 dflt = 0
385  ) const;
387  virtual PInt64 GetInt64(
388  const PString & section,
389  const PString & key,
390  PInt64 dflt = 0
391  ) const;
392 
399  virtual void SetInt64(
400  const PString & key,
401  PInt64 value
402  );
404  virtual void SetInt64(
405  const PString & section,
406  const PString & key,
407  PInt64 value
408  );
409 
410 
420  virtual double GetReal(
421  const PString & key,
422  double dflt = 0
423  ) const;
425  virtual double GetReal(
426  const PString & section,
427  const PString & key,
428  double dflt = 0
429  ) const;
430 
438  virtual void SetReal(
439  const PString & key,
440  double value
441  );
443  virtual void SetReal(
444  const PString & section,
445  const PString & key,
446  double value
447  );
448 
458  virtual PTime GetTime(
459  const PString & key
460  ) const;
462  virtual PTime GetTime(
463  const PString & key,
464  const PTime & dflt
465  ) const;
467  virtual PTime GetTime(
468  const PString & section,
469  const PString & key
470  ) const;
472  virtual PTime GetTime(
473  const PString & section,
474  const PString & key,
475  const PTime & dflt
476  ) const;
477 
481  virtual void SetTime(
482  const PString & key,
483  const PTime & value
484  );
486  virtual void SetTime(
487  const PString & section,
488  const PString & key,
489  const PTime & value
490  );
492 
493 
494  protected:
495  // Member variables
498 
499 
500  private:
501  // Do common construction code.
502  void Construct(
503  Source src,
504  const PString & appname,
505  const PString & manuf
506  );
507  void Construct(
508  const PFilePath & filename
509  );
510 
511 
512 // Include platform dependent part of class
513 #ifdef _WIN32
514 #include "msos/ptlib/config.h"
515 #else
516 #include "unix/ptlib/config.h"
517 #endif
518 };
519 
520 #endif // P_CONFIG_FILE
521 
522 #endif // PTLIB_CONFIG_H
523 
524 // End Of File ///////////////////////////////////////////////////////////////