void C4KeyboardInput::UpdateKeyCodes(C4CustomKey *pKey, const C4CustomKey::CodeList &rOldCodes, const C4CustomKey::CodeList &rNewCodes) { // new key codes must be the new current key codes assert(pKey->GetCodes() == rNewCodes); // kill from old list C4CustomKey::CodeList::const_iterator iCode; for (iCode = rOldCodes.begin(); iCode != rOldCodes.end(); ++iCode) { // no need to kill if code stayed if (std::find(rNewCodes.begin(), rNewCodes.end(), *iCode) != rNewCodes.end()) continue; std::pair<KeyCodeMap::iterator, KeyCodeMap::iterator> KeyRange = KeysByCode.equal_range((*iCode).Key); for (KeyCodeMap::iterator i = KeyRange.first; i != KeyRange.second; ++i) if (i->second == pKey) { KeysByCode.erase(i); break; } } // readd new codes for (iCode = rNewCodes.begin(); iCode != rNewCodes.end(); ++iCode) { // no double-add if it was in old list already if (std::find(rOldCodes.begin(), rOldCodes.end(), *iCode) != rOldCodes.end()) continue; KeysByCode.insert(std::make_pair((*iCode).Key, pKey)); } }