Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremyletang/safe_event
C++ 11/14 type safe light event system
https://github.com/jeremyletang/safe_event
Last synced: 3 months ago
JSON representation
C++ 11/14 type safe light event system
- Host: GitHub
- URL: https://github.com/jeremyletang/safe_event
- Owner: jeremyletang
- License: mit
- Created: 2015-01-19T17:31:39.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-29T16:46:48.000Z (almost 10 years ago)
- Last Synced: 2023-07-31T14:58:49.337Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 422 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# safe_event
C++ 11/14 type safe light event system## A simple example
```C++
#include
#includestruct hello_event {
void say_hello()
{ std::cout << "hello world !" << std::endl; }
};int
main() {
se::dispatcher ev_disp;// add the hello_event struct to the available events
ev_disp.add_event();// listen hello_event
ev_disp.listen(std::function([](const hello_event& ev) {
std::cout << "This is a real hello_event !" << std::endl;;
}));// listen any event
ev_disp.listen_any([](const se::any_event& ev) {
// make dynamic test to check the event type
if (se::is(ev)) {
std::cout << "any_event is an hello_event" << std::endl;
auto real_ev = se::into(ev);
real_ev.say_hello();
}
});// dispatch an event
ev_disp.trigger(hello_event());
}
```