PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | List of all members
PIConfig::Entry Class Reference

Entry of configuration file More...

Public Member Functions

Entryparent () const
 Returns parent entry, or 0 if there is no parent (root of default value)
 
int childCount () const
 Returns children count.
 
Branchchildren () const
 Returns children as PIConfig::Branch.
 
Entrychild (const int index) const
 Returns child at index "index".
 
EntryfindChild (const PIString &name)
 Returns first child with name "name".
 
const EntryfindChild (const PIString &name) const
 Returns first child with name "name".
 
bool isLeaf () const
 Returns true if there is no children.
 
const PIStringname () const
 Returns name.
 
const PIStringvalue () const
 Returns value.
 
const PIStringtype () const
 Returns type.
 
const PIStringcomment () const
 Returns comment.
 
const PIStringfullName () const
 Returns full name, i.e. name as it looks in file. More...
 
EntrysetName (const PIString &value)
 Set name to "value" and returns this.
 
EntrysetType (const PIString &value)
 Set type to "value" and returns this.
 
EntrysetComment (const PIString &value)
 Set comment to "value" and returns this.
 
EntrysetValue (const PIString &value)
 Set value to "value" and returns this.
 
EntrysetValue (const PIStringList &value)
 Set value to "value" and returns this. Type is set to "l".
 
EntrysetValue (const char *value)
 Set value to "value" and returns this. Type is set to "s".
 
EntrysetValue (const bool value)
 Set value to "value" and returns this. Type is set to "b".
 
EntrysetValue (const char value)
 Set value to "value" and returns this. Type is set to "s".
 
EntrysetValue (const short value)
 Set value to "value" and returns this. Type is set to "n".
 
EntrysetValue (const int value)
 Set value to "value" and returns this. Type is set to "n".
 
EntrysetValue (const long value)
 Set value to "value" and returns this. Type is set to "n".
 
EntrysetValue (const uchar value)
 Set value to "value" and returns this. Type is set to "n".
 
EntrysetValue (const ushort value)
 Set value to "value" and returns this. Type is set to "n".
 
EntrysetValue (const uint value)
 Set value to "value" and returns this. Type is set to "n".
 
EntrysetValue (const ulong value)
 Set value to "value" and returns this. Type is set to "n".
 
EntrysetValue (const float value)
 Set value to "value" and returns this. Type is set to "f".
 
EntrysetValue (const double value)
 Set value to "value" and returns this. Type is set to "f".
 
EntrygetValue (const PIString &vname, const PIString &def=PIString(), bool *exists=0)
 Returns entry with name "vname" and default value "def". More...
 
EntrygetValue (const PIString &vname, const char *def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const PIStringList &def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const bool def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const short def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const int def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const long def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const uchar def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const ushort def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const uint def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const ulong def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const float def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
EntrygetValue (const PIString &vname, const double def, bool *exists=0)
 Returns entry with name "vname" and default value "def".
 
Branch getValues (const PIString &vname)
 Find all entries with names with substrings "vname" and returns them as PIConfig::Branch.
 
bool isEntryExists (const PIString &name) const
 If there is no children returns if name == "name". Else returns if any child has name == "name".
 
bool toBool () const
 Convertion to boolean.
 
char toChar () const
 Convertion to char.
 
short toShort () const
 Convertion to short.
 
int toInt () const
 Convertion to int.
 
long toLong () const
 Convertion to long.
 
uchar toUChar () const
 Convertion to uchar.
 
ushort toUShort () const
 Convertion to ushort.
 
uint toUInt () const
 Convertion to uint.
 
ulong toULong () const
 Convertion to ulong.
 
float toFloat () const
 Convertion to float.
 
double toDouble () const
 Convertion to double.
 
PIString toString () const
 Convertion to PIString.
 
PIStringList toStringList () const
 Convertion to PIStringList.
 

Detailed Description

Entry of configuration file

This class is node of internal PIConfig tree. Entry provide access to elements of PIConfig. Each entry has children or next properties:

Each property is a PIString. These properties forms from text line with format:

<name> = <value> #<type> <comment>
const PIString & type() const
Returns type.
Definition: piconfig.h:191
const PIString & value() const
Returns value.
Definition: piconfig.h:188
const PIString & comment() const
Returns comment.
Definition: piconfig.h:194
const PIString & name() const
Returns name.
Definition: piconfig.h:185

Type and comment are optional fields. Type is a single letter immediately after comment symbol "#".

Entry has many implicit convertions to common types: boolean, integers, float, double, PIString, PIStringList.

Generally there is no need to create instance of PIConfig::Entry manually, it returns by functions getValue() of PIConfig, PIConfig::Entry or PIConfig::Branch. If there is no suitable entry to return, reference to internal instance of PIConfig::Entry with "default" value will be returned.

/* "example.conf"
a = 1
s0.a = A
s0.b = B
*/
PIConfig conf("example.conf", PIIODevice::ReadOnly);
PIConfig::Entry ce = conf.getValue("a");
int a = ce; // a = 1
PIString A = ce; // A = "1"
ce = conf.getValue("s0");
piCout << ce.childCount(); // 2
A = ce.getValue("b"); // A = "B"
A = conf.getValue("s0.a"); // A = "A"
Entry of configuration file
Definition: piconfig.h:141
int childCount() const
Returns children count.
Definition: piconfig.h:155
Entry & getValue(const PIString &vname, const PIString &def=PIString(), bool *exists=0)
Returns entry with name "vname" and default value "def".
Definition: piconfig.cpp:212
Configuration file.
Definition: piconfig.h:61
@ ReadOnly
Definition: piiodevice.h:101
String class.
Definition: pistring.h:42
#define piCout
Macro used for conditional (piDebug) output to PICout(StdOut)
Definition: picout.h:35

Member Function Documentation

◆ fullName()

const PIString & PIConfig::Entry::fullName ( ) const
inline

Returns full name, i.e. name as it looks in file.

In case of default entry full name always is empty

PIConfig conf("example.conf", PIIODevice::ReadOnly);
piCout << conf.getValue("a.b.c").name(); // "c"
piCout << conf.getValue("a.b.c").fullName(); // "a.b.c"

◆ getValue()

PIConfig::Entry & PIConfig::Entry::getValue ( const PIString vname,
const PIString def = PIString(),
bool *  exists = 0 
)

Returns entry with name "vname" and default value "def".

If there is no suitable entry found, reference to default internal entry with value = "def" will be returned, and if "exists" not null it will be set to false