forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_bus.h
33 lines (26 loc) · 809 Bytes
/
event_bus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#ifndef CATA_SRC_EVENT_BUS_H
#define CATA_SRC_EVENT_BUS_H
#include <type_traits>
#include <vector>
#include "event.h"
class event_subscriber;
class event_bus
{
public:
event_bus() = default;
event_bus( const event_bus & ) = delete;
event_bus &operator=( const event_bus & ) = delete;
~event_bus();
void subscribe( event_subscriber * );
void unsubscribe( event_subscriber * );
void send( const cata::event & ) const;
template<event_type Type, typename... Args>
void send( Args &&... args ) const {
send( cata::event::make<Type>( std::forward<Args>( args )... ) );
}
private:
std::vector<event_subscriber *> subscribers;
};
event_bus &get_event_bus();
#endif // CATA_SRC_EVENT_BUS_H