]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modechange.h
Merge v2.0.23 and v2.0.24 into master.
[user/henk/code/inspircd.git] / include / modechange.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 namespace Modes
23 {
24         struct Change;
25         class ChangeList;
26 }
27
28 /** A single mode to be changed
29  */
30 struct Modes::Change
31 {
32         bool adding;
33         ModeHandler* mh;
34         std::string param;
35
36         /**
37          * @param handler Mode handler
38          * @param add True if this mode is being set, false if removed
39          * @param parameter Mode parameter
40          */
41         Change(ModeHandler* handler, bool add, const std::string& parameter)
42                 : adding(add)
43                 , mh(handler)
44                 , param(parameter)
45         {
46         }
47 };
48
49 /** A list of mode changes that can be applied on a Channel or User
50  */
51 class Modes::ChangeList
52 {
53  public:
54         typedef std::vector<Change> List;
55
56         /** Add a new mode to be changed to this ChangeList
57          * @param handler Mode handler
58          * @param add True if this mode is being set, false if removed
59          * @param parameter Mode parameter
60          */
61         void push(ModeHandler* mh, bool adding, const std::string& param = std::string())
62         {
63                 items.push_back(Change(mh, adding, param));
64         }
65
66         /** Add a new mode to this ChangeList which will be set on the target
67          * @param handler Mode handler
68          * @param parameter Mode parameter
69          */
70         void push_add(ModeHandler* mh, const std::string& param = std::string())
71         {
72                 push(mh, true, param);
73         }
74
75         /** Add a new mode to this ChangeList which will be unset from the target
76          * @param handler Mode handler
77          * @param parameter Mode parameter
78          */
79         void push_remove(ModeHandler* mh, const std::string& param = std::string())
80         {
81                 push(mh, false, param);
82         }
83
84         /** Remove all mode changes from this stack
85          */
86         void clear() { items.clear(); }
87
88         /** Checks whether the ChangeList is empty, equivalent to (size() != 0).
89          * @return True if the ChangeList is empty, false otherwise.
90          */
91         bool empty() const { return items.empty(); }
92
93         /** Get number of mode changes in this ChangeList
94          * @return Number of mode changes in this ChangeList
95          */
96         List::size_type size() const { return items.size(); }
97
98         /** Get the list of mode changes in this ChangeList
99          * @return List of modes added to this ChangeList
100          */
101         const List& getlist() const { return items; }
102
103         /** Get the list of mode changes in this ChangeList
104          * @return List of modes added to this ChangeList
105          */
106         List& getlist() { return items; }
107
108  private:
109         List items;
110 };