eventpp is a C++ event library for callbacks, event dispatcher, and event queue. With eventpp you can easily implement signal and slot mechanism, publisher and subscriber pattern, or observer pattern.
eventpp is mature and production-ready.
Apache License, Version 2.0
eventpp
package is available in C++ package managers Vcpkg, Conan, Hunter, and Homebrew.
The master branch is usable and stable.
Don't worry about the large time span between commits and releases. The library is actively maintained.
The master branch is currently fully back compatible with the first version. So your project won't get any back compatible issues.
If you find any back compatible issue which is not announced, please report a bug.
https://github.com/wqking/eventpp
Tested with MSVC 2022 and 2019, MinGW (Msys) GCC 7.2, Ubuntu GCC 5.4, Intel C++ 2022, and MacOS GCC. GCC 4.8.3 can compile the library, but I don't support or maintain for GCC prior to GCC 5. In brief, MSVC, GCC, Clang that has well support for C++11, or released after 2019, should be able to compile the library.
C++ standard requirementseventpp
eventpp
package is available in C++ package managers Vcpkg, Conan, and Hunter. There are various methods to use eventpp.
Please read the document for details.
#include "eventpp/callbacklist.h" eventpp::CallbackList<void (const std::string &, const bool)> callbackList; callbackList.append([](const std::string & s, const bool b) { std::cout << std::boolalpha << "Got callback 1, s is " << s << " b is " << b << std::endl; }); callbackList.append([](std::string s, int b) { std::cout << std::boolalpha << "Got callback 2, s is " << s << " b is " << b << std::endl; }); callbackList("Hello world", true);
#include "eventpp/eventdispatcher.h" eventpp::EventDispatcher<int, void ()> dispatcher; dispatcher.appendListener(3, []() { std::cout << "Got event 3." << std::endl; }); dispatcher.appendListener(5, []() { std::cout << "Got event 5." << std::endl; }); dispatcher.appendListener(5, []() { std::cout << "Got another event 5." << std::endl; }); // dispatch event 3 dispatcher.dispatch(3); // dispatch event 5 dispatcher.dispatch(5);
#include "eventpp/eventqueue.h" eventpp::EventQueue<int, void (const std::string &, const bool)> queue; queue.appendListener(3, [](const std::string s, bool b) { std::cout << std::boolalpha << "Got event 3, s is " << s << " b is " << b << std::endl; }); queue.appendListener(5, [](const std::string s, bool b) { std::cout << std::boolalpha << "Got event 5, s is " << s << " b is " << b << std::endl; }); // The listeners are not triggered during enqueue. queue.enqueue(3, "Hello", true); queue.enqueue(5, "World", false); // Process the event queue, dispatch all queued events. queue.process();
I (wqking) am a big fan of observer pattern (publish/subscribe pattern), and I used this pattern extensively in my code. I either used GCallbackList in my cpgf library which is too simple and unsafe (not support multi-threading or nested events), or repeated coding event dispatching mechanism such as I did in my Gincu game engine (the latest version has be rewritten to use eventpp). Both methods are not fun nor robust.
Thanking to C++11, now it's quite easy to write a reusable event library with beautiful syntax (it's a nightmare to simulate the variadic template in C++03), so here is eventpp
.
Version 0.1.3 Sep 21, 2023
Added utility class AnyData.
Small bugs fixes and improvements.
Version 0.1.2 Mar 11, 2022
Bug fix.
Added more unit tests.
Added utilities argumentAdapter and conditionalFunctor.
Added utilities AnyId.
Added event maker macros.
Version 0.1.1 Dec 13, 2019
Added HeterCallbackList, HeterEventDispatcher, and HeterEventQueue.
Version 0.1.0 Sep 1, 2018
First version.
Added CallbackList, EventDispatcher, EventQueue, CounterRemover, ConditionalRemover, ScopedRemover, and utilities.
I (wqking) would like to sincerely thank all participants for the contributions. Your contributions make eventpp
better and bright future. I maintain the contributors list manually, according to the criteria below,
If you think you should be on the contributors list, such as I miss out your work, or you have work not technology related but can help eventpp
growing (such as posting review in social network with large amount of readers), please contact me, I'm happy to get the contributors list larger.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4