antioch-0.4.0
List of all members | Public Member Functions | Private Attributes
tinyxml2::XMLHandle Class Reference

#include <tinyxml2.h>

Public Member Functions

 XMLHandle (XMLNode *_node)
 Create a handle from any node (at any depth of the tree.) This can be a null pointer. More...
 
 XMLHandle (XMLNode &_node)
 Create a handle from a node. More...
 
 XMLHandle (const XMLHandle &ref)
 Copy constructor. More...
 
XMLHandleoperator= (const XMLHandle &ref)
 Assignment. More...
 
XMLHandle FirstChild ()
 Get the first child of this handle. More...
 
XMLHandle FirstChildElement (const char *value=0)
 Get the first child element of this handle. More...
 
XMLHandle LastChild ()
 Get the last child of this handle. More...
 
XMLHandle LastChildElement (const char *_value=0)
 Get the last child element of this handle. More...
 
XMLHandle PreviousSibling ()
 Get the previous sibling of this handle. More...
 
XMLHandle PreviousSiblingElement (const char *_value=0)
 Get the previous sibling element of this handle. More...
 
XMLHandle NextSibling ()
 Get the next sibling of this handle. More...
 
XMLHandle NextSiblingElement (const char *_value=0)
 Get the next sibling element of this handle. More...
 
XMLNodeToNode ()
 Safe cast to XMLNode. This can return null. More...
 
XMLElementToElement ()
 Safe cast to XMLElement. This can return null. More...
 
XMLTextToText ()
 Safe cast to XMLText. This can return null. More...
 
XMLUnknownToUnknown ()
 Safe cast to XMLUnknown. This can return null. More...
 
XMLDeclarationToDeclaration ()
 Safe cast to XMLDeclaration. This can return null. More...
 

Private Attributes

XMLNodenode
 

Detailed Description

A XMLHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thing. Note that XMLHandle is not part of the TinyXML DOM structure. It is a separate utility class.

Take an example:

<Document>
        <Element attributeA = "valueA">
                <Child attributeB = "value1" />
                <Child attributeB = "value2" />
        </Element>
</Document>

Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very easy to write a lot of code that looks like:

XMLElement* root = document.FirstChildElement( "Document" );
if ( root )
{
        XMLElement* element = root->FirstChildElement( "Element" );
        if ( element )
        {
                XMLElement* child = element->FirstChildElement( "Child" );
                if ( child )
                {
                        XMLElement* child2 = child->NextSiblingElement( "Child" );
                        if ( child2 )
                        {
                                // Finally do something useful.

And that doesn't even cover "else" cases. XMLHandle addresses the verbosity of such code. A XMLHandle checks for null pointers so it is perfectly safe and correct to use:

XMLHandle docHandle( &document );
XMLElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild().NextSibling().ToElement();
if ( child2 )
{
        // do something useful

Which is MUCH more concise and useful.

It is also safe to copy handles - internally they are nothing more than node pointers.

XMLHandle handleCopy = handle;

See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects.

Definition at line 1286 of file tinyxml2.h.

Constructor & Destructor Documentation

tinyxml2::XMLHandle::XMLHandle ( XMLNode _node)
inline

Create a handle from any node (at any depth of the tree.) This can be a null pointer.

Definition at line 1290 of file tinyxml2.h.

References node.

Referenced by FirstChild(), FirstChildElement(), LastChild(), LastChildElement(), NextSibling(), NextSiblingElement(), PreviousSibling(), and PreviousSiblingElement().

1290 { node = _node; }
tinyxml2::XMLHandle::XMLHandle ( XMLNode _node)
inline

Create a handle from a node.

Definition at line 1292 of file tinyxml2.h.

References node.

1292 { node = &_node; }
tinyxml2::XMLHandle::XMLHandle ( const XMLHandle ref)
inline

Copy constructor.

Definition at line 1294 of file tinyxml2.h.

References node.

1294 { node = ref.node; }

Member Function Documentation

XMLHandle tinyxml2::XMLHandle::FirstChild ( )
inline

Get the first child of this handle.

Definition at line 1299 of file tinyxml2.h.

References tinyxml2::XMLNode::FirstChild(), node, and XMLHandle().

1299 { return XMLHandle( node ? node->FirstChild() : 0 ); }
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:496
XMLHandle tinyxml2::XMLHandle::FirstChildElement ( const char *  value = 0)
inline

Get the first child element of this handle.

Definition at line 1301 of file tinyxml2.h.

References tinyxml2::XMLNode::FirstChildElement(), node, and XMLHandle().

1301 { return XMLHandle( node ? node->FirstChildElement( value ) : 0 ); }
const XMLElement * FirstChildElement(const char *value=0) const
Definition: tinyxml2_imp.h:740
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
XMLHandle tinyxml2::XMLHandle::LastChild ( )
inline

Get the last child of this handle.

Definition at line 1303 of file tinyxml2.h.

References tinyxml2::XMLNode::LastChild(), node, and XMLHandle().

1303 { return XMLHandle( node ? node->LastChild() : 0 ); }
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:505
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
XMLHandle tinyxml2::XMLHandle::LastChildElement ( const char *  _value = 0)
inline

Get the last child element of this handle.

Definition at line 1305 of file tinyxml2.h.

References tinyxml2::XMLNode::LastChildElement(), node, and XMLHandle().

1305 { return XMLHandle( node ? node->LastChildElement( _value ) : 0 ); }
const XMLElement * LastChildElement(const char *value=0) const
Definition: tinyxml2_imp.h:755
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
XMLHandle tinyxml2::XMLHandle::NextSibling ( )
inline

Get the next sibling of this handle.

Definition at line 1311 of file tinyxml2.h.

References tinyxml2::XMLNode::NextSibling(), node, and XMLHandle().

1311 { return XMLHandle( node ? node->NextSibling() : 0 ); }
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:523
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
XMLHandle tinyxml2::XMLHandle::NextSiblingElement ( const char *  _value = 0)
inline

Get the next sibling element of this handle.

Definition at line 1313 of file tinyxml2.h.

References tinyxml2::XMLNode::NextSiblingElement(), node, and XMLHandle().

1313 { return XMLHandle( node ? node->NextSiblingElement( _value ) : 0 ); }
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an opitionally supplied name.
Definition: tinyxml2_imp.h:770
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
XMLHandle& tinyxml2::XMLHandle::operator= ( const XMLHandle ref)
inline

Assignment.

Definition at line 1296 of file tinyxml2.h.

References node.

1296 { node = ref.node; return *this; }
XMLHandle tinyxml2::XMLHandle::PreviousSibling ( )
inline

Get the previous sibling of this handle.

Definition at line 1307 of file tinyxml2.h.

References node, tinyxml2::XMLNode::PreviousSibling(), and XMLHandle().

1307 { return XMLHandle( node ? node->PreviousSibling() : 0 ); }
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:515
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
XMLHandle tinyxml2::XMLHandle::PreviousSiblingElement ( const char *  _value = 0)
inline

Get the previous sibling element of this handle.

Definition at line 1309 of file tinyxml2.h.

References node, tinyxml2::XMLNode::PreviousSiblingElement(), and XMLHandle().

1309 { return XMLHandle( node ? node->PreviousSiblingElement( _value ) : 0 ); }
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an opitionally supplied name...
Definition: tinyxml2_imp.h:784
XMLHandle(XMLNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1290
XMLDeclaration* tinyxml2::XMLHandle::ToDeclaration ( )
inline

Safe cast to XMLDeclaration. This can return null.

Definition at line 1324 of file tinyxml2.h.

References node, and tinyxml2::XMLNode::ToDeclaration().

1324 { return ( ( node && node->ToDeclaration() ) ? node->ToDeclaration() : 0 ); }
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:463
XMLElement* tinyxml2::XMLHandle::ToElement ( )
inline

Safe cast to XMLElement. This can return null.

Definition at line 1318 of file tinyxml2.h.

References node, and tinyxml2::XMLNode::ToElement().

1318 { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:459
XMLNode* tinyxml2::XMLHandle::ToNode ( )
inline

Safe cast to XMLNode. This can return null.

Definition at line 1316 of file tinyxml2.h.

References node.

1316 { return node; }
XMLText* tinyxml2::XMLHandle::ToText ( )
inline

Safe cast to XMLText. This can return null.

Definition at line 1320 of file tinyxml2.h.

References node, and tinyxml2::XMLNode::ToText().

1320 { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:460
XMLUnknown* tinyxml2::XMLHandle::ToUnknown ( )
inline

Safe cast to XMLUnknown. This can return null.

Definition at line 1322 of file tinyxml2.h.

References node, and tinyxml2::XMLNode::ToUnknown().

1322 { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:464

Member Data Documentation

XMLNode* tinyxml2::XMLHandle::node
private

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

Generated on Thu Jul 7 2016 11:09:52 for antioch-0.4.0 by  doxygen 1.8.8