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 
12 namespace fz {
13 
21 class FZ_PUBLIC_SYMBOL event_base
22 {
23 public:
24  event_base() = default;
25  virtual ~event_base() {}
26 
27  event_base(event_base const&) = delete;
28  event_base& operator=(event_base const&) = delete;
29 
45  virtual void const* derived_type() const = 0;
46 };
47 
57 template<typename UniqueType, typename...Values>
58 class simple_event final : public event_base
59 {
60 public:
61  typedef UniqueType unique_type;
62  typedef std::tuple<Values...> tuple_type;
63 
64  simple_event() = default;
65 
66  template<typename First_Value, typename...Remaining_Values>
67  explicit simple_event(First_Value&& value, Remaining_Values&& ...values)
68  : v_(std::forward<First_Value>(value), std::forward<Remaining_Values>(values)...)
69  {
70  }
71 
72  simple_event(simple_event const& op) = default;
73  simple_event& operator=(simple_event const& op) = default;
74 
76  static void const* type() {
77  static const char* f = nullptr;
78  return &f;
79  }
80 
82  virtual void const* derived_type() const {
83  return type();
84  }
85 
90  tuple_type v_;
91 };
92 
95 template<typename T>
96 bool same_type(event_base const& ev)
97 {
98  return ev.derived_type() == T::type();
99 }
100 
101 typedef unsigned long long timer_id;
102 
104 struct timer_event_type{};
105 
111 
114 extern template class FZ_PUBLIC_SYMBOL simple_event<timer_event_type, timer_id>;
115 
116 }
117 
118 #endif
simple_event< timer_event_type, timer_id > timer_event
All timer events have this type.
Definition: event.hpp:110
tuple_type v_
The event value, gets built from the arguments passed in the constructur.
Definition: event.hpp:90
static void const * type()
Returns a unique pointer for the type such that can be used directly in derived_type.
Definition: event.hpp:76
This is the recommended event class.
Definition: event.hpp:58
virtual void const * derived_type() const
Simply returns type()
Definition: event.hpp:82
bool same_type(event_base const &ev)
Definition: event.hpp:96
virtual void const * derived_type() const =0
The namespace used by libfilezilla.
Definition: apply.hpp:16
Sets some global macros and further includes string.hpp.
Common base class for all events.
Definition: event.hpp:21