From ba82cc80029ec4496042cf969c8712bb02cac6b6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 6 Oct 2006 06:38:46 +0000 Subject: [PATCH] m_Value -> base pointer --- stepmania/src/XmlFile.cpp | 25 +++++++++++++++++++++---- stepmania/src/XmlFile.h | 13 +++++++------ stepmania/src/XmlFileUtil.cpp | 26 +++++++++++++++----------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 04ad738f7d..1ceb31c420 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -13,10 +13,21 @@ #include "DateTime.h" #include "Foreach.h" -XNode::XNode( const XNode &cpy ): - m_sName( cpy.m_sName ), - m_Value( cpy.m_Value ) +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->AppendAttr( pAttr->first, pAttr->second->Copy() ); FOREACH_CONST_Child( &cpy, c ) @@ -25,10 +36,16 @@ XNode::XNode( const XNode &cpy ): XNode::~XNode() { - Clear(); + Free(); } void XNode::Clear() +{ + Free(); + m_pValue = new XNodeStringValue; +} + +void XNode::Free() { FOREACH_Child( this, p ) SAFE_DELETE( p ); diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 936f9d9f83..b325e0a7f7 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -83,18 +83,18 @@ class XNode { public: RString m_sName; // a duplicate of the m_sName in the parent's map - XNodeStringValue m_Value; + 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 RString &GetValue() const { return m_Value.m_sValue; } + RString GetValue() const { return m_pValue->GetValue(); } template - void GetValue( T &out ) const { m_Value.GetValue(out); } + void GetValue( T &out ) const { m_pValue->GetValue(out); } template - void SetValue( const T val ) { m_Value.SetValue(val); } + void SetValue( const T val ) { m_pValue->SetValue(val); } // in own attribute list const XNodeValue *GetAttr( const RString &sAttrName ) const; @@ -121,14 +121,15 @@ public: XNodeValue *AppendAttr( const RString &sName, T value ) { XNodeValue *pVal = AppendAttr( sName ); pVal->SetValue( value ); return pVal; } bool RemoveAttr( const RString &sName ); - XNode() { } - explicit XNode( const RString &sName ) { m_sName = sName; } + XNode(); + explicit XNode( const RString &sName ); XNode( const XNode &cpy ); ~XNode(); void Clear(); private: + void Free(); XNode &operator=( const XNode &cpy ); // don't use }; diff --git a/stepmania/src/XmlFileUtil.cpp b/stepmania/src/XmlFileUtil.cpp index dfa57b40ac..85d3f5043b 100644 --- a/stepmania/src/XmlFileUtil.cpp +++ b/stepmania/src/XmlFileUtil.cpp @@ -295,7 +295,7 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut // open/close tag ... // ^- current pointer - if( XIsEmptyString(pNode->m_Value.m_sValue) ) + if( XIsEmptyString(pNode->m_pValue->GetValue()) ) { // Text Value ++iOffset; @@ -308,11 +308,13 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut return string::npos; } - SetString( xml, iOffset, iEnd, &pNode->m_Value.m_sValue, true ); + RString sValue; + SetString( xml, iOffset, iEnd, &sValue, true ); iOffset = iEnd; - // TEXTVALUE reference - ReplaceEntityText( pNode->m_Value.m_sValue, g_mapEntitiesToChars ); + ReplaceEntityText( sValue, g_mapEntitiesToChars ); + + pNode->m_pValue->SetValue( sValue ); } // generate child nodes @@ -371,7 +373,7 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut } else // Alone child Tag Loaded { - if( XIsEmptyString(pNode->m_Value.m_sValue) && iOffset < xml.size() && xml[iOffset] != chXMLTagOpen ) + if( XIsEmptyString(pNode->m_pValue->GetValue()) && iOffset < xml.size() && xml[iOffset] != chXMLTagOpen ) { // Text Value unsigned iEnd = xml.find( chXMLTagOpen, iOffset ); @@ -383,11 +385,12 @@ unsigned XmlFileUtil::Load( XNode *pNode, const RString &xml, RString &sErrorOut return string::npos; } - SetString( xml, iOffset, iEnd, &pNode->m_Value.m_sValue, true ); + RString sValue; + SetString( xml, iOffset, iEnd, &sValue, true ); iOffset = iEnd; - //TEXTVALUE - ReplaceEntityText( pNode->m_Value.m_sValue, g_mapEntitiesToChars ); + ReplaceEntityText( sValue, g_mapEntitiesToChars ); + pNode->m_pValue->SetValue( sValue ); } } } @@ -426,7 +429,7 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int if( !GetAttrXML(f, p->first, p->second->GetValue()) ) return false; - if( pNode->m_childs.empty() && pNode->m_Value.m_sValue.empty() ) + if( pNode->m_childs.empty() && pNode->m_pValue->GetValue().empty() ) { // alone tag if( f.Write("/>") == -1 ) @@ -446,7 +449,7 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int return false; // Text Value - if( !pNode->m_Value.m_sValue.empty() ) + if( !pNode->m_pValue->GetValue().empty() ) { if( !pNode->m_childs.empty() ) { @@ -457,7 +460,8 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int if( f.Write("\t") == -1 ) return false; } - RString s( pNode->m_Value.m_sValue ); + RString s; + pNode->m_pValue->GetValue( s ); ReplaceEntityText( s, g_mapCharsToEntities ); if( f.Write(s) == -1 ) return false;