Main Page - Header
Author: The Inti Development Team

Reference Manual

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

# signals.h

Go to the documentation of this file.

    00001 /*  Inti: Integrated Foundation Classes
    00002  *  Copyright (C) 2002 The Inti Development Team.
    00003  *  Copyright (C) 2000 Red Hat, Inc.
    00004  *
    00005  *  This program is free software; you can redistribute it and/or modify
    00006  *  it under the terms of the GNU General Public License as published by
    00007  *  the Free Software Foundation; either version 2 of the License, or
    00008  *  (at your option) any later version.
    00009  *
    00010  *  This program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013  *  GNU Library General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU Library General Public License
    00016  *  along with this program; if not, write to the Free Software
    00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00018  */
    00019
    00032
    00033 #ifndef INTI_G_SIGNALS_H
    00034 #define INTI_G_SIGNALS_H
    00035
    00036 #ifndef INTI_SLOT_H
    00037 #include <inti/slot.h>
    00038 #endif
    00039
    00040 #ifndef INTI_CONNECTION_H
    00041 #include <inti/connection.h>
    00042 #endif
    00043
    00044 #ifndef __GLIB_GOBJECT_H__
    00045 #include <glib-object.h>
    00046 #endif
    00047
    00048 namespace Inti {
    00049
    00050 namespace G {
    00051
    00052 class TypeInstance;
    00053
    00056
    00057 class SlotNode : public Node
    00058 {
    00059         SlotNode(GObject *object, const Slot *slot);
    00060         ~SlotNode();
    00061
    00062         GObject *object_;
    00063         unsigned long connect_id;
    00064
    00065 public:
    00066         static SlotNode* connect(TypeInstance *instance, const char *name, GCallback callback, const Slot *slot, bool after);
    00067
    00068         static void destroy(void *data);
    00069
    00070         virtual void block();
    00072
    00073         virtual void unblock();
    00075
    00076         virtual void disconnect();
    00078 };
    00079
    00082
    00083 class Signal
    00084 {
    00085         Signal(const Signal&);
    00086         Signal& operator=(const Signal&);
    00087
    00088         const char *const name_;
    00089
    00090 protected:
    00091         SlotNode* connect(TypeInstance *instance, GCallback callback, const Slot *slot, bool after) const;
    00092
    00093 public:
    00094         Signal(const char *name);
    00096
    00097         ~Signal();
    00099
    00100         const char* name() const;
    00102 };
    00103
    00108
    00109 template<typename ObjectType, typename SignalType>
    00110 class SignalProxy
    00111 {
    00112         ObjectType *const object_;
    00113         const SignalType *const signal_;
    00114
    00115 public:
    00116         typedef typename SignalType::SlotType SlotType;
    00117
    00118         SignalProxy(ObjectType *object, const SignalType *signal) : object_(object), signal_(signal)
    00119         {
    00120         }
    00122
    00123         Connection connect(const SlotType *slot, bool after = false) const
    00124         {
    00125                 return signal_->connect(object_, slot, after);
    00126         }
    00137 };
    00138
    00141
    00142 template<typename R>
    00143 class Signal0 : Signal
    00144 {
    00145 public:
    00146         typedef Slot0<R> SlotType;
    00148
    00149 private:
    00150         static R gtk_callback(void *data)
    00151         {
    00152                 SlotType *slot = dynamic_cast<SlotType*>(static_cast<Node*>(data)->slot());
    00153                 return slot->call();
    00154         }
    00155
    00156 public:
    00157         Signal0(const char *name) : Signal(name)
    00158         {
    00159         }
    00162
    00163         ~Signal0()
    00164         {
    00165         }
    00167
    00168         Connection connect(TypeInstance *instance, const SlotType *slot, bool after = false) const
    00169         {
    00170                 return Signal::connect(instance, (GCallback)gtk_callback, slot, after);
    00171         }
    00183 };
    00184
    00185
    00188
    00189 template <typename R, typename P1>
    00190 class Signal1 : public Signal
    00191 {
    00192 public:
    00193         typedef Slot1<R, P1> SlotType;
    00195
    00196 private:
    00197         static R gtk_callback(void *data, P1 p1)
    00198         {
    00199                 SlotType *slot = dynamic_cast<SlotType*>(static_cast<Node*>(data)->slot());
    00200                 return slot->call(p1);
    00201         }
    00202
    00203 public:
    00204         Signal1(const char *name) : Signal(name)
    00205         {
    00206         }
    00209
    00210         ~Signal1()
    00211         {
    00212         }
    00214
    00215         Connection connect(TypeInstance *instance, const SlotType *slot, bool after = false) const
    00216         {
    00217                 return Signal::connect(instance, (GCallback)gtk_callback, slot, after);
    00218         }
    00230 };
    00231
    00235
    00236 template <typename R, typename P1, typename P2>
    00237 class Signal2 : public Signal
    00238 {
    00239 public:
    00240         typedef Slot2<R, P1, P2> SlotType;
    00242
    00243 private:
    00244         static R gtk_callback(void *data, P1 p1, P2 p2)
    00245         {
    00246                 SlotType *slot = dynamic_cast<SlotType*>(static_cast<Node*>(data)->slot());
    00247                 return slot->call(p1, p2);
    00248         }
    00249
    00250 public:
    00251         Signal2(const char *name) : Signal(name)
    00252         {
    00253         }
    00256
    00257         ~Signal2()
    00258         {
    00259         }
    00261
    00262         Connection connect(TypeInstance *instance, const SlotType *slot, bool after = false) const
    00263         {
    00264                 return Signal::connect(instance, (GCallback)gtk_callback, slot, after);
    00265         }
    00277 };
    00278
    00282
    00283 template <typename R, typename P1, typename P2, typename P3>
    00284 class Signal3 : public Signal
    00285 {
    00286 public:
    00287         typedef Slot3<R, P1, P2, P3> SlotType;
    00289
    00290 private:
    00291         static R gtk_callback(void *data, P1 p1, P2 p2, P3 p3)
    00292         {
    00293                 SlotType *slot = dynamic_cast<SlotType*>(static_cast<Node*>(data)->slot());
    00294                 return slot->call(p1, p2, p3);
    00295         }
    00296
    00297 public:
    00298         Signal3(const char *name) : Signal(name)
    00299         {
    00300         }
    00303
    00304         ~Signal3()
    00305         {
    00306         }
    00308
    00309         Connection connect(TypeInstance *instance, const SlotType *slot, bool after = false) const
    00310         {
    00311                 return Signal::connect(instance, (GCallback)gtk_callback, slot, after);
    00312         }
    00324 };
    00325
    00329
    00330 template <typename R, typename P1, typename P2, typename P3, typename P4>
    00331 class Signal4 : public Signal
    00332 {
    00333 public:
    00334         typedef Slot4<R, P1, P2, P3, P4> SlotType;
    00336
    00337 private:
    00338         static R gtk_callback(void *data, P1 p1, P2 p2, P3 p3, P4 p4)
    00339         {
    00340                 SlotType *slot = dynamic_cast<SlotType*>(static_cast<Node*>(data)->slot());
    00341                 return slot->call(p1, p2, p3, p4);
    00342         }
    00343
    00344 public:
    00345         Signal4(const char *name) : Signal(name)
    00346         {
    00347         }
    00350
    00351         ~Signal4()
    00352         {
    00353         }
    00355
    00356         Connection connect(TypeInstance *instance, const SlotType *slot, bool after = false) const
    00357         {
    00358                 return Signal::connect(instance, (GCallback)gtk_callback, slot, after);
    00359         }
    00371 };
    00372
    00376
    00377 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
    00378 class Signal5 : public Signal
    00379 {
    00380 public:
    00381         typedef Slot5<R, P1, P2, P3, P4, P5> SlotType;
    00383
    00384 private:
    00385         static R gtk_callback(void *data, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
    00386         {
    00387                 SlotType *slot = dynamic_cast<SlotType*>(static_cast<Node*>(data)->slot());
    00388                 return slot->call(p1, p2, p3, p4, p5);
    00389         }
    00390
    00391 public:
    00392         Signal5(const char *name) : Signal(name)
    00393         {
    00394         }
    00397
    00398         ~Signal5()
    00399         {
    00400         }
    00402
    00403         Connection connect(TypeInstance *instance, const SlotType *slot, bool after = false) const
    00404         {
    00405                 return Signal::connect(instance, (GCallback)gtk_callback, slot, after);
    00406         }
    00418 };
    00419
    00423
    00424 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
    00425 class Signal6 : public Signal
    00426 {
    00427 public:
    00428         typedef Slot6<R, P1, P2, P3, P4, P5, P6> SlotType;
    00430
    00431 private:
    00432         static R gtk_callback(void *data, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
    00433         {
    00434                 SlotType *slot = dynamic_cast<SlotType*>(static_cast<Node*>(data)->slot());
    00435                 return slot->call(p1, p2, p3, p4, p5, p6);
    00436         }
    00437
    00438 public:
    00439         Signal6(const char *name) : Signal(name)
    00440         {
    00441         }
    00444
    00445         ~Signal6()
    00446         {
    00447         }
    00449
    00450         Connection connect(TypeInstance *instance, const SlotType *slot, bool after = false) const
    00451         {
    00452                 return Signal::connect(instance, (GCallback)gtk_callback, slot, after);
    00453         }
    00465 };
    00466
    00467 } // namespace G
    00468
    00469 } // namespace Inti
    00470
    00471 #endif // INTI_G_SIGNALS_H
    00472

Main Page - Footer