]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Create a name -> ModeHandler* map
authorAttila Molnar <attilamolnar@hush.com>
Thu, 20 Feb 2014 12:20:21 +0000 (13:20 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Thu, 20 Feb 2014 12:20:21 +0000 (13:20 +0100)
include/mode.h
src/mode.cpp

index 2e40badca5e8d246a2759cea19fdd6f95523c442..4b8aa09359fdb2403e5831c96e03acd3172055e3 100644 (file)
@@ -479,6 +479,10 @@ class CoreExport ModeParser
         */
        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
@@ -486,6 +490,10 @@ class CoreExport ModeParser
         */
        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
index a2a0790b823d54443bf186c056f2c64d91503569..e70df5479f7320b85177cbddc6e9d4909e1a77d2 100644 (file)
@@ -635,6 +635,9 @@ bool ModeParser::AddMode(ModeHandler* mh)
        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)
@@ -651,6 +654,11 @@ bool ModeParser::DelMode(ModeHandler* mh)
        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;
@@ -689,6 +697,7 @@ bool ModeParser::DelMode(ModeHandler* mh)
                break;
        }
 
+       mhmap.erase(mhmapit);
        slot = NULL;
        if (mh->IsPrefixMode())
                mhlist.prefix.erase(std::find(mhlist.prefix.begin(), mhlist.prefix.end(), mh->IsPrefixMode()));