Simplify.

This commit is contained in:
Steve Checkoway
2006-10-01 13:55:01 +00:00
parent 01cd66bd0f
commit f73100705b
8 changed files with 45 additions and 48 deletions
+1 -2
View File
@@ -138,9 +138,8 @@ void Bookkeeper::WriteToDisk()
return; return;
} }
XMLDisplayOptions opt;
XNode *xml = CreateNode(); XNode *xml = CreateNode();
xml->SaveToFile( f, opt ); xml->SaveToFile( f );
delete xml; delete xml;
} }
+1 -4
View File
@@ -392,10 +392,7 @@ void CatalogXml::Save( LoadingWindow *loading_window )
xml.AppendChild( "FooterText", FOOTER_TEXT ); xml.AppendChild( "FooterText", FOOTER_TEXT );
xml.AppendChild( "FooterLink", FOOTER_LINK ); xml.AppendChild( "FooterLink", FOOTER_LINK );
XMLDisplayOptions opts; xml.SaveToFile( fn, XMLDisplayOptions(CATALOG_XSL, false) );
opts.stylesheet = CATALOG_XSL;
opts.write_tabs = false;
xml.SaveToFile(fn, opts);
LOG->Trace( "Done." ); LOG->Trace( "Done." );
} }
+1 -3
View File
@@ -57,9 +57,7 @@ void ExportStrings::LuaInformation()
XNode *pDateNode = pNode->AppendChild( "Date" ); XNode *pDateNode = pNode->AppendChild( "Date" );
pDateNode->m_sValue = DateTime::GetNowDate().GetString(); pDateNode->m_sValue = DateTime::GetNowDate().GetString();
XMLDisplayOptions disp; pNode->SaveToFile( "Lua.xml", XMLDisplayOptions( "Lua.xsl") );
disp.stylesheet = "Lua.xsl";
pNode->SaveToFile( "Lua.xml", disp );
delete pNode; delete pNode;
} }
+1 -4
View File
@@ -940,10 +940,7 @@ bool Profile::SaveStatsXmlToDir( RString sDir, bool bSignData ) const
// Save stats.xml // Save stats.xml
RString fn = sDir + STATS_XML; RString fn = sDir + STATS_XML;
XMLDisplayOptions opts; bool bSaved = xml->SaveToFile( fn, XMLDisplayOptions(STATS_XSL, false) );
opts.stylesheet = STATS_XSL;
opts.write_tabs = false;
bool bSaved = xml->SaveToFile( fn, opts );
SAFE_DELETE( xml ); SAFE_DELETE( xml );
+1 -2
View File
@@ -2592,7 +2592,6 @@ void ScreenGameplay::SaveReplay()
FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi ) FOREACH_EnabledPlayerInfo( m_vPlayerInfo, pi )
{ {
XNode *p = pi->m_pPlayer->GetNoteData().CreateNode(); XNode *p = pi->m_pPlayer->GetNoteData().CreateNode();
XMLDisplayOptions opt;
// //
// Find a file name for the screenshot // Find a file name for the screenshot
@@ -2620,7 +2619,7 @@ void ScreenGameplay::SaveReplay()
RString sFileName = ssprintf( "replay%05d.xml", iIndex ); RString sFileName = ssprintf( "replay%05d.xml", iIndex );
p->SaveToFile( "Save/"+sFileName, opt ); p->SaveToFile( "Save/"+sFileName );
SAFE_DELETE( p ); SAFE_DELETE( p );
return; return;
} }
+1 -2
View File
@@ -213,8 +213,7 @@ bool Workout::SaveToFile( RString sFile )
songGenres->AppendChild( "SongGenre", *s ); songGenres->AppendChild( "SongGenre", *s );
} }
XMLDisplayOptions opts; return xml.SaveToFile( sFile );
return xml.SaveToFile( sFile, opts );
} }
// lua start // lua start
+26 -19
View File
@@ -391,7 +391,7 @@ unsigned XNode::Load( const RString &xml, RString &sErrorOut, unsigned iOffset )
// Desc : convert plain xml text from parsed xml attirbute // Desc : convert plain xml text from parsed xml attirbute
// Return : converted plain string // 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); RString s(sValue);
ReplaceEntityText( s, g_mapCharsToEntities ); 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 // Desc : convert plain xml text from parsed xml node
// Return : converted plain string // Return : converted plain string
bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const bool XNode::GetXMLInternal( RageFileBasic &f, bool bWriteTabs, int &iTabBase ) const
{ {
// tab // tab
if( f.Write("\r\n") == -1 ) if( f.Write("\r\n") == -1 )
return false; return false;
if( opt.write_tabs ) if( bWriteTabs )
for( int i = 0 ; i < opt.tab_base ; i++) for( int i = 0 ; i < iTabBase ; i++)
if( f.Write("\t") == -1 ) if( f.Write("\t") == -1 )
return false; return false;
@@ -419,7 +419,7 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const
if( f.Write(" ") == -1 ) if( f.Write(" ") == -1 )
return false; return false;
FOREACH_CONST_Attr( this, p ) FOREACH_CONST_Attr( this, p )
if( !GetAttrXML(f, opt, p->first, p->second) ) if( !GetAttrXML(f, p->first, p->second) )
return false; return false;
if( m_childs.empty() && m_sValue.empty() ) if( m_childs.empty() && m_sValue.empty() )
@@ -435,10 +435,10 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const
return false; return false;
if( !m_childs.empty() ) if( !m_childs.empty() )
opt.tab_base++; iTabBase++;
FOREACH_CONST_Child( this, p ) FOREACH_CONST_Child( this, p )
if( !p->GetXML( f, opt ) ) if( !p->GetXMLInternal( f, bWriteTabs, iTabBase ) )
return false; return false;
// Text Value // Text Value
@@ -448,8 +448,8 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const
{ {
if( f.Write("\r\n") == -1 ) if( f.Write("\r\n") == -1 )
return false; return false;
if( opt.write_tabs ) if( bWriteTabs )
for( int i = 0 ; i < opt.tab_base ; i++) for( int i = 0 ; i < iTabBase ; i++)
if( f.Write("\t") == -1 ) if( f.Write("\t") == -1 )
return false; return false;
} }
@@ -464,8 +464,8 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const
{ {
if( f.Write("\r\n") == -1 ) if( f.Write("\r\n") == -1 )
return false; return false;
if( opt.write_tabs ) if( bWriteTabs )
for( int i = 0 ; i < opt.tab_base-1 ; i++) for( int i = 0 ; i < iTabBase-1 ; i++)
if( f.Write("\t") == -1 ) if( f.Write("\t") == -1 )
return false; return false;
} }
@@ -473,18 +473,24 @@ bool XNode::GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const
return false; return false;
if( !m_childs.empty() ) if( !m_childs.empty() )
opt.tab_base--; iTabBase--;
} }
return true; 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 // Desc : convert plain xml text from parsed xml node
// Return : converted plain string // Return : converted plain string
RString XNode::GetXML() const RString XNode::GetXML() const
{ {
RageFileObjMem f; RageFileObjMem f;
XMLDisplayOptions opt; int iTabBase = 0;
GetXML( f, opt ); GetXMLInternal( f, true, iTabBase );
return f.GetString(); 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, int value ) { AppendAttr(sName,ssprintf("%d",value)); }
void XNode::AppendAttr( const RString &sName, unsigned value ) { AppendAttr(sName,ssprintf("%u",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( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" ); f.PutLine( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" );
if( !opt.stylesheet.empty() ) if( !opt.m_sStylesheet.empty() )
f.PutLine( "<?xml-stylesheet type=\"text/xsl\" href=\"" + opt.stylesheet + "\"?>" ); f.PutLine( "<?xml-stylesheet type=\"text/xsl\" href=\"" + opt.m_sStylesheet + "\"?>" );
if( !this->GetXML(f, opt) ) int iTabBase = 0;
if( !this->GetXMLInternal(f, opt.m_bWriteTabs, iTabBase) )
return false; return false;
if( f.Flush() == -1 ) if( f.Flush() == -1 )
return false; return false;
return true; return true;
} }
bool XNode::SaveToFile( const RString &sFile, XMLDisplayOptions &opt ) const bool XNode::SaveToFile( const RString &sFile, const XMLDisplayOptions &opt ) const
{ {
RageFile f; RageFile f;
if( !f.Open(sFile, RageFile::WRITE) ) if( !f.Open(sFile, RageFile::WRITE) )
+13 -12
View File
@@ -38,16 +38,14 @@ typedef multimap<RString,XNode*> XNodes;
// display optional environment // display optional environment
struct XMLDisplayOptions struct XMLDisplayOptions
{ {
RString stylesheet; // empty string = no stylesheet XMLDisplayOptions( const RString &sStylesheet = "", bool bWriteTabs = true )
bool write_tabs; // if false, don't write tab indent characters
int tab_base; // internal usage
XMLDisplayOptions()
{ {
stylesheet = ""; m_sStylesheet = sStylesheet;
write_tabs = true; m_bWriteTabs = bWriteTabs;
tab_base = 0;
} }
RString m_sStylesheet; // empty string = no stylesheet
bool m_bWriteTabs; // if false, don't write tab indent characters
}; };
// XMLNode structure // XMLNode structure
@@ -74,12 +72,12 @@ public:
// Load/Save XML // Load/Save XML
unsigned Load( const RString &sXml, RString &sErrorOut, unsigned iOffset = 0 ); unsigned Load( const RString &sXml, RString &sErrorOut, unsigned iOffset = 0 );
unsigned LoadAttributes( const RString &sAttrs, RString &sErrorOut, unsigned iOffset ); unsigned LoadAttributes( const RString &sAttrs, RString &sErrorOut, unsigned iOffset );
bool GetXML( RageFileBasic &f, XMLDisplayOptions &opt ) const; bool GetAttrXML( RageFileBasic &f, const RString &sName, const RString &sValue ) const;
bool GetAttrXML( RageFileBasic &f, XMLDisplayOptions &opt, const RString &sName, const RString &sValue ) const; bool GetXML( RageFileBasic &f, bool bWriteTabs = true ) const;
RString GetXML() const; RString GetXML() const;
bool SaveToFile( const RString &sFile, XMLDisplayOptions &opt ) const; bool SaveToFile( const RString &sFile, const XMLDisplayOptions &opt = XMLDisplayOptions() ) const;
bool SaveToFile( RageFileBasic &f, XMLDisplayOptions &opt ) const; bool SaveToFile( RageFileBasic &f, const XMLDisplayOptions &opt = XMLDisplayOptions() ) const;
// in own attribute list // in own attribute list
const RString *GetAttr( const RString &sAttrName ) const; const RString *GetAttr( const RString &sAttrName ) const;
@@ -122,6 +120,9 @@ public:
~XNode(); ~XNode();
void Clear(); void Clear();
private:
bool GetXMLInternal( RageFileBasic &f, bool bWriteTabs, int &iTabBase ) const;
}; };
#endif #endif