Nebula
|
#include <xmlreader.h>
Reads XML formatted data with random access from a stream using TinyXML as backend.
The XML document is represented as a tree of nodes, which can be navigated and queried.
Inherits IO::StreamReader.
Classes | |
class | TinyXmlInitHelper |
static helper object for TinyXml-Initialization at application startup More... | |
Public Member Functions | |
XmlReader () | |
constructor | |
virtual | ~XmlReader () |
destructor | |
virtual bool | Open () |
begin reading from the stream | |
virtual void | Close () |
end reading from the stream | |
bool | HasNode (const Util::String &path) const |
return true if node exists | |
Util::String | GetCurrentNodeName () const |
get short name of current node | |
Util::String | GetCurrentNodePath () const |
get path to current node | |
int | GetCurrentNodeLineNumber () const |
returns the line number of the current node | |
void | SetToRoot () |
sets the current node to root | |
void | SetToNode (const Util::String &path) |
set current node as path | |
bool | SetToFirstChild (const Util::String &name="") |
set current node to first child node, return false if no child exists | |
bool | SetToNextChild (const Util::String &name="") |
set current node to next sibling node, return false if no more sibling exists | |
bool | SetToParent () |
set current node to parent, return false if no parent exists | |
bool | HasAttr (const char *attr) const |
return true if matching attribute exists on current node | |
Util::Array< Util::String > | GetAttrs () const |
return names of all attrs on current node | |
bool | HasContent () const |
return true if current node has embedded content | |
Util::String | GetContent () const |
return embedded content of current node | |
bool | HasComment () const |
return true if current node has trailing comment | |
Util::String | GetComment () const |
return trailing comment | |
Util::String | GetString (const char *attr) const |
get string attribute value from current node | |
bool | GetBool (const char *attr) const |
get bool attribute value from current node | |
int | GetInt (const char *attr) const |
get int attribute value from current node | |
float | GetFloat (const char *attr) const |
get float attribute value from current node | |
Math::vec2 | GetVec2 (const char *attr) const |
get vec2 attribute value from current node | |
Math::vec4 | GetVec4 (const char *attr) const |
get vec4 attribute value from current node | |
Math::mat4 | GetMat4 (const char *attr) const |
get mat4 attribute value from current node | |
Math::transform44 | GetTransform44 (const char *attr) const |
get transform44 attribute value from current node | |
template<typename T > | |
T | Get (const char *attr) const |
generic getter for extension types | |
Util::String | GetOptString (const char *attr, const Util::String &defaultValue) const |
get optional string attribute value from current node | |
bool | GetOptBool (const char *attr, bool defaultValue) const |
get optional bool attribute value from current node | |
int | GetOptInt (const char *attr, int defaultValue) const |
get optional int attribute value from current node | |
float | GetOptFloat (const char *attr, float defaultValue) const |
get optional float attribute value from current node | |
Math::vec2 | GetOptVec2 (const char *attr, const Math::vec2 &defaultValue) const |
get vec2 attribute value from current node | |
Math::vec4 | GetOptVec4 (const char *attr, const Math::vec4 &defaultValue) const |
get optional vec4 attribute value from current node | |
Math::mat4 | GetOptMat4 (const char *attr, const Math::mat4 &defaultValue) const |
get optional mat4 attribute value from current node | |
Math::transform44 | GetOptTransform44 (const char *attr, const Math::transform44 &defaultValue) const |
get transform44 attribute value from current node | |
Public Member Functions inherited from IO::StreamReader | |
StreamReader () | |
constructor | |
virtual | ~StreamReader () |
destructor | |
void | SetStream (const Ptr< Stream > &s) |
set stream to read from | |
const Ptr< Stream > & | GetStream () const |
get currently set stream | |
bool | HasStream () const |
return true if a stream is set | |
bool | Eof () const |
return true if the stream has reached EOF | |
bool | IsOpen () const |
return true if currently open | |
Public Member Functions inherited from Core::RefCounted | |
RefCounted () | |
constructor | |
int | GetRefCount () const |
get the current refcount | |
void | AddRef () |
increment refcount by one | |
void | Release () |
decrement refcount and destroy object if refcount is zero | |
bool | IsInstanceOf (const Rtti &rtti) const |
return true if this object is instance of given class | |
bool | IsInstanceOf (const Util::String &className) const |
return true if this object is instance of given class by string | |
bool | IsInstanceOf (const Util::FourCC &classFourCC) const |
return true if this object is instance of given class by fourcc | |
bool | IsA (const Rtti &rtti) const |
return true if this object is instance of given class, or a derived class | |
bool | IsA (const Util::String &rttiName) const |
return true if this object is instance of given class, or a derived class, by string | |
bool | IsA (const Util::FourCC &rttiFourCC) const |
return true if this object is instance of given class, or a derived class, by fourcc | |
const Util::String & | GetClassName () const |
get the class name | |
Util::FourCC | GetClassFourCC () const |
get the class FourCC code | |
Private Member Functions | |
__DeclareClass (XmlReader) | |
TiXmlNode * | FindNode (const Util::String &path) const |
find a node by path, handles relativ paths as well | |
Private Attributes | |
TiXmlDocument * | xmlDocument |
TiXmlElement * | curNode |
Static Private Attributes | |
static TinyXmlInitHelper | initTinyXml |
Additional Inherited Members | |
Static Public Member Functions inherited from Core::RefCounted | |
static void | DumpRefCountingLeaks () |
dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!) | |
Protected Member Functions inherited from Core::RefCounted | |
virtual | ~RefCounted () |
destructor (called when refcount reaches zero) | |
Protected Attributes inherited from IO::StreamReader | |
Ptr< Stream > | stream |
bool | isOpen |
bool | streamWasOpen |
IO::XmlReader::XmlReader | ( | ) |
constructor
|
virtual |
destructor
|
private |
|
virtual |
end reading from the stream
Reimplemented from IO::StreamReader.
|
private |
find a node by path, handles relativ paths as well
This method finds an xml node by path name.
It can handle absolute paths and paths relative to the current node. All the usual file system path conventions are valid: "/" is the path separator, "." is the current directory, ".." the parent directory.
T IO::XmlReader::Get | ( | const char * | attr | ) | const |
generic getter for extension types
return names of all attrs on current node
Return array with names of all attrs on current node.
bool IO::XmlReader::GetBool | ( | const char * | name | ) | const |
get bool attribute value from current node
Return the provided attribute as a bool.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
Util::String IO::XmlReader::GetComment | ( | ) | const |
return trailing comment
String IO::XmlReader::GetContent | ( | ) | const |
return embedded content of current node
int IO::XmlReader::GetCurrentNodeLineNumber | ( | ) | const |
returns the line number of the current node
This method returns the line number of the current node.
String IO::XmlReader::GetCurrentNodeName | ( | ) | const |
get short name of current node
Get the short name (without path) of the current node.
String IO::XmlReader::GetCurrentNodePath | ( | ) | const |
get path to current node
This returns the full absolute path of the current node.
Path components are separated by slashes.
float IO::XmlReader::GetFloat | ( | const char * | name | ) | const |
get float attribute value from current node
Return the provided attribute as float.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
int IO::XmlReader::GetInt | ( | const char * | name | ) | const |
get int attribute value from current node
Return the provided attribute as int.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
mat4 IO::XmlReader::GetMat4 | ( | const char * | name | ) | const |
get mat4 attribute value from current node
Return the provided attribute as mat4.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
bool IO::XmlReader::GetOptBool | ( | const char * | name, |
bool | defaultValue ) const |
get optional bool attribute value from current node
Return the provided optional attribute as bool.
If the attribute doesn't exist, the default value will be returned.
float IO::XmlReader::GetOptFloat | ( | const char * | name, |
float | defaultValue ) const |
get optional float attribute value from current node
Return the provided optional attribute as float.
If the attribute doesn't exist, the default value will be returned.
int IO::XmlReader::GetOptInt | ( | const char * | name, |
int | defaultValue ) const |
get optional int attribute value from current node
Return the provided optional attribute as int.
If the attribute doesn't exist, the default value will be returned.
mat4 IO::XmlReader::GetOptMat4 | ( | const char * | name, |
const Math::mat4 & | defaultValue ) const |
get optional mat4 attribute value from current node
Return the provided optional attribute as mat4.
If the attribute doesn't exist, the default value will be returned.
String IO::XmlReader::GetOptString | ( | const char * | name, |
const Util::String & | defaultValue ) const |
get optional string attribute value from current node
Return the provided optional attribute as string.
If the attribute doesn't exist, the default value will be returned.
transform44 IO::XmlReader::GetOptTransform44 | ( | const char * | name, |
const Math::transform44 & | defaultValue ) const |
get transform44 attribute value from current node
Return the provided optional attribute as transform44.
If the attribute doesn't exist, the default value will be returned.
vec2 IO::XmlReader::GetOptVec2 | ( | const char * | name, |
const Math::vec2 & | defaultValue ) const |
get vec2 attribute value from current node
Return the provided optional attribute as vec2.
If the attribute doesn't exist, the default value will be returned.
vec4 IO::XmlReader::GetOptVec4 | ( | const char * | name, |
const Math::vec4 & | defaultValue ) const |
get optional vec4 attribute value from current node
Return the provided optional attribute as vec4.
If the attribute doesn't exist, the default value will be returned.
String IO::XmlReader::GetString | ( | const char * | name | ) | const |
get string attribute value from current node
Return the provided attribute as string.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
transform44 IO::XmlReader::GetTransform44 | ( | const char * | name | ) | const |
get transform44 attribute value from current node
Return the provided attribute as transform44.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
vec2 IO::XmlReader::GetVec2 | ( | const char * | name | ) | const |
get vec2 attribute value from current node
Return the provided attribute as vec2.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
vec4 IO::XmlReader::GetVec4 | ( | const char * | name | ) | const |
get vec4 attribute value from current node
Return the provided attribute as vec4.
If the attribute does not exist the method will fail hard (use HasAttr() to check for its existance).
bool IO::XmlReader::HasAttr | ( | const char * | attr | ) | const |
return true if matching attribute exists on current node
Return true if an attribute of the given name exists on the current node.
bool IO::XmlReader::HasComment | ( | ) | const |
return true if current node has trailing comment
bool IO::XmlReader::HasContent | ( | ) | const |
return true if current node has embedded content
bool IO::XmlReader::HasNode | ( | const Util::String & | path | ) | const |
return true if node exists
This method returns true if the node identified by path exists.
Path follows the normal filesystem path conventions, "/" is the separator, ".." is the parent node, "." is the current node. An absolute path starts with a "/", a relative path doesn't.
|
virtual |
begin reading from the stream
Opens the stream and reads the content of the stream into TinyXML.
Reimplemented from IO::StreamReader.
bool IO::XmlReader::SetToFirstChild | ( | const Util::String & | name = "" | ) |
set current node to first child node, return false if no child exists
Sets the current node to the first child node.
If no child node exists, the current node will remain unchanged and the method will return false. If name is a valid string, only child element matching the name will be returned. If name is empty, all child nodes will be considered.
bool IO::XmlReader::SetToNextChild | ( | const Util::String & | name = "" | ) |
set current node to next sibling node, return false if no more sibling exists
Sets the current node to the next sibling.
If no more children exist, the current node will be reset to the parent node and the method will return false. If name is a valid string, only child element matching the name will be returned. If name is empty, all child nodes will be considered.
void IO::XmlReader::SetToNode | ( | const Util::String & | path | ) |
set current node as path
Set the node pointed to by the path string as current node.
The path may be absolute or relative, following the usual filesystem path conventions. Separator is a slash.
bool IO::XmlReader::SetToParent | ( | ) |
set current node to parent, return false if no parent exists
Sets the current node to its parent.
If no parent exists, the current node will remain unchanged and the method will return false.
void IO::XmlReader::SetToRoot | ( | ) |
sets the current node to root
Resets the xml reader to the root node.
|
private |
|
staticprivate |
|
private |