GFC Logo GFC Title Logo
Reference Manual
Main Page  |  Namespace List  |  Alphabetical List  |  Class List  |  File List

signals.hh

Go to the documentation of this file.
00001 /* GFC-Core: GTK+ Foundation Classes (Core Library) 00002 * Copyright (C) 2003-2004 The GFC Development Team. 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00031 00032 #ifndef GFC_G_SIGNALS_HH 00033 #define GFC_G_SIGNALS_HH 00034 00035 #ifndef SIGCXX_SIGCXX_H 00036 #include <sigc++/sigc++.h> 00037 #endif 00038 00039 #ifndef __G_OBJECT_H__ 00040 #include <glib-object.h> 00041 #endif 00042 00043 namespace GFC { 00044 00045 namespace G { 00046 00047 typedef sigc::nil nil; 00048 00049 class TypeInstance; 00050 00053 00054 class SignalBase : public sigc::signal_base 00055 { 00056 SignalBase(const SignalBase&); 00057 SignalBase& operator=(const SignalBase&); 00058 00059 const char *const name_; 00060 const GCallback callback_; 00061 00062 protected: 00063 typedef sigc::slot_base SlotBase; 00065 00066 SignalBase(const char *name, GCallback callback); 00070 00071 ~SignalBase(); 00073 00074 void connect(TypeInstance *instance, const SlotBase& slot, const char *detail, bool after) const; 00081 00082 public: 00083 const char* name() const { return name_; } 00085 00086 void stop_emission(TypeInstance *instance); 00093 }; 00094 00099 00100 template<typename ObjectType, typename SignalType> 00101 class SignalProxy 00102 { 00103 ObjectType *const object_; 00104 const SignalType *const signal_; 00105 const char *const detail_; 00106 00107 public: 00108 typedef typename SignalType::SlotType SlotType; 00110 00111 SignalProxy(ObjectType *object, const SignalType *signal, const char *detail = 0) 00112 : object_(object), signal_(signal), detail_(detail) 00113 { 00114 } 00126 00127 sigc::connection connect(const SlotType& slot, bool after = false) const 00128 { 00129 return signal_->connect(object_, slot, detail_, after); 00130 } 00141 00142 template<typename MethodObjectType, typename MethodType> 00143 sigc::connection connect(MethodObjectType *object, MethodType method, bool after = false) const 00144 { 00145 return signal_->connect(object_, SlotType(object, method), detail_, after); 00146 } 00160 00161 template<typename FunctionType> 00162 sigc::connection connect(FunctionType function, bool after = false) const 00163 { 00164 return signal_->connect(object_, SlotType(function), detail_, after); 00165 } 00178 }; 00179 00182 00183 template <class R> 00184 class Signal0 : public SignalBase 00185 { 00186 Signal0(const Signal0&); 00187 Signal0& operator=(const Signal0&); 00188 00189 public: 00190 typedef sigc::slot<R> SlotType; 00193 00194 Signal0(const char *name, GCallback callback) : SignalBase(name, callback) 00195 { 00196 } 00200 00201 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00202 const char *detail = 0, bool after = false) const 00203 { 00204 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00205 return sigc::connection(const_cast<SlotType&>(slot)); 00206 } 00219 }; 00220 00223 00224 template <typename R, typename P1> 00225 class Signal1 : public SignalBase 00226 { 00227 Signal1(const Signal1&); 00228 Signal1& operator=(const Signal1&); 00229 00230 public: 00231 typedef sigc::slot<R, P1> SlotType; 00234 00235 Signal1(const char *name, GCallback callback) : SignalBase(name, callback) 00236 { 00237 } 00241 00242 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00243 const char *detail = 0, bool after = false) const 00244 { 00245 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00246 return sigc::connection(const_cast<SlotType&>(slot)); 00247 } 00260 }; 00261 00265 00266 template <typename R, typename P1, typename P2> 00267 class Signal2 : public SignalBase 00268 { 00269 Signal2(const Signal2&); 00270 Signal2& operator=(const Signal2&); 00271 00272 public: 00273 typedef sigc::slot<R, P1, P2> SlotType; 00276 00277 Signal2(const char *name, GCallback callback) : SignalBase(name, callback) 00278 { 00279 } 00283 00284 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00285 const char *detail = 0, bool after = false) const 00286 { 00287 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00288 return sigc::connection(const_cast<SlotType&>(slot)); 00289 } 00302 }; 00303 00307 00308 template <typename R, typename P1, typename P2, typename P3> 00309 class Signal3 : public SignalBase 00310 { 00311 Signal3(const Signal3&); 00312 Signal3& operator=(const Signal3&); 00313 00314 public: 00315 typedef sigc::slot<R, P1, P2, P3> SlotType; 00318 00319 Signal3(const char *name, GCallback callback) : SignalBase(name, callback) 00320 { 00321 } 00325 00326 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00327 const char *detail = 0, bool after = false) const 00328 { 00329 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00330 return sigc::connection(const_cast<SlotType&>(slot)); 00331 } 00344 }; 00345 00349 00350 template <typename R, typename P1, typename P2, typename P3, typename P4> 00351 class Signal4 : public SignalBase 00352 { 00353 Signal4(const Signal4&); 00354 Signal4& operator=(const Signal4&); 00355 00356 public: 00357 typedef sigc::slot<R, P1, P2, P3, P4> SlotType; 00360 00361 Signal4(const char *name, GCallback callback) : SignalBase(name, callback) 00362 { 00363 } 00367 00368 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00369 const char *detail = 0, bool after = false) const 00370 { 00371 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00372 return sigc::connection(const_cast<SlotType&>(slot)); 00373 } 00386 }; 00387 00391 00392 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 00393 class Signal5 : public SignalBase 00394 { 00395 Signal5(const Signal5&); 00396 Signal5& operator=(const Signal5&); 00397 00398 public: 00399 typedef sigc::slot<R, P1, P2, P3, P4, P5> SlotType; 00402 00403 Signal5(const char *name, GCallback callback) : SignalBase(name, callback) 00404 { 00405 } 00409 00410 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00411 const char *detail = 0, bool after = false) const 00412 { 00413 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00414 return sigc::connection(const_cast<SlotType&>(slot)); 00415 } 00428 }; 00429 00433 00434 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 00435 class Signal6 : public SignalBase 00436 { 00437 Signal6(const Signal6&); 00438 Signal6& operator=(const Signal6&); 00439 00440 public: 00441 typedef sigc::slot<R, P1, P2, P3, P4, P5, P6> SlotType; 00444 00445 Signal6(const char *name, GCallback callback) : SignalBase(name, callback) 00446 { 00447 } 00451 00452 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00453 const char *detail = 0, bool after = false) const 00454 { 00455 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00456 return sigc::connection(const_cast<SlotType&>(slot)); 00457 } 00470 }; 00471 00475 00476 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> 00477 class Signal7 : public SignalBase 00478 { 00479 Signal7(const Signal7&); 00480 Signal7& operator=(const Signal7&); 00481 00482 public: 00483 typedef sigc::slot<R, P1, P2, P3, P4, P5, P6, P7> SlotType; 00486 00487 Signal7(const char *name, GCallback callback) : SignalBase(name, callback) 00488 { 00489 } 00493 00494 sigc::connection connect(TypeInstance *instance, const SlotType& slot, 00495 const char *detail = 0, bool after = false) const 00496 { 00497 SignalBase::connect(instance, static_cast<const SlotBase&>(slot), detail, after); 00498 return sigc::connection(const_cast<SlotType&>(slot)); 00499 } 00512 }; 00513 00520 00521 template<typename R, typename P1 = nil, typename P2 = nil, typename P3 = nil, typename P4 = nil, typename P5 = nil, typename P6 = nil, typename P7 = nil> 00522 class Signal : public Signal7<R, P1, P2, P3, P4, P5, P6, P7> 00523 { 00524 public: 00525 Signal(const char *name, GCallback callback) 00526 : Signal7<R, P1, P2, P3, P4, P5, P6, P7>(name, callback) 00527 { 00528 } 00529 }; 00530 00531 // A convenience template wrapper for the numbered Signal#<> templates. 00532 // This is the template specialization of the unnumbered Signal<> template for 0 arguments. 00533 00534 template<typename R> 00535 class Signal<R> : public Signal0<R> 00536 { 00537 public: 00538 Signal(const char *name, GCallback callback) 00539 : Signal0<R>(name, callback) 00540 { 00541 } 00542 }; 00543 00544 // A convenience template wrapper for the numbered Signal#<> templates. 00545 // This is the template specialization of the unnumbered Signal<> template for 1 arguments. 00546 00547 template<typename R, typename P1> 00548 class Signal<R, P1> : public Signal1<R, P1> 00549 { 00550 public: 00551 Signal(const char *name, GCallback callback) 00552 : Signal1<R, P1>(name, callback) 00553 { 00554 } 00555 }; 00556 00557 // A convenience template wrapper for the numbered Signal#<> templates. 00558 // This is the template specialization of the unnumbered Signal<> template for 2 arguments. 00559 00560 template<typename R, typename P1, typename P2> 00561 class Signal<R, P1, P2> : public Signal2<R, P1, P2> 00562 { 00563 public: 00564 Signal(const char *name, GCallback callback) 00565 : Signal2<R, P1, P2>(name, callback) 00566 { 00567 } 00568 }; 00569 00570 // A convenience template wrapper for the numbered Signal#<> templates. 00571 // This is the template specialization of the unnumbered Signal<> template for 3 arguments. 00572 00573 template<typename R, typename P1, typename P2, typename P3> 00574 class Signal<R, P1, P2, P3> : public Signal3<R, P1, P2, P3> 00575 { 00576 public: 00577 Signal(const char *name, GCallback callback) 00578 : Signal3<R, P1, P2, P3>(name, callback) 00579 { 00580 } 00581 }; 00582 00583 // A convenience template wrapper for the numbered Signal#<> templates. 00584 // This is the template specialization of the unnumbered Signal<> template for 4 arguments. 00585 00586 template<typename R, typename P1, typename P2, typename P3, typename P4> 00587 class Signal<R, P1, P2, P3, P4> : public Signal4<R, P1, P2, P3, P4> 00588 { 00589 public: 00590 Signal(const char *name, GCallback callback) 00591 : Signal4<R, P1, P2, P3, P4>(name, callback) 00592 { 00593 } 00594 }; 00595 00596 // A convenience template wrapper for the numbered Signal#<> templates. 00597 // This is the template specialization of the unnumbered Signal<> template for 5 arguments. 00598 00599 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 00600 class Signal<R, P1, P2, P3, P4, P5> : public Signal5<R, P1, P2, P3, P4, P5> 00601 { 00602 Signal(const char *name, GCallback callback) 00603 : Signal5<R, P1, P2, P3, P4, P5>(name, callback) 00604 { 00605 } 00606 }; 00607 00608 // A convenience template wrapper for the numbered Signal#<> templates. 00609 // This is the template specialization of the unnumbered Signal<> template for 6 arguments. 00610 00611 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 00612 class Signal<R, P1, P2, P3, P4, P5, P6> : public Signal6<R, P1, P2, P3, P4, P5, P6> 00613 { 00614 public: 00615 Signal(const char *name, GCallback callback) 00616 : Signal6<R, P1, P2, P3, P4, P5, P6>(name, callback) 00617 { 00618 } 00619 }; 00620 00621 } // namespace G 00622 00623 } // namespace GFC 00624 00625 #endif // GFC_G_SIGNALS_HH 00626

Generated on Tue Aug 24 00:04:56 2004 for GFC-Core by doxygen 1.3.8