From 9bdeea56424d800007cc28fba85b503ed9512f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 19 Sep 2014 18:50:52 +0200 Subject: [PATCH] tinyxml: update to latest git version 5321a0e (v2.2.0) (https://github.com/leethomason/tinyxml2) --- externals/tinyxml/tinyxml2.cpp | 123 +++++++++++++++++++++------------ externals/tinyxml/tinyxml2.h | 85 ++++++++++++----------- 2 files changed, 124 insertions(+), 84 deletions(-) diff --git a/externals/tinyxml/tinyxml2.cpp b/externals/tinyxml/tinyxml2.cpp index df345f974..53d78bd2f 100644 --- a/externals/tinyxml/tinyxml2.cpp +++ b/externals/tinyxml/tinyxml2.cpp @@ -45,22 +45,6 @@ static const unsigned char TIXML_UTF_LEAD_0 = 0xefU; static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; - -#define DELETE_NODE( node ) { \ - if ( node ) { \ - MemPool* pool = node->_memPool; \ - node->~XMLNode(); \ - pool->Free( node ); \ - } \ - } -#define DELETE_ATTRIBUTE( attrib ) { \ - if ( attrib ) { \ - MemPool* pool = attrib->_memPool; \ - attrib->~XMLAttribute(); \ - pool->Free( attrib ); \ - } \ - } - namespace tinyxml2 { @@ -618,7 +602,7 @@ void XMLNode::DeleteChildren() XMLNode* node = _firstChild; Unlink( node ); - DELETE_NODE( node ); + DeleteNode( node ); } _firstChild = _lastChild = 0; } @@ -646,7 +630,7 @@ void XMLNode::Unlink( XMLNode* child ) void XMLNode::DeleteChild( XMLNode* node ) { TIXMLASSERT( node->_parent == this ); - DELETE_NODE( node ); + DeleteNode( node ); } @@ -773,10 +757,11 @@ const XMLElement* XMLNode::LastChildElement( const char* value ) const const XMLElement* XMLNode::NextSiblingElement( const char* value ) const { - for( XMLNode* element=this->_next; element; element = element->_next ) { - if ( element->ToElement() - && (!value || XMLUtil::StringEqual( value, element->Value() ))) { - return element->ToElement(); + for( XMLNode* node=this->_next; node; node = node->_next ) { + const XMLElement* element = node->ToElement(); + if ( element + && (!value || XMLUtil::StringEqual( value, node->Value() ))) { + return element; } } return 0; @@ -785,10 +770,11 @@ const XMLElement* XMLNode::NextSiblingElement( const char* value ) const const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const { - for( XMLNode* element=_prev; element; element = element->_prev ) { - if ( element->ToElement() - && (!value || XMLUtil::StringEqual( value, element->Value() ))) { - return element->ToElement(); + for( XMLNode* node=_prev; node; node = node->_prev ) { + const XMLElement* element = node->ToElement(); + if ( element + && (!value || XMLUtil::StringEqual( value, node->Value() ))) { + return element; } } return 0; @@ -825,7 +811,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) StrPair endTag; p = node->ParseDeep( p, &endTag ); if ( !p ) { - DELETE_NODE( node ); + DeleteNode( node ); node = 0; if ( !_document->Error() ) { _document->SetError( XML_ERROR_PARSING, 0, 0 ); @@ -833,19 +819,19 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) break; } + XMLElement* ele = node->ToElement(); // We read the end tag. Return it to the parent. - if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) { + if ( ele && ele->ClosingType() == XMLElement::CLOSING ) { if ( parentEnd ) { *parentEnd = static_cast(node)->_value; } node->_memPool->SetTracked(); // created and then immediately deleted. - DELETE_NODE( node ); + DeleteNode( node ); return p; } // Handle an end tag returned to this level. // And handle a bunch of annoying errors. - XMLElement* ele = node->ToElement(); if ( ele ) { if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) { _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); @@ -863,7 +849,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) } } if ( p == 0 ) { - DELETE_NODE( node ); + DeleteNode( node ); node = 0; } if ( node ) { @@ -873,6 +859,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) return 0; } +void XMLNode::DeleteNode( XMLNode* node ) +{ + if ( node == 0 ) { + return; + } + MemPool* pool = node->_memPool; + node->~XMLNode(); + pool->Free( node ); +} + // --------- XMLText ---------- // char* XMLText::ParseDeep( char* p, StrPair* ) { @@ -961,7 +957,8 @@ XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const bool XMLComment::ShallowEqual( const XMLNode* compare ) const { - return ( compare->ToComment() && XMLUtil::StringEqual( compare->ToComment()->Value(), Value() )); + const XMLComment* comment = compare->ToComment(); + return ( comment && XMLUtil::StringEqual( comment->Value(), Value() )); } @@ -1008,7 +1005,8 @@ XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const { - return ( compare->ToDeclaration() && XMLUtil::StringEqual( compare->ToDeclaration()->Value(), Value() )); + const XMLDeclaration* declaration = compare->ToDeclaration(); + return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() )); } @@ -1055,7 +1053,8 @@ XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const { - return ( compare->ToUnknown() && XMLUtil::StringEqual( compare->ToUnknown()->Value(), Value() )); + const XMLUnknown* unknown = compare->ToUnknown(); + return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() )); } @@ -1211,7 +1210,7 @@ XMLElement::~XMLElement() { while( _rootAttribute ) { XMLAttribute* next = _rootAttribute->_next; - DELETE_ATTRIBUTE( _rootAttribute ); + DeleteAttribute( _rootAttribute ); _rootAttribute = next; } } @@ -1219,8 +1218,7 @@ XMLElement::~XMLElement() XMLAttribute* XMLElement::FindAttribute( const char* name ) { - XMLAttribute* a = 0; - for( a=_rootAttribute; a; a = a->_next ) { + for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) { if ( XMLUtil::StringEqual( a->Name(), name ) ) { return a; } @@ -1231,8 +1229,7 @@ XMLAttribute* XMLElement::FindAttribute( const char* name ) const XMLAttribute* XMLElement::FindAttribute( const char* name ) const { - XMLAttribute* a = 0; - for( a=_rootAttribute; a; a = a->_next ) { + for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) { if ( XMLUtil::StringEqual( a->Name(), name ) ) { return a; } @@ -1418,7 +1415,7 @@ void XMLElement::DeleteAttribute( const char* name ) else { _rootAttribute = a->_next; } - DELETE_ATTRIBUTE( a ); + DeleteAttribute( a ); break; } prev = a; @@ -1447,7 +1444,7 @@ char* XMLElement::ParseAttributes( char* p ) p = attrib->ParseDeep( p, _document->ProcessEntities() ); if ( !p || Attribute( attrib->Name() ) ) { - DELETE_ATTRIBUTE( attrib ); + DeleteAttribute( attrib ); _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p ); return 0; } @@ -1482,6 +1479,15 @@ char* XMLElement::ParseAttributes( char* p ) return p; } +void XMLElement::DeleteAttribute( XMLAttribute* attribute ) +{ + if ( attribute == 0 ) { + return; + } + MemPool* pool = attribute->_memPool; + attribute->~XMLAttribute(); + pool->Free( attribute ); +} // // @@ -1571,6 +1577,32 @@ bool XMLElement::Accept( XMLVisitor* visitor ) const // --------- XMLDocument ----------- // + +// Warning: List must match 'enum XMLError' +const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { + "XML_SUCCESS", + "XML_NO_ATTRIBUTE", + "XML_WRONG_ATTRIBUTE_TYPE", + "XML_ERROR_FILE_NOT_FOUND", + "XML_ERROR_FILE_COULD_NOT_BE_OPENED", + "XML_ERROR_FILE_READ_ERROR", + "XML_ERROR_ELEMENT_MISMATCH", + "XML_ERROR_PARSING_ELEMENT", + "XML_ERROR_PARSING_ATTRIBUTE", + "XML_ERROR_IDENTIFYING_TAG", + "XML_ERROR_PARSING_TEXT", + "XML_ERROR_PARSING_CDATA", + "XML_ERROR_PARSING_COMMENT", + "XML_ERROR_PARSING_DECLARATION", + "XML_ERROR_PARSING_UNKNOWN", + "XML_ERROR_EMPTY_DOCUMENT", + "XML_ERROR_MISMATCHED_ELEMENT", + "XML_ERROR_PARSING", + "XML_CAN_NOT_CONVERT_TEXT", + "XML_NO_TEXT_NODE" +}; + + XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) : XMLNode( 0 ), _writeBOM( false ), @@ -1806,6 +1838,11 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 ) _errorStr2 = str2; } +const char* XMLDocument::ErrorName() const +{ + TIXMLASSERT(_errorID >= 0 && _errorID < XML_ERROR_COUNT ); + return _errorNames[_errorID]; +} void XMLDocument::PrintError() const { @@ -1821,8 +1858,8 @@ void XMLDocument::PrintError() const TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 ); } - printf( "XMLDocument error id=%d str1=%s str2=%s\n", - _errorID, buf1, buf2 ); + printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n", + _errorID, ErrorName(), buf1, buf2 ); } } diff --git a/externals/tinyxml/tinyxml2.h b/externals/tinyxml/tinyxml2.h index f4503fd5b..1fdc928b0 100644 --- a/externals/tinyxml/tinyxml2.h +++ b/externals/tinyxml/tinyxml2.h @@ -122,9 +122,9 @@ inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) /* Versioning, past 1.0.14: http://semver.org/ */ -static const int TIXML2_MAJOR_VERSION = 2; -static const int TIXML2_MINOR_VERSION = 1; -static const int TIXML2_PATCH_VERSION = 0; +static const int TIXML2_MAJOR_VERSION = 2; +static const int TIXML2_MINOR_VERSION = 2; +static const int TIXML2_PATCH_VERSION = 0; namespace tinyxml2 { @@ -480,6 +480,33 @@ public: } }; +// WARNING: must match XMLErrorNames[] +enum XMLError { + XML_SUCCESS = 0, + XML_NO_ERROR = 0, + XML_NO_ATTRIBUTE, + XML_WRONG_ATTRIBUTE_TYPE, + XML_ERROR_FILE_NOT_FOUND, + XML_ERROR_FILE_COULD_NOT_BE_OPENED, + XML_ERROR_FILE_READ_ERROR, + XML_ERROR_ELEMENT_MISMATCH, + XML_ERROR_PARSING_ELEMENT, + XML_ERROR_PARSING_ATTRIBUTE, + XML_ERROR_IDENTIFYING_TAG, + XML_ERROR_PARSING_TEXT, + XML_ERROR_PARSING_CDATA, + XML_ERROR_PARSING_COMMENT, + XML_ERROR_PARSING_DECLARATION, + XML_ERROR_PARSING_UNKNOWN, + XML_ERROR_EMPTY_DOCUMENT, + XML_ERROR_MISMATCHED_ELEMENT, + XML_ERROR_PARSING, + XML_CAN_NOT_CONVERT_TEXT, + XML_NO_TEXT_NODE, + + XML_ERROR_COUNT +}; + /* Utility functionality. @@ -847,6 +874,7 @@ protected: private: MemPool* _memPool; void Unlink( XMLNode* child ); + static void DeleteNode( XMLNode* node ); }; @@ -996,33 +1024,6 @@ protected: }; -enum XMLError { - XML_NO_ERROR = 0, - XML_SUCCESS = 0, - - XML_NO_ATTRIBUTE, - XML_WRONG_ATTRIBUTE_TYPE, - - XML_ERROR_FILE_NOT_FOUND, - XML_ERROR_FILE_COULD_NOT_BE_OPENED, - XML_ERROR_FILE_READ_ERROR, - XML_ERROR_ELEMENT_MISMATCH, - XML_ERROR_PARSING_ELEMENT, - XML_ERROR_PARSING_ATTRIBUTE, - XML_ERROR_IDENTIFYING_TAG, - XML_ERROR_PARSING_TEXT, - XML_ERROR_PARSING_CDATA, - XML_ERROR_PARSING_COMMENT, - XML_ERROR_PARSING_DECLARATION, - XML_ERROR_PARSING_UNKNOWN, - XML_ERROR_EMPTY_DOCUMENT, - XML_ERROR_MISMATCHED_ELEMENT, - XML_ERROR_PARSING, - - XML_CAN_NOT_CONVERT_TEXT, - XML_NO_TEXT_NODE -}; - /** An attribute is a name-value pair. Elements have an arbitrary number of attributes, each with a unique name. @@ -1480,6 +1481,7 @@ private: XMLAttribute* FindOrCreateAttribute( const char* name ); //void LinkAttribute( XMLAttribute* attrib ); char* ParseAttributes( char* p ); + static void DeleteAttribute( XMLAttribute* attribute ); enum { BUF_SIZE = 200 }; int _closingType; @@ -1661,6 +1663,8 @@ public: XMLError ErrorID() const { return _errorID; } + const char* ErrorName() const; + /// Return a possibly helpful diagnostic location or string. const char* GetErrorStr1() const { return _errorStr1; @@ -1701,6 +1705,8 @@ private: MemPoolT< sizeof(XMLAttribute) > _attributePool; MemPoolT< sizeof(XMLText) > _textPool; MemPoolT< sizeof(XMLComment) > _commentPool; + + static const char* _errorNames[XML_ERROR_COUNT]; }; @@ -1819,19 +1825,19 @@ public: } /// Safe cast to XMLElement. This can return null. XMLElement* ToElement() { - return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToElement() ); } /// Safe cast to XMLText. This can return null. XMLText* ToText() { - return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToText() ); } /// Safe cast to XMLUnknown. This can return null. XMLUnknown* ToUnknown() { - return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToUnknown() ); } /// Safe cast to XMLDeclaration. This can return null. XMLDeclaration* ToDeclaration() { - return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() ); } private: @@ -1891,16 +1897,16 @@ public: return _node; } const XMLElement* ToElement() const { - return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToElement() ); } const XMLText* ToText() const { - return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToText() ); } const XMLUnknown* ToUnknown() const { - return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToUnknown() ); } const XMLDeclaration* ToDeclaration() const { - return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); + return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() ); } private: @@ -2064,9 +2070,6 @@ private: bool _restrictedEntityFlag[ENTITY_RANGE]; DynArray< char, 20 > _buffer; -#ifdef _MSC_VER - DynArray< char, 20 > _accumulator; -#endif };