diff --git a/src/alloy/runtime/debugger.h b/src/alloy/runtime/debugger.h index 1ab802f40..6100ae7e1 100644 --- a/src/alloy/runtime/debugger.h +++ b/src/alloy/runtime/debugger.h @@ -15,7 +15,7 @@ #include #include -#include +#include namespace alloy { namespace runtime { @@ -104,7 +104,7 @@ class Debugger { void OnBreakpointHit(ThreadState* thread_state, Breakpoint* breakpoint); public: - Delegate breakpoint_hit; + poly::Delegate breakpoint_hit; private: Runtime* runtime_; diff --git a/src/alloy/sources.gypi b/src/alloy/sources.gypi index 44a87a7d2..18b7c409f 100644 --- a/src/alloy/sources.gypi +++ b/src/alloy/sources.gypi @@ -6,7 +6,6 @@ 'alloy.h', 'arena.cc', 'arena.h', - 'delegate.h', 'memory.cc', 'memory.h', 'reset_scope.h', diff --git a/src/alloy/delegate.h b/src/poly/delegate.h similarity index 56% rename from src/alloy/delegate.h rename to src/poly/delegate.h index 137773ab6..3c351a3d9 100644 --- a/src/alloy/delegate.h +++ b/src/poly/delegate.h @@ -7,24 +7,21 @@ ****************************************************************************** */ -#ifndef ALLOY_DELEGATE_H_ -#define ALLOY_DELEGATE_H_ +#ifndef POLY_DELEGATE_H_ +#define POLY_DELEGATE_H_ #include #include #include -namespace alloy { +namespace poly { // TODO(benvanik): go lockfree, and don't hold the lock while emitting. -template -class Delegate; - -template +template class Delegate { public: - typedef std::function Listener; + typedef std::function Listener; void AddListener(Listener const& listener) { std::lock_guard guard(lock_); @@ -36,10 +33,10 @@ class Delegate { listeners_.clear(); } - void operator()(T& e) { + void operator()(Args&... args) { std::lock_guard guard(lock_); for (auto& listener : listeners_) { - listener(e); + listener(args...); } } @@ -48,33 +45,6 @@ class Delegate { std::vector listeners_; }; -template <> -class Delegate { - public: - typedef std::function Listener; +} // namespace poly - void AddListener(Listener const& listener) { - std::lock_guard guard(lock_); - listeners_.push_back(listener); - } - - void RemoveAllListeners() { - std::lock_guard guard(lock_); - listeners_.clear(); - } - - void operator()() { - std::lock_guard guard(lock_); - for (auto& listener : listeners_) { - listener(); - } - } - - private: - std::mutex lock_; - std::vector listeners_; -}; - -} // namespace alloy - -#endif // ALLOY_DELEGATE_H_ +#endif // POLY_DELEGATE_H_ diff --git a/src/poly/sources.gypi b/src/poly/sources.gypi index a0fe765f3..ec514df44 100644 --- a/src/poly/sources.gypi +++ b/src/poly/sources.gypi @@ -5,6 +5,7 @@ 'atomic.h', 'byte_order.h', 'debugging.h', + 'delegate.h', 'config.h', 'cxx_compat.h', 'logging.cc', diff --git a/src/xdb/cursor.h b/src/xdb/cursor.h index 8c9fa2481..13a99afec 100644 --- a/src/xdb/cursor.h +++ b/src/xdb/cursor.h @@ -12,7 +12,7 @@ #include -#include +#include #include #include #include @@ -27,15 +27,15 @@ class Cursor { // TODO(benvanik): breakpoints/events - alloy::Delegate end_of_stream; + poly::Delegate end_of_stream; std::vector modules(); std::vector threads(); - alloy::Delegate module_loaded; - alloy::Delegate module_unloaded; - alloy::Delegate thread_created; - alloy::Delegate thread_exited; + poly::Delegate module_loaded; + poly::Delegate module_unloaded; + poly::Delegate thread_created; + poly::Delegate thread_exited; // TODO(benvanik): memory access diff --git a/src/xenia/ui/window.h b/src/xenia/ui/window.h index 1deafd712..9519f33d3 100644 --- a/src/xenia/ui/window.h +++ b/src/xenia/ui/window.h @@ -12,7 +12,7 @@ #include -#include +#include #include #include @@ -39,20 +39,20 @@ class Window { void Close(); public: - alloy::Delegate shown; - alloy::Delegate hidden; - alloy::Delegate resizing; - alloy::Delegate resized; - alloy::Delegate closing; - alloy::Delegate closed; + poly::Delegate shown; + poly::Delegate hidden; + poly::Delegate resizing; + poly::Delegate resized; + poly::Delegate closing; + poly::Delegate closed; - alloy::Delegate key_down; - alloy::Delegate key_up; + poly::Delegate key_down; + poly::Delegate key_up; - alloy::Delegate mouse_down; - alloy::Delegate mouse_move; - alloy::Delegate mouse_up; - alloy::Delegate mouse_wheel; + poly::Delegate mouse_down; + poly::Delegate mouse_move; + poly::Delegate mouse_up; + poly::Delegate mouse_wheel; protected: void OnShow();