![]() |
libfilezilla
|
00001 #ifndef LIBFILEZILLA_EVENT_HEADER 00002 #define LIBFILEZILLA_EVENT_HEADER 00003 00004 #include "libfilezilla.hpp" 00005 00006 #include <tuple> 00007 00012 namespace fz { 00013 00021 class FZ_PUBLIC_SYMBOL event_base 00022 { 00023 public: 00024 event_base() = default; 00025 virtual ~event_base() {} 00026 00027 event_base(event_base const&) = delete; 00028 event_base& operator=(event_base const&) = delete; 00029 00045 virtual void const* derived_type() const = 0; 00046 }; 00047 00057 template<typename UniqueType, typename...Values> 00058 class simple_event final : public event_base 00059 { 00060 public: 00061 typedef UniqueType unique_type; 00062 typedef std::tuple<Values...> tuple_type; 00063 00064 simple_event() = default; 00065 00066 template<typename First_Value, typename...Remaining_Values> 00067 explicit simple_event(First_Value&& value, Remaining_Values&& ...values) 00068 : v_(std::forward<First_Value>(value), std::forward<Remaining_Values>(values)...) 00069 { 00070 } 00071 00072 simple_event(simple_event const& op) = default; 00073 simple_event& operator=(simple_event const& op) = default; 00074 00076 static void const* type() { 00077 static const char* f = 0; 00078 return &f; 00079 } 00080 00082 virtual void const* derived_type() const { 00083 return type(); 00084 } 00085 00090 tuple_type v_; 00091 }; 00092 00095 template<typename T> 00096 bool same_type(event_base const& ev) 00097 { 00098 return ev.derived_type() == T::type(); 00099 } 00100 00101 typedef unsigned long long timer_id; 00102 00104 struct timer_event_type{}; 00105 00110 typedef simple_event<timer_event_type, timer_id> timer_event; 00111 00114 extern template class FZ_PUBLIC_SYMBOL simple_event<timer_event_type, timer_id>; 00115 00116 } 00117 00118 #endif