add key renaming

fix a possible glitch
This commit is contained in:
Glenn Maynard
2003-01-03 22:37:44 +00:00
parent 0c9b9c8b28
commit 6341356c9e
4 changed files with 29 additions and 11 deletions
+15 -2
View File
@@ -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);
}
+6 -1
View File
@@ -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
+4 -4
View File
@@ -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;
+4 -4
View File
@@ -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;