Orxonox  0.0.5 Codename: Arcturus
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 
41 #ifdef TIXML_USE_TICPP
42 
43 #ifndef TICPP_INCLUDED
44 #define TICPP_INCLUDED
45 
46 #include "tinyxml.h"
47 #include <sstream>
48 #include <vector>
49 #include <memory>
50 #include <exception>
51 #include <typeinfo>
52 
63 namespace ticpp
64 {
68  class Exception : public std::exception
69  {
70  public:
74  Exception( const std::string& details );
75  ~Exception() throw();
76 
78  const char* what() const throw();
79 
80  std::string m_details;
81  };
82 
87  #define TICPPTHROW( message ) \
88  { \
89  std::ostringstream full_message; \
90  std::string file( __FILE__ ); \
91  file = file.substr( file.find_last_of( "\\/" ) + 1 ); \
92  full_message << message << " <" << file << "@" << __LINE__ << ">"; \
93  full_message << BuildDetailedErrorString(); \
94  throw Exception( full_message.str() ); \
95  }
96 
97  // Forward Declarations for Visitor, and others.
98  class Document;
99  class Element;
100  class Declaration;
101  class StylesheetReference;
102  class Text;
103  class Comment;
104  class Attribute;
105 
107  class Visitor : public TiXmlVisitor
108  {
109  public:
110  // Overload the TiXmlVisitor functions, wrap objects, call ticpp::Visitor functions
112  virtual bool VisitEnter( const TiXmlDocument& doc );
114  virtual bool VisitExit( const TiXmlDocument& doc );
116  virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
118  virtual bool VisitExit( const TiXmlElement& element );
120  virtual bool Visit( const TiXmlDeclaration& declaration );
122  virtual bool Visit( const TiXmlStylesheetReference& stylesheet );
124  virtual bool Visit( const TiXmlText& text );
126  virtual bool Visit( const TiXmlComment& comment );
127 
128  public:
130  virtual bool VisitEnter( const Document& /*doc*/ ) { return true; }
132  virtual bool VisitExit( const Document& /*doc*/ ) { return true; }
133 
135  virtual bool VisitEnter( const Element& /*element*/, const Attribute* /*firstAttribute*/ ) { return true; }
137  virtual bool VisitExit( const Element& /*element*/ ) { return true; }
138 
140  virtual bool Visit( const Declaration& /*declaration*/ ) { return true; }
142  virtual bool Visit( const StylesheetReference& /*stylesheet*/ ) { return true; }
144  virtual bool Visit( const Text& /*text*/ ) { return true; }
146  virtual bool Visit( const Comment& /*comment*/ ) { return true; }
147  };
148 
150  class Base
151  {
152  public:
153 
159  template < class T >
160  std::string ToString( const T& value ) const
161  {
162  std::stringstream convert;
163  convert << value;
164  if ( convert.fail() )
165  {
166  TICPPTHROW( "Could not convert value to text" );
167  }
168  return convert.str();
169  }
170 
171  std::string ToString( const std::string& value ) const
172  {
173  return value;
174  }
175 
182  template < class T >
183  void FromString( const std::string& temp, T* out ) const
184  {
185  std::istringstream val( temp );
186  val >> *out;
187 
188  if ( val.fail() )
189  {
190  TICPPTHROW( "Could not convert \"" << temp << "\" to target type" );
191  }
192  }
193 
197  void FromString( const std::string& temp, std::string* out ) const
198  {
199  *out = temp;
200  }
201 
206  int Row() const
207  {
208  return GetBasePointer()->Row();
209  }
210 
215  int Column() const
216  {
217  return GetBasePointer()->Column();
218  }
219 
223  bool operator == ( const Base& rhs ) const
224  {
225  return ( GetBasePointer() == rhs.GetBasePointer() );
226  }
227 
231  bool operator != ( const Base& rhs ) const
232  {
233  return ( GetBasePointer() != rhs.GetBasePointer() );
234  }
235 
239  std::string BuildDetailedErrorString() const
240  {
241  std::ostringstream full_message;
242  #ifndef TICPP_NO_RTTI
243  TiXmlNode* node = dynamic_cast< TiXmlNode* >( GetBasePointer() );
244  if ( node != 0 )
245  {
246  TiXmlDocument* doc = node->GetDocument();
247  if ( doc != 0 )
248  {
249  if ( doc->Error() )
250  {
251  full_message << "\nDescription: " << doc->ErrorDesc()
252  << "\nFile: " << (strlen( doc->Value() ) > 0 ? doc->Value() : "<unnamed-file>")
253  << "\nLine: " << doc->ErrorRow()
254  << "\nColumn: " << doc->ErrorCol();
255  }
256  }
257  }
258  #endif
259  return full_message.str();
260  }
261 
265  virtual ~Base()
266  {
267  }
268 
269  protected:
270  mutable TiCppRCImp* m_impRC;
278  void SetImpRC( TiXmlBase* node )
279  {
280  m_impRC = node->m_tiRC;
281  }
282 
283  void ValidatePointer() const
284  {
285  if ( m_impRC->IsNull() )
286  {
287  TICPPTHROW( "Internal TiXml Pointer is NULL" );
288  }
289  }
290 
295  virtual TiXmlBase* GetBasePointer() const = 0;
296  };
297 
301  class Attribute : public Base
302  {
303  private:
304  TiXmlAttribute* m_tiXmlPointer;
305  TiXmlBase* GetBasePointer() const
306  {
307  ValidatePointer();
308  return m_tiXmlPointer;
309  }
310 
311  public:
315  Attribute();
316 
323  Attribute( const std::string& name, const std::string& value );
324 
331  Attribute( TiXmlAttribute* attribute );
332 
340  template < class T >
341  void GetValue( T* value ) const
342  {
343  ValidatePointer();
344  FromString( m_tiXmlPointer->ValueStr(), value );
345  }
346 
353  std::string Value() const;
354 
361  template < class T >
362  void SetValue( const T& value )
363  {
364  ValidatePointer();
365  m_tiXmlPointer->SetValue( ToString( value ) );
366  }
367 
375  template < class T >
376  void GetName( T* name ) const
377  {
378  ValidatePointer();
379  FromString( m_tiXmlPointer->Name(), name );
380  }
381 
388  std::string Name() const;
389 
396  template < class T >
397  void SetName( const T& name )
398  {
399  ValidatePointer();
400  m_tiXmlPointer->SetName( ToString( name ) );
401  }
402 
407  void operator=( const Attribute& copy );
408 
413  Attribute( const Attribute& copy );
414 
415  /*
416  Decrements reference count.
417  */
418  ~Attribute();
419 
423  Attribute* Next( bool throwIfNoAttribute = true ) const;
424 
428  Attribute* Previous( bool throwIfNoAttribute = true ) const;
429 
437  void IterateNext( const std::string&, Attribute** next ) const;
438 
446  void IteratePrevious( const std::string&, Attribute** previous ) const;
447 
451  virtual void Print( FILE* file, int depth ) const;
452 
453  private:
454 
462  void SetTiXmlPointer( TiXmlAttribute* newPointer );
463  };
464 
468  class Node : public Base
469  {
470  public:
471 
479  template < class T >
480  void GetValue( T* value) const
481  {
482  FromString( GetTiXmlPointer()->ValueStr(), value );
483  }
484 
491  std::string Value() const;
492 
499  template < class T >
500  void SetValue( const T& value )
501  {
502  GetTiXmlPointer()->SetValue( ToString( value ) );
503  }
504 
509  void Clear();
510 
519  Node* Parent( bool throwIfNoParent = true ) const;
520 
530  Node* FirstChild( bool throwIfNoChildren = true ) const;
531 
542  Node* FirstChild( const char* value, bool throwIfNoChildren = true ) const;
543 
553  Node* FirstChild( const std::string& value, bool throwIfNoChildren = true ) const;
554 
564  Node* LastChild( bool throwIfNoChildren = true ) const;
565 
576  Node* LastChild( const char* value, bool throwIfNoChildren = true ) const;
577 
587  Node* LastChild( const std::string& value, bool throwIfNoChildren = true ) const;
588 
596  Node* IterateChildren( Node* previous ) const;
597 
606  Node* IterateChildren( const std::string& value, Node* previous ) const;
607 
619  Node* InsertEndChild( const Node& addThis );
620 
631  Node* LinkEndChild( Node* childNode );
632 
644  Node* InsertBeforeChild( Node* beforeThis, const Node& addThis );
645 
657  Node* InsertAfterChild( Node* afterThis, const Node& addThis );
658 
669  Node* ReplaceChild( Node* replaceThis, const Node& withThis );
670 
679  void RemoveChild( Node* removeThis );
680 
689  Node* PreviousSibling( bool throwIfNoSiblings = true ) const;
690 
700  Node* PreviousSibling( const std::string& value, bool throwIfNoSiblings = true ) const;
701 
712  Node* PreviousSibling( const char* value, bool throwIfNoSiblings = true ) const;
713 
722  Node* NextSibling( bool throwIfNoSiblings = true ) const;
723 
733  Node* NextSibling( const std::string& value, bool throwIfNoSiblings = true ) const;
734 
745  Node* NextSibling( const char* value, bool throwIfNoSiblings = true ) const;
746 
754  template < class T >
755  void IterateFirst( const std::string& value, T** first ) const
756  {
757  *first = 0;
758  for( Node* child = FirstChild( value, false ); child; child = child->NextSibling( value, false ) )
759  {
760  *first = dynamic_cast< T* >( child );
761  if ( 0 != *first )
762  {
763  return;
764  }
765  }
766  }
767 
768  virtual void IterateFirst( const std::string&, Attribute** ) const
769  {
770  TICPPTHROW( "Attributes can only be iterated with Elements." )
771  }
772 
780  template < class T >
781  void IterateNext( const std::string& value, T** next ) const
782  {
783  Node* sibling = NextSibling( value, false );
784  *next = dynamic_cast< T* >( sibling );
785 
786  while ( ( 0 != sibling ) && ( 0 == *next ) )
787  {
788  sibling = sibling->NextSibling( value, false );
789  *next = dynamic_cast< T* >( sibling );
790  }
791  }
792 
800  template < class T >
801  void IteratePrevious( const std::string& value, T** previous ) const
802  {
803  Node* sibling = PreviousSibling( value, false );
804  *previous = dynamic_cast< T* >( sibling );
805 
806  while ( ( 0 != sibling ) && ( 0 == *previous ) )
807  {
808  sibling = sibling->PreviousSibling( value, false );
809  *previous = dynamic_cast< T* >( sibling );
810  }
811  }
812 
821  Element* NextSiblingElement( bool throwIfNoSiblings = true ) const;
822 
831  Element* NextSiblingElement( const std::string& value, bool throwIfNoSiblings = true ) const;
832 
843  Element* NextSiblingElement( const char* value, bool throwIfNoSiblings = true ) const;
844 
854  Element* FirstChildElement( bool throwIfNoChildren = true ) const;
855 
866  Element* FirstChildElement( const char* value, bool throwIfNoChildren = true ) const;
867 
877  Element* FirstChildElement( const std::string& value, bool throwIfNoChildren = true ) const;
878 
882  int Type() const;
883 
891  Document* GetDocument( bool throwIfNoDocument = true ) const;
892 
898  bool NoChildren() const;
899 
900  #ifndef TICPP_NO_RTTI
901 
907  template < class T >
908  T* To() const
909  {
910  T* pointer = dynamic_cast< T* >( this );
911  if ( 0 == pointer )
912  {
913  std::string thisType = typeid( this ).name();
914  std::string targetType = typeid( T ).name();
915  std::string thatType = typeid( *this ).name();
916  TICPPTHROW( "The " << thisType.substr( 6 ) << " could not be casted to a " << targetType.substr( 6 )
917  << " *, because the target object is not a " << targetType.substr( 6 ) << ". (It is a " << thatType.substr( 6 ) << ")" );
918  }
919  return pointer;
920  }
921  #endif
922 
928  Document* ToDocument() const;
929 
935  Element* ToElement() const;
936 
942  Comment* ToComment() const;
943 
949  Text* ToText() const;
950 
956  Declaration* ToDeclaration() const;
957 
963  StylesheetReference* ToStylesheetReference() const;
964 
982  std::unique_ptr< Node > Clone() const;
983 
988  bool Accept( TiXmlVisitor* visitor ) const;
989 
993  friend std::istream& operator >>( std::istream& in, Node& base )
994  {
995  in >> *base.GetTiXmlPointer();
996  return in;
997  }
998 
1002  friend std::ostream& operator <<( std::ostream& out, const Node& base )
1003  {
1004  out << *base.GetTiXmlPointer();
1005  return out;
1006  }
1007 
1008  protected:
1013  virtual TiXmlNode* GetTiXmlPointer() const = 0;
1014 
1015  TiXmlBase* GetBasePointer() const
1016  {
1017  return GetTiXmlPointer();
1018  }
1019 
1024  Node* NodeFactory( TiXmlNode* tiXmlNode, bool throwIfNull = true, bool rememberSpawnedWrapper = true ) const;
1025 
1026  };
1027 
1054  template < class T = Node >
1055  class Iterator
1056  {
1057  private:
1058  T* m_p;
1059  std::string m_value;
1061  public:
1062 
1072  T* begin( const Node* parent ) const
1073  {
1074  T* pointer;
1075  parent->IterateFirst( m_value, &pointer );
1076  return pointer;
1077  }
1078 
1087  T* end() const
1088  {
1089  return 0;
1090  }
1091 
1100  Iterator( const std::string& value = "" )
1101  : m_p( 0 ), m_value( value )
1102  {
1103  }
1104 
1106  Iterator( T* node, const std::string& value = "" )
1107  : m_p( node ), m_value( value )
1108  {
1109  }
1110 
1112  Iterator( const Iterator& it )
1113  : m_p( it.m_p ), m_value( it.m_value )
1114  {
1115  }
1116 
1121  T* Get() const
1122  {
1123  return m_p;
1124  }
1125 
1127  Iterator& operator=( const Iterator& it )
1128  {
1129  m_p = it.m_p;
1130  m_value = it.m_value;
1131  return *this;
1132  }
1133 
1135  Iterator& operator=( T* p )
1136  {
1137  m_p = p;
1138  return *this;
1139  }
1140 
1142  Iterator& operator++()
1143  {
1144  m_p->IterateNext( m_value, &m_p );
1145  return *this;
1146  }
1147 
1149  Iterator operator++(int)
1150  {
1151  Iterator tmp(*this);
1152  ++(*this);
1153  return tmp;
1154  }
1155 
1157  Iterator& operator--()
1158  {
1159  m_p->IteratePrevious( m_value, &m_p );
1160  return *this;
1161  }
1162 
1164  Iterator operator--(int)
1165  {
1166  Iterator tmp(*this);
1167  --(*this);
1168  return tmp;
1169  }
1170 
1172  bool operator!=( const T* p ) const
1173  {
1174  if ( m_p == p )
1175  {
1176  return false;
1177  }
1178  if ( 0 == m_p || 0 == p )
1179  {
1180  return true;
1181  }
1182  return *m_p != *p;
1183  }
1184 
1186  bool operator!=( const Iterator& it ) const
1187  {
1188  return operator!=( it.m_p );
1189  }
1190 
1192  bool operator==( T* p ) const
1193  {
1194  if ( m_p == p )
1195  {
1196  return true;
1197  }
1198  if ( 0 == m_p || 0 == p )
1199  {
1200  return false;
1201  }
1202  return *m_p == *p;
1203  }
1204 
1206  bool operator==( const Iterator& it ) const
1207  {
1208  return operator==( it.m_p );
1209  }
1210 
1212  T* operator->() const
1213  {
1214  return m_p;
1215  }
1216 
1218  T& operator*() const
1219  {
1220  return *m_p;
1221  }
1222  };
1223 
1225  template < class T >
1226  class NodeImp : public Node
1227  {
1228  protected:
1229 
1230  T* m_tiXmlPointer;
1232  public:
1239  TiXmlNode* GetTiXmlPointer() const
1240  {
1241  ValidatePointer();
1242  return m_tiXmlPointer;
1243  }
1244  protected:
1245 
1253  void SetTiXmlPointer( T* newPointer )
1254  {
1255  m_tiXmlPointer = newPointer;
1256  SetImpRC( newPointer );
1257  }
1258 
1263  NodeImp( T* tiXmlPointer )
1264  {
1265  // Check for NULL pointers
1266  if ( 0 == tiXmlPointer )
1267  {
1268  #ifdef TICPP_NO_RTTI
1269  TICPPTHROW( "Can not create TinyXML objext" );
1270  #else
1271  TICPPTHROW( "Can not create a " << typeid( T ).name() );
1272  #endif
1273  }
1274  SetTiXmlPointer( tiXmlPointer );
1275  m_impRC->IncRef();
1276  }
1277 
1283  virtual void operator=( const NodeImp<T>& copy )
1284  {
1285  // Dropping the reference to the old object
1286  this->m_impRC->DecRef();
1287 
1288  // Pointing to the new Object
1289  SetTiXmlPointer( copy.m_tiXmlPointer );
1290 
1291  // The internal tixml pointer changed in the above line
1292  this->m_impRC->IncRef();
1293  }
1294 
1300  NodeImp( const NodeImp<T>& copy ) : Node( copy )
1301  {
1302  // Pointing to the new Object
1303  SetTiXmlPointer( copy.m_tiXmlPointer );
1304 
1305  // The internal tixml pointer changed in the above line
1306  this->m_impRC->IncRef();
1307  }
1308 
1309  public:
1310 
1311  /*
1312  Deletes the spawned wrapper objects.
1313  Decrements reference count.
1314  */
1315  virtual ~NodeImp()
1316  {
1317  m_impRC->DecRef();
1318  }
1319  };
1320 
1322  class Comment : public NodeImp< TiXmlComment >
1323  {
1324  public:
1325 
1329  Comment();
1330 
1334  Comment( TiXmlComment* comment );
1335 
1339  Comment( const std::string& comment );
1340  };
1341 
1343  class Text : public NodeImp< TiXmlText >
1344  {
1345  public:
1346 
1350  Text();
1351 
1356  Text( TiXmlText* text );
1357 
1362  Text( const std::string& value );
1363 
1373  template < class T >
1374  Text( const T& value )
1375  : NodeImp< TiXmlText >( new TiXmlText( ToString( value ) ) )
1376  {
1377  m_impRC->InitRef();
1378  }
1379  };
1380 
1382  class Document : public NodeImp< TiXmlDocument >
1383  {
1384  public:
1389  Document();
1390 
1394  Document( TiXmlDocument* document );
1395 
1399  Document( const char* documentName );
1400 
1408  Document( const std::string& documentName );
1409 
1417  void LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1418 
1424  void SaveFile() const;
1425 
1434  void LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1435 
1439  void LoadFile( const char* filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1440 
1447  void SaveFile( const std::string& filename ) const;
1448 
1457  void Parse( const std::string& xml, bool throwIfParseError = true, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1458  };
1459 
1461  class Element : public NodeImp< TiXmlElement >
1462  {
1463  public:
1467  Element();
1468 
1473  Element( const std::string& value );
1474 
1479  Element( const char* value );
1480 
1484  Element( TiXmlElement* element );
1485 
1491  template < class T >
1492  Element( const std::string& value, const T& text )
1493  : NodeImp< TiXmlElement >( new TiXmlElement( value ) )
1494  {
1495  m_impRC->InitRef();
1496  SetText( text );
1497  }
1498 
1505  Attribute* FirstAttribute( bool throwIfNoAttributes = true ) const;
1506 
1513  Attribute* LastAttribute( bool throwIfNoAttributes = true ) const;
1514 
1522  void IterateFirst( const std::string&, Attribute** first ) const
1523  {
1524  *first = 0;
1525  for( Attribute* child = FirstAttribute( false ); child; child = child->Next( false ) )
1526  {
1527  *first = dynamic_cast< Attribute* >( child );
1528  if ( 0 != *first )
1529  {
1530  return;
1531  }
1532  }
1533  }
1534 
1542  template < class T >
1543  void SetAttribute ( const std::string& name, const T& value )
1544  {
1545  ValidatePointer();
1546  m_tiXmlPointer->SetAttribute( name, ToString( value ) );
1547  }
1548 
1561  std::string GetText( bool throwIfNotFound = true ) const
1562  {
1563  // Get the element's text value as a std::string
1564  std::string temp;
1565  if ( !GetTextImp( &temp ) )
1566  {
1567  if ( throwIfNotFound )
1568  {
1569  TICPPTHROW( "Text does not exists in the current element" );
1570  }
1571  }
1572 
1573  return temp;
1574  }
1575 
1587  std::string GetTextOrDefault( const std::string& defaultValue ) const
1588  {
1589  // Get the element's text value as a std::string
1590  std::string temp;
1591  if ( !GetTextImp( &temp ) )
1592  {
1593  return defaultValue;
1594  }
1595 
1596  return temp;
1597  }
1598 
1613  template < class T, class DefaultT >
1614  void GetTextOrDefault( T* value, const DefaultT& defaultValue ) const
1615  {
1616  // Get the element's text value as a std::string
1617  std::string temp;
1618  if ( !GetTextImp( &temp ) )
1619  {
1620  // The text value does not exist - set value to the default
1621  *value = defaultValue;
1622  return;
1623  }
1624 
1625  // Stream the value from the string to T
1626  FromString( temp, value );
1627  }
1628 
1644  template< class T >
1645  void GetText( T* value, bool throwIfNotFound = true ) const
1646  {
1647  // Get the element's text value as a std::string
1648  std::string temp;
1649  if ( !GetTextImp( &temp ) )
1650  {
1651  if ( throwIfNotFound )
1652  {
1653  TICPPTHROW( "Text does not exists in the current element" );
1654  }
1655  else
1656  {
1657  return;
1658  }
1659  }
1660 
1661  // Stream the value from the string to T
1662  FromString( temp, value );
1663  }
1664 
1672  template < class T >
1673  void SetText( const T& value )
1674  {
1675  ValidatePointer();
1676  std::string temp = ToString( value );
1677 
1678  if ( m_tiXmlPointer->NoChildren() )
1679  {
1680  m_tiXmlPointer->LinkEndChild( new TiXmlText( temp ) );
1681  }
1682  else
1683  {
1684  if ( 0 == m_tiXmlPointer->GetText() )
1685  {
1686  m_tiXmlPointer->InsertBeforeChild( m_tiXmlPointer->FirstChild(), TiXmlText( temp ) );
1687  }
1688  else
1689  {
1690  // There already is text, so change it
1691  m_tiXmlPointer->FirstChild()->SetValue( temp );
1692  }
1693  }
1694  }
1695 
1707  template < class T, class DefaulT >
1708  void GetAttributeOrDefault( const std::string& name, T* value, const DefaulT& defaultValue ) const
1709  {
1710  // Get the attribute's value as a std::string
1711  std::string temp;
1712  if ( !GetAttributeImp( name, &temp ) )
1713  {
1714  // The attribute does not exist - set value to the default
1715  *value = defaultValue;
1716  return;
1717  }
1718 
1719  // Stream the value from the string to T
1720  FromString( temp, value );
1721  }
1722 
1731  std::string GetAttributeOrDefault( const std::string& name, const std::string& defaultValue ) const;
1732 
1742  template < class T >
1743  T GetAttribute( const std::string& name, bool throwIfNotFound = true ) const
1744  {
1745  // Get the attribute's value as a std::string
1746  std::string temp;
1747  T value;
1748  if ( !GetAttributeImp( name, &temp ) )
1749  {
1750  if ( throwIfNotFound )
1751  {
1752  const std::string error( std::string( "Attribute '" ) + name + std::string( "' does not exist" ) );
1753  TICPPTHROW( error );
1754  }
1755  }
1756  else
1757  {
1758  // Stream the value from the string to T
1759  FromString( temp, &value );
1760  }
1761 
1762  return value;
1763  }
1764 
1776  template< class T >
1777  void GetAttribute( const std::string& name, T* value, bool throwIfNotFound = true ) const
1778  {
1779  // Get the attribute's value as a std::string
1780  std::string temp;
1781  if ( !GetAttributeImp( name, &temp ) )
1782  {
1783  if ( throwIfNotFound )
1784  {
1785  const std::string error( std::string( "Attribute '" ) + name + std::string( "' does not exist" ) );
1786  TICPPTHROW( error );
1787  }
1788  else
1789  {
1790  return;
1791  }
1792  }
1793 
1794  // Stream the value from the string to T
1795  FromString( temp, value );
1796  }
1797 
1807  std::string GetAttribute( const std::string& name ) const;
1808 
1815  bool HasAttribute( const std::string& name ) const;
1816 
1822  void RemoveAttribute( const std::string& name );
1823 
1824  private:
1825 
1830  bool GetAttributeImp( const std::string& name, std::string* value ) const;
1831 
1836  bool GetTextImp( std::string* value ) const;
1837  };
1838 
1840  class Declaration : public NodeImp< TiXmlDeclaration >
1841  {
1842  public:
1846  Declaration();
1847 
1851  Declaration( TiXmlDeclaration* declaration );
1852 
1856  Declaration( const std::string& version, const std::string& encoding, const std::string& standalone );
1857 
1861  std::string Version() const;
1862 
1866  std::string Encoding() const;
1867 
1871  std::string Standalone() const;
1872  };
1873 
1875  class StylesheetReference : public NodeImp< TiXmlStylesheetReference >
1876  {
1877  public:
1881  StylesheetReference();
1882 
1886  StylesheetReference( TiXmlStylesheetReference* stylesheetReference );
1887 
1891  StylesheetReference( const std::string& type, const std::string& href );
1892 
1896  std::string Type() const;
1897 
1901  std::string Href() const;
1902  };
1903 }
1904 
1905 #endif // TICPP_INCLUDED
1906 
1907 #endif // TIXML_USE_TICPP
Always the top level node.
Definition: tinyxml.h:1466
static void version(void)
Definition: tolua.c:58
bool Error() const
If an error occurs, Error will be set to true.
Definition: tinyxml.h:1537
::std::string string
Definition: gtest-port.h:756
bool operator==(T *ptr, const linked_ptr< T > &x)
Definition: gtest-linked_ptr.h:213
STL namespace.
const char * Value() const
The meaning of &#39;value&#39; changes for the specific type of TiXmlNode.
Definition: tinyxml.h:503
std::ostream & operator<<(std::ostream &os, const Message &sb)
Definition: gtest-message.h:224
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:829
Value
Definition: CorePrereqs.h:113
static void error(char *o)
Definition: tolua.c:79
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:438
int ErrorCol() const
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1555
int ErrorRow() const
Returns the location (if known) of the error.
Definition: tinyxml.h:1554
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:853
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition: tinyxml.h:180
An attribute is a name-value pair.
Definition: tinyxml.h:797
false defaultValue(2, false).argumentCompleter(0
TiXmlBase is a base class for every class in TinyXml.
Definition: tinyxml.h:208
An XML comment.
Definition: tinyxml.h:1171
In correct XML the declaration is the first entry in the file.
Definition: tinyxml.h:1294
TiXmlEncoding
Definition: tinyxml.h:173
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:854
A stylesheet reference looks like this:
Definition: tinyxml.h:1364
Definition: InputPrereqs.h:78
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
Definition: tinyxml.h:136
Definition: CorePrereqs.h:409
Type
Each Input class has a General Type variable, a form of RTTI.
Definition: OISPrereqs.h:138
XML text.
Definition: tinyxml.h:1221
The element is a container class.
Definition: tinyxml.h:961
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1540
bool operator!=(T *ptr, const linked_ptr< T > &x)
Definition: gtest-linked_ptr.h:218
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition: tinyxml.cpp:490
ORX_FORCEINLINE bool operator>>(std::istream &instream, ToType &output)
Fallback operator >>() (delegates to orxonox::ConverterFallback)
Definition: Convert.h:249