45#define TIXML_USE_TICPP
83 const char*
what()
const throw();
92#define TICPPTHROW(message) \
94 std::ostringstream full_message; \
95 std::string file( __FILE__); \
96 file = file.substr(file.find_last_of("\\/") + 1); \
97 full_message << message << " <" << file << "@" << __LINE__ << ">"; \
98 full_message << BuildDetailedErrorString(); \
99 throw Exception(full_message.str()); \
106 class StylesheetReference;
170 std::stringstream convert;
173 if (convert.fail()) {
174 TICPPTHROW(
"Could not convert value to text");
177 return convert.str();
180 std::string
ToString(
const std::string& value)
const {
return value; }
190 std::istringstream val(temp);
194 TICPPTHROW(
"Could not convert \"" << temp <<
"\" to target type");
201 void FromString(
const std::string& temp, std::string* out)
const {
239 std::ostringstream full_message;
248 full_message <<
"\nDescription: " << doc->
ErrorDesc() <<
"\nFile: "
258 return full_message.str();
283 TICPPTHROW(
"Internal TiXml Pointer is nullptr");
317 Attribute(
const std::string& name,
const std::string& value);
347 std::string
Value()
const;
381 std::string
Name()
const;
444 virtual void Print(FILE* file,
int depth)
const;
480 std::string
Value()
const;
510 Node*
Parent(
bool throwIfNoParent =
true)
const;
539 Node*
FirstChild(
const char* value,
bool throwIfNoChildren =
true)
const;
553 bool throwIfNoChildren =
true)
const;
582 Node*
LastChild(
const char* value,
bool throwIfNoChildren =
true)
const;
595 Node*
LastChild(
const std::string& value,
bool throwIfNoChildren =
true)
const;
717 bool throwIfNoSiblings =
true)
const;
759 bool throwIfNoSiblings =
true)
const;
773 Node*
NextSibling(
const char* value,
bool throwIfNoSiblings =
true)
const;
788 *first =
dynamic_cast< T*
>(child);
797 TICPPTHROW(
"Attributes can only be iterated with Elements.")
810 *next =
dynamic_cast< T*
>(sibling);
812 while ((0 != sibling) && (0 == *next)) {
814 *next =
dynamic_cast< T*
>(sibling);
828 *previous =
dynamic_cast< T*
>(sibling);
830 while ((0 != sibling) && (0 == *previous)) {
832 *previous =
dynamic_cast< T*
>(sibling);
861 bool throwIfNoSiblings =
true)
const;
876 bool throwIfNoSiblings =
true)
const;
907 bool throwIfNoChildren =
true)
const;
921 bool throwIfNoChildren =
true)
const;
962 T* pointer =
dynamic_cast< T*
>(
this);
965 std::string thisType =
typeid(
this).name();
966 std::string targetType =
typeid(T).name();
967 std::string thatType =
typeid(*this).name();
968 TICPPTHROW(
"The " << thisType.substr(6) <<
" could not be casted to a "
969 << targetType.substr(6)
970 <<
" *, because the target object is not a "
971 << targetType.substr(6)
973 << thatType.substr(6)
1042 std::unique_ptr< Node >
Clone()
const;
1080 bool throwIfNull =
true,
1081 bool rememberSpawnedWrapper =
true)
const;
1111 template <
class T = Node >
1225 if (0 ==
m_p || 0 == p) {
1241 if (0 ==
m_p || 0 == p) {
1259 template <
class T >
1294 if (0 == tiXmlPointer) {
1298 TICPPTHROW(
"Can not create a " <<
typeid(T).name());
1367 Comment(
const std::string& comment);
1390 Text(
const std::string& value);
1401 template <
class T >
1427 Document(
const char* documentName);
1441 Document(
const std::string& documentName);
1469 void LoadFile(
const std::string& filename,
1475 void LoadFile(
const char* filename,
1484 void SaveFile(
const std::string& filename)
const;
1494 void Parse(
const std::string& xml,
1495 bool throwIfParseError =
true,
1514 Element(
const std::string& value);
1532 template <
class T >
1572 child = child->
Next(
false)) {
1573 *first =
dynamic_cast< Attribute*
>(child);
1590 template <
class T >
1610 std::string
GetText(
bool throwIfNotFound =
true)
const {
1615 if (throwIfNotFound) {
1616 TICPPTHROW(
"Text does not exists in the current element");
1641 return defaultValue;
1665 template <
class T,
class DefaultT >
1672 *value = defaultValue;
1699 template <
class T >
1700 void GetText(T* value,
bool throwIfNotFound =
true)
const {
1705 if (throwIfNotFound) {
1706 TICPPTHROW(
"Text does not exists in the current element");
1723 template <
class T >
1726 std::string temp =
ToString(value);
1755 template <
class T,
class DefaulT >
1758 const DefaulT& defaultValue)
const {
1764 *value = defaultValue;
1784 const std::string& defaultValue)
const;
1798 template <
class T >
1799 T
GetAttribute(
const std::string& name,
bool throwIfNotFound =
true)
const {
1805 if (throwIfNotFound) {
1806 const std::string error(std::string(
"Attribute '") + name +
1807 std::string(
"' does not exist"));
1832 template <
class T >
1835 bool throwIfNotFound =
true)
const {
1840 if (throwIfNotFound) {
1841 const std::string error(std::string(
"Attribute '") + name +
1842 std::string(
"' does not exist"));
1862 std::string
GetAttribute(
const std::string& name)
const;
1885 bool GetAttributeImp(
const std::string& name, std::string* value)
const;
1914 const std::string& encoding,
1915 const std::string& standalone);
1956 std::string
Type()
const;
1961 std::string
Href()
const;
TiCppRCImp * m_tiRC
Pointer to reference counter.
An attribute is a name-value pair.
TiXmlBase is a base class for every class in TinyXml.
int Row() const
Return the position, in the original source file, of this node or attribute.
int Column() const
See Row().
In correct XML the declaration is the first entry in the file.
Always the top level node.
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
int ErrorRow() const
Returns the location (if known) of the error.
bool Error() const
If an error occurs, Error will be set to true.
int ErrorCol() const
The column where the error occured. See ErrorRow().
The element is a container class.
The parent class for everything in the Document Object Model.
void SetValue(const char *_value)
Changes the value of the node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
A stylesheet reference looks like this:
Any tag that tinyXml doesn't recognize is saved as an unknown.
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks.
Wrapper around TiXmlAttribute.
void GetValue(T *value) const
Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::ValueStr from a std:...
std::string Name() const
Get the value of this attribute.
std::string Value() const
Get the value of this attribute.
void operator=(const Attribute ©)
virtual void Print(FILE *file, int depth) const
All TinyXml classes can print themselves to a filestream.
void IterateNext(const std::string &, Attribute **next) const
Attribute()
Construct an empty attribute.
void GetName(T *name) const
Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::Name from a std::str...
Attribute * Previous(bool throwIfNoAttribute=true) const
Get the previous sibling attribute in the DOM.
TiXmlBase * GetBasePointer() const
Attribute * Next(bool throwIfNoAttribute=true) const
Get the next sibling attribute in the DOM.
TiXmlAttribute * m_tiXmlPointer
void SetTiXmlPointer(TiXmlAttribute *newPointer)
void SetValue(const T &value)
Set the value of this node.
void SetName(const T &name)
Set the value of this attribute.
void IteratePrevious(const std::string &, Attribute **previous) const
Wrapper around TiXmlBase.
int Column() const
Return the position, in the original source file, of this node or attribute.
bool operator==(const Base &rhs) const
Compare internal TiXml pointers to determine is both are wrappers around the same node.
void SetImpRC(TiXmlBase *nodeBase)
int Row() const
Return the position, in the original source file, of this node or attribute.
bool operator!=(const Base &rhs) const
Compare internal TiXml pointers to determine is both are wrappers around the same node.
void FromString(const std::string &temp, T *out) const
Converts a std::string to any class with a proper overload of the >> opertor.
std::string ToString(const T &value) const
Converts any class with a proper overload of the << opertor to a std::string.
virtual ~Base()
Destructor.
std::string ToString(const std::string &value) const
TiCppRCImp * m_impRC
Holds status of internal TiXmlPointer - use this to determine if object has been deleted already.
void FromString(const std::string &temp, std::string *out) const
Specialization for std::string.
std::string BuildDetailedErrorString() const
Builds detailed error string using TiXmlDocument::Error() and others.
virtual TiXmlBase * GetBasePointer() const =0
void ValidatePointer() const
Wrapper around TiXmlDeclaration.
std::string Encoding() const
Encoding.
Declaration()
Default Constructor.
std::string Standalone() const
StandAlone.
std::string Version() const
Version.
Wrapper around TiXmlDocument.
void LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
void Parse(const std::string &xml, bool throwIfParseError=true, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given xml data.
void SaveFile() const
Save a file using the current document value.
Document()
Default Constructor.
Wrapper around TiXmlElement.
bool GetTextImp(std::string *value) const
void GetAttribute(const std::string &name, T *value, bool throwIfNotFound=true) const
Gets an attribute of name from an element.
void SetAttribute(const std::string &name, const T &value)
Sets an attribute of name to a given value.
void SetText(const T &value)
Convenience function to set the text of an element.
bool GetAttributeImp(const std::string &name, std::string *value) const
Attribute * LastAttribute(bool throwIfNoAttributes=true) const
Access the last attribute in this element.
void RemoveAttribute(const std::string &name)
Removes attribute from element.
void GetText(T *value, bool throwIfNotFound=true) const
Gets the text of an Element.
Attribute * FirstAttribute(bool throwIfNoAttributes=true) const
Access the first attribute in this element.
std::string GetTextOrDefault(const std::string &defaultValue) const
Gets the text of an Element, if it doesn't exist it will return the defaultValue.
std::string GetText(bool throwIfNotFound=true) const
Gets the text of an Element.
Element()
Default Constructor.
T GetAttribute(const std::string &name, bool throwIfNotFound=true) const
Returns an attribute of name from an element.
void IterateFirst(const std::string &, Attribute **first) const
bool HasAttribute(const std::string &name) const
Returns true, if attribute exists.
void GetTextOrDefault(T *value, const DefaultT &defaultValue) const
Gets the text value of an Element, if it doesn't exist it will return the defaultValue.
Element(const std::string &value, const T &text)
Constructor that allows you to set the element text.
void GetAttributeOrDefault(const std::string &name, T *value, const DefaulT &defaultValue) const
Gets an attribute of name from an element, if it doesn't exist it will return the defaultValue.
std::string m_details
Exception Details.
const char * what() const
Override std::exception::what() to return m_details.
Exception(const std::string &details)
Construct an exception with a message.
Iterator(T *node, const std::string &value="")
Constructor.
T * Get() const
Gets internal pointer.
T * end() const
For for loop comparisons.
bool operator!=(const Iterator &it) const
Compares internal pointer.
Iterator operator++(int)
Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.
Iterator & operator=(T *p)
Sets internal pointer.
bool operator==(T *p) const
Compares internal pointer*.
Iterator & operator--()
Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.
Iterator operator--(int)
Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.
Iterator & operator++()
Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.
T & operator*() const
So Iterator behaves like a STL iterator.
Iterator(const std::string &value="")
Constructor.
std::string m_value
Value for NextSibling calls.
bool operator!=(const T *p) const
Compares internal pointer.
T * operator->() const
So Iterator behaves like a STL iterator.
bool operator==(const Iterator &it) const
Compares internal pointer.
T * begin(const Node *parent) const
For for loop comparisons.
Iterator & operator=(const Iterator &it)
Sets internal pointer.
Iterator(const Iterator &it)
Constructor.
virtual void operator=(const NodeImp< T > ©)
TiXmlNode * GetTiXmlPointer() const
void SetTiXmlPointer(T *newPointer)
NodeImp(const NodeImp< T > ©)
T * m_tiXmlPointer
Internal pointer to the TiXml Class which is being wrapped.
Wrapper around TiXmlNode.
Comment * ToComment() const
Pointer conversion - replaces TiXmlNode::ToComment.
Node * ReplaceChild(Node *replaceThis, Node &withThis)
Replace a child of this node.
Declaration * ToDeclaration() const
Pointer conversion - replaces TiXmlNode::ToDeclaration.
std::unique_ptr< Node > Clone() const
Create an exact duplicate of this node and return it.
void SetValue(const T &value)
Set the value of this node.
StylesheetReference * ToStylesheetReference() const
Pointer conversion - replaces TiXmlNode::ToStylesheetReference.
Element * FirstChildElement(bool throwIfNoChildren=true) const
The first child element of this node.
Node * Parent(bool throwIfNoParent=true) const
The Parent of this Node.
bool Accept(TiXmlVisitor *visitor) const
Accept a hierchical visit the nodes in the TinyXML DOM.
void Clear()
Clear all Nodes below this.
bool NoChildren() const
Check if this node has no children.
void RemoveChild(Node *removeThis)
Delete a child of this node.
Document * ToDocument() const
Pointer conversion - replaces TiXmlNode::ToDocument.
std::string Value() const
Get the value of this node.
T * To() const
Pointer conversion ( NOT OBJECT CONVERSION ) - replaces TiXmlNode::ToElement, TiXmlNode::ToDocument,...
Node * NodeFactory(TiXmlNode *tiXmlNode, bool throwIfNull=true, bool rememberSpawnedWrapper=true) const
void IteratePrevious(const std::string &value, T **previous) const
Element * NextSiblingElement(bool throwIfNoSiblings=true) const
Navigate to a sibling element.
Node * InsertAfterChild(Node *afterThis, Node &addThis)
Adds a child after the specified child.
Node * InsertEndChild(Node &addThis)
Adds a child past the LastChild.
Node * LastChild(bool throwIfNoChildren=true) const
The last child of this node.
Node * InsertBeforeChild(Node *beforeThis, Node &addThis)
Adds a child before the specified child.
Node * NextSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
void IterateNext(const std::string &value, T **next) const
friend std::ostream & operator<<(std::ostream &out, const Node &base)
Stream output operator.
Document * GetDocument(bool throwIfNoDocument=true) const
Return a pointer to the Document this node lives in.
Node * IterateChildren(Node *previous) const
An alternate way to walk the children of a node.
int Type() const
Query the type (as TiXmlNode::NodeType ) of this node.
void GetValue(T *value) const
Get the value of this node Uses Base::FromString to convert TiXmlNode::ValueStr from a std::string,...
void IterateFirst(const std::string &value, T **first) const
virtual void IterateFirst(const std::string &, Attribute **) const
Node * PreviousSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
virtual TiXmlNode * GetTiXmlPointer() const =0
friend std::istream & operator>>(std::istream &in, Node &base)
Stream input operator.
Node * LinkEndChild(Node *childNode)
Adds a child past the LastChild.
Node * FirstChild(bool throwIfNoChildren=true) const
The first child of this node.
Element * ToElement() const
Pointer conversion - replaces TiXmlNode::ToElement.
Text * ToText() const
Pointer conversion - replaces TiXmlNode::ToText.
TiXmlBase * GetBasePointer() const
Wrapper around TiXmlStylesheetReference.
std::string Href() const
Href.
StylesheetReference()
Default Constructor.
std::string Type() const
Type.
Wrapper around TiXmlText.
Text(const T &value)
Streams value into a string and creates a Text with it.
Wrapper around TiXmlVisitor.
virtual bool Visit(const Text &)
Visit a text node.
virtual bool VisitEnter(const Element &, const Attribute *)
Visit an element.
virtual bool VisitEnter(const Document &)
Visit a document.
virtual bool Visit(const StylesheetReference &)
Visit a stylesheet reference.
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
virtual bool Visit(const Declaration &)
Visit a declaration.
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
virtual bool Visit(const Comment &)
Visit a comment node.
virtual bool VisitExit(const Document &)
Visit a document.
virtual bool VisitExit(const Element &)
Visit an element.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
ticpp is a TinyXML wrapper that uses a lot more C++ ideals.
#define TICPPTHROW(message)
This allows you to stream your exceptions in.
const TiXmlEncoding TIXML_DEFAULT_ENCODING