summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaBind/signal
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Lua/LuaBind/signal')
-rw-r--r--Runtime/Lua/LuaBind/signal/bind.h510
-rw-r--r--Runtime/Lua/LuaBind/signal/remove_from_container.h32
-rw-r--r--Runtime/Lua/LuaBind/signal/signal.h451
-rw-r--r--Runtime/Lua/LuaBind/signal/slot.h203
4 files changed, 1196 insertions, 0 deletions
diff --git a/Runtime/Lua/LuaBind/signal/bind.h b/Runtime/Lua/LuaBind/signal/bind.h
new file mode 100644
index 0000000..e29896b
--- /dev/null
+++ b/Runtime/Lua/LuaBind/signal/bind.h
@@ -0,0 +1,510 @@
+// Aseprite Base Library
+// Copyright (c) 2001-2013 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef BASE_BIND_H_INCLUDED
+#define BASE_BIND_H_INCLUDED
+#pragma once
+
+// BindAdapter0_fun
+template<typename R, typename F>
+class BindAdapter0_fun
+{
+ F f;
+public:
+ BindAdapter0_fun(const F& f) : f(f) { }
+
+ R operator()() { return f(); }
+
+ template<typename A1>
+ R operator()(const A1& a1) { return f(); }
+
+ template<typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return f(); }
+
+ template<typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(); }
+};
+
+template<typename F>
+class BindAdapter0_fun<void, F>
+{
+ F f;
+public:
+ BindAdapter0_fun(const F& f) : f(f) { }
+
+ void operator()() { f(); }
+
+ template<typename A1>
+ void operator()(const A1& a1) { f(); }
+
+ template<typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { f(); }
+
+ template<typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { f(); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(); }
+};
+
+template<typename R, typename F>
+BindAdapter0_fun<R, F>
+Bind(const F& f)
+{
+ return BindAdapter0_fun<R, F>(f);
+}
+
+// BindAdapter0_mem
+template<typename R, typename T>
+class BindAdapter0_mem
+{
+ R (T::*m)();
+ T* t;
+public:
+ template<typename T2>
+ BindAdapter0_mem(R (T::*m)(), T2* t) : m(m), t(t) { }
+
+ R operator()() { return (t->*m)(); }
+
+ template <typename A1>
+ R operator()(const A1& a1) { return (t->*m)(); }
+
+ template <typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return (t->*m)(); }
+
+ template <typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(); }
+
+ template <typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(); }
+};
+
+template<typename T>
+class BindAdapter0_mem<void, T>
+{
+ void (T::*m)();
+ T* t;
+public:
+ template<typename T2>
+ BindAdapter0_mem(void (T::*m)(), T2* t) : m(m), t(t) { }
+
+ void operator()() { (t->*m)(); }
+
+ template <typename A1>
+ void operator()(const A1& a1) { (t->*m)(); }
+
+ template <typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { (t->*m)(); }
+
+ template <typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(); }
+
+ template <typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(); }
+};
+
+template<typename R, typename T, typename T2>
+BindAdapter0_mem<R, T>
+Bind(R (T::*m)(), T2* t)
+{
+ return BindAdapter0_mem<R, T>(m, t);
+}
+
+// BindAdapter1_fun
+template<typename R, typename F,
+ typename X1>
+class BindAdapter1_fun
+{
+ F f;
+ X1 x1;
+public:
+ BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { }
+
+ R operator()() { return f(x1); }
+
+ template<typename A1>
+ R operator()(const A1& a1) { return f(x1); }
+
+ template<typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return f(x1); }
+
+ template<typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1); }
+};
+
+template<typename F,
+ typename X1>
+class BindAdapter1_fun<void, F, X1>
+{
+ F f;
+ X1 x1;
+public:
+ BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { }
+
+ void operator()() { f(x1); }
+
+ template<typename A1>
+ void operator()(const A1& a1) { f(x1); }
+
+ template<typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { f(x1); }
+
+ template<typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1); }
+};
+
+template<typename R, typename F,
+ typename X1>
+BindAdapter1_fun<R, F, X1>
+Bind(const F& f, X1 x1)
+{
+ return BindAdapter1_fun<R, F, X1>(f, x1);
+}
+
+// BindAdapter1_mem
+template<typename R, typename T,
+ typename B1,
+ typename X1>
+class BindAdapter1_mem
+{
+ R (T::*m)(B1);
+ T* t;
+ X1 x1;
+public:
+ template<typename T2>
+ BindAdapter1_mem(R (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { }
+
+ R operator()() { return (t->*m)(x1); }
+
+ template <typename A1>
+ R operator()(const A1& a1) { return (t->*m)(x1); }
+
+ template <typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1); }
+
+ template <typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1); }
+
+ template <typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1); }
+};
+
+template<typename T,
+ typename B1,
+ typename X1>
+class BindAdapter1_mem<void, T, B1, X1>
+{
+ void (T::*m)(B1);
+ T* t;
+ X1 x1;
+public:
+ template<typename T2>
+ BindAdapter1_mem(void (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { }
+
+ void operator()() { (t->*m)(x1); }
+
+ template <typename A1>
+ void operator()(const A1& a1) { (t->*m)(x1); }
+
+ template <typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { (t->*m)(x1); }
+
+ template <typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1); }
+
+ template <typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1); }
+};
+
+template<typename R, typename T, typename T2,
+ typename B1, typename X1>
+BindAdapter1_mem<R, T, B1, X1>
+Bind(R (T::*m)(B1), T2* t, X1 x1)
+{
+ return BindAdapter1_mem<R, T, B1, X1>(m, t, x1);
+}
+
+// BindAdapter2_fun
+template<typename R, typename F,
+ typename X1, typename X2>
+class BindAdapter2_fun
+{
+ F f;
+ X1 x1;
+ X2 x2;
+public:
+ BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { }
+
+ R operator()() { return f(x1, x2); }
+
+ template<typename A1>
+ R operator()(const A1& a1) { return f(x1, x2); }
+
+ template<typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return f(x1, x2); }
+
+ template<typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2); }
+};
+
+template<typename F,
+ typename X1, typename X2>
+class BindAdapter2_fun<void, F, X1, X2>
+{
+ F f;
+ X1 x1;
+ X2 x2;
+public:
+ BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { }
+
+ void operator()() { f(x1, x2); }
+
+ template<typename A1>
+ void operator()(const A1& a1) { f(x1, x2); }
+
+ template<typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { f(x1, x2); }
+
+ template<typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2); }
+};
+
+template<typename R, typename F,
+ typename X1, typename X2>
+BindAdapter2_fun<R, F, X1, X2>
+Bind(const F& f, X1 x1, X2 x2)
+{
+ return BindAdapter2_fun<R, F, X1, X2>(f, x1, x2);
+}
+
+// BindAdapter2_mem
+template<typename R, typename T,
+ typename B1, typename B2,
+ typename X1, typename X2>
+class BindAdapter2_mem
+{
+ R (T::*m)(B1, B2);
+ T* t;
+ X1 x1;
+ X2 x2;
+public:
+ template<typename T2>
+ BindAdapter2_mem(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { }
+
+ R operator()() { return (t->*m)(x1, x2); }
+
+ template<typename A1>
+ R operator()(const A1& a1) { return (t->*m)(x1, x2); }
+
+ template<typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2); }
+
+ template<typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2); }
+};
+
+template<typename T,
+ typename B1, typename B2,
+ typename X1, typename X2>
+class BindAdapter2_mem<void, T, B1, B2, X1, X2>
+{
+ void (T::*m)(B1, B2);
+ T* t;
+ X1 x1;
+ X2 x2;
+public:
+ template<typename T2>
+ BindAdapter2_mem(void (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { }
+
+ void operator()() { (t->*m)(x1, x2); }
+
+ template<typename A1>
+ void operator()(const A1& a1) { (t->*m)(x1, x2); }
+
+ template<typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2); }
+
+ template<typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2); }
+};
+
+template<typename R, typename T, typename T2, typename B1, typename B2, typename X1, typename X2>
+BindAdapter2_mem<R, T, B1, B2, X1, X2>
+Bind(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2)
+{
+ return BindAdapter2_mem<R, T, B1, B2, X1, X2>(m, t, x1, x2);
+}
+
+// BindAdapter3_fun
+template<typename R, typename F,
+ typename X1, typename X2, typename X3>
+class BindAdapter3_fun
+{
+ F f;
+ X1 x1;
+ X2 x2;
+ X3 x3;
+public:
+ BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { }
+
+ R operator()() { return f(x1, x2, x3); }
+
+ template<typename A1>
+ R operator()(const A1& a1) { return f(x1, x2, x3); }
+
+ template<typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return f(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2, x3); }
+};
+
+template<typename F,
+ typename X1, typename X2, typename X3>
+class BindAdapter3_fun<void, F, X1, X2, X3>
+{
+ F f;
+ X1 x1;
+ X2 x2;
+ X3 x3;
+public:
+ BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { }
+
+ void operator()() { f(x1, x2, x3); }
+
+ template<typename A1>
+ void operator()(const A1& a1) { f(x1, x2, x3); }
+
+ template<typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { f(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2, x3); }
+};
+
+template<typename R, typename F,
+ typename X1, typename X2, typename X3>
+BindAdapter3_fun<R, F, X1, X2, X3>
+Bind(const F& f, X1 x1, X2 x2, X3 x3)
+{
+ return BindAdapter3_fun<R, F, X1, X2, X3>(f, x1, x2, x3);
+}
+
+// BindAdapter3_mem
+template<typename R, typename T,
+ typename B1, typename B2, typename B3,
+ typename X1, typename X2, typename X3>
+class BindAdapter3_mem
+{
+ R (T::*m)(B1, B2, B3);
+ T* t;
+ X1 x1;
+ X2 x2;
+ X3 x3;
+public:
+ template<typename T2>
+ BindAdapter3_mem(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2, X3 x3) : m(m), t(t), x1(x1), x2(x2), x3(x3) { }
+
+ R operator()() { return (t->*m)(x1, x2, x3); }
+
+ template<typename A1>
+ R operator()(const A1& a1) { return (t->*m)(x1, x2, x3); }
+
+ template<typename A1, typename A2>
+ R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3>
+ R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2, x3); }
+};
+
+template<typename T,
+ typename B1, typename B2, typename B3,
+ typename X1, typename X2, typename X3>
+class BindAdapter3_mem<void, T, B1, B2, B3, X1, X2, X3>
+{
+ void (T::*m)(B1, B2, B3);
+ T* t;
+ X1 x1;
+ X2 x2;
+ X3 x3;
+public:
+ template<typename T2>
+ BindAdapter3_mem(void (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { }
+
+ void operator()() { (t->*m)(x1, x2, x3); }
+
+ template<typename A1>
+ void operator()(const A1& a1) { (t->*m)(x1, x2, x3); }
+
+ template<typename A1, typename A2>
+ void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3>
+ void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2, x3); }
+
+ template<typename A1, typename A2, typename A3, typename A4>
+ void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2, x3); }
+};
+
+template<typename R, typename T, typename T2,
+ typename B1, typename B2, typename B3,
+ typename X1, typename X2, typename X3>
+BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3>
+Bind(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2)
+{
+ return BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3>(m, t, x1, x2);
+}
+
+// Helper class to holds references as pointers (to avoid copying the
+// original object).
+template<class T>
+class RefWrapper
+{
+ T* ptr;
+public:
+ RefWrapper(T& ref) : ptr(&ref) { }
+ operator T&() const { return *ptr; }
+};
+
+// Creates RefWrappers, useful to wrap arguments that have to be
+// passed as a reference when you use Bind.
+template<class T>
+RefWrapper<T> Ref(T& ref)
+{
+ return RefWrapper<T>(ref);
+}
+
+#endif
diff --git a/Runtime/Lua/LuaBind/signal/remove_from_container.h b/Runtime/Lua/LuaBind/signal/remove_from_container.h
new file mode 100644
index 0000000..9fdc442
--- /dev/null
+++ b/Runtime/Lua/LuaBind/signal/remove_from_container.h
@@ -0,0 +1,32 @@
+// Aseprite Base Library
+// Copyright (c) 2001-2013 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
+#define BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
+#pragma once
+
+namespace base {
+
+// Removes all ocurrences of the specified element from the STL container.
+template<typename ContainerType>
+void remove_from_container(ContainerType& container,
+ typename ContainerType::const_reference element)
+{
+ for (typename ContainerType::iterator
+ it = container.begin(),
+ end = container.end(); it != end; ) {
+ if (*it == element) {
+ it = container.erase(it);
+ end = container.end();
+ }
+ else
+ ++it;
+ }
+}
+
+}
+
+#endif
diff --git a/Runtime/Lua/LuaBind/signal/signal.h b/Runtime/Lua/LuaBind/signal/signal.h
new file mode 100644
index 0000000..97882c6
--- /dev/null
+++ b/Runtime/Lua/LuaBind/signal/signal.h
@@ -0,0 +1,451 @@
+// Aseprite Base Library
+// Copyright (c) 2001-2013 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef BASE_SIGNAL_H_INCLUDED
+#define BASE_SIGNAL_H_INCLUDED
+#pragma once
+
+//#include "base/slot.h"
+//#include "base/remove_from_container.h"
+
+#include "./slot.h"
+#include "./remove_from_container.h"
+
+#include <vector>
+
+// Signal0_base<R> - Base class to delegate responsibility to
+// functions of zero arguments.
+template<typename R>
+class Signal0_base
+{
+public:
+ typedef R ReturnType;
+ typedef Slot0<R> SlotType;
+ typedef std::vector<SlotType*> SlotList;
+
+protected:
+ SlotList m_slots;
+
+public:
+ Signal0_base() { }
+ Signal0_base(const Signal0_base<R>& s)
+ {
+ copy(s);
+ }
+ ~Signal0_base()
+ {
+ disconnectAll();
+ }
+
+ SlotType* addSlot(SlotType* slot)
+ {
+ m_slots.push_back(slot);
+ return slot;
+ }
+
+ template<typename F>
+ SlotType* connect(const F& f)
+ {
+ return addSlot(new Slot0_fun<R, F>(f));
+ }
+
+ template<class T>
+ SlotType* connect(R (T::*m)(), T* t)
+ {
+ return addSlot(new Slot0_mem<R, T>(m, t));
+ }
+
+ const SlotList& getSlots() const
+ {
+ return m_slots;
+ }
+
+ void disconnect(SlotType* slot)
+ {
+ base::remove_from_container(m_slots, slot);
+ }
+
+ void disconnectAll()
+ {
+ typename SlotList::iterator end = m_slots.end();
+ for (typename SlotList::iterator
+ it = m_slots.begin(); it != end; ++it)
+ delete *it;
+ m_slots.clear();
+ }
+
+ bool empty() const
+ {
+ return m_slots.empty();
+ }
+
+ Signal0_base& operator=(const Signal0_base<R>& s) {
+ copy(s);
+ return *this;
+ }
+
+private:
+
+ void copy(const Signal0_base<R>& s)
+ {
+ typename SlotList::const_iterator end = s.m_slots.end();
+ for (typename SlotList::const_iterator
+ it = s.m_slots.begin(); it != end; ++it) {
+ m_slots.push_back((*it)->clone());
+ }
+ }
+
+};
+
+// Signal0<R>
+template<typename R>
+class Signal0 : public Signal0_base<R>
+{
+public:
+ Signal0() { }
+
+ Signal0(const Signal0<R>& s)
+ : Signal0_base<R>(s) { }
+
+ R operator()(R default_result = R())
+ {
+ R result(default_result);
+ typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
+ for (typename Signal0_base<R>::SlotList::iterator
+ it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
+ typename Signal0_base<R>::SlotType* slot = *it;
+ result = (*slot)();
+ }
+ return result;
+ }
+
+ template<typename Merger>
+ R operator()(R default_result, const Merger& m)
+ {
+ R result(default_result);
+ Merger merger(m);
+ typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
+ for (typename Signal0_base<R>::SlotList::iterator
+ it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
+ typename Signal0_base<R>::SlotType* slot = *it;
+ result = merger(result, (*slot)());
+ }
+ return result;
+ }
+
+};
+
+// Signal0<void>
+template<>
+class Signal0<void> : public Signal0_base<void>
+{
+public:
+ Signal0() { }
+
+ Signal0(const Signal0<void>& s)
+ : Signal0_base<void>(s) { }
+
+ void operator()()
+ {
+ SlotList::iterator end = m_slots.end();
+ for (SlotList::iterator
+ it = m_slots.begin(); it != end; ++it) {
+ SlotType* slot = *it;
+ (*slot)();
+ }
+ }
+
+};
+
+// Signal1_base<R, A1> - Base class to delegate responsibility to
+// functions of one argument.
+template<typename R, typename A1>
+class Signal1_base
+{
+public:
+ typedef R ReturnType;
+ typedef Slot1<R, A1> SlotType;
+ typedef std::vector<SlotType*> SlotList;
+
+protected:
+ SlotList m_slots;
+
+public:
+ Signal1_base() { }
+ Signal1_base(const Signal1_base<R, A1>& s)
+ {
+ copy(s);
+ }
+ ~Signal1_base()
+ {
+ disconnectAll();
+ }
+
+ SlotType* addSlot(SlotType* slot)
+ {
+ m_slots.push_back(slot);
+ return slot;
+ }
+
+ template<typename F>
+ SlotType* connect(const F& f)
+ {
+ return addSlot(new Slot1_fun<R, F, A1>(f));
+ }
+
+ template<class T>
+ SlotType* connect(R (T::*m)(A1), T* t)
+ {
+ return addSlot(new Slot1_mem<R, T, A1>(m, t));
+ }
+
+ const SlotList& getSlots() const
+ {
+ return m_slots;
+ }
+
+ void disconnect(SlotType* slot)
+ {
+ base::remove_from_container(m_slots, slot);
+ }
+
+ void disconnectAll()
+ {
+ typename SlotList::iterator end = m_slots.end();
+ for (typename SlotList::iterator
+ it = m_slots.begin(); it != end; ++it)
+ delete *it;
+ m_slots.clear();
+ }
+
+ bool empty() const
+ {
+ return m_slots.empty();
+ }
+
+ Signal1_base& operator=(const Signal1_base<R, A1>& s) {
+ copy(s);
+ return *this;
+ }
+
+private:
+
+ void copy(const Signal1_base<R, A1>& s)
+ {
+ typename SlotList::const_iterator end = s.m_slots.end();
+ for (typename SlotList::const_iterator
+ it = s.m_slots.begin(); it != end; ++it) {
+ m_slots.push_back((*it)->clone());
+ }
+ }
+
+};
+
+// Signal1<R, A1>
+template<typename R, typename A1>
+class Signal1 : public Signal1_base<R, A1>
+{
+public:
+ Signal1() { }
+
+ Signal1(const Signal1<R, A1>& s)
+ : Signal1_base<R, A1>(s) { }
+
+ R operator()(A1 a1, R default_result = R())
+ {
+ R result(default_result);
+ typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
+ for (typename Signal1_base<R, A1>::SlotList::iterator
+ it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
+ typename Signal1_base<R, A1>::SlotType* slot = *it;
+ result = (*slot)(a1);
+ }
+ return result;
+ }
+
+ template<typename Merger>
+ R operator()(A1 a1, R default_result, const Merger& m)
+ {
+ R result(default_result);
+ Merger merger(m);
+ typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
+ for (typename Signal1_base<R, A1>::SlotList::iterator
+ it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
+ typename Signal1_base<R, A1>::SlotType* slot = *it;
+ result = merger(result, (*slot)(a1));
+ }
+ return result;
+ }
+
+};
+
+// Signal1<void, A1>
+template<typename A1>
+class Signal1<void, A1> : public Signal1_base<void, A1>
+{
+public:
+ Signal1() { }
+
+ Signal1(const Signal1<void, A1>& s)
+ : Signal1_base<void, A1>(s) { }
+
+ void operator()(A1 a1)
+ {
+ typename Signal1_base<void, A1>::SlotList::iterator end = Signal1_base<void, A1>::m_slots.end();
+ for (typename Signal1_base<void, A1>::SlotList::iterator
+ it = Signal1_base<void, A1>::m_slots.begin(); it != end; ++it) {
+ typename Signal1_base<void, A1>::SlotType* slot = *it;
+ (*slot)(a1);
+ }
+ }
+
+};
+
+// Signal2_base<R, A1, A2> - Base class to delegate responsibility to
+// functions of two arguments.
+template<typename R, typename A1, typename A2>
+class Signal2_base
+{
+public:
+ typedef R ReturnType;
+ typedef Slot2<R, A1, A2> SlotType;
+ typedef std::vector<SlotType*> SlotList;
+
+protected:
+ SlotList m_slots;
+
+public:
+ Signal2_base() { }
+ Signal2_base(const Signal2_base<R, A1, A2>& s)
+ {
+ copy(s);
+ }
+ ~Signal2_base()
+ {
+ disconnectAll();
+ }
+
+ SlotType* addSlot(SlotType* slot)
+ {
+ m_slots.push_back(slot);
+ return slot;
+ }
+
+ template<typename F>
+ SlotType* connect(const F& f)
+ {
+ return addSlot(new Slot2_fun<R, F, A1, A2>(f));
+ }
+
+ template<class T>
+ SlotType* connect(R (T::*m)(A1, A2), T* t)
+ {
+ return addSlot(new Slot2_mem<R, T, A1, A2>(m, t));
+ }
+
+ const SlotList& getSlots() const
+ {
+ return m_slots;
+ }
+
+ void disconnect(SlotType* slot)
+ {
+ base::remove_from_container(m_slots, slot);
+ }
+
+ void disconnectAll()
+ {
+ typename SlotList::iterator end = m_slots.end();
+ for (typename SlotList::iterator
+ it = m_slots.begin(); it != end; ++it)
+ delete *it;
+ m_slots.clear();
+ }
+
+ bool empty() const
+ {
+ return m_slots.empty();
+ }
+
+ Signal2_base& operator=(const Signal2_base<R, A1, A2>& s) {
+ copy(s);
+ return *this;
+ }
+
+private:
+
+ void copy(const Signal2_base<R, A1, A2>& s)
+ {
+ typename SlotList::const_iterator end = s.m_slots.end();
+ for (typename SlotList::const_iterator
+ it = s.m_slots.begin(); it != end; ++it) {
+ m_slots.push_back((*it)->clone());
+ }
+ }
+
+};
+
+// Signal2<R, A1>
+template<typename R, typename A1, typename A2>
+class Signal2 : public Signal2_base<R, A1, A2>
+{
+public:
+ Signal2() { }
+
+ Signal2(const Signal2<R, A1, A2>& s)
+ : Signal2_base<R, A1, A2>(s) { }
+
+ R operator()(A1 a1, A2 a2, R default_result = R())
+ {
+ R result(default_result);
+ typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
+ for (typename Signal2_base<R, A1, A2>::SlotList::iterator
+ it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
+ typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
+ result = (*slot)(a1, a2);
+ }
+ return result;
+ }
+
+ template<typename Merger>
+ R operator()(A1 a1, A2 a2, R default_result, const Merger& m)
+ {
+ R result(default_result);
+ Merger merger(m);
+ typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
+ for (typename Signal2_base<R, A1, A2>::SlotList::iterator
+ it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
+ typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
+ result = merger(result, (*slot)(a1, a2));
+ }
+ return result;
+ }
+
+};
+
+// Signal2<void, A1>
+template<typename A1, typename A2>
+class Signal2<void, A1, A2> : public Signal2_base<void, A1, A2>
+{
+public:
+ Signal2() { }
+
+ Signal2(const Signal2<void, A1, A2>& s)
+ : Signal2_base<void, A1, A2>(s) { }
+
+ void operator()(A1 a1, A2 a2)
+ {
+ typename Signal2_base<void, A1, A2>::SlotList::iterator end = Signal2_base<void, A1, A2>::m_slots.end();
+ for (typename Signal2_base<void, A1, A2>::SlotList::iterator
+ it = Signal2_base<void, A1, A2>::m_slots.begin(); it != end; ++it) {
+ typename Signal2_base<void, A1, A2>::SlotType* slot = *it;
+ (*slot)(a1, a2);
+ }
+ }
+
+};
+
+#endif
diff --git a/Runtime/Lua/LuaBind/signal/slot.h b/Runtime/Lua/LuaBind/signal/slot.h
new file mode 100644
index 0000000..226d382
--- /dev/null
+++ b/Runtime/Lua/LuaBind/signal/slot.h
@@ -0,0 +1,203 @@
+// Aseprite Base Library
+// Copyright (c) 2001-2013 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef BASE_SLOT_H_INCLUDED
+#define BASE_SLOT_H_INCLUDED
+#pragma once
+
+// Slot0 - Base class for delegates of zero arguments.
+template<typename R>
+class Slot0
+{
+public:
+ Slot0() { }
+ Slot0(const Slot0& s) { (void)s; }
+ virtual ~Slot0() { }
+ virtual R operator()() = 0;
+ virtual Slot0* clone() const = 0;
+};
+
+// Slot0_fun - hold a F instance and use the function call operator
+template<typename R, typename F>
+class Slot0_fun : public Slot0<R>
+{
+ F f;
+public:
+ Slot0_fun(const F& f) : f(f) { }
+ Slot0_fun(const Slot0_fun& s) : Slot0<R>(s), f(s.f) { }
+ ~Slot0_fun() { }
+ R operator()() { return f(); }
+ Slot0_fun* clone() const { return new Slot0_fun(*this); }
+};
+
+template<typename F>
+class Slot0_fun<void, F> : public Slot0<void>
+{
+ F f;
+public:
+ Slot0_fun(const F& f) : f(f) { }
+ Slot0_fun(const Slot0_fun& s) : Slot0<void>(s), f(s.f) { }
+ ~Slot0_fun() { }
+ void operator()() { f(); }
+ Slot0_fun* clone() const { return new Slot0_fun(*this); }
+};
+
+// Slot0_mem - pointer to a member function of the T class
+template<typename R, class T>
+class Slot0_mem : public Slot0<R>
+{
+ R (T::*m)();
+ T* t;
+public:
+ Slot0_mem(R (T::*m)(), T* t) : m(m), t(t) { }
+ Slot0_mem(const Slot0_mem& s) : Slot0<R>(s), m(s.m), t(s.t) { }
+ ~Slot0_mem() { }
+ R operator()() { return (t->*m)(); }
+ Slot0_mem* clone() const { return new Slot0_mem(*this); }
+};
+
+template<class T>
+class Slot0_mem<void, T> : public Slot0<void>
+{
+ void (T::*m)();
+ T* t;
+public:
+ Slot0_mem(void (T::*m)(), T* t) : m(m), t(t) { }
+ Slot0_mem(const Slot0_mem& s) : Slot0<void>(s), m(s.m), t(s.t) { }
+ ~Slot0_mem() { }
+ void operator()() { (t->*m)(); }
+ Slot0_mem* clone() const { return new Slot0_mem(*this); }
+};
+
+// Slot1 - Base class for delegates of one argument.
+template<typename R, typename A1>
+class Slot1
+{
+public:
+ Slot1() { }
+ Slot1(const Slot1& s) { (void)s; }
+ virtual ~Slot1() { }
+ virtual R operator()(A1 a1) = 0;
+ virtual Slot1* clone() const = 0;
+};
+
+// Slot1_fun - hold a F instance and use the function call operator
+template<typename R, typename F, typename A1>
+class Slot1_fun : public Slot1<R, A1>
+{
+ F f;
+public:
+ Slot1_fun(const F& f) : f(f) { }
+ Slot1_fun(const Slot1_fun& s) : Slot1<R, A1>(s), f(s.f) { }
+ ~Slot1_fun() { }
+ R operator()(A1 a1) { return f(a1); }
+ Slot1_fun* clone() const { return new Slot1_fun(*this); }
+};
+
+template<typename F, typename A1>
+class Slot1_fun<void, F, A1> : public Slot1<void, A1>
+{
+ F f;
+public:
+ Slot1_fun(const F& f) : f(f) { }
+ Slot1_fun(const Slot1_fun& s) : Slot1<void, A1>(s), f(s.f) { }
+ ~Slot1_fun() { }
+ void operator()(A1 a1) { f(a1); }
+ Slot1_fun* clone() const { return new Slot1_fun(*this); }
+};
+
+// Slot1_mem - pointer to a member function of the T class
+template<typename R, class T, typename A1>
+class Slot1_mem : public Slot1<R, A1>
+{
+ R (T::*m)(A1);
+ T* t;
+public:
+ Slot1_mem(R (T::*m)(A1), T* t) : m(m), t(t) { }
+ Slot1_mem(const Slot1_mem& s) : Slot1<R, A1>(s), m(s.m), t(s.t) { }
+ ~Slot1_mem() { }
+ R operator()(A1 a1) { return (t->*m)(a1); }
+ Slot1_mem* clone() const { return new Slot1_mem(*this); }
+};
+
+template<class T, typename A1>
+class Slot1_mem<void, T, A1> : public Slot1<void, A1>
+{
+ void (T::*m)(A1);
+ T* t;
+public:
+ Slot1_mem(void (T::*m)(A1), T* t) : m(m), t(t) { }
+ Slot1_mem(const Slot1_mem& s) : Slot1<void, A1>(s), m(s.m), t(s.t) { }
+ ~Slot1_mem() { }
+ void operator()(A1 a1) { (t->*m)(a1); }
+ Slot1_mem* clone() const { return new Slot1_mem(*this); }
+};
+
+// Slot2 - Base class for delegates of two arguments.
+template<typename R, typename A1, typename A2>
+class Slot2
+{
+public:
+ Slot2() { }
+ Slot2(const Slot2& s) { (void)s; }
+ virtual ~Slot2() { }
+ virtual R operator()(A1 a1, A2 a2) = 0;
+ virtual Slot2* clone() const = 0;
+};
+
+// Slot2_fun - hold a F instance and use the function call operator
+template<typename R, typename F, typename A1, typename A2>
+class Slot2_fun : public Slot2<R, A1, A2>
+{
+ F f;
+public:
+ Slot2_fun(const F& f) : f(f) { }
+ Slot2_fun(const Slot2_fun& s) : Slot2<R, A1, A2>(s), f(s.f) { }
+ ~Slot2_fun() { }
+ R operator()(A1 a1, A2 a2) { return f(a1, a2); }
+ Slot2_fun* clone() const { return new Slot2_fun(*this); }
+};
+
+template<typename F, typename A1, typename A2>
+class Slot2_fun<void, F, A1, A2> : public Slot2<void, A1, A2>
+{
+ F f;
+public:
+ Slot2_fun(const F& f) : f(f) { }
+ Slot2_fun(const Slot2_fun& s) : Slot2<void, A1, A2>(s), f(s.f) { }
+ ~Slot2_fun() { }
+ void operator()(A1 a1, A2 a2) { f(a1, a2); }
+ Slot2_fun* clone() const { return new Slot2_fun(*this); }
+};
+
+// Slot2_mem - pointer to a member function of the T class
+template<typename R, class T, typename A1, typename A2>
+class Slot2_mem : public Slot2<R, A1, A2>
+{
+ R (T::*m)(A1, A2);
+ T* t;
+public:
+ Slot2_mem(R (T::*m)(A1, A2), T* t) : m(m), t(t) { }
+ Slot2_mem(const Slot2_mem& s) : Slot2<R, A1, A2>(s), m(s.m), t(s.t) { }
+ ~Slot2_mem() { }
+ R operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
+ Slot2_mem* clone() const { return new Slot2_mem(*this); }
+};
+
+template<class T, typename A1, typename A2>
+class Slot2_mem<void, T, A1, A2> : public Slot2<void, A1, A2>
+{
+ void (T::*m)(A1, A2);
+ T* t;
+public:
+ Slot2_mem(void (T::*m)(A1, A2), T* t) : m(m), t(t) { }
+ Slot2_mem(const Slot2_mem& s) : Slot2<void, A1, A2>(s), m(s.m), t(s.t) { }
+ ~Slot2_mem() { }
+ void operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
+ Slot2_mem* clone() const { return new Slot2_mem(*this); }
+};
+
+#endif