InspIRCd  4.0
modechange.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2017-2018 Sadie Powell <[email protected]>
5  * Copyright (C) 2014, 2018 Attila Molnar <[email protected]>
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 
32 {
33  bool adding;
34  ModeHandler* mh;
35  std::string param;
36  std::optional<std::string> set_by;
37  std::optional<time_t> set_at;
38 
44  Change(ModeHandler* handler, bool add, const std::string& parameter = "")
45  : adding(add)
46  , mh(handler)
47  , param(parameter)
48  {
49  }
50 
58  Change(ModeHandler* handler, bool add, const std::string& parameter, const std::string& setby, time_t setat)
59  : adding(add)
60  , mh(handler)
61  , param(parameter)
62  , set_by(setby)
63  , set_at(setat)
64  {
65  }
66 };
67 
71 {
72  public:
73  typedef std::vector<Change> List;
74 
78  void push(const Modes::Change& change)
79  {
80  items.push_back(change);
81  }
82 
87  void push(List::const_iterator first, List::const_iterator last)
88  {
89  items.insert(items.end(), first, last);
90  }
91 
93  template <typename... Args>
94  void push(Args&&... args)
95  {
96  items.emplace_back(std::forward<Args>(args)...);
97  }
98 
103  void push_add(ModeHandler* mh, const std::string& param = std::string())
104  {
105  push(mh, true, param);
106  }
107 
112  void push_remove(ModeHandler* mh, const std::string& param = std::string())
113  {
114  push(mh, false, param);
115  }
116 
119  void clear() { items.clear(); }
120 
124  bool empty() const { return items.empty(); }
125 
129  List::size_type size() const { return items.size(); }
130 
134  const List& getlist() const { return items; }
135 
139  List& getlist() { return items; }
140 
141  private:
142  List items;
143 };
Definition: mode.h:100
Definition: modechange.h:71
void push_remove(ModeHandler *mh, const std::string &param=std::string())
Definition: modechange.h:112
bool empty() const
Definition: modechange.h:124
void clear()
Definition: modechange.h:119
List::size_type size() const
Definition: modechange.h:129
void push(Args &&... args)
Definition: modechange.h:94
const List & getlist() const
Definition: modechange.h:134
void push(const Modes::Change &change)
Definition: modechange.h:78
void push_add(ModeHandler *mh, const std::string &param=std::string())
Definition: modechange.h:103
List & getlist()
Definition: modechange.h:139
void push(List::const_iterator first, List::const_iterator last)
Definition: modechange.h:87
Definition: modechange.h:32
Change(ModeHandler *handler, bool add, const std::string &parameter, const std::string &setby, time_t setat)
Definition: modechange.h:58
Change(ModeHandler *handler, bool add, const std::string &parameter="")
Definition: modechange.h:44