Xpace
Xpace::Configuration Class Reference

Each high-level Xpace object has a Configuration. More...

#include <config.h>

Public Types

typedef std::function< bool(uint depth, uint pos, const String &tag, const String &config)> nodeCallback
 Callback for traversing Configuration nodes depth the node's depth. More...
 
typedef std::function< bool(uint depth, const String &tag, intptr_t elt)> elt_callback
 

Public Member Functions

 Configuration (const String &str=String(), const String &tag=String())
 create a configuration from a fragment of XML More...
 
 Configuration (File *file, const String &tag=String())
 create a configuration from a configuration File More...
 
 Configuration (const Configuration &, const String &tag=String())
 
Configurationoperator= (const Configuration &)
 
 ~Configuration ()
 
bool operator! () const
 
String toString () const
 
 Configuration (const QDomElement &elt, const QDomDocument &doc=QDomDocument(), bool deep=false)
 Convert a QDomElement to a Configuration. More...
 
 operator const QDomElement & () const
 Convert a Configuration to a QDomElement. More...
 
const QDomDocument & getDomDocument () const
 Get the QDomDocument containing this Config. More...
 
String getTag () const
 
Configuration findTag (const String &tag, const String &name=String(), const String &value=String(), bool deep=true) const
 Copy a sub-configuration. More...
 
String getValue (const String &tag=String()) const
 get a node's value or an attribute search for attribute first, then child value More...
 
int64 getValueInt (const String &tag=String(), int64 def=0, bool *ok=0) const
 
bool getValueBool (const String &tag=String()) const
 
String getValuePath (const String &tag) const
 get named values, starting at root More...
 
bool hasChild (const String &tag) const
 
void addChild (const Configuration &child)
 
std::vector< StringgetChild (const String &tag) const
 
std::vector< int64getChildInt (const String &tag, int64 def, bool *ok) const
 
std::vector< boolgetChildBool (const String &tag) const
 
void setTag (const String &tag)
 set attribute values More...
 
void setValue (const String &name, const String &value)
 
void setValue (const String &name, int64 value)
 
void setValue (const String &name, bool value)
 
bool traverse (nodeCallback callback, bool deep=false, const String &tag=String(), uint maxDepth=~0) const
 Traverse (pre-order) a Configuration. More...
 
bool write (File *f) const
 serialize the Configuration More...
 

Protected Member Functions

bool elt_traverse (elt_callback, const String &tag)
 

Detailed Description

Each high-level Xpace object has a Configuration.

Definition at line 29 of file config.h.

Member Typedef Documentation

typedef std::function<bool(uint depth, uint pos, const String& tag, const String& config)> Xpace::Configuration::nodeCallback

Callback for traversing Configuration nodes depth the node's depth.

Parameters
posthe node's position (relative to parent)
tagthe node's XML tag
configthe node's (sub-)Configuration
Returns
true to continue, false to break

Definition at line 216 of file config.h.

typedef std::function<bool(uint depth, const String& tag, intptr_t elt)> Xpace::Configuration::elt_callback

Definition at line 243 of file config.h.

Constructor & Destructor Documentation

Xpace::Configuration::Configuration ( const String str = String(),
const String tag = String() 
)

create a configuration from a fragment of XML

Parameters
strthe XML fragment
tagsearch the Configuration for a sub-configuration with this tag (cf. findTag)
Exceptions
XML_No_Valueif tag is not found
XML_Error
Xpace::Configuration::Configuration ( File file,
const String tag = String() 
)

create a configuration from a configuration File

Parameters
filethe configuration File
tagsearch the Configuration for a sub-configuration with this tag (cf. findTag)
Exceptions
File_Cant_Read
XML_Error
XML_No_Valueif tag is not found
Xpace::Configuration::Configuration ( const Configuration ,
const String tag = String() 
)
Parameters
tagsearch the Configuration for a sub-configuration with this tag (cf. findTag)
Xpace::Configuration::~Configuration ( )
Xpace::Configuration::Configuration ( const QDomElement &  elt,
const QDomDocument &  doc = QDomDocument(),
bool  deep = false 
)

Convert a QDomElement to a Configuration.

Parameters
eltthe QDomElement to be converted
docthe QDomDocument the element's XML document (if none, create a document)
deepif true, convert children as well

Member Function Documentation

Configuration& Xpace::Configuration::operator= ( const Configuration )
bool Xpace::Configuration::operator! ( ) const
Returns
true if empty
Xpace::Configuration::operator const QDomElement & ( ) const

Convert a Configuration to a QDomElement.

Returns
the QDomElement
const QDomDocument& Xpace::Configuration::getDomDocument ( ) const

Get the QDomDocument containing this Config.

Returns
the QDomDocument
String Xpace::Configuration::getTag ( ) const
Configuration Xpace::Configuration::findTag ( const String tag,
const String name = String(),
const String value = String(),
bool  deep = true 
) const

Copy a sub-configuration.

Parameters
tagsearch the Configuration for a sub-configuration with this tag
namesearch for a sub-configuration with this attribute or child
valuesearch for a sub-configuration with an attribute/child called name with this value
deepiff true, return all descendants
Returns
a copy of the sub-configuration
String Xpace::Configuration::getValue ( const String tag = String()) const

get a node's value or an attribute search for attribute first, then child value

Parameters
tagthe tag of the child/attribute whose value we want; separate >1 tags with '|' if tag is empty, return this node's value
Returns
the (String) value

Referenced by Xpace::TranslatePtr< LOC, STR >::create(), and Xpace::TranslateString< LOC, STR >::create().

int64 Xpace::Configuration::getValueInt ( const String tag = String(),
int64  def = 0,
bool ok = 0 
) const
Parameters
tagthe tag of the child/attribute whose value we want; separate >1 tags with '|' if tag is empty, return this node's value
defthe default value if not found
okfillin true if found
Returns
the integer value

Referenced by Xpace::TranslateStringInt< LOC, STR >::operator()().

bool Xpace::Configuration::getValueBool ( const String tag = String()) const
Parameters
tagthe tag of the child/attribute whose value we want; separate >1 tags with '|' if tag is empty, return this node's value
Returns
the (boolean) value

Referenced by Xpace::TranslatePtr< LOC, STR >::create().

String Xpace::Configuration::getValuePath ( const String tag) const

get named values, starting at root

Parameters
namedepth-first search for this tag
Returns
the values associated with this tag, delimited by '.'
bool Xpace::Configuration::hasChild ( const String tag) const
Parameters
tagthe Child's tag
Returns
true iff the Child exists
void Xpace::Configuration::addChild ( const Configuration child)
Parameters
adda this as a child
std::vector<String> Xpace::Configuration::getChild ( const String tag) const
Parameters
tagthe child tag whose values we want
Returns
the (String) values
std::vector<int64> Xpace::Configuration::getChildInt ( const String tag,
int64  def,
bool ok 
) const
Parameters
tagthe child tag whose values we want
defthe default value if not found
okfillin true if found
Returns
the integer values
std::vector<bool> Xpace::Configuration::getChildBool ( const String tag) const
Parameters
tagthe child tags whose values we want
Returns
the (boolean) values
void Xpace::Configuration::setTag ( const String tag)

set attribute values

set this Configuation's XML tag

Parameters
tagthe new tag
void Xpace::Configuration::setValue ( const String name,
const String value 
)
Parameters
nameset this attribute
valueto this (String) value
void Xpace::Configuration::setValue ( const String name,
int64  value 
)
Parameters
nameset this attribute
valueto this (integer) value
void Xpace::Configuration::setValue ( const String name,
bool  value 
)
Parameters
tagset this attribute
valueto this (boolean) value
bool Xpace::Configuration::traverse ( nodeCallback  callback,
bool  deep = false,
const String tag = String(),
uint  maxDepth = ~0 
) const

Traverse (pre-order) a Configuration.

Parameters
callbackthe callback function
deepiff true, put each node's children in config sent to callback
tagif not empty, match this tag before calling back
maxDepthhow many levels to descend (relative to tag, if any)
Returns
true iff the callback always returned true
bool Xpace::Configuration::write ( File f) const

serialize the Configuration

Parameters
fto this file
Returns
true if successfully serialized
bool Xpace::Configuration::elt_traverse ( elt_callback  ,
const String tag 
)
protected

The documentation for this class was generated from the following file:

current as of Wed Jun 10 2026 12:00:06