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