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 module dcouple.slot;
00026
00027
private import dcouple.signal;
00028
private import dcouple.signalslot;
00029
00030 /+
00032
00033 interface
SlotManager
00034 {
00042
void register(GenericSlot);
00043 }
00044 +/
00045
00047
00048
class GenericSlot
00049 {
00051
00052
00053
void disconnect() {}
00054
SignalSlotManager owner() {
return null; }
00055
00056
void genericConnect(GenericSignal s) {}
00057
void genericDisconnect(GenericSignal s) {}
00058
00059 uint
numberOfArguments() {
return 0;}
00060
char[][]
arguments() {
return DUMMYarguments;}
00061
private:
00062
char[][]
DUMMYarguments;
00063 }
00064
00066 private template SlotGenericCore() {
00068
00072
00073
this(
SignalSlotManager owner, CallBack callBack)
00074 {
00075 _owner =
owner;
00076 _callBack = callBack;
00077
owner.
register(
this);
00078 initArguments();
00079 }
00080
00082
00086 ~this()
00087 {
00088
disconnect();
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 }
00099
00103
void connect(CompatibleSignal s)
00104 {
00105
if(s in _signals) {}
else {
00106 _signals[s] = s;
00107 s.connect(
this);
00108 }
00109 }
00110
00111
void genericConnect(GenericSignal gs)
00112 {
00113 CompatibleSignal s = cast(CompatibleSignal) gs;
00114 if( s ) {
00115
connect(s);
00116 }
else {
00117 printf(
"dcouple WARNING: %.*s.%.*s!(",
00118 _owner.classinfo.name,
this.classinfo.name);
00119
if(
numberOfArguments()>0) printf(
"%.*s",
arguments()[0]);
00120
for(
int i=1; i<
numberOfArguments();i++)
00121 printf(
",%.*s",
arguments()[i]);
00122 printf(
") is incompatible with %.*s.%.*s!(",
00123 gs.owner().classinfo.name, gs.classinfo.name);
00124
if(gs.numberOfArguments()>0)
00125 printf(
"%.*s",gs.arguments()[0]);
00126
for(
int i=1; i<gs.numberOfArguments();i++)
00127 printf(
",%.*s",gs.arguments()[i]);
00128 printf(
"); not connected. (Sorry, no line number...)\n");
00129 }
00130 }
00131
00135
void disconnect(CompatibleSignal s)
00136 {
00137
if(s in _signals) {
00138
delete _signals[s];
00139 s.disconnect(
this);
00140 }
00141 }
00142
00143
void genericDisconnect(GenericSignal gs)
00144 {
00145 CompatibleSignal s = cast(CompatibleSignal) gs;
00146 if( s ) {
00147
disconnect(s);
00148 }
else {
00149 printf(
"dcouple WARNING: %.*s.%.*s!(",
00150 _owner.classinfo.name,
this.classinfo.name);
00151
if(
numberOfArguments()>0) printf(
"%.*s",
arguments()[0]);
00152 for(
int i=1; i<
numberOfArguments();i++)
00153 printf(
",%.*s",
arguments()[i]);
00154 printf(
") is incompatible with %.*s.%.*s!(",
00155 gs.owner().classinfo.name, gs.classinfo.name);
00156
if(gs.numberOfArguments()>0)
00157 printf(
"%.*s",gs.arguments()[0]);
00158
for(
int i=1; i<gs.numberOfArguments();i++)
00159 printf(
",%.*s",gs.arguments()[i]);
00160 printf(
"); not disconnected. (Sorry, no line number...)\n");
00161 }
00162 }
00163
00165
00166
void disconnect()
00167 {
00168 foreach(CompatibleSignal s; _signals) {
00169
disconnect(s);
00170 }
00171 }
00172
00174
int count() {
00175
return _signals.length;
00176 }
00177
00178 uint
numberOfArguments()
00179 {
00180
return _arguments.length;
00181 }
00182
00183
char[][]
arguments() {
return _arguments;}
00184
00185
SignalSlotManager owner() {
return _owner; }
00186
protected:
00188
00189
SignalSlotManager _owner;
00191 CallBack _callBack;
00193 CompatibleSignal[CompatibleSignal] _signals;
00194
char[][] _arguments;
00195 }
00196
00197
00198
00200
00203
class Slot() : GenericSlot
00204 {
00205 alias
void delegate() CallBack;
00206 alias Signal!() CompatibleSignal;
00207 mixin SlotGenericCore;
00208
00212
void opCall()
00213 {
00214 _callBack();
00215 }
00216
void initArguments() {}
00217 }
00218
00219
class Slot(T1) : GenericSlot
00220 {
00221 alias
void delegate(T1) CallBack;
00222 alias Signal!(T1) CompatibleSignal;
00223 mixin SlotGenericCore;
00224
00228
void opCall(T1 t1)
00229 {
00230 _callBack(t1);
00231 }
00232
00233
void initArguments()
00234 {
00235 _arguments ~=
typeid(T1).toString();
00236 }
00237 }
00238
00239
class Slot(T1, T2) : GenericSlot
00240 {
00241 alias
void delegate(T1,T2) CallBack;
00242 alias Signal!(T1,T2) CompatibleSignal;
00243 mixin SlotGenericCore;
00244
00248
void opCall(T1 t1, T2 t2)
00249 {
00250 _callBack(t1, t2);
00251 }
00252
00253
void initArguments()
00254 {
00255 _arguments ~=
typeid(T1).toString();
00256 _arguments ~=
typeid(T2).toString();
00257 }
00258 }
00259
00260
class Slot(T1,T2,T3) : GenericSlot
00261 {
00262 alias
void delegate(T1,T2,T3) CallBack;
00263 alias Signal!(T1,T2,T3) CompatibleSignal;
00264 mixin SlotGenericCore;
00265
00269
void opCall(T1 t1, T2 t2, T3 t3)
00270 {
00271 _callBack(t1, t2, t3);
00272 }
00273
00274
void initArguments()
00275 {
00276 _arguments ~=
typeid(T1).toString();
00277 _arguments ~=
typeid(T2).toString();
00278 _arguments ~=
typeid(T3).toString();
00279 }
00280 }
00281
00282
class Slot(T1,T2,T3,T4) : GenericSlot
00283 {
00284 alias
void delegate(T1,T2,T3,T4) CallBack;
00285 alias Signal!(T1,T2,T3,T4) CompatibleSignal;
00286 mixin SlotGenericCore;
00287
00291
void opCall(T1 t1, T2 t2, T3 t3, T4 t4)
00292 {
00293 _callBack(t1, t2, t3, t4);
00294 }
00295
00296
void initArguments()
00297 {
00298 _arguments ~=
typeid(T1).toString();
00299 _arguments ~=
typeid(T2).toString();
00300 _arguments ~=
typeid(T3).toString();
00301 _arguments ~=
typeid(T4).toString();
00302 }
00303 }
00304
00305
class Slot(T1,T2,T3,T4,T5) : GenericSlot
00306 {
00307 alias
void delegate(T1,T2,T3,T4,T5) CallBack;
00308 alias Signal!(T1,T2,T3,T4,T5) CompatibleSignal;
00309 mixin SlotGenericCore;
00310
00314
void opCall(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
00315 {
00316 _callBack(t1, t2, t3, t4, t5);
00317 }
00318
00319
void initArguments()
00320 {
00321 _arguments ~=
typeid(T1).toString();
00322 _arguments ~=
typeid(T2).toString();
00323 _arguments ~=
typeid(T3).toString();
00324 _arguments ~=
typeid(T4).toString();
00325 _arguments ~=
typeid(T5).toString();
00326 }
00327 }
00328
00329
class Slot(T1,T2,T3,T4,T5,T6) : GenericSlot
00330 {
00331 alias
void delegate(T1,T2,T3,T4,T5,T6) CallBack;
00332 alias Signal!(T1,T2,T3,T4,T5,T6) CompatibleSignal;
00333 mixin SlotGenericCore;
00334
00338
void opCall(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
00339 {
00340 _callBack(t1, t2, t3, t4, t5, t6);
00341 }
00342
00343
void initArguments()
00344 {
00345 _arguments ~=
typeid(T1).toString();
00346 _arguments ~=
typeid(T2).toString();
00347 _arguments ~=
typeid(T3).toString();
00348 _arguments ~=
typeid(T4).toString();
00349 _arguments ~=
typeid(T5).toString();
00350 _arguments ~=
typeid(T6).toString();
00351 }
00352 }
00353
00354
class Slot(T1,T2,T3,T4,T5,T6,T7) : GenericSlot
00355 {
00356 alias
void delegate(T1,T2,T3,T4,T5,T6,T7) CallBack;
00357 alias Signal!(T1,T2,T3,T4,T5,T6,T7) CompatibleSignal;
00358 mixin SlotGenericCore;
00359
00363
void opCall(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
00364 {
00365 _callBack(t1, t2, t3, t4, t5, t6, t7);
00366 }
00367
00368
void initArguments()
00369 {
00370 _arguments ~=
typeid(T1).toString();
00371 _arguments ~=
typeid(T2).toString();
00372 _arguments ~=
typeid(T3).toString();
00373 _arguments ~=
typeid(T4).toString();
00374 _arguments ~=
typeid(T5).toString();
00375 _arguments ~=
typeid(T6).toString();
00376 _arguments ~=
typeid(T7).toString();
00377 }
00378 }