PIP  0.4.0_beta2
Platform-Independent Primitives
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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".
 
 operator bool ()
 Convertion to boolean.
 
 operator char ()
 Convertion to char.
 
 operator short ()
 Convertion to short.
 
 operator int ()
 Convertion to int.
 
 operator long ()
 Convertion to long.
 
 operator uchar ()
 Convertion to uchar.
 
 operator ushort ()
 Convertion to ushort.
 
 operator uint ()
 Convertion to uint.
 
 operator ulong ()
 Convertion to ulong.
 
 operator float ()
 Convertion to float.
 
 operator double ()
 Convertion to double.
 
 operator PIString ()
 Convertion to PIString.
 
 operator PIStringList ()
 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:

  • name
  • value
  • type
  • comment

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

<name> = <value> #<type> <comment>

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"

Member Function Documentation

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"
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