ReactOS  0.4.12-dev-90-g2e2e63e
tinyxml2::XMLHandle Class Reference

#include <tinyxml2.h>

Collaboration diagram for tinyxml2::XMLHandle:

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 *name=0)
 Get the first child element of this handle. More...
 
XMLHandle LastChild ()
 Get the last child of this handle. More...
 
XMLHandle LastChildElement (const char *name=0)
 Get the last child element of this handle. More...
 
XMLHandle PreviousSibling ()
 Get the previous sibling of this handle. More...
 
XMLHandle PreviousSiblingElement (const char *name=0)
 Get the previous sibling element of this handle. More...
 
XMLHandle NextSibling ()
 Get the next sibling of this handle. More...
 
XMLHandle NextSiblingElement (const char *name=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

XMLNode_node
 

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-2 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.FirstChildElement( "Document" ).FirstChildElement( "Element" ).FirstChildElement().NextSiblingElement();
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 1788 of file tinyxml2.h.

Constructor & Destructor Documentation

◆ XMLHandle() [1/3]

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 1792 of file tinyxml2.h.

1792  {
1793  _node = node;
1794  }
struct node node

◆ XMLHandle() [2/3]

tinyxml2::XMLHandle::XMLHandle ( XMLNode node)
inline

Create a handle from a node.

Definition at line 1796 of file tinyxml2.h.

1796  {
1797  _node = &node;
1798  }
struct node node

◆ XMLHandle() [3/3]

tinyxml2::XMLHandle::XMLHandle ( const XMLHandle ref)
inline

Copy constructor.

Definition at line 1800 of file tinyxml2.h.

1800  {
1801  _node = ref._node;
1802  }
Definition: send.c:47

Member Function Documentation

◆ FirstChild()

XMLHandle tinyxml2::XMLHandle::FirstChild ( )
inline

Get the first child of this handle.

Definition at line 1810 of file tinyxml2.h.

Referenced by Database::fromXml(), and ToString().

1810  {
1811  return XMLHandle( _node ? _node->FirstChild() : 0 );
1812  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:705

◆ FirstChildElement()

XMLHandle tinyxml2::XMLHandle::FirstChildElement ( const char name = 0)
inline

Get the first child element of this handle.

Definition at line 1814 of file tinyxml2.h.

Referenced by Database::fromXml(), ReadGeneric(), and ReadStringNode().

1814  {
1815  return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
1816  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:876
Definition: name.c:36

◆ LastChild()

XMLHandle tinyxml2::XMLHandle::LastChild ( )
inline

Get the last child of this handle.

Definition at line 1818 of file tinyxml2.h.

1818  {
1819  return XMLHandle( _node ? _node->LastChild() : 0 );
1820  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:723

◆ LastChildElement()

XMLHandle tinyxml2::XMLHandle::LastChildElement ( const char name = 0)
inline

Get the last child element of this handle.

Definition at line 1822 of file tinyxml2.h.

1822  {
1823  return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
1824  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
Definition: name.c:36
const XMLElement * LastChildElement(const char *name=0) const
Definition: tinyxml2.cpp:890

◆ NextSibling()

XMLHandle tinyxml2::XMLHandle::NextSibling ( )
inline

Get the next sibling of this handle.

Definition at line 1834 of file tinyxml2.h.

Referenced by Database::fromXml().

1834  {
1835  return XMLHandle( _node ? _node->NextSibling() : 0 );
1836  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:757

◆ NextSiblingElement()

XMLHandle tinyxml2::XMLHandle::NextSiblingElement ( const char name = 0)
inline

Get the next sibling element of this handle.

Definition at line 1838 of file tinyxml2.h.

Referenced by ReadGeneric().

1838  {
1839  return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
1840  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
const XMLElement * NextSiblingElement(const char *name=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
Definition: tinyxml2.cpp:904
Definition: name.c:36

◆ operator=()

Assignment.

Definition at line 1804 of file tinyxml2.h.

1804  {
1805  _node = ref._node;
1806  return *this;
1807  }
Definition: send.c:47

◆ PreviousSibling()

XMLHandle tinyxml2::XMLHandle::PreviousSibling ( )
inline

Get the previous sibling of this handle.

Definition at line 1826 of file tinyxml2.h.

1826  {
1827  return XMLHandle( _node ? _node->PreviousSibling() : 0 );
1828  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:741

◆ PreviousSiblingElement()

XMLHandle tinyxml2::XMLHandle::PreviousSiblingElement ( const char name = 0)
inline

Get the previous sibling element of this handle.

Definition at line 1830 of file tinyxml2.h.

1830  {
1831  return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
1832  }
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1792
const XMLElement * PreviousSiblingElement(const char *name=0) const
Get the previous (left) sibling element of this node, with an optionally supplied name...
Definition: tinyxml2.cpp:917
Definition: name.c:36

◆ ToDeclaration()

XMLDeclaration* tinyxml2::XMLHandle::ToDeclaration ( )
inline

Safe cast to XMLDeclaration. This can return null.

Definition at line 1859 of file tinyxml2.h.

1859  {
1860  return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
1861  }
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:647

◆ ToElement()

XMLElement* tinyxml2::XMLHandle::ToElement ( )
inline

Safe cast to XMLElement. This can return null.

Definition at line 1847 of file tinyxml2.h.

Referenced by ReadStringNode().

1847  {
1848  return ( ( _node == 0 ) ? 0 : _node->ToElement() );
1849  }
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:631

◆ ToNode()

XMLNode* tinyxml2::XMLHandle::ToNode ( )
inline

Safe cast to XMLNode. This can return null.

Definition at line 1843 of file tinyxml2.h.

Referenced by Database::fromXml(), ReadGeneric(), and ToNodeName().

1843  {
1844  return _node;
1845  }

◆ ToText()

XMLText* tinyxml2::XMLHandle::ToText ( )
inline

Safe cast to XMLText. This can return null.

Definition at line 1851 of file tinyxml2.h.

Referenced by ToString().

1851  {
1852  return ( ( _node == 0 ) ? 0 : _node->ToText() );
1853  }
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:635

◆ ToUnknown()

XMLUnknown* tinyxml2::XMLHandle::ToUnknown ( )
inline

Safe cast to XMLUnknown. This can return null.

Definition at line 1855 of file tinyxml2.h.

1855  {
1856  return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
1857  }
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:651

Member Data Documentation

◆ _node

XMLNode* tinyxml2::XMLHandle::_node
private

Definition at line 1864 of file tinyxml2.h.

Referenced by operator=(), and XMLHandle().


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