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

scim_bind.h

Go to the documentation of this file.
00001 /**
00002  * @file scim_bind.h
00003  * @brief Binding adapters.
00004  * 
00005  * A binding adaptor is an object that allows you to convert between slot types.
00006  * Usually you wont use a BoundSlot directly but instead call the bind() factory
00007  * function (similiar to the slot() factory function) which will create an
00008  * appropriate bound slot for you, depending on the parameters passed.
00009  *
00010  * Most code of this file are came from Inti project.
00011  */
00012 
00013 /*
00014  * Smart Common Input Method
00015  * 
00016  * Copyright (c) 2004 James Su <suzhe@turbolinux.com.cn>
00017  * Copyright (c) 2003 James Su <suzhe@turbolinux.com.cn>
00018  * Copyright (c) 2002 James Su <suzhe@turbolinux.com.cn>
00019  * Copyright (c) 2002 The Inti Development Team.
00020  * Copyright (c) 2000 Red Hat, Inc.
00021  *
00022  *
00023  * This library is free software; you can redistribute it and/or
00024  * modify it under the terms of the GNU Lesser General Public
00025  * License as published by the Free Software Foundation; either
00026  * version 2 of the License, or (at your option) any later version.
00027  *
00028  * This library is distributed in the hope that it will be useful,
00029  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00030  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00031  * GNU Lesser General Public License for more details.
00032  *
00033  * You should have received a copy of the GNU Lesser General Public
00034  * License along with this program; if not, write to the
00035  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00036  * Boston, MA  02111-1307  USA
00037  *
00038  * $Id: scim_bind.h,v 1.7 2004/02/06 07:53:15 suzhe Exp $
00039  */
00040 
00041 
00042 #ifndef __SCIM_BOUND_SLOT_H
00043 #define __SCIM_BOUND_SLOT_H
00044 
00045 namespace scim {
00046 /**
00047  * @addtogroup SignalSlot
00048  * The classes for signal/slot mechanism.
00049  * @{
00050  */
00051 
00052 //! @name Bind functions returning a new BoundSlot.
00053 //! @{
00054 
00055 //! @class BoundSlot0_1 
00056 //! @brief Converts a slot taking one argument into a slot taking no arguments.
00057 
00058 template<typename R, typename P1>
00059 class BoundSlot0_1 : public Slot0<R>
00060 {
00061     Slot1<R, P1> *original_slot;
00062     P1 p;
00063 
00064 public:
00065     BoundSlot0_1(Slot1<R, P1> *slot, P1 p1) : original_slot(slot), p(p1) {}
00066     //!< Constructor.
00067     //!< @param slot - a pointer to a slot of type Slot1<R, P1>.
00068     //!< @param p1 - a bound argument of type P1
00069 
00070     virtual R call() const { return original_slot->call(p); }
00071     //!< Calls the original slot passing it the bound argument p as the last parameter.
00072 };
00073 
00074 //! Overloaded bind() factory function.
00075 //! @param s - a slot of type Slot1<R, P1>.
00076 //! @param p1 - a value of type P1.
00077 //! @return a new slot that stores the value p1.
00078 //!
00079 //! <BR>When then returned slot is called it calls the original slot <EM>s</EM>, passing
00080 //! it the arguments passed to it and the value <EM>p1</EM>, as the last parameter. If
00081 //! the returned slot is connected to a signal it doesn't have to be unreferenced. The
00082 //! signal it's connected to will unreference the slot when it is destroyed. Otherwise
00083 //! the slot must be unreferenced by calling unref().
00084 
00085 template<typename R, typename P1>
00086 inline Slot0<R>*
00087 bind(Slot1<R, P1> *s, P1 p1)
00088 {
00089     return new BoundSlot0_1<R, P1>(s, p1);
00090 }
00091 
00092 //! @class BoundSlot1_2
00093 //! @brief Converts a slot taking two arguments into a slot taking one argument.
00094 
00095 template<typename R, typename P1, typename P2>
00096 class BoundSlot1_2 : public Slot1<R, P1>
00097 {
00098     Slot2<R, P1, P2> *original_slot;
00099     P2 p;
00100 
00101 public:
00102     BoundSlot1_2(Slot2<R, P1, P2> *slot, P2 p2) : original_slot(slot), p(p2) {}
00103     //!< Constructor.
00104     //!< @param slot - a pointer to a slot of type Slot1<R, P1, P2>.
00105     //!< @param p2 - a bound argument of type P2
00106 
00107     virtual R call(P1 p1) const { return original_slot->call(p1, p); }
00108     //!< Calls the original slot passing it argument p1 and the bound argument p as the last parameter.
00109 };
00110 
00111 //! Overloaded bind() factory function.
00112 //! @param s - a slot of type Slot1<R, P1, P2>.
00113 //! @param p2 - a value of type P2.
00114 //! @return a new slot that stores the value p2.
00115 //!
00116 //! <BR>When then returned slot is called it calls the original slot <EM>s</EM>, passing
00117 //! it the arguments passed to it and the value <EM>p2</EM>, as the last parameter. If
00118 //! the returned slot is connected to a signal it doesn't have to be unreferenced. The
00119 //! signal it's connected to will unreference the slot when it is destroyed. Otherwise
00120 //! the slot must be unreferenced by calling unref().
00121 
00122 template<typename R, typename P1, typename P2>
00123 inline Slot1<R, P1>*
00124 bind(Slot2<R, P1, P2> *s, P2 p2)
00125 {
00126     return new BoundSlot1_2<R, P1, P2>(s, p2);
00127 }
00128 
00129 //! @class BoundSlot2_3
00130 //! @brief Converts a slot taking three arguments into a slot taking two arguments.
00131 
00132 template<typename R, typename P1, typename P2, typename P3>
00133 class BoundSlot2_3 : public Slot2<R, P1, P2>
00134 {
00135     Slot3<R, P1, P2, P3> *original_slot;
00136     P3 p;
00137 
00138 public:
00139     BoundSlot2_3(Slot3<R, P1, P2, P3> *slot, P3 p3) : original_slot(slot), p(p3) {}
00140     //!< Constructor.
00141     //!< @param slot - a pointer to a slot of type Slot1<R, P1, P2, P3>.
00142     //!< @param p3 - a bound argument of type P3
00143 
00144     virtual R call(P1 p1, P2 p2) const { return original_slot->call(p1, p2, p); }
00145     //!< Calls the original slot passing it arguments p1 and p2, and the bound argument p as the last parameter.
00146 };
00147  
00148 //! Overloaded bind() factory function.
00149 //! @param s - a slot of type Slot1<R, P1, P2, P3>.
00150 //! @param p3 - a value of type P3.
00151 //! @return a new slot that stores the value p3.
00152 //!
00153 //! <BR>When then returned slot is called it calls the original slot <EM>s</EM>, passing
00154 //! it the arguments passed to it and the value <EM>p3</EM>, as the last parameter. If
00155 //! the returned slot is connected to a signal it doesn't have to be unreferenced. The
00156 //! signal it's connected to will unreference the slot when it is destroyed. Otherwise
00157 //! the slot must be unreferenced by calling unref().
00158 
00159 template<typename R, typename P1, typename P2, typename P3>
00160 inline Slot2<R, P1, P2>*
00161 bind(Slot3<R, P1, P2, P3> *s, P3 p3)
00162 {
00163     return new BoundSlot2_3<R, P1, P2, P3>(s, p3);
00164 }
00165 
00166 //! @class BoundSlot3_4
00167 //! @brief Converts a slot taking four arguments into a slot taking three arguments.
00168 
00169 template<typename R, typename P1, typename P2, typename P3, typename P4>
00170 class BoundSlot3_4 : public Slot3<R, P1, P2, P3>
00171 {
00172     Slot4<R, P1, P2, P3, P4> *original_slot;
00173     P4 p;
00174 
00175 public:
00176     BoundSlot3_4(Slot4<R, P1, P2, P3, P4> *slot, P4 p4) : original_slot(slot), p(p4) {}
00177     //!< Constructor.
00178     //!< @param slot - a pointer to a slot of type Slot1<R, P1, P2, P3, P4>.
00179     //!< @param p4 - a bound argument of type P4
00180 
00181     virtual R call(P1 p1, P2 p2, P3 p3) const { return original_slot->call(p1, p2, p3, p); }
00182     //!< Calls the original slot passing it arguments p1, p2 and p3, and the bound argument p as the last parameter.
00183 };
00184  
00185 //! Overloaded bind() factory function.
00186 //! @param s - a slot of type Slot1<R, P1, P2, P3, P4>.
00187 //! @param p4 - a value of type P4.
00188 //! @return a new slot that stores the value p4.
00189 //!
00190 //! <BR>When then returned slot is called it calls the original slot <EM>s</EM>, passing
00191 //! it the arguments passed to it and the value <EM>p4</EM>, as the last parameter. If
00192 //! the returned slot is connected to a signal it doesn't have to be unreferenced. The
00193 //! signal it's connected to will unreference the slot when it is destroyed. Otherwise
00194 //! the slot must be unreferenced by calling unref().
00195 
00196 template<typename R, typename P1, typename P2, typename P3, typename P4>
00197 inline Slot3<R, P1, P2, P3>*
00198 bind(Slot4<R, P1, P2, P3, P4> *s, P4 p4)
00199 {
00200     return new BoundSlot3_4<R, P1, P2, P3, P4>(s, p4);
00201 }
00202 
00203 //! @class BoundSlot4_5
00204 //! @brief Converts a slot taking five arguments into a slot taking four arguments.
00205 
00206 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00207 class BoundSlot4_5 : public Slot4<R, P1, P2, P3, P4>
00208 {
00209     Slot5<R, P1, P2, P3, P4, P5> *original_slot;
00210     P5 p;
00211 
00212 public:
00213     BoundSlot4_5(Slot5<R, P1, P2, P3, P4, P5> *slot, P5 p5) : original_slot(slot), p(p5) {}
00214     //!< Constructor.
00215     //!< @param slot - a pointer to a slot of type Slot1<R, P1, P2, P3, P4, P5>.
00216     //!< @param p5 - a bound argument of type P5
00217 
00218     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4) const { return original_slot->call(p1, p2, p3, p4, p); }
00219     //!< Calls the original slot passing it arguments p1, p2, p3 and p4, and the bound argument p as the last parameter.
00220 };
00221  
00222 //! Overloaded bind() factory function.
00223 //! @param s - a slot of type Slot1<R, P1, P2, P3, P4, P5>.
00224 //! @param p5 - a value of type P5.
00225 //! @return a new slot that stores the value p5.
00226 //!
00227 //! <BR>When then returned slot is called it calls the original slot <EM>s</EM>, passing
00228 //! it the arguments passed to it and the value <EM>p5</EM>, as the last parameter. If
00229 //! the returned slot is connected to a signal it doesn't have to be unreferenced. The
00230 //! signal it's connected to will unreference the slot when it is destroyed. Otherwise
00231 //! the slot must be unreferenced by calling unref().
00232 
00233 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
00234 inline Slot4<R, P1, P2, P3, P4>*
00235 bind(Slot5<R, P1, P2, P3, P4, P5> *s, P5 p5)
00236 {
00237     return new BoundSlot4_5<R, P1, P2, P3, P4, P5>(s, p5);
00238 }
00239 
00240 //! @class BoundSlot5_6
00241 //! @brief Converts a slot taking six arguments into a slot taking five arguments.
00242 
00243 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00244 class BoundSlot5_6 : public Slot5<R, P1, P2, P3, P4, P5>
00245 {
00246     Slot6<R, P1, P2, P3, P4, P5, P6> *original_slot;
00247     P6 p;
00248 
00249 public:
00250     BoundSlot5_6(Slot6<R, P1, P2, P3, P4, P5, P6> *slot, P6 p6) : original_slot(slot), p(p6) {}
00251     //!< Constructor.
00252     //!< @param slot - a pointer to a slot of type Slot1<R, P1, P2, P3, P4, P5, P6>.
00253     //!< @param p6 - a bound argument of type P6
00254 
00255     virtual R call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const { return original_slot->call(p1, p2, p3, p4, p5, p); }
00256     //!< Calls the original slot passing it arguments p1, p2, p3, p4 and p5, and the bound argument p as the last parameter.
00257 };
00258  
00259 //! Overloaded bind() factory function.
00260 //! @param s - a slot of type Slot1<R, P1, P2, P3, P4, P5, P6>.
00261 //! @param p6 - a value of type P6.
00262 //! @return a new slot that stores the value p6.
00263 //!
00264 //! <BR>When then returned slot is called it calls the original slot <EM>s</EM>, passing
00265 //! it the arguments passed to it and the value <EM>p6</EM>, as the last parameter. If
00266 //! the returned slot is connected to a signal it doesn't have to be unreferenced. The
00267 //! signal it's connected to will unreference the slot when it is destroyed. Otherwise
00268 //! the slot must be unreferenced by calling unref().
00269 
00270 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00271 inline Slot5<R, P1, P2, P3, P4, P5>*
00272 bind(Slot6<R, P1, P2, P3, P4, P5, P6> *s, P6 p6)
00273 {
00274     return new BoundSlot5_6<R, P1, P2, P3, P4, P5, P6>(s, p6);
00275 }
00276 
00277 //! @}
00278 
00279 /** @} */
00280 
00281 } // namespace scim
00282 
00283 #endif //__SCIM_BOUND_SLOT_H
00284 
00285 /*
00286 vi:ts=4:nowrap:ai:expandtab
00287 */
00288 

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