diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-09-03 14:06:45 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-09-03 14:06:45 +0200 |
commit | 39bd7db53837fd5d2a0e4d2e9ca54e0f309a0d17 (patch) | |
tree | 3d7b36350b4118c9541c5750291a5c2ef8091a74 /include | |
parent | 01a6b5d21c8a24a133693c7c65779cfa78fc164d (diff) |
Add Modes::Change and Modes::ChangeList
Diffstat (limited to 'include')
-rw-r--r-- | include/mode.h | 1 | ||||
-rw-r--r-- | include/modechange.h | 110 |
2 files changed, 111 insertions, 0 deletions
diff --git a/include/mode.h b/include/mode.h index 9e57cf298..596a7bcbe 100644 --- a/include/mode.h +++ b/include/mode.h @@ -23,6 +23,7 @@ #pragma once #include "ctables.h" +#include "modechange.h" /** * Holds the values for different type of modes diff --git a/include/modechange.h b/include/modechange.h new file mode 100644 index 000000000..e20665790 --- /dev/null +++ b/include/modechange.h @@ -0,0 +1,110 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#pragma once + +namespace Modes +{ + struct Change; + class ChangeList; +} + +/** A single mode to be changed + */ +struct Modes::Change +{ + bool adding; + ModeHandler* mh; + std::string param; + + /** + * @param handler Mode handler + * @param add True if this mode is being set, false if removed + * @param parameter Mode parameter + */ + Change(ModeHandler* handler, bool add, const std::string& parameter) + : adding(add) + , mh(handler) + , param(parameter) + { + } +}; + +/** A list of mode changes that can be applied on a Channel or User + */ +class Modes::ChangeList +{ + public: + typedef std::vector<Change> List; + + /** Add a new mode to be changed to this ChangeList + * @param handler Mode handler + * @param add True if this mode is being set, false if removed + * @param parameter Mode parameter + */ + void push(ModeHandler* mh, bool adding, const std::string& param = std::string()) + { + items.push_back(Change(mh, adding, param)); + } + + /** Add a new mode to this ChangeList which will be set on the target + * @param handler Mode handler + * @param parameter Mode parameter + */ + void push_add(ModeHandler* mh, const std::string& param = std::string()) + { + push(mh, true, param); + } + + /** Add a new mode to this ChangeList which will be unset from the target + * @param handler Mode handler + * @param parameter Mode parameter + */ + void push_remove(ModeHandler* mh, const std::string& param = std::string()) + { + push(mh, false, param); + } + + /** Remove all mode changes from this stack + */ + void clear() { items.clear(); } + + /** Checks whether the ChangeList is empty, equivalent to (size() != 0). + * @return True if the ChangeList is empty, false otherwise. + */ + bool empty() const { return items.empty(); } + + /** Get number of mode changes in this ChangeList + * @return Number of mode changes in this ChangeList + */ + List::size_type size() const { return items.size(); } + + /** Get the list of mode changes in this ChangeList + * @return List of modes added to this ChangeList + */ + const List& getlist() const { return items; } + + /** Get the list of mode changes in this ChangeList + * @return List of modes added to this ChangeList + */ + List& getlist() { return items; } + + private: + List items; +}; |