libfilezilla
0.59.0
A cross-platform C++ library for asynchronous and networked applications
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
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
12
13
namespace
fz
{
14
22
class
FZ_PUBLIC_SYMBOL event_base
23
{
24
public
:
25
event_base() =
default
;
26
virtual
~event_base() =
default
;
27
28
event_base(event_base
const
&) =
default
;
29
event_base& operator=(event_base
const
&) =
default
;
30
event_base(event_base &&) =
default
;
31
event_base& operator=(event_base &&) =
default
;
32
48
virtual
size_t
derived_type
()
const
= 0;
49
};
50
54
size_t
FZ_PUBLIC_SYMBOL
get_unique_type_id
(std::type_info
const
&
id
);
55
65
66
template
<
typename
UniqueType,
typename
...Values>
67
class
simple_event final :
public
event_base
68
{
69
public
:
70
typedef
UniqueType unique_type;
71
typedef
std::tuple<Values...> tuple_type;
72
73
using
event_base::event_base;
74
75
template
<
typename
First_Value,
typename
...Remaining_Values>
76
explicit
simple_event(First_Value&& value, Remaining_Values&& ...values)
77
:
v_
(std::forward<First_Value>(value), std::forward<Remaining_Values>(values)...)
78
{
79
}
80
82
inline
static
size_t
type
() {
83
// Exporting templates from DLLs is problematic to say the least. It breaks
84
// ODR, so we use this trick that goes over the type name.
85
static
size_t
const
v =
get_unique_type_id
(
typeid
(UniqueType*));
86
return
v;
87
}
88
90
virtual
size_t
derived_type
()
const override
{
91
return
type
();
92
}
93
98
mutable
tuple_type
v_
;
99
};
100
101
class
event_source
{};
102
104
class
FZ_PUBLIC_SYMBOL event_with_source_base :
public
event_base
105
{
106
public
:
107
using
event_base::event_base;
108
virtual
event_source
const
* source()
const
= 0;
109
};
110
122
template
<
typename
UniqueType,
typename
...Values>
123
class
event_with_source final :
public
event_with_source_base
124
{
125
public
:
126
typedef
UniqueType unique_type;
127
typedef
std::tuple<Values...> tuple_type;
128
129
using
event_with_source_base::event_with_source_base;
130
131
template
<
typename
First_Value,
typename
...Remaining_Values>
132
explicit
event_with_source(First_Value&& value, Remaining_Values&& ...values)
133
: v_(std::forward<First_Value>(value), std::forward<Remaining_Values>(values)...)
134
{
135
}
136
137
inline
static
size_t
type() {
138
static
size_t
const
v =
get_unique_type_id
(
typeid
(UniqueType*));
139
return
v;
140
}
141
142
virtual
size_t
derived_type
()
const override
{
143
return
type();
144
}
145
146
virtual
event_source
const
* source()
const override
{
147
return
static_cast<
event_source
const*
>
(std::get<0>(v_));
148
}
149
150
mutable
tuple_type v_;
151
};
152
155
template
<
typename
T>
156
bool
same_type
(
event_base
const
& ev)
157
{
158
return
ev.
derived_type
() == T::type();
159
}
160
161
typedef
unsigned
long
long
timer_id;
162
164
struct
timer_event_type{};
165
170
typedef
simple_event<timer_event_type, timer_id>
timer_event
;
171
172
}
173
174
#endif
fz::event_base
Common base class for all events.
Definition
event.hpp:23
fz::event_base::derived_type
virtual size_t derived_type() const =0
fz::event_source
Definition
event.hpp:101
fz::event_with_source::derived_type
virtual size_t derived_type() const override
Definition
event.hpp:142
fz::simple_event
This is the recommended event class.
Definition
event.hpp:68
fz::simple_event::v_
tuple_type v_
The event value, gets built from the arguments passed in the constructor.
Definition
event.hpp:98
fz::simple_event::derived_type
virtual size_t derived_type() const override
Simply returns type().
Definition
event.hpp:90
fz::simple_event::type
static size_t type()
Returns a unique id for the type such that can be used directly in derived_type.
Definition
event.hpp:82
libfilezilla.hpp
Sets some global macros and further includes string.hpp.
fz
The namespace used by libfilezilla.
Definition
apply.hpp:17
fz::timer_event
simple_event< timer_event_type, timer_id > timer_event
All timer events have this type.
Definition
event.hpp:170
fz::get_unique_type_id
size_t get_unique_type_id(std::type_info const &id)
fz::same_type
bool same_type(event_base const &ev)
Definition
event.hpp:156
Generated by
1.18.0