00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _pslot_h_
00021 #define _pslot_h_
00022
00023 #include <pclasses/config.h>
00024
00025 namespace P {
00026
00028
00032 template <class R>
00033 class Slot0 {
00034 public:
00035 Slot0() {}
00036 virtual ~Slot0() {}
00037 virtual R proxy() = 0;
00038 virtual Slot0* clone() const = 0;
00039 };
00040
00042
00046 template <class RetType>
00047 class FuncSlot0: public Slot0<RetType> {
00048 public:
00049 typedef RetType (*Callback)();
00050
00051 FuncSlot0(Callback cb)
00052 : _callback(cb) {}
00053
00054 ~FuncSlot0() {}
00055
00056 RetType proxy()
00057 { return _callback(); }
00058
00059 Slot0<RetType>* clone() const
00060 { return new FuncSlot0(*this); }
00061
00062 bool operator==(const FuncSlot0& slot) const
00063 { return (_callback == slot._callback); }
00064
00065 private:
00066 Callback _callback;
00067 };
00068
00069
00071
00075 template <>
00076 class FuncSlot0<void>: public Slot0<void> {
00077 public:
00078 typedef void (*Callback)();
00079
00080 FuncSlot0(Callback cb)
00081 : _callback(cb) {}
00082
00083 ~FuncSlot0() {}
00084
00085 void proxy()
00086 { _callback(); }
00087
00088 Slot0<void>* clone() const
00089 { return new FuncSlot0(*this); }
00090
00091 bool operator==(const FuncSlot0& slot) const
00092 { return (_callback == slot._callback); }
00093
00094 private:
00095 Callback _callback;
00096 };
00097
00098
00100
00104 template <class R>
00105 FuncSlot0<R> slot(R (*func)(void))
00106 { return FuncSlot0<R>(func); }
00107
00109
00113 template <class RetType, class ObjType>
00114 class MethodSlot0: public Slot0<RetType> {
00115 public:
00116 typedef RetType (ObjType::*Callback)();
00117
00118 MethodSlot0(ObjType* obj, Callback cb)
00119 : _object(obj), _callback(cb) {}
00120
00121 ~MethodSlot0() {}
00122
00123 RetType proxy()
00124 { return (_object->*_callback)(); }
00125
00126 Slot0<RetType>* clone() const
00127 { return new MethodSlot0(*this); }
00128
00129 bool operator==(const MethodSlot0& slot) const
00130 { return (_object == slot._object && _callback == slot._callback); }
00131
00132 private:
00133 ObjType* _object;
00134 Callback _callback;
00135 };
00136
00137 #ifdef CXX_PARTIAL_SPECIALIZATION
00138
00140
00144 template <class ObjType>
00145 class MethodSlot0<void, ObjType>: public Slot0<void> {
00146 public:
00147 typedef void (ObjType::*Callback)();
00148
00149 MethodSlot0(ObjType* obj, Callback cb)
00150 : _object(obj), _callback(cb) {}
00151
00152 ~MethodSlot0() {}
00153
00154 void proxy()
00155 { (_object->*_callback)(); }
00156
00157 Slot0<void>* clone() const
00158 { return new MethodSlot0(*this); }
00159
00160 bool operator==(const MethodSlot0& slot) const
00161 { return (_object == slot._object && _callback == slot._callback); }
00162
00163 private:
00164 ObjType* _object;
00165 Callback _callback;
00166 };
00167
00168 #endif
00169
00171
00175 template <class R, class O>
00176 MethodSlot0<R,O> slot(O* obj, R (O::*func)(void))
00177 { return MethodSlot0<R,O>(obj, func); }
00178
00179
00181
00185 template <class R, class P1>
00186 class Slot1 {
00187 public:
00188 Slot1() {}
00189 virtual ~Slot1() {}
00190 virtual R proxy(P1) = 0;
00191 virtual Slot1* clone() const = 0;
00192
00193 };
00194
00196
00200 template <class RetType, class ParamType1>
00201 class FuncSlot1: public Slot1<RetType, ParamType1> {
00202 public:
00203 typedef RetType (*Callback)(ParamType1);
00204
00205 FuncSlot1(Callback cb)
00206 : _callback(cb) {}
00207
00208 ~FuncSlot1() {}
00209
00210 RetType proxy(ParamType1 p1)
00211 { return _callback(p1); }
00212
00213 Slot1<RetType, ParamType1>* clone() const
00214 { return new FuncSlot1(*this); }
00215
00216 bool operator==(const FuncSlot1& slot) const
00217 { return (_callback == slot._callback); }
00218
00219 private:
00220 Callback _callback;
00221 };
00222
00223 #ifdef CXX_PARTIAL_SPECIALIZATION
00224
00226
00230 template <class ParamType1>
00231 class FuncSlot1<void, ParamType1>: public Slot1<void, ParamType1> {
00232 public:
00233 typedef void (*Callback)(ParamType1);
00234
00235 FuncSlot1(Callback cb)
00236 : _callback(cb) {}
00237
00238 ~FuncSlot1() {}
00239
00240 void proxy(ParamType1 p1)
00241 { _callback(p1); }
00242
00243 Slot1<void, ParamType1>* clone() const
00244 { return new FuncSlot1(*this); }
00245
00246 bool operator==(const FuncSlot1& slot) const
00247 { return (_callback == slot._callback); }
00248
00249 private:
00250 Callback _callback;
00251 };
00252
00253 #endif
00254
00256
00260 template <class R, class P1>
00261 FuncSlot1<R,P1> slot(R (*func)(P1))
00262 { return FuncSlot1<R,P1>(func); }
00263
00265
00269 template <class RetType, class ObjType, class ParamType1>
00270 class MethodSlot1: public Slot1<RetType, ParamType1> {
00271 public:
00272 typedef RetType (ObjType::*Callback)(ParamType1);
00273
00274 MethodSlot1(ObjType* obj, Callback cb)
00275 : _object(obj), _callback(cb) {}
00276
00277 ~MethodSlot1() {}
00278
00279 RetType proxy(ParamType1 p1)
00280 { return (_object->*_callback)(p1); }
00281
00282 Slot1<RetType, ParamType1>* clone() const
00283 { return new MethodSlot1(*this); }
00284
00285 bool operator==(const MethodSlot1& slot) const
00286 { return (_object == slot._object && _callback == slot._callback); }
00287
00288 private:
00289 ObjType* _object;
00290 Callback _callback;
00291 };
00292
00293 #ifdef CXX_PARTIAL_SPECIALIZATION
00294
00296
00300 template <class ObjType, class ParamType1>
00301 class MethodSlot1<void, ObjType, ParamType1>: public Slot1<void, ParamType1> {
00302 public:
00303 typedef void (ObjType::*Callback)(ParamType1);
00304
00305 MethodSlot1(ObjType* obj, Callback cb)
00306 : _object(obj), _callback(cb) {}
00307
00308 ~MethodSlot1() {}
00309
00310 void proxy(ParamType1 p1)
00311 { (_object->*_callback)(p1); }
00312
00313 Slot1<void, ParamType1>* clone() const
00314 { return new MethodSlot1(*this); }
00315
00316 bool operator==(const MethodSlot1& slot) const
00317 { return (_object == slot._object && _callback == slot._callback); }
00318
00319 private:
00320 ObjType* _object;
00321 Callback _callback;
00322 };
00323
00324 #endif
00325
00327
00331 template <class R, class O, class P1>
00332 MethodSlot1<R,O,P1> slot(O* obj, R (O::*func)(P1))
00333 { return MethodSlot1<R,O,P1>(obj, func); }
00334
00335
00337
00341 template <class R, class P1, class P2>
00342 class Slot2 {
00343 public:
00344 Slot2() {}
00345 virtual ~Slot2() {}
00346 virtual R proxy(P1, P2) = 0;
00347 virtual Slot2* clone() const = 0;
00348 };
00349
00351
00355 template <class RetType, class ParamType1, class ParamType2>
00356 class FuncSlot2: public Slot2<RetType, ParamType1, ParamType2> {
00357 public:
00358 typedef RetType (*Callback)(ParamType1, ParamType2);
00359
00360 FuncSlot2(Callback cb)
00361 : _callback(cb) {}
00362
00363 ~FuncSlot2() {}
00364
00365 RetType proxy(ParamType1 p1, ParamType2 p2)
00366 { return _callback(p1, p2); }
00367
00368 FuncSlot2* clone() const
00369 { return new FuncSlot2(*this); }
00370
00371 bool operator==(const FuncSlot2& slot) const
00372 { return (_callback == slot._callback); }
00373
00374 private:
00375 Callback _callback;
00376 };
00377
00378 #ifdef CXX_PARTIAL_SPECIALIZATION
00379
00381
00385 template <class ParamType1, class ParamType2>
00386 class FuncSlot2<void, ParamType1, ParamType2>:
00387 public Slot2<void, ParamType1, ParamType2>
00388 {
00389 public:
00390 typedef void (*Callback)(ParamType1, ParamType2);
00391
00392 FuncSlot2(Callback cb)
00393 : _callback(cb) {}
00394
00395 ~FuncSlot2() {}
00396
00397 void proxy(ParamType1 p1, ParamType2 p2)
00398 { _callback(p1, p2); }
00399
00400 FuncSlot2* clone() const
00401 { return new FuncSlot2(*this); }
00402
00403 bool operator==(const FuncSlot2& slot) const
00404 { return (_callback == slot._callback); }
00405
00406 private:
00407 Callback _callback;
00408 };
00409
00410 #endif
00411
00413
00417 template <class R, class P1, class P2>
00418 FuncSlot2<R,P1,P2> slot(R (*func)(P1, P2))
00419 { return FuncSlot2<R,P1,P2>(func); }
00420
00422
00426 template <class RetType, class ObjType, class ParamType1, class ParamType2>
00427 class MethodSlot2: public Slot2<RetType, ParamType1, ParamType2> {
00428 public:
00429 typedef RetType (ObjType::*Callback)(ParamType1, ParamType2);
00430
00431 MethodSlot2(ObjType* obj, Callback cb)
00432 : _object(obj), _callback(cb) {}
00433
00434 ~MethodSlot2() {}
00435
00436 RetType proxy(ParamType1 p1, ParamType2 p2)
00437 { return (_object->*_callback)(p1, p2); }
00438
00439 MethodSlot2* clone() const
00440 { return new MethodSlot2(*this); }
00441
00442 bool operator==(const MethodSlot2& slot) const
00443 { return (_object == slot._object && _callback == slot._callback); }
00444
00445 private:
00446 ObjType* _object;
00447 Callback _callback;
00448 };
00449
00450 #ifdef CXX_PARTIAL_SPECIALIZATION
00451
00453
00457 template <class ObjType, class ParamType1, class ParamType2>
00458 class MethodSlot2<void, ObjType, ParamType1, ParamType2>:
00459 public Slot2<void, ParamType1, ParamType2>
00460 {
00461 public:
00462 typedef void (ObjType::*Callback)(ParamType1, ParamType2);
00463
00464 MethodSlot2(ObjType* obj, Callback cb)
00465 : _object(obj), _callback(cb) {}
00466
00467 ~MethodSlot2() {}
00468
00469 void proxy(ParamType1 p1, ParamType2 p2)
00470 { (_object->*_callback)(p1, p2); }
00471
00472 MethodSlot2* clone() const
00473 { return new MethodSlot2(*this); }
00474
00475 bool operator==(const MethodSlot2& slot) const
00476 { return (_object == slot._object && _callback == slot._callback); }
00477
00478 private:
00479 ObjType* _object;
00480 Callback _callback;
00481 };
00482
00483 #endif
00484
00486
00490 template <class R, class O, class P1, class P2>
00491 MethodSlot2<R,O,P1,P2> slot(O* obj, R (O::*func)(P1,P2))
00492 { return MethodSlot2<R,O,P1,P2>(obj, func); }
00493
00494
00496
00500 template <class R, class P1, class P2, class P3>
00501 class Slot3 {
00502 public:
00503 Slot3() {}
00504 virtual ~Slot3() {}
00505 virtual R proxy(P1, P2, P3) = 0;
00506 virtual Slot3* clone() const = 0;
00507 };
00508
00510
00514 template <class RetType, class ParamType1, class ParamType2, class ParamType3>
00515 class FuncSlot3: public Slot3<RetType, ParamType1, ParamType2, ParamType3> {
00516 public:
00517 typedef RetType (*Callback)(ParamType1, ParamType2, ParamType3);
00518
00519 FuncSlot3(Callback cb)
00520 : _callback(cb) {}
00521
00522 ~FuncSlot3() {}
00523
00524 RetType proxy(ParamType1 p1, ParamType2 p2, ParamType3 p3)
00525 { return _callback(p1, p2, p3); }
00526
00527 FuncSlot3* clone() const
00528 { return new FuncSlot3(*this); }
00529
00530 bool operator==(const FuncSlot3& slot) const
00531 { return (_callback == slot._callback); }
00532
00533 private:
00534 Callback _callback;
00535 };
00536
00537 #ifdef CXX_PARTIAL_SPECIALIZATION
00538
00540
00544 template <class ParamType1, class ParamType2, class ParamType3>
00545 class FuncSlot3<void, ParamType1, ParamType2, ParamType3>:
00546 public Slot3<void, ParamType1, ParamType2, ParamType3>
00547 {
00548 public:
00549 typedef void (*Callback)(ParamType1, ParamType2, ParamType3);
00550
00551 FuncSlot3(Callback cb)
00552 : _callback(cb) {}
00553
00554 ~FuncSlot3() {}
00555
00556 void proxy(ParamType1 p1, ParamType2 p2, ParamType3 p3)
00557 { _callback(p1, p2); }
00558
00559 FuncSlot3* clone() const
00560 { return new FuncSlot3(*this); }
00561
00562 bool operator==(const FuncSlot3& slot) const
00563 { return (_callback == slot._callback); }
00564
00565 private:
00566 Callback _callback;
00567 };
00568
00569 #endif
00570
00572
00576 template <class R, class P1, class P2, class P3>
00577 FuncSlot3<R,P1,P2,P3> slot(R (*func)(P1, P2, P3))
00578 { return FuncSlot3<R,P1,P2,P3>(func); }
00579
00581
00585 template <class RetType, class ObjType, class ParamType1, class ParamType2, class ParamType3>
00586 class MethodSlot3: public Slot3<RetType, ParamType1, ParamType2, ParamType3> {
00587 public:
00588 typedef RetType (ObjType::*Callback)(ParamType1, ParamType2, ParamType3);
00589
00590 MethodSlot3(ObjType* obj, Callback cb)
00591 : _object(obj), _callback(cb) {}
00592
00593 ~MethodSlot3() {}
00594
00595 RetType proxy(ParamType1 p1, ParamType2 p2, ParamType3 p3)
00596 { return (_object->*_callback)(p1, p2, p3); }
00597
00598 MethodSlot3* clone() const
00599 { return new MethodSlot3(*this); }
00600
00601 bool operator==(const MethodSlot3& slot) const
00602 { return (_object == slot._object && _callback == slot._callback); }
00603
00604 private:
00605 ObjType* _object;
00606 Callback _callback;
00607 };
00608
00609 #ifdef CXX_PARTIAL_SPECIALIZATION
00610
00612
00616 template <class ObjType, class ParamType1, class ParamType2, class ParamType3>
00617 class MethodSlot3<void, ObjType, ParamType1, ParamType2, ParamType3>:
00618 public Slot3<void, ParamType1, ParamType2, ParamType3>
00619 {
00620 public:
00621 typedef void (ObjType::*Callback)(ParamType1, ParamType2, ParamType3);
00622
00623 MethodSlot3(ObjType* obj, Callback cb)
00624 : _object(obj), _callback(cb) {}
00625
00626 ~MethodSlot3() {}
00627
00628 void proxy(ParamType1 p1, ParamType2 p2, ParamType3 p3)
00629 { (_object->*_callback)(p1, p2, p3); }
00630
00631 MethodSlot3* clone() const
00632 { return new MethodSlot3(*this); }
00633
00634 bool operator==(const MethodSlot3& slot) const
00635 { return (_object == slot._object && _callback == slot._callback); }
00636
00637 private:
00638 ObjType* _object;
00639 Callback _callback;
00640 };
00641
00642 #endif
00643
00645
00649 template <class R, class O, class P1, class P2, class P3>
00650 MethodSlot3<R,O,P1,P2,P3> slot(O* obj, R (O::*func)(P1,P2,P3))
00651 { return MethodSlot3<R,O,P1,P2,P3>(obj, func); }
00652
00653
00654 }
00655
00656 #endif