tXmlParserNamespace::tXmlParser::node Class Reference

DOM node class; provides convienient access to libxml without dealing with its functions. More...

#include <tXmlParser.h>

List of all members.

Public Member Functions

 node (xmlNode *cur)
 Constructor from a libxml node.
 node ()
 Dummy constructor, only of use for stl containers.
bool IsOfType (CHAR const *name) const
 Checks the type (name) of a node.
tString GetName (void) const
 Gets the type (name) of the node.
bool HasProp (CHAR const *prop) const
 Check if a property of the given name exists.
tString GetProp (CHAR const *prop) const
 Get a property of this node as a raw string.
bool GetPropBool (CHAR const *prop) const
 Get a boolean value out of a property.
template<typename T>
void GetProp (CHAR const *prop, T &target) const
 Get a property, convert to any type.
bool IsOfType (tString const &name) const
 Checks the type (name) of a node.
bool HasProp (tString const &prop) const
 Check if a property of the given name exists.
tString GetProp (tString const &prop) const
 Get a property of this node as a raw string.
bool GetPropBool (tString const &prop) const
 Get a boolean value out of a property.
template<typename T>
void GetProp (tString const &prop, T &target) const
 Get a property, convert to any type.
nodeoperator++ ()
 Move on to the next element on the same level.
node const operator++ (int)
 Move on to the next element on the same level.
 operator bool () const
 Does this node actually exist?
node GetFirstChild (void) const
 Get the first child node.

Private Types

typedef char CHAR
 change to wchar for future unicode support

Private Attributes

xmlNode * m_cur
 The current node, the whole class is a wrapper around it.


Detailed Description

DOM node class; provides convienient access to libxml without dealing with its functions.

Basic example of use (within a child of tXmlResource):

    node cur = GetFileContents(); // node now points to the first child of the Resource tag, which is most likely a text node
    for (; cur; ++cur) { // iterate throgh the following nodes to find the one we're looking for (ignoring all comments and text nodes)
        if(cur.IsOfType("whateveryouwant")) { // check if this is the right node
           // ok, it is the right node, now we want to parse all children and get their "height" property as floats, their "show" property as booleans, and their "name" property as a plain string
            for(node child = cur.GetFirstChild; child; ++child) {
                float height;
                cur.GetProp("height", height);
                bool show = cur.GetPropBool("show");
                tString name = cur.GetProp("name");
                // do something with that info...
            }
            break; // break out of the loop, we found what we were looking for
        }
    }
    

Definition at line 55 of file tXmlParser.h.


Member Typedef Documentation

typedef char tXmlParserNamespace::tXmlParser::node::CHAR [private]

change to wchar for future unicode support

Definition at line 56 of file tXmlParser.h.


Constructor & Destructor Documentation

tXmlParserNamespace::tXmlParser::node::node ( xmlNode *  cur  ) 

Constructor from a libxml node.

Parameters:
cur The node this object should be constructed around

Definition at line 513 of file tXmlParser.cpp.

00513                                  : m_cur(cur) {
00514     //tASSERT(m_cur);
00515 }

tXmlParserNamespace::tXmlParser::node::node (  )  [inline]

Dummy constructor, only of use for stl containers.

Definition at line 60 of file tXmlParser.h.


Member Function Documentation

bool tXmlParserNamespace::tXmlParser::node::IsOfType ( CHAR const *  name  )  const

Checks the type (name) of a node.

Parameters:
name The name to be checked
Returns:
true if the name matches, false if it doesn't. The conversion is case sensitive.

Definition at line 519 of file tXmlParser.cpp.

References m_cur, and tASSERT.

Referenced by HasProp(), and tXmlParserNamespace::tXmlResource::ValidateXml().

00519                                                     {
00520     tASSERT(m_cur);
00521     return(!xmlStrcmp(m_cur->name, reinterpret_cast<xmlChar const *>(name)));
00522 }

Here is the caller graph for this function:

tString tXmlParserNamespace::tXmlParser::node::GetName ( void   )  const

Gets the type (name) of the node.

Returns:
the name (type) of the node

Definition at line 525 of file tXmlParser.cpp.

References m_cur, and tASSERT.

Referenced by GetProp(), and tXmlParserNamespace::tXmlResource::ValidateXml().

00525                                           {
00526     tASSERT(m_cur);
00527     return tString(reinterpret_cast<const char *>(m_cur->name));
00528 }

Here is the caller graph for this function:

bool tXmlParserNamespace::tXmlParser::node::HasProp ( CHAR const *  prop  )  const

Check if a property of the given name exists.

Parameters:
prop The name of the property to be checked
Returns:
true if the property exists

Definition at line 532 of file tXmlParser.cpp.

References m_cur, and tASSERT.

Referenced by GetProp().

00532                                                    {
00533     tASSERT(m_cur);
00534     return xmlHasProp(m_cur,
00535                       reinterpret_cast<const xmlChar *>
00536                       (prop)
00537                      );
00538 }

Here is the caller graph for this function:

tString tXmlParserNamespace::tXmlParser::node::GetProp ( CHAR const *  prop  )  const

Get a property of this node as a raw string.

This function prints a warning if the attribute doesn't exist

Parameters:
prop The name of the attribute to be read
Returns:
The property as a string

Definition at line 543 of file tXmlParser.cpp.

References GetName(), m_cur, st_Breakpoint(), tASSERT, and tERR_WARN.

Referenced by GetPropBool(), and tXmlParserNamespace::tXmlResource::ValidateXml().

00543                                                       {
00544     tASSERT(m_cur);
00545     xmlChar *val = xmlGetProp(m_cur,
00546                               reinterpret_cast<const xmlChar *>
00547                               (prop)
00548                              );
00549     if(val == 0) {
00550         tERR_WARN(tString("Call for non- existent Attribute '") + tString(prop) + "' of element of type '" + GetName() + '"');
00551         st_Breakpoint();
00552         return tString();
00553     }
00554     tString ret(reinterpret_cast<const char *>(val));
00555     xmlFree(val);
00556     return(ret);
00557 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tXmlParserNamespace::tXmlParser::node::GetPropBool ( CHAR const *  prop  )  const

Get a boolean value out of a property.

This function prints a warning if the attribute doesn't exist

Parameters:
prop The name of the attribute to be read
Returns:
true if the attribute starts with one of [tTyY] (true, True, yes, Yes) or if it equeals "on" or if it converts completely to an integer that in not 0

Definition at line 562 of file tXmlParser.cpp.

References GetProp().

Referenced by GetProp().

00562                                                        {
00563     tString string(GetProp(prop));
00564     if (string.empty()) return false;
00565     switch(string[0]) {
00566 case 't': case 'T':
00567 case 'y': case 'Y':
00568         return true;
00569     default:
00570         if(string == "on") return true;
00571         int i;
00572         return string.Convert(i) && i;
00573     }
00574 }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T>
void tXmlParserNamespace::tXmlParser::node::GetProp ( CHAR const *  prop,
T &  target 
) const [inline]

Get a property, convert to any type.

This function will print an error message if the extraction failed

Parameters:
prop The name of the attribute to be read
target The place where the extacted value will be stored

Definition at line 157 of file tXmlParser.h.

00158                                                                                    {
00159     if(!(GetProp(prop).Convert(target))) {
00160         tERR_WARN( "Property '" + tString(prop) + "' of node of type '" + GetName() + "' is '" + GetProp(prop) + "' which isn't of type '" + typeid(T).name() + "' as needed.");
00161     }

bool tXmlParserNamespace::tXmlParser::node::IsOfType ( tString const &  name  )  const [inline]

Checks the type (name) of a node.

Definition at line 74 of file tXmlParser.h.

bool tXmlParserNamespace::tXmlParser::node::HasProp ( tString const &  prop  )  const [inline]

Check if a property of the given name exists.

Definition at line 75 of file tXmlParser.h.

References IsOfType().

Here is the call graph for this function:

tString tXmlParserNamespace::tXmlParser::node::GetProp ( tString const &  prop  )  const [inline]

Get a property of this node as a raw string.

Definition at line 76 of file tXmlParser.h.

References HasProp().

Here is the call graph for this function:

bool tXmlParserNamespace::tXmlParser::node::GetPropBool ( tString const &  prop  )  const [inline]

Get a boolean value out of a property.

Definition at line 77 of file tXmlParser.h.

References GetProp().

Here is the call graph for this function:

template<typename T>
void tXmlParserNamespace::tXmlParser::node::GetProp ( tString const &  prop,
T &  target 
) const [inline]

Get a property, convert to any type.

Definition at line 78 of file tXmlParser.h.

References GetPropBool().

Here is the call graph for this function:

tXmlParser::node & tXmlParserNamespace::tXmlParser::node::operator++ (  ) 

Move on to the next element on the same level.

Returns:
The node as it was before the incrementation

Definition at line 577 of file tXmlParser.cpp.

References m_cur, and tASSERT.

00577                                            {
00578     tASSERT(m_cur);
00579     m_cur=m_cur->next;
00580     return *this;
00581 }

tXmlParser::node const tXmlParserNamespace::tXmlParser::node::operator++ ( int   ) 

Move on to the next element on the same level.

Returns:
The node as it is after the incrementation

Definition at line 583 of file tXmlParser.cpp.

References m_cur, and tASSERT.

00583                                                    {
00584     tASSERT(m_cur);
00585     xmlNode *old = m_cur;
00586     m_cur=m_cur->next;
00587     return old;
00588 }

tXmlParserNamespace::tXmlParser::node::operator bool (  )  const

Does this node actually exist?

Returns:
true if the object exists, false if it doesn't (any operations on this node will segfault)

Definition at line 597 of file tXmlParser.cpp.

References m_cur.

00597                                     {
00598     return(m_cur != 0);
00599 }

tXmlParser::node tXmlParserNamespace::tXmlParser::node::GetFirstChild ( void   )  const

Get the first child node.

Returns:
A node pointing to the first child

Definition at line 591 of file tXmlParser.cpp.

References m_cur, and tASSERT.

00591                                                        {
00592     tASSERT(m_cur);
00593     return m_cur->xmlChildrenNode;
00594 }


Member Data Documentation

xmlNode* tXmlParserNamespace::tXmlParser::node::m_cur [private]

The current node, the whole class is a wrapper around it.

Definition at line 57 of file tXmlParser.h.

Referenced by GetFirstChild(), GetName(), GetProp(), HasProp(), IsOfType(), operator bool(), and operator++().


The documentation for this class was generated from the following files:
Generated on Sun Mar 16 00:05:26 2008 for Armagetron Advanced by  doxygen 1.5.4