From 9aed486eeb95b38b18ad47e3c8634b5832943ad8 Mon Sep 17 00:00:00 2001 From: Axel Cocat Date: Fri, 5 Aug 2022 15:09:26 +0200 Subject: [PATCH] feat(Core/Utilities): add event emitter class (#12632) --- src/common/Utilities/EventEmitter.h | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/common/Utilities/EventEmitter.h diff --git a/src/common/Utilities/EventEmitter.h b/src/common/Utilities/EventEmitter.h new file mode 100644 index 000000000..77755935b --- /dev/null +++ b/src/common/Utilities/EventEmitter.h @@ -0,0 +1,44 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * 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 Affero 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 . + */ + +#ifndef __EVENT_EMITTER_H +#define __EVENT_EMITTER_H + +template +class EventEmitter +{ +public: + template + void operator+=(Functor&& f) + { + functions.emplace_back(std::forward(f)); + } + + template + void operator()(Args&&... args) const + { + for (auto& f : functions) + { + f(args...); + } + } + +private: + std::vector> functions; +}; + +#endif