From f73100705b157c1cb6835c888c54c7ed41c62036 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 1 Oct 2006 13:55:01 +0000 Subject: [PATCH] Simplify. --- stepmania/src/Bookkeeper.cpp | 3 +-- stepmania/src/CatalogXml.cpp | 5 +--- stepmania/src/ExportStrings.cpp | 4 +-- stepmania/src/Profile.cpp | 5 +--- stepmania/src/ScreenGameplay.cpp | 3 +-- stepmania/src/Workout.cpp | 3 +-- stepmania/src/XmlFile.cpp | 45 ++++++++++++++++++-------------- stepmania/src/XmlFile.h | 25 +++++++++--------- 8 files changed, 45 insertions(+), 48 deletions(-) diff --git a/stepmania/src/Bookkeeper.cpp b/stepmania/src/Bookkeeper.cpp index 9b68e88f9c..45a02eb46d 100644 --- a/stepmania/src/Bookkeeper.cpp +++ b/stepmania/src/Bookkeeper.cpp @@ -138,9 +138,8 @@ void Bookkeeper::WriteToDisk() return; } - XMLDisplayOptions opt; XNode *xml = CreateNode(); - xml->SaveToFile( f, opt ); + xml->SaveToFile( f ); delete xml; } diff --git a/stepmania/src/CatalogXml.cpp b/stepmania/src/CatalogXml.cpp index d9b02ee629..7730e952d9 100644 --- a/stepmania/src/CatalogXml.cpp +++ b/stepmania/src/CatalogXml.cpp @@ -392,10 +392,7 @@ void CatalogXml::Save( LoadingWindow *loading_window ) xml.AppendChild( "FooterText", FOOTER_TEXT ); xml.AppendChild( "FooterLink", FOOTER_LINK ); - XMLDisplayOptions opts; - opts.stylesheet = CATALOG_XSL; - opts.write_tabs = false; - xml.SaveToFile(fn, opts); + xml.SaveToFile( fn, XMLDisplayOptions(CATALOG_XSL, false) ); LOG->Trace( "Done." ); } diff --git a/stepmania/src/ExportStrings.cpp b/stepmania/src/ExportStrings.cpp index 94cee0353e..913af5437d 100644 --- a/stepmania/src/ExportStrings.cpp +++ b/stepmania/src/ExportStrings.cpp @@ -57,9 +57,7 @@ void ExportStrings::LuaInformation() XNode *pDateNode = pNode->AppendChild( "Date" ); pDateNode->m_sValue = DateTime::GetNowDate().GetString(); - XMLDisplayOptions disp; - disp.stylesheet = "Lua.xsl"; - pNode->SaveToFile( "Lua.xml", disp ); + pNode->SaveToFile( "Lua.xml", XMLDisplayOptions( "Lua.xsl") ); delete pNode; } diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 47bb46a4f6..7708922fd4 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -940,10 +940,7 @@ bool Profile::SaveStatsXmlToDir( RString sDir, bool bSignData ) const // Save stats.xml RString fn = sDir + STATS_XML; - XMLDisplayOptions opts; - opts.stylesheet = STATS_XSL; - opts.write_tabs = false; - bool bSaved = xml->SaveToFile( fn, opts ); + bool bSaved = xml->SaveToFile( fn, XMLDisplayOptions(STATS_XSL, false) ); SAFE_DELETE( xml ); diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 0ff52840a2..52eebd0f60 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -2592,7 +2592,6 @@ void ScreenGameplay::SaveReplay() FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi ) { XNode *p = pi->m_pPlayer->GetNoteData().CreateNode(); - XMLDisplayOptions opt; // // Find a file name for the screenshot @@ -2620,7 +2619,7 @@ void ScreenGameplay::SaveReplay() RString sFileName = ssprintf( "replay%05d.xml", iIndex ); - p->SaveToFile( "Save/"+sFileName, opt ); + p->SaveToFile( "Save/"+sFileName ); SAFE_DELETE( p ); return; } diff --git a/stepmania/src/Workout.cpp b/stepmania/src/Workout.cpp index 4f7f1b8727..885a311aa9 100644 --- a/stepmania/src/Workout.cpp +++ b/stepmania/src/Workout.cpp @@ -213,8 +213,7 @@ bool Workout::SaveToFile( RString sFile ) songGenres->AppendChild( "SongGenre", *s ); } - XMLDisplayOptions opts; - return xml.SaveToFile( sFile, opts ); + return xml.SaveToFile( sFile ); } // lua start diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 1d4671a45b..a12b031fbb 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -391,7 +391,7 @@ unsigned XNode::Load( const RString &xml, RString &sErrorOut, unsigned iOffset ) // Desc : convert plain xml text from parsed xml attirbute // Return : converted plain string -bool XNode::GetAttrXML( RageFileBasic &f, XMLDisplayOptions &opt, const RString &sName, const RString &sValue ) const +bool XNode::GetAttrXML( RageFileBasic &f, const RString &sName, const RString &sValue ) const { RString s(sValue); ReplaceEntityText( s, g_mapCharsToEntities ); @@ -400,13 +400,13 @@ bool XNode::GetAttrXML( RageFileBasic &f, XMLDisplayOptions &opt, const RString // Desc : convert plain xml text from parsed xml node // Return : converted plain string -bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const +bool XNode::GetXMLInternal( RageFileBasic &f, bool bWriteTabs, int &iTabBase ) const { // tab if( f.Write("\r\n") == -1 ) return false; - if( opt.write_tabs ) - for( int i = 0 ; i < opt.tab_base ; i++) + if( bWriteTabs ) + for( int i = 0 ; i < iTabBase ; i++) if( f.Write("\t") == -1 ) return false; @@ -419,7 +419,7 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const if( f.Write(" ") == -1 ) return false; FOREACH_CONST_Attr( this, p ) - if( !GetAttrXML(f, opt, p->first, p->second) ) + if( !GetAttrXML(f, p->first, p->second) ) return false; if( m_childs.empty() && m_sValue.empty() ) @@ -435,10 +435,10 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const return false; if( !m_childs.empty() ) - opt.tab_base++; + iTabBase++; FOREACH_CONST_Child( this, p ) - if( !p->GetXML( f, opt ) ) + if( !p->GetXMLInternal( f, bWriteTabs, iTabBase ) ) return false; // Text Value @@ -448,8 +448,8 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const { if( f.Write("\r\n") == -1 ) return false; - if( opt.write_tabs ) - for( int i = 0 ; i < opt.tab_base ; i++) + if( bWriteTabs ) + for( int i = 0 ; i < iTabBase ; i++) if( f.Write("\t") == -1 ) return false; } @@ -464,8 +464,8 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const { if( f.Write("\r\n") == -1 ) return false; - if( opt.write_tabs ) - for( int i = 0 ; i < opt.tab_base-1 ; i++) + if( bWriteTabs ) + for( int i = 0 ; i < iTabBase-1 ; i++) if( f.Write("\t") == -1 ) return false; } @@ -473,18 +473,24 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const return false; if( !m_childs.empty() ) - opt.tab_base--; + iTabBase--; } return true; } +bool XNode::GetXML( RageFileBasic &f, bool bWriteTabs ) const +{ + int iTabBase = 0; + return GetXMLInternal( f, bWriteTabs, iTabBase ); +} + // Desc : convert plain xml text from parsed xml node // Return : converted plain string RString XNode::GetXML() const { RageFileObjMem f; - XMLDisplayOptions opt; - GetXML( f, opt ); + int iTabBase = 0; + GetXMLInternal( f, true, iTabBase ); return f.GetString(); } @@ -596,19 +602,20 @@ void XNode::AppendAttr( const RString &sName, float value ){ AppendAttr(sName,ss void XNode::AppendAttr( const RString &sName, int value ) { AppendAttr(sName,ssprintf("%d",value)); } void XNode::AppendAttr( const RString &sName, unsigned value ) { AppendAttr(sName,ssprintf("%u",value)); } -bool XNode::SaveToFile( RageFileBasic &f, XMLDisplayOptions &opt ) const +bool XNode::SaveToFile( RageFileBasic &f, const XMLDisplayOptions &opt ) const { f.PutLine( "" ); - if( !opt.stylesheet.empty() ) - f.PutLine( "" ); - if( !this->GetXML(f, opt) ) + if( !opt.m_sStylesheet.empty() ) + f.PutLine( "" ); + int iTabBase = 0; + if( !this->GetXMLInternal(f, opt.m_bWriteTabs, iTabBase) ) return false; if( f.Flush() == -1 ) return false; return true; } -bool XNode::SaveToFile( const RString &sFile, XMLDisplayOptions &opt ) const +bool XNode::SaveToFile( const RString &sFile, const XMLDisplayOptions &opt ) const { RageFile f; if( !f.Open(sFile, RageFile::WRITE) ) diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index d9fa873ada..d1ceb51a8f 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -38,16 +38,14 @@ typedef multimap XNodes; // display optional environment struct XMLDisplayOptions { - RString stylesheet; // empty string = no stylesheet - bool write_tabs; // if false, don't write tab indent characters - - int tab_base; // internal usage - XMLDisplayOptions() + XMLDisplayOptions( const RString &sStylesheet = "", bool bWriteTabs = true ) { - stylesheet = ""; - write_tabs = true; - tab_base = 0; + m_sStylesheet = sStylesheet; + m_bWriteTabs = bWriteTabs; } + + RString m_sStylesheet; // empty string = no stylesheet + bool m_bWriteTabs; // if false, don't write tab indent characters }; // XMLNode structure @@ -74,12 +72,12 @@ public: // Load/Save XML unsigned Load( const RString &sXml, RString &sErrorOut, unsigned iOffset = 0 ); unsigned LoadAttributes( const RString &sAttrs, RString &sErrorOut, unsigned iOffset ); - bool GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const; - bool GetAttrXML( RageFileBasic &f, XMLDisplayOptions &opt, const RString &sName, const RString &sValue ) const; + bool GetAttrXML( RageFileBasic &f, const RString &sName, const RString &sValue ) const; + bool GetXML( RageFileBasic &f, bool bWriteTabs = true ) const; RString GetXML() const; - bool SaveToFile( const RString &sFile, XMLDisplayOptions &opt ) const; - bool SaveToFile( RageFileBasic &f, XMLDisplayOptions &opt ) const; + bool SaveToFile( const RString &sFile, const XMLDisplayOptions &opt = XMLDisplayOptions() ) const; + bool SaveToFile( RageFileBasic &f, const XMLDisplayOptions &opt = XMLDisplayOptions() ) const; // in own attribute list const RString *GetAttr( const RString &sAttrName ) const; @@ -122,6 +120,9 @@ public: ~XNode(); void Clear(); + +private: + bool GetXMLInternal( RageFileBasic &f, bool bWriteTabs, int &iTabBase ) const; }; #endif