Moving delegate to poly.
This commit is contained in:
parent
a0eebf8898
commit
c1df273600
|
@ -15,7 +15,7 @@
|
|||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <alloy/delegate.h>
|
||||
#include <poly/delegate.h>
|
||||
|
||||
namespace alloy {
|
||||
namespace runtime {
|
||||
|
@ -104,7 +104,7 @@ class Debugger {
|
|||
void OnBreakpointHit(ThreadState* thread_state, Breakpoint* breakpoint);
|
||||
|
||||
public:
|
||||
Delegate<BreakpointHitEvent> breakpoint_hit;
|
||||
poly::Delegate<BreakpointHitEvent> breakpoint_hit;
|
||||
|
||||
private:
|
||||
Runtime* runtime_;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
'alloy.h',
|
||||
'arena.cc',
|
||||
'arena.h',
|
||||
'delegate.h',
|
||||
'memory.cc',
|
||||
'memory.h',
|
||||
'reset_scope.h',
|
||||
|
|
|
@ -7,24 +7,21 @@
|
|||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_DELEGATE_H_
|
||||
#define ALLOY_DELEGATE_H_
|
||||
#ifndef POLY_DELEGATE_H_
|
||||
#define POLY_DELEGATE_H_
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace alloy {
|
||||
namespace poly {
|
||||
|
||||
// TODO(benvanik): go lockfree, and don't hold the lock while emitting.
|
||||
|
||||
template <typename T>
|
||||
class Delegate;
|
||||
|
||||
template <typename T>
|
||||
template <typename... Args>
|
||||
class Delegate {
|
||||
public:
|
||||
typedef std::function<void(T&)> Listener;
|
||||
typedef std::function<void(Args&...)> Listener;
|
||||
|
||||
void AddListener(Listener const& listener) {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
|
@ -36,10 +33,10 @@ class Delegate {
|
|||
listeners_.clear();
|
||||
}
|
||||
|
||||
void operator()(T& e) {
|
||||
void operator()(Args&... args) {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
for (auto& listener : listeners_) {
|
||||
listener(e);
|
||||
listener(args...);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,33 +45,6 @@ class Delegate {
|
|||
std::vector<Listener> listeners_;
|
||||
};
|
||||
|
||||
template <>
|
||||
class Delegate<void> {
|
||||
public:
|
||||
typedef std::function<void()> Listener;
|
||||
} // namespace poly
|
||||
|
||||
void AddListener(Listener const& listener) {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
listeners_.push_back(listener);
|
||||
}
|
||||
|
||||
void RemoveAllListeners() {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
listeners_.clear();
|
||||
}
|
||||
|
||||
void operator()() {
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
for (auto& listener : listeners_) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex lock_;
|
||||
std::vector<Listener> listeners_;
|
||||
};
|
||||
|
||||
} // namespace alloy
|
||||
|
||||
#endif // ALLOY_DELEGATE_H_
|
||||
#endif // POLY_DELEGATE_H_
|
|
@ -5,6 +5,7 @@
|
|||
'atomic.h',
|
||||
'byte_order.h',
|
||||
'debugging.h',
|
||||
'delegate.h',
|
||||
'config.h',
|
||||
'cxx_compat.h',
|
||||
'logging.cc',
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
#include <alloy/delegate.h>
|
||||
#include <poly/delegate.h>
|
||||
#include <xdb/module.h>
|
||||
#include <xdb/protocol.h>
|
||||
#include <xdb/thread.h>
|
||||
|
@ -27,15 +27,15 @@ class Cursor {
|
|||
|
||||
// TODO(benvanik): breakpoints/events
|
||||
|
||||
alloy::Delegate<void> end_of_stream;
|
||||
poly::Delegate<void> end_of_stream;
|
||||
|
||||
std::vector<Module*> modules();
|
||||
std::vector<Thread*> threads();
|
||||
|
||||
alloy::Delegate<Module*> module_loaded;
|
||||
alloy::Delegate<Module*> module_unloaded;
|
||||
alloy::Delegate<Thread*> thread_created;
|
||||
alloy::Delegate<Thread*> thread_exited;
|
||||
poly::Delegate<Module*> module_loaded;
|
||||
poly::Delegate<Module*> module_unloaded;
|
||||
poly::Delegate<Thread*> thread_created;
|
||||
poly::Delegate<Thread*> thread_exited;
|
||||
|
||||
// TODO(benvanik): memory access
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <alloy/delegate.h>
|
||||
#include <poly/delegate.h>
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/ui/ui_event.h>
|
||||
|
||||
|
@ -39,20 +39,20 @@ class Window {
|
|||
void Close();
|
||||
|
||||
public:
|
||||
alloy::Delegate<UIEvent> shown;
|
||||
alloy::Delegate<UIEvent> hidden;
|
||||
alloy::Delegate<UIEvent> resizing;
|
||||
alloy::Delegate<UIEvent> resized;
|
||||
alloy::Delegate<UIEvent> closing;
|
||||
alloy::Delegate<UIEvent> closed;
|
||||
poly::Delegate<UIEvent> shown;
|
||||
poly::Delegate<UIEvent> hidden;
|
||||
poly::Delegate<UIEvent> resizing;
|
||||
poly::Delegate<UIEvent> resized;
|
||||
poly::Delegate<UIEvent> closing;
|
||||
poly::Delegate<UIEvent> closed;
|
||||
|
||||
alloy::Delegate<KeyEvent> key_down;
|
||||
alloy::Delegate<KeyEvent> key_up;
|
||||
poly::Delegate<KeyEvent> key_down;
|
||||
poly::Delegate<KeyEvent> key_up;
|
||||
|
||||
alloy::Delegate<MouseEvent> mouse_down;
|
||||
alloy::Delegate<MouseEvent> mouse_move;
|
||||
alloy::Delegate<MouseEvent> mouse_up;
|
||||
alloy::Delegate<MouseEvent> mouse_wheel;
|
||||
poly::Delegate<MouseEvent> mouse_down;
|
||||
poly::Delegate<MouseEvent> mouse_move;
|
||||
poly::Delegate<MouseEvent> mouse_up;
|
||||
poly::Delegate<MouseEvent> mouse_wheel;
|
||||
|
||||
protected:
|
||||
void OnShow();
|
||||
|
|
Loading…
Reference in New Issue