]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modechange.h
Use IsCTCP in blockcolor for ignoring CTCPs.
[user/henk/code/inspircd.git] / include / modechange.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2014, 2018 Attila Molnar <attilamolnar@hush.com>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #pragma once
22
23 namespace Modes
24 {
25         struct Change;
26         class ChangeList;
27 }
28
29 /** A single mode to be changed
30  */
31 struct Modes::Change
32 {
33         bool adding;
34         ModeHandler* mh;
35         std::string param;
36
37         /**
38          * @param handler Mode handler
39          * @param add True if this mode is being set, false if removed
40          * @param parameter Mode parameter
41          */
42         Change(ModeHandler* handler, bool add, const std::string& parameter)
43                 : adding(add)
44                 , mh(handler)
45                 , param(parameter)
46         {
47         }
48 };
49
50 /** A list of mode changes that can be applied on a Channel or User
51  */
52 class Modes::ChangeList
53 {
54  public:
55         typedef std::vector<Change> List;
56
57         /** Add a new mode to be changed to this ChangeList
58          * @param change Mode change to add
59          */
60         void push(const Modes::Change& change)
61         {
62                 items.push_back(change);
63         }
64
65         /** Insert multiple mode changes to the ChangeList
66          * @param first Iterator to the first change to insert
67          * @param last Iterator to the first change to not insert
68          */
69         void push(List::const_iterator first, List::const_iterator last)
70         {
71                 items.insert(items.end(), first, last);
72         }
73
74         /** Add a new mode to be changed to this ChangeList
75          * @param mh Mode handler
76          * @param adding True if this mode is being set, false if removed
77          * @param param Mode parameter
78          */
79         void push(ModeHandler* mh, bool adding, const std::string& param = std::string())
80         {
81                 items.push_back(Change(mh, adding, param));
82         }
83
84         /** Add a new mode to this ChangeList which will be set on the target
85          * @param mh Mode handler
86          * @param param Mode parameter
87          */
88         void push_add(ModeHandler* mh, const std::string& param = std::string())
89         {
90                 push(mh, true, param);
91         }
92
93         /** Add a new mode to this ChangeList which will be unset from the target
94          * @param mh Mode handler
95          * @param param Mode parameter
96          */
97         void push_remove(ModeHandler* mh, const std::string& param = std::string())
98         {
99                 push(mh, false, param);
100         }
101
102         /** Remove all mode changes from this stack
103          */
104         void clear() { items.clear(); }
105
106         /** Checks whether the ChangeList is empty, equivalent to (size() != 0).
107          * @return True if the ChangeList is empty, false otherwise.
108          */
109         bool empty() const { return items.empty(); }
110
111         /** Get number of mode changes in this ChangeList
112          * @return Number of mode changes in this ChangeList
113          */
114         List::size_type size() const { return items.size(); }
115
116         /** Get the list of mode changes in this ChangeList
117          * @return List of modes added to this ChangeList
118          */
119         const List& getlist() const { return items; }
120
121         /** Get the list of mode changes in this ChangeList
122          * @return List of modes added to this ChangeList
123          */
124         List& getlist() { return items; }
125
126  private:
127         List items;
128 };