aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
ticpp.h
Go to the documentation of this file.
1/*
2http://code.google.com/p/ticpp/
3Copyright (c) 2006 Ryan Pusztai, Ryan Mulder
4
5Permission is hereby granted, free of charge, to any person obtaining a copy of
6this software and associated documentation files (the "Software"), to deal in
7the Software without restriction, including without limitation the rights to
8use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all
13copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21*/
22
45#define TIXML_USE_TICPP
46#ifdef TIXML_USE_TICPP
47
48#ifndef TICPP_INCLUDED
49#define TICPP_INCLUDED
50
51#include "ticpprc.h"
52#include "tinyxml.h"
53
54#include <exception>
55#include <memory>
56#include <sstream>
57#include <typeinfo>
58#include <vector>
59
70namespace ticpp {
74 class Exception : public std::exception {
75 public:
79 Exception(const std::string& details);
80 ~Exception() throw();
81
83 const char* what() const throw();
84
85 std::string m_details;
86 };
87
92#define TICPPTHROW(message) \
93 { \
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()); \
100 }
101
102 // Forward Declarations for Visitor, and others.
103 class Document;
104 class Element;
105 class Declaration;
106 class StylesheetReference;
107 class Text;
108 class Comment;
109 class Attribute;
110
112 class Visitor : public TiXmlVisitor {
113 public:
114 // Overload the TiXmlVisitor functions, wrap objects, call ticpp::Visitor
115 // functions
117 virtual bool VisitEnter(const TiXmlDocument& doc);
119 virtual bool VisitExit(const TiXmlDocument& doc);
121 virtual bool VisitEnter(const TiXmlElement& element,
122 const TiXmlAttribute* firstAttribute);
124 virtual bool VisitExit(const TiXmlElement& element);
126 virtual bool Visit(const TiXmlDeclaration& declaration);
128 virtual bool Visit(const TiXmlStylesheetReference& stylesheet);
130 virtual bool Visit(const TiXmlText& text);
132 virtual bool Visit(const TiXmlComment& comment);
134 virtual bool Visit(const TiXmlUnknown& /*unknown*/);
135
136 public:
138 virtual bool VisitEnter(const Document& /*doc*/) { return true; }
140 virtual bool VisitExit(const Document& /*doc*/) { return true; }
141
143 virtual bool VisitEnter(const Element& /*element*/,
144 const Attribute* /*firstAttribute*/) {
145 return true;
146 }
147
148 virtual bool VisitExit(const Element& /*element*/) { return true; }
149
151 virtual bool Visit(const Declaration& /*declaration*/) { return true; }
153 virtual bool Visit(const StylesheetReference& /*stylesheet*/) { return true; }
155 virtual bool Visit(const Text& /*text*/) { return true; }
157 virtual bool Visit(const Comment& /*comment*/) { return true; }
158 };
159
161 class Base {
162 public:
168 template < class T >
169 std::string ToString(const T& value) const {
170 std::stringstream convert;
171 convert << value;
172
173 if (convert.fail()) {
174 TICPPTHROW("Could not convert value to text");
175 }
176
177 return convert.str();
178 }
179
180 std::string ToString(const std::string& value) const { return value; }
181
188 template < class T >
189 void FromString(const std::string& temp, T* out) const {
190 std::istringstream val(temp);
191 val >> *out;
192
193 if (val.fail()) {
194 TICPPTHROW("Could not convert \"" << temp << "\" to target type");
195 }
196 }
197
201 void FromString(const std::string& temp, std::string* out) const {
202 *out = temp;
203 }
204
209 int Row() const { return GetBasePointer()->Row(); }
210
215 int Column() const { return GetBasePointer()->Column(); }
216
222 bool operator==(const Base& rhs) const {
223 return (GetBasePointer() == rhs.GetBasePointer());
224 }
225
231 bool operator!=(const Base& rhs) const {
232 return (GetBasePointer() != rhs.GetBasePointer());
233 }
234
238 std::string BuildDetailedErrorString() const {
239 std::ostringstream full_message;
240#ifndef TICPP_NO_RTTI
241 TiXmlNode* node = dynamic_cast< TiXmlNode* >(GetBasePointer());
242
243 if (node != 0) {
244 TiXmlDocument* doc = node->GetDocument();
245
246 if (doc != 0) {
247 if (doc->Error()) {
248 full_message << "\nDescription: " << doc->ErrorDesc() << "\nFile: "
249 << (strlen(doc->Value()) > 0 ? doc->Value()
250 : "<unnamed-file>")
251 << "\nLine: " << doc->ErrorRow()
252 << "\nColumn: " << doc->ErrorCol();
253 }
254 }
255 }
256
257#endif
258 return full_message.str();
259 }
260
264 virtual ~Base() {}
265
266 protected:
270
279 void SetImpRC(TiXmlBase* nodeBase) { m_impRC = nodeBase->m_tiRC; }
280
281 void ValidatePointer() const {
282 if (m_impRC->IsNull()) {
283 TICPPTHROW("Internal TiXml Pointer is nullptr");
284 }
285 }
286
291 virtual TiXmlBase* GetBasePointer() const = 0;
292 };
293
297 class Attribute : public Base {
298 private:
302 return m_tiXmlPointer;
303 }
304
305 public:
309 Attribute();
310
317 Attribute(const std::string& name, const std::string& value);
318
325 Attribute(TiXmlAttribute* attribute);
326
335 template < class T >
336 void GetValue(T* value) const {
338 FromString(m_tiXmlPointer->ValueStr(), value);
339 }
340
347 std::string Value() const;
348
356 template < class T >
357 void SetValue(const T& value) {
359 m_tiXmlPointer->SetValue(ToString(value));
360 }
361
369 template < class T >
370 void GetName(T* name) const {
372 FromString(m_tiXmlPointer->Name(), name);
373 }
374
381 std::string Name() const;
382
390 template < class T >
391 void SetName(const T& name) {
393 m_tiXmlPointer->SetName(ToString(name));
394 }
395
400 void operator=(const Attribute& copy);
401
406 Attribute(const Attribute& copy);
407
408 /*
409 Decrements reference count.
410 */
411 ~Attribute();
412
416 Attribute* Next(bool throwIfNoAttribute = true) const;
417
421 Attribute* Previous(bool throwIfNoAttribute = true) const;
422
430 void IterateNext(const std::string&, Attribute** next) const;
431
439 void IteratePrevious(const std::string&, Attribute** previous) const;
440
444 virtual void Print(FILE* file, int depth) const;
445
446 private:
454 void SetTiXmlPointer(TiXmlAttribute* newPointer);
455 };
456
460 class Node : public Base {
461 public:
469 template < class T >
470 void GetValue(T* value) const {
471 FromString(GetTiXmlPointer()->ValueStr(), value);
472 }
473
480 std::string Value() const;
481
489 template < class T >
490 void SetValue(const T& value) {
492 }
493
498 void Clear();
499
510 Node* Parent(bool throwIfNoParent = true) const;
511
525 Node* FirstChild(bool throwIfNoChildren = true) const;
526
539 Node* FirstChild(const char* value, bool throwIfNoChildren = true) const;
540
552 Node* FirstChild(const std::string& value,
553 bool throwIfNoChildren = true) const;
554
568 Node* LastChild(bool throwIfNoChildren = true) const;
569
582 Node* LastChild(const char* value, bool throwIfNoChildren = true) const;
583
595 Node* LastChild(const std::string& value, bool throwIfNoChildren = true) const;
596
604 Node* IterateChildren(Node* previous) const;
605
615 Node* IterateChildren(const std::string& value, Node* previous) const;
616
629 Node* InsertEndChild(Node& addThis);
630
641 Node* LinkEndChild(Node* childNode);
642
654 Node* InsertBeforeChild(Node* beforeThis, Node& addThis);
655
667 Node* InsertAfterChild(Node* afterThis, Node& addThis);
668
679 Node* ReplaceChild(Node* replaceThis, Node& withThis);
680
689 void RemoveChild(Node* removeThis);
690
703 Node* PreviousSibling(bool throwIfNoSiblings = true) const;
704
716 Node* PreviousSibling(const std::string& value,
717 bool throwIfNoSiblings = true) const;
718
731 Node* PreviousSibling(const char* value, bool throwIfNoSiblings = true) const;
732
745 Node* NextSibling(bool throwIfNoSiblings = true) const;
746
758 Node* NextSibling(const std::string& value,
759 bool throwIfNoSiblings = true) const;
760
773 Node* NextSibling(const char* value, bool throwIfNoSiblings = true) const;
774
782 template < class T >
783 void IterateFirst(const std::string& value, T** first) const {
784 *first = 0;
785
786 for (Node* child = FirstChild(value, false); child;
787 child = child->NextSibling(value, false)) {
788 *first = dynamic_cast< T* >(child);
789
790 if (0 != *first) {
791 return;
792 }
793 }
794 }
795
796 virtual void IterateFirst(const std::string&, Attribute**) const {
797 TICPPTHROW("Attributes can only be iterated with Elements.")
798 }
799
807 template < class T >
808 void IterateNext(const std::string& value, T** next) const {
809 Node* sibling = NextSibling(value, false);
810 *next = dynamic_cast< T* >(sibling);
811
812 while ((0 != sibling) && (0 == *next)) {
813 sibling = sibling->NextSibling(value, false);
814 *next = dynamic_cast< T* >(sibling);
815 }
816 }
817
825 template < class T >
826 void IteratePrevious(const std::string& value, T** previous) const {
827 Node* sibling = PreviousSibling(value, false);
828 *previous = dynamic_cast< T* >(sibling);
829
830 while ((0 != sibling) && (0 == *previous)) {
831 sibling = sibling->PreviousSibling(value, false);
832 *previous = dynamic_cast< T* >(sibling);
833 }
834 }
835
848 Element* NextSiblingElement(bool throwIfNoSiblings = true) const;
849
860 Element* NextSiblingElement(const std::string& value,
861 bool throwIfNoSiblings = true) const;
862
875 Element* NextSiblingElement(const char* value,
876 bool throwIfNoSiblings = true) const;
877
892 Element* FirstChildElement(bool throwIfNoChildren = true) const;
893
906 Element* FirstChildElement(const char* value,
907 bool throwIfNoChildren = true) const;
908
920 Element* FirstChildElement(const std::string& value,
921 bool throwIfNoChildren = true) const;
922
926 int Type() const;
927
940 Document* GetDocument(bool throwIfNoDocument = true) const;
941
947 bool NoChildren() const;
948
949#ifndef TICPP_NO_RTTI
960 template < class T >
961 T* To() const {
962 T* pointer = dynamic_cast< T* >(this);
963
964 if (0 == pointer) {
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)
972 << ". (It is a "
973 << thatType.substr(6)
974 << ")");
975 }
976
977 return pointer;
978 }
979#endif
980
986 Document* ToDocument() const;
987
993 Element* ToElement() const;
994
1000 Comment* ToComment() const;
1001
1007 Text* ToText() const;
1008
1014 Declaration* ToDeclaration() const;
1015
1022
1042 std::unique_ptr< Node > Clone() const;
1043
1048 bool Accept(TiXmlVisitor* visitor) const;
1049
1053 friend std::istream& operator>>(std::istream& in, Node& base) {
1054 in >> *base.GetTiXmlPointer();
1055 return in;
1056 }
1057
1061 friend std::ostream& operator<<(std::ostream& out, const Node& base) {
1062 out << *base.GetTiXmlPointer();
1063 return out;
1064 }
1065
1066 protected:
1071 virtual TiXmlNode* GetTiXmlPointer() const = 0;
1072
1074
1079 Node* NodeFactory(TiXmlNode* tiXmlNode,
1080 bool throwIfNull = true,
1081 bool rememberSpawnedWrapper = true) const;
1082 };
1083
1111 template < class T = Node >
1112 class Iterator {
1113 private:
1114 T* m_p;
1115 std::string m_value;
1116
1117 public:
1127 T* begin(const Node* parent) const {
1128 T* pointer;
1129 parent->IterateFirst(m_value, &pointer);
1130 return pointer;
1131 }
1132
1141 T* end() const { return 0; }
1142
1152 Iterator(const std::string& value = "")
1153 : m_p(0)
1154 , m_value(value) {}
1155
1157 Iterator(T* node, const std::string& value = "")
1158 : m_p(node)
1159 , m_value(value) {}
1160
1163 : m_p(it.m_p)
1164 , m_value(it.m_value) {}
1165
1170 T* Get() const { return m_p; }
1171
1174 m_p = it.m_p;
1175 m_value = it.m_value;
1176 return *this;
1177 }
1178
1181 m_p = p;
1182 return *this;
1183 }
1184
1189 m_p->IterateNext(m_value, &m_p);
1190 return *this;
1191 }
1192
1197 Iterator tmp(*this);
1198 ++(*this);
1199 return tmp;
1200 }
1201
1206 m_p->IteratePrevious(m_value, &m_p);
1207 return *this;
1208 }
1209
1214 Iterator tmp(*this);
1215 --(*this);
1216 return tmp;
1217 }
1218
1220 bool operator!=(const T* p) const {
1221 if (m_p == p) {
1222 return false;
1223 }
1224
1225 if (0 == m_p || 0 == p) {
1226 return true;
1227 }
1228
1229 return *m_p != *p;
1230 }
1231
1233 bool operator!=(const Iterator& it) const { return operator!=(it.m_p); }
1234
1236 bool operator==(T* p) const {
1237 if (m_p == p) {
1238 return true;
1239 }
1240
1241 if (0 == m_p || 0 == p) {
1242 return false;
1243 }
1244
1245 return *m_p == *p;
1246 }
1247
1249 bool operator==(const Iterator& it) const { return operator==(it.m_p); }
1250
1252 T* operator->() const { return m_p; }
1253
1255 T& operator*() const { return *m_p; }
1256 };
1257
1259 template < class T >
1260 class NodeImp : public Node {
1261 protected:
1264
1273 return m_tiXmlPointer;
1274 }
1275
1283 void SetTiXmlPointer(T* newPointer) {
1284 m_tiXmlPointer = newPointer;
1285 SetImpRC(newPointer);
1286 }
1287
1292 NodeImp(T* tiXmlPointer) {
1293 // Check for nullptr pointers
1294 if (0 == tiXmlPointer) {
1295#ifdef TICPP_NO_RTTI
1296 TICPPTHROW("Can not create TinyXML objext");
1297#else
1298 TICPPTHROW("Can not create a " << typeid(T).name());
1299#endif
1300 }
1301
1302 SetTiXmlPointer(tiXmlPointer);
1303 m_impRC->IncRef();
1304 }
1305
1313 virtual void operator=(const NodeImp< T >& copy) {
1314 // Dropping the reference to the old object
1315 this->m_impRC->DecRef();
1316
1317 // Pointing to the new Object
1319
1320 // The internal tixml pointer changed in the above line
1321 this->m_impRC->IncRef();
1322 }
1323
1332 : Node(copy) {
1333 // Pointing to the new Object
1335
1336 // The internal tixml pointer changed in the above line
1337 this->m_impRC->IncRef();
1338 }
1339
1340 public:
1341 /*
1342 Deletes the spawned wrapper objects.
1343 Decrements reference count.
1344 */
1345 virtual ~NodeImp() { m_impRC->DecRef(); }
1346 };
1347
1349 class Comment : public NodeImp< TiXmlComment > {
1350 private: // best attempt to get rid of overloaded virtual warnings
1351 using NodeImp< TiXmlComment >::operator=;
1352
1353 public:
1357 Comment();
1358
1362 Comment(TiXmlComment* comment);
1363
1367 Comment(const std::string& comment);
1368 };
1369
1371 class Text : public NodeImp< TiXmlText > {
1372 private: // best attempt to get rid of overloaded virtual warnings
1373 using NodeImp< TiXmlText >::operator=;
1374 public:
1378 Text();
1379
1384 Text(TiXmlText* text);
1385
1390 Text(const std::string& value);
1391
1401 template < class T >
1402 Text(const T& value)
1403 : NodeImp< TiXmlText >(new TiXmlText(ToString(value))) {
1404 m_impRC->InitRef();
1405 }
1406 };
1407
1409 class Document : public NodeImp< TiXmlDocument > {
1410 private: // best attempt to get rid of overloaded virtual warnings
1411 using NodeImp< TiXmlDocument >::operator=;
1412 public:
1417 Document();
1418
1422 Document(TiXmlDocument* document);
1423
1427 Document(const char* documentName);
1428
1441 Document(const std::string& documentName);
1442
1452
1459 void SaveFile() const;
1460
1469 void LoadFile(const std::string& filename,
1471
1475 void LoadFile(const char* filename,
1477
1484 void SaveFile(const std::string& filename) const;
1485
1494 void Parse(const std::string& xml,
1495 bool throwIfParseError = true,
1497 };
1498
1500 class Element : public NodeImp< TiXmlElement > {
1501 private: // best attempt to get rid of overloaded virtual warnings
1502 using NodeImp< TiXmlElement >::operator=;
1503
1504 public:
1508 Element();
1509
1514 Element(const std::string& value);
1515
1520 Element(const char* value);
1521
1525 Element(TiXmlElement* element);
1526
1532 template < class T >
1533 Element(const std::string& value, const T& text)
1534 : NodeImp< TiXmlElement >(new TiXmlElement(value)) {
1535 m_impRC->InitRef();
1536 SetText(text);
1537 }
1538
1548 Attribute* FirstAttribute(bool throwIfNoAttributes = true) const;
1549
1559 Attribute* LastAttribute(bool throwIfNoAttributes = true) const;
1560
1568 void IterateFirst(const std::string&, Attribute** first) const {
1569 *first = 0;
1570
1571 for (Attribute* child = FirstAttribute(false); child;
1572 child = child->Next(false)) {
1573 *first = dynamic_cast< Attribute* >(child);
1574
1575 if (0 != *first) {
1576 return;
1577 }
1578 }
1579 }
1580
1590 template < class T >
1591 void SetAttribute(const std::string& name, const T& value) {
1593 m_tiXmlPointer->SetAttribute(name, ToString(value));
1594 }
1595
1610 std::string GetText(bool throwIfNotFound = true) const {
1611 // Get the element's text value as a std::string
1612 std::string temp;
1613
1614 if (!GetTextImp(&temp)) {
1615 if (throwIfNotFound) {
1616 TICPPTHROW("Text does not exists in the current element");
1617 }
1618 }
1619
1620 return temp;
1621 }
1622
1636 std::string GetTextOrDefault(const std::string& defaultValue) const {
1637 // Get the element's text value as a std::string
1638 std::string temp;
1639
1640 if (!GetTextImp(&temp)) {
1641 return defaultValue;
1642 }
1643
1644 return temp;
1645 }
1646
1665 template < class T, class DefaultT >
1666 void GetTextOrDefault(T* value, const DefaultT& defaultValue) const {
1667 // Get the element's text value as a std::string
1668 std::string temp;
1669
1670 if (!GetTextImp(&temp)) {
1671 // The text value does not exist - set value to the default
1672 *value = defaultValue;
1673 return;
1674 }
1675
1676 // Stream the value from the string to T
1677 FromString(temp, value);
1678 }
1679
1699 template < class T >
1700 void GetText(T* value, bool throwIfNotFound = true) const {
1701 // Get the element's text value as a std::string
1702 std::string temp;
1703
1704 if (!GetTextImp(&temp)) {
1705 if (throwIfNotFound) {
1706 TICPPTHROW("Text does not exists in the current element");
1707 } else {
1708 return;
1709 }
1710 }
1711
1712 // Stream the value from the string to T
1713 FromString(temp, value);
1714 }
1715
1723 template < class T >
1724 void SetText(const T& value) {
1726 std::string temp = ToString(value);
1727
1728 if (m_tiXmlPointer->NoChildren()) {
1729 m_tiXmlPointer->LinkEndChild(new TiXmlText(temp));
1730 } else {
1731 if (0 == m_tiXmlPointer->GetText()) {
1732 m_tiXmlPointer->InsertBeforeChild(m_tiXmlPointer->FirstChild(),
1733 TiXmlText(temp));
1734 } else {
1735 // There already is text, so change it
1736 m_tiXmlPointer->FirstChild()->SetValue(temp);
1737 }
1738 }
1739 }
1740
1755 template < class T, class DefaulT >
1756 void GetAttributeOrDefault(const std::string& name,
1757 T* value,
1758 const DefaulT& defaultValue) const {
1759 // Get the attribute's value as a std::string
1760 std::string temp;
1761
1762 if (!GetAttributeImp(name, &temp)) {
1763 // The attribute does not exist - set value to the default
1764 *value = defaultValue;
1765 return;
1766 }
1767
1768 // Stream the value from the string to T
1769 FromString(temp, value);
1770 }
1771
1783 std::string GetAttributeOrDefault(const std::string& name,
1784 const std::string& defaultValue) const;
1785
1798 template < class T >
1799 T GetAttribute(const std::string& name, bool throwIfNotFound = true) const {
1800 // Get the attribute's value as a std::string
1801 std::string temp;
1802 T value;
1803
1804 if (!GetAttributeImp(name, &temp)) {
1805 if (throwIfNotFound) {
1806 const std::string error(std::string("Attribute '") + name +
1807 std::string("' does not exist"));
1808 TICPPTHROW(error);
1809 }
1810 } else {
1811 // Stream the value from the string to T
1812 FromString(temp, &value);
1813 }
1814
1815 return value;
1816 }
1817
1832 template < class T >
1833 void GetAttribute(const std::string& name,
1834 T* value,
1835 bool throwIfNotFound = true) const {
1836 // Get the attribute's value as a std::string
1837 std::string temp;
1838
1839 if (!GetAttributeImp(name, &temp)) {
1840 if (throwIfNotFound) {
1841 const std::string error(std::string("Attribute '") + name +
1842 std::string("' does not exist"));
1843 TICPPTHROW(error);
1844 } else {
1845 return;
1846 }
1847 }
1848
1849 // Stream the value from the string to T
1850 FromString(temp, value);
1851 }
1852
1862 std::string GetAttribute(const std::string& name) const;
1863
1870 bool HasAttribute(const std::string& name) const;
1871
1877 void RemoveAttribute(const std::string& name);
1878
1879 private:
1885 bool GetAttributeImp(const std::string& name, std::string* value) const;
1886
1892 bool GetTextImp(std::string* value) const;
1893 };
1894
1896 class Declaration : public NodeImp< TiXmlDeclaration > {
1897 private: // best attempt to get rid of overloaded virtual warnings
1898 using NodeImp< TiXmlDeclaration >::operator=;
1899 public:
1903 Declaration();
1904
1908 Declaration(TiXmlDeclaration* declaration);
1909
1913 Declaration(const std::string& version,
1914 const std::string& encoding,
1915 const std::string& standalone);
1916
1920 std::string Version() const;
1921
1925 std::string Encoding() const;
1926
1930 std::string Standalone() const;
1931 };
1932
1934 class StylesheetReference : public NodeImp< TiXmlStylesheetReference > {
1935 private: // best attempt to get rid of overloaded virtual warnings
1936 using NodeImp< TiXmlStylesheetReference >::operator=;
1937 public:
1942
1946 StylesheetReference(TiXmlStylesheetReference* stylesheetReference);
1947
1951 StylesheetReference(const std::string& type, const std::string& href);
1952
1956 std::string Type() const;
1957
1961 std::string Href() const;
1962 };
1963}
1964
1965#endif // TICPP_INCLUDED
1966
1967#endif // TIXML_USE_TICPP
TiCppRCImp * m_tiRC
Pointer to reference counter.
Definition ticpprc.h:46
An attribute is a name-value pair.
Definition tinyxml.h:915
TiXmlBase is a base class for every class in TinyXml.
Definition tinyxml.h:215
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition tinyxml.h:275
int Column() const
See Row().
Definition tinyxml.h:276
An XML comment.
Definition tinyxml.h:1330
In correct XML the declaration is the first entry in the file.
Definition tinyxml.h:1469
Always the top level node.
Definition tinyxml.h:1655
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition tinyxml.h:1743
int ErrorRow() const
Returns the location (if known) of the error.
Definition tinyxml.h:1761
bool Error() const
If an error occurs, Error will be set to true.
Definition tinyxml.h:1740
int ErrorCol() const
The column where the error occured. See ErrorRow().
Definition tinyxml.h:1762
The element is a container class.
Definition tinyxml.h:1095
The parent class for everything in the Document Object Model.
Definition tinyxml.h:454
void SetValue(const char *_value)
Changes the value of the node.
Definition tinyxml.h:538
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
Definition tinyxml.h:517
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition tinyxml.cpp:424
A stylesheet reference looks like this:
Definition tinyxml.h:1543
XML text.
Definition tinyxml.h:1386
Any tag that tinyXml doesn't recognize is saved as an unknown.
Definition tinyxml.h:1608
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks.
Definition tinyxml.h:144
Wrapper around TiXmlAttribute.
Definition ticpp.h:297
void GetValue(T *value) const
Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::ValueStr from a std:...
Definition ticpp.h:336
std::string Name() const
Get the value of this attribute.
Definition ticpp.cpp:120
std::string Value() const
Get the value of this attribute.
Definition ticpp.cpp:115
void operator=(const Attribute &copy)
Definition ticpp.cpp:90
virtual void Print(FILE *file, int depth) const
All TinyXml classes can print themselves to a filestream.
Definition ticpp.cpp:169
void IterateNext(const std::string &, Attribute **next) const
Definition ticpp.cpp:161
Attribute()
Construct an empty attribute.
Definition ticpp.cpp:75
void GetName(T *name) const
Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::Name from a std::str...
Definition ticpp.h:370
Attribute * Previous(bool throwIfNoAttribute=true) const
Get the previous sibling attribute in the DOM.
Definition ticpp.cpp:143
TiXmlBase * GetBasePointer() const
Definition ticpp.h:300
Attribute * Next(bool throwIfNoAttribute=true) const
Get the next sibling attribute in the DOM.
Definition ticpp.cpp:125
TiXmlAttribute * m_tiXmlPointer
Definition ticpp.h:299
void SetTiXmlPointer(TiXmlAttribute *newPointer)
Definition ticpp.cpp:174
void SetValue(const T &value)
Set the value of this node.
Definition ticpp.h:357
void SetName(const T &name)
Set the value of this attribute.
Definition ticpp.h:391
void IteratePrevious(const std::string &, Attribute **previous) const
Definition ticpp.cpp:165
Wrapper around TiXmlBase.
Definition ticpp.h:161
int Column() const
Return the position, in the original source file, of this node or attribute.
Definition ticpp.h:215
bool operator==(const Base &rhs) const
Compare internal TiXml pointers to determine is both are wrappers around the same node.
Definition ticpp.h:222
void SetImpRC(TiXmlBase *nodeBase)
Definition ticpp.h:279
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition ticpp.h:209
bool operator!=(const Base &rhs) const
Compare internal TiXml pointers to determine is both are wrappers around the same node.
Definition ticpp.h:231
void FromString(const std::string &temp, T *out) const
Converts a std::string to any class with a proper overload of the >> opertor.
Definition ticpp.h:189
std::string ToString(const T &value) const
Converts any class with a proper overload of the << opertor to a std::string.
Definition ticpp.h:169
virtual ~Base()
Destructor.
Definition ticpp.h:264
std::string ToString(const std::string &value) const
Definition ticpp.h:180
TiCppRCImp * m_impRC
Holds status of internal TiXmlPointer - use this to determine if object has been deleted already.
Definition ticpp.h:267
void FromString(const std::string &temp, std::string *out) const
Specialization for std::string.
Definition ticpp.h:201
std::string BuildDetailedErrorString() const
Builds detailed error string using TiXmlDocument::Error() and others.
Definition ticpp.h:238
virtual TiXmlBase * GetBasePointer() const =0
void ValidatePointer() const
Definition ticpp.h:281
Wrapper around TiXmlComment.
Definition ticpp.h:1349
Comment()
Constructor.
Definition ticpp.cpp:656
Wrapper around TiXmlDeclaration.
Definition ticpp.h:1896
std::string Encoding() const
Encoding.
Definition ticpp.cpp:885
Declaration()
Default Constructor.
Definition ticpp.cpp:867
std::string Standalone() const
StandAlone.
Definition ticpp.cpp:887
std::string Version() const
Version.
Definition ticpp.cpp:883
Wrapper around TiXmlDocument.
Definition ticpp.h:1409
void LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
Definition ticpp.cpp:705
void Parse(const std::string &xml, bool throwIfParseError=true, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given xml data.
Definition ticpp.cpp:735
void SaveFile() const
Save a file using the current document value.
Definition ticpp.cpp:711
Document()
Default Constructor.
Definition ticpp.cpp:687
Wrapper around TiXmlElement.
Definition ticpp.h:1500
bool GetTextImp(std::string *value) const
Definition ticpp.cpp:850
void GetAttribute(const std::string &name, T *value, bool throwIfNotFound=true) const
Gets an attribute of name from an element.
Definition ticpp.h:1833
void SetAttribute(const std::string &name, const T &value)
Sets an attribute of name to a given value.
Definition ticpp.h:1591
void SetText(const T &value)
Convenience function to set the text of an element.
Definition ticpp.h:1724
bool GetAttributeImp(const std::string &name, std::string *value) const
Definition ticpp.cpp:835
Attribute * LastAttribute(bool throwIfNoAttributes=true) const
Access the last attribute in this element.
Definition ticpp.cpp:788
void RemoveAttribute(const std::string &name)
Removes attribute from element.
Definition ticpp.cpp:830
void GetText(T *value, bool throwIfNotFound=true) const
Gets the text of an Element.
Definition ticpp.h:1700
Attribute * FirstAttribute(bool throwIfNoAttributes=true) const
Access the first attribute in this element.
Definition ticpp.cpp:766
std::string GetTextOrDefault(const std::string &defaultValue) const
Gets the text of an Element, if it doesn't exist it will return the defaultValue.
Definition ticpp.h:1636
std::string GetText(bool throwIfNotFound=true) const
Gets the text of an Element.
Definition ticpp.h:1610
Element()
Default Constructor.
Definition ticpp.cpp:747
T GetAttribute(const std::string &name, bool throwIfNotFound=true) const
Returns an attribute of name from an element.
Definition ticpp.h:1799
void IterateFirst(const std::string &, Attribute **first) const
Definition ticpp.h:1568
bool HasAttribute(const std::string &name) const
Returns true, if attribute exists.
Definition ticpp.cpp:825
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.
Definition ticpp.h:1666
Element(const std::string &value, const T &text)
Constructor that allows you to set the element text.
Definition ticpp.h:1533
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.
Definition ticpp.h:1756
std::string m_details
Exception Details.
Definition ticpp.h:85
const char * what() const
Override std::exception::what() to return m_details.
Definition ticpp.cpp:920
Exception(const std::string &details)
Construct an exception with a message.
Definition ticpp.cpp:915
Iterator(T *node, const std::string &value="")
Constructor.
Definition ticpp.h:1157
T * Get() const
Gets internal pointer.
Definition ticpp.h:1170
T * end() const
For for loop comparisons.
Definition ticpp.h:1141
bool operator!=(const Iterator &it) const
Compares internal pointer.
Definition ticpp.h:1233
Iterator operator++(int)
Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.
Definition ticpp.h:1196
T * m_p
Internal Pointer.
Definition ticpp.h:1114
Iterator & operator=(T *p)
Sets internal pointer.
Definition ticpp.h:1180
bool operator==(T *p) const
Compares internal pointer*.
Definition ticpp.h:1236
Iterator & operator--()
Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.
Definition ticpp.h:1205
Iterator operator--(int)
Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.
Definition ticpp.h:1213
Iterator & operator++()
Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.
Definition ticpp.h:1188
T & operator*() const
So Iterator behaves like a STL iterator.
Definition ticpp.h:1255
Iterator(const std::string &value="")
Constructor.
Definition ticpp.h:1152
std::string m_value
Value for NextSibling calls.
Definition ticpp.h:1115
bool operator!=(const T *p) const
Compares internal pointer.
Definition ticpp.h:1220
T * operator->() const
So Iterator behaves like a STL iterator.
Definition ticpp.h:1252
bool operator==(const Iterator &it) const
Compares internal pointer.
Definition ticpp.h:1249
T * begin(const Node *parent) const
For for loop comparisons.
Definition ticpp.h:1127
Iterator & operator=(const Iterator &it)
Sets internal pointer.
Definition ticpp.h:1173
Iterator(const Iterator &it)
Constructor.
Definition ticpp.h:1162
virtual void operator=(const NodeImp< T > &copy)
Definition ticpp.h:1313
NodeImp(T *tiXmlPointer)
Definition ticpp.h:1292
TiXmlNode * GetTiXmlPointer() const
Definition ticpp.h:1271
void SetTiXmlPointer(T *newPointer)
Definition ticpp.h:1283
NodeImp(const NodeImp< T > &copy)
Definition ticpp.h:1331
virtual ~NodeImp()
Definition ticpp.h:1345
T * m_tiXmlPointer
Internal pointer to the TiXml Class which is being wrapped.
Definition ticpp.h:1262
Wrapper around TiXmlNode.
Definition ticpp.h:460
Comment * ToComment() const
Pointer conversion - replaces TiXmlNode::ToComment.
Definition ticpp.cpp:583
Node * ReplaceChild(Node *replaceThis, Node &withThis)
Replace a child of this node.
Definition ticpp.cpp:383
Declaration * ToDeclaration() const
Pointer conversion - replaces TiXmlNode::ToDeclaration.
Definition ticpp.cpp:609
std::unique_ptr< Node > Clone() const
Create an exact duplicate of this node and return it.
Definition ticpp.cpp:635
void SetValue(const T &value)
Set the value of this node.
Definition ticpp.h:490
StylesheetReference * ToStylesheetReference() const
Pointer conversion - replaces TiXmlNode::ToStylesheetReference.
Definition ticpp.cpp:622
Element * FirstChildElement(bool throwIfNoChildren=true) const
The first child element of this node.
Definition ticpp.cpp:501
Node * Parent(bool throwIfNoParent=true) const
The Parent of this Node.
Definition ticpp.cpp:234
bool Accept(TiXmlVisitor *visitor) const
Accept a hierchical visit the nodes in the TinyXML DOM.
Definition ticpp.cpp:650
void Clear()
Clear all Nodes below this.
Definition ticpp.cpp:232
bool NoChildren() const
Check if this node has no children.
Definition ticpp.cpp:555
void RemoveChild(Node *removeThis)
Delete a child of this node.
Definition ticpp.cpp:401
Document * ToDocument() const
Pointer conversion - replaces TiXmlNode::ToDocument.
Definition ticpp.cpp:557
std::string Value() const
Get the value of this node.
Definition ticpp.cpp:230
T * To() const
Pointer conversion ( NOT OBJECT CONVERSION ) - replaces TiXmlNode::ToElement, TiXmlNode::ToDocument,...
Definition ticpp.h:961
Node * NodeFactory(TiXmlNode *tiXmlNode, bool throwIfNull=true, bool rememberSpawnedWrapper=true) const
Definition ticpp.cpp:181
void IteratePrevious(const std::string &value, T **previous) const
Definition ticpp.h:826
Element * NextSiblingElement(bool throwIfNoSiblings=true) const
Navigate to a sibling element.
Definition ticpp.cpp:464
Node * InsertAfterChild(Node *afterThis, Node &addThis)
Adds a child after the specified child.
Definition ticpp.cpp:365
Node * InsertEndChild(Node &addThis)
Adds a child past the LastChild.
Definition ticpp.cpp:317
Node * LastChild(bool throwIfNoChildren=true) const
The last child of this node.
Definition ticpp.cpp:268
Node * InsertBeforeChild(Node *beforeThis, Node &addThis)
Adds a child before the specified child.
Definition ticpp.cpp:347
Node * NextSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition ticpp.cpp:438
void IterateNext(const std::string &value, T **next) const
Definition ticpp.h:808
friend std::ostream & operator<<(std::ostream &out, const Node &base)
Stream output operator.
Definition ticpp.h:1061
Document * GetDocument(bool throwIfNoDocument=true) const
Return a pointer to the Document this node lives in.
Definition ticpp.cpp:538
Node * IterateChildren(Node *previous) const
An alternate way to walk the children of a node.
Definition ticpp.cpp:292
int Type() const
Query the type (as TiXmlNode::NodeType ) of this node.
Definition ticpp.cpp:536
void GetValue(T *value) const
Get the value of this node Uses Base::FromString to convert TiXmlNode::ValueStr from a std::string,...
Definition ticpp.h:470
void IterateFirst(const std::string &value, T **first) const
Definition ticpp.h:783
virtual void IterateFirst(const std::string &, Attribute **) const
Definition ticpp.h:796
Node * PreviousSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition ticpp.cpp:410
virtual TiXmlNode * GetTiXmlPointer() const =0
friend std::istream & operator>>(std::istream &in, Node &base)
Stream input operator.
Definition ticpp.h:1053
Node * LinkEndChild(Node *childNode)
Adds a child past the LastChild.
Definition ticpp.cpp:332
Node * FirstChild(bool throwIfNoChildren=true) const
The first child of this node.
Definition ticpp.cpp:244
Element * ToElement() const
Pointer conversion - replaces TiXmlNode::ToElement.
Definition ticpp.cpp:570
Text * ToText() const
Pointer conversion - replaces TiXmlNode::ToText.
Definition ticpp.cpp:596
TiXmlBase * GetBasePointer() const
Definition ticpp.h:1073
Wrapper around TiXmlStylesheetReference.
Definition ticpp.h:1934
std::string Href() const
Href.
Definition ticpp.cpp:911
StylesheetReference()
Default Constructor.
Definition ticpp.cpp:893
std::string Type() const
Type.
Definition ticpp.cpp:909
Wrapper around TiXmlText.
Definition ticpp.h:1371
Text(const T &value)
Streams value into a string and creates a Text with it.
Definition ticpp.h:1402
Text()
Constructor.
Definition ticpp.cpp:672
Wrapper around TiXmlVisitor.
Definition ticpp.h:112
virtual bool Visit(const Text &)
Visit a text node.
Definition ticpp.h:155
virtual bool VisitEnter(const Element &, const Attribute *)
Visit an element.
Definition ticpp.h:143
virtual bool VisitEnter(const Document &)
Visit a document.
Definition ticpp.h:138
virtual bool Visit(const StylesheetReference &)
Visit a stylesheet reference.
Definition ticpp.h:153
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
Definition ticpp.cpp:38
virtual bool Visit(const Declaration &)
Visit a declaration.
Definition ticpp.h:151
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Definition ticpp.cpp:34
virtual bool Visit(const Comment &)
Visit a comment node.
Definition ticpp.h:157
virtual bool VisitExit(const Document &)
Visit a document.
Definition ticpp.h:140
virtual bool VisitExit(const Element &)
Visit an element.
Definition ticpp.h:148
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
Definition ticpp.cpp:56
ticpp is a TinyXML wrapper that uses a lot more C++ ideals.
Definition ticpp.h:70
#define TICPPTHROW(message)
This allows you to stream your exceptions in.
Definition ticpp.h:92
TiXmlEncoding
Definition tinyxml.h:179
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition tinyxml.h:185