aGrUM  0.16.0
ticpp.h
Go to the documentation of this file.
1 /*
2 http://code.google.com/p/ticpp/
3 Copyright (c) 2006 Ryan Pusztai, Ryan Mulder
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of
6 this software and associated documentation files (the "Software"), to deal in
7 the Software without restriction, including without limitation the rights to
8 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 the Software, and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION 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 
70 namespace 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  }
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:
267  mutable TiCppRCImp* m_impRC;
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:
301  ValidatePointer();
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 {
337  ValidatePointer();
338  FromString(m_tiXmlPointer->ValueStr(), value);
339  }
340 
347  std::string Value() const;
348 
356  template < class T >
357  void SetValue(const T& value) {
358  ValidatePointer();
359  m_tiXmlPointer->SetValue(ToString(value));
360  }
361 
369  template < class T >
370  void GetName(T* name) const {
371  ValidatePointer();
372  FromString(m_tiXmlPointer->Name(), name);
373  }
374 
381  std::string Name() const;
382 
390  template < class T >
391  void SetName(const T& name) {
392  ValidatePointer();
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) {
491  GetTiXmlPointer()->SetValue(ToString(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
950 
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 
1021  StylesheetReference* ToStylesheetReference() const;
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 
1073  TiXmlBase* GetBasePointer() const { return GetTiXmlPointer(); }
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;
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 
1162  Iterator(const Iterator& it)
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:
1272  ValidatePointer();
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
1318  SetTiXmlPointer(copy.m_tiXmlPointer);
1319 
1320  // The internal tixml pointer changed in the above line
1321  this->m_impRC->IncRef();
1322  }
1323 
1331  NodeImp(const NodeImp< T >& copy)
1332  : Node(copy) {
1333  // Pointing to the new Object
1334  SetTiXmlPointer(copy.m_tiXmlPointer);
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  public:
1354  Comment();
1355 
1359  Comment(TiXmlComment* comment);
1360 
1364  Comment(const std::string& comment);
1365  };
1366 
1368  class Text : public NodeImp< TiXmlText > {
1369  public:
1373  Text();
1374 
1379  Text(TiXmlText* text);
1380 
1385  Text(const std::string& value);
1386 
1396  template < class T >
1397  Text(const T& value)
1398  : NodeImp< TiXmlText >(new TiXmlText(ToString(value))) {
1399  m_impRC->InitRef();
1400  }
1401  };
1402 
1404  class Document : public NodeImp< TiXmlDocument > {
1405  public:
1410  Document();
1411 
1415  Document(TiXmlDocument* document);
1416 
1420  Document(const char* documentName);
1421 
1434  Document(const std::string& documentName);
1435 
1444  void LoadFile(TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
1445 
1452  void SaveFile() const;
1453 
1462  void LoadFile(const std::string& filename,
1464 
1468  void LoadFile(const char* filename,
1470 
1477  void SaveFile(const std::string& filename) const;
1478 
1487  void Parse(const std::string& xml,
1488  bool throwIfParseError = true,
1490  };
1491 
1493  class Element : public NodeImp< TiXmlElement > {
1494  public:
1498  Element();
1499 
1504  Element(const std::string& value);
1505 
1510  Element(const char* value);
1511 
1515  Element(TiXmlElement* element);
1516 
1522  template < class T >
1523  Element(const std::string& value, const T& text)
1524  : NodeImp< TiXmlElement >(new TiXmlElement(value)) {
1525  m_impRC->InitRef();
1526  SetText(text);
1527  }
1528 
1538  Attribute* FirstAttribute(bool throwIfNoAttributes = true) const;
1539 
1549  Attribute* LastAttribute(bool throwIfNoAttributes = true) const;
1550 
1558  void IterateFirst(const std::string&, Attribute** first) const {
1559  *first = 0;
1560 
1561  for (Attribute* child = FirstAttribute(false); child;
1562  child = child->Next(false)) {
1563  *first = dynamic_cast< Attribute* >(child);
1564 
1565  if (0 != *first) {
1566  return;
1567  }
1568  }
1569  }
1570 
1580  template < class T >
1581  void SetAttribute(const std::string& name, const T& value) {
1582  ValidatePointer();
1583  m_tiXmlPointer->SetAttribute(name, ToString(value));
1584  }
1585 
1600  std::string GetText(bool throwIfNotFound = true) const {
1601  // Get the element's text value as a std::string
1602  std::string temp;
1603 
1604  if (!GetTextImp(&temp)) {
1605  if (throwIfNotFound) {
1606  TICPPTHROW("Text does not exists in the current element");
1607  }
1608  }
1609 
1610  return temp;
1611  }
1612 
1626  std::string GetTextOrDefault(const std::string& defaultValue) const {
1627  // Get the element's text value as a std::string
1628  std::string temp;
1629 
1630  if (!GetTextImp(&temp)) {
1631  return defaultValue;
1632  }
1633 
1634  return temp;
1635  }
1636 
1655  template < class T, class DefaultT >
1656  void GetTextOrDefault(T* value, const DefaultT& defaultValue) const {
1657  // Get the element's text value as a std::string
1658  std::string temp;
1659 
1660  if (!GetTextImp(&temp)) {
1661  // The text value does not exist - set value to the default
1662  *value = defaultValue;
1663  return;
1664  }
1665 
1666  // Stream the value from the string to T
1667  FromString(temp, value);
1668  }
1669 
1689  template < class T >
1690  void GetText(T* value, bool throwIfNotFound = true) const {
1691  // Get the element's text value as a std::string
1692  std::string temp;
1693 
1694  if (!GetTextImp(&temp)) {
1695  if (throwIfNotFound) {
1696  TICPPTHROW("Text does not exists in the current element");
1697  } else {
1698  return;
1699  }
1700  }
1701 
1702  // Stream the value from the string to T
1703  FromString(temp, value);
1704  }
1705 
1713  template < class T >
1714  void SetText(const T& value) {
1715  ValidatePointer();
1716  std::string temp = ToString(value);
1717 
1718  if (m_tiXmlPointer->NoChildren()) {
1719  m_tiXmlPointer->LinkEndChild(new TiXmlText(temp));
1720  } else {
1721  if (0 == m_tiXmlPointer->GetText()) {
1722  m_tiXmlPointer->InsertBeforeChild(m_tiXmlPointer->FirstChild(),
1723  TiXmlText(temp));
1724  } else {
1725  // There already is text, so change it
1726  m_tiXmlPointer->FirstChild()->SetValue(temp);
1727  }
1728  }
1729  }
1730 
1745  template < class T, class DefaulT >
1746  void GetAttributeOrDefault(const std::string& name,
1747  T* value,
1748  const DefaulT& defaultValue) const {
1749  // Get the attribute's value as a std::string
1750  std::string temp;
1751 
1752  if (!GetAttributeImp(name, &temp)) {
1753  // The attribute does not exist - set value to the default
1754  *value = defaultValue;
1755  return;
1756  }
1757 
1758  // Stream the value from the string to T
1759  FromString(temp, value);
1760  }
1761 
1773  std::string GetAttributeOrDefault(const std::string& name,
1774  const std::string& defaultValue) const;
1775 
1788  template < class T >
1789  T GetAttribute(const std::string& name, bool throwIfNotFound = true) const {
1790  // Get the attribute's value as a std::string
1791  std::string temp;
1792  T value;
1793 
1794  if (!GetAttributeImp(name, &temp)) {
1795  if (throwIfNotFound) {
1796  const std::string error(std::string("Attribute '") + name +
1797  std::string("' does not exist"));
1798  TICPPTHROW(error);
1799  }
1800  } else {
1801  // Stream the value from the string to T
1802  FromString(temp, &value);
1803  }
1804 
1805  return value;
1806  }
1807 
1822  template < class T >
1823  void GetAttribute(const std::string& name,
1824  T* value,
1825  bool throwIfNotFound = true) const {
1826  // Get the attribute's value as a std::string
1827  std::string temp;
1828 
1829  if (!GetAttributeImp(name, &temp)) {
1830  if (throwIfNotFound) {
1831  const std::string error(std::string("Attribute '") + name +
1832  std::string("' does not exist"));
1833  TICPPTHROW(error);
1834  } else {
1835  return;
1836  }
1837  }
1838 
1839  // Stream the value from the string to T
1840  FromString(temp, value);
1841  }
1842 
1852  std::string GetAttribute(const std::string& name) const;
1853 
1860  bool HasAttribute(const std::string& name) const;
1861 
1867  void RemoveAttribute(const std::string& name);
1868 
1869  private:
1875  bool GetAttributeImp(const std::string& name, std::string* value) const;
1876 
1882  bool GetTextImp(std::string* value) const;
1883  };
1884 
1886  class Declaration : public NodeImp< TiXmlDeclaration > {
1887  public:
1891  Declaration();
1892 
1896  Declaration(TiXmlDeclaration* declaration);
1897 
1901  Declaration(const std::string& version,
1902  const std::string& encoding,
1903  const std::string& standalone);
1904 
1908  std::string Version() const;
1909 
1913  std::string Encoding() const;
1914 
1918  std::string Standalone() const;
1919  };
1920 
1922  class StylesheetReference : public NodeImp< TiXmlStylesheetReference > {
1923  public:
1928 
1932  StylesheetReference(TiXmlStylesheetReference* stylesheetReference);
1933 
1937  StylesheetReference(const std::string& type, const std::string& href);
1938 
1942  std::string Type() const;
1943 
1947  std::string Href() const;
1948  };
1949 }
1950 
1951 #endif // TICPP_INCLUDED
1952 
1953 #endif // TIXML_USE_TICPP
Wrapper around TiXmlNode.
Definition: ticpp.h:460
Iterator & operator=(const Iterator &it)
Sets internal pointer.
Definition: ticpp.h:1173
void IteratePrevious(const std::string &value, T **previous) const
Definition: ticpp.h:826
int ErrorCol() const
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1762
NodeImp(T *tiXmlPointer)
Definition: ticpp.h:1292
An attribute is a name-value pair.
Definition: tinyxml.h:915
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
Definition: tinyxml.h:144
Wrapper around TiXmlComment.
Definition: ticpp.h:1349
Node * PreviousSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition: ticpp.cpp:410
Text(const T &value)
Streams value into a string and creates a Text with it.
Definition: ticpp.h:1397
Iterator operator--(int)
Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings...
Definition: ticpp.h:1213
Wrapper around TiXmlElement.
Definition: ticpp.h:1493
virtual void operator=(const NodeImp< T > &copy)
Definition: ticpp.h:1313
void IterateNext(const std::string &value, T **next) const
Definition: ticpp.h:808
virtual bool VisitExit(const Document &)
Visit a document.
Definition: ticpp.h:140
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:944
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1743
#define TICPPTHROW(message)
This allows you to stream your exceptions in.
Definition: ticpp.h:92
void GetAttributeOrDefault(const std::string &name, T *value, const DefaulT &defaultValue) const
Gets an attribute of name from an element, if it doesn&#39;t exist it will return the defaultValue...
Definition: ticpp.h:1746
std::string ToString(const std::string &value) const
Definition: ticpp.h:180
virtual bool Visit(const Text &)
Visit a text node.
Definition: ticpp.h:155
Iterator & operator=(T *p)
Sets internal pointer.
Definition: ticpp.h:1180
void FromString(const std::string &temp, std::string *out) const
Specialization for std::string.
Definition: ticpp.h:201
void SetName(const T &name)
Set the value of this attribute.
Definition: ticpp.h:391
NodeImp(const NodeImp< T > &copy)
Definition: ticpp.h:1331
virtual TiXmlBase * GetBasePointer() const =0
bool Error() const
If an error occurs, Error will be set to true.
Definition: tinyxml.h:1740
virtual bool Visit(const Declaration &)
Visit a declaration.
Definition: ticpp.h:151
void ValidatePointer() const
Definition: ticpp.h:281
std::string GetTextOrDefault(const std::string &defaultValue) const
Gets the text of an Element, if it doesn&#39;t exist it will return the defaultValue. ...
Definition: ticpp.h:1626
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:976
Implementation of Node wrapper.
Definition: ticpp.h:1260
std::string GetText(bool throwIfNotFound=true) const
Gets the text of an Element.
Definition: ticpp.h:1600
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 SetValue(const T &value)
Set the value of this node.
Definition: ticpp.h:490
virtual void IterateFirst(const std::string &, Attribute **) const
Definition: ticpp.h:796
bool operator==(const Iterator &it) const
Compares internal pointer.
Definition: ticpp.h:1249
bool IsNull()
Returns state of internal pointer - will be null if the object was deleted.
Definition: ticpp.cpp:973
Iterator operator++(int)
Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings...
Definition: ticpp.h:1196
Wrapper around TiXmlText.
Definition: ticpp.h:1368
const std::string & ValueStr() const
Return the value of this attribute.
Definition: tinyxml.h:951
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition: ticpp.h:209
bool operator!=(const T *p) const
Compares internal pointer.
Definition: ticpp.h:1220
virtual TiXmlNode * GetTiXmlPointer() const =0
A stylesheet reference looks like this:
Definition: tinyxml.h:1543
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
In correct XML the declaration is the first entry in the file.
Definition: tinyxml.h:1469
void SetTiXmlPointer(T *newPointer)
Definition: ticpp.h:1283
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115
Any tag that tinyXml doesn&#39;t recognize is saved as an unknown.
Definition: tinyxml.h:1608
T * Get() const
Gets internal pointer.
Definition: ticpp.h:1170
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition: tinyxml.h:185
virtual bool VisitEnter(const Element &, const Attribute *)
Visit an element.
Definition: ticpp.h:143
virtual bool VisitExit(const Element &)
Visit an element.
Definition: ticpp.h:148
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
bool operator!=(const Base &rhs) const
Compare internal TiXml pointers to determine is both are wrappers around the same node...
Definition: ticpp.h:231
T * m_p
Internal Pointer.
Definition: ticpp.h:1114
const char * Value() const
The meaning of &#39;value&#39; changes for the specific type of TiXmlNode.
Definition: tinyxml.h:517
T * begin(const Node *parent) const
For for loop comparisons.
Definition: ticpp.h:1127
void GetAttribute(const std::string &name, T *value, bool throwIfNotFound=true) const
Gets an attribute of name from an element.
Definition: ticpp.h:1823
const char * what() const
Override std::exception::what() to return m_details.
Definition: ticpp.cpp:920
void SetText(const T &value)
Convenience function to set the text of an element.
Definition: ticpp.h:1714
friend std::istream & operator>>(std::istream &in, Node &base)
Stream input operator.
Definition: ticpp.h:1053
void SetValue(const T &value)
Set the value of this node.
Definition: ticpp.h:357
This is a ticpp exception class.
Definition: ticpp.h:74
Wrapper around TiXmlDeclaration.
Definition: ticpp.h:1886
TiXmlNode * GetTiXmlPointer() const
Definition: ticpp.h:1271
Wrapper around TiXmlBase.
Definition: ticpp.h:161
Always the top level node.
Definition: tinyxml.h:1655
T * operator->() const
So Iterator behaves like a STL iterator.
Definition: ticpp.h:1252
TiXmlEncoding
Definition: tinyxml.h:179
void SetAttribute(const std::string &name, const T &value)
Sets an attribute of name to a given value.
Definition: ticpp.h:1581
TiXmlBase * GetBasePointer() const
Definition: ticpp.h:300
Iterator(const Iterator &it)
Constructor.
Definition: ticpp.h:1162
void GetText(T *value, bool throwIfNotFound=true) const
Gets the text of an Element.
Definition: ticpp.h:1690
virtual bool Visit(const Comment &)
Visit a comment node.
Definition: ticpp.h:157
Iterator & operator--()
Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings...
Definition: ticpp.h:1205
int ErrorRow() const
Returns the location (if known) of the error.
Definition: tinyxml.h:1761
virtual ~NodeImp()
Definition: ticpp.h:1345
void IterateFirst(const std::string &value, T **first) const
Definition: ticpp.h:783
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition: tinyxml.cpp:424
void SetImpRC(TiXmlBase *nodeBase)
Definition: ticpp.h:279
TiXmlBase is a base class for every class in TinyXml.
Definition: tinyxml.h:211
std::string m_details
Exception Details.
Definition: ticpp.h:85
TiXmlAttribute * m_tiXmlPointer
Definition: ticpp.h:299
bool operator==(const Base &rhs) const
Compare internal TiXml pointers to determine is both are wrappers around the same node...
Definition: ticpp.h:222
Wrapper around TiXmlVisitor.
Definition: ticpp.h:112
friend std::ostream & operator<<(std::ostream &out, const Node &base)
Stream output operator.
Definition: ticpp.h:1061
Definition: ticpp.h:70
Iterator & operator++()
Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings...
Definition: ticpp.h:1188
Element(const std::string &value, const T &text)
Constructor that allows you to set the element text.
Definition: ticpp.h:1523
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:454
XML text.
Definition: tinyxml.h:1386
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
Iterator(const std::string &value="")
Constructor.
Definition: ticpp.h:1152
T * To() const
Pointer conversion ( NOT OBJECT CONVERSION ) - replaces TiXmlNode::ToElement, TiXmlNode::ToDocument, TiXmlNode::ToComment, etc.
Definition: ticpp.h:961
T * m_tiXmlPointer
Internal pointer to the TiXml Class which is being wrapped.
Definition: ticpp.h:1262
T * end() const
For for loop comparisons.
Definition: ticpp.h:1141
Node * NextSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
Definition: ticpp.cpp:438
void IterateFirst(const std::string &, Attribute **first) const
Definition: ticpp.h:1558
T & operator*() const
So Iterator behaves like a STL iterator.
Definition: ticpp.h:1255
void GetTextOrDefault(T *value, const DefaultT &defaultValue) const
Gets the text value of an Element, if it doesn&#39;t exist it will return the defaultValue.
Definition: ticpp.h:1656
Wrapper around TiXmlDocument.
Definition: ticpp.h:1404
Attribute * Next(bool throwIfNoAttribute=true) const
Get the next sibling attribute in the DOM.
Definition: ticpp.cpp:125
TiCppRCImp * m_impRC
Holds status of internal TiXmlPointer - use this to determine if object has been deleted already...
Definition: ticpp.h:267
virtual ~Base()
Destructor.
Definition: ticpp.h:264
An XML comment.
Definition: tinyxml.h:1330
T GetAttribute(const std::string &name, bool throwIfNotFound=true) const
Returns an attribute of name from an element.
Definition: ticpp.h:1789
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:979
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
int Column() const
Return the position, in the original source file, of this node or attribute.
Definition: ticpp.h:215
Wrapper around TiXmlStylesheetReference.
Definition: ticpp.h:1922
Iterator for conveniently stepping through Nodes and Attributes.
Definition: ticpp.h:1112
std::string BuildDetailedErrorString() const
Builds detailed error string using TiXmlDocument::Error() and others.
Definition: ticpp.h:238
TiXmlBase * GetBasePointer() const
Definition: ticpp.h:1073
Exception(const std::string &details)
Construct an exception with a message.
Definition: ticpp.cpp:915
virtual bool VisitEnter(const Document &)
Visit a document.
Definition: ticpp.h:138
bool operator!=(const Iterator &it) const
Compares internal pointer.
Definition: ticpp.h:1233
Wrapper around TiXmlAttribute.
Definition: ticpp.h:297
Iterator(T *node, const std::string &value="")
Constructor.
Definition: ticpp.h:1157
The element is a container class.
Definition: tinyxml.h:1095
virtual bool Visit(const StylesheetReference &)
Visit a stylesheet reference.
Definition: ticpp.h:153
bool operator==(T *p) const
Compares internal pointer*.
Definition: ticpp.h:1236