*/
static const unsigned int MODETYPE_LAST = 2;
+ /** Type of the container that maps mode names to ModeHandlers
+ */
+ typedef TR1NS::unordered_map<std::string, ModeHandler*, irc::insensitive, irc::StrHashComp> ModeHandlerMap;
+
/** Mode handlers for each mode, to access a handler subtract
* 65 from the ascii value of the mode letter.
* The upper bit of the value indicates if its a usermode
*/
ModeHandler* modehandlers[MODETYPE_LAST][128];
+ /** A map of mode handlers keyed by their name
+ */
+ ModeHandlerMap modehandlersbyname[MODETYPE_LAST];
+
/** Lists of mode handlers by type
*/
struct
if (slot)
return false;
+ if (!modehandlersbyname[mh->GetModeType()].insert(std::make_pair(mh->name, mh)).second)
+ return false;
+
// Everything is fine, add the mode
slot = mh;
if (pm)
if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
return false;
+ ModeHandlerMap& mhmap = modehandlersbyname[mh->GetModeType()];
+ ModeHandlerMap::iterator mhmapit = mhmap.find(mh->name);
+ if ((mhmapit == mhmap.end()) || (mhmapit->second != mh))
+ return false;
+
ModeHandler*& slot = modehandlers[mh->GetModeType()][mh->GetModeChar()-65];
if (slot != mh)
return false;
break;
}
+ mhmap.erase(mhmapit);
slot = NULL;
if (mh->IsPrefixMode())
mhlist.prefix.erase(std::find(mhlist.prefix.begin(), mhlist.prefix.end(), mh->IsPrefixMode()));