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;
}
XMLDisplayOptions opt;
XNode *xml = CreateNode();
xml->SaveToFile( f, opt );
xml->SaveToFile( f );
delete xml;
}
+1 -4
View File
@@ -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." );
}
+1 -3
View File
@@ -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;
}
+1 -4
View File
@@ -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 );
+1 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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
+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
// 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( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" );
if( !opt.stylesheet.empty() )
f.PutLine( "<?xml-stylesheet type=\"text/xsl\" href=\"" + opt.stylesheet + "\"?>" );
if( !this->GetXML(f, opt) )
if( !opt.m_sStylesheet.empty() )
f.PutLine( "<?xml-stylesheet type=\"text/xsl\" href=\"" + opt.m_sStylesheet + "\"?>" );
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) )
+13 -12
View File
@@ -38,16 +38,14 @@ typedef multimap<RString,XNode*> 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