Skip to content

Commit dd1b5f9

Browse files
committed
Updated tinyxml
1 parent 94187c4 commit dd1b5f9

File tree

2 files changed

+72
-21
lines changed

2 files changed

+72
-21
lines changed

externals/tinyxml/tinyxml2.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ XMLNode::~XMLNode()
595595
}
596596
}
597597

598+
const char* XMLNode::Value() const
599+
{
600+
return _value.GetStr();
601+
}
598602

599603
void XMLNode::SetValue( const char* str, bool staticMem )
600604
{
@@ -621,7 +625,6 @@ void XMLNode::DeleteChildren()
621625

622626
void XMLNode::Unlink( XMLNode* child )
623627
{
624-
TIXMLASSERT( child->_parent == this );
625628
if ( child == _firstChild ) {
626629
_firstChild = _firstChild->_next;
627630
}
@@ -635,7 +638,7 @@ void XMLNode::Unlink( XMLNode* child )
635638
if ( child->_next ) {
636639
child->_next->_prev = child->_prev;
637640
}
638-
child->_parent = 0;
641+
child->_parent = 0;
639642
}
640643

641644

@@ -648,6 +651,14 @@ void XMLNode::DeleteChild( XMLNode* node )
648651

649652
XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
650653
{
654+
if (addThis->_document != _document)
655+
return 0;
656+
657+
if (addThis->_parent)
658+
addThis->_parent->Unlink( addThis );
659+
else
660+
addThis->_memPool->SetTracked();
661+
651662
if ( _lastChild ) {
652663
TIXMLASSERT( _firstChild );
653664
TIXMLASSERT( _lastChild->_next == 0 );
@@ -665,13 +676,20 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
665676
addThis->_next = 0;
666677
}
667678
addThis->_parent = this;
668-
addThis->_memPool->SetTracked();
669679
return addThis;
670680
}
671681

672682

673683
XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
674684
{
685+
if (addThis->_document != _document)
686+
return 0;
687+
688+
if (addThis->_parent)
689+
addThis->_parent->Unlink( addThis );
690+
else
691+
addThis->_memPool->SetTracked();
692+
675693
if ( _firstChild ) {
676694
TIXMLASSERT( _lastChild );
677695
TIXMLASSERT( _firstChild->_prev == 0 );
@@ -690,14 +708,17 @@ XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
690708
addThis->_next = 0;
691709
}
692710
addThis->_parent = this;
693-
addThis->_memPool->SetTracked();
694-
return addThis;
711+
return addThis;
695712
}
696713

697714

698715
XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
699716
{
717+
if (addThis->_document != _document)
718+
return 0;
719+
700720
TIXMLASSERT( afterThis->_parent == this );
721+
701722
if ( afterThis->_parent != this ) {
702723
return 0;
703724
}
@@ -706,12 +727,15 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
706727
// The last node or the only node.
707728
return InsertEndChild( addThis );
708729
}
730+
if (addThis->_parent)
731+
addThis->_parent->Unlink( addThis );
732+
else
733+
addThis->_memPool->SetTracked();
709734
addThis->_prev = afterThis;
710735
addThis->_next = afterThis->_next;
711736
afterThis->_next->_prev = addThis;
712737
afterThis->_next = addThis;
713738
addThis->_parent = this;
714-
addThis->_memPool->SetTracked();
715739
return addThis;
716740
}
717741

@@ -1040,6 +1064,17 @@ bool XMLUnknown::Accept( XMLVisitor* visitor ) const
10401064
}
10411065

10421066
// --------- XMLAttribute ---------- //
1067+
1068+
const char* XMLAttribute::Name() const
1069+
{
1070+
return _name.GetStr();
1071+
}
1072+
1073+
const char* XMLAttribute::Value() const
1074+
{
1075+
return _value.GetStr();
1076+
}
1077+
10431078
char* XMLAttribute::ParseDeep( char* p, bool processEntities )
10441079
{
10451080
// Parse using the name rules: bug fix, was using ParseText before

externals/tinyxml/tinyxml2.h

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
118118

119119
static const int TIXML2_MAJOR_VERSION = 1;
120120
static const int TIXML2_MINOR_VERSION = 0;
121-
static const int TIXML2_PATCH_VERSION = 11;
121+
static const int TIXML2_PATCH_VERSION = 12;
122122

123123
namespace tinyxml2
124124
{
@@ -251,6 +251,11 @@ class DynArray
251251
return _mem[i];
252252
}
253253

254+
const T& PeekTop() const {
255+
TIXMLASSERT( _size > 0 );
256+
return _mem[ _size - 1];
257+
}
258+
254259
int Size() const {
255260
return _size;
256261
}
@@ -638,9 +643,7 @@ class TINYXML2_LIB XMLNode
638643
Text: the text string
639644
@endverbatim
640645
*/
641-
const char* Value() const {
642-
return _value.GetStr();
643-
}
646+
const char* Value() const;
644647

645648
/** Set the Value of an XML node.
646649
@sa Value()
@@ -731,6 +734,10 @@ class TINYXML2_LIB XMLNode
731734

732735
/**
733736
Add a child node as the last (right) child.
737+
If the child node is already part of the document,
738+
it is moved from its old location to the new location.
739+
Returns the addThis argument or 0 if the node does not
740+
belong to the same document.
734741
*/
735742
XMLNode* InsertEndChild( XMLNode* addThis );
736743

@@ -739,10 +746,19 @@ class TINYXML2_LIB XMLNode
739746
}
740747
/**
741748
Add a child node as the first (left) child.
749+
If the child node is already part of the document,
750+
it is moved from its old location to the new location.
751+
Returns the addThis argument or 0 if the node does not
752+
belong to the same document.
742753
*/
743754
XMLNode* InsertFirstChild( XMLNode* addThis );
744755
/**
745756
Add a node after the specified child node.
757+
If the child node is already part of the document,
758+
it is moved from its old location to the new location.
759+
Returns the addThis argument or 0 if the afterThis node
760+
is not a child of this node, or if the node does not
761+
belong to the same document.
746762
*/
747763
XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
748764

@@ -1009,13 +1025,11 @@ class TINYXML2_LIB XMLAttribute
10091025
friend class XMLElement;
10101026
public:
10111027
/// The name of the attribute.
1012-
const char* Name() const {
1013-
return _name.GetStr();
1014-
}
1028+
const char* Name() const;
1029+
10151030
/// The value of the attribute.
1016-
const char* Value() const {
1017-
return _value.GetStr();
1018-
}
1031+
const char* Value() const;
1032+
10191033
/// The next attribute in the list.
10201034
const XMLAttribute* Next() const {
10211035
return _next;
@@ -1884,7 +1898,7 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor
18841898
with only required whitespace and newlines.
18851899
*/
18861900
XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
1887-
~XMLPrinter() {}
1901+
virtual ~XMLPrinter() {}
18881902

18891903
/** If streaming, write the BOM and declaration. */
18901904
void PushHeader( bool writeBOM, bool writeDeclaration );
@@ -1899,7 +1913,7 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor
18991913
void PushAttribute( const char* name, bool value );
19001914
void PushAttribute( const char* name, double value );
19011915
/// If streaming, close the Element.
1902-
void CloseElement();
1916+
virtual void CloseElement();
19031917

19041918
/// Add a text node.
19051919
void PushText( const char* text, bool cdata=false );
@@ -1949,13 +1963,16 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor
19491963
return _buffer.Size();
19501964
}
19511965

1952-
private:
1966+
protected:
19531967
void SealElement();
1968+
bool _elementJustOpened;
1969+
DynArray< const char*, 10 > _stack;
1970+
1971+
private:
19541972
void PrintSpace( int depth );
19551973
void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
19561974
void Print( const char* format, ... );
19571975

1958-
bool _elementJustOpened;
19591976
bool _firstElement;
19601977
FILE* _fp;
19611978
int _depth;
@@ -1970,7 +1987,6 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor
19701987
bool _entityFlag[ENTITY_RANGE];
19711988
bool _restrictedEntityFlag[ENTITY_RANGE];
19721989

1973-
DynArray< const char*, 10 > _stack;
19741990
DynArray< char, 20 > _buffer;
19751991
#ifdef _MSC_VER
19761992
DynArray< char, 20 > _accumulator;

0 commit comments

Comments
 (0)