PTLib
Version 2.18.8
|
A class representing a configuration for the application. More...
#include <config.h>
Public Member Functions | |
~PConfig () | |
Section functions | |
virtual void | SetDefaultSection (const PString §ion) |
Set the default section for variable operations. More... | |
virtual PString | GetDefaultSection () const |
Get the default section for variable operations. More... | |
virtual PStringArray | GetSections () const |
Get all of the section names currently specified in the file. More... | |
virtual PStringArray | GetKeys () const |
Get a list of all the keys in the section. More... | |
virtual PStringArray | GetKeys (const PString §ion) const |
Get a list of all the keys in the section. More... | |
virtual PStringToString | GetAllKeyValues () const |
Get all of the keys in the section and their values. More... | |
virtual PStringToString | GetAllKeyValues (const PString §ion) const |
Get all of the keys in the section and their values. More... | |
virtual void | DeleteSection () |
Delete all variables in the specified section. More... | |
virtual void | DeleteSection (const PString §ion) |
Delete all variables in the specified section. More... | |
virtual void | DeleteKey (const PString &key) |
Delete the particular variable in the specified section. More... | |
virtual void | DeleteKey (const PString §ion, const PString &key) |
Delete the particular variable in the specified section. More... | |
virtual PBoolean | HasKey (const PString &key) const |
Determine if the particular variable in the section is actually present. More... | |
virtual PBoolean | HasKey (const PString §ion, const PString &key) const |
Determine if the particular variable in the section is actually present. More... | |
Get/Set variables | |
virtual PString | GetString (const PString &key) const |
Get a string variable determined by the key in the section. More... | |
virtual PString | GetString (const PString &key, const PString &dflt) const |
Get a string variable determined by the key in the section. More... | |
virtual PString | GetString (const PString §ion, const PString &key, const PString &dflt) const |
Get a string variable determined by the key in the section. More... | |
virtual void | SetString (const PString &key, const PString &value) |
Set a string variable determined by the key in the section. More... | |
virtual void | SetString (const PString §ion, const PString &key, const PString &value) |
Set a string variable determined by the key in the section. More... | |
virtual PBoolean | GetBoolean (const PString &key, PBoolean dflt=false) const |
Get a boolean variable determined by the key in the section. More... | |
virtual PBoolean | GetBoolean (const PString §ion, const PString &key, PBoolean dflt=false) const |
Get a boolean variable determined by the key in the section. More... | |
virtual void | SetBoolean (const PString &key, PBoolean value) |
Set a boolean variable determined by the key in the section. More... | |
virtual void | SetBoolean (const PString §ion, const PString &key, PBoolean value) |
Set a boolean variable determined by the key in the section. More... | |
virtual long | GetInteger (const PString &key, long dflt=0) const |
virtual long | GetInteger (const PString §ion, const PString &key, long dflt=0) const |
virtual void | SetInteger (const PString &key, long value) |
Set an integer variable determined by the key in the section. More... | |
virtual void | SetInteger (const PString §ion, const PString &key, long value) |
Set an integer variable determined by the key in the section. More... | |
template<typename Enumeration > | |
Enumeration | GetEnum (const PString &key, Enumeration dflt) const |
template<typename Enumeration > | |
Enumeration | GetEnum (const PString §ion, const PString &key, Enumeration dflt) const |
template<typename Enumeration > | |
void | SetEnum (const PString &key, Enumeration value) |
Set an enum variable determined by the key in the section. More... | |
template<typename Enumeration > | |
void | SetEnum (const PString §ion, const PString &key, Enumeration value) |
Set an enum variable determined by the key in the section. More... | |
virtual PInt64 | GetInt64 (const PString &key, PInt64 dflt=0) const |
Get a 64 bit integer variable determined by the key in the section. More... | |
virtual PInt64 | GetInt64 (const PString §ion, const PString &key, PInt64 dflt=0) const |
Get a 64 bit integer variable determined by the key in the section. More... | |
virtual void | SetInt64 (const PString &key, PInt64 value) |
Set a 64 bit integer variable determined by the key in the section. More... | |
virtual void | SetInt64 (const PString §ion, const PString &key, PInt64 value) |
Set a 64 bit integer variable determined by the key in the section. More... | |
virtual double | GetReal (const PString &key, double dflt=0) const |
Get a floating point variable determined by the key in the section. More... | |
virtual double | GetReal (const PString §ion, const PString &key, double dflt=0) const |
Get a floating point variable determined by the key in the section. More... | |
virtual void | SetReal (const PString &key, double value) |
Set a floating point variable determined by the key in the section. More... | |
virtual void | SetReal (const PString §ion, const PString &key, double value) |
Set a floating point variable determined by the key in the section. More... | |
virtual PTime | GetTime (const PString &key) const |
Get a PTime variable determined by the key in the section. More... | |
virtual PTime | GetTime (const PString &key, const PTime &dflt) const |
Get a PTime variable determined by the key in the section. More... | |
virtual PTime | GetTime (const PString §ion, const PString &key) const |
Get a PTime variable determined by the key in the section. More... | |
virtual PTime | GetTime (const PString §ion, const PString &key, const PTime &dflt) const |
Get a PTime variable determined by the key in the section. More... | |
virtual void | SetTime (const PString &key, const PTime &value) |
Set a PTime variable determined by the key in the section. More... | |
virtual void | SetTime (const PString §ion, const PString &key, const PTime &value) |
Set a PTime variable determined by the key in the section. More... | |
![]() | |
__inline unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
__inline void | SetTraceContextIdentifier (unsigned id) |
__inline void | SetTraceContextIdentifier (const PObject &obj) |
__inline void | SetTraceContextIdentifier (const PObject *obj) |
__inline void | CopyTraceContextIdentifier (PObject &obj) const |
__inline void | CopyTraceContextIdentifier (PObject *obj) const |
virtual | ~PObject () |
__inline const char * | GetClass () const |
__inline bool | IsClass (const char *name) const |
__inline const PObject * | PTraceObjectInstance () const |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. More... | |
template<class CLS > | |
CLS * | CloneAs () const |
As for Clone() but converts to specified type. More... | |
virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
virtual Comparison | Compare (const PObject &obj) const |
Compare the two objects and return their relative rank. More... | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. More... | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
Static Public Member Functions | |
static const PString & | DefaultSectionName () |
![]() | |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
static __inline const char * | Class () |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
template<typename T > | |
static Comparison | Compare2 (T v1, T v2) |
Compare two types, returning Comparison type. More... | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
Protected Attributes | |
PString | defaultSection |
The current section for variable values. More... | |
Cached * | m_config |
![]() | |
unsigned | m_traceContextIdentifier |
Construction | |
enum | Source { Environment, System, Application, NumSources } |
Description of the standard source for configuration information. More... | |
PConfig (Source src=Application) | |
Create a new configuration object. More... | |
PConfig (Source src, const PString &appname) | |
Create a new configuration object. More... | |
PConfig (Source src, const PString &appname, const PString &manuf) | |
Create a new configuration object. More... | |
PConfig (const PString §ion, Source src=Application) | |
Create a new configuration object. More... | |
PConfig (const PString §ion, Source src, const PString &appname) | |
Create a new configuration object. More... | |
PConfig (const PString §ion, Source src, const PString &appname, const PString &manuf) | |
Create a new configuration object. More... | |
PConfig (const PFilePath &filename, const PString §ion) | |
Create a new configuration object. More... | |
Additional Inherited Members | |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
A class representing a configuration for the application.
There are four sources of configuration information. The system environment, a system wide configuration file, an application specific configuration file or an explicit configuration file.
Configuration information follows a three level hierarchy: file
, section
and variable
. Thus, a configuration file consists of a number of sections each with a number of variables selected by a key
. Each variable has an associated value.
Note that the evironment source for configuration information does not have sections. The section is ignored and the same set of keys are available.
The configuration file is a standard text file for the platform with its internals appearing in the form:
[Section String]
Key Name=Value String
enum PConfig::Source |
Description of the standard source for configuration information.
PConfig::PConfig | ( | Source | src = Application | ) |
Create a new configuration object.
Once a source is selected for the configuration it cannot be changed. Only at the next level of the hierarchy (sections) are selection able to be made dynamically with an active PConfig object.
src | Standard source for the configuration. |
Create a new configuration object.
src | Standard source for the configuration. |
appname | Name of application |
Create a new configuration object.
src | Standard source for the configuration. |
appname | Name of application |
manuf | Manufacturer |
PConfig::PConfig | ( | const PString & | section, |
Source | src = Application |
||
) |
Create a new configuration object.
section | Default section to search for variables. |
src | Standard source for the configuration. |
Create a new configuration object.
section | Default section to search for variables. |
src | Standard source for the configuration. |
appname | Name of application |
PConfig::PConfig | ( | const PString & | section, |
Source | src, | ||
const PString & | appname, | ||
const PString & | manuf | ||
) |
Create a new configuration object.
section | Default section to search for variables. |
src | Standard source for the configuration. |
appname | Name of application |
manuf | Manufacturer |
Create a new configuration object.
filename | Explicit name of the configuration file. |
section | Default section to search for variables. |
PConfig::~PConfig | ( | ) |
|
static |
|
virtual |
Delete the particular variable in the specified section.
If the section name is not specified then the default section is used.
Note that the variable and key are removed from the file. The key will no longer appear in the GetKeys() function. If you wish to delete the value without deleting the key, use SetString() to set it to the empty string.
key | Key of the variable to delete. |
Delete the particular variable in the specified section.
section | Section to use instead of the default. |
key | Key of the variable to delete. |
|
virtual |
Delete all variables in the specified section.
If the section name is not specified then the default section is deleted.
Note that the section header is also removed so the section will not appear in the GetSections() function.
|
virtual |
Delete all variables in the specified section.
section | Name of section to delete. |
|
virtual |
Get all of the keys in the section and their values.
If the section name is not specified then use the default section.
|
virtual |
Get all of the keys in the section and their values.
section | Section to use instead of the default. |
Get a boolean variable determined by the key in the section.
If the section name is not specified then the default section is used.
The boolean value can be specified in a number of ways. The true value is returned if the string value for the variable begins with either the 'T' character or the 'Y' character. Alternatively if the string can be converted to a numeric value, a non-zero value will also return true. Thus the values can be Key=True, Key=Yes or Key=1 for true and Key=False, Key=No, or Key=0 for false.
If the key is not present the value returned is the that provided by the dlft
parameter. Note that this is different from the key being present but having no value, in which case false is returned.
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
Get a boolean variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
Get the default section for variable operations.
All functions that deal with keys and get or set configuration values will use this section unless an explicit section name is specified.
Note when the Environment
source is being used the default section may be retrieved but it is ignored.
|
inline |
key | The key name for the variable. |
dflt | Default value for the variable. |
References GetInteger().
|
inline |
section | Section to use instead of the default. |
key | The key name for the variable. |
dflt | Default value for the variable. |
References GetInteger().
|
virtual |
Get a 64 bit integer variable determined by the key in the section.
If the section name is not specified then the default section is used.
If the key is not present the value returned is the that provided by the dlft
parameter. Note that this is different from the key being present but having no value, in which case zero is returned.
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
Get a 64 bit integer variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
key | The key name for the variable. |
dflt | Default value for the variable. |
Referenced by GetEnum().
|
virtual |
section | Section to use instead of the default. |
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
Get a list of all the keys in the section.
If the section name is not specified then use the default section.
|
virtual |
Get a list of all the keys in the section.
section | Section to use instead of the default. |
|
virtual |
Get a floating point variable determined by the key in the section.
If the section name is not specified then the default section is used.
If the key is not present the value returned is the that provided by the dlft
parameter. Note that this is different from the key being present but having no value, in which case zero is returned.
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
Get a floating point variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
Get all of the section names currently specified in the file.
A section is the part specified by the [ and ] characters.
Note when the Environment
source is being used this will return an empty list as there are no section present.
Get a string variable determined by the key in the section.
If the section name is not specified then the default section is used.
If the key is not present the value returned is the that provided by the dlft
parameter. Note that this is different from the key being present but having no value, in which case an empty string is returned.
key | The key name for the variable. |
Get a string variable determined by the key in the section.
key | The key name for the variable. |
dflt | Default value for the variable. |
|
virtual |
Get a string variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
dflt | Default value for the variable. |
Get a PTime
variable determined by the key in the section.
If the section name is not specified then the default section is used.
If the key is not present the value returned is the that provided by the dlft
parameter. Note that this is different from the key being present but having no value, in which case zero is returned.
key | The key name for the variable. |
Get a PTime
variable determined by the key in the section.
key | The key name for the variable. |
dflt | Default value for the variable. |
Get a PTime
variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
|
virtual |
Get a PTime
variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
dflt | Default value for the variable. |
Determine if the particular variable in the section is actually present.
This function allows a caller to distinguish between getting a saved value or using the default value. For example if you called GetString("MyKey", "DefVal") there is no way to distinguish between the default "DefVal" being used, or the user had explicitly saved the value "DefVal" into the PConfig.
key | Key of the variable. |
Determine if the particular variable in the section is actually present.
section | Section to use instead of the default. |
key | Key of the variable. |
Set a boolean variable determined by the key in the section.
If the section name is not specified then the default section is used.
If value is true then the string "True" is written to the variable otherwise the string "False" is set.
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set a boolean variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set the default section for variable operations.
All functions that deal with keys and get or set configuration values will use this section unless an explicit section name is specified.
Note when the Environment
source is being used the default section may be set but it is ignored.
section | New default section name. |
|
inline |
Set an enum variable determined by the key in the section.
If the section name is not specified then the default section is used.
The value is always formatted as a signed number with no leading or trailing blanks.
key | The key name for the variable. |
value | New value to set for the variable. |
References SetInteger().
|
inline |
Set an enum variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
value | New value to set for the variable. |
References SetInteger().
|
virtual |
Set a 64 bit integer variable determined by the key in the section.
If the section name is not specified then the default section is used.
The value is always formatted as a signed number with no leading or trailing blanks.
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set a 64 bit integer variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set an integer variable determined by the key in the section.
If the section name is not specified then the default section is used.
The value is always formatted as a signed number with no leading or trailing blanks.
key | The key name for the variable. |
value | New value to set for the variable. |
Referenced by SetEnum().
|
virtual |
Set an integer variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set a floating point variable determined by the key in the section.
If the section name is not specified then the default section is used.
The value is always formatted as a signed decimal or exponential form number with no leading or trailing blanks, ie it uses the g formatter from the printf() function.
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set a floating point variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
value | New value to set for the variable. |
Set a string variable determined by the key in the section.
If the section name is not specified then the default section is used.
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set a string variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
value | New value to set for the variable. |
Set a PTime
variable determined by the key in the section.
If the section name is not specified then the default section is used.
key | The key name for the variable. |
value | New value to set for the variable. |
|
virtual |
Set a PTime
variable determined by the key in the section.
section | Section to use instead of the default. |
key | The key name for the variable. |
value | New value to set for the variable. |
|
protected |
The current section for variable values.
|
protected |