Nebula
Loading...
Searching...
No Matches
xmlreader.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "io/streamreader.h"
15#include "tinyxml/tinyxml.h"
16
17//------------------------------------------------------------------------------
18namespace IO
19{
20class XmlReader : public StreamReader
21{
23public:
25 XmlReader();
27 virtual ~XmlReader();
28
30 virtual bool Open();
32 virtual void Close();
33
35 bool HasNode(const Util::String& path) const;
41 int GetCurrentNodeLineNumber() const;
42
44 void SetToRoot();
46 void SetToNode(const Util::String& path);
48 bool SetToFirstChild(const Util::String& name = "");
50 bool SetToNextChild(const Util::String& name = "");
52 bool SetToParent();
53
55 bool HasAttr(const char* attr) const;
58
60 bool HasContent() const;
63
65 bool HasComment() const;
68
70 Util::String GetString(const char* attr) const;
72 bool GetBool(const char* attr) const;
74 int GetInt(const char* attr) const;
76 float GetFloat(const char* attr) const;
77 #if !__OSX__
79 Math::vec2 GetVec2(const char* attr) const;
81 Math::vec4 GetVec4(const char* attr) const;
83 Math::mat4 GetMat4(const char* attr) const;
85 Math::transform44 GetTransform44(const char* attr) const;
86 #endif
88 template<typename T> T Get(const char* attr) const;
89
91 Util::String GetOptString(const char* attr, const Util::String& defaultValue) const;
93 bool GetOptBool(const char* attr, bool defaultValue) const;
95 int GetOptInt(const char* attr, int defaultValue) const;
97 float GetOptFloat(const char* attr, float defaultValue) const;
98 #if !__OSX__
100 Math::vec2 GetOptVec2(const char* attr, const Math::vec2& defaultValue) const;
102 Math::vec4 GetOptVec4(const char* attr, const Math::vec4& defaultValue) const;
104 Math::mat4 GetOptMat4(const char* attr, const Math::mat4& defaultValue) const;
106 Math::transform44 GetOptTransform44(const char* attr, const Math::transform44& defaultValue) const;
107 #endif
108
109private:
111 TiXmlNode* FindNode(const Util::String& path) const;
112
115 {
116 public:
122 };
123
127};
128
129} // namespace IO
130//------------------------------------------------------------------------------
Stream reader classes provide a specialized read-interface for a stream.
Definition streamreader.h:24
static helper object for TinyXml-Initialization at application startup
Definition xmlreader.h:115
TinyXmlInitHelper()
constructor
Definition xmlreader.h:118
Reads XML formatted data with random access from a stream using TinyXML as backend.
Definition xmlreader.h:21
Math::vec2 GetVec2(const char *attr) const
get vec2 attribute value from current node
Definition xmlreader.cc:461
T Get(const char *attr) const
generic getter for extension types
bool HasNode(const Util::String &path) const
return true if node exists
Definition xmlreader.cc:191
Util::Array< Util::String > GetAttrs() const
return names of all attrs on current node
Definition xmlreader.cc:383
float GetFloat(const char *attr) const
get float attribute value from current node
Definition xmlreader.cc:449
virtual ~XmlReader()
destructor
Definition xmlreader.cc:42
bool SetToFirstChild(const Util::String &name="")
set current node to first child node, return false if no child exists
Definition xmlreader.cc:285
XmlReader()
constructor
Definition xmlreader.cc:32
virtual bool Open()
begin reading from the stream
Definition xmlreader.cc:56
__DeclareClass(XmlReader)
float GetOptFloat(const char *attr, float defaultValue) const
get optional float attribute value from current node
Definition xmlreader.cc:568
TiXmlElement * curNode
Definition xmlreader.h:126
int GetInt(const char *attr) const
get int attribute value from current node
Definition xmlreader.cc:438
bool HasAttr(const char *attr) const
return true if matching attribute exists on current node
Definition xmlreader.cc:370
virtual void Close()
end reading from the stream
Definition xmlreader.cc:99
Util::String GetContent() const
return embedded content of current node
Definition xmlreader.cc:670
int GetCurrentNodeLineNumber() const
returns the line number of the current node
Definition xmlreader.cc:116
Util::String GetComment() const
return trailing comment
Definition xmlreader.cc:695
Math::mat4 GetOptMat4(const char *attr, const Math::mat4 &defaultValue) const
get optional mat4 attribute value from current node
Definition xmlreader.cc:623
Math::vec4 GetVec4(const char *attr) const
get vec4 attribute value from current node
Definition xmlreader.cc:472
Util::String GetCurrentNodePath() const
get path to current node
Definition xmlreader.cc:214
int GetOptInt(const char *attr, int defaultValue) const
get optional int attribute value from current node
Definition xmlreader.cc:550
TiXmlNode * FindNode(const Util::String &path) const
find a node by path, handles relativ paths as well
Definition xmlreader.cc:130
void SetToRoot()
sets the current node to root
Definition xmlreader.cc:247
TiXmlDocument * xmlDocument
Definition xmlreader.h:125
Util::String GetString(const char *attr) const
get string attribute value from current node
Definition xmlreader.cc:403
bool GetBool(const char *attr) const
get bool attribute value from current node
Definition xmlreader.cc:427
bool SetToParent()
set current node to parent, return false if no parent exists
Definition xmlreader.cc:349
bool HasContent() const
return true if current node has embedded content
Definition xmlreader.cc:658
Math::mat4 GetMat4(const char *attr) const
get mat4 attribute value from current node
Definition xmlreader.cc:491
Math::vec4 GetOptVec4(const char *attr, const Math::vec4 &defaultValue) const
get optional vec4 attribute value from current node
Definition xmlreader.cc:605
Math::transform44 GetTransform44(const char *attr) const
get transform44 attribute value from current node
Definition xmlreader.cc:502
Math::transform44 GetOptTransform44(const char *attr, const Math::transform44 &defaultValue) const
get transform44 attribute value from current node
Definition xmlreader.cc:641
void SetToNode(const Util::String &path)
set current node as path
Definition xmlreader.cc:262
bool HasComment() const
return true if current node has trailing comment
Definition xmlreader.cc:683
bool GetOptBool(const char *attr, bool defaultValue) const
get optional bool attribute value from current node
Definition xmlreader.cc:532
static TinyXmlInitHelper initTinyXml
Definition xmlreader.h:124
bool SetToNextChild(const Util::String &name="")
set current node to next sibling node, return false if no more sibling exists
Definition xmlreader.cc:317
Math::vec2 GetOptVec2(const char *attr, const Math::vec2 &defaultValue) const
get vec2 attribute value from current node
Definition xmlreader.cc:587
Util::String GetCurrentNodeName() const
get short name of current node
Definition xmlreader.cc:201
Util::String GetOptString(const char *attr, const Util::String &defaultValue) const
get optional string attribute value from current node
Definition xmlreader.cc:514
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
static void SetCondenseWhiteSpace(bool condense)
The world does not agree on whether white space should be kept or not.
Definition tinyxml.h:174
Always the top level node.
Definition tinyxml.h:1228
The element is a container class.
Definition tinyxml.h:841
The parent class for everything in the Document Object Model.
Definition tinyxml.h:388
Nebula's dynamic array class.
Definition array.h:60
Instances of wrapped stream classes.
Definition orientation.cc:10
A 4x4 single point precision float matrix.
Definition mat4.h:49
A 2-component float vector class.
Definition vec2.h:21
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50