diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 8263796..b710b40 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -50,14 +50,14 @@ static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; #define DELETE_NODE( node ) { \ if ( node ) { \ - MemPool* pool = node->memPool; \ + MemPool* pool = node->_memPool; \ node->~XMLNode(); \ pool->Free( node ); \ } \ } #define DELETE_ATTRIBUTE( attrib ) { \ if ( attrib ) { \ - MemPool* pool = attrib->memPool; \ + MemPool* pool = attrib->_memPool; \ attrib->~XMLAttribute(); \ pool->Free( attrib ); \ } \ @@ -527,35 +527,35 @@ char* XMLDocument::Identify( char* p, XMLNode** node ) #pragma warning (pop) #endif if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { - returnNode = new (commentPool.Alloc()) XMLDeclaration( this ); - returnNode->memPool = &commentPool; + returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); + returnNode->_memPool = &_commentPool; p += xmlHeaderLen; } else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { - returnNode = new (commentPool.Alloc()) XMLComment( this ); - returnNode->memPool = &commentPool; + returnNode = new (_commentPool.Alloc()) XMLComment( this ); + returnNode->_memPool = &_commentPool; p += commentHeaderLen; } else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { - XMLText* text = new (textPool.Alloc()) XMLText( this ); + XMLText* text = new (_textPool.Alloc()) XMLText( this ); returnNode = text; - returnNode->memPool = &textPool; + returnNode->_memPool = &_textPool; p += cdataHeaderLen; text->SetCData( true ); } else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { - returnNode = new (commentPool.Alloc()) XMLUnknown( this ); - returnNode->memPool = &commentPool; + returnNode = new (_commentPool.Alloc()) XMLUnknown( this ); + returnNode->_memPool = &_commentPool; p += dtdHeaderLen; } else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { - returnNode = new (elementPool.Alloc()) XMLElement( this ); - returnNode->memPool = &elementPool; + returnNode = new (_elementPool.Alloc()) XMLElement( this ); + returnNode->_memPool = &_elementPool; p += elementHeaderLen; } else { - returnNode = new (textPool.Alloc()) XMLText( this ); - returnNode->memPool = &textPool; + returnNode = new (_textPool.Alloc()) XMLText( this ); + returnNode->_memPool = &_textPool; p = start; // Back it up, all the text counts. } @@ -580,10 +580,10 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const // --------- XMLNode ----------- // XMLNode::XMLNode( XMLDocument* doc ) : - document( doc ), - parent( 0 ), - firstChild( 0 ), lastChild( 0 ), - prev( 0 ), next( 0 ) + _document( doc ), + _parent( 0 ), + _firstChild( 0 ), _lastChild( 0 ), + _prev( 0 ), _next( 0 ) { } @@ -591,8 +591,8 @@ XMLNode::XMLNode( XMLDocument* doc ) : XMLNode::~XMLNode() { DeleteChildren(); - if ( parent ) { - parent->Unlink( this ); + if ( _parent ) { + _parent->Unlink( this ); } } @@ -600,116 +600,116 @@ XMLNode::~XMLNode() void XMLNode::SetValue( const char* str, bool staticMem ) { if ( staticMem ) { - value.SetInternedStr( str ); + _value.SetInternedStr( str ); } else { - value.SetStr( str ); + _value.SetStr( str ); } } void XMLNode::DeleteChildren() { - while( firstChild ) { - XMLNode* node = firstChild; + while( _firstChild ) { + XMLNode* node = _firstChild; Unlink( node ); DELETE_NODE( node ); } - firstChild = lastChild = 0; + _firstChild = _lastChild = 0; } void XMLNode::Unlink( XMLNode* child ) { - TIXMLASSERT( child->parent == this ); - if ( child == firstChild ) { - firstChild = firstChild->next; + TIXMLASSERT( child->_parent == this ); + if ( child == _firstChild ) { + _firstChild = _firstChild->_next; } - if ( child == lastChild ) { - lastChild = lastChild->prev; + if ( child == _lastChild ) { + _lastChild = _lastChild->_prev; } - if ( child->prev ) { - child->prev->next = child->next; + if ( child->_prev ) { + child->_prev->_next = child->_next; } - if ( child->next ) { - child->next->prev = child->prev; + if ( child->_next ) { + child->_next->_prev = child->_prev; } - child->parent = 0; + child->_parent = 0; } void XMLNode::DeleteChild( XMLNode* node ) { - TIXMLASSERT( node->parent == this ); + TIXMLASSERT( node->_parent == this ); DELETE_NODE( node ); } XMLNode* XMLNode::InsertEndChild( XMLNode* addThis ) { - if ( lastChild ) { - TIXMLASSERT( firstChild ); - TIXMLASSERT( lastChild->next == 0 ); - lastChild->next = addThis; - addThis->prev = lastChild; - lastChild = addThis; + if ( _lastChild ) { + TIXMLASSERT( _firstChild ); + TIXMLASSERT( _lastChild->_next == 0 ); + _lastChild->_next = addThis; + addThis->_prev = _lastChild; + _lastChild = addThis; - addThis->next = 0; + addThis->_next = 0; } else { - TIXMLASSERT( firstChild == 0 ); - firstChild = lastChild = addThis; + TIXMLASSERT( _firstChild == 0 ); + _firstChild = _lastChild = addThis; - addThis->prev = 0; - addThis->next = 0; + addThis->_prev = 0; + addThis->_next = 0; } - addThis->parent = this; + addThis->_parent = this; return addThis; } XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis ) { - if ( firstChild ) { - TIXMLASSERT( lastChild ); - TIXMLASSERT( firstChild->prev == 0 ); + if ( _firstChild ) { + TIXMLASSERT( _lastChild ); + TIXMLASSERT( _firstChild->_prev == 0 ); - firstChild->prev = addThis; - addThis->next = firstChild; - firstChild = addThis; + _firstChild->_prev = addThis; + addThis->_next = _firstChild; + _firstChild = addThis; - addThis->prev = 0; + addThis->_prev = 0; } else { - TIXMLASSERT( lastChild == 0 ); - firstChild = lastChild = addThis; + TIXMLASSERT( _lastChild == 0 ); + _firstChild = _lastChild = addThis; - addThis->prev = 0; - addThis->next = 0; + addThis->_prev = 0; + addThis->_next = 0; } - addThis->parent = this; + addThis->_parent = this; return addThis; } XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) { - TIXMLASSERT( afterThis->parent == this ); - if ( afterThis->parent != this ) { + TIXMLASSERT( afterThis->_parent == this ); + if ( afterThis->_parent != this ) { return 0; } - if ( afterThis->next == 0 ) { + if ( afterThis->_next == 0 ) { // The last node or the only node. return InsertEndChild( addThis ); } - addThis->prev = afterThis; - addThis->next = afterThis->next; - afterThis->next->prev = addThis; - afterThis->next = addThis; - addThis->parent = this; + addThis->_prev = afterThis; + addThis->_next = afterThis->_next; + afterThis->_next->_prev = addThis; + afterThis->_next = addThis; + addThis->_parent = this; return addThis; } @@ -718,7 +718,7 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) const XMLElement* XMLNode::FirstChildElement( const char* value ) const { - for( XMLNode* node=firstChild; node; node=node->next ) { + for( XMLNode* node=_firstChild; node; node=node->_next ) { XMLElement* element = node->ToElement(); if ( element ) { if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) { @@ -732,7 +732,7 @@ const XMLElement* XMLNode::FirstChildElement( const char* value ) const const XMLElement* XMLNode::LastChildElement( const char* value ) const { - for( XMLNode* node=lastChild; node; node=node->prev ) { + for( XMLNode* node=_lastChild; node; node=node->_prev ) { XMLElement* element = node->ToElement(); if ( element ) { if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) { @@ -746,7 +746,7 @@ 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 ) { + for( XMLNode* element=this->_next; element; element = element->_next ) { if ( element->ToElement() && (!value || XMLUtil::StringEqual( value, element->Value() ))) { return element->ToElement(); @@ -758,7 +758,7 @@ const XMLElement* XMLNode::NextSiblingElement( const char* value ) const const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const { - for( XMLNode* element=this->prev; element; element = element->prev ) { + for( XMLNode* element=_prev; element; element = element->_prev ) { if ( element->ToElement() && (!value || XMLUtil::StringEqual( value, element->Value() ))) { return element->ToElement(); @@ -790,7 +790,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) while( p && *p ) { XMLNode* node = 0; - p = document->Identify( p, &node ); + p = _document->Identify( p, &node ); if ( p == 0 || node == 0 ) { break; } @@ -800,8 +800,8 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) if ( !p ) { DELETE_NODE( node ); node = 0; - if ( !document->Error() ) { - document->SetError( XML_ERROR_PARSING, 0, 0 ); + if ( !_document->Error() ) { + _document->SetError( XML_ERROR_PARSING, 0, 0 ); } break; } @@ -809,7 +809,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) // We read the end tag. Return it to the parent. if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) { if ( parentEnd ) { - *parentEnd = static_cast(node)->value; + *parentEnd = static_cast(node)->_value; } DELETE_NODE( node ); return p; @@ -820,16 +820,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) XMLElement* ele = node->ToElement(); if ( ele ) { if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) { - document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); p = 0; } else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) { - document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); p = 0; } else if ( !endTag.Empty() ) { if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) { - document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); p = 0; } } @@ -850,21 +850,21 @@ char* XMLText::ParseDeep( char* p, StrPair* ) { const char* start = p; if ( this->CData() ) { - p = value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); + p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); if ( !p ) { - document->SetError( XML_ERROR_PARSING_CDATA, start, 0 ); + _document->SetError( XML_ERROR_PARSING_CDATA, start, 0 ); } return p; } else { - int flags = document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES; - if ( document->WhitespaceMode() == COLLAPSE_WHITESPACE ) { + int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES; + if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) { flags |= StrPair::COLLAPSE_WHITESPACE; } - p = value.ParseText( p, "<", flags ); + p = _value.ParseText( p, "<", flags ); if ( !p ) { - document->SetError( XML_ERROR_PARSING_TEXT, start, 0 ); + _document->SetError( XML_ERROR_PARSING_TEXT, start, 0 ); } if ( p && *p ) { return p-1; @@ -877,7 +877,7 @@ char* XMLText::ParseDeep( char* p, StrPair* ) XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { - doc = document; + doc = _document; } XMLText* text = doc->NewText( Value() ); // fixme: this will always allocate memory. Intern? text->SetCData( this->CData() ); @@ -906,7 +906,6 @@ XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc ) XMLComment::~XMLComment() { - //printf( "~XMLComment\n" ); } @@ -914,9 +913,9 @@ char* XMLComment::ParseDeep( char* p, StrPair* ) { // Comment parses as text. const char* start = p; - p = value.ParseText( p, "-->", StrPair::COMMENT ); + p = _value.ParseText( p, "-->", StrPair::COMMENT ); if ( p == 0 ) { - document->SetError( XML_ERROR_PARSING_COMMENT, start, 0 ); + _document->SetError( XML_ERROR_PARSING_COMMENT, start, 0 ); } return p; } @@ -925,7 +924,7 @@ char* XMLComment::ParseDeep( char* p, StrPair* ) XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { - doc = document; + doc = _document; } XMLComment* comment = doc->NewComment( Value() ); // fixme: this will always allocate memory. Intern? return comment; @@ -961,9 +960,9 @@ char* XMLDeclaration::ParseDeep( char* p, StrPair* ) { // Declaration parses as text. const char* start = p; - p = value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); + p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); if ( p == 0 ) { - document->SetError( XML_ERROR_PARSING_DECLARATION, start, 0 ); + _document->SetError( XML_ERROR_PARSING_DECLARATION, start, 0 ); } return p; } @@ -972,7 +971,7 @@ char* XMLDeclaration::ParseDeep( char* p, StrPair* ) XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { - doc = document; + doc = _document; } XMLDeclaration* dec = doc->NewDeclaration( Value() ); // fixme: this will always allocate memory. Intern? return dec; @@ -1008,9 +1007,9 @@ char* XMLUnknown::ParseDeep( char* p, StrPair* ) // Unknown parses as text. const char* start = p; - p = value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION ); + p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION ); if ( !p ) { - document->SetError( XML_ERROR_PARSING_UNKNOWN, start, 0 ); + _document->SetError( XML_ERROR_PARSING_UNKNOWN, start, 0 ); } return p; } @@ -1019,7 +1018,7 @@ char* XMLUnknown::ParseDeep( char* p, StrPair* ) XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { - doc = document; + doc = _document; } XMLUnknown* text = doc->NewUnknown( Value() ); // fixme: this will always allocate memory. Intern? return text; @@ -1041,7 +1040,7 @@ bool XMLUnknown::Accept( XMLVisitor* visitor ) const char* XMLAttribute::ParseDeep( char* p, bool processEntities ) { // Parse using the name rules: bug fix, was using ParseText before - p = name.ParseName( p ); + p = _name.ParseName( p ); if ( !p || !*p ) { return 0; } @@ -1061,14 +1060,14 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities ) char endTag[2] = { *p, 0 }; ++p; // move past opening quote - p = value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES ); + p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES ); return p; } void XMLAttribute::SetName( const char* n ) { - name.SetStr( n ); + _name.SetStr( n ); } @@ -1119,7 +1118,7 @@ int XMLAttribute::QueryDoubleValue( double* value ) const void XMLAttribute::SetAttribute( const char* v ) { - value.SetStr( v ); + _value.SetStr( v ); } @@ -1127,7 +1126,7 @@ void XMLAttribute::SetAttribute( int v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); - value.SetStr( buf ); + _value.SetStr( buf ); } @@ -1135,7 +1134,7 @@ void XMLAttribute::SetAttribute( unsigned v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); - value.SetStr( buf ); + _value.SetStr( buf ); } @@ -1143,38 +1142,38 @@ void XMLAttribute::SetAttribute( bool v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); - value.SetStr( buf ); + _value.SetStr( buf ); } void XMLAttribute::SetAttribute( double v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); - value.SetStr( buf ); + _value.SetStr( buf ); } void XMLAttribute::SetAttribute( float v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); - value.SetStr( buf ); + _value.SetStr( buf ); } // --------- XMLElement ---------- // XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ), - closingType( 0 ), - rootAttribute( 0 ) + _closingType( 0 ), + _rootAttribute( 0 ) { } XMLElement::~XMLElement() { - while( rootAttribute ) { - XMLAttribute* next = rootAttribute->next; - DELETE_ATTRIBUTE( rootAttribute ); - rootAttribute = next; + while( _rootAttribute ) { + XMLAttribute* next = _rootAttribute->_next; + DELETE_ATTRIBUTE( _rootAttribute ); + _rootAttribute = next; } } @@ -1182,7 +1181,7 @@ XMLElement::~XMLElement() XMLAttribute* XMLElement::FindAttribute( const char* name ) { XMLAttribute* a = 0; - for( a=rootAttribute; a; a = a->next ) { + for( a=_rootAttribute; a; a = a->_next ) { if ( XMLUtil::StringEqual( a->Name(), name ) ) { return a; } @@ -1194,7 +1193,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( a=_rootAttribute; a; a = a->_next ) { if ( XMLUtil::StringEqual( a->Name(), name ) ) { return a; } @@ -1295,21 +1294,21 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) { XMLAttribute* last = 0; XMLAttribute* attrib = 0; - for( attrib = rootAttribute; + for( attrib = _rootAttribute; attrib; - last = attrib, attrib = attrib->next ) { + last = attrib, attrib = attrib->_next ) { if ( XMLUtil::StringEqual( attrib->Name(), name ) ) { break; } } if ( !attrib ) { - attrib = new (document->attributePool.Alloc() ) XMLAttribute(); - attrib->memPool = &document->attributePool; + attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); + attrib->_memPool = &_document->_attributePool; if ( last ) { - last->next = attrib; + last->_next = attrib; } else { - rootAttribute = attrib; + _rootAttribute = attrib; } attrib->SetName( name ); } @@ -1320,13 +1319,13 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) void XMLElement::DeleteAttribute( const char* name ) { XMLAttribute* prev = 0; - for( XMLAttribute* a=rootAttribute; a; a=a->next ) { + for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) { if ( XMLUtil::StringEqual( name, a->Name() ) ) { if ( prev ) { - prev->next = a->next; + prev->_next = a->_next; } else { - rootAttribute = a->next; + _rootAttribute = a->_next; } DELETE_ATTRIBUTE( a ); break; @@ -1345,19 +1344,19 @@ char* XMLElement::ParseAttributes( char* p ) while( p ) { p = XMLUtil::SkipWhiteSpace( p ); if ( !p || !(*p) ) { - document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() ); return 0; } // attribute. if ( XMLUtil::IsAlpha( *p ) ) { - XMLAttribute* attrib = new (document->attributePool.Alloc() ) XMLAttribute(); - attrib->memPool = &document->attributePool; + XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); + attrib->_memPool = &_document->_attributePool; - p = attrib->ParseDeep( p, document->ProcessEntities() ); + p = attrib->ParseDeep( p, _document->ProcessEntities() ); if ( !p || Attribute( attrib->Name() ) ) { DELETE_ATTRIBUTE( attrib ); - document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p ); + _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p ); return 0; } // There is a minor bug here: if the attribute in the source xml @@ -1366,16 +1365,16 @@ char* XMLElement::ParseAttributes( char* p ) // avoids re-scanning the attribute list. Preferring performance for // now, may reconsider in the future. if ( prevAttribute ) { - prevAttribute->next = attrib; + prevAttribute->_next = attrib; } else { - rootAttribute = attrib; + _rootAttribute = attrib; } prevAttribute = attrib; } // end of the tag else if ( *p == '/' && *(p+1) == '>' ) { - closingType = CLOSED; + _closingType = CLOSED; return p+2; // done; sealed element. } // end of the tag @@ -1384,7 +1383,7 @@ char* XMLElement::ParseAttributes( char* p ) break; } else { - document->SetError( XML_ERROR_PARSING_ELEMENT, start, p ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, start, p ); return 0; } } @@ -1408,17 +1407,17 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair ) // parsed just like a regular element then deleted from // the DOM. if ( *p == '/' ) { - closingType = CLOSING; + _closingType = CLOSING; ++p; } - p = value.ParseName( p ); - if ( value.Empty() ) { + p = _value.ParseName( p ); + if ( _value.Empty() ) { return 0; } p = ParseAttributes( p ); - if ( !p || !*p || closingType ) { + if ( !p || !*p || _closingType ) { return p; } @@ -1431,7 +1430,7 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair ) XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { - doc = document; + doc = _document; } XMLElement* element = doc->NewElement( Value() ); // fixme: this will always allocate memory. Intern? for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) { @@ -1468,7 +1467,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const bool XMLElement::Accept( XMLVisitor* visitor ) const { - if ( visitor->VisitEnter( *this, rootAttribute ) ) { + if ( visitor->VisitEnter( *this, _rootAttribute ) ) { for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) { if ( !node->Accept( visitor ) ) { break; @@ -1480,24 +1479,24 @@ bool XMLElement::Accept( XMLVisitor* visitor ) const // --------- XMLDocument ----------- // -XMLDocument::XMLDocument( bool _processEntities, Whitespace _whitespace ) : +XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) : XMLNode( 0 ), - writeBOM( false ), - processEntities( _processEntities ), - errorID( 0 ), - whitespace( _whitespace ), - errorStr1( 0 ), - errorStr2( 0 ), - charBuffer( 0 ) + _writeBOM( false ), + _processEntities( processEntities ), + _errorID( 0 ), + _whitespace( whitespace ), + _errorStr1( 0 ), + _errorStr2( 0 ), + _charBuffer( 0 ) { - document = this; // avoid warning about 'this' in initializer list + _document = this; // avoid warning about 'this' in initializer list } XMLDocument::~XMLDocument() { DeleteChildren(); - delete [] charBuffer; + delete [] _charBuffer; #if 0 textPool.Trace( "text" ); @@ -1506,29 +1505,28 @@ XMLDocument::~XMLDocument() attributePool.Trace( "attribute" ); #endif - TIXMLASSERT( textPool.CurrentAllocs() == 0 ); - TIXMLASSERT( elementPool.CurrentAllocs() == 0 ); - TIXMLASSERT( commentPool.CurrentAllocs() == 0 ); - TIXMLASSERT( attributePool.CurrentAllocs() == 0 ); + TIXMLASSERT( _textPool.CurrentAllocs() == 0 ); + TIXMLASSERT( _elementPool.CurrentAllocs() == 0 ); + TIXMLASSERT( _commentPool.CurrentAllocs() == 0 ); + TIXMLASSERT( _attributePool.CurrentAllocs() == 0 ); } void XMLDocument::InitDocument() { - errorID = XML_NO_ERROR; - errorStr1 = 0; - errorStr2 = 0; - - delete [] charBuffer; - charBuffer = 0; + _errorID = XML_NO_ERROR; + _errorStr1 = 0; + _errorStr2 = 0; + delete [] _charBuffer; + _charBuffer = 0; } XMLElement* XMLDocument::NewElement( const char* name ) { - XMLElement* ele = new (elementPool.Alloc()) XMLElement( this ); - ele->memPool = &elementPool; + XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this ); + ele->_memPool = &_elementPool; ele->SetName( name ); return ele; } @@ -1536,8 +1534,8 @@ XMLElement* XMLDocument::NewElement( const char* name ) XMLComment* XMLDocument::NewComment( const char* str ) { - XMLComment* comment = new (commentPool.Alloc()) XMLComment( this ); - comment->memPool = &commentPool; + XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this ); + comment->_memPool = &_commentPool; comment->SetValue( str ); return comment; } @@ -1545,8 +1543,8 @@ XMLComment* XMLDocument::NewComment( const char* str ) XMLText* XMLDocument::NewText( const char* str ) { - XMLText* text = new (textPool.Alloc()) XMLText( this ); - text->memPool = &textPool; + XMLText* text = new (_textPool.Alloc()) XMLText( this ); + text->_memPool = &_textPool; text->SetValue( str ); return text; } @@ -1554,8 +1552,8 @@ XMLText* XMLDocument::NewText( const char* str ) XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) { - XMLDeclaration* dec = new (commentPool.Alloc()) XMLDeclaration( this ); - dec->memPool = &commentPool; + XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this ); + dec->_memPool = &_commentPool; dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" ); return dec; } @@ -1563,8 +1561,8 @@ XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) XMLUnknown* XMLDocument::NewUnknown( const char* str ) { - XMLUnknown* unk = new (commentPool.Alloc()) XMLUnknown( this ); - unk->memPool = &commentPool; + XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this ); + unk->_memPool = &_commentPool; unk->SetValue( str ); return unk; } @@ -1584,11 +1582,11 @@ int XMLDocument::LoadFile( const char* filename ) if ( !fp) { #endif SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0 ); - return errorID; + return _errorID; } LoadFile( fp ); fclose( fp ); - return errorID; + return _errorID; } @@ -1602,28 +1600,28 @@ int XMLDocument::LoadFile( FILE* fp ) fseek( fp, 0, SEEK_SET ); if ( size == 0 ) { - return errorID; + return _errorID; } - charBuffer = new char[size+1]; - size_t read = fread( charBuffer, 1, size, fp ); + _charBuffer = new char[size+1]; + size_t read = fread( _charBuffer, 1, size, fp ); if ( read != size ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); - return errorID; + return _errorID; } - charBuffer[size] = 0; + _charBuffer[size] = 0; - const char* p = charBuffer; + const char* p = _charBuffer; p = XMLUtil::SkipWhiteSpace( p ); - p = XMLUtil::ReadBOM( p, &writeBOM ); + p = XMLUtil::ReadBOM( p, &_writeBOM ); if ( !p || !*p ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); - return errorID; + return _errorID; } - ParseDeep( charBuffer + (p-charBuffer), 0 ); - return errorID; + ParseDeep( _charBuffer + (p-_charBuffer), 0 ); + return _errorID; } @@ -1638,11 +1636,11 @@ int XMLDocument::SaveFile( const char* filename, bool compact ) if ( !fp) { #endif SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 ); - return errorID; + return _errorID; } SaveFile(fp, compact); fclose( fp ); - return errorID; + return _errorID; } @@ -1650,7 +1648,7 @@ int XMLDocument::SaveFile( FILE* fp, bool compact ) { XMLPrinter stream( fp, compact ); Print( &stream ); - return errorID; + return _errorID; } @@ -1661,24 +1659,24 @@ int XMLDocument::Parse( const char* p, size_t len ) if ( !p || !*p ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); - return errorID; + return _errorID; } if ( len == (size_t)(-1) ) { len = strlen( p ); } - charBuffer = new char[ len+1 ]; - memcpy( charBuffer, p, len ); - charBuffer[len] = 0; + _charBuffer = new char[ len+1 ]; + memcpy( _charBuffer, p, len ); + _charBuffer[len] = 0; p = XMLUtil::SkipWhiteSpace( p ); - p = XMLUtil::ReadBOM( p, &writeBOM ); + p = XMLUtil::ReadBOM( p, &_writeBOM ); if ( !p || !*p ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); - return errorID; + return _errorID; } - ParseDeep( charBuffer, 0 ); - return errorID; + ParseDeep( _charBuffer, 0 ); + return _errorID; } @@ -1694,55 +1692,55 @@ void XMLDocument::Print( XMLPrinter* streamer ) void XMLDocument::SetError( int error, const char* str1, const char* str2 ) { - errorID = error; - errorStr1 = str1; - errorStr2 = str2; + _errorID = error; + _errorStr1 = str1; + _errorStr2 = str2; } void XMLDocument::PrintError() const { - if ( errorID ) { + if ( _errorID ) { static const int LEN = 20; char buf1[LEN] = { 0 }; char buf2[LEN] = { 0 }; - if ( errorStr1 ) { - TIXML_SNPRINTF( buf1, LEN, "%s", errorStr1 ); + if ( _errorStr1 ) { + TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1 ); } - if ( errorStr2 ) { - TIXML_SNPRINTF( buf2, LEN, "%s", errorStr2 ); + if ( _errorStr2 ) { + TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 ); } printf( "XMLDocument error id=%d str1=%s str2=%s\n", - errorID, buf1, buf2 ); + _errorID, buf1, buf2 ); } } XMLPrinter::XMLPrinter( FILE* file, bool compact ) : - elementJustOpened( false ), - firstElement( true ), - fp( file ), - depth( 0 ), - textDepth( -1 ), - processEntities( true ), - compactMode( compact ) + _elementJustOpened( false ), + _firstElement( true ), + _fp( file ), + _depth( 0 ), + _textDepth( -1 ), + _processEntities( true ), + _compactMode( compact ) { for( int i=0; i'] = true; // not required, but consistency is nice - buffer.Push( 0 ); + _restrictedEntityFlag[(int)'&'] = true; + _restrictedEntityFlag[(int)'<'] = true; + _restrictedEntityFlag[(int)'>'] = true; // not required, but consistency is nice + _buffer.Push( 0 ); } @@ -1751,8 +1749,8 @@ void XMLPrinter::Print( const char* format, ... ) va_list va; va_start( va, format ); - if ( fp ) { - vfprintf( fp, format, va ); + if ( _fp ) { + vfprintf( _fp, format, va ); } else { // This seems brutally complex. Haven't figured out a better @@ -1761,20 +1759,20 @@ void XMLPrinter::Print( const char* format, ... ) int len = -1; int expand = 1000; while ( len < 0 ) { - len = vsnprintf_s( accumulator.Mem(), accumulator.Capacity(), _TRUNCATE, format, va ); + len = vsnprintf_s( _accumulator.Mem(), _accumulator.Capacity(), _TRUNCATE, format, va ); if ( len < 0 ) { expand *= 3/2; accumulator.PushArr( expand ); } } - char* p = buffer.PushArr( len ) - 1; - memcpy( p, accumulator.Mem(), len+1 ); + char* p = _buffer.PushArr( len ) - 1; + memcpy( p, _accumulator.Mem(), len+1 ); #else int len = vsnprintf( 0, 0, format, va ); // Close out and re-start the va-args va_end( va ); va_start( va, format ); - char* p = buffer.PushArr( len ) - 1; + char* p = _buffer.PushArr( len ) - 1; vsnprintf( p, len+1, format, va ); #endif } @@ -1794,9 +1792,9 @@ void XMLPrinter::PrintString( const char* p, bool restricted ) { // Look for runs of bytes between entities to print. const char* q = p; - const bool* flag = restricted ? restrictedEntityFlag : entityFlag; + const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag; - if ( processEntities ) { + if ( _processEntities ) { while ( *q ) { // Remember, char is sometimes signed. (How many times has that bitten me?) if ( *q > 0 && *q < ENTITY_RANGE ) { @@ -1822,7 +1820,7 @@ void XMLPrinter::PrintString( const char* p, bool restricted ) } // Flush the remaining string. This will be the entire // string if an entity wasn't found. - if ( !processEntities || (q-p > 0) ) { + if ( !_processEntities || (q-p > 0) ) { Print( "%s", p ); } } @@ -1842,26 +1840,26 @@ void XMLPrinter::PushHeader( bool writeBOM, bool writeDec ) void XMLPrinter::OpenElement( const char* name ) { - if ( elementJustOpened ) { + if ( _elementJustOpened ) { SealElement(); } - stack.Push( name ); + _stack.Push( name ); - if ( textDepth < 0 && !firstElement && !compactMode ) { + if ( _textDepth < 0 && !_firstElement && !_compactMode ) { Print( "\n" ); - PrintSpace( depth ); + PrintSpace( _depth ); } Print( "<%s", name ); - elementJustOpened = true; - firstElement = false; - ++depth; + _elementJustOpened = true; + _firstElement = false; + ++_depth; } void XMLPrinter::PushAttribute( const char* name, const char* value ) { - TIXMLASSERT( elementJustOpened ); + TIXMLASSERT( _elementJustOpened ); Print( " %s=\"", name ); PrintString( value, false ); Print( "\"" ); @@ -1902,42 +1900,42 @@ void XMLPrinter::PushAttribute( const char* name, double v ) void XMLPrinter::CloseElement() { - --depth; - const char* name = stack.Pop(); + --_depth; + const char* name = _stack.Pop(); - if ( elementJustOpened ) { + if ( _elementJustOpened ) { Print( "/>" ); } else { - if ( textDepth < 0 && !compactMode) { + if ( _textDepth < 0 && !_compactMode) { Print( "\n" ); - PrintSpace( depth ); + PrintSpace( _depth ); } Print( "", name ); } - if ( textDepth == depth ) { - textDepth = -1; + if ( _textDepth == _depth ) { + _textDepth = -1; } - if ( depth == 0 && !compactMode) { + if ( _depth == 0 && !_compactMode) { Print( "\n" ); } - elementJustOpened = false; + _elementJustOpened = false; } void XMLPrinter::SealElement() { - elementJustOpened = false; + _elementJustOpened = false; Print( ">" ); } void XMLPrinter::PushText( const char* text, bool cdata ) { - textDepth = depth-1; + _textDepth = _depth-1; - if ( elementJustOpened ) { + if ( _elementJustOpened ) { SealElement(); } if ( cdata ) { @@ -1992,49 +1990,49 @@ void XMLPrinter::PushText( double value ) void XMLPrinter::PushComment( const char* comment ) { - if ( elementJustOpened ) { + if ( _elementJustOpened ) { SealElement(); } - if ( textDepth < 0 && !firstElement && !compactMode) { + if ( _textDepth < 0 && !_firstElement && !_compactMode) { Print( "\n" ); - PrintSpace( depth ); + PrintSpace( _depth ); } - firstElement = false; + _firstElement = false; Print( "", comment ); } void XMLPrinter::PushDeclaration( const char* value ) { - if ( elementJustOpened ) { + if ( _elementJustOpened ) { SealElement(); } - if ( textDepth < 0 && !firstElement && !compactMode) { + if ( _textDepth < 0 && !_firstElement && !_compactMode) { Print( "\n" ); - PrintSpace( depth ); + PrintSpace( _depth ); } - firstElement = false; + _firstElement = false; Print( "", value ); } void XMLPrinter::PushUnknown( const char* value ) { - if ( elementJustOpened ) { + if ( _elementJustOpened ) { SealElement(); } - if ( textDepth < 0 && !firstElement && !compactMode) { + if ( _textDepth < 0 && !_firstElement && !_compactMode) { Print( "\n" ); - PrintSpace( depth ); + PrintSpace( _depth ); } - firstElement = false; + _firstElement = false; Print( "", value ); } bool XMLPrinter::VisitEnter( const XMLDocument& doc ) { - processEntities = doc.ProcessEntities(); + _processEntities = doc.ProcessEntities(); if ( doc.HasBOM() ) { PushHeader( true, false ); } diff --git a/tinyxml2.h b/tinyxml2.h index ca80039..f6b3ba6 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -129,12 +129,12 @@ public: NEEDS_NEWLINE_NORMALIZATION = 0x02, COLLAPSE_WHITESPACE = 0x04, - TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, + TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, - ATTRIBUTE_NAME = 0, - ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, - ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, - COMMENT = NEEDS_NEWLINE_NORMALIZATION + ATTRIBUTE_NAME = 0, + ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, + ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, + COMMENT = NEEDS_NEWLINE_NORMALIZATION }; StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} @@ -189,58 +189,58 @@ class DynArray { public: DynArray< T, INIT >() { - _mem = pool; - allocated = INIT; - size = 0; + _mem = _pool; + _allocated = INIT; + _size = 0; } ~DynArray() { - if ( _mem != pool ) { + if ( _mem != _pool ) { delete [] _mem; } } void Push( T t ) { - EnsureCapacity( size+1 ); - _mem[size++] = t; + EnsureCapacity( _size+1 ); + _mem[_size++] = t; } T* PushArr( int count ) { - EnsureCapacity( size+count ); - T* ret = &_mem[size]; - size += count; + EnsureCapacity( _size+count ); + T* ret = &_mem[_size]; + _size += count; return ret; } T Pop() { - return _mem[--size]; + return _mem[--_size]; } void PopArr( int count ) { - TIXMLASSERT( size >= count ); - size -= count; + TIXMLASSERT( _size >= count ); + _size -= count; } bool Empty() const { - return size == 0; + return _size == 0; } T& operator[](int i) { - TIXMLASSERT( i>= 0 && i < size ); + TIXMLASSERT( i>= 0 && i < _size ); return _mem[i]; } const T& operator[](int i) const { - TIXMLASSERT( i>= 0 && i < size ); + TIXMLASSERT( i>= 0 && i < _size ); return _mem[i]; } int Size() const { - return size; + return _size; } int Capacity() const { - return allocated; + return _allocated; } const T* Mem() const { @@ -253,22 +253,22 @@ public: private: void EnsureCapacity( int cap ) { - if ( cap > allocated ) { + if ( cap > _allocated ) { int newAllocated = cap * 2; T* newMem = new T[newAllocated]; - memcpy( newMem, _mem, sizeof(T)*size ); // warning: not using constructors, only works for PODs - if ( _mem != pool ) { + memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs + if ( _mem != _pool ) { delete [] _mem; } _mem = newMem; - allocated = newAllocated; + _allocated = newAllocated; } } - T* _mem; - T pool[INIT]; - int allocated; // objects allocated - int size; // number objects in use + T* _mem; + T _pool[INIT]; + int _allocated; // objects allocated + int _size; // number objects in use }; @@ -295,11 +295,11 @@ template< int SIZE > class MemPoolT : public MemPool { public: - MemPoolT() : root(0), currentAllocs(0), nAllocs(0), maxAllocs(0) {} + MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0) {} ~MemPoolT() { // Delete the blocks. - for( int i=0; ichunk[i].next = &block->chunk[i+1]; } block->chunk[COUNT-1].next = 0; - root = block->chunk; + _root = block->chunk; } - void* result = root; - root = root->next; + void* result = _root; + _root = _root->next; - ++currentAllocs; - if ( currentAllocs > maxAllocs ) { - maxAllocs = currentAllocs; + ++_currentAllocs; + if ( _currentAllocs > _maxAllocs ) { + _maxAllocs = _currentAllocs; } - nAllocs++; + _nAllocs++; return result; } virtual void Free( void* mem ) { if ( !mem ) { return; } - --currentAllocs; + --_currentAllocs; Chunk* chunk = (Chunk*)mem; #ifdef DEBUG memset( chunk, 0xfe, sizeof(Chunk) ); #endif - chunk->next = root; - root = chunk; + chunk->next = _root; + _root = chunk; } void Trace( const char* name ) { printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", - name, maxAllocs, maxAllocs*SIZE/1024, currentAllocs, SIZE, nAllocs, blockPtrs.Size() ); + name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() ); } private: enum { COUNT = 1024/SIZE }; union Chunk { - Chunk* next; - char mem[SIZE]; + Chunk* next; + char mem[SIZE]; }; struct Block { Chunk chunk[COUNT]; }; - DynArray< Block*, 10 > blockPtrs; - Chunk* root; + DynArray< Block*, 10 > _blockPtrs; + Chunk* _root; - int currentAllocs; - int nAllocs; - int maxAllocs; + int _currentAllocs; + int _nAllocs; + int _maxAllocs; }; @@ -533,11 +533,11 @@ public: /// Get the XMLDocument that owns this XMLNode. const XMLDocument* GetDocument() const { - return document; + return _document; } /// Get the XMLDocument that owns this XMLNode. XMLDocument* GetDocument() { - return document; + return _document; } virtual XMLElement* ToElement() { @@ -588,8 +588,9 @@ public: @endverbatim */ const char* Value() const { - return value.GetStr(); + return _value.GetStr(); } + /** Set the Value of an XML node. @sa Value() */ @@ -597,36 +598,41 @@ public: /// Get the parent of this node on the DOM. const XMLNode* Parent() const { - return parent; + return _parent; } + XMLNode* Parent() { - return parent; + return _parent; } /// Returns true if this node has no children. bool NoChildren() const { - return !firstChild; + return !_firstChild; } /// Get the first child node, or null if none exists. const XMLNode* FirstChild() const { - return firstChild; + return _firstChild; } + XMLNode* FirstChild() { - return firstChild; + return _firstChild; } + /** Get the first child element, or optionally the first child element with the specified name. */ const XMLElement* FirstChildElement( const char* value=0 ) const; - XMLElement* FirstChildElement( const char* _value=0 ) { - return const_cast(const_cast(this)->FirstChildElement( _value )); + + XMLElement* FirstChildElement( const char* value=0 ) { + return const_cast(const_cast(this)->FirstChildElement( value )); } /// Get the last child node, or null if none exists. const XMLNode* LastChild() const { - return lastChild; + return _lastChild; } + XMLNode* LastChild() { return const_cast(const_cast(this)->LastChild() ); } @@ -635,36 +641,41 @@ public: element with the specified name. */ const XMLElement* LastChildElement( const char* value=0 ) const; - XMLElement* LastChildElement( const char* _value=0 ) { - return const_cast(const_cast(this)->LastChildElement(_value) ); + + XMLElement* LastChildElement( const char* value=0 ) { + return const_cast(const_cast(this)->LastChildElement(value) ); } /// Get the previous (left) sibling node of this node. const XMLNode* PreviousSibling() const { - return prev; + return _prev; } + XMLNode* PreviousSibling() { - return prev; + return _prev; } /// Get the previous (left) sibling element of this node, with an opitionally supplied name. const XMLElement* PreviousSiblingElement( const char* value=0 ) const ; - XMLElement* PreviousSiblingElement( const char* _value=0 ) { - return const_cast(const_cast(this)->PreviousSiblingElement( _value ) ); + + XMLElement* PreviousSiblingElement( const char* value=0 ) { + return const_cast(const_cast(this)->PreviousSiblingElement( value ) ); } /// Get the next (right) sibling node of this node. const XMLNode* NextSibling() const { - return next; + return _next; } + XMLNode* NextSibling() { - return next; + return _next; } /// Get the next (right) sibling element of this node, with an opitionally supplied name. const XMLElement* NextSiblingElement( const char* value=0 ) const; - XMLElement* NextSiblingElement( const char* _value=0 ) { - return const_cast(const_cast(this)->NextSiblingElement( _value ) ); + + XMLElement* NextSiblingElement( const char* value=0 ) { + return const_cast(const_cast(this)->NextSiblingElement( value ) ); } /** @@ -746,18 +757,18 @@ protected: XMLNode( const XMLNode& ); // not supported XMLNode& operator=( const XMLNode& ); // not supported - XMLDocument* document; - XMLNode* parent; - mutable StrPair value; + XMLDocument* _document; + XMLNode* _parent; + mutable StrPair _value; - XMLNode* firstChild; - XMLNode* lastChild; + XMLNode* _firstChild; + XMLNode* _lastChild; - XMLNode* prev; - XMLNode* next; + XMLNode* _prev; + XMLNode* _next; private: - MemPool* memPool; + MemPool* _memPool; void Unlink( XMLNode* child ); }; @@ -781,35 +792,34 @@ class XMLText : public XMLNode public: virtual bool Accept( XMLVisitor* visitor ) const; - virtual XMLText* ToText() { + virtual XMLText* ToText() { return this; } - virtual const XMLText* ToText() const { + virtual const XMLText* ToText() const { return this; } /// Declare whether this should be CDATA or standard text. - void SetCData( bool _isCData ) { - this->isCData = _isCData; + void SetCData( bool isCData ) { + _isCData = isCData; } /// Returns true if this is a CDATA text element. bool CData() const { - return isCData; + return _isCData; } char* ParseDeep( char*, StrPair* endTag ); virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual bool ShallowEqual( const XMLNode* compare ) const; - protected: - XMLText( XMLDocument* doc ) : XMLNode( doc ), isCData( false ) {} + XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} virtual ~XMLText() {} XMLText( const XMLText& ); // not supported XMLText& operator=( const XMLText& ); // not supported private: - bool isCData; + bool _isCData; }; @@ -948,13 +958,13 @@ class XMLAttribute friend class XMLElement; public: const char* Name() const { - return name.GetStr(); ///< The name of the attribute. + return _name.GetStr(); ///< The name of the attribute. } const char* Value() const { - return value.GetStr(); ///< The value of the attribute. + return _value.GetStr(); ///< The value of the attribute. } const XMLAttribute* Next() const { - return next; ///< The next attribute in the list. + return _next; ///< The next attribute in the list. } /** IntAttribute interprets the attribute as an integer, and returns the value. @@ -1021,18 +1031,19 @@ public: private: enum { BUF_SIZE = 200 }; - XMLAttribute() : next( 0 ) {} + XMLAttribute() : _next( 0 ) {} virtual ~XMLAttribute() {} + XMLAttribute( const XMLAttribute& ); // not supported void operator=( const XMLAttribute& ); // not supported void SetName( const char* name ); char* ParseDeep( char* p, bool processEntities ); - mutable StrPair name; - mutable StrPair value; - XMLAttribute* next; - MemPool* memPool; + mutable StrPair _name; + mutable StrPair _value; + XMLAttribute* _next; + MemPool* _memPool; }; @@ -1135,70 +1146,70 @@ public: QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 @endverbatim */ - int QueryIntAttribute( const char* name, int* _value ) const { + int QueryIntAttribute( const char* name, int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } - return a->QueryIntValue( _value ); + return a->QueryIntValue( value ); } /// See QueryIntAttribute() - int QueryUnsignedAttribute( const char* name, unsigned int* _value ) const { + int QueryUnsignedAttribute( const char* name, unsigned int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } - return a->QueryUnsignedValue( _value ); + return a->QueryUnsignedValue( value ); } /// See QueryIntAttribute() - int QueryBoolAttribute( const char* name, bool* _value ) const { + int QueryBoolAttribute( const char* name, bool* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } - return a->QueryBoolValue( _value ); + return a->QueryBoolValue( value ); } /// See QueryIntAttribute() - int QueryDoubleAttribute( const char* name, double* _value ) const { + int QueryDoubleAttribute( const char* name, double* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } - return a->QueryDoubleValue( _value ); + return a->QueryDoubleValue( value ); } /// See QueryIntAttribute() - int QueryFloatAttribute( const char* name, float* _value ) const { + int QueryFloatAttribute( const char* name, float* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } - return a->QueryFloatValue( _value ); + return a->QueryFloatValue( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, const char* _value ) { + void SetAttribute( const char* name, const char* value ) { XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( _value ); + a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, int _value ) { + void SetAttribute( const char* name, int value ) { XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( _value ); + a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, unsigned _value ) { + void SetAttribute( const char* name, unsigned value ) { XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( _value ); + a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, bool _value ) { + void SetAttribute( const char* name, bool value ) { XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( _value ); + a->SetAttribute( value ); } /// Sets the named attribute to value. - void SetAttribute( const char* name, double _value ) { + void SetAttribute( const char* name, double value ) { XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( _value ); + a->SetAttribute( value ); } /** @@ -1208,7 +1219,7 @@ public: /// Return the first attribute in the list. const XMLAttribute* FirstAttribute() const { - return rootAttribute; + return _rootAttribute; } /// Query a specific attribute in the list. const XMLAttribute* FindAttribute( const char* name ) const; @@ -1286,7 +1297,7 @@ public: CLOSING // }; int ClosingType() const { - return closingType; + return _closingType; } char* ParseDeep( char* p, StrPair* endTag ); virtual XMLNode* ShallowClone( XMLDocument* document ) const; @@ -1303,11 +1314,11 @@ private: //void LinkAttribute( XMLAttribute* attrib ); char* ParseAttributes( char* p ); - int closingType; + int _closingType; // The attribute list is ordered; there is no 'lastAttribute' // because the list needs to be scanned for dupes before adding // a new attribute. - XMLAttribute* rootAttribute; + XMLAttribute* _rootAttribute; }; @@ -1382,22 +1393,22 @@ public: int SaveFile( FILE* fp, bool compact = false ); bool ProcessEntities() const { - return processEntities; + return _processEntities; } Whitespace WhitespaceMode() const { - return whitespace; + return _whitespace; } /** Returns true if this document has a leading Byte Order Mark of UTF8. */ bool HasBOM() const { - return writeBOM; + return _writeBOM; } /** Sets whether to write the BOM when writing the file. */ void SetBOM( bool useBOM ) { - writeBOM = useBOM; + _writeBOM = useBOM; } /** Return the root element of DOM. Equivalent to FirstChildElement(). @@ -1459,7 +1470,7 @@ public: XMLDeclaration* NewDeclaration( const char* text=0 ); /** Create a new Unknown associated with - this Document. The memory for the object + this Document. The memory forthe object is managed by the Document. */ XMLUnknown* NewUnknown( const char* text ); @@ -1469,26 +1480,26 @@ public: It will be unlinked from the DOM. */ void DeleteNode( XMLNode* node ) { - node->parent->DeleteChild( node ); + node->_parent->DeleteChild( node ); } void SetError( int error, const char* str1, const char* str2 ); /// Return true if there was an error parsing the document. bool Error() const { - return errorID != XML_NO_ERROR; + return _errorID != XML_NO_ERROR; } /// Return the errorID. int ErrorID() const { - return errorID; + return _errorID; } /// Return a possibly helpful diagnostic location or string. const char* GetErrorStr1() const { - return errorStr1; + return _errorStr1; } /// Return a possibly helpful secondary diagnostic location or string. const char* GetErrorStr2() const { - return errorStr2; + return _errorStr2; } /// If there is an error, print it to stdout. void PrintError() const; @@ -1508,18 +1519,18 @@ private: void operator=( const XMLDocument& ); // not supported void InitDocument(); - bool writeBOM; - bool processEntities; - int errorID; - Whitespace whitespace; - const char* errorStr1; - const char* errorStr2; - char* charBuffer; + bool _writeBOM; + bool _processEntities; + int _errorID; + Whitespace _whitespace; + const char* _errorStr1; + const char* _errorStr2; + char* _charBuffer; - MemPoolT< sizeof(XMLElement) > elementPool; - MemPoolT< sizeof(XMLAttribute) > attributePool; - MemPoolT< sizeof(XMLText) > textPool; - MemPoolT< sizeof(XMLComment) > commentPool; + MemPoolT< sizeof(XMLElement) > _elementPool; + MemPoolT< sizeof(XMLAttribute) > _attributePool; + MemPoolT< sizeof(XMLText) > _textPool; + MemPoolT< sizeof(XMLComment) > _commentPool; }; @@ -1582,79 +1593,79 @@ class XMLHandle { public: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. - XMLHandle( XMLNode* _node ) { - node = _node; + XMLHandle( XMLNode* node ) { + _node = node; } /// Create a handle from a node. - XMLHandle( XMLNode& _node ) { - node = &_node; + XMLHandle( XMLNode& node ) { + _node = &node; } /// Copy constructor XMLHandle( const XMLHandle& ref ) { - node = ref.node; + _node = ref._node; } /// Assignment XMLHandle& operator=( const XMLHandle& ref ) { - node = ref.node; + _node = ref._node; return *this; } /// Get the first child of this handle. XMLHandle FirstChild() { - return XMLHandle( node ? node->FirstChild() : 0 ); + return XMLHandle( _node ? _node->FirstChild() : 0 ); } /// Get the first child element of this handle. XMLHandle FirstChildElement( const char* value=0 ) { - return XMLHandle( node ? node->FirstChildElement( value ) : 0 ); + return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 ); } /// Get the last child of this handle. XMLHandle LastChild() { - return XMLHandle( node ? node->LastChild() : 0 ); + return XMLHandle( _node ? _node->LastChild() : 0 ); } /// Get the last child element of this handle. XMLHandle LastChildElement( const char* _value=0 ) { - return XMLHandle( node ? node->LastChildElement( _value ) : 0 ); + return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 ); } /// Get the previous sibling of this handle. XMLHandle PreviousSibling() { - return XMLHandle( node ? node->PreviousSibling() : 0 ); + return XMLHandle( _node ? _node->PreviousSibling() : 0 ); } /// Get the previous sibling element of this handle. XMLHandle PreviousSiblingElement( const char* _value=0 ) { - return XMLHandle( node ? node->PreviousSiblingElement( _value ) : 0 ); + return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); } /// Get the next sibling of this handle. XMLHandle NextSibling() { - return XMLHandle( node ? node->NextSibling() : 0 ); + return XMLHandle( _node ? _node->NextSibling() : 0 ); } /// Get the next sibling element of this handle. XMLHandle NextSiblingElement( const char* _value=0 ) { - return XMLHandle( node ? node->NextSiblingElement( _value ) : 0 ); + return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); } /// Safe cast to XMLNode. This can return null. XMLNode* ToNode() { - return node; + return _node; } /// Safe cast to XMLElement. This can return null. XMLElement* ToElement() { - return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); + return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); } /// Safe cast to XMLText. This can return null. XMLText* ToText() { - return ( ( node && node->ToText() ) ? node->ToText() : 0 ); + return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); } /// Safe cast to XMLUnknown. This can return null. XMLUnknown* ToUnknown() { - return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); + return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); } /// Safe cast to XMLDeclaration. This can return null. XMLDeclaration* ToDeclaration() { - return ( ( node && node->ToDeclaration() ) ? node->ToDeclaration() : 0 ); + return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); } private: - XMLNode* node; + XMLNode* _node; }; @@ -1665,65 +1676,65 @@ private: class XMLConstHandle { public: - XMLConstHandle( const XMLNode* _node ) { - node = _node; + XMLConstHandle( const XMLNode* node ) { + _node = node; } - XMLConstHandle( const XMLNode& _node ) { - node = &_node; + XMLConstHandle( const XMLNode& node ) { + _node = &node; } XMLConstHandle( const XMLConstHandle& ref ) { - node = ref.node; + _node = ref._node; } XMLConstHandle& operator=( const XMLConstHandle& ref ) { - node = ref.node; + _node = ref._node; return *this; } const XMLConstHandle FirstChild() const { - return XMLConstHandle( node ? node->FirstChild() : 0 ); + return XMLConstHandle( _node ? _node->FirstChild() : 0 ); } const XMLConstHandle FirstChildElement( const char* value=0 ) const { - return XMLConstHandle( node ? node->FirstChildElement( value ) : 0 ); + return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 ); } const XMLConstHandle LastChild() const { - return XMLConstHandle( node ? node->LastChild() : 0 ); + return XMLConstHandle( _node ? _node->LastChild() : 0 ); } const XMLConstHandle LastChildElement( const char* _value=0 ) const { - return XMLConstHandle( node ? node->LastChildElement( _value ) : 0 ); + return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 ); } const XMLConstHandle PreviousSibling() const { - return XMLConstHandle( node ? node->PreviousSibling() : 0 ); + return XMLConstHandle( _node ? _node->PreviousSibling() : 0 ); } const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const { - return XMLConstHandle( node ? node->PreviousSiblingElement( _value ) : 0 ); + return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); } const XMLConstHandle NextSibling() const { - return XMLConstHandle( node ? node->NextSibling() : 0 ); + return XMLConstHandle( _node ? _node->NextSibling() : 0 ); } const XMLConstHandle NextSiblingElement( const char* _value=0 ) const { - return XMLConstHandle( node ? node->NextSiblingElement( _value ) : 0 ); + return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); } const XMLNode* ToNode() const { - return node; + return _node; } const XMLElement* ToElement() const { - return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); + return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); } const XMLText* ToText() const { - return ( ( node && node->ToText() ) ? node->ToText() : 0 ); + return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); } const XMLUnknown* ToUnknown() const { - return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); + return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); } const XMLDeclaration* ToDeclaration() const { - return ( ( node && node->ToDeclaration() ) ? node->ToDeclaration() : 0 ); + return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); } private: - const XMLNode* node; + const XMLNode* _node; }; @@ -1833,7 +1844,7 @@ public: the XML file in memory. */ const char* CStr() const { - return buffer.Mem(); + return _buffer.Mem(); } /** If in print to memory mode, return the size @@ -1841,7 +1852,7 @@ public: includes the terminating null.) */ int CStrSize() const { - return buffer.Size(); + return _buffer.Size(); } private: @@ -1850,25 +1861,25 @@ private: void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. void Print( const char* format, ... ); - bool elementJustOpened; - bool firstElement; - FILE* fp; - int depth; - int textDepth; - bool processEntities; - bool compactMode; + bool _elementJustOpened; + bool _firstElement; + FILE* _fp; + int _depth; + int _textDepth; + bool _processEntities; + bool _compactMode; enum { ENTITY_RANGE = 64, BUF_SIZE = 200 }; - bool entityFlag[ENTITY_RANGE]; - bool restrictedEntityFlag[ENTITY_RANGE]; + bool _entityFlag[ENTITY_RANGE]; + bool _restrictedEntityFlag[ENTITY_RANGE]; - DynArray< const char*, 10 > stack; - DynArray< char, 20 > buffer; + DynArray< const char*, 10 > _stack; + DynArray< char, 20 > _buffer; #ifdef _MSC_VER - DynArray< char, 20 > accumulator; + DynArray< char, 20 > _accumulator; #endif };