diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 1f2149f7ce..abb0134d92 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -14,21 +14,20 @@ #include "Foreach.h" #include "LuaManager.h" +const RString XNode::TEXT_ATTRIBUTE = "__TEXT__"; + XNode::XNode() { - m_pValue = new XNodeStringValue; } XNode::XNode( const RString &sName ) { m_sName = sName; - m_pValue = new XNodeStringValue; } XNode::XNode( const XNode &cpy ): m_sName( cpy.m_sName ) { - m_pValue = cpy.m_pValue->Copy(); FOREACH_CONST_Attr( &cpy, pAttr ) this->AppendAttrFrom( pAttr->first, pAttr->second->Copy() ); FOREACH_CONST_Child( &cpy, c ) @@ -38,7 +37,6 @@ XNode::XNode( const XNode &cpy ): void XNode::Clear() { Free(); - m_pValue = new XNodeStringValue; } void XNode::Free() @@ -49,8 +47,6 @@ void XNode::Free() delete pAttr->second; m_childs.clear(); m_attrs.clear(); - - SAFE_DELETE( m_pValue ); } void XNodeStringValue::GetValue( RString &out ) const { out = m_sValue; } @@ -119,7 +115,7 @@ bool XNode::PushChildValue( lua_State *L, const RString &sName ) const lua_pushnil( L ); return false; } - pChild->m_pValue->PushValue( L ); + pChild->GetAttr(XNode::TEXT_ATTRIBUTE)->PushValue( L ); return true; } diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 2d176bd329..44fa12e260 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -80,26 +80,21 @@ typedef multimap XNodes; Var##Iter != (pNode)->m_childs.end(); \ ++Var##Iter ) -// XMLNode structure class XNode { public: RString m_sName; // a duplicate of the m_sName in the parent's map - XNodeValue *m_pValue; XNodes m_childs; // child node XAttrs m_attrs; // attributes void SetName( const RString &sName ) { m_sName = sName; } const RString &GetName() const { return m_sName; } - const XNodeValue *GetTextValue() const { return m_pValue; } - XNodeValue *GetTextValue() { return m_pValue; } - void SetTextValueFrom( XNodeValue *pValue ) { delete m_pValue; m_pValue = pValue; } - + static const RString TEXT_ATTRIBUTE; template - void GetTextValue( T &out ) const { m_pValue->GetValue(out); } + void GetTextValue( T &out ) const { GetAttrValue(TEXT_ATTRIBUTE, out); } template - void SetTextValue( const T val ) { m_pValue->SetValue(val); } + void SetTextValue( const T val ) { AppendAttr(TEXT_ATTRIBUTE, val); } // in own attribute list const XNodeValue *GetAttr( const RString &sAttrName ) const; diff --git a/stepmania/src/XmlFileUtil.cpp b/stepmania/src/XmlFileUtil.cpp index 33722f8956..a03c56fcae 100644 --- a/stepmania/src/XmlFileUtil.cpp +++ b/stepmania/src/XmlFileUtil.cpp @@ -293,7 +293,7 @@ unsigned LoadInternal( XNode *pNode, const RString &xml, RString &sErrorOut, uns // open/close tag ... // ^- current pointer - if( XIsEmptyString(pNode->GetTextValue()->GetValue()) ) + if( pNode->GetAttr(XNode::TEXT_ATTRIBUTE) == NULL ) { // Text Value ++iOffset; @@ -377,7 +377,7 @@ unsigned LoadInternal( XNode *pNode, const RString &xml, RString &sErrorOut, uns } else // Alone child Tag Loaded { - if( XIsEmptyString(pNode->GetTextValue()->GetValue()) && iOffset < xml.size() && xml[iOffset] != chXMLTagOpen ) + if( pNode->GetAttr(XNode::TEXT_ATTRIBUTE) == NULL && iOffset < xml.size() && xml[iOffset] != chXMLTagOpen ) { // Text Value unsigned iEnd = xml.find( chXMLTagOpen, iOffset ); @@ -416,19 +416,20 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int WRITE( pNode->GetName() ); // m_attrs.empty() ) - WRITE( " " ); FOREACH_CONST_Attr( pNode, p ) { + if( p->first == XNode::TEXT_ATTRIBUTE ) + continue; RString attr( p->second->GetValue() ); ReplaceEntityText( attr, g_mapCharsToEntities ); + WRITE( " " ); WRITE( p->first ); WRITE( "='" ); WRITE( attr ); - WRITE( "' " ); + WRITE( "'" ); } - if( pNode->m_childs.empty() && pNode->GetTextValue()->GetValue().empty() ) + if( pNode->m_childs.empty() && pNode->GetAttr(XNode::TEXT_ATTRIBUTE) == NULL ) { // alone tag WRITE( "/>" ); @@ -446,7 +447,8 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int return false; // Text Value - if( !pNode->GetTextValue()->GetValue().empty() ) + const XNodeValue *pText = pNode->GetAttr( XNode::TEXT_ATTRIBUTE ); + if( pText != NULL ) { if( !pNode->m_childs.empty() ) { @@ -456,7 +458,7 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int WRITE( "\t" ); } RString s; - pNode->GetTextValue( s ); + pText->GetValue( s ); ReplaceEntityText( s, g_mapCharsToEntities ); WRITE( s ); } @@ -617,12 +619,9 @@ void XmlFileUtil::CompileXNodeTree( XNode *pNode, const RString &sFile ) FOREACH_Child( pNode, pChild ) aToCompile.push_back( pChild ); - XNodeValue *pValue = CompileXMLNodeValue( L, pNode->GetName(), pNode->GetTextValue(), sFile ); - pNode->SetTextValueFrom( pValue ); - FOREACH_Attr( pNode, pAttr ) { - pValue = CompileXMLNodeValue( L, pAttr->first, pAttr->second, sFile ); + XNodeValue *pValue = CompileXMLNodeValue( L, pAttr->first, pAttr->second, sFile ); delete pAttr->second; pAttr->second = pValue; } @@ -642,7 +641,7 @@ namespace XNodeLuaValue *pValue = new XNodeLuaValue; lua_pushvalue( L, -1 ); pValue->SetValueFromStack( L ); - pNode->SetTextValueFrom( pValue ); + pNode->AppendAttrFrom( XNode::TEXT_ATTRIBUTE, pValue ); } /* Iterate over the table, pulling out attributes and tables to process. */