🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

eventpp -- open source C++ library for event dispatcher and callback list

Started by
0 comments, last by wqking 5 years, 11 months ago

https://github.com/wqking/eventpp

eventpp is an open source C++ event library that provides tools that allow your application components to communicate with each other by dispatching events and listening to them. With eventpp you can implement signal/slot mechanism, or observer pattern, very easily.

Facts and features

  • Powerful
    • Supports both synchronous event dispatching and asynchronous event queue.
    • Configurable and extensible with policies and mixins.
    • Supports event filter via mixins.
  • Robust
    • Supports nested event. During handling an event a listener can safely dispatch event, append/prepend/insert/remove other listeners.
    • Thread safety. Supports multiple threading.
    • Exception safety. Most operations guarantee strong exception safety.
    • Well tested. Backed by unit tests.
  • Fast
    • The EventQueue can process 10M events in 1 second (10K events per millisecond).
    • The CallbackList can invoke 100M callbacks in 1 second (100K callbacks per millisecond).
    • The CallbackList can add/remove 5M callbacks in 1 second (5K callbacks per millisecond).
  • Flexible and easy to use
    • The listeners and events can be any type, no need to inherit from any base class.
    • Header only, no source file, no need to build. No dependencies on other libraries.
    • Requires C++ 11 (tested with MSVC 2017, MSVC 2015, MinGW (Msys) gcc 7.2, and Ubuntu gcc 5.4).
    • Written in portable and standard C++, no hacks or quirks.

License

Apache License, Version 2.0

Version 0.1.0

eventpp is currently usable and near stable.

Quick start

Namespace

eventpp

Using CallbackList


#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);

Using EventDispatcher


#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);

Using EventQueue


eventpp::EventQueue<int, void (const std::string &, const bool)> queue;

dispatcher.appendListener(3, [](const std::string s, bool b) {
	std::cout << std::boolalpha << "Got event 3, s is " << s << " b is " << b << std::endl;
});
dispatcher.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();

 

Please check Github for the source code and documentations.

https://github.com/wqking/eventpp

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

This topic is closed to new replies.

Advertisement