PIP  1.4.0
Platform-Independent Primitives
PIConfig Class Reference

Configuration file. More...

Classes

class  Branch
 Branch is a list of entries of configuration file More...
 
class  Entry
 Entry of configuration file More...
 

Public Member Functions

 PIConfig (const PIString &path, PIIODevice::DeviceMode mode=PIIODevice::ReadWrite)
 Contructs and read configuration file at path "path" in mode "mode".
 
 PIConfig (PIString *string, PIIODevice::DeviceMode mode=PIIODevice::ReadWrite)
 Contructs and read configuration string "string" in mode "mode".
 
 PIConfig (PIIODevice *device=0, PIIODevice::DeviceMode mode=PIIODevice::ReadWrite)
 Contructs and read configuration from custom device "device" in mode "mode".
 
bool open (const PIString &path, PIIODevice::DeviceMode mode=PIIODevice::ReadWrite)
 Read configuration file at path "path" in mode "mode".
 
bool open (PIString *string, PIIODevice::DeviceMode mode=PIIODevice::ReadWrite)
 Read configuration string "string" in mode "mode".
 
EntrygetValue (const PIString &vname, const PIString &def=PIString(), bool *exists=0)
 Returns top-level entry with name "vname", if doesn`t exists return entry with value "def" and set *exist to false.
 
EntrygetValue (const PIString &vname, const char *def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const PIStringList &def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const bool def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const short def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const int def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const long def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const uchar def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const ushort def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const uint def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const ulong def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const float def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const double def, bool *exists=0)
 Returns top-level entry with name "vname" and default value "def".
 
Branch getValues (const PIString &vname)
 Returns top-level entries with names with substrings "vname".
 
void setValue (const PIString &name, const PIString &value, const PIString &type="s", bool write=true)
 Set top-level entry with name "name" value to "value", type to "type" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const PIStringList &value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "l" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const char *value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "s" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const bool value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "b" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const short value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const int value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const long value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const uchar value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const ushort value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const uint value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const ulong value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const float value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
void setValue (const PIString &name, const double value, bool write=true)
 Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is no suitable exists.
 
EntryrootEntry ()
 Returns root entry.
 
int entriesCount () const
 Returns top-level entries count.
 
bool isEntryExists (const PIString &name) const
 Returns if top-level entry with name "name" exists.
 
Branch allTree ()
 Returns all top-level entries.
 
Branch allLeaves ()
 Returns all entries without children.
 
void clear ()
 Remove all tree and device content.
 
void readAll ()
 Parse device and build internal tree.
 
void writeAll ()
 Write all internal tree to device.
 
const PIStringdelimiter () const
 Returns current tree delimiter, default ".".
 
void setDelimiter (const PIString &d)
 Set current tree delimiter.
 

Detailed Description

Configuration file.

This class provide handle access to configuration file.

Synopsis

PIConfig reads configuration file and create internal dendritic representation of all entries of this file. You can easily read some values and write new.

piconfig.png

PIConfig supports also INI-style files with sections "[section]". In this case line with section name interpret as prefix to the next lines. For example, these configs are equal:

ser.device = /dev/ttyS0
ser.speed = 115200
debug = true
[ser]
device = /dev/ttyS0
speed = 115200
[]
debug = true

Concepts

Each node of internal tree has type PIConfig::Entry. PIConfig has one root element rootEntry(). Any entry of configuration file is a child of this element.