2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 class CoreExport ParamModeBase : public ModeHandler
25 virtual void OnUnsetInternal(User* source, Channel* chan) = 0;
28 ParamModeBase(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps)
29 : ModeHandler(Creator, Name, modeletter, ps, MODETYPE_CHANNEL, MC_PARAM) { }
31 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& param, bool adding) CXX11_OVERRIDE;
33 // Does nothing by default
34 void OnUnset(User* source, Channel* chan) { }
35 virtual ModeAction OnSet(User* source, Channel* chan, std::string& param) = 0;
36 virtual void GetParameter(Channel* chan, std::string& out) = 0;
39 /** Defines a parameter mode
41 * ExtItemT = Type of the extension item used to store the parameter
43 * When unsetting the mode, the extension is automatically unset.
45 template <typename T, typename ExtItemT>
46 class ParamMode : public ParamModeBase
52 * @param Creator Module handling this mode
53 * @param Name The internal name of this mode
54 * @param modeletter The mode letter of this mode
55 * @param ps The parameter type of this mode, one of ParamSpec
57 ParamMode(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps = PARAM_SETONLY)
58 : ParamModeBase(Creator, Name, modeletter, ps)
59 , ext("parammode_" + Name, Creator)
63 void OnUnsetInternal(User* source, Channel* chan) CXX11_OVERRIDE
65 T* mh = static_cast<T*>(this);
66 mh->OnUnset(source, chan);
70 void GetParameter(Channel* chan, std::string& out) CXX11_OVERRIDE
72 T* mh = static_cast<T*>(this);
73 mh->SerializeParam(chan, ext.get(chan), out);