InspIRCd  3.0
parammode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2014 Attila Molnar <[email protected]>
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  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;
37 };
38 
45 template <typename T, typename ExtItemT>
46 class ParamMode : public ParamModeBase
47 {
48  public:
49  ExtItemT ext;
50 
57  ParamMode(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps = PARAM_SETONLY)
58  : ParamModeBase(Creator, Name, modeletter, ps)
59  , ext("parammode_" + Name, ExtensionItem::EXT_CHANNEL, Creator)
60  {
61  }
62 
63  void OnUnsetInternal(User* source, Channel* chan) CXX11_OVERRIDE
64  {
65  T* mh = static_cast<T*>(this);
66  mh->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 };
Definition: mode.h:95
ModeHandler(Module *me, const std::string &name, char modeletter, ParamSpec params, ModeType type, Class mclass=MC_OTHER)
Definition: mode.cpp:29
ParamMode(Module *Creator, const std::string &Name, char modeletter, ParamSpec ps=PARAM_SETONLY)
Definition: parammode.h:57
Definition: users.h:224
Definition: extensible.h:36
virtual ModeAction OnModeChange(User *source, User *dest, Channel *channel, std::string &parameter, bool adding)
Definition: mode.cpp:71
Definition: modules.h:245
Definition: parammode.h:22
Definition: parammode.h:46
Definition: channels.h:37