PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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: 27762 $
30 * $Author: rjongbloed $
31 * $Date: 2012-06-04 17:02:25 +1000 (Mon, 04 Jun 2012) $
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 {
81 Environment,
87 System,
96 Application,
97 NumSources
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;
196 virtual PStringToString GetAllKeyValues(
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
373 /* Get an enum variable determined by the key in the section. If the
374 section name is not specified then the default section is used.
375
376 @return enum value of the variable.
377 */
378 template <typename Enumeration>
379 Enumeration GetEnum(
380 const PString & key,
381 Enumeration dflt
382 ) const { return (Enumeration)GetInteger(key, dflt); }
383 /* Get an enum variable determined by the key in the section. */
384 template <typename Enumeration>
385 Enumeration GetEnum(
386 const PString & section,
387 const PString & key,
388 Enumeration dflt
389 ) const { return (Enumeration)GetInteger(section, key, dflt); }
390
397 template <typename Enumeration>
398 void SetEnum(
399 const PString & key,
400 Enumeration value
401 ) { SetInteger(key, value); }
403 template <typename Enumeration>
404 void SetEnum(
405 const PString & section,
406 const PString & key,
407 Enumeration value
408 ) { SetInteger(section, key, value); }
409
410
420 virtual PInt64 GetInt64(
421 const PString & key,
422 PInt64 dflt = 0
423 ) const;
425 virtual PInt64 GetInt64(
426 const PString & section,
427 const PString & key,
428 PInt64 dflt = 0
429 ) const;
430
437 virtual void SetInt64(
438 const PString & key,
439 PInt64 value
440 );
442 virtual void SetInt64(
443 const PString & section,
444 const PString & key,
445 PInt64 value
446 );
447
448
458 virtual double GetReal(
459 const PString & key,
460 double dflt = 0
461 ) const;
463 virtual double GetReal(
464 const PString & section,
465 const PString & key,
466 double dflt = 0
467 ) const;
468
476 virtual void SetReal(
477 const PString & key,
478 double value
479 );
481 virtual void SetReal(
482 const PString & section,
483 const PString & key,
484 double value
485 );
486
496 virtual PTime GetTime(
497 const PString & key
498 ) const;
500 virtual PTime GetTime(
501 const PString & key,
502 const PTime & dflt
503 ) const;
505 virtual PTime GetTime(
506 const PString & section,
507 const PString & key
508 ) const;
510 virtual PTime GetTime(
511 const PString & section,
512 const PString & key,
513 const PTime & dflt
514 ) const;
515
519 virtual void SetTime(
520 const PString & key,
521 const PTime & value
522 );
524 virtual void SetTime(
525 const PString & section,
526 const PString & key,
527 const PTime & value
528 );
530
531
532 protected:
533 // Member variables
535 PString defaultSection;
536
537
538 private:
539 // Do common construction code.
540 void Construct(
541 Source src,
542 const PString & appname,
543 const PString & manuf
544 );
545 void Construct(
546 const PFilePath & filename
547 );
548
549
550 // Include platform dependent part of class
551 #ifdef _WIN32
552 #include "msos/ptlib/config.h"
553 #else
554 #include "unix/ptlib/config.h"
555 #endif
556 };
557
558 #endif // P_CONFIG_FILE
559
560 #endif // PTLIB_CONFIG_H
561
562 // End Of File ///////////////////////////////////////////////////////////////