]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modechange.h
Merge branch 'insp20' into insp3.
[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 change Mode change to add
58          */
59         void push(const Modes::Change& change)
60         {
61                 items.push_back(change);
62         }
63
64         /** Insert multiple mode changes to the ChangeList
65          * @param first Iterator to the first change to insert
66          * @param last Iterator to the first change to not insert
67          */
68         void push(List::const_iterator first, List::const_iterator last)
69         {
70                 items.insert(items.end(), first, last);
71         }
72
73         /** Add a new mode to be changed to this ChangeList
74          * @param mh Mode handler
75          * @param adding True if this mode is being set, false if removed
76          * @param param Mode parameter
77          */
78         void push(ModeHandler* mh, bool adding, const std::string& param = std::string())
79         {
80                 items.push_back(Change(mh, adding, param));
81         }
82
83         /** Add a new mode to this ChangeList which will be set on the target
84          * @param mh Mode handler
85          * @param param Mode parameter
86          */
87         void push_add(ModeHandler* mh, const std::string& param = std::string())
88         {
89                 push(mh, true, param);
90         }
91
92         /** Add a new mode to this ChangeList which will be unset from the target
93          * @param mh Mode handler
94          * @param param Mode parameter
95          */
96         void push_remove(ModeHandler* mh, const std::string& param = std::string())
97         {
98                 push(mh, false, param);
99         }
100
101         /** Remove all mode changes from this stack
102          */
103         void clear() { items.clear(); }
104
105         /** Checks whether the ChangeList is empty, equivalent to (size() != 0).
106          * @return True if the ChangeList is empty, false otherwise.
107          */
108         bool empty() const { return items.empty(); }
109
110         /** Get number of mode changes in this ChangeList
111          * @return Number of mode changes in this ChangeList
112          */
113         List::size_type size() const { return items.size(); }
114
115         /** Get the list of mode changes in this ChangeList
116          * @return List of modes added to this ChangeList
117          */
118         const List& getlist() const { return items; }
119
120         /** Get the list of mode changes in this ChangeList
121          * @return List of modes added to this ChangeList
122          */
123         List& getlist() { return items; }
124
125  private:
126         List items;
127 };