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

#include <tinyxml2.h>

Public Member Functions

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 NextSibling ()
 Get the next sibling of this handle. More...
 
XMLHandle NextSiblingElement (const char *name=0)
 Get the next sibling element of this handle. More...
 
XMLHandleoperator= (const XMLHandle &ref)
 Assignment. 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...
 
XMLDeclarationToDeclaration ()
 Safe cast to XMLDeclaration. This can return null. More...
 
XMLElementToElement ()
 Safe cast to XMLElement. This can return null. More...
 
XMLNodeToNode ()
 Safe cast to XMLNode. 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...
 
 XMLHandle (const XMLHandle &ref)
 Copy constructor. More...
 
 XMLHandle (XMLNode &node)
 Create a handle from a node. More...
 
 XMLHandle (XMLNode *node)
 Create a handle from any node (at any depth of the tree.) This can be a null pointer. 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 2068 of file tinyxml2.h.

Constructor & Destructor Documentation

◆ XMLHandle() [1/3]

tinyxml2::XMLHandle::XMLHandle ( XMLNode node)
inlineexplicit

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

Definition at line 2072 of file tinyxml2.h.

◆ XMLHandle() [2/3]

tinyxml2::XMLHandle::XMLHandle ( XMLNode node)
inlineexplicit

Create a handle from a node.

Definition at line 2077 of file tinyxml2.h.

◆ XMLHandle() [3/3]

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

Copy constructor.

Definition at line 2082 of file tinyxml2.h.

Member Function Documentation

◆ FirstChild()

XMLHandle tinyxml2::XMLHandle::FirstChild ( )
inline

Get the first child of this handle.

Definition at line 2094 of file tinyxml2.h.

◆ FirstChildElement()

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

Get the first child element of this handle.

Definition at line 2096 of file tinyxml2.h.

◆ LastChild()

XMLHandle tinyxml2::XMLHandle::LastChild ( )
inline

Get the last child of this handle.

Definition at line 2101 of file tinyxml2.h.

◆ LastChildElement()

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

Get the last child element of this handle.

Definition at line 2103 of file tinyxml2.h.

◆ NextSibling()

XMLHandle tinyxml2::XMLHandle::NextSibling ( )
inline

Get the next sibling of this handle.

Definition at line 2115 of file tinyxml2.h.

◆ NextSiblingElement()

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

Get the next sibling element of this handle.

Definition at line 2117 of file tinyxml2.h.

◆ operator=()

XMLHandle& tinyxml2::XMLHandle::operator= ( const XMLHandle ref)
inline

Assignment.

Definition at line 2087 of file tinyxml2.h.

◆ PreviousSibling()

XMLHandle tinyxml2::XMLHandle::PreviousSibling ( )
inline

Get the previous sibling of this handle.

Definition at line 2108 of file tinyxml2.h.

◆ PreviousSiblingElement()

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

Get the previous sibling element of this handle.

Definition at line 2110 of file tinyxml2.h.

◆ ToDeclaration()

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

Safe cast to XMLDeclaration. This can return null.

Definition at line 2131 of file tinyxml2.h.

◆ ToElement()

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

Safe cast to XMLElement. This can return null.

Definition at line 2125 of file tinyxml2.h.

◆ ToNode()

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

Safe cast to XMLNode. This can return null.

Definition at line 2123 of file tinyxml2.h.

◆ ToText()

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

Safe cast to XMLText. This can return null.

Definition at line 2127 of file tinyxml2.h.

◆ ToUnknown()

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

Safe cast to XMLUnknown. This can return null.

Definition at line 2129 of file tinyxml2.h.

Member Data Documentation

◆ _node

XMLNode* tinyxml2::XMLHandle::_node
private

Definition at line 2134 of file tinyxml2.h.


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


sick_safevisionary_base
Author(s):
autogenerated on Sat Oct 21 2023 02:24:26