]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/parammode.h
Add an event provider class for the event/messagetag event.
[user/henk/code/inspircd.git] / include / parammode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #pragma once
21
22 class CoreExport ParamModeBase : public ModeHandler
23 {
24  private:
25         virtual void OnUnsetInternal(User* source, Channel* chan) = 0;
26
27  public:
28         ParamModeBase(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps)
29                 : ModeHandler(Creator, Name, modeletter, ps, MODETYPE_CHANNEL, MC_PARAM) { }
30
31         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& param, bool adding) CXX11_OVERRIDE;
32
33         // Does nothing by default
34         virtual bool IsParameterSecret() { return false; }
35         virtual void OnUnset(User* source, Channel* chan) { }
36         virtual ModeAction OnSet(User* source, Channel* chan, std::string& param) = 0;
37         virtual void GetParameter(Channel* chan, std::string& out) = 0;
38 };
39
40 /** Defines a parameter mode
41  * T = Child class
42  * ExtItemT = Type of the extension item used to store the parameter
43  *
44  * When unsetting the mode, the extension is automatically unset.
45  */
46 template <typename T, typename ExtItemT>
47 class ParamMode : public ParamModeBase
48 {
49  public:
50         ExtItemT ext;
51
52         /**
53          * @param Creator Module handling this mode
54          * @param Name The internal name of this mode
55          * @param modeletter The mode letter of this mode
56          * @param ps The parameter type of this mode, one of ParamSpec
57          */
58         ParamMode(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps = PARAM_SETONLY)
59                 : ParamModeBase(Creator, Name, modeletter, ps)
60                 , ext("parammode_" + Name, ExtensionItem::EXT_CHANNEL, Creator)
61         {
62         }
63
64         void OnUnsetInternal(User* source, Channel* chan) CXX11_OVERRIDE
65         {
66                 this->OnUnset(source, chan);
67                 ext.unset(chan);
68         }
69
70         void GetParameter(Channel* chan, std::string& out) CXX11_OVERRIDE
71         {
72                 T* mh = static_cast<T*>(this);
73                 mh->SerializeParam(chan, ext.get(chan), out);
74         }
75 };