neoGFX
Cross-platform C++ app/game engine
plugin_event.hpp
Go to the documentation of this file.
1 // plugin_event.hpp
2 /*
3  * Copyright (c) 2015, 2020 Leigh Johnston.
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * * Neither the name of Leigh Johnston nor the names of any
19  * other contributors to this software may be used to endorse or
20  * promote products derived from this software without specific prior
21  * written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #pragma once
37 
38 #include <neolib/neolib.hpp>
39 #include <neolib/task/event.hpp>
41 
42 namespace neolib
43 {
44  namespace plugin_events
45  {
48 
49  template <typename... Args>
50  class event : public i_event<Args...>, public neolib::event<Args...>
51  {
52  typedef neolib::event<Args...> base_type;
53  public:
54  using typename i_event<Args...>::abstract_callback;
55  public:
58  public:
59  using event_type::event_type;
60  public:
62  using event_type::operator();
64  public:
65  const neolib::i_event& raw_event() const override
66  {
67  return *this;
68  }
70  {
71  return *this;
72  }
73  public:
74  void pre_trigger() const override
75  {
77  }
78  public:
79  bool trigger(Args... aArguments) const override
80  {
81  return event_type::trigger(aArguments...);
82  }
83  bool sync_trigger(Args... aArguments) const override
84  {
85  return event_type::sync_trigger(aArguments...);
86  }
87  void async_trigger(Args... aArguments) const override
88  {
89  event_type::async_trigger(rvalue_cast<Args>(aArguments)...);
90  }
91  bool accepted() const override
92  {
93  return event_type::accepted();
94  }
95  void accept() const override
96  {
98  }
99  void ignore() const override
100  {
102  }
103  private:
104  event_handle do_subscribe(const abstract_callback& aCallback, const void* aUniqueId = nullptr) const override
105  {
106  auto callback = aCallback.clone();
107  return event_type::subscribe(
108  [callback](Args&& ... aArguments)
109  {
110  (*callback)(std::forward<Args>(aArguments)...);
111  },
112  aUniqueId);
113  }
114  void do_unsubscribe(event_handle aHandle) const override
115  {
116  return event_type::unsubscribe(aHandle);
117  }
118  void do_unsubscribe(const void* aUniqueId) const override
119  {
120  return event_type::unsubscribe(aUniqueId);
121  }
122  };
123  }
124 }
neolib::plugin_events::event::trigger
bool trigger(Args... aArguments) const override
Definition: plugin_event.hpp:79
neolib::event_handle
Definition: event.hpp:57
neolib::event::accepted
bool accepted() const override
Definition: event.hpp:596
neolib::async_event_queue
Definition: event.hpp:272
event.hpp
i_plugin_event.hpp
neolib::plugin_events::event::accepted
bool accepted() const override
Definition: plugin_event.hpp:91
neolib::plugin_events::event::event_type
base_type event_type
Definition: plugin_event.hpp:56
neolib::plugin_events::event::abstract_plugin_event_type
i_event< Args... > abstract_plugin_event_type
Definition: plugin_event.hpp:57
neolib::event::accept
void accept() const override
Definition: event.hpp:601
neolib::event_trigger_type
event_trigger_type
Definition: event.hpp:328
neolib::plugin_events::event::raw_event
const neolib::i_event & raw_event() const override
Definition: plugin_event.hpp:65
neolib::event::sync_trigger
bool sync_trigger(Args... aArguments) const
Definition: event.hpp:497
neolib::plugin_events::i_event
Definition: i_plugin_event.hpp:88
neolib
Definition: application.hpp:46
neolib::plugin_events::event::raw_event
neolib::i_event & raw_event() override
Definition: plugin_event.hpp:69
neolib::plugin_events::event::ignore
void ignore() const override
Definition: plugin_event.hpp:99
neolib::event::ignore
void ignore() const override
Definition: event.hpp:606
neolib::event::trigger
bool trigger(Args... aArguments) const
Definition: event.hpp:480
neolib::event::async_trigger
void async_trigger(Args... aArguments) const
Definition: event.hpp:562
neolib::event::pre_trigger
void pre_trigger() const override
Definition: event.hpp:462
neolib::event::subscribe
event_handle subscribe(const concrete_callable &aCallable, const void *aUniqueId=nullptr) const
Definition: event.hpp:629
neolib::event
Definition: event.hpp:338
neolib::plugin_events::event::sync_trigger
bool sync_trigger(Args... aArguments) const override
Definition: plugin_event.hpp:83
neolib::plugin_events::event::async_trigger
void async_trigger(Args... aArguments) const override
Definition: plugin_event.hpp:87
neolib::plugin_events::event::pre_trigger
void pre_trigger() const override
Definition: plugin_event.hpp:74
neolib::plugin_events::event
Definition: plugin_event.hpp:51
neolib::event::unsubscribe
void unsubscribe(event_handle aHandle) const
Definition: event.hpp:661
neolib::i_event
Definition: i_event.hpp:71
neolib.hpp
neolib::plugin_events::event::accept
void accept() const override
Definition: plugin_event.hpp:95