41 #ifdef TIXML_USE_TICPP 43 #ifndef TICPP_INCLUDED 44 #define TICPP_INCLUDED 68 class Exception :
public std::exception
78 const
char* what() const throw();
80 std::
string m_details;
87 #define TICPPTHROW( message ) \ 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() ); \ 101 class StylesheetReference;
124 virtual bool Visit(
const TiXmlText& text );
130 virtual bool VisitEnter(
const Document& ) {
return true; }
132 virtual bool VisitExit(
const Document& ) {
return true; }
135 virtual bool VisitEnter(
const Element& ,
const Attribute* ) {
return true; }
137 virtual bool VisitExit(
const Element& ) {
return true; }
140 virtual bool Visit(
const Declaration& ) {
return true; }
142 virtual bool Visit(
const StylesheetReference& ) {
return true; }
144 virtual bool Visit(
const Text& ) {
return true; }
146 virtual bool Visit(
const Comment& ) {
return true; }
162 std::stringstream convert;
164 if ( convert.fail() )
166 TICPPTHROW(
"Could not convert value to text" );
168 return convert.str();
183 void FromString(
const std::string& temp,
T* out )
const 185 std::istringstream val( temp );
190 TICPPTHROW(
"Could not convert \"" << temp <<
"\" to target type" );
208 return GetBasePointer()->Row();
217 return GetBasePointer()->Column();
225 return ( GetBasePointer() == rhs.GetBasePointer() );
233 return ( GetBasePointer() != rhs.GetBasePointer() );
241 std::ostringstream full_message;
242 #ifndef TICPP_NO_RTTI 251 full_message <<
"\nDescription: " << doc->
ErrorDesc()
252 <<
"\nFile: " << (strlen( doc->
Value() ) > 0 ? doc->
Value() :
"<unnamed-file>")
259 return full_message.str();
270 mutable TiCppRCImp* m_impRC;
280 m_impRC = node->m_tiRC;
283 void ValidatePointer()
const 285 if ( m_impRC->IsNull() )
287 TICPPTHROW(
"Internal TiXml Pointer is NULL" );
295 virtual TiXmlBase* GetBasePointer()
const = 0;
301 class Attribute :
public Base
308 return m_tiXmlPointer;
341 void GetValue(
T* value )
const 344 FromString( m_tiXmlPointer->ValueStr(), value );
362 void SetValue(
const T& value )
365 m_tiXmlPointer->
SetValue( ToString( value ) );
376 void GetName(
T* name )
const 379 FromString( m_tiXmlPointer->
Name(), name );
397 void SetName(
const T& name )
400 m_tiXmlPointer->
SetName( ToString( name ) );
407 void operator=(
const Attribute& copy );
413 Attribute(
const Attribute& copy );
423 Attribute* Next(
bool throwIfNoAttribute =
true )
const;
428 Attribute* Previous(
bool throwIfNoAttribute =
true )
const;
437 void IterateNext(
const std::string&, Attribute** next )
const;
446 void IteratePrevious(
const std::string&, Attribute** previous )
const;
451 virtual void Print( FILE* file,
int depth )
const;
468 class Node :
public Base
480 void GetValue(
T* value)
const 482 FromString( GetTiXmlPointer()->ValueStr(), value );
500 void SetValue(
const T& value )
502 GetTiXmlPointer()->SetValue( ToString( value ) );
519 Node* Parent(
bool throwIfNoParent =
true )
const;
530 Node* FirstChild(
bool throwIfNoChildren =
true )
const;
542 Node* FirstChild(
const char* value,
bool throwIfNoChildren =
true )
const;
553 Node* FirstChild(
const std::string& value,
bool throwIfNoChildren =
true )
const;
564 Node* LastChild(
bool throwIfNoChildren =
true )
const;
576 Node* LastChild(
const char* value,
bool throwIfNoChildren =
true )
const;
587 Node* LastChild(
const std::string& value,
bool throwIfNoChildren =
true )
const;
596 Node* IterateChildren( Node* previous )
const;
606 Node* IterateChildren(
const std::string& value, Node* previous )
const;
619 Node* InsertEndChild(
const Node& addThis );
631 Node* LinkEndChild( Node* childNode );
644 Node* InsertBeforeChild( Node* beforeThis,
const Node& addThis );
657 Node* InsertAfterChild( Node* afterThis,
const Node& addThis );
669 Node* ReplaceChild( Node* replaceThis,
const Node& withThis );
679 void RemoveChild( Node* removeThis );
689 Node* PreviousSibling(
bool throwIfNoSiblings =
true )
const;
700 Node* PreviousSibling(
const std::string& value,
bool throwIfNoSiblings =
true )
const;
712 Node* PreviousSibling(
const char* value,
bool throwIfNoSiblings =
true )
const;
722 Node* NextSibling(
bool throwIfNoSiblings =
true )
const;
733 Node* NextSibling(
const std::string& value,
bool throwIfNoSiblings =
true )
const;
745 Node* NextSibling(
const char* value,
bool throwIfNoSiblings =
true )
const;
755 void IterateFirst(
const std::string& value,
T** first )
const 758 for( Node* child = FirstChild( value,
false ); child; child = child->NextSibling( value,
false ) )
760 *first =
dynamic_cast< T*
>( child );
768 virtual void IterateFirst(
const std::string&, Attribute** )
const 770 TICPPTHROW(
"Attributes can only be iterated with Elements." )
781 void IterateNext(
const std::string& value,
T** next )
const 783 Node* sibling = NextSibling( value,
false );
784 *next =
dynamic_cast< T*
>( sibling );
786 while ( ( 0 != sibling ) && ( 0 == *next ) )
788 sibling = sibling->NextSibling( value,
false );
789 *next =
dynamic_cast< T*
>( sibling );
801 void IteratePrevious(
const std::string& value,
T** previous )
const 803 Node* sibling = PreviousSibling( value,
false );
804 *previous =
dynamic_cast< T*
>( sibling );
806 while ( ( 0 != sibling ) && ( 0 == *previous ) )
808 sibling = sibling->PreviousSibling( value,
false );
809 *previous =
dynamic_cast< T*
>( sibling );
821 Element* NextSiblingElement(
bool throwIfNoSiblings =
true )
const;
831 Element* NextSiblingElement(
const std::string& value,
bool throwIfNoSiblings =
true )
const;
843 Element* NextSiblingElement(
const char* value,
bool throwIfNoSiblings =
true )
const;
854 Element* FirstChildElement(
bool throwIfNoChildren =
true )
const;
866 Element* FirstChildElement(
const char* value,
bool throwIfNoChildren =
true )
const;
877 Element* FirstChildElement(
const std::string& value,
bool throwIfNoChildren =
true )
const;
891 Document* GetDocument(
bool throwIfNoDocument =
true )
const;
898 bool NoChildren()
const;
900 #ifndef TICPP_NO_RTTI 910 T* pointer =
dynamic_cast< T*
>( this );
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 ) <<
")" );
928 Document* ToDocument()
const;
935 Element* ToElement()
const;
942 Comment* ToComment()
const;
949 Text* ToText()
const;
956 Declaration* ToDeclaration()
const;
963 StylesheetReference* ToStylesheetReference()
const;
982 std::unique_ptr< Node > Clone()
const;
993 friend std::istream&
operator >>( std::istream& in, Node& base )
995 in >> *base.GetTiXmlPointer();
1002 friend std::ostream&
operator <<( std::ostream& out,
const Node& base )
1004 out << *base.GetTiXmlPointer();
1013 virtual TiXmlNode* GetTiXmlPointer()
const = 0;
1017 return GetTiXmlPointer();
1024 Node* NodeFactory(
TiXmlNode* tiXmlNode,
bool throwIfNull =
true,
bool rememberSpawnedWrapper =
true )
const;
1054 template <
class T = Node >
1072 T* begin(
const Node* parent )
const 1075 parent->IterateFirst( m_value, &pointer );
1101 : m_p( 0 ), m_value( value )
1107 : m_p( node ), m_value( value )
1112 Iterator(
const Iterator& it )
1113 : m_p( it.m_p ), m_value( it.m_value )
1127 Iterator& operator=(
const Iterator& it )
1130 m_value = it.m_value;
1135 Iterator& operator=(
T* p )
1142 Iterator& operator++()
1144 m_p->IterateNext( m_value, &m_p );
1149 Iterator operator++(
int)
1151 Iterator tmp(*
this);
1157 Iterator& operator--()
1159 m_p->IteratePrevious( m_value, &m_p );
1164 Iterator operator--(
int)
1166 Iterator tmp(*
this);
1178 if ( 0 == m_p || 0 == p )
1198 if ( 0 == m_p || 0 == p )
1212 T* operator->()
const 1218 T& operator*()
const 1225 template <
class T >
1226 class NodeImp :
public Node
1242 return m_tiXmlPointer;
1253 void SetTiXmlPointer(
T* newPointer )
1255 m_tiXmlPointer = newPointer;
1256 SetImpRC( newPointer );
1263 NodeImp(
T* tiXmlPointer )
1266 if ( 0 == tiXmlPointer )
1268 #ifdef TICPP_NO_RTTI 1269 TICPPTHROW(
"Can not create TinyXML objext" );
1271 TICPPTHROW(
"Can not create a " <<
typeid(
T ).name() );
1274 SetTiXmlPointer( tiXmlPointer );
1283 virtual void operator=(
const NodeImp<T>& copy )
1286 this->m_impRC->DecRef();
1289 SetTiXmlPointer( copy.m_tiXmlPointer );
1292 this->m_impRC->IncRef();
1300 NodeImp(
const NodeImp<T>& copy ) : Node( copy )
1303 SetTiXmlPointer( copy.m_tiXmlPointer );
1306 this->m_impRC->IncRef();
1322 class Comment :
public NodeImp< TiXmlComment >
1343 class Text :
public NodeImp< TiXmlText >
1373 template <
class T >
1374 Text(
const T& value )
1382 class Document :
public NodeImp< TiXmlDocument >
1399 Document(
const char* documentName );
1424 void SaveFile()
const;
1447 void SaveFile(
const std::string& filename )
const;
1461 class Element :
public NodeImp< TiXmlElement >
1479 Element(
const char* value );
1491 template <
class T >
1505 Attribute* FirstAttribute(
bool throwIfNoAttributes =
true )
const;
1513 Attribute* LastAttribute(
bool throwIfNoAttributes =
true )
const;
1522 void IterateFirst(
const std::string&, Attribute** first )
const 1525 for( Attribute* child = FirstAttribute(
false ); child; child = child->Next(
false ) )
1527 *first =
dynamic_cast< Attribute*
>( child );
1542 template <
class T >
1543 void SetAttribute (
const std::string& name,
const T& value )
1546 m_tiXmlPointer->SetAttribute( name, ToString( value ) );
1561 std::string GetText(
bool throwIfNotFound =
true )
const 1565 if ( !GetTextImp( &temp ) )
1567 if ( throwIfNotFound )
1569 TICPPTHROW(
"Text does not exists in the current element" );
1591 if ( !GetTextImp( &temp ) )
1613 template <
class T,
class DefaultT >
1614 void GetTextOrDefault(
T* value,
const DefaultT& defaultValue )
const 1618 if ( !GetTextImp( &temp ) )
1626 FromString( temp, value );
1645 void GetText(
T* value,
bool throwIfNotFound =
true )
const 1649 if ( !GetTextImp( &temp ) )
1651 if ( throwIfNotFound )
1653 TICPPTHROW(
"Text does not exists in the current element" );
1662 FromString( temp, value );
1672 template <
class T >
1673 void SetText(
const T& value )
1678 if ( m_tiXmlPointer->NoChildren() )
1680 m_tiXmlPointer->LinkEndChild(
new TiXmlText( temp ) );
1684 if ( 0 == m_tiXmlPointer->GetText() )
1686 m_tiXmlPointer->InsertBeforeChild( m_tiXmlPointer->FirstChild(),
TiXmlText( temp ) );
1691 m_tiXmlPointer->FirstChild()->SetValue( temp );
1707 template <
class T,
class DefaulT >
1708 void GetAttributeOrDefault(
const std::string& name,
T* value,
const DefaulT& defaultValue )
const 1712 if ( !GetAttributeImp( name, &temp ) )
1720 FromString( temp, value );
1742 template <
class T >
1743 T GetAttribute(
const std::string& name,
bool throwIfNotFound =
true )
const 1748 if ( !GetAttributeImp( name, &temp ) )
1750 if ( throwIfNotFound )
1753 TICPPTHROW(
error );
1759 FromString( temp, &value );
1777 void GetAttribute(
const std::string& name,
T* value,
bool throwIfNotFound =
true )
const 1781 if ( !GetAttributeImp( name, &temp ) )
1783 if ( throwIfNotFound )
1786 TICPPTHROW(
error );
1795 FromString( temp, value );
1815 bool HasAttribute(
const std::string& name )
const;
1840 class Declaration :
public NodeImp< TiXmlDeclaration >
1875 class StylesheetReference :
public NodeImp< TiXmlStylesheetReference >
1881 StylesheetReference();
1905 #endif // TICPP_INCLUDED 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
const char * Value() const
The meaning of 'value' 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
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