diff --git a/stepmania/src/IniFile.cpp b/stepmania/src/IniFile.cpp index 207e27167d..65076e629b 100644 --- a/stepmania/src/IniFile.cpp +++ b/stepmania/src/IniFile.cpp @@ -246,7 +246,20 @@ bool IniFile::DeleteKey(const CString &keyname) return true; } -IniFile::const_iterator IniFile::GetKey(const CString &keyname) const +const IniFile::key *IniFile::GetKey(const CString &keyname) const { - return keys.find(keyname); + keymap::const_iterator i = keys.find(keyname); + if(i == keys.end()) return NULL; + return &i->second; +} + +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); } diff --git a/stepmania/src/IniFile.h b/stepmania/src/IniFile.h index 45d4e3c0e5..5dd6e2cc7d 100644 --- a/stepmania/src/IniFile.h +++ b/stepmania/src/IniFile.h @@ -90,7 +90,12 @@ public: //returns true if key existed and deleted, false otherwise bool DeleteKey(const CString &keyname); - const_iterator GetKey(const CString &keyname) const; + const key *GetKey(const CString &keyname) const; + + /* 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); }; #endif diff --git a/stepmania/src/InputMapper.cpp b/stepmania/src/InputMapper.cpp index 96637cb094..e53c4625ff 100644 --- a/stepmania/src/InputMapper.cpp +++ b/stepmania/src/InputMapper.cpp @@ -75,12 +75,12 @@ void InputMapper::ReadMappingsFromDisk() if( !ini.ReadFile() ) LOG->Warn( "could not input mapping file '%s'.", sPath.GetString() ); - IniFile::const_iterator Key = ini.GetKey( "Input" ); + const IniFile::key *Key = ini.GetKey( "Input" ); - if( Key != ini.end() ) + if( Key ) { - for( IniFile::key::const_iterator i = Key->second.begin(); - i != Key->second.end(); ++i ) + for( IniFile::key::const_iterator i = Key->begin(); + i != Key->end(); ++i ) { CString name = i->first; CString value = i->second; diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 2866dd7dc8..a4d31a94d3 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -265,11 +265,11 @@ void SongManager::ReadStatisticsFromDisk() // load song statistics - IniFile::const_iterator Key = ini.GetKey( "Statistics" ); - if( Key != ini.end() ) + const IniFile::key *Key = ini.GetKey( "Statistics" ); + if( Key ) { - for( IniFile::key::const_iterator i = Key->second.begin(); - i != Key->second.end(); ++i ) + for( IniFile::key::const_iterator i = Key->begin(); + i != Key->end(); ++i ) { CString name = i->first; CString value = i->second;