libfilezilla
event.hpp
Go to the documentation of this file.
1#ifndef LIBFILEZILLA_EVENT_HEADER
2#define LIBFILEZILLA_EVENT_HEADER
3
4#include "libfilezilla.hpp"
5
6#include <tuple>
7#include <typeinfo>
8
13namespace fz {
14
22class FZ_PUBLIC_SYMBOL event_base
23{
24public:
25 event_base() = default;
26 virtual ~event_base() {}
27
28 event_base(event_base const&) = delete;
29 event_base& operator=(event_base const&) = delete;
30
46 virtual size_t derived_type() const = 0;
47};
48
52size_t FZ_PUBLIC_SYMBOL get_unique_type_id(std::type_info const& id);
53
64template<typename UniqueType, typename...Values>
65class simple_event final : public event_base
66{
67public:
68 typedef UniqueType unique_type;
69 typedef std::tuple<Values...> tuple_type;
70
71 simple_event() = default;
72
73 template<typename First_Value, typename...Remaining_Values>
74 explicit simple_event(First_Value&& value, Remaining_Values&& ...values)
75 : v_(std::forward<First_Value>(value), std::forward<Remaining_Values>(values)...)
76 {
77 }
78
79 simple_event(simple_event const& op) = default;
80 simple_event& operator=(simple_event const& op) = default;
81
83 inline static size_t type() {
84 // Exporting templates from DLLs is problematic to say the least. It breaks
85 // ODR, so we use this trick that goes over the type name.
86 static size_t const v = get_unique_type_id(typeid(UniqueType*));
87 return v;
88 }
89
91 virtual size_t derived_type() const {
92 return type();
93 }
94
99 mutable tuple_type v_;
100};
101
104template<typename T>
105bool same_type(event_base const& ev)
106{
107 return ev.derived_type() == T::type();
108}
109
110typedef unsigned long long timer_id;
111
113struct timer_event_type{};
114
120
121}
122
123#endif
Common base class for all events.
Definition: event.hpp:23
virtual size_t derived_type() const =0
This is the recommended event class.
Definition: event.hpp:66
tuple_type v_
The event value, gets built from the arguments passed in the constructor.
Definition: event.hpp:99
virtual size_t derived_type() const
Simply returns type()
Definition: event.hpp:91
static size_t type()
Returns a unique id for the type such that can be used directly in derived_type.
Definition: event.hpp:83
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition: apply.hpp:17
simple_event< timer_event_type, timer_id > timer_event
All timer events have this type.
Definition: event.hpp:119
size_t get_unique_type_id(std::type_info const &id)
bool same_type(event_base const &ev)
Definition: event.hpp:105