00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#ifndef USLOT_HPP
00029
#define USLOT_HPP
00030
00031
00032
00033
00034
#include "../ufo_global.hpp"
00035
#include "../utrait.hpp"
00036
#include "../usharedptr.hpp"
00037
00038
namespace ufo {
00039
00040
00041
typedef void (*ProxyPtr)(
void*);
00042
typedef void (*FuncPtr)(
void*);
00043
00044
struct UFO_EXPORT USlotNode {
00045 USlotNode() : m_died(false) {}
00046 USlotNode(FuncPtr proxy) : _proxy(proxy), m_died(false) {}
00047
virtual ~USlotNode() {}
00048
00049
00050
00051
00052
virtual void notify(
bool ) {
00053 m_died =
true;
00054 }
00055
virtual bool died() {
return m_died; }
00056
00057
virtual bool equals(
const USlotNode * )
const {
return false; }
00058
00059
bool connected() {
return _proxy != NULL; }
00060
00061
public:
00065 ProxyPtr _proxy;
00066
private:
00067
bool m_died;
00068 };
00069
00074 class UFO_EXPORT USlotBase {
00075
public:
00076 USlotBase() : _node(0) {}
00077 USlotBase(USlotNode * node) : _node(node) {}
00078 ~USlotBase() {}
00079
00081 USlotNode * node() {
return _node; }
00082
const USlotNode * node()
const {
return _node; }
00083
00084
bool operator ==(
const USlotBase & slot)
const {
00085
00086
return _node->equals(slot._node);
00087 }
00088
bool equals(
const USlotBase * slot)
const {
00089
return _node->equals(slot->_node);
00090 }
00091
00092
void assign(USlotNode * node) {
00093 _node = node;
00094 }
00095
00096
private:
00098 USharedPtr<USlotNode> _node;
00099 };
00100
00101
00102
00103
00104
00105
00106
class UFO_EXPORT USlot0 :
public USlotBase {
00107
public:
00108
00109
typedef void (*Callback)();
00110
typedef void (*Proxy)(
void*);
00111
00112
void operator()() {
00113
if (!node())
return;
00114
00115 ((Proxy)(node()->_proxy))(node());
00116 }
00117
00118 USlot0(USlotNode * node = NULL) : USlotBase(node) {}
00119 };
00120
00121
template <
typename P1>
00122
class UFO_EXPORT USlot1 :
public USlotBase {
00123
public:
00124
typedef void (*Proxy)(
typename UTrait<P1>::ref,
void*);
00125
00126
void operator ()(
typename UTrait<P1>::ref p1) {
00127
if (!node())
return;
00128
00129 ((Proxy)(node()->_proxy))(p1, node());
00130 }
00131
00132 USlot1(USlotNode * node = NULL) : USlotBase(node) {}
00133 };
00134
00135
template <
typename P1,
typename P2>
00136
class UFO_EXPORT USlot2 :
public USlotBase {
00137
public:
00138
typedef void (*Proxy)(
typename UTrait<P1>::ref,
typename UTrait<P2>::ref,
void*);
00139
00140
void operator ()(
typename UTrait<P1>::ref p1,
typename UTrait<P2>::ref p2) {
00141
if (!node())
return;
00142
00143 ((Proxy)(node()->_proxy))(p1, p2, node());
00144 }
00145
00146 USlot2(USlotNode * node = NULL) : USlotBase(node) {}
00147 };
00148
00149
00150
template <
typename P1,
typename P2,
typename P3>
00151
class UFO_EXPORT USlot3 :
public USlotBase {
00152
public:
00153
typedef void (*Proxy)(
typename UTrait<P1>::ref,
typename UTrait<P2>::ref,
00154
typename UTrait<P3>::ref,
void*);
00155
00156
void operator ()(
typename UTrait<P1>::ref p1,
typename UTrait<P2>::ref p2,
00157
typename UTrait<P3>::ref p3) {
00158
if (!node())
return;
00159
00160 ((Proxy)(node()->_proxy))(p1, p2, p3, node());
00161 }
00162
00163 USlot3(USlotNode * node = NULL) : USlotBase(node) {}
00164 };
00165
00166
00167
template <
typename P1,
typename P2,
typename P3,
typename P4>
00168
class UFO_EXPORT USlot4 :
public USlotBase {
00169
public:
00170
typedef void (*Proxy)(
typename UTrait<P1>::ref,
typename UTrait<P2>::ref,
00171
typename UTrait<P3>::ref,
typename UTrait<P4>::ref,
void*);
00172
00173
void operator ()(
typename UTrait<P1>::ref p1,
typename UTrait<P2>::ref p2,
00174
typename UTrait<P3>::ref p3,
typename UTrait<P4>::ref p4) {
00175
if (!node())
return;
00176
00177 ((Proxy)(node()->_proxy))(p1, p2, p3, p4, node());
00178 }
00179
00180 USlot4(USlotNode * node = NULL) : USlotBase(node) {}
00181 };
00182
00183 }
00184
00185
#endif // USLOT_HPP