Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

scim_slot.h

Go to the documentation of this file.
00001 /** @file scim_slot.h
00002  * @brief C++ slot interface.
00003  * 
00004  * Provides a set of slot class templates. Slots are callable objects that
00005  * can be used to connect functions, class methods and function objects to
00006  * scim::Signals. 
00007  *
00008  * Most code of this file are came from Inti project.
00009  */
00010 
00011 /*
00012  * Smart Common Input Method
00013  * 
00014  * Copyright (c) 2004 James Su <suzhe@turbolinux.com.cn>
00015  * Copyright (c) 2003 James Su <suzhe@turbolinux.com.cn>
00016  * Copyright (c) 2002 James Su <suzhe@turbolinux.com.cn>
00017  * Copyright (c) 2002 The Inti Development Team.
00018  * Copyright (c) 2000 Red Hat, Inc.
00019  * Copyright 1999, Karl Einar Nelson
00020  *
00021  *
00022  * This library is free software; you can redistribute it and/or
00023  * modify it under the terms of the GNU Lesser General Public
00024  * License as published by the Free Software Foundation; either
00025  * version 2 of the License, or (at your option) any later version.
00026  *
00027  * This library is distributed in the hope that it will be useful,
00028  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00029  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00030  * GNU Lesser General Public License for more details.
00031  *
00032  * You should have received a copy of the GNU Lesser General Public
00033  * License along with this program; if not, write to the
00034  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00035  * Boston, MA  02111-1307  USA
00036  *
00037  * $Id: scim_slot.h,v 1.6 2004/02/06 07:53:15 suzhe Exp $
00038  */
00039 
00040 #ifndef __SCIM_SLOT_H
00041 #define __SCIM_SLOT_H
00042 
00043 namespace scim {
00044 
00045 /**
00046  * @addtogroup SignalSlot
00047  * @{
00048  */
00049 
00050 //! @name Slot functions returning a new slot
00051 //! @{
00052 
00053 //! @class Slot 
00054 //! @brief Base class for slots that can connect to scim::Signals.
00055 
00056 class Slot : public ReferencedObject
00057 {
00058     Slot(const Slot&);
00059     Slot& operator=(const Slot&);
00060 
00061 protected:
00062     Slot();
00063     //!< Constructor.
00064 
00065     virtual ~Slot() = 0;
00066     //!< Destructor.
00067 };
00068 
00069 //! @class Slot0 
00070 //! @brief Base class template for slots passing no arguments and returning a value of type R.
00071 
00072 template <typename R>
00073 class Slot0 : public Slot
00074 {
00075 protected:
00076     Slot0() {}
00077     //!< Constructor.
00078 
00079 public:
00080     virtual R call() const = 0;
00081     //!< Calls the signal handler connected to this slot.
00082 
00083     R operator()() const { return call(); }
00084     //!< Function operator; Calls call().
00085 };
00086 
00087 //! @class FunctionSlot0 
00088 //! @brief A slot template for static functions taking no arguments and returning a value of type R.
00089 
00090 template <typename R>
00091 class FunctionSlot0 : public Slot0<R>
00092 {
00093     typedef R (*PF)();
00094     PF pf;
00095     
00096 public:
00097     FunctionSlot0(PF function) : pf(function) {} 
00098     //!< Construct a new function slot for a static function.
00099     //!< @param function - static function with the signature R (*PF)().
00100 
00101     virtual R call() const { return (*pf)(); }
00102     //!< Calls the function connected to this slot.
00103     //!< @return a value of type R returned by the called function.
00104 };
00105 
00106 //! Overloaded slot factory function.
00107 //! @param function - a static function with the signature R (*function)().
00108 //! @return a new slot passing no arguments and returning a value of type R.
00109 //!
00110 //! <BR>If the returned slot is connected to a signal it doesn't have to be
00111 //! unreferenced. The signal it's connected to will unreference the slot when
00112 //! it is destroyed. Otherwise the slot must be unreferenced by calling unref().
00113 
00114 template <typename R>
00115 inline Slot0<R>*
00116 slot(R (*function)())
00117 {
00118     return new FunctionSlot0<R>(function);
00119 }
00120 
00121 //! @class MethodSlot0 
00122 //! @brief A slot template for methods in a class of type T taking no arguments and returning a value of type R.
00123 
00124 template <typename T, typename R>
00125 class MethodSlot0 : public Slot0<R>
00126 {
00127     typedef R (T::*PMF)();
00128     PMF pmf;
00129     T *t;
00130     
00131 public:
00132     MethodSlot0(T *object, PMF function) : pmf(function), t(object) {}
00133     //!< Construct a new method slot for a class member function.
00134     //!< @param object - a pointer to an object of type T.
00135     //!< @param function - a class method with the signature R (T::*PMF)().
00136 
00137     virtual R call() const { return (t->*pmf)(); }
00138     //!< Calls the class method connected to this slot.
00139     //!< @return a value of type R returned by the called method.
00140 };
00141 
00142 //! Overloaded slot factory function.
00143 //! @param object - a reference to a pointer to an object of type T1.
00144 //! @param function - a class method with the signature R (T2::*function)().
00145 //! @return a new slot passing no arguments and returning a value of type R.
00146 //!
00147 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00148 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00149 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00150 //! unreferenced by calling unref().
00151 
00152 template <typename T1, typename T2, typename R>
00153 inline Slot0<R>*
00154 slot(T1* &object, R (T2::*function)())
00155 {
00156     return new MethodSlot0<T2, R>(object, function);
00157 }
00158 
00159 //! Overloaded slot factory function.
00160 //! @param object - a reference to a const pointer to an object of type T1 (e.g. this).
00161 //! @param function - a class method with the signature R (T2::*function)().
00162 //! @return a new slot passing no arguments and returning a value of type R.
00163 //!
00164 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00165 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00166 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00167 //! unreferenced by calling unref().
00168 
00169 template <typename T1, typename T2, typename R>
00170 inline Slot0<R>*
00171 slot(T1* const &object, R (T2::*function)())
00172 {
00173     return new MethodSlot0<T2, R>(object, function);
00174 }
00175 
00176 //! Overloaded slot factory function.
00177 //! @param object - a reference to an object of type T1.
00178 //! @param function - a class method with the signature R (T2::*function)().
00179 //! @return a new slot passing no arguments and returning a value of type R.
00180 //!
00181 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00182 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00183 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00184 //! unreferenced by calling unref().
00185 
00186 template <typename T1, typename T2, typename R>
00187 inline Slot0<R>*
00188 slot(T1& object, R (T2::*function)())
00189 {
00190     return new MethodSlot0<T2, R>(&object, function);
00191 }
00192 
00193 /*  SignalSlot0
00194  */
00195 
00196 template <typename T, typename R>
00197 class SignalSlot0 : public Slot0<R>
00198 {
00199     typedef R (*PF)(void*);
00200     PF pf;
00201     T *t;
00202     
00203 public:
00204     SignalSlot0(T *signal, PF function) : pf(function), t(signal) {} 
00205 
00206     virtual R call() const { return (*pf)(t); }
00207 };
00208 
00209 //! @class Slot1 
00210 //! @brief Base class template for slots passing one argument of type P1 and returning a value of type R.
00211 
00212 template <typename R, typename P1>
00213 class Slot1 : public Slot
00214 {
00215 protected:
00216     Slot1() {}
00217     //!< Constructor.
00218 
00219 public:
00220     virtual R call(P1 p1) const = 0;
00221     //!< Calls the signal handler connected to this slot.
00222 
00223     R operator()(P1 p1) const { return call(p1); }
00224     //!< Function operator; Calls call().
00225 };
00226 
00227 //! @class FunctionSlot1 
00228 //! @brief A slot template for static functions taking one argument of type P1
00229 //! and returning a value of type R.
00230 
00231 template <typename R, typename P1>
00232 class FunctionSlot1 : public Slot1<R, P1>
00233 {
00234     typedef R (*PF)(P1);
00235     PF pf;
00236     
00237 public:
00238     FunctionSlot1(PF function) : pf(function) {} 
00239     //!< Construct a new function slot for a static function.
00240     //!< @param function - static function with the signature R (*PF)(P1).
00241 
00242     virtual R call(P1 p1) const { return (*pf)(p1); }
00243     //!< Calls the function connected to this slot passing it argument p1.
00244     //!< @return a value of type R returned by the called function.
00245 };
00246 
00247 //! Overloaded slot factory function.
00248 //! @param function - a static function with the signature R (*function)(P1).
00249 //! @return a new slot passing one argument of type P1 and returning a value of type R.
00250 //!
00251 //! <BR>If the returned slot is connected to a signal it doesn't have to be
00252 //! unreferenced. The signal it's connected to will unreference the slot when
00253 //! it is destroyed. Otherwise the slot must be unreferenced by calling unref().
00254 
00255 template <typename R, typename P1>
00256 inline Slot1<R, P1>*
00257 slot(R (*function)(P1))
00258 {
00259     return new FunctionSlot1<R, P1>(function);
00260 }
00261 
00262 //! @class MethodSlot1
00263 //! @brief A slot template for methods in a class of type T taking one argument of type P1
00264 //! and returning a value of type R.
00265 
00266 template <typename T, typename R, typename P1>
00267 class MethodSlot1 : public Slot1<R, P1>
00268 {
00269     typedef R (T::*PMF)(P1);
00270     PMF pmf;
00271     T *t;
00272     
00273 public:
00274     MethodSlot1(T *object, PMF function) : pmf(function), t(object) {}
00275     //!< Construct a new method slot for a class member function.
00276     //!< @param object - a pointer to an object of type T.
00277     //!< @param function - a class method with the signature R (T::*PMF)(P1).
00278 
00279     virtual R call(P1 p1) const { return (t->*pmf)(p1); }
00280     //!< Calls the class method connected to this slot passing it argument p1.
00281     //!< @return a value of type R returned by the called method.
00282 };
00283 
00284 //! Overloaded slot factory function.
00285 //! @param object - a reference to a pointer to an object of type T1.
00286 //! @param function - a class method with the signature R (T2::*function)(P1).
00287 //! @return a new slot passing one argument of type P1 and returning a value of type R.
00288 //!
00289 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00290 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00291 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00292 //! unreferenced by calling unref().
00293 
00294 template <typename T1, typename T2, typename R, typename P1>
00295 inline Slot1<R, P1>*
00296 slot(T1* &object, R (T2::*function)(P1))
00297 {
00298     return new MethodSlot1<T2, R, P1>(object, function);
00299 }
00300 
00301 //! Overloaded slot factory function.
00302 //! @param object - a reference to a const pointer to an object of type T1 (e.g. this).
00303 //! @param function - a class method with the signature R (T2::*function)(P1).
00304 //! @return a new slot passing one argument of type P1 and returning a value of type R.
00305 //!
00306 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00307 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00308 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00309 //! unreferenced by calling unref().
00310 
00311 template <typename T1, typename T2, typename R, typename P1>
00312 inline Slot1<R, P1>*
00313 slot(T1* const &object, R (T2::*function)(P1))
00314 {
00315     return new MethodSlot1<T2, R, P1>(object, function);
00316 }
00317 
00318 //! Overloaded slot factory function.
00319 //! @param object - a reference to an object of type T1.
00320 //! @param function - a class method with the signature R (T2::*function)(P1).
00321 //! @return a new slot passing one argument of type P1 and returning a value of type R.
00322 //!
00323 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00324 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00325 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00326 //! unreferenced by calling unref().
00327 
00328 template <typename T1, typename T2, typename R, typename P1>
00329 inline Slot1<R, P1>*
00330 slot(T1& object, R (T2::*function)(P1))
00331 {
00332     return new MethodSlot1<T2, R, P1>(&object, function);
00333 }
00334 
00335 /*  SignalSlot1
00336  */
00337 
00338 template <typename T, typename R, typename P1>
00339 class SignalSlot1 : public Slot1<R, P1>
00340 {
00341     typedef R (*PF)(void*, P1);
00342     PF pf;
00343     T *t;
00344     
00345 public:
00346     SignalSlot1(T *signal, PF function) : pf(function), t(signal) {} 
00347 
00348     virtual R call(P1 p1) const { return (*pf)(t, p1); }
00349 };
00350 
00351 //! @class Slot2 
00352 //! @brief Base class template for slots passing two arguments of type P1 and P2,
00353 //! and returning a value of type R.
00354 
00355 template <typename R, typename P1, typename P2>
00356 class Slot2 : public Slot
00357 {
00358 protected:
00359     Slot2() {}
00360     //!< Constructor.
00361     
00362 public:
00363     virtual R call(P1 p1, P2 p2) const = 0;
00364     //!< Calls the signal handler connected to this slot.
00365 
00366     R operator()(P1 p1, P2 p2) const { return call(p1, p2); }
00367     //!< Function operator; Calls call().
00368 };
00369 
00370 //! @class FunctionSlot2 
00371 //! @brief A slot template for static functions taking two arguments of type P1 and P2,
00372 //! and returning a value of type R.
00373 
00374 template <typename R, typename P1, typename P2>
00375 class FunctionSlot2 : public Slot2<R, P1, P2>
00376 {
00377     typedef R (*PF)(P1, P2);
00378     PF pf;
00379     
00380 public:
00381     FunctionSlot2(PF function) : pf(function) {} 
00382     //!< Construct a new function slot for a static function.
00383     //!< @param function - static function with the signature R (*PF)(P1, P2).
00384 
00385     virtual R call(P1 p1, P2 p2) const { return (*pf)(p1, p2); }
00386     //!< Calls the function connected to this slot passing it arguments p1 and p2.
00387     //!< @return a value of type R returned by the called function.
00388 };
00389 
00390 //! Overloaded slot factory function.
00391 //! @param function - a static function with the signature R (*function)(P1, P2).
00392 //! @return a new slot passing two arguments of type P1 and P2, and returning a value of type R.
00393 //!
00394 //! <BR>If the returned slot is connected to a signal it doesn't have to be
00395 //! unreferenced. The signal it's connected to will unreference the slot when
00396 //! it is destroyed. Otherwise the slot must be unreferenced by calling unref().
00397 
00398 template <typename R, typename P1, typename P2>
00399 inline Slot2<R, P1, P2>*
00400 slot(R (*function)(P1, P2))
00401 {
00402     return new FunctionSlot2<R, P1, P2>(function);
00403 }
00404 
00405 //! @class MethodSlot2
00406 //! @brief A slot template for methods in a class of type T taking two arguments of type P1 and P2,
00407 //! and returning a value of type R.
00408 
00409 template <typename T, typename R, typename P1, typename P2>
00410 class MethodSlot2 : public Slot2<R, P1, P2>
00411 {
00412     typedef R (T::*PMF)(P1, P2);
00413     PMF pmf;
00414     T *t;
00415     
00416 public:
00417     MethodSlot2(T *object, PMF function) : pmf(function), t(object) {}
00418     //!< Construct a new method slot for a class member function.
00419     //!< @param object - a pointer to an object of type T.
00420     //!< @param function - a class method with the signature R (T::*PMF)(P1, P2).
00421 
00422     virtual R call(P1 p1, P2 p2) const { return (t->*pmf)(p1, p2); }
00423     //!< Calls the class method connected to this slot passing it arguments p1 and p2.
00424     //!< @return a value of type R returned by the called method.
00425 };
00426 
00427 //! Overloaded slot factory function.
00428 //! @param object - a reference to a pointer to an object of type T1.
00429 //! @param function - a class method with the signature R (T2::*function)(P1, P2).
00430 //! @return a new slot passing two arguments of type P1 and P2, and returning a value of type R.
00431 //!
00432 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00433 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00434 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00435 //! unreferenced by calling unref().
00436 
00437 template <typename T1, typename T2, typename R, typename P1, typename P2>
00438 inline Slot2<R, P1, P2>*
00439 slot(T1* &object, R (T2::*function)(P1, P2))
00440 {
00441     return new MethodSlot2<T2, R, P1, P2>(object, function);
00442 }
00443 
00444 //! Overloaded slot factory function.
00445 //! @param object - a reference to a const pointer to an object of type T1 (e.g. this).
00446 //! @param function - a class method with the signature R (T2::*function)(P1, P2).
00447 //! @return a new slot passing two arguments of type P1 and P2, and returning a value of type R.
00448 //!
00449 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00450 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00451 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00452 //! unreferenced by calling unref().
00453 
00454 template <typename T1, typename T2, typename R, typename P1, typename P2>
00455 inline Slot2<R, P1, P2>*
00456 slot(T1* const &object, R (T2::*function)(P1, P2))
00457 {
00458     return new MethodSlot2<T2, R, P1, P2>(object, function);
00459 }
00460 
00461 //! Overloaded slot factory function.
00462 //! @param object - a reference to an object of type T1.
00463 //! @param function - a class method with the signature R (T2::*function)(P1, P2).
00464 //! @return a new slot passing two arguments of type P1 and P2, and returning a value of type R.
00465 //!
00466 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00467 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00468 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00469 //! unreferenced by calling unref().
00470 
00471 template <typename T1, typename T2, typename R, typename P1, typename P2>
00472 inline Slot2<R, P1, P2>*
00473 slot(T1& object, R (T2::*function)(P1, P2))
00474 {
00475     return new MethodSlot2<T2, R, P1, P2>(&object, function);
00476 }
00477 
00478 /*  SignalSlot2
00479  */
00480 
00481 template <typename T, typename R, typename P1, typename P2>
00482 class SignalSlot2 : public Slot2<R, P1, P2>
00483 {
00484     typedef R (*PF)(void*, P1, P2);
00485     PF pf;
00486     T *t;
00487     
00488 public:
00489     SignalSlot2(T *signal, PF function) : pf(function), t(signal) {} 
00490 
00491     virtual R call(P1 p1, P2 p2) const { return (*pf)(t, p1, p2); }
00492 };
00493 
00494 //! @class Slot3 
00495 //! @brief Base class template for slots passing three arguments of type P1, P2 and P3,
00496 //! and returning a value of type R.
00497 
00498 template <typename R, typename P1, typename P2, typename P3>
00499 class Slot3 : public Slot
00500 {
00501 protected:
00502     Slot3() {}
00503     //!< Constructor.
00504 
00505 public:
00506     virtual R call(P1 p1, P2 p2, P3 p3) const = 0;
00507     //!< Calls the signal handler connected to this slot.
00508 
00509     R operator()(P1 p1, P2 p2, P3 p3) const { return call(p1, p2, p3); }
00510     //!< Function operator; Calls call().
00511 };
00512 
00513 //! @class FunctionSlot3 
00514 //! @brief A slot template for static functions taking three arguments of type P1, P2 and P3,
00515 //! and returning a value of type R.
00516 
00517 template <typename R, typename P1, typename P2, typename P3>
00518 class FunctionSlot3 : public Slot3<R, P1, P2, P3>
00519 {
00520     typedef R (*PF)(P1, P2, P3);
00521     PF pf;
00522     
00523 public:
00524     FunctionSlot3(PF function) : pf(function) {} 
00525     //!< Construct a new function slot for a static function.
00526     //!< @param function - static function with the signature R (*PF)(P1, P2, P3).
00527 
00528     virtual R call(P1 p1, P2 p2, P3 p3) const { return (*pf)(p1, p2, p3); }
00529     //!< Calls the function connected to this slot passing it arguments p1, p2 and p3.
00530     //!< @return a value of type R returned by the called function.
00531 };
00532 
00533 //! Overloaded slot factory function.
00534 //! @param function - a static function with the signature R (*function)(P1, P2, P3).
00535 //! @return a new slot passing three arguments of type P1, P2 and P3, and returning a value of type R.
00536 //!
00537 //! <BR>If the returned slot is connected to a signal it doesn't have to be
00538 //! unreferenced. The signal it's connected to will unreference the slot when
00539 //! it is destroyed. Otherwise the slot must be unreferenced by calling unref().
00540 
00541 template <typename R, typename P1, typename P2, typename P3>
00542 inline Slot3<R, P1, P2, P3>*
00543 slot(R (*function)(P1, P2, P3))
00544 {
00545     return new FunctionSlot3<R, P1, P2, P3>(function);
00546 }
00547 
00548 //! @class MethodSlot3
00549 //! @brief A slot template for methods in a class of type T taking three arguments of type P1, P2 and P3,
00550 //! and returning a value of type R.
00551 
00552 template <typename T, typename R, typename P1, typename P2, typename P3>
00553 class MethodSlot3 : public Slot3<R, P1, P2, P3>
00554 {
00555     typedef R (T::*PMF)(P1, P2, P3);
00556     PMF pmf;
00557     T *t;
00558     
00559 public:
00560     MethodSlot3(T *object, PMF function) : pmf(function), t(object) {}
00561     //!< Construct a new method slot for a class member function.
00562     //!< @param object - a pointer to an object of type T.
00563     //!< @param function - a class method with the signature R (T::*PMF)(P1, P2, P3).
00564 
00565     virtual R call(P1 p1, P2 p2, P3 p3) const { return (t->*pmf)(p1, p2, p3); }
00566     //!< Calls the class method connected to this slot passing it arguments p1, p2 and p3.
00567     //!< @return a value of type R returned by the called method.
00568 };
00569 
00570 //! Overloaded slot factory function.
00571 //! @param object - a reference to a pointer to an object of type T1.
00572 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3).
00573 //! @return a new slot passing three arguments of type P1, P2 and P3, and returning a value of type R.
00574 //!
00575 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00576 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00577 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00578 //! unreferenced by calling unref().
00579 
00580 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3>
00581 inline Slot3<R, P1, P2, P3>*
00582 slot(T1* &object, R (T2::*function)(P1, P2, P3))
00583 {
00584     return new MethodSlot3<T2, R, P1, P2, P3>(object, function);
00585 }
00586 
00587 //! Overloaded slot factory function.
00588 //! @param object - a reference to a const pointer to an object of type T1 (e.g. this).
00589 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3).
00590 //! @return a new slot passing three arguments of type P1, P2 and P3, and returning a value of type R.
00591 //!
00592 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00593 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00594 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00595 //! unreferenced by calling unref().
00596 
00597 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3>
00598 inline Slot3<R, P1, P2, P3>*
00599 slot(T1* const &object, R (T2::*function)(P1, P2, P3))
00600 {
00601     return new MethodSlot3<T2, R, P1, P2, P3>(object, function);
00602 }
00603 
00604 //! Overloaded slot factory function.
00605 //! @param object - a reference to an object of type T1.
00606 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3).
00607 //! @return a new slot passing three arguments of type P1, P2 and P3, and returning a value of type R.
00608 //!
00609 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00610 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00611 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00612 //! unreferenced by calling unref().
00613 
00614 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3>
00615 inline Slot3<R, P1, P2, P3>*
00616 slot(T1& object, R (T2::*function)(P1, P2, P3))
00617 {
00618     return new MethodSlot3<T2, R, P1, P2, P3>(&object, function);
00619 }
00620 
00621 /*  SignalSlot3
00622  */
00623 
00624 template <typename T, typename R, typename P1, typename P2, typename P3>
00625 class SignalSlot3 : public Slot3<R, P1, P2, P3>
00626 {
00627     typedef R (*PF)(void*, P1, P2, P3);
00628     PF pf;
00629     T *t;
00630     
00631 public:
00632     SignalSlot3(T *signal, PF function) : pf(function), t(signal) {} 
00633 
00634     virtual R call(P1 p1, P2 p2, P3 p3) const { return (*pf)(t, p1, p2, p3); }
00635 };
00636 
00637 //! @class Slot4
00638 //! @brief Base class template for slots passing four arguments of type P1, P2, P3 and P4,
00639 //! and returning a value of type R.
00640 
00641 template <typename R, typename P1, typename P2, typename P3, typename P4>
00642 class Slot4 : public Slot
00643 {
00644 protected:
00645     Slot4() {}
00646     //!< Constructor.
00647 
00648 public:
00649     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4) const = 0;
00650     //!< Calls the signal handler connected to this slot.
00651 
00652     R operator()(P1 p1, P2 p2, P3 p3, P4 p4) const { return call(p1, p2, p3, p4); }
00653     //!< Function operator; Calls call().
00654 };
00655 
00656 //! @class FunctionSlot4 
00657 //! @brief A slot template for static functions taking four arguments of type P1, P2, P3 and P4,
00658 //! and returning a value of type R.
00659 
00660 template <typename R, typename P1, typename P2, typename P3, typename P4>
00661 class FunctionSlot4 : public Slot4<R, P1, P2, P3, P4>
00662 {
00663     typedef R (*PF)(P1, P2, P3, P4);
00664     PF pf;
00665     
00666 public:
00667     FunctionSlot4(PF function) : pf(function) {} 
00668     //!< Construct a new function slot for a static function.
00669     //!< @param function - static function with the signature R (*PF)(P1, P2, P3, P4).
00670 
00671     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4) const { return (*pf)(p1, p2, p3, p4); }
00672     //!< Calls the function connected to this slot passing it arguments p1, p2, p3 and p4.
00673     //!< @return a value of type R returned by the called function.
00674 };
00675 
00676 //! Overloaded slot factory function.
00677 //! @param function - a static function with the signature R (*function)(P1, P2, P3, P4).
00678 //! @return a new slot passing four arguments of type P1, P2, P3 and P4, and returning a value of type R.
00679 //!
00680 //! <BR>If the returned slot is connected to a signal it doesn't have to be
00681 //! unreferenced. The signal it's connected to will unreference the slot when
00682 //! it is destroyed. Otherwise the slot must be unreferenced by calling unref().
00683 
00684 template <typename R, typename P1, typename P2, typename P3, typename P4>
00685 inline Slot4<R, P1, P2, P3, P4>*
00686 slot(R (*function)(P1, P2, P3, P4))
00687 {
00688     return new FunctionSlot4<R, P1, P2, P3, P4>(function);
00689 }
00690 
00691 //! @class MethodSlot4 
00692 //! @brief A slot template for methods in a class of type T taking four arguments of type P1, P2, P3 and P4,
00693 //! and returning a value of type R.
00694 
00695 template <typename T, typename R, typename P1, typename P2, typename P3, typename P4>
00696 class MethodSlot4 : public Slot4<R, P1, P2, P3, P4>
00697 {
00698     typedef R (T::*PMF)(P1, P2, P3, P4);
00699     PMF pmf;
00700     T *t;
00701     
00702 public:
00703     MethodSlot4(T *object, PMF function) : pmf(function), t(object) {}
00704     //!< Construct a new method slot for a class member function.
00705     //!< @param object - a pointer to an object of type T.
00706     //!< @param function - a class method with the signature R (T::*PMF)(P1, P2, P3, P4).
00707 
00708     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4) const { return (t->*pmf)(p1, p2, p3, p4); }
00709     //!< Calls the class method connected to this slot passing it arguments p1, p2, p3 and p4.
00710     //!< @return a value of type R returned by the called method.
00711 };
00712 
00713 //! Overloaded slot factory function.
00714 //! @param object - a reference to a pointer to an object of type T1.
00715 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4).
00716 //! @return a new slot passing four arguments of type P1, P2, P3 and P4, and returning a value of type R.
00717 //!
00718 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00719 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00720 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00721 //! unreferenced by calling unref().
00722 
00723 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4>
00724 inline Slot4<R, P1, P2, P3, P4>*
00725 slot(T1* &object, R (T2::*function)(P1, P2, P3, P4))
00726 {
00727     return new MethodSlot4<T2, R, P1, P2, P3, P4>(object, function);
00728 }
00729 
00730 //! Overloaded slot factory function.
00731 //! @param object - a reference to a const pointer to an object of type T1 (e.g. this).
00732 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4).
00733 //! @return a new slot passing four arguments of type P1, P2, P3 and P4, and returning a value of type R.
00734 //!
00735 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00736 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00737 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00738 //! unreferenced by calling unref().
00739 
00740 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4>
00741 inline Slot4<R, P1, P2, P3, P4>*
00742 slot(T1* const &object, R (T2::*function)(P1, P2, P3, P4))
00743 {
00744     return new MethodSlot4<T2, R, P1, P2, P3, P4>(object, function);
00745 }
00746 
00747 //! Overloaded slot factory function.
00748 //! @param object - a reference to an object of type T1.
00749 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4).
00750 //! @return a new slot passing four arguments of type P1, P2, P3 and P4, and returning a value of type R.
00751 //!
00752 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00753 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00754 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00755 //! unreferenced by calling unref().
00756 
00757 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4>
00758 inline Slot4<R, P1, P2, P3, P4>*
00759 slot(T1& object, R (T2::*function)(P1, P2, P3, P4))
00760 {
00761     return new MethodSlot4<T2, R, P1, P2, P3, P4>(&object, function);
00762 }
00763 
00764 /*  SignalSlot4
00765  */
00766 
00767 template <typename T, typename R, typename P1, typename P2, typename P3, typename P4>
00768 class SignalSlot4 : public Slot4<R, P1, P2, P3, P4>
00769 {
00770     typedef R (*PF)(void*, P1, P2, P3, P4);
00771     PF pf;
00772     T *t;
00773     
00774 public:
00775     SignalSlot4(T *signal, PF function) : pf(function), t(signal) {} 
00776 
00777     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4) const { return (*pf)(t, p1, p2, p3, p4); }
00778 };
00779 
00780 //! @class Slot5 
00781 //! @brief Base class template for slots passing five arguments of type P1, P2, P3, P4 and P5,
00782 //! and returning a value of type R.
00783 
00784 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00785 class Slot5 : public Slot
00786 {
00787 protected:
00788     Slot5() {}
00789 
00790 public:
00791     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const = 0;
00792     //!< Calls the signal handler connected to this slot.
00793 
00794     R operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const { return call(p1, p2, p3, p4, p5); }
00795     //!< Function operator; Calls call().
00796 };
00797 
00798 //! @class FunctionSlot5
00799 //! @brief A slot template for static functions taking five arguments of type P1, P2, P3, P4 and P5,
00800 //! and returning a value of type R.
00801 
00802 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00803 class FunctionSlot5 : public Slot5<R, P1, P2, P3, P4, P5>
00804 {
00805     typedef R (*PF)(P1, P2, P3, P4, P5);
00806     PF pf;
00807     
00808 public:
00809     FunctionSlot5(PF function) : pf(function) {} 
00810     //!< Construct a new function slot for a static function.
00811     //!< @param function - static function with the signature R (*PF)(P1, P2, P3, P4, P5).
00812 
00813     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const { return (*pf)(p1, p2, p3, p4, p5); }
00814     //!< Calls the function connected to this slot passing it arguments p1, p2, p3, p4 and p5.
00815     //!< @return a value of type R returned by the called function.
00816 };
00817 
00818 //! Overloaded slot factory function.
00819 //! @param function - a static function with the signature R (*function)(P1, P2, P3, P4, P5).
00820 //! @return a new slot passing five arguments of type P1, P2, P3, P4 and P5, and returning a value of type R.
00821 //!
00822 //! <BR>If the returned slot is connected to a signal it doesn't have to be
00823 //! unreferenced. The signal it's connected to will unreference the slot when
00824 //! it is destroyed. Otherwise the slot must be unreferenced by calling unref().
00825 
00826 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00827 inline Slot5<R, P1, P2, P3, P4, P5>*
00828 slot(R (*function)(P1, P2, P3, P4, P5))
00829 {
00830     return new FunctionSlot5<R, P1, P2, P3, P4, P5>(function);
00831 }
00832 
00833 //! @class MethodSlot5 
00834 //! @brief A slot template for methods in a class of type T taking five arguments of type P1, P2, P3, P4 and P5,
00835 //! and returning a value of type R.
00836 
00837 template <typename T, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00838 class MethodSlot5 : public Slot5<R, P1, P2, P3, P4, P5>
00839 {
00840     typedef R (T::*PMF)(P1, P2, P3, P4, P5);
00841     PMF pmf;
00842     T *t;
00843     
00844 public:
00845     MethodSlot5(T *object, PMF function) : pmf(function), t(object) {}
00846     //!< Construct a new method slot for a class member function.
00847     //!< @param object - a pointer to an object of type T.
00848     //!< @param function - a class method with the signature R (T::*PMF)(P1, P2, P3, P4, P5).
00849 
00850     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const { return (t->*pmf)(p1, p2, p3, p4, p5); }
00851     //!< Calls the class method connected to this slot passing it arguments p1, p2, p3, p4 and p5.
00852     //!< @return a value of type R returned by the called method.
00853 };
00854 
00855 //! Overloaded slot factory function.
00856 //! @param object - a reference to a pointer to an object of type T1.
00857 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4, P5).
00858 //! @return a new slot passing five arguments of type P1, P2, P3, P4 and P5, and returning a value of type R.
00859 //!
00860 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00861 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00862 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00863 //! unreferenced by calling unref().
00864 
00865 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00866 inline Slot5<R, P1, P2, P3, P4, P5>*
00867 slot(T1* &object, R (T2::*function)(P1, P2, P3, P4, P5))
00868 {
00869     return new MethodSlot5<T2, R, P1, P2, P3, P4, P5>(object, function);
00870 }
00871 
00872 //! Overloaded slot factory function.
00873 //! @param object - a reference to a const pointer to an object of type T1 (e.g. this).
00874 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4, P5).
00875 //! @return a new slot passing five arguments of type P1, P2, P3, P4 and P5, and returning a value of type R.
00876 //!
00877 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00878 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00879 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00880 //! unreferenced by calling unref().
00881 
00882 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00883 inline Slot5<R, P1, P2, P3, P4, P5>*
00884 slot(T1* const &object, R (T2::*function)(P1, P2, P3, P4, P5))
00885 {
00886     return new MethodSlot5<T2, R, P1, P2, P3, P4, P5>(object, function);
00887 }
00888 
00889 //! Overloaded slot factory function.
00890 //! @param object - a reference to an object of type T1.
00891 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4, P5).
00892 //! @return a new slot passing five arguments of type P1, P2, P3, P4 and P5, and returning a value of type R.
00893 //!
00894 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
00895 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
00896 //! will unreference the slot when it is destroyed. Otherwise the slot must be
00897 //! unreferenced by calling unref().
00898 
00899 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00900 inline Slot5<R, P1, P2, P3, P4, P5>*
00901 slot(T1& object, R (T2::*function)(P1, P2, P3, P4, P5))
00902 {
00903     return new MethodSlot5<T2, R, P1, P2, P3, P4, P5>(&object, function);
00904 }
00905 
00906 /*  SignalSlot5
00907  */
00908 
00909 template <typename T, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00910 class SignalSlot5 : public Slot5<R, P1, P2, P3, P4, P5>
00911 {
00912     typedef R (*PF)(void*, P1, P2, P3, P4, P5);
00913     PF pf;
00914     T *t;
00915     
00916 public:
00917     SignalSlot5(T *signal, PF function) : pf(function), t(signal) {} 
00918 
00919     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const { return (*pf)(t, p1, p2, p3, p4, p5); }
00920 };
00921 
00922 //! @class Slot6 
00923 //! @brief Base class template for slots passing six arguments of type P1, P2, P3, P4, P5 and P6,
00924 //! and returning a value of type R.
00925 
00926 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00927 class Slot6 : public Slot
00928 {
00929 protected:
00930     Slot6() {}
00931     //!< Constructor.
00932 
00933 public:
00934     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) const = 0;
00935     //!< Calls the signal handler connected to this slot.
00936 
00937     R operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) const { return call(p1, p2, p3, p4, p5, p6); }
00938     //!< Function operator; Calls call().
00939 };
00940 
00941 //! @class FunctionSlot6
00942 //! @brief A slot template for static functions taking six arguments of type P1, P2, P3, P4, P5 and P6,
00943 //! and returning a value of type R.
00944 
00945 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00946 class FunctionSlot6 : public Slot6<R, P1, P2, P3, P4, P5, P6>
00947 {
00948     typedef R (*PF)(P1, P2, P3, P4, P5, P6);
00949     PF pf;
00950     
00951 public:
00952     FunctionSlot6(PF function) : pf(function) {} 
00953     //!< Construct a new function slot for a static function.
00954     //!< @param function - static function with the signature R (*PF)(P1, P2, P3, P4, P5).
00955 
00956     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) const { return (*pf)(p1, p2, p3, p4, p5, p6); }
00957     //!< Calls the function connected to this slot passing it arguments p1, p2, p3, p4, p5 and p6.
00958     //!< @return a value of type R returned by the called function.
00959 };
00960 
00961 //! Overloaded slot factory function.
00962 //! @param function - a static function with the signature R (*function)(P1, P2, P3, P4, P5, P6).
00963 //! @return a new slot passing six arguments of type P1, P2, P3, P4, P5 and P6, and returning a value of type R.
00964 //!
00965 //! <BR>If the returned slot is connected to a signal it doesn't have to be
00966 //! unreferenced. The signal it's connected to will unreference the slot when
00967 //! it is destroyed. Otherwise the slot must be unreferenced by calling unref().
00968 
00969 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00970 inline Slot6<R, P1, P2, P3, P4, P5, P6>*
00971 slot(R (*function)(P1, P2, P3, P4, P5, P6))
00972 {
00973     return new FunctionSlot6<R, P1, P2, P3, P4, P5, P6>(function);
00974 }
00975 
00976 //! @class MethodSlot6
00977 //! @brief A slot template for methods in a class of type T taking six arguments of type P1, P2, P3, P4, P5 and P6,
00978 //! and returning a value of type R.
00979 
00980 template <typename T, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00981 class MethodSlot6 : public Slot6<R, P1, P2, P3, P4, P5, P6>
00982 {
00983     typedef R (T::*PMF)(P1, P2, P3, P4, P5, P6);
00984     PMF pmf;
00985     T *t;
00986     
00987 public:
00988     MethodSlot6(T *object, PMF function) : pmf(function), t(object) {}
00989     //!< Construct a new method slot for a class member function.
00990     //!< @param object - a pointer to an object of type T.
00991     //!< @param function - a class method with the signature R (T::*PMF)(P1, P2, P3, P4, P5, P6).
00992 
00993     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) const { return (t->*pmf)(p1, p2, p3, p4, p5, p6); }
00994     //!< Calls the class method connected to this slot passing it arguments p1, p2, p3, p4, p5 and p6.
00995     //!< @return a value of type R returned by the called method.
00996 };
00997 
00998 //! Overloaded slot factory function.
00999 //! @param object - a reference to a pointer to an object of type T1.
01000 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4, P5, P6).
01001 //! @return a new slot passing six arguments of type P1, P2, P3, P4, P5 and P6, and returning a value of type R.
01002 //!
01003 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
01004 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
01005 //! will unreference the slot when it is destroyed. Otherwise the slot must be
01006 //! unreferenced by calling unref().
01007 
01008 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
01009 inline Slot6<R, P1, P2, P3, P4, P5, P6>*
01010 slot(T1* &object, R (T2::*function)(P1, P2, P3, P4, P5, P6))
01011 {
01012     return new MethodSlot6<T2, R, P1, P2, P3, P4, P5, P6>(object, function);
01013 }
01014 
01015 //! Overloaded slot factory function.
01016 //! @param object - a reference to a const pointer to an object of type T1 (e.g. this).
01017 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4, P5, P6).
01018 //! @return a new slot passing six arguments of type P1, P2, P3, P4, P5 and P6, and returning a value of type R.
01019 //!
01020 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
01021 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
01022 //! will unreference the slot when it is destroyed. Otherwise the slot must be
01023 //! unreferenced by calling unref().
01024 
01025 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
01026 inline Slot6<R, P1, P2, P3, P4, P5, P6>*
01027 slot(T1* const &object, R (T2::*function)(P1, P2, P3, P4, P5, P6))
01028 {
01029     return new MethodSlot6<T2, R, P1, P2, P3, P4, P5, P6>(object, function);
01030 }
01031 
01032 //! Overloaded slot factory function.
01033 //! @param object - a reference to an object of type T1.
01034 //! @param function - a class method with the signature R (T2::*function)(P1, P2, P3, P4, P5, P6).
01035 //! @return a new slot passing six arguments of type P1, P2, P3, P4, P5 and P6, and returning a value of type R.
01036 //!
01037 //! <BR>T1 can be the same object type as T2. If the returned slot is connected
01038 //! to a signal it doesn't have to be unreferenced. The signal it's connected to
01039 //! will unreference the slot when it is destroyed. Otherwise the slot must be
01040 //! unreferenced by calling unref().
01041 
01042 template <typename T1, typename T2, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
01043 inline Slot6<R, P1, P2, P3, P4, P5, P6>*
01044 slot(T1& object, R (T2::*function)(P1, P2, P3, P4, P5, P6))
01045 {
01046     return new MethodSlot6<T2, R, P1, P2, P3, P4, P5, P6>(&object, function);
01047 }
01048 
01049 /*  SignalSlot6
01050  */
01051 
01052 template <typename T, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
01053 class SignalSlot6 : public Slot6<R, P1, P2, P3, P4, P5, P6>
01054 {
01055     typedef R (*PF)(void*, P1, P2, P3, P4, P5, P6);
01056     PF pf;
01057     T *t;
01058     
01059 public:
01060     SignalSlot6(T *signal, PF function) : pf(function), t(signal) {} 
01061 
01062     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) const { return (*pf)(t, p1, p2, p3, p4, p5, p6); }
01063 };
01064 
01065 //! @}
01066 
01067 /** @} */
01068 
01069 } // namespace scim
01070 
01071 #endif //__SCIM_SLOT_H
01072 
01073 /*
01074 vi:ts=4:nowrap:ai:expandtab
01075 */

Generated on Fri May 7 17:27:25 2004 for scim by doxygen 1.3.6