eXperiment robotics framework

Xml

The XML utils are used for parsing XML configuration files and object persistence (save the actual state of a world). More...

Classes

class  Serializable
 Those who inherit from this class can be serialized to xml. More...
class  Parser
 A parser of a specific xml element. More...
class  XmlHandler
 Returns a XmlHandler in case of the plugin with the specified id is a XmlHandler. More...
float getFloat (const XE *element, string property, float def=0)
 get a float.
double getDouble (const TiXmlElement *element, string property, double def=0)
 get a double.
int getInt (const TiXmlElement *element, string property, int def=0)
 get a integer.
bool getBool (const TiXmlElement *element, string property, bool def=0)
 get a boolean.
string getString (const TiXmlElement *element, string property, string def="")
 get a string.
XNgetInclude (XE *Xe)
 resolve a xi:include element.
void resolveIncludes (XE *XEinput)
 do a single pass to resolve all includes in XEinput.
XmlHandlergetXmlHandler (string target_plugin_tmp)
 Returns x XmlHandler in case of the plugin with the specified id is a XmlHandler.
template<typename T>
TiXmlElementoperator<< (TiXmlElement *element, T t)
 output the class to a xml element.
template<typename T>
void operator>> (const TiXmlElement *element, T &t)
 input a xml element to a class.
#define SAVE_XE(CHILD_VALUE)
 save the variable->xml_element with the same name.
#define SAVE_XE2(CHILD_VALUE, NAME)
 saves a xml element text that is also a variable.
#define CHECK_XE_ARG
 if a xe_arg was given to the function, if so create a local xe_tmp that points to it, else creates a local xe_tmp that points to the xe of the Serializable class.
typedef TiXmlDocument XD
 short name to TiXmlDocument.
typedef TiXmlElement XE
 short name to TiXmlElement.
typedef TiXmlAttribute XA
 short name to TiXmlAttribute.
typedef TiXmlText XT
 short name to TiXmlText.
typedef TiXmlNode XN
 short name to TiXmlNode.
typedef std::auto_ptr< ParserParserPtr
 is a std::auto_ptr<Parser>.

Functions

template<typename T>
std::string stringify (const T &x)
 turn any simple type into a string.
template<class T>
std::string typenameof (const T &t)
 return a string with the Type of the variable.
template<typename T>
void print (T t)
 print anything

Detailed Description

The XML utils are used for parsing XML configuration files and object persistence (save the actual state of a world).

The class can parse basic types, like integers, floats, strings and booleans. ERF uses XML for the following tasks:

  1. configuration files, where it solves the problem of syntax; provides auto-completion and validation.
  2. communication between components and the framework.
  3. component introspection/reflexion to expose the component interface, i.e. inputs and outputs.
  4. application state persistence and serialization.
    Author:
    smogzer_at_gmail.com
    Todo:
    template<class Tcollection, class Type> XN * serialize (T & )
    Todo:
    should the serialize be non-intrusive ? to better serialize other types like int, float, etc.
    Todo:
    << style operators for major types.

Define Documentation

#define CHECK_XE_ARG

Value:

XE * xe_tmp; \
  xe_tmp = (xe_arg) ? const_cast<XE*>(xe_arg) : xe; \
  if(!xe_tmp) \
    return;
if a xe_arg was given to the function, if so create a local xe_tmp that points to it, else creates a local xe_tmp that points to the xe of the Serializable class.

Definition at line 179 of file erf_xml.hpp.

#define SAVE_XE ( CHILD_VALUE   ) 

Value:

{\
    XN * xtmp=0;\
    xtmp = xe_tmp->FirstChild(#CHILD_VALUE) ;\
    if (!xtmp) { \
     xtmp = new XE(#CHILD_VALUE); \
     xe_tmp->LinkEndChild(xtmp); \
    }\
    ostringstream outs;\
    outs << CHILD_VALUE;\
    XN * xtmp2 = xtmp->FirstChild();\
    if (xtmp2) {\
        xtmp2->SetValue(outs.str());\
    } else {\
        TiXmlText * text = new TiXmlText( outs.str() );\
        xtmp->LinkEndChild( text );\
    };\
}
save the variable->xml_element with the same name.

saves a xml element text that is also a variable. does not create the xml element if it does not exist.

Definition at line 134 of file erf_xml.hpp.

#define SAVE_XE2 ( CHILD_VALUE,
NAME   ) 

Value:

{\
    XN * xtmp=0;\
    xtmp = xe_tmp->FirstChild(NAME) ;\
    if (!xtmp) { \
        xtmp = new XE(NAME); \
        xe_tmp->LinkEndChild(xtmp); \
    }\
    ostringstream outs;\
    outs << CHILD_VALUE;\
    XN * xtmp2 = xtmp->FirstChild();\
    if (xtmp2) {\
        xtmp2->SetValue(outs.str());\
    } else {\
        TiXmlText * text = new TiXmlText( outs.str() );\
        xtmp->LinkEndChild( text );\
    };\
}
saves a xml element text that is also a variable.

does not create the xml element if it does not exist.

Definition at line 157 of file erf_xml.hpp.


Typedef Documentation

is a std::auto_ptr<Parser>.

Parser of a specific xml element.

Definition at line 204 of file erf_xml.hpp.

XA

short name to TiXmlAttribute.

Definition at line 41 of file erf_xml.hpp.

XD

short name to TiXmlDocument.

Definition at line 33 of file erf_xml.hpp.

XE

short name to TiXmlElement.

Definition at line 37 of file erf_xml.hpp.

XN

short name to TiXmlNode.

Definition at line 49 of file erf_xml.hpp.

XT

short name to TiXmlText.

Definition at line 45 of file erf_xml.hpp.


Function Documentation

bool getBool ( const TiXmlElement element,
string  property,
bool  def = 0 
)

get a boolean.

Scans the childs and attributes of the specified element for a property, if not found return the default. The booleans are just 0 and 1, not true or false.

Returns:
default 1 or 0.
  • element a pointer to TiXmlElement.
  • property the property to search for e.g. id="".
  • def the default value.

double getDouble ( const TiXmlElement element,
string  property,
double  def = 0 
)

get a double.

Scans the childs and attributes of the specified element for a property, if not found return the default.

Returns:
default double if the property is not found.
  • element a pointer to TiXmlElement.
  • property the property to search for e.g. id="".
  • def the default value.

float getFloat ( const XE element,
string  property,
float  def = 0 
)

get a float.

Scans the childs and attributes of the specified element for a property, if not found return the default.

Returns:
default float if the property is not found.
  • element a pointer to TiXmlElement.
  • property the property to search for e.g. id="".
  • def the default value.

XN* getInclude ( XE Xe  ) 

resolve a xi:include element.

Returns:
a the contents of a file in <xi:include href="file.xml"> in the form of a TiXmlNode pointer.
  • Xe the element to expand.

int getInt ( const TiXmlElement element,
string  property,
int  def = 0 
)

get a integer.

Scans the childs and attributes of the specified element for a property, if not found return the default.

Returns:
default int if the property is not found.
  • element a pointer to TiXmlElement.
  • property the property to search for e.g. id="".
  • def the default value.

string getString ( const TiXmlElement element,
string  property,
string  def = "" 
)

get a string.

Scans the childs and attributes of the specified element for a property, if not found return the default.

Returns:
default string if the property is not found.
  • element a pointer to TiXmlElement.
  • property the property to search for e.g. id="".
  • def the default string.

XmlHandler* getXmlHandler ( string  target_plugin_tmp  ) 

Returns x XmlHandler in case of the plugin with the specified id is a XmlHandler.

template<typename T>
TiXmlElement* operator<< ( TiXmlElement element,
t 
) [inline]

output the class to a xml element.

Definition at line 236 of file erf_xml.hpp.

References TiXmlNode::LinkEndChild(), tpn::ToXml(), typenameof(), and TiXmlNode::ValueStr().

template<typename T>
void operator>> ( const TiXmlElement element,
T &  t 
) [inline]

input a xml element to a class.

Definition at line 259 of file erf_xml.hpp.

References TiXmlNode::FirstChildElement(), tpn::FromXml(), MSG_WARN, P, typenameof(), and TiXmlNode::ValueStr().

template<typename T>
void print ( t  )  [inline]

print anything

Definition at line 40 of file erf_string.hpp.

void resolveIncludes ( XE XEinput  ) 

do a single pass to resolve all includes in XEinput.

  • XEinput the element to expand.

template<typename T>
std::string stringify ( const T &  x  )  [inline]

turn any simple type into a string.

Definition at line 7 of file erf_string.hpp.

template<class T>
std::string typenameof ( const T &  t  )  [inline]

return a string with the Type of the variable.

Definition at line 29 of file erf_string.hpp.

References demangle_cpp_name().

Referenced by operator<<(), and operator>>().


The miarn project - written by Joao Xavier