add key renaming
fix a possible glitch
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user