1 /*
2 * pconfig.cxx
3 *
4 * Operating System utilities.
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: 20385 $
30 * $Author: rjongbloed $
31 * $Date: 2008-06-04 05:40:38 -0500 (Wed, 04 Jun 2008) $
32 */
33
34 #include <ptlib.h>
35
36 #if P_CONFIG_FILE
37
38 #include <ctype.h>
39
40
41 ///////////////////////////////////////////////////////////////////////////////
42 // PConfig
43
GetAllKeyValues(const PString & section) const44 PStringToString PConfig::GetAllKeyValues(const PString & section) const
45 {
46 PStringToString dict;
47
48 PStringArray keys = GetKeys(section);
49 for (PINDEX i = 0; i < keys.GetSize(); i++)
50 dict.SetAt(keys[i], GetString(section, keys[i], ""));
51
52 return dict;
53 }
54
55
56 #if !defined(_WIN32) || defined (__NUCLEUS_MNT__)
57
GetBoolean(const PString & section,const PString & key,PBoolean dflt) const58 PBoolean PConfig::GetBoolean(const PString & section, const PString & key, PBoolean dflt) const
59 {
60 PString str = GetString(section, key, dflt ? "T" : "F").ToUpper();
61 return str[0] == 'T' || str[0] == 'Y' || str.AsInteger() != 0;
62 }
63
64
SetBoolean(const PString & section,const PString & key,PBoolean value)65 void PConfig::SetBoolean(const PString & section, const PString & key, PBoolean value)
66 {
67 SetString(section, key, value ? "True" : "False");
68 }
69
70
GetInteger(const PString & section,const PString & key,long dflt) const71 long PConfig::GetInteger(const PString & section, const PString & key, long dflt) const
72 {
73 PString str(PString::Signed, dflt);
74 return GetString(section, key, str).AsInteger();
75 }
76
77
SetInteger(const PString & section,const PString & key,long value)78 void PConfig::SetInteger(const PString & section, const PString & key, long value)
79 {
80 PString str(PString::Signed, value);
81 SetString(section, key, str);
82 }
83
84 #endif
85
86
GetInt64(const PString & section,const PString & key,PInt64 dflt) const87 PInt64 PConfig::GetInt64(const PString & section, const PString & key, PInt64 dflt) const
88 {
89 PString str = GetString(section, key, "");
90 if (!str)
91 return str.AsInt64();
92 return dflt;
93 }
94
95
SetInt64(const PString & section,const PString & key,PInt64 value)96 void PConfig::SetInt64(const PString & section, const PString & key, PInt64 value)
97 {
98 PStringStream strm;
99 strm << value;
100 SetString(section, key, strm);
101 }
102
103
GetReal(const PString & section,const PString & key,double dflt) const104 double PConfig::GetReal(const PString & section, const PString & key, double dflt) const
105 {
106 PString str(PString::Printf, "%g", dflt);
107 return GetString(section, key, str).AsReal();
108 }
109
110
SetReal(const PString & section,const PString & key,double value)111 void PConfig::SetReal(const PString & section, const PString & key, double value)
112 {
113 PString str(PString::Printf, "%g", value);
114 SetString(section, key, str);
115 }
116
117
GetTime(const PString & section,const PString & key) const118 PTime PConfig::GetTime(const PString & section, const PString & key) const
119 {
120 return GetString(section, key, "1 Jan 1996");
121 }
122
123
GetTime(const PString & section,const PString & key,const PTime & dflt) const124 PTime PConfig::GetTime(const PString & section, const PString & key, const PTime & dflt) const
125 {
126 return GetString(section, key, dflt.AsString());
127 }
128
129
SetTime(const PString & section,const PString & key,const PTime & value)130 void PConfig::SetTime(const PString & section, const PString & key, const PTime & value)
131 {
132 SetString(section, key, value.AsString());
133 }
134
135 #endif // P_CONFIG_FILE
136
137
138 // End Of File ///////////////////////////////////////////////////////////////
139