From 1b6dda7ad54dd0242cd9eac30f167d76f061d2fa Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Fri, 21 Feb 2014 14:42:16 +0100 Subject: Assign an id to user modes, parameter chanmodes and simple chanmodes --- include/mode.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'include') diff --git a/include/mode.h b/include/mode.h index d3fdabde1..d71423ecf 100644 --- a/include/mode.h +++ b/include/mode.h @@ -94,6 +94,8 @@ class ParamModeBase; class CoreExport ModeHandler : public ServiceProvider { public: + typedef size_t Id; + enum Class { MC_PREFIX, @@ -102,6 +104,11 @@ class CoreExport ModeHandler : public ServiceProvider MC_OTHER }; + private: + /** The opaque id of this mode assigned by the mode parser + */ + Id modeid; + protected: /** * The mode parameter translation type @@ -213,6 +220,11 @@ class CoreExport ModeHandler : public ServiceProvider */ inline char GetModeChar() { return mode; } + /** Return the id of this mode which is used in User::modes and + * Channel::modes as the index to determine whether a mode is set. + */ + Id GetId() const { return modeid; } + /** For user modes, return the current parameter, if any */ virtual std::string GetUserParameter(User* useor); @@ -295,6 +307,8 @@ class CoreExport ModeHandler : public ServiceProvider virtual void RemoveMode(Channel* channel, irc::modestacker& stack); inline unsigned int GetLevelRequired() const { return levelrequired; } + + friend class ModeParser; }; /** @@ -474,6 +488,9 @@ typedef std::multimap::iterator ModeWatchIter; */ class CoreExport ModeParser { + public: + static const ModeHandler::Id MODEID_MAX = 64; + private: /** Last item in the ModeType enum */ @@ -490,6 +507,10 @@ class CoreExport ModeParser */ ModeHandler* modehandlers[MODETYPE_LAST][128]; + /** An array of mode handlers indexed by the mode id + */ + ModeHandler* modehandlersbyid[MODETYPE_LAST][MODEID_MAX]; + /** A map of mode handlers keyed by their name */ ModeHandlerMap modehandlersbyname[MODETYPE_LAST]; @@ -539,6 +560,12 @@ class CoreExport ModeParser */ void RecreateModeListFor004Numeric(); + /** Allocates an unused id for the given mode type, throws a ModuleException if out of ids. + * @param mt The type of the mode to allocate the id for + * @return The id + */ + ModeHandler::Id AllocateModeId(ModeType mt); + /** The string representing the last set of modes to be parsed. * Use GetLastParse() to get this value, to be used for display purposes. */ -- cgit v1.2.3