merge IniFile and XmlFile

This commit is contained in:
Chris Danford
2005-01-07 14:28:00 +00:00
parent 5b2582cab3
commit 981e52ec58
27 changed files with 427 additions and 509 deletions
+17 -21
View File
@@ -27,26 +27,23 @@ Actor* LoadFromActorFile( const CString &sIniPath, const CString &sLayer )
if( !ini.ReadFile( sIniPath ) )
RageException::Throw( "%s", ini.GetError().c_str() );
if( !ini.GetKey(sLayer) )
RageException::Throw( "The file '%s' doesn't have layer '%s'.", sIniPath.c_str(), sLayer.c_str() );
CString sDir = Dirname( sIniPath );
const IniFile::key* k = ini.GetKey( sLayer );
if( k == NULL )
const XNode* pLayer = ini.GetChild(sLayer);
if( pLayer == NULL )
RageException::Throw( "The file '%s' doesn't have layer '%s'.", sIniPath.c_str(), sLayer.c_str() );
return LoadFromActorFile( sDir, *k );
return LoadFromActorFile( sDir, *pLayer );
}
Actor* LoadFromActorFile( const CString& sAniDir, const IniKey& layer )
Actor* LoadFromActorFile( const CString& sAniDir, const XNode& layer )
{
Actor* pActor = NULL; // fill this in before we return;
CString sType;
layer.GetValue( "Type", sType );
layer.GetAttrValue( "Type", sType );
CString sFile;
layer.GetValue( "File", sFile );
layer.GetAttrValue( "File", sFile );
FixSlashesInPlace( sFile );
if( sType == "SongCreditDisplay" )
@@ -72,14 +69,14 @@ Actor* LoadFromActorFile( const CString& sAniDir, const IniKey& layer )
sAniDir.c_str() );
CString text;
if( layer.GetValue("Text", text) )
if( layer.GetAttrValue("Text", text) )
{
/* It's a BitmapText. Note that we could do the actual text setting with metrics,
* by adding "text" and "alttext" commands, but right now metrics can't contain
* commas or semicolons. It's useful to be able to refer to fonts in the real
* theme font dirs, too. */
CString alttext;
layer.GetValue("AltText", alttext );
layer.GetAttrValue("AltText", alttext );
text.Replace( "::", "\n" );
alttext.Replace( "::", "\n" );
@@ -233,27 +230,26 @@ retry:
}
float f;
if( layer.GetValue( "BaseRotationXDegrees", f ) ) pActor->SetBaseRotationX( f );
if( layer.GetValue( "BaseRotationYDegrees", f ) ) pActor->SetBaseRotationY( f );
if( layer.GetValue( "BaseRotationZDegrees", f ) ) pActor->SetBaseRotationZ( f );
if( layer.GetValue( "BaseZoomX", f ) ) pActor->SetBaseZoomX( f );
if( layer.GetValue( "BaseZoomY", f ) ) pActor->SetBaseZoomY( f );
if( layer.GetValue( "BaseZoomZ", f ) ) pActor->SetBaseZoomZ( f );
if( layer.GetAttrValue( "BaseRotationXDegrees", f ) ) pActor->SetBaseRotationX( f );
if( layer.GetAttrValue( "BaseRotationYDegrees", f ) ) pActor->SetBaseRotationY( f );
if( layer.GetAttrValue( "BaseRotationZDegrees", f ) ) pActor->SetBaseRotationZ( f );
if( layer.GetAttrValue( "BaseZoomX", f ) ) pActor->SetBaseZoomX( f );
if( layer.GetAttrValue( "BaseZoomY", f ) ) pActor->SetBaseZoomY( f );
if( layer.GetAttrValue( "BaseZoomZ", f ) ) pActor->SetBaseZoomZ( f );
//
// Load commands
//
for( IniKey::const_iterator i = layer.begin();
i != layer.end(); ++i)
FOREACH_CONST_Attr( &layer, a )
{
CString KeyName = i->first; /* "OnCommand" */
CString KeyName = a->m_sName; /* "OnCommand" */
KeyName.MakeLower();
if( KeyName.Right(7) != "command" )
continue; /* not a command */
const CString &sCommands = i->second;
const CString &sCommands = a->m_sValue;
Commands cmds = ParseCommands( sCommands );
CString sCmdName;
/* Special case: "Command=foo" -> "OnCommand=foo" */
+2 -2
View File
@@ -4,7 +4,7 @@
#include "Actor.h"
#include "RageTexture.h"
class IniKey;
struct XNode;
#define SET_XY( actor ) UtilSetXY( actor, m_sName )
#define ON_COMMAND( actor ) UtilOnCommand( actor, m_sName )
@@ -34,7 +34,7 @@ inline void UtilSetXYAndOnCommand( Actor* pActor, const CString &sScreenName ) {
// Return a Sprite, BitmapText, or Model depending on the file type
Actor* LoadFromActorFile( const CString &sIniPath, const CString &sLayer = "Actor" );
Actor* LoadFromActorFile( const CString& sAniDir, const IniKey& layer );
Actor* LoadFromActorFile( const CString& sAniDir, const XNode& layer );
Actor* MakeActor( const RageTextureID &ID );
+7 -7
View File
@@ -77,10 +77,10 @@ void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &layersAddTo, bool Gen
{
vector<CString> vsLayerNames;
for( IniFile::const_iterator iter = ini.begin(); iter != ini.end(); iter++ )
FOREACH_CONST_Child( &ini, pLayer )
{
if( strncmp(iter->first, "Layer", 5) == 0 )
vsLayerNames.push_back( iter->first );
if( strncmp(pLayer->m_sName, "Layer", 5) == 0 )
vsLayerNames.push_back( pLayer->m_sName );
}
sort( vsLayerNames.begin(), vsLayerNames.end(), CompareLayerNames );
@@ -88,15 +88,15 @@ void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &layersAddTo, bool Gen
FOREACH_CONST( CString, vsLayerNames, s )
{
const CString sLayer = *s;
const IniFile::key* pKey = ini.GetKey( sLayer );
const CString &sLayer = *s;
const XNode* pKey = ini.GetChild( sLayer );
ASSERT( pKey );
CString sImportDir;
if( ini.GetValue(sLayer, "Import", sImportDir) )
if( pKey->GetAttrValue("Import", sImportDir) )
{
CString expr;
if( ini.GetValue(sLayer,"Condition",expr) )
if( pKey->GetAttrValue("Condition",expr) )
{
if( !Lua::RunExpressionB( expr ) )
continue;
+33 -33
View File
@@ -395,7 +395,7 @@ void BGAnimationLayer::LoadFromAniLayerFile( const CString& sPath )
m_SubActors[i]->SetBlendMode( BLEND_ADD );
}
void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const IniKey& layer )
void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const XNode& layer )
{
CString sAniDir = sAniDir_;
@@ -410,13 +410,13 @@ void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const IniKey& layer
{
CString sPlayer;
if( layer.GetValue("Player", sPlayer) )
if( layer.GetAttrValue("Player", sPlayer) )
ASSERT_M( 0, "The BGAnimation parameter 'Player' is deprecated. Please use 'Condition=IsPlayerEnabled(p)'." );
}
{
CString expr;
if( layer.GetValue("Cond",expr) || layer.GetValue("Condition",expr) )
if( layer.GetAttrValue("Cond",expr) || layer.GetAttrValue("Condition",expr) )
{
if( !Lua::RunExpressionB( expr ) )
return;
@@ -426,12 +426,12 @@ void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const IniKey& layer
bool bStretch = false;
{
CString type = "sprite";
layer.GetValue( "Type", type );
layer.GetAttrValue( "Type", type );
type.MakeLower();
/* The preferred way of stretching a sprite to fit the screen is "Type=sprite"
* and "stretch=1". "type=1" is for backwards-compatibility. */
layer.GetValue( "Stretch", bStretch );
layer.GetAttrValue( "Stretch", bStretch );
// Check for string match first, then do integer match.
// "if(atoi(type)==0)" was matching against all string matches.
@@ -467,34 +467,34 @@ void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const IniKey& layer
}
}
layer.GetValue( "CommandRepeatSeconds", m_fRepeatCommandEverySeconds );
layer.GetAttrValue( "CommandRepeatSeconds", m_fRepeatCommandEverySeconds );
m_fSecondsUntilNextCommand = m_fRepeatCommandEverySeconds;
layer.GetValue( "FOV", m_fFOV );
layer.GetValue( "Lighting", m_bLighting );
layer.GetValue( "TexCoordVelocityX", m_fTexCoordVelocityX );
layer.GetValue( "TexCoordVelocityY", m_fTexCoordVelocityY );
layer.GetValue( "DrawCond", m_sDrawCond );
layer.GetAttrValue( "FOV", m_fFOV );
layer.GetAttrValue( "Lighting", m_bLighting );
layer.GetAttrValue( "TexCoordVelocityX", m_fTexCoordVelocityX );
layer.GetAttrValue( "TexCoordVelocityY", m_fTexCoordVelocityY );
layer.GetAttrValue( "DrawCond", m_sDrawCond );
// compat:
layer.GetValue( "StretchTexCoordVelocityX", m_fTexCoordVelocityX );
layer.GetValue( "StretchTexCoordVelocityY", m_fTexCoordVelocityY );
layer.GetValue( "ZoomMin", m_fZoomMin );
layer.GetValue( "ZoomMax", m_fZoomMax );
layer.GetValue( "VelocityXMin", m_fVelocityXMin );
layer.GetValue( "VelocityXMax", m_fVelocityXMax );
layer.GetValue( "VelocityYMin", m_fVelocityYMin );
layer.GetValue( "VelocityYMax", m_fVelocityYMax );
layer.GetValue( "VelocityZMin", m_fVelocityZMin );
layer.GetValue( "VelocityZMax", m_fVelocityZMax );
layer.GetValue( "OverrideSpeed", m_fOverrideSpeed );
layer.GetValue( "NumParticles", m_iNumParticles );
layer.GetValue( "ParticlesBounce", m_bParticlesBounce );
layer.GetValue( "TilesStartX", m_fTilesStartX );
layer.GetValue( "TilesStartY", m_fTilesStartY );
layer.GetValue( "TilesSpacingX", m_fTilesSpacingX );
layer.GetValue( "TilesSpacingY", m_fTilesSpacingY );
layer.GetValue( "TileVelocityX", m_fTileVelocityX );
layer.GetValue( "TileVelocityY", m_fTileVelocityY );
layer.GetAttrValue( "StretchTexCoordVelocityX", m_fTexCoordVelocityX );
layer.GetAttrValue( "StretchTexCoordVelocityY", m_fTexCoordVelocityY );
layer.GetAttrValue( "ZoomMin", m_fZoomMin );
layer.GetAttrValue( "ZoomMax", m_fZoomMax );
layer.GetAttrValue( "VelocityXMin", m_fVelocityXMin );
layer.GetAttrValue( "VelocityXMax", m_fVelocityXMax );
layer.GetAttrValue( "VelocityYMin", m_fVelocityYMin );
layer.GetAttrValue( "VelocityYMax", m_fVelocityYMax );
layer.GetAttrValue( "VelocityZMin", m_fVelocityZMin );
layer.GetAttrValue( "VelocityZMax", m_fVelocityZMax );
layer.GetAttrValue( "OverrideSpeed", m_fOverrideSpeed );
layer.GetAttrValue( "NumParticles", m_iNumParticles );
layer.GetAttrValue( "ParticlesBounce", m_bParticlesBounce );
layer.GetAttrValue( "TilesStartX", m_fTilesStartX );
layer.GetAttrValue( "TilesStartY", m_fTilesStartY );
layer.GetAttrValue( "TilesSpacingX", m_fTilesSpacingX );
layer.GetAttrValue( "TilesSpacingY", m_fTilesSpacingY );
layer.GetAttrValue( "TileVelocityX", m_fTileVelocityX );
layer.GetAttrValue( "TileVelocityY", m_fTileVelocityY );
bool NeedTextureStretch = false;
@@ -522,7 +522,7 @@ void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const IniKey& layer
case TYPE_PARTICLES:
{
CString sFile;
layer.GetValue( "File", sFile );
layer.GetAttrValue( "File", sFile );
FixSlashesInPlace( sFile );
CString sPath = sAniDir+sFile;
@@ -552,7 +552,7 @@ void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const IniKey& layer
case TYPE_TILES:
{
CString sFile;
layer.GetValue( "File", sFile );
layer.GetAttrValue( "File", sFile );
FixSlashesInPlace( sFile );
CString sPath = sAniDir+sFile;
@@ -585,7 +585,7 @@ void BGAnimationLayer::LoadFromIni( const CString& sAniDir_, const IniKey& layer
}
bool bStartOnRandomFrame = false;
layer.GetValue( "StartOnRandomFrame", bStartOnRandomFrame );
layer.GetAttrValue( "StartOnRandomFrame", bStartOnRandomFrame );
if( bStartOnRandomFrame )
{
for( unsigned i=0; i<m_SubActors.size(); i++ )
+2 -2
View File
@@ -7,7 +7,7 @@
#include "ActorFrame.h"
#include <map>
class IniKey;
struct XNode;
class BGAnimationLayer : public ActorFrame
{
@@ -21,7 +21,7 @@ public:
void LoadFromAniLayerFile( const CString& sPath );
void LoadFromMovie( const CString& sMoviePath );
void LoadFromVisualization( const CString& sMoviePath );
void LoadFromIni( const CString& sAniDir, const IniKey& layer );
void LoadFromIni( const CString& sAniDir, const XNode& layer );
void Update( float fDeltaTime );
void DrawPrimitives();
+1 -1
View File
@@ -36,7 +36,7 @@ void SaveCatalogXml()
LOG->Trace( "Writing %s ...", fn.c_str() );
XNode xml;
xml.name = "Catalog";
xml.m_sName = "Catalog";
{
bool ShowStepsType[NUM_STEPS_TYPES];
+2 -2
View File
@@ -220,7 +220,7 @@ Course *CourseID::ToCourse() const
XNode* CourseID::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Course";
pNode->m_sName = "Course";
if( !sPath.empty() )
pNode->AppendAttr( "Path", sPath );
@@ -232,7 +232,7 @@ XNode* CourseID::CreateNode() const
void CourseID::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "Course" );
ASSERT( pNode->m_sName == "Course" );
pNode->GetAttrValue("Path", sPath);
pNode->GetAttrValue("FullTitle", sFullTitle);
}
+22 -22
View File
@@ -475,25 +475,25 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
ini.GetValue( PageName, "TextureHints", cfg.TextureHints );
/* Iterate over all keys. */
const IniFile::key *k = ini.GetKey(PageName);
if( k )
const XNode* pNode = ini.GetChild( PageName );
if( pNode )
{
for(IniFile::key::const_iterator key = k->begin(); key != k->end(); ++key)
FOREACH_CONST_Attr( pNode, pAttr )
{
CString val = key->first;
CString data = key->second;
CString name = pAttr->m_sName;
const CString &value = pAttr->m_sValue;
val.MakeUpper();
name.MakeUpper();
/* If val is an integer, it's a width, eg. "10=27". */
if(IsAnInt(val))
if(IsAnInt(name))
{
cfg.GlyphWidths[atoi(val)] = atoi(data);
cfg.GlyphWidths[atoi(name)] = atoi(value);
continue;
}
/* "map codepoint=frame" maps a char to a frame. */
if(val.substr(0, 4) == "MAP ")
if(name.substr(0, 4) == "MAP ")
{
/* map CODEPOINT=frame. CODEPOINT can be
* 1. U+hexval
@@ -504,7 +504,7 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
* map 1=2 is the same as
* range unicode #1-1=2
*/
CString codepoint = val.substr(4); /* "CODEPOINT" */
CString codepoint = name.substr(4); /* "CODEPOINT" */
const Game* pGame = NULL;
@@ -534,21 +534,21 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
c = utf8_get_char(codepoint.c_str());
if(c == wchar_t(-1))
LOG->Warn("Font definition '%s' has an invalid value '%s'.",
ini.GetPath().c_str(), val.c_str() );
ini.GetPath().c_str(), name.c_str() );
}
else if(!FontCharAliases::GetChar(codepoint, c))
{
LOG->Warn("Font definition '%s' has an invalid value '%s'.",
ini.GetPath().c_str(), val.c_str() );
ini.GetPath().c_str(), name.c_str() );
continue;
}
cfg.CharToGlyphNo[c] = atoi(data);
cfg.CharToGlyphNo[c] = atoi(value);
continue;
}
if(val.substr(0, 6) == "RANGE ")
if(name.substr(0, 6) == "RANGE ")
{
/* range CODESET=first_frame or
* range CODESET #start-end=first_frame
@@ -567,13 +567,13 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
*/
vector<CString> matches;
static Regex parse("^RANGE ([A-Z\\-]+)( ?#([0-9A-F]+)-([0-9A-F]+))?$");
bool match = parse.Compare(val, matches);
bool match = parse.Compare(name, matches);
ASSERT(matches.size() == 4); /* 4 parens */
if(!match || matches[0].empty())
RageException::Throw("Font definition '%s' has an invalid range '%s': parse error",
ini.GetPath().c_str(), val.c_str() );
ini.GetPath().c_str(), name.c_str() );
/* We must have either 1 match (just the codeset) or 4 (the whole thing). */
@@ -586,20 +586,20 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
sscanf(matches[3].c_str(), "%x", &last);
if(last < first)
RageException::Throw("Font definition '%s' has an invalid range '%s': %i < %i.",
ini.GetPath().c_str(), val.c_str(), last < first );
ini.GetPath().c_str(), name.c_str(), last < first );
cnt = last-first+1;
}
CString ret = cfg.MapRange(matches[0], first, atoi(data), cnt);
CString ret = cfg.MapRange(matches[0], first, atoi(value), cnt);
if(!ret.empty())
RageException::Throw("Font definition '%s' has an invalid range '%s': %s.",
ini.GetPath().c_str(), val.c_str(), ret.c_str() );
ini.GetPath().c_str(), name.c_str(), ret.c_str() );
continue;
}
if(val.substr(0, 5) == "LINE ")
if(name.substr(0, 5) == "LINE ")
{
/* line ROW=CHAR1CHAR2CHAR3CHAR4
* eg.
@@ -607,7 +607,7 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
*
* This lets us assign characters very compactly and readably. */
CString row_str = val.substr(5);
CString row_str = name.substr(5);
ASSERT(IsAnInt(row_str));
const int row = atoi(row_str.c_str());
const int first_frame = row * NumFramesWide;
@@ -617,7 +617,7 @@ void Font::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, const CStri
ini.GetPath().c_str(), first_frame, NumFramesHigh);
/* Decode the string. */
const wstring wdata(CStringToWstring(data));
const wstring wdata(CStringToWstring(value));
if(int(wdata.size()) > NumFramesWide)
RageException::Throw("The font definition \"%s\" assigns %i characters to row %i (\"%ls\"), but the font only has %i characters wide",
+8 -8
View File
@@ -36,7 +36,7 @@ bool HighScore::operator>=( const HighScore& other ) const
XNode* HighScore::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "HighScore";
pNode->m_sName = "HighScore";
// TRICKY: Don't write "name to fill in" markers.
pNode->AppendChild( "Name", IsRankingToFillIn(sName) ? CString("") : sName );
@@ -64,7 +64,7 @@ XNode* HighScore::CreateNode() const
void HighScore::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "HighScore" );
ASSERT( pNode->m_sName == "HighScore" );
CString s;
@@ -151,7 +151,7 @@ const HighScore& HighScoreList::GetTopScore() const
XNode* HighScoreList::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "HighScoreList";
pNode->m_sName = "HighScoreList";
pNode->AppendChild( "NumTimesPlayed", iNumTimesPlayed );
@@ -168,14 +168,14 @@ void HighScoreList::LoadFromNode( const XNode* pHighScoreList )
{
Init();
ASSERT( pHighScoreList->name == "HighScoreList" );
ASSERT( pHighScoreList->m_sName == "HighScoreList" );
FOREACH_CONST_Child( pHighScoreList, p )
{
if( p->name == "NumTimesPlayed" )
if( p->m_sName == "NumTimesPlayed" )
{
p->GetValue( iNumTimesPlayed );
}
else if( p->name == "HighScore" )
else if( p->m_sName == "HighScore" )
{
vHighScores.resize( vHighScores.size()+1 );
vHighScores.back().LoadFromNode( p );
@@ -190,7 +190,7 @@ void HighScoreList::LoadFromNode( const XNode* pHighScoreList )
XNode* Screenshot::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Screenshot";
pNode->m_sName = "Screenshot";
// TRICKY: Don't write "name to fill in" markers.
pNode->AppendChild( "FileName", sFileName );
@@ -202,7 +202,7 @@ XNode* Screenshot::CreateNode() const
void Screenshot::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "Screenshot" );
ASSERT( pNode->m_sName == "Screenshot" );
pNode->GetChildValue( "FileName", sFileName );
pNode->GetChildValue( "MD5", sMD5 );
+55 -105
View File
@@ -3,6 +3,7 @@
#include "RageUtil.h"
#include "RageLog.h"
#include "RageFile.h"
#include "Foreach.h"
bool IniFile::ReadFile( const CString &sPath )
{
@@ -61,7 +62,7 @@ bool IniFile::ReadFile( RageFileBasic &f )
}
}
bool IniFile::WriteFile( const CString &sPath )
bool IniFile::WriteFile( const CString &sPath ) const
{
RageFile f;
if( !f.Open( sPath, RageFile::WRITE ) )
@@ -74,22 +75,22 @@ bool IniFile::WriteFile( const CString &sPath )
return IniFile::WriteFile( f );
}
bool IniFile::WriteFile( RageFileBasic &f )
bool IniFile::WriteFile( RageFileBasic &f ) const
{
for( keymap::const_iterator k = keys.begin(); k != keys.end(); ++k )
FOREACH_CONST_Child( this, pKey )
{
if( k->second.empty() )
continue;
if( f.PutLine( ssprintf("[%s]", k->first.c_str()) ) == -1 )
if( f.PutLine( ssprintf("[%s]", pKey->m_sName.c_str()) ) == -1 )
{
m_sError = f.GetError();
return false;
}
for( key::const_iterator i = k->second.begin(); i != k->second.end(); ++i )
f.PutLine( ssprintf("%s=%s", i->first.c_str(), i->second.c_str()) );
FOREACH_CONST_Attr( pKey, pAttr )
{
f.PutLine( ssprintf("%s=%s", pAttr->m_sName.c_str(), pAttr->m_sValue.c_str()) );
m_sError = f.GetError();
return false;
}
if( f.PutLine( "" ) == -1 )
{
@@ -100,68 +101,35 @@ bool IniFile::WriteFile( RageFileBasic &f )
return true;
}
void IniFile::Reset()
{
keys.clear();
}
int IniFile::GetNumKeys() const
{
return keys.size();
}
int IniFile::GetNumValues( const CString &keyname ) const
{
keymap::const_iterator k = keys.find(keyname);
if( k == keys.end() )
return -1;
return k->second.size();
}
bool IniKey::GetValue( const CString &valuename, CString& value ) const
{
const_iterator i = find(valuename);
if( i == end() )
return false;
value = i->second;
return true;
}
bool IniKey::SetValue( const CString &valuename, const CString &value )
{
(*this)[valuename] = value;
return true;
}
bool IniFile::GetValue( const CString &keyname, const CString &valuename, CString& value ) const
{
keymap::const_iterator k = keys.find(keyname);
if (k == keys.end())
const XNode* pNode = GetChild( keyname );
if( pNode == NULL )
return false;
return k->second.GetValue( valuename, value );
return pNode->GetAttrValue( valuename, value );
}
bool IniFile::SetValue( const CString &keyname, const CString &valuename, const CString &value )
void IniFile::SetValue( const CString &keyname, const CString &valuename, const CString &value )
{
keys[keyname].SetValue( valuename, value );
return true;
XNode* pNode = GetChild( keyname );
if( pNode == NULL )
pNode = AppendChild( keyname );
pNode->SetAttrValue( valuename, value );
}
bool IniFile::DeleteValue(const CString &keyname, const CString &valuename)
{
XNode* pNode = GetChild( keyname );
if( pNode == NULL )
return false;
XAttr* pAttr = pNode->GetAttr( valuename );
if( pAttr == NULL )
return false;
return pNode->RemoveAttr( pAttr );
}
#define TYPE(T) \
bool IniKey::GetValue( const CString &valuename, T &value ) const \
{ \
CString sValue; \
if( !GetValue(valuename,sValue) ) \
return false; \
return FromString( sValue, value ); \
} \
bool IniKey::SetValue( const CString &valuename, T value ) \
{ \
return SetValue( valuename, ToString(value) ); \
} \
bool IniFile::GetValue( const CString &keyname, const CString &valuename, T &value ) const \
{ \
CString sValue; \
@@ -169,9 +137,9 @@ bool IniFile::SetValue( const CString &keyname, const CString &valuename, const
return false; \
return FromString( sValue, value ); \
} \
bool IniFile::SetValue( const CString &keyname, const CString &valuename, T value ) \
void IniFile::SetValue( const CString &keyname, const CString &valuename, T value ) \
{ \
return SetValue( keyname, valuename, ToString(value) ); \
SetValue( keyname, valuename, ToString(value) ); \
}
TYPE(int);
@@ -179,54 +147,36 @@ TYPE(unsigned);
TYPE(float);
TYPE(bool);
bool IniFile::DeleteValue(const CString &keyname, const CString &valuename)
{
keymap::iterator k = keys.find(keyname);
if( k == keys.end() )
return false;
key::iterator i = k->second.find(valuename);
if( i == k->second.end() )
return false;
k->second.erase(i);
return true;
}
bool IniFile::DeleteKey(const CString &keyname)
{
keymap::iterator k = keys.find(keyname);
if( k == keys.end() )
XNode* pNode = GetChild( keyname );
if( pNode == NULL )
return false;
return RemoveChild( pNode );
}
bool IniFile::RenameKey(const CString &from, const CString &to)
{
/* If to already exists, do nothing. */
XNode* pTo = GetChild( to );
if( pTo )
return false;
keys.erase(k);
multimap<CString, XNode*>::iterator it = m_childs.find( from );
if( it == m_childs.end() )
return false;
XNode* pNode = it->second;
m_childs.erase( it );
pNode->m_sName = to;
m_childs.insert( pair<CString,XNode*>(pNode->m_sName,pNode) );
return true;
}
const IniKey *IniFile::GetKey(const CString &keyname) const
{
keymap::const_iterator i = keys.find(keyname);
if( i == keys.end() )
return NULL;
return &i->second;
}
void IniFile::SetValue(const CString &keyname, const key &key)
{
keys[keyname] = key;
}
void IniFile::RenameKey(const CString &from, const CString &to)
{
if( keys.find(from) == keys.end() )
return;
if( keys.find(to) != keys.end() )
return;
keys[to] = keys[from];
keys.erase(from);
}
/*
* (c) 2001-2004 Adam Clauss, Chris Danford
+10 -48
View File
@@ -3,47 +3,16 @@
#ifndef INIFILE_H
#define INIFILE_H
#include <map>
#include "XmlFile.h"
using namespace std;
class RageFileBasic;
class IniKey : public map<CString, CString>
class IniFile : public XNode
{
public:
bool GetValue( const CString &valuename, CString& value ) const;
bool GetValue( const CString &valuename, int& value ) const;
bool GetValue( const CString &valuename, unsigned& value ) const;
bool GetValue( const CString &valuename, float& value ) const;
bool GetValue( const CString &valuename, bool& value ) const;
bool SetValue( const CString &valuename, const CString &value );
bool SetValue( const CString &valuename, int value );
bool SetValue( const CString &valuename, unsigned value );
bool SetValue( const CString &valuename, float value );
bool SetValue( const CString &valuename, bool value );
};
class IniFile
{
public:
// all keys are of this type
typedef IniKey key;
typedef map<CString, key> keymap;
typedef keymap::const_iterator const_iterator;
const_iterator begin() const { return keys.begin(); }
const_iterator end() const { return keys.end(); }
typedef keymap::iterator iterator;
iterator begin() { return keys.begin(); }
iterator end() { return keys.end(); }
private:
CString m_sPath;
keymap keys;
mutable CString m_sError;
public:
@@ -53,12 +22,8 @@ public:
bool ReadFile( const CString &sPath );
bool ReadFile( RageFileBasic &sFile );
bool WriteFile( const CString &sPath );
bool WriteFile( RageFileBasic &sFile );
void Reset();
int GetNumKeys() const;
int GetNumValues( const CString &keyname ) const;
bool WriteFile( const CString &sPath ) const;
bool WriteFile( RageFileBasic &sFile ) const;
bool GetValue( const CString &key, const CString &valuename, CString& value ) const;
bool GetValue( const CString &key, const CString &valuename, int& value ) const;
@@ -66,22 +31,19 @@ public:
bool GetValue( const CString &key, const CString &valuename, float& value ) const;
bool GetValue( const CString &key, const CString &valuename, bool& value ) const;
bool SetValue( const CString &key, const CString &valuename, const CString &value );
bool SetValue( const CString &key, const CString &valuename, int value );
bool SetValue( const CString &key, const CString &valuename, unsigned value );
bool SetValue( const CString &key, const CString &valuename, float value );
bool SetValue( const CString &key, const CString &valuename, bool value );
void SetValue( const CString &key, const CString &valuename, const CString &value );
void SetValue( const CString &key, const CString &valuename, int value );
void SetValue( const CString &key, const CString &valuename, unsigned value );
void SetValue( const CString &key, const CString &valuename, float value );
void SetValue( const CString &key, const CString &valuename, bool value );
bool DeleteKey( const CString &keyname );
bool DeleteValue( const CString &keyname, const CString &valuename );
const key *GetKey( const CString &keyname ) const;
void SetValue( const CString &keyname, const key &key );
/* Rename a key. For example, call RenameKey("foo", "main") after
* reading an INI where [foo] is an alias to [main]. If to already
* exists, nothing happens. */
void RenameKey( const CString &from, const CString &to );
bool RenameKey( const CString &from, const CString &to );
};
#endif
+4 -5
View File
@@ -396,15 +396,14 @@ void InputMapper::ReadMappingsFromDisk()
if( !ini.ReadFile( KEYMAPS_PATH ) )
LOG->Trace( "Couldn't open mapping file \"%s\": %s.", KEYMAPS_PATH, ini.GetError().c_str() );
const IniFile::key *Key = ini.GetKey( GAMESTATE->GetCurrentGame()->m_szName );
const XNode *Key = ini.GetChild( GAMESTATE->GetCurrentGame()->m_szName );
if( Key )
{
for( IniFile::key::const_iterator i = Key->begin();
i != Key->end(); ++i )
FOREACH_CONST_Child( Key, i )
{
CString name = i->first;
CString value = i->second;
const CString &name = i->m_sName;
const CString &value = i->m_sValue;
GameInput GameI;
GameI.fromString( name );
+6 -5
View File
@@ -41,11 +41,12 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
if( !ini.ReadFile( sTexOrIniPath ) )
RageException::Throw( "Error reading %s: %s", sTexOrIniPath.c_str(), ini.GetError().c_str() );
if( !ini.GetKey("AnimatedTexture") )
const XNode* pAnimatedTexture = ini.GetChild("AnimatedTexture");
if( pAnimatedTexture == NULL )
RageException::Throw( "The animated texture file '%s' doesn't contain a section called 'AnimatedTexture'.", sTexOrIniPath.c_str() );
ini.GetValue( "AnimatedTexture", "TexVelocityX", m_fTexVelocityX );
ini.GetValue( "AnimatedTexture", "TexVelocityY", m_fTexVelocityY );
pAnimatedTexture->GetAttrValue( "TexVelocityX", m_fTexVelocityX );
pAnimatedTexture->GetAttrValue( "TexVelocityY", m_fTexVelocityY );
for( int i=0; i<1000; i++ )
{
@@ -54,8 +55,8 @@ void AnimatedTexture::Load( CString sTexOrIniPath )
CString sFileName;
float fDelay = 0;
if( ini.GetValue( "AnimatedTexture", sFileKey, sFileName ) &&
ini.GetValue( "AnimatedTexture", sDelayKey, fDelay ) )
if( pAnimatedTexture->GetAttrValue( sFileKey, sFileName ) &&
pAnimatedTexture->GetAttrValue( sDelayKey, fDelay ) )
{
RageTextureID ID;
ID.filename = Dirname(sTexOrIniPath) + sFileName;
+29 -28
View File
@@ -12,6 +12,7 @@
#include "Game.h"
#include "ScreenDimensions.h"
#include "PlayerState.h"
#include "XmlFile.h"
/* Copies of the current mode. Update this by calling Load. */
NoteFieldMode g_NoteFieldMode[NUM_PLAYERS];
@@ -50,51 +51,49 @@ void NoteFieldMode::EndDrawTrack(int tn)
}
template <class T>
static bool GetValue(IniFile &ini, int pn,
const CString &key, const CString &valuename, T &value )
static bool GetValue(const XNode *pNode, int pn, const CString &valuename, T &value )
{
if(pn != -1 && ini.GetValue(key, ssprintf("P%i%s", pn+1, valuename.c_str()), value))
if(pn != -1 && pNode->GetAttrValue( ssprintf("P%i%s", pn+1, valuename.c_str()), value))
return true;
return ini.GetValue(key, valuename, value);
return pNode->GetAttrValue( valuename, value );
}
void NoteFieldMode::Load(IniFile &ini, CString id, int pn)
void NoteFieldMode::Load(const XNode *pNode, int pn)
{
m_Id = id;
m_Id = pNode->m_sName;
/* Required: */
ASSERT( ini.GetValue ( id, "Name", m_Name ) );
ASSERT( pNode->GetAttrValue("Name", m_Name ) );
// if we aren't loading a player, we can bail here.
if(pn == -1)
return;
GetValue( ini, pn, id, "Backdrop", m_Backdrop );
GetValue( ini, pn, id, "FOV", m_fFov );
GetValue( ini, pn, id, "NearClipDistance", m_fNear );
GetValue( ini, pn, id, "FarClipDistance", m_fFar );
GetValue( ini, pn, id, "PixelsDrawAheadScale", m_fFirstPixelToDrawScale );
GetValue( ini, pn, id, "PixelsDrawBehindScale", m_fLastPixelToDrawScale );
GetValue( pNode, pn, "Backdrop", m_Backdrop );
GetValue( pNode, pn, "FOV", m_fFov );
GetValue( pNode, pn, "NearClipDistance", m_fNear );
GetValue( pNode, pn, "FarClipDistance", m_fFar );
GetValue( pNode, pn, "PixelsDrawAheadScale", m_fFirstPixelToDrawScale );
GetValue( pNode, pn, "PixelsDrawBehindScale", m_fLastPixelToDrawScale );
CString s;
if( GetValue( ini, pn, id, "Judgment", s ) ) m_JudgmentCmd = ParseCommands(s);
if( GetValue( ini, pn, id, "Combo", s ) ) m_ComboCmd = ParseCommands(s);
if( GetValue( pNode, pn, "Judgment", s ) ) m_JudgmentCmd = ParseCommands(s);
if( GetValue( pNode, pn, "Combo", s ) ) m_ComboCmd = ParseCommands(s);
/* Load per-track data: */
int t;
for(t = 0; t < MAX_NOTE_TRACKS; ++t)
for( int t = 0; t < MAX_NOTE_TRACKS; ++t )
{
GetValue( ini, pn, id, ssprintf("GrayButton"), GrayButtonNames[t] );
GetValue( ini, pn, id, ssprintf("GrayButton%i", t+1), GrayButtonNames[t] );
GetValue( pNode, pn, ssprintf("GrayButton"), GrayButtonNames[t] );
GetValue( pNode, pn, ssprintf("GrayButton%i", t+1), GrayButtonNames[t] );
GetValue( ini, pn, id, ssprintf("NoteButton"), NoteButtonNames[t] );
GetValue( ini, pn, id, ssprintf("NoteButton%i", t+1), NoteButtonNames[t] );
GetValue( pNode, pn, ssprintf("NoteButton"), NoteButtonNames[t] );
GetValue( pNode, pn, ssprintf("NoteButton%i", t+1), NoteButtonNames[t] );
GetValue( ini, pn, id, ssprintf("GhostButton"), GhostButtonNames[t] );
GetValue( ini, pn, id, ssprintf("GhostButton%i", t+1), GhostButtonNames[t] );
GetValue( pNode, pn, ssprintf("GhostButton"), GhostButtonNames[t] );
GetValue( pNode, pn, ssprintf("GhostButton%i", t+1), GhostButtonNames[t] );
if( GetValue( ini, pn, id, ssprintf("HoldJudgment"), s ) ) m_HoldJudgmentCmd[t] = ParseCommands(s);
if( GetValue( ini, pn, id, ssprintf("HoldJudgment%i",t+1), s ) ) m_HoldJudgmentCmd[t] = ParseCommands(s);
if( GetValue( pNode, pn, ssprintf("HoldJudgment"), s ) ) m_HoldJudgmentCmd[t] = ParseCommands(s);
if( GetValue( pNode, pn, ssprintf("HoldJudgment%i",t+1), s ) ) m_HoldJudgmentCmd[t] = ParseCommands(s);
}
}
@@ -105,10 +104,10 @@ NoteFieldPositioning::NoteFieldPositioning(CString fn)
if( !ini.ReadFile(fn) )
return;
for(IniFile::const_iterator i = ini.begin(); i != ini.end(); ++i)
FOREACH_CONST_Child( &ini, i )
{
NoteFieldMode m;
m.Load(ini, i->first);
m.Load( i );
Modes.push_back(m);
}
@@ -145,7 +144,9 @@ void NoteFieldPositioning::Load(PlayerNumber pn)
if( !ini.ReadFile(m_Filename) )
return;
mode.Load(ini, Modes[ModeNum].m_Id, pn);
XNode* pNode = ini.GetChild( Modes[ModeNum].m_Id );
ASSERT( pNode );
mode.Load( pNode, pn );
}
+2 -1
View File
@@ -6,12 +6,13 @@
#include "Command.h"
class IniFile;
struct XNode;
struct NoteFieldMode
{
NoteFieldMode();
bool MatchesCurrentGame() const;
void Load(IniFile &ini, CString id, int pn = -1);
void Load(const XNode* pNode, int pn = -1);
void BeginDrawTrack(int tn);
void EndDrawTrack(int tn);
+1 -1
View File
@@ -62,7 +62,7 @@ void NoteSkinManager::RefreshNoteSkinData( const Game* pGame )
void NoteSkinManager::LoadNoteSkinData( const CString &sNoteSkinName, NoteSkinData& data_out )
{
data_out.sName = sNoteSkinName;
data_out.metrics.Reset();
data_out.metrics.Clear();
data_out.vsDirSearchOrder.clear();
/* Load global NoteSkin defaults */
+8 -7
View File
@@ -40,17 +40,18 @@ void PlayerAI::InitFromDisk()
for( int i=0; i<NUM_SKILL_LEVELS; i++ )
{
CString sKey = ssprintf("Skill%d", i);
if( ini.GetKey(sKey)==NULL )
XNode* pNode = ini.GetChild(sKey);
if( pNode == NULL )
RageException::Throw( "AI.ini: '%s' doesn't exist.", sKey.c_str() );
TapScoreDistribution& dist = g_Distributions[i];
dist.fPercent[TNS_NONE] = 0;
ini.GetValue ( sKey, "MissWeight", dist.fPercent[TNS_MISS] );
ini.GetValue ( sKey, "BooWeight", dist.fPercent[TNS_BOO] );
ini.GetValue ( sKey, "GoodWeight", dist.fPercent[TNS_GOOD] );
ini.GetValue ( sKey, "GreatWeight", dist.fPercent[TNS_GREAT] );
ini.GetValue ( sKey, "PerfectWeight", dist.fPercent[TNS_PERFECT] );
ini.GetValue ( sKey, "MarvelousWeight", dist.fPercent[TNS_MARVELOUS] );
pNode->GetAttrValue( "MissWeight", dist.fPercent[TNS_MISS] );
pNode->GetAttrValue( "BooWeight", dist.fPercent[TNS_BOO] );
pNode->GetAttrValue( "GoodWeight", dist.fPercent[TNS_GOOD] );
pNode->GetAttrValue( "GreatWeight", dist.fPercent[TNS_GREAT] );
pNode->GetAttrValue( "PerfectWeight", dist.fPercent[TNS_PERFECT] );
pNode->GetAttrValue( "MarvelousWeight", dist.fPercent[TNS_MARVELOUS] );
float fSum = 0;
for( int j=0; j<NUM_TAP_NOTE_SCORES; j++ )
+42 -42
View File
@@ -657,12 +657,12 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur
/* The placeholder stats.xml file has an <html> tag. Don't load it, but don't
* warn about it. */
if( xml.name == "html" )
if( xml.m_sName == "html" )
return failed_no_profile;
if( xml.name != "Stats" )
if( xml.m_sName != "Stats" )
{
WARN_M( xml.name );
WARN_M( xml.m_sName );
return failed_tampered;
}
@@ -701,7 +701,7 @@ XNode *Profile::SaveStatsXmlCreateNode() const
{
XNode *xml = new XNode;
xml->name = "Stats";
xml->m_sName = "Stats";
xml->AppendChild( SaveGeneralDataCreateNode() );
xml->AppendChild( SaveSongScoresCreateNode() );
xml->AppendChild( SaveCourseScoresCreateNode() );
@@ -763,7 +763,7 @@ void Profile::SaveEditableDataToDir( CString sDir ) const
XNode* Profile::SaveGeneralDataCreateNode() const
{
XNode* pGeneralDataNode = new XNode;
pGeneralDataNode->name = "GeneralData";
pGeneralDataNode->m_sName = "GeneralData";
// TRICKY: These are write-only elements that are never read again. This
// data is required by other apps (like internet ranking), but is
@@ -915,7 +915,7 @@ void Profile::LoadEditableDataFromDir( CString sDir )
void Profile::LoadGeneralDataFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "GeneralData" );
ASSERT( pNode->m_sName == "GeneralData" );
CString s;
const XNode* pTemp;
@@ -949,7 +949,7 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode )
{
FOREACH_CONST_Child( pDefaultModifiers, game_type )
{
m_sDefaultModifiers[game_type->name] = game_type->value;
m_sDefaultModifiers[game_type->m_sName] = game_type->m_sValue;
}
}
}
@@ -961,7 +961,7 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode )
FOREACH_CONST_Child( pUnlockedSongs, song )
{
int iUnlock;
if( sscanf(song->name.c_str(),"Unlock%d",&iUnlock) == 1 )
if( sscanf(song->m_sName.c_str(),"Unlock%d",&iUnlock) == 1 )
m_UnlockedSongs.insert( iUnlock );
}
}
@@ -980,7 +980,7 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode )
{
FOREACH_CONST_Child( pNumSongsPlayedByStyle, style )
{
if( style->name != "Style" )
if( style->m_sName != "Style" )
continue;
StyleID s;
@@ -1056,7 +1056,7 @@ XNode* Profile::SaveSongScoresCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "SongScores";
pNode->m_sName = "SongScores";
for( map<SongID,HighScoresForASong>::const_iterator i = m_SongHighScores.begin();
i != m_SongHighScores.end();
@@ -1097,11 +1097,11 @@ void Profile::LoadSongScoresFromNode( const XNode* pSongScores )
{
CHECKPOINT;
ASSERT( pSongScores->name == "SongScores" );
ASSERT( pSongScores->m_sName == "SongScores" );
FOREACH_CONST_Child( pSongScores, pSong )
{
if( pSong->name != "Song" )
if( pSong->m_sName != "Song" )
continue;
SongID songID;
@@ -1111,7 +1111,7 @@ void Profile::LoadSongScoresFromNode( const XNode* pSongScores )
FOREACH_CONST_Child( pSong, pSteps )
{
if( pSteps->name != "Steps" )
if( pSteps->m_sName != "Steps" )
continue;
StepsID stepsID;
@@ -1138,7 +1138,7 @@ XNode* Profile::SaveCourseScoresCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "CourseScores";
pNode->m_sName = "CourseScores";
for( map<CourseID,HighScoresForACourse>::const_iterator i = m_CourseHighScores.begin();
@@ -1180,11 +1180,11 @@ void Profile::LoadCourseScoresFromNode( const XNode* pCourseScores )
{
CHECKPOINT;
ASSERT( pCourseScores->name == "CourseScores" );
ASSERT( pCourseScores->m_sName == "CourseScores" );
FOREACH_CONST_Child( pCourseScores, pCourse )
{
if( pCourse->name != "Course" )
if( pCourse->m_sName != "Course" )
continue;
CourseID courseID;
@@ -1194,7 +1194,7 @@ void Profile::LoadCourseScoresFromNode( const XNode* pCourseScores )
FOREACH_CONST_Child( pCourse, pTrail )
{
if( pTrail->name != "Trail" )
if( pTrail->m_sName != "Trail" )
continue;
TrailID trailID;
@@ -1220,7 +1220,7 @@ XNode* Profile::SaveCategoryScoresCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "CategoryScores";
pNode->m_sName = "CategoryScores";
FOREACH_StepsType( st )
{
@@ -1253,11 +1253,11 @@ void Profile::LoadCategoryScoresFromNode( const XNode* pCategoryScores )
{
CHECKPOINT;
ASSERT( pCategoryScores->name == "CategoryScores" );
ASSERT( pCategoryScores->m_sName == "CategoryScores" );
FOREACH_CONST_Child( pCategoryScores, pStepsType )
{
if( pStepsType->name != "StepsType" )
if( pStepsType->m_sName != "StepsType" )
continue;
CString str;
@@ -1269,7 +1269,7 @@ void Profile::LoadCategoryScoresFromNode( const XNode* pCategoryScores )
FOREACH_CONST_Child( pStepsType, pRadarCategory )
{
if( pRadarCategory->name != "RankingCategory" )
if( pRadarCategory->m_sName != "RankingCategory" )
continue;
if( !pRadarCategory->GetAttrValue( "Type", str ) )
@@ -1313,11 +1313,11 @@ void Profile::LoadScreenshotDataFromNode( const XNode* pScreenshotData )
{
CHECKPOINT;
ASSERT( pScreenshotData->name == "ScreenshotData" );
ASSERT( pScreenshotData->m_sName == "ScreenshotData" );
FOREACH_CONST_Child( pScreenshotData, pScreenshot )
{
if( pScreenshot->name != "Screenshot" )
WARN_AND_CONTINUE_M( pScreenshot->name );
if( pScreenshot->m_sName != "Screenshot" )
WARN_AND_CONTINUE_M( pScreenshot->m_sName );
Screenshot ss;
ss.LoadFromNode( pScreenshot );
@@ -1334,7 +1334,7 @@ XNode* Profile::SaveScreenshotDataCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "ScreenshotData";
pNode->m_sName = "ScreenshotData";
FOREACH_CONST( Screenshot, m_vScreenshots, ss )
{
@@ -1348,11 +1348,11 @@ void Profile::LoadCalorieDataFromNode( const XNode* pCalorieData )
{
CHECKPOINT;
ASSERT( pCalorieData->name == "CalorieData" );
ASSERT( pCalorieData->m_sName == "CalorieData" );
FOREACH_CONST_Child( pCalorieData, pCaloriesBurned )
{
if( pCaloriesBurned->name != "CaloriesBurned" )
WARN_AND_CONTINUE_M( pCaloriesBurned->name );
if( pCaloriesBurned->m_sName != "CaloriesBurned" )
WARN_AND_CONTINUE_M( pCaloriesBurned->m_sName );
CString sDate;
if( !pCaloriesBurned->GetAttrValue("Date",sDate) )
@@ -1377,7 +1377,7 @@ XNode* Profile::SaveCalorieDataCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "CalorieData";
pNode->m_sName = "CalorieData";
for( map<DateTime,float>::const_iterator i = m_mapDayToCaloriesBurned.begin();
i != m_mapDayToCaloriesBurned.end();
@@ -1404,7 +1404,7 @@ float Profile::GetCaloriesBurnedForDay( DateTime day ) const
XNode* Profile::HighScoreForASongAndSteps::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "HighScoreForASongAndSteps";
pNode->m_sName = "HighScoreForASongAndSteps";
pNode->AppendChild( songID.CreateNode() );
pNode->AppendChild( stepsID.CreateNode() );
@@ -1417,7 +1417,7 @@ void Profile::HighScoreForASongAndSteps::LoadFromNode( const XNode* pNode )
{
Unset();
ASSERT( pNode->name == "HighScoreForASongAndSteps" );
ASSERT( pNode->m_sName == "HighScoreForASongAndSteps" );
const XNode* p;
if( (p = pNode->GetChild("Song")) )
songID.LoadFromNode( p );
@@ -1431,10 +1431,10 @@ void Profile::LoadRecentSongScoresFromNode( const XNode* pRecentSongScores )
{
CHECKPOINT;
ASSERT( pRecentSongScores->name == "RecentSongScores" );
ASSERT( pRecentSongScores->m_sName == "RecentSongScores" );
FOREACH_CONST_Child( pRecentSongScores, p )
{
if( p->name == "HighScoreForASongAndSteps" )
if( p->m_sName == "HighScoreForASongAndSteps" )
{
HighScoreForASongAndSteps h;
h.LoadFromNode( p );
@@ -1443,7 +1443,7 @@ void Profile::LoadRecentSongScoresFromNode( const XNode* pRecentSongScores )
}
else
{
WARN_AND_CONTINUE_M( p->name );
WARN_AND_CONTINUE_M( p->m_sName );
}
}
}
@@ -1456,7 +1456,7 @@ XNode* Profile::SaveRecentSongScoresCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "RecentSongScores";
pNode->m_sName = "RecentSongScores";
unsigned uNumToSave = min( m_vRecentStepsScores.size(), (unsigned)MAX_RECENT_SCORES_TO_SAVE );
@@ -1481,7 +1481,7 @@ void Profile::AddStepsRecentScore( const Song* pSong, const Steps* pSteps, HighS
XNode* Profile::HighScoreForACourseAndTrail::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "HighScoreForACourseAndTrail";
pNode->m_sName = "HighScoreForACourseAndTrail";
pNode->AppendChild( courseID.CreateNode() );
pNode->AppendChild( trailID.CreateNode() );
@@ -1494,7 +1494,7 @@ void Profile::HighScoreForACourseAndTrail::LoadFromNode( const XNode* pNode )
{
Unset();
ASSERT( pNode->name == "HighScoreForACourseAndTrail" );
ASSERT( pNode->m_sName == "HighScoreForACourseAndTrail" );
const XNode* p;
if( (p = pNode->GetChild("Course")) )
courseID.LoadFromNode( p );
@@ -1508,10 +1508,10 @@ void Profile::LoadRecentCourseScoresFromNode( const XNode* pRecentCourseScores )
{
CHECKPOINT;
ASSERT( pRecentCourseScores->name == "RecentCourseScores" );
ASSERT( pRecentCourseScores->m_sName == "RecentCourseScores" );
FOREACH_CONST_Child( pRecentCourseScores, p )
{
if( p->name == "HighScoreForACourseAndTrail" )
if( p->m_sName == "HighScoreForACourseAndTrail" )
{
HighScoreForACourseAndTrail h;
h.LoadFromNode( p );
@@ -1520,7 +1520,7 @@ void Profile::LoadRecentCourseScoresFromNode( const XNode* pRecentCourseScores )
}
else
{
WARN_AND_CONTINUE_M( p->name );
WARN_AND_CONTINUE_M( p->m_sName );
}
}
}
@@ -1533,7 +1533,7 @@ XNode* Profile::SaveRecentCourseScoresCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "RecentCourseScores";
pNode->m_sName = "RecentCourseScores";
unsigned uNumToSave = min( m_vRecentCourseScores.size(), (unsigned)MAX_RECENT_SCORES_TO_SAVE );
@@ -1587,7 +1587,7 @@ XNode* Profile::SaveCoinDataCreateNode() const
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "CoinData";
pNode->m_sName = "CoinData";
{
int coins[NUM_LAST_DAYS];
+2 -2
View File
@@ -28,7 +28,7 @@ void RadarValues::Zero()
XNode* RadarValues::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "RadarValues";
pNode->m_sName = "RadarValues";
// TRICKY: Don't print a remainder for the integer values.
FOREACH_RadarCategory( rc )
@@ -50,7 +50,7 @@ XNode* RadarValues::CreateNode() const
void RadarValues::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "RadarValues" );
ASSERT( pNode->m_sName == "RadarValues" );
Zero();
+1 -1
View File
@@ -66,7 +66,7 @@ void SongCacheIndex::ReadCacheIndex()
EmptyDir( CACHE_DIR "Banners/" );
EmptyDir( CACHE_DIR "Songs/" );
CacheIndex.Reset();
CacheIndex.Clear();
}
void SongCacheIndex::AddCacheIndex(const CString &path, unsigned hash)
+2 -2
View File
@@ -375,7 +375,7 @@ Song *SongID::ToSong() const
XNode* SongID::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Song";
pNode->m_sName = "Song";
pNode->AppendAttr( "Dir", sDir );
@@ -384,7 +384,7 @@ XNode* SongID::CreateNode() const
void SongID::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "Song" );
ASSERT( pNode->m_sName == "Song" );
pNode->GetAttrValue("Dir", sDir);
}
+2 -2
View File
@@ -181,7 +181,7 @@ Steps *StepsID::ToSteps( const Song *p, bool bAllowNull, bool bUseCache ) const
XNode* StepsID::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Steps";
pNode->m_sName = "Steps";
pNode->AppendAttr( "StepsType", GameManager::StepsTypeToString(st) );
pNode->AppendAttr( "Difficulty", DifficultyToString(dc) );
@@ -202,7 +202,7 @@ void StepsID::ClearCache()
void StepsID::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "Steps" );
ASSERT( pNode->m_sName == "Steps" );
CString sTemp;
+2 -2
View File
@@ -32,7 +32,7 @@ const Style *StyleID::ToStyle() const
XNode* StyleID::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Style";
pNode->m_sName = "Style";
pNode->AppendAttr( "Game", sGame );
pNode->AppendAttr( "Style", sStyle );
@@ -43,7 +43,7 @@ XNode* StyleID::CreateNode() const
void StyleID::LoadFromNode( const XNode* pNode )
{
Unset();
ASSERT( pNode->name == "Style" );
ASSERT( pNode->m_sName == "Style" );
sGame = "";
pNode->GetAttrValue("Game", sGame);
+12 -11
View File
@@ -42,7 +42,7 @@ const CString ELEMENT_CATEGORY_STRING[NUM_ELEMENT_CATEGORIES] =
struct Theme
{
CString sThemeName;
IniFile iniMetrics; // make this a pointer so we don't have to include IniFile here
IniFile *iniMetrics; // pointer because the copy constructor isn't a deep copy
};
// When looking for a metric or an element, search these from head to tail.
deque<Theme> g_vThemes;
@@ -190,17 +190,18 @@ void ThemeManager::LoadThemeRecursive( deque<Theme> &theme, const CString &sThem
loaded_base = true;
Theme t;
t.iniMetrics = new IniFile;
t.sThemeName = sThemeName;
t.iniMetrics.ReadFile( GetMetricsIniPath(sThemeName) );
t.iniMetrics.ReadFile( GetLanguageIniPath(sThemeName,BASE_LANGUAGE) );
t.iniMetrics->ReadFile( GetMetricsIniPath(sThemeName) );
t.iniMetrics->ReadFile( GetLanguageIniPath(sThemeName,BASE_LANGUAGE) );
if( m_sCurLanguage.CompareNoCase(BASE_LANGUAGE) )
t.iniMetrics.ReadFile( GetLanguageIniPath(sThemeName,m_sCurLanguage) );
t.iniMetrics->ReadFile( GetLanguageIniPath(sThemeName,m_sCurLanguage) );
/* Read the fallback theme. If no fallback theme is specified, and we havn't
* already loaded it, fall back on BASE_THEME_NAME. That way, default theme
* fallbacks can be disabled with "FallbackTheme=". */
CString sFallback;
if( !t.iniMetrics.GetValue("Global","FallbackTheme",sFallback) )
if( !t.iniMetrics->GetValue("Global","FallbackTheme",sFallback) )
{
if( sThemeName.CompareNoCase( BASE_THEME_NAME ) && !loaded_base )
sFallback = BASE_THEME_NAME;
@@ -253,7 +254,7 @@ void ThemeManager::SwitchThemeAndLanguage( const CString &sThemeName, const CStr
if( !re.Compare( sMetric, sBits ) )
RageException::Throw( "Invalid argument \"--metric=%s\"", sMetric.c_str() );
g_vThemes.front().iniMetrics.SetValue( sBits[0], sBits[1], sBits[2] );
g_vThemes.front().iniMetrics->SetValue( sBits[0], sBits[1], sBits[2] );
}
LOG->MapLog("theme", "Theme: %s", sTheme.c_str());
@@ -568,9 +569,9 @@ bool ThemeManager::GetMetricRaw( const CString &sClassName, const CString &sValu
iter != g_vThemes.end();
iter++ )
{
if( iter->iniMetrics.GetValue(sClassName,sValueName,ret) )
if( iter->iniMetrics->GetValue(sClassName,sValueName,ret) )
return true;
if( iter->iniMetrics.GetValue(sClassName,"Fallback",sFallback) )
if( iter->iniMetrics->GetValue(sClassName,"Fallback",sFallback) )
{
if( GetMetricRaw(sFallback,sValueName,ret,level+1) )
return true;
@@ -735,11 +736,11 @@ void ThemeManager::GetModifierNames( set<CString>& AddTo )
iter != g_vThemes.end();
++iter )
{
const IniFile::key *cur = iter->iniMetrics.GetKey( "OptionNames" );
const XNode *cur = iter->iniMetrics->GetChild( "OptionNames" );
if( cur )
{
for( IniFile::key::const_iterator iter = cur->begin(); iter != cur->end(); ++iter )
AddTo.insert( iter->first );
FOREACH_CONST_Attr( cur, p )
AddTo.insert( p->m_sName );
}
}
}
+2 -2
View File
@@ -37,7 +37,7 @@ Trail *TrailID::ToTrail( const Course *p, bool bAllowNull ) const
XNode* TrailID::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Trail";
pNode->m_sName = "Trail";
pNode->AppendAttr( "StepsType", GameManager::StepsTypeToString(st) );
pNode->AppendAttr( "CourseDifficulty", CourseDifficultyToString(cd) );
@@ -47,7 +47,7 @@ XNode* TrailID::CreateNode() const
void TrailID::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "Trail" );
ASSERT( pNode->m_sName == "Trail" );
CString sTemp;
+122 -117
View File
@@ -150,18 +150,18 @@ void SetString( char* psz, char* end, CString* ps, bool trim = false, int escape
XNode::~XNode()
{
Close();
Clear();
}
void XNode::Close()
void XNode::Clear()
{
FOREACH_Child( this, p )
SAFE_DELETE( p );
childs.clear();
m_childs.clear();
FOREACH_Attr( this, p2 )
SAFE_DELETE( p2 );
attrs.clear();
m_attrs.clear();
}
// attr1="value1" attr2='value2' attr3=value3 />
@@ -201,7 +201,7 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*
pi->erorr_occur = true;
pi->error_pointer = xml;
pi->error_code = PIE_ATTR_NO_VALUE;
pi->error_string = ssprintf( ("<%s> attribute has error "), name.c_str() );
pi->error_string = ssprintf( ("<%s> attribute has error "), m_sName.c_str() );
}
return NULL;
}
@@ -209,10 +209,11 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*
XAttr *attr = new XAttr;
// XML Attr Name
SetString( xml, pEnd, &attr->name );
SetString( xml, pEnd, &attr->m_sName );
// add new attribute
attrs.insert( pair<CString,XAttr*>(attr->name, attr) );
DEBUG_ASSERT( attr->m_sName.size() );
m_attrs.insert( pair<CString,XAttr*>(attr->m_sName, attr) );
xml = pEnd;
// XML Attr Value
@@ -230,7 +231,9 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*
// or none quote
int quote = *xml;
if( quote == '"' || quote == '\'' )
{
pEnd = tcsechr( ++xml, quote, chXMLEscape );
}
else
{
//attr= value>
@@ -241,12 +244,12 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*
bool trim = pi->trim_value;
char escape = pi->escape_value;
//SetString( xml, pEnd, &attr->value, trim, chXMLEscape );
SetString( xml, pEnd, &attr->value, trim, escape );
//SetString( xml, pEnd, &attr->m_sValue, trim, chXMLEscape );
SetString( xml, pEnd, &attr->m_sValue, trim, escape );
xml = pEnd;
// ATTRVALUE
if( pi->entity_value && pi->entitys )
attr->value = pi->entitys->Ref2Entity(attr->value);
attr->m_sValue = pi->entitys->Ref2Entity(attr->m_sValue);
if( quote == '"' || quote == '\'' )
xml++;
@@ -274,8 +277,7 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*
//========================================================
char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
{
// Close it
Close();
Clear();
char* xml = (char*)pszXml;
@@ -290,7 +292,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
// XML Node Tag Name Open
xml++;
char* pTagEnd = strpbrk( xml, " />" );
SetString( xml, pTagEnd, &name );
SetString( xml, pTagEnd, &m_sName );
xml = pTagEnd;
// Generate XML Attributte List
xml = LoadAttributes( xml, pi );
@@ -309,7 +311,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
// UGLY: We want to ignore all XML meta tags. So, since the Node we
// just loaded is a meta tag, then Load ourself again using the rest
// of the file until we reach a non-meta tag.
if( !name.empty() && name[0] == chXMLTagQuestion )
if( !m_sName.empty() && m_sName[0] == chXMLTagQuestion )
xml = Load( xml, pi );
return xml;
@@ -333,8 +335,8 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
// ^- current pointer
{
// text value°¡ ¾øÀ¸¸E³Öµµ·ÏÇÑ´Ù.
//if( this->value.empty() || this->value == ("") )
if( XIsEmptyString( value ) )
//if( this->m_sValue.empty() || this->m_sValue == ("") )
if( XIsEmptyString( m_sValue ) )
{
// Text Value
char* pEnd = tcsechr( ++xml, chXMLTagOpen, chXMLEscape );
@@ -345,7 +347,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
pi->erorr_occur = true;
pi->error_pointer = xml;
pi->error_code = PIE_NOT_CLOSED;
pi->error_string = ssprintf( "%s must be closed with </%s>", name.c_str(), name.c_str() );
pi->error_string = ssprintf( "%s must be closed with </%s>", m_sName.c_str(), m_sName.c_str() );
}
// error cos not exist CloseTag </TAG>
return NULL;
@@ -353,13 +355,13 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
bool trim = pi->trim_value;
char escape = pi->escape_value;
//SetString( xml, pEnd, &value, trim, chXMLEscape );
SetString( xml, pEnd, &value, trim, escape );
//SetString( xml, pEnd, &m_sValue, trim, chXMLEscape );
SetString( xml, pEnd, &m_sValue, trim, escape );
xml = pEnd;
// TEXTVALUE reference
if( pi->entity_value && pi->entitys )
value = pi->entitys->Ref2Entity(value);
m_sValue = pi->entitys->Ref2Entity(m_sValue);
}
// generate child nodes
@@ -368,9 +370,10 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
XNode *node = new XNode;
xml = node->Load( xml,pi );
if( !node->name.empty() )
if( !node->m_sName.empty() )
{
childs.insert( pair<CString,XNode*>(node->name, node) );
DEBUG_ASSERT( node->m_sName.size() );
m_childs.insert( pair<CString,XNode*>(node->m_sName, node) );
}
else
{
@@ -398,13 +401,13 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
pi->erorr_occur = true;
pi->error_pointer = xml;
pi->error_code = PIE_NOT_CLOSED;
pi->error_string = ssprintf( "it must be closed with </%s>", name.c_str() );
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
}
// error
return NULL;
}
SetString( xml, pEnd, &closename );
if( closename == this->name )
if( closename == this->m_sName )
{
// wel-formed open/close
xml = pEnd+1;
@@ -420,7 +423,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
pi->erorr_occur = true;
pi->error_pointer = xml;
pi->error_code = PIE_NOT_NESTED;
pi->error_string = ssprintf( "'<%s> ... </%s>' is not well-formed.", name.c_str(), closename.c_str() );
pi->error_string = ssprintf( "'<%s> ... </%s>' is not well-formed.", m_sName.c_str(), closename.c_str() );
}
return NULL;
@@ -430,8 +433,8 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
// else ÇØ¾ßÇÏ´ÂÁE¸»¾Æ¾ßÇÏ´ÂÁEÀǽɰ£´Ù.
{
//if( xml && this->value.empty() && *xml !=chXMLTagOpen )
if( xml && XIsEmptyString( value ) && *xml !=chXMLTagOpen )
//if( xml && this->m_sValue.empty() && *xml !=chXMLTagOpen )
if( xml && XIsEmptyString( m_sValue ) && *xml !=chXMLTagOpen )
{
// Text Value
char* pEnd = tcsechr( xml, chXMLTagOpen, chXMLEscape );
@@ -443,20 +446,20 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
pi->erorr_occur = true;
pi->error_pointer = xml;
pi->error_code = PIE_NOT_CLOSED;
pi->error_string = ssprintf( "it must be closed with </%s>", name.c_str() );
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
}
return NULL;
}
bool trim = pi->trim_value;
char escape = pi->escape_value;
//SetString( xml, pEnd, &value, trim, chXMLEscape );
SetString( xml, pEnd, &value, trim, escape );
//SetString( xml, pEnd, &m_sValue, trim, chXMLEscape );
SetString( xml, pEnd, &m_sValue, trim, escape );
xml = pEnd;
//TEXTVALUE
if( pi->entity_value && pi->entitys )
value = pi->entitys->Ref2Entity(value);
m_sValue = pi->entitys->Ref2Entity(m_sValue);
}
}
}
@@ -476,7 +479,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
//========================================================
bool XAttr::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ )
{
return f.Write(name + "='" + (opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(value):value) + "' ") != -1;
return f.Write(m_sName + "='" + (opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(m_sValue):m_sValue) + "' ") != -1;
}
//========================================================
@@ -503,18 +506,18 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ )
}
// <TAG
if( f.Write("<" + name) == -1 )
if( f.Write("<" + m_sName) == -1 )
return false;
// <TAG Attr1="Val1"
if( !attrs.empty() )
if( !m_attrs.empty() )
if( f.Write(" ") == -1 )
return false;
FOREACH_Attr( this, p )
if( !p->GetXML(f, opt) )
return false;
if( childs.empty() && value.empty() )
if( m_childs.empty() && m_sValue.empty() )
{
// <TAG Attr1="Val1"/> alone tag
if( f.Write("/>") == -1 )
@@ -526,7 +529,7 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ )
if( f.Write(">") == -1 )
return false;
if( opt && opt->newline && !childs.empty() )
if( opt && opt->newline && !m_childs.empty() )
{
opt->tab_base++;
}
@@ -536,9 +539,9 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ )
return false;
// Text Value
if( value != ("") )
if( m_sValue != ("") )
{
if( opt && opt->newline && !childs.empty() )
if( opt && opt->newline && !m_childs.empty() )
{
if( opt && opt->newline )
if( f.Write("\r\n") == -1 )
@@ -548,12 +551,12 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ )
if( f.Write("\t") == -1 )
return false;
}
if( f.Write((opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(value):value)) == -1 )
if( f.Write((opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(m_sValue):m_sValue)) == -1 )
return false;
}
// </TAG> CloseTag
if( opt && opt->newline && !childs.empty() )
if( opt && opt->newline && !m_childs.empty() )
{
if( f.Write("\r\n") == -1 )
return false;
@@ -562,12 +565,12 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ )
if( f.Write("\t") == -1 )
return false;
}
if( f.Write("</" + name + ">") == -1 )
if( f.Write("</" + m_sName + ">") == -1 )
return false;
if( opt && opt->newline )
{
if( !childs.empty() )
if( !m_childs.empty() )
opt->tab_base--;
}
}
@@ -582,19 +585,19 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt /*= &optDefault*/ )
//--------------------------------------------------------
// Coder Date Desc
//========================================================
void XNode::GetValue(CString &out) const { out = value; }
void XNode::GetValue(int &out) const { out = atoi(value); }
void XNode::GetValue(float &out) const { out = strtof(value, NULL); }
void XNode::GetValue(bool &out) const { out = atoi(value) != 0; }
void XNode::GetValue(unsigned &out) const { out = (unsigned)atoi(value) != 0; }
void XNode::GetValue(DateTime &out) const { out.FromString( value ); }
void XNode::GetValue(CString &out) const { out = m_sValue; }
void XNode::GetValue(int &out) const { out = atoi(m_sValue); }
void XNode::GetValue(float &out) const { out = strtof(m_sValue, NULL); }
void XNode::GetValue(bool &out) const { out = atoi(m_sValue) != 0; }
void XNode::GetValue(unsigned &out) const { out = (unsigned)atoi(m_sValue) != 0; }
void XNode::GetValue(DateTime &out) const { out.FromString( m_sValue ); }
void XAttr::GetValue(CString &out) const { out = value; }
void XAttr::GetValue(int &out) const { out = atoi(value); }
void XAttr::GetValue(float &out) const { out = strtof(value, NULL); }
void XAttr::GetValue(bool &out) const { out = atoi(value) != 0; }
void XAttr::GetValue(unsigned &out) const { out = (unsigned)atoi(value) != 0; }
void XAttr::GetValue(DateTime &out) const { out.FromString( value ); }
void XAttr::GetValue(CString &out) const { out = m_sValue; }
void XAttr::GetValue(int &out) const { out = atoi(m_sValue); }
void XAttr::GetValue(float &out) const { out = strtof(m_sValue, NULL); }
void XAttr::GetValue(bool &out) const { out = atoi(m_sValue) != 0; }
void XAttr::GetValue(unsigned &out) const { out = (unsigned)atoi(m_sValue) != 0; }
void XAttr::GetValue(DateTime &out) const { out.FromString( m_sValue ); }
//========================================================
// Name : SetValue
@@ -604,11 +607,11 @@ void XAttr::GetValue(DateTime &out) const { out.FromString( value ); }
//--------------------------------------------------------
// Coder Date Desc
//========================================================
void XNode::SetValue(int v) { value = ssprintf("%d",v); }
void XNode::SetValue(float v) { value = ssprintf("%f",v); }
void XNode::SetValue(bool v) { value = ssprintf("%d",v); }
void XNode::SetValue(unsigned v) { value = ssprintf("%u",v); }
void XNode::SetValue(const DateTime &v) { value = v.GetString(); }
void XNode::SetValue(int v) { m_sValue = ssprintf("%d",v); }
void XNode::SetValue(float v) { m_sValue = ssprintf("%f",v); }
void XNode::SetValue(bool v) { m_sValue = ssprintf("%d",v); }
void XNode::SetValue(unsigned v) { m_sValue = ssprintf("%u",v); }
void XNode::SetValue(const DateTime &v) { m_sValue = v.GetString(); }
//========================================================
// Name : GetAttr
@@ -621,17 +624,23 @@ void XNode::SetValue(const DateTime &v) { value = v.GetString(); }
//========================================================
const XAttr *XNode::GetAttr( const char* attrname ) const
{
multimap<CString, XAttr*>::const_iterator it = attrs.find( name );
if( it != attrs.end() )
multimap<CString, XAttr*>::const_iterator it = m_attrs.find( attrname );
if( it != m_attrs.end() )
{
DEBUG_ASSERT( attrname == it->second->m_sName );
return it->second;
}
return NULL;
}
XAttr *XNode::GetAttr( const char* attrname )
{
multimap<CString, XAttr*>::iterator it = attrs.find( name );
if( it != attrs.end() )
multimap<CString, XAttr*>::iterator it = m_attrs.find( attrname );
if( it != m_attrs.end() )
{
DEBUG_ASSERT( attrname == it->second->m_sName );
return it->second;
}
return NULL;
}
@@ -647,7 +656,7 @@ XAttr *XNode::GetAttr( const char* attrname )
const char* XNode::GetAttrValue( const char* attrname )
{
XAttr *attr = GetAttr( attrname );
return attr ? (const char*)attr->value : NULL;
return attr ? (const char*)attr->m_sValue : NULL;
}
@@ -662,7 +671,7 @@ const char* XNode::GetAttrValue( const char* attrname )
//========================================================
int XNode::GetChildCount()
{
return childs.size();
return m_childs.size();
}
//========================================================
@@ -676,17 +685,24 @@ int XNode::GetChildCount()
//========================================================
XNode *XNode::GetChild( const char* name )
{
multimap<CString, XNode*>::iterator it = childs.find( name );
if( it != childs.end() )
multimap<CString, XNode*>::iterator it = m_childs.find( name );
if( it != m_childs.end() )
{
DEBUG_ASSERT( name == it->second->m_sName );
return it->second;
}
return NULL;
}
const XNode *XNode::GetChild( const char* name ) const
{
multimap<CString, XNode*>::const_iterator it = childs.find( name );
if( it != childs.end() )
multimap<CString, XNode*>::const_iterator it = m_childs.find( name );
if( it != m_childs.end() )
{
XNode* p = it->second;
DEBUG_ASSERT( name == it->second->m_sName );
return it->second;
}
return NULL;
}
@@ -702,7 +718,7 @@ const XNode *XNode::GetChild( const char* name ) const
const char* XNode::GetChildValue( const char* name )
{
XNode *node = GetChild( name );
return (node != NULL)? (const char*)node->value : NULL;
return (node != NULL)? (const char*)node->m_sValue : NULL;
}
XAttr *XNode::GetChildAttr( const char* name, const char* attrname )
@@ -714,7 +730,7 @@ XAttr *XNode::GetChildAttr( const char* name, const char* attrname )
const char* XNode::GetChildAttrValue( const char* name, const char* attrname )
{
XAttr *attr = GetChildAttr( name, attrname );
return attr ? (const char*)attr->value : NULL;
return attr ? (const char*)attr->m_sValue : NULL;
}
@@ -727,11 +743,11 @@ const char* XNode::GetChildAttrValue( const char* name, const char* attrname )
// Coder Date Desc
// bro 2002-10-29
//========================================================
XNode *XNode::AppendChild( const char* name, const char* value ) { XNode *p = new XNode; p->name = name; p->value = value; return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, float value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, int value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, unsigned value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, const DateTime &value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, const char* value ) { XNode *p = new XNode; p->m_sName = name; p->m_sValue = value; return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, float value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, int value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, unsigned value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const char* name, const DateTime &value ) { XNode *p = new XNode; p->m_sName = name; p->SetValue( value ); return AppendChild( p ); }
//========================================================
// Name : AppendChild
@@ -744,7 +760,8 @@ XNode *XNode::AppendChild( const char* name, const DateTime &value ) { XNode *p
//========================================================
XNode *XNode::AppendChild( XNode *node )
{
childs.insert( pair<CString,XNode*>(node->name,node) );
DEBUG_ASSERT( node->m_sName.size() );
m_childs.insert( pair<CString,XNode*>(node->m_sName,node) );
return node;
}
@@ -759,12 +776,12 @@ XNode *XNode::AppendChild( XNode *node )
//========================================================
bool XNode::RemoveChild( XNode *node )
{
FOREACHMM( CString, XNode*, childs, p )
FOREACHMM( CString, XNode*, m_childs, p )
{
if( p->second == node )
{
SAFE_DELETE( p->second );
childs.erase( p );
m_childs.erase( p );
return true;
}
}
@@ -783,7 +800,8 @@ bool XNode::RemoveChild( XNode *node )
//========================================================
XAttr *XNode::AppendAttr( XAttr *attr )
{
attrs.insert( pair<CString,XAttr*>(attr->name,attr) );
DEBUG_ASSERT( attr->m_sName.size() );
m_attrs.insert( pair<CString,XAttr*>(attr->m_sName,attr) );
return attr;
}
@@ -798,52 +816,18 @@ XAttr *XNode::AppendAttr( XAttr *attr )
//========================================================
bool XNode::RemoveAttr( XAttr *attr )
{
FOREACHMM( CString, XAttr*, attrs, p )
FOREACHMM( CString, XAttr*, m_attrs, p )
{
if( p->second == attr )
{
SAFE_DELETE( p->second );
attrs.erase( p );
m_attrs.erase( p );
return true;
}
}
return false;
}
//========================================================
// Name : CreateNode
// Desc : Create node object and return it
// Param :
// Return :
//--------------------------------------------------------
// Coder Date Desc
// bro 2002-10-29
//========================================================
XNode *XNode::CreateNode( const char* name /*= NULL*/, const char* value /*= NULL*/ )
{
XNode *node = new XNode;
node->name = name;
node->value = value;
return node;
}
//========================================================
// Name : CreateAttr
// Desc : create Attribute object and return it
// Param :
// Return :
//--------------------------------------------------------
// Coder Date Desc
// bro 2002-10-29
//========================================================
XAttr *XNode::CreateAttr( const char* name /*= NULL*/, const char* value /*= NULL*/ )
{
XAttr *attr = new XAttr;
attr->name = name;
attr->value = value;
return attr;
}
//========================================================
// Name : AppendAttr
// Desc : add attribute
@@ -855,13 +839,34 @@ XAttr *XNode::CreateAttr( const char* name /*= NULL*/, const char* value /*= NUL
//========================================================
XAttr *XNode::AppendAttr( const char* name /*= NULL*/, const char* value /*= NULL*/ )
{
return AppendAttr( CreateAttr( name, value ) );
XAttr *attr = new XAttr;
attr->m_sName = name;
attr->m_sValue = value;
return AppendAttr( attr );
}
XAttr *XNode::AppendAttr( const char* name, float value ){ return AppendAttr(name,ssprintf("%f",value)); }
XAttr *XNode::AppendAttr( const char* name, int value ) { return AppendAttr(name,ssprintf("%d",value)); }
XAttr *XNode::AppendAttr( const char* name, unsigned value ) { return AppendAttr(name,ssprintf("%u",value)); }
//========================================================
// Name : SetAttrValue
// Desc : add attribute
// Param :
// Return :
//--------------------------------------------------------
// Coder Date Desc
// bro 2002-10-29
//========================================================
void XNode::SetAttrValue( const char* name, const char* value )
{
XAttr* pAttr = GetAttr( name );
if( pAttr )
pAttr->m_sValue = value;
else
AppendAttr( name, value );
}
XENTITYS::XENTITYS( XENTITY *entities, int count )
{
+31 -30
View File
@@ -31,29 +31,29 @@ typedef multimap<CString,XNode*> XNodes;
#define FOREACH_Attr( pNode, Var ) \
XAttrs::iterator Var##Iter; \
XAttr *Var = NULL; \
for( Var##Iter = pNode->attrs.begin(); \
(Var##Iter != pNode->attrs.end() && (Var = Var##Iter->second) ), Var##Iter != pNode->attrs.end(); \
for( Var##Iter = (pNode)->m_attrs.begin(); \
(Var##Iter != (pNode)->m_attrs.end() && (Var = Var##Iter->second) ), Var##Iter != (pNode)->m_attrs.end(); \
++Var##Iter )
#define FOREACH_CONST_Attr( pNode, Var ) \
XAttrs::const_iterator Var##Iter; \
const XAttr *Var = NULL; \
for( Var##Iter = pNode->attrs.begin(); \
(Var##Iter != pNode->attrs.end() && (Var = Var##Iter->second) ), Var##Iter != pNode->attrs.end(); \
for( Var##Iter = (pNode)->m_attrs.begin(); \
(Var##Iter != (pNode)->m_attrs.end() && (Var = Var##Iter->second) ), Var##Iter != (pNode)->m_attrs.end(); \
++Var##Iter )
#define FOREACH_Child( pNode, Var ) \
XNodes::iterator Var##Iter; \
XNode *Var = NULL; \
for( Var##Iter = pNode->childs.begin(); \
(Var##Iter != pNode->childs.end() && (Var = Var##Iter->second) ), Var##Iter != pNode->childs.end(); \
for( Var##Iter = (pNode)->m_childs.begin(); \
(Var##Iter != (pNode)->m_childs.end() && (Var = Var##Iter->second) ), Var##Iter != (pNode)->m_childs.end(); \
++Var##Iter )
#define FOREACH_CONST_Child( pNode, Var ) \
XNodes::const_iterator Var##Iter; \
const XNode *Var = NULL; \
for( Var##Iter = pNode->childs.begin(); \
(Var##Iter != pNode->childs.end() && (Var = Var##Iter->second) ), Var##Iter != pNode->childs.end(); \
for( Var##Iter = (pNode)->m_childs.begin(); \
(Var##Iter != (pNode)->m_childs.end() && (Var = Var##Iter->second) ), Var##Iter != (pNode)->m_childs.end(); \
++Var##Iter )
@@ -135,8 +135,8 @@ extern DISP_OPT optDefault;
// XAttr : Attribute Implementation
struct XAttr
{
CString name; // a duplicate of the name in the parent's map
CString value;
CString m_sName; // a duplicate of the m_sName in the parent's map
CString m_sValue;
void GetValue(CString &out) const;
void GetValue(int &out) const;
void GetValue(float &out) const;
@@ -150,8 +150,8 @@ struct XAttr
// XMLNode structure
struct XNode
{
CString name; // a duplicate of the name in the parent's map
CString value;
CString m_sName; // a duplicate of the m_sName in the parent's map
CString m_sValue;
void GetValue(CString &out) const;
void GetValue(int &out) const;
void GetValue(float &out) const;
@@ -165,8 +165,8 @@ struct XNode
void SetValue(const DateTime &v);
// internal variables
XNodes childs; // child node
XAttrs attrs; // attributes
XNodes m_childs; // child node
XAttrs m_attrs; // attributes
// Load/Save XML
char* Load( const char* pszXml, PARSEINFO *pi = &piDefault );
@@ -189,9 +189,9 @@ struct XNode
bool GetAttrValue(const char* name,DateTime &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
// in one level child nodes
const XNode *GetChild( const char* name ) const;
XNode *GetChild( const char* name );
const char* GetChildValue( const char* name );
const XNode *GetChild( const char* m_sName ) const;
XNode *GetChild( const char* m_sName );
const char* GetChildValue( const char* m_sName );
bool GetChildValue(const char* name,CString &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue(const char* name,int &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue(const char* name,float &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
@@ -204,28 +204,29 @@ struct XNode
// modify DOM
int GetChildCount();
XNode *CreateNode( const char* name = NULL, const char* value = NULL );
XNode *AppendChild( const char* name = NULL, const char* value = NULL );
XNode *AppendChild( const char* name, float value );
XNode *AppendChild( const char* name, int value );
XNode *AppendChild( const char* name, unsigned value );
XNode *AppendChild( const char* name, const DateTime &value );
XNode *AppendChild( const char* m_sName = NULL, const char* value = NULL );
XNode *AppendChild( const char* m_sName, float value );
XNode *AppendChild( const char* m_sName, int value );
XNode *AppendChild( const char* m_sName, unsigned value );
XNode *AppendChild( const char* m_sName, const DateTime &value );
XNode *AppendChild( XNode *node );
bool RemoveChild( XNode *node );
XAttr *CreateAttr( const char* anem = NULL, const char* value = NULL );
XAttr *AppendAttr( const char* name = NULL, const char* value = NULL );
XAttr *AppendAttr( const char* name, float value );
XAttr *AppendAttr( const char* name, int value );
XAttr *AppendAttr( const char* name, unsigned value );
XAttr *AppendAttr( const char* name, const DateTime &value );
XAttr *AppendAttr( const char* m_sName = NULL, const char* value = NULL );
XAttr *AppendAttr( const char* m_sName, float value );
XAttr *AppendAttr( const char* m_sName, int value );
XAttr *AppendAttr( const char* m_sName, unsigned value );
XAttr *AppendAttr( const char* m_sName, const DateTime &value );
XAttr *AppendAttr( XAttr *attr );
bool RemoveAttr( XAttr *attr );
// creates the attribute if it doesn't already exist
void SetAttrValue( const char* m_sName, const char* value );
XNode() { }
~XNode();
void Close();
void Clear();
};
// Helper Funtion