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

Node of the parsed configuration tree. More...

#include <piconfig.h>

Public Member Functions

 Entry ()
 Constructs an empty detached entry.
 
Entryparent () const
 Returns parent entry, or 0 for the root and default placeholder entries.
 
int childCount () const
 Returns direct children count.
 
Branchchildren () const
 Returns direct children as PIConfig::Branch.
 
Entrychild (const int index) const
 Returns direct child at position "index".
 
EntryfindChild (const PIString &name)
 Returns first direct child named "name".
 
const EntryfindChild (const PIString &name) const
 Returns first direct child named "name".
 
bool isLeaf () const
 Returns true when the entry has no children.
 
const PIStringname () const
 Returns local entry name without parent prefix.
 
const PIStringvalue () const
 Returns raw stored value.
 
const PIStringtype () const
 Returns one-letter stored type mark.
 
const PIStringcomment () const
 Returns inline comment stored after the type mark.
 
const PIStringfullName () const
 Returns full dotted name as it appears in the tree. More...
 
EntrysetName (const PIString &value)
 Sets local name to "value" and returns this entry.
 
EntrysetType (const PIString &value)
 Sets stored type mark to "value" and returns this entry.
 
EntrysetComment (const PIString &value)
 Sets inline comment to "value" and returns this entry.
 
EntrysetValue (const PIString &value)
 Sets raw stored value to "value" and returns this entry.
 
EntrysetValue (const PIStringList &value)
 Stores string list value and marks entry type as "l".
 
EntrysetValue (const char *value)
 Stores C-string value and marks entry type as "s".
 
EntrysetValue (const bool value)
 Stores boolean value and marks entry type as "b".
 
EntrysetValue (const char value)
 Stores character value and marks entry type as "s".
 
EntrysetValue (const short value)
 Stores numeric value and marks entry type as "n".
 
EntrysetValue (const int value)
 Stores numeric value and marks entry type as "n".
 
EntrysetValue (const long value)
 Stores numeric value and marks entry type as "n".
 
EntrysetValue (const uchar value)
 Stores numeric value and marks entry type as "n".
 
EntrysetValue (const ushort value)
 Stores numeric value and marks entry type as "n".
 
EntrysetValue (const uint value)
 Stores numeric value and marks entry type as "n".
 
EntrysetValue (const ulong value)
 Stores numeric value and marks entry type as "n".
 
EntrysetValue (const float value)
 Stores floating-point value and marks entry type as "f".
 
EntrysetValue (const double value)
 Stores floating-point value and marks entry type as "f".
 
EntrygetValue (const PIString &vname, const PIString &def=PIString(), bool *exists=0)
 Get entry with name "vname" and default value "def". More...
 
Branch getValues (const PIString &vname)
 Get entry with name "vname" and default value "def". More...
 
bool isEntryExists (const PIString &name) const
 Returns true if this entry or any descendant has name "name".
 
bool toBool () const
 Converts stored value to bool.
 
char toChar () const
 Converts stored value to char.
 
short toShort () const
 Converts stored value to short.
 
int toInt () const
 Converts stored value to int.
 
long toLong () const
 Converts stored value to long.
 
uchar toUChar () const
 Converts stored value to uchar.
 
ushort toUShort () const
 Converts stored value to ushort.
 
uint toUInt () const
 Converts stored value to uint.
 
ulong toULong () const
 Converts stored value to ulong.
 
float toFloat () const
 Converts stored value to float.
 
double toDouble () const
 Converts stored value to double.
 
PIString toString () const
 Returns stored value as PIString.
 
PIStringList toStringList () const
 Splits stored list value into PIStringList using internal list separator.
 

Detailed Description

Node of the parsed configuration tree.

Entry of configuration file

Stores entry name, value, type mark, inline comment and child entries derived from dotted names.

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 one-letter stored type mark.
Definition: piconfig.h:307
const PIString & value() const
Returns raw stored value.
Definition: piconfig.h:303
const PIString & comment() const
Returns inline comment stored after the type mark.
Definition: piconfig.h:311
const PIString & name() const
Returns local entry name without parent prefix.
Definition: piconfig.h:299

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"
Node of the parsed configuration tree.
Definition: piconfig.h:245
int childCount() const
Returns direct children count.
Definition: piconfig.h:263
Entry & getValue(const PIString &vname, const PIString &def=PIString(), bool *exists=0)
Get entry with name "vname" and default value "def".
Definition: piconfig.cpp:212
Parser and writer for configuration files with tree structure supportPIConfig provides functionality ...
Definition: piconfig.h:71
@ ReadOnly
Definition: piiodevice.h:104
String class.
Definition: pistring.h:42
#define piCout
Definition: picout.h:36

Member Function Documentation

◆ fullName()

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

Returns full dotted name as it appears in the tree.

Default placeholder entries always have empty full name.

◆ getValue()

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

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

If lookup fails, returns a shared default entry filled with "def" and sets exists to false when provided.

◆ getValues()

PIConfig::Branch PIConfig::Entry::getValues ( const PIString vname)

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

Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Get entry with name "vname" and default value "def" Returns direct children whose names contain substring "vname".