RobWorkProject  23.9.11-
Classes | Public Types | Public Member Functions | List of all members
DOMElem Class Referenceabstract

an wrapper interface for easy access to XML DOM parser. This require an active back-end that does the actual parsing and validation. More...

#include <DOMElem.hpp>

Inherited by BoostDOMElem.

Classes

class  Iterator
 DOMElem iterator based on concrete ItImpl implementations. More...
 
class  ItImpl
 The DOMElem Iterator is initialized with a specific implementation of this interface. More...
 

Public Types

typedef rw::core::Ptr< DOMElemPtr
 smart pointer type
 
typedef rw::core::iter_pair< class IteratorIteratorPair
 DOMElem Iterator Pair type.
 

Public Member Functions

virtual ~DOMElem ()
 destructor
 
virtual bool isName (const std::string &elemname) const =0
 test if name of this elem equals elemname More...
 
virtual const std::string & getName () const =0
 get name of this DOMElem More...
 
virtual std::string getValue () const =0
 get string value of this DOMElem More...
 
virtual int getValueAsInt () const =0
 get value as an integer, throws an exception if this is not an int value. More...
 
virtual double getValueAsDouble () const =0
 get value as an double floating point, throws an exception if this is not an double value. More...
 
virtual std::vector< std::string > getValueAsStringList (char stringseperator=';') const =0
 get value as a list of strings, throws an exception if this is not a list of strings. The default string seperator is semicolon (;). More...
 
virtual std::vector< double > getValueAsDoubleList () const =0
 get value as a list of doubles, throws an exception if this is not a list of doubles. The default string seperator is space ( ). More...
 
virtual std::vector< double > getValueAsDoubleList (int N) const =0
 get value as a list of N doubles, throws an exception if this is not a list of N doubles. The default string seperator is space ( ). More...
 
virtual rw::core::Ptr< DOMElemgetChild (const std::string &name, bool optional=false)=0
 get a child with a specific name. If more children with the same name occur then it cannot be guaranteed which is returned. If optional is false then an exception will be thrown if the child cannot be found. If optional is true then NULL is returned if child is not found. More...
 
virtual rw::core::Ptr< DOMElemgetAttribute (const std::string &name, bool optional=false)=0
 get a attribute with a specific name. If more attributes with the same name occur then it cannot be guaranteed which is returned. If optional is false then an exception will be thrown if the child cannot be found. If optional is true then NULL is returned if child is not found. More...
 
virtual bool hasChild (const std::string &name) const =0
 test if this DOMElem has a child by name name. More...
 
virtual bool hasChildren () const =0
 test if this DOMElem has any children More...
 
virtual bool hasAttribute (const std::string &name) const =0
 test if this DOMElem has an attribute by name name. More...
 
std::string getAttributeValue (const std::string &name)
 Get the value of attribute as a string. More...
 
std::string getAttributeValue (const std::string &name, const std::string &default_value)
 Get the value of attribute as a string. More...
 
int getAttributeValueAsInt (const std::string &name)
 Get the value of attribute as an integer. More...
 
int getAttributeValueAsInt (const std::string &name, int default_value)
 Get the value of attribute as an integer. More...
 
double getAttributeValueAsDouble (const std::string &name)
 Get the value of attribute as an double. More...
 
double getAttributeValueAsDouble (const std::string &name, double default_value)
 Get the value of attribute as an double. More...
 
bool getValueAsBool ()
 Get the value as a boolean. More...
 
bool getAttributeValueAsBool (const std::string &name)
 Get the value of attribute as an boolean. More...
 
bool getAttributeValueAsBool (const std::string &name, bool default_value)
 Get the value of attribute as an boolean. More...
 
virtual Iterator begin ()=0
 Get iterator to first child element. More...
 
virtual Iterator end ()=0
 Get iterator to last child element. More...
 
virtual IteratorPair getChildren ()=0
 Get iterator to child elements. More...
 
virtual IteratorPair getAttributes ()=0
 Get iterator to attributes. More...
 
virtual rw::core::Ptr< DOMElemaddChild ()
 Add a child with an empty name. More...
 
virtual rw::core::Ptr< DOMElemaddChild (const std::string &name)=0
 Add a child element. More...
 
virtual rw::core::Ptr< DOMElemaddAttribute (const std::string &name)=0
 Add an attribute element. More...
 
virtual void setValue (const std::string &val)=0
 Set the value of this element. More...
 
virtual void setName (const std::string &val)=0
 Set the name of this element. More...
 
virtual void setValue (bool val)
 Set the value of this element. More...
 
virtual void setValue (int val)
 Set the value of this element. More...
 
virtual void setValue (double val)
 Set the value of this element. More...
 
virtual void setValue (const char *val)
 Set the value of this element. More...
 
virtual void setValueString (std::string val)
 Set the value of this element. More...
 

Detailed Description

an wrapper interface for easy access to XML DOM parser. This require an active back-end that does the actual parsing and validation.

The DOMElem consist of a <name>, <value> and a DOMElem list of <attributes> and <children>. The value is a string and can (for convenience) be extracted as different primitive values on the interface eg. double or std::vector<double>. Attributes are DOMElem that does not have any children. Children are DOMElem that might contain other children.

Member Function Documentation

◆ addAttribute()

virtual rw::core::Ptr<DOMElem> addAttribute ( const std::string &  name)
pure virtual

Add an attribute element.

Parameters
name[in] name of the attribute.
Returns
pointer to the new attribute.

Implemented in BoostDOMElem.

◆ addChild() [1/2]

virtual rw::core::Ptr<DOMElem> addChild ( )
inlinevirtual

Add a child with an empty name.

Returns
pointer to the new child element.

◆ addChild() [2/2]

virtual rw::core::Ptr<DOMElem> addChild ( const std::string &  name)
pure virtual

Add a child element.

Parameters
name[in] name of child.
Returns
pointer to the new child element.

Implemented in BoostDOMElem.

◆ begin()

virtual Iterator begin ( )
pure virtual

Get iterator to first child element.

Returns
iterator.

Implemented in BoostDOMElem.

◆ end()

virtual Iterator end ( )
pure virtual

Get iterator to last child element.

Returns
iterator.

Implemented in BoostDOMElem.

◆ getAttribute()

virtual rw::core::Ptr<DOMElem> getAttribute ( const std::string &  name,
bool  optional = false 
)
pure virtual

get a attribute with a specific name. If more attributes with the same name occur then it cannot be guaranteed which is returned. If optional is false then an exception will be thrown if the child cannot be found. If optional is true then NULL is returned if child is not found.

Parameters
name[in] name of the attribute to find
optional[in]
Returns
the DOMElem attribute if found, else either NULL (is optional) or an exception is thrown.

Implemented in BoostDOMElem.

◆ getAttributes()

virtual IteratorPair getAttributes ( )
pure virtual

Get iterator to attributes.

Returns
iterator pair for the first and last attributes.

Implemented in BoostDOMElem.

◆ getAttributeValue() [1/2]

std::string getAttributeValue ( const std::string &  name)
inline

Get the value of attribute as a string.

Parameters
name[in] the name of the attribute.
Returns
the value.

◆ getAttributeValue() [2/2]

std::string getAttributeValue ( const std::string &  name,
const std::string &  default_value 
)

Get the value of attribute as a string.

Parameters
name[in] the name of the attribute.
Returns
the value.
Parameters
default_value[in] a default value to return if attibute is not found.

◆ getAttributeValueAsBool() [1/2]

bool getAttributeValueAsBool ( const std::string &  name)
inline

Get the value of attribute as an boolean.

Parameters
name[in] the name of the attribute.
Returns
the value.

◆ getAttributeValueAsBool() [2/2]

bool getAttributeValueAsBool ( const std::string &  name,
bool  default_value 
)

Get the value of attribute as an boolean.

Parameters
name[in] the name of the attribute.
Returns
the value.
Parameters
default_value[in] a default value to return if attibute is not found.

◆ getAttributeValueAsDouble() [1/2]

double getAttributeValueAsDouble ( const std::string &  name)
inline

Get the value of attribute as an double.

Parameters
name[in] the name of the attribute.
Returns
the value.

◆ getAttributeValueAsDouble() [2/2]

double getAttributeValueAsDouble ( const std::string &  name,
double  default_value 
)

Get the value of attribute as an double.

Parameters
name[in] the name of the attribute.
Returns
the value.
Parameters
default_value[in] a default value to return if attibute is not found.

◆ getAttributeValueAsInt() [1/2]

int getAttributeValueAsInt ( const std::string &  name)
inline

Get the value of attribute as an integer.

Parameters
name[in] the name of the attribute.
Returns
the value.

◆ getAttributeValueAsInt() [2/2]

int getAttributeValueAsInt ( const std::string &  name,
int  default_value 
)

Get the value of attribute as an integer.

Parameters
name[in] the name of the attribute.
Returns
the value.
Parameters
default_value[in] a default value to return if attibute is not found.

◆ getChild()

virtual rw::core::Ptr<DOMElem> getChild ( const std::string &  name,
bool  optional = false 
)
pure virtual

get a child with a specific name. If more children with the same name occur then it cannot be guaranteed which is returned. If optional is false then an exception will be thrown if the child cannot be found. If optional is true then NULL is returned if child is not found.

Parameters
name[in] name of the child to find
optional[in]
Returns
the DOMElem child if found, else either NULL (is optional) or an exception is thrown.

Implemented in BoostDOMElem.

◆ getChildren()

virtual IteratorPair getChildren ( )
pure virtual

Get iterator to child elements.

Returns
iterator pair for the first and last elements.

Implemented in BoostDOMElem.

◆ getName()

virtual const std::string& getName ( ) const
pure virtual

get name of this DOMElem

Returns
name of DOMElem

Implemented in BoostDOMElem.

◆ getValue()

virtual std::string getValue ( ) const
pure virtual

get string value of this DOMElem

Returns
string value of this elem

Implemented in BoostDOMElem.

◆ getValueAsBool()

bool getValueAsBool ( )

Get the value as a boolean.

Returns
boolean value.

◆ getValueAsDouble()

virtual double getValueAsDouble ( ) const
pure virtual

get value as an double floating point, throws an exception if this is not an double value.

Returns
the double value

Implemented in BoostDOMElem.

◆ getValueAsDoubleList() [1/2]

virtual std::vector<double> getValueAsDoubleList ( ) const
pure virtual

get value as a list of doubles, throws an exception if this is not a list of doubles. The default string seperator is space ( ).

Returns
list of doubles

Implemented in BoostDOMElem.

◆ getValueAsDoubleList() [2/2]

virtual std::vector<double> getValueAsDoubleList ( int  N) const
pure virtual

get value as a list of N doubles, throws an exception if this is not a list of N doubles. The default string seperator is space ( ).

Returns
list of N doubles

Implemented in BoostDOMElem.

◆ getValueAsInt()

virtual int getValueAsInt ( ) const
pure virtual

get value as an integer, throws an exception if this is not an int value.

Returns
the int value

Implemented in BoostDOMElem.

◆ getValueAsStringList()

virtual std::vector<std::string> getValueAsStringList ( char  stringseperator = ';') const
pure virtual

get value as a list of strings, throws an exception if this is not a list of strings. The default string seperator is semicolon (;).

Returns
list of strings

Implemented in BoostDOMElem.

◆ hasAttribute()

virtual bool hasAttribute ( const std::string &  name) const
pure virtual

test if this DOMElem has an attribute by name name.

Parameters
name[in] name of the attribute DOMElem
Returns
true if this DOMElem has an attribute with name name

Implemented in BoostDOMElem.

◆ hasChild()

virtual bool hasChild ( const std::string &  name) const
pure virtual

test if this DOMElem has a child by name name.

Parameters
name[in] name of the child DOMElem
Returns
true if this DOMElem has a child with name name

Implemented in BoostDOMElem.

◆ hasChildren()

virtual bool hasChildren ( ) const
pure virtual

test if this DOMElem has any children

Returns
true if this DOMElem has any children

Implemented in BoostDOMElem.

◆ isName()

virtual bool isName ( const std::string &  elemname) const
pure virtual

test if name of this elem equals elemname

Parameters
elemname[in] string name to test with
Returns
true if elemname equals name of this DOMElem, false otherwise

Implemented in BoostDOMElem.

◆ setName()

virtual void setName ( const std::string &  val)
pure virtual

Set the name of this element.

Parameters
val[in] new name.

Implemented in BoostDOMElem.

◆ setValue() [1/5]

virtual void setValue ( bool  val)
virtual

Set the value of this element.

Parameters
val[in] new value.

◆ setValue() [2/5]

virtual void setValue ( const char *  val)
virtual

Set the value of this element.

Parameters
val[in] new value.

◆ setValue() [3/5]

virtual void setValue ( const std::string &  val)
pure virtual

Set the value of this element.

Parameters
val[in] new value.

Implemented in BoostDOMElem.

◆ setValue() [4/5]

virtual void setValue ( double  val)
virtual

Set the value of this element.

Parameters
val[in] new value.

◆ setValue() [5/5]

virtual void setValue ( int  val)
virtual

Set the value of this element.

Parameters
val[in] new value.

◆ setValueString()

virtual void setValueString ( std::string  val)
virtual

Set the value of this element.

Parameters
val[in] new value.

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