ROOT logo
// @(#)root/base:$Id: TQObject.h 22791 2008-03-20 15:33:49Z rdm $
// Author: Valeriy Onuchin & Fons Rademakers   15/10/2000

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TQObject
#define ROOT_TQObject

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// This is the ROOT implementation of the Qt object communication       //
// mechanism (see also http://www.troll.no/qt/metaobjects.html)         //
//                                                                      //
// Signals and slots are used for communication between objects.        //
// When an object has changed in some way that might be interesting     //
// for the outside world, it emits a signal to tell whoever is          //
// listening. All slots that are connected to this signal will be       //
// activated (called).  It is even possible to connect a signal         //
// directly to  another signal (this will emit the second signal        //
// immediately whenever the first is emitted.) There is no limitation   //
// on the number of slots that can be connected to a signal.            //
// The slots will be activated in the order they were connected         //
// to the signal. This mechanism allows objects to be easily reused,    //
// because the object that emits a signal does not need to know         //
// to what the signals are connected to.                                //
// Together, signals and slots make up a powerfull component            //
// programming mechanism.                                               //
//                                                                      //
// This implementation is provided by                                   //
// Valeriy Onuchin (onuchin@sirius.ihep.su).                            //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TString
#include "TString.h"
#endif

class TList;
class TObject;
class TQConnection;
class TClass;

class TQObject {

friend class TQConnection;

protected:
   TList   *fListOfSignals;        //! list of signals from this object
   TList   *fListOfConnections;    //! list of connections to this object
   Bool_t   fSignalsBlocked;       //! flag used for suppression of signals

   static Bool_t fgAllSignalsBlocked;  // flag used for suppression of all signals

   virtual void       *GetSender() { return this; }
   virtual const char *GetSenderClassName() const { return ""; }

   static Bool_t ConnectToClass(TQObject *sender,
                                const char *signal,
                                TClass *receiver_class,
                                void *receiver,
                                const char *slot);

   static Bool_t ConnectToClass(const char *sender_class,
                                const char *signal,
                                TClass *receiver_class,
                                void *receiver,
                                const char *slot);

   static Int_t CheckConnectArgs(TQObject *sender,
                                 TClass *sender_class, const char *signal,
                                 TClass *receiver_class, const char *slot);

private:
   TQObject(const TQObject& tqo);            // not implemented
   TQObject& operator=(const TQObject& tqo); // not implemented

public:
   TQObject();
   virtual ~TQObject();

   TList   *GetListOfClassSignals() const;
   TList   *GetListOfSignals() const { return fListOfSignals; }
   TList   *GetListOfConnections() const { return fListOfConnections; }

   Bool_t   AreSignalsBlocked() const { return fSignalsBlocked; }
   Bool_t   BlockSignals(Bool_t b)
            { Bool_t ret = fSignalsBlocked; fSignalsBlocked = b; return ret; }

   void  CollectClassSignalLists(TList& list, TClass* cls);

   void  EmitVA(const char *signal, Int_t nargs, ...);
   void  EmitVA(const char *signal, Int_t nargs, va_list va);
   void  Emit(const char *signal);
   void  Emit(const char *signal, Long_t *paramArr);
   void  Emit(const char *signal, const char *params);
   void  Emit(const char *signal, Double_t param);
   void  Emit(const char *signal, Long_t param);
   void  Emit(const char *signal, Long64_t param);
   void  Emit(const char *signal, Bool_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, Char_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, UChar_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, Short_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, UShort_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, Int_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, UInt_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, ULong_t param)
         { Emit(signal, (Long_t)param); }
   void  Emit(const char *signal, ULong64_t param)
         { Emit(signal, (Long64_t) param); }
   void  Emit(const char *signal, Float_t param)
         { Emit(signal, (Double_t)param); }

   Bool_t Connect(const char *signal,
                  const char *receiver_class,
                  void *receiver,
                  const char *slot);

   Bool_t Disconnect(const char *signal = 0,
                     void *receiver = 0,
                     const char *slot = 0);

   virtual void   HighPriority(const char *signal_name,
                               const char *slot_name = 0);

   virtual void   LowPriority(const char *signal_name,
                              const char *slot_name = 0);

   virtual Bool_t HasConnection(const char *signal_name) const;
   virtual Int_t  NumberOfSignals() const;
   virtual Int_t  NumberOfConnections() const;
   virtual void   Connected(const char * /*signal_name*/) { }
   virtual void   Disconnected(const char * /*signal_name*/) { }

   virtual void   Destroyed()
                  { Emit("Destroyed()"); }                 // *SIGNAL*
   virtual void   ChangedBy(const char *method)
                  { Emit("ChangedBy(char*)", method); }    // *SIGNAL*
   virtual void   Message(const char *msg)
                  { Emit("Message(char*)", msg); }         // *SIGNAL*

   static Bool_t  Connect(TQObject *sender,
                          const char *signal,
                          const char *receiver_class,
                          void *receiver,
                          const char *slot);

   static Bool_t  Connect(const char *sender_class,
                          const char *signal,
                          const char *receiver_class,
                          void *receiver,
                          const char *slot);

   static Bool_t  Disconnect(TQObject *sender,
                             const char *signal = 0,
                             void *receiver = 0,
                             const char *slot = 0);

   static Bool_t  Disconnect(const char *class_name,
                             const char *signal,
                             void *receiver = 0,
                             const char *slot = 0);

   static Bool_t  AreAllSignalsBlocked();
   static Bool_t  BlockAllSignals(Bool_t b);

   static void    LoadRQ_OBJECT();

   ClassDef(TQObject,1) //Base class for object communication mechanism
};


R__EXTERN void *gTQSender;   // the latest sender object

class TQObjSender : public TQObject {

protected:
   void    *fSender;        //delegation object
   TString  fSenderClass;   //class name of delegation object

   virtual void       *GetSender() { return fSender; }
   virtual const char *GetSenderClassName() const { return fSenderClass; }

private:
   TQObjSender(const TQObjSender&);            // not implemented
   TQObjSender& operator=(const TQObjSender&); // not implemented

public:
   TQObjSender() : TQObject(), fSender(0), fSenderClass() { }
   virtual ~TQObjSender() { Disconnect(); }

   virtual void SetSender(void *sender) { fSender = sender; }
   void SetSenderClassName(const char *sclass = "") { fSenderClass = sclass; }

   ClassDef(TQObjSender,0) //Used to "delegate" TQObject functionality
                           //to interpreted classes, see also RQ_OBJECT.h
};

// Global function which simplifies making connections in interpreted
// ROOT session
//
//  ConnectCINT      - connects to interpreter(CINT) command

extern Bool_t ConnectCINT(TQObject *sender, const char *signal,
                          const char *slot);

#ifdef G__DICTIONARY
// This include makes it possible to have a single connection
// from all objects of the same class but is only needed in
// the dictionary.
#include "TQClass.h"
#endif


//---- ClassImpQ macro ----------------------------------------------
//
// This macro used to correspond to the ClassImp macro and should be used
// for classes derived from TQObject instead of the ClassImp macro.
// This macro makes it possible to have a single connection from
// all objects of the same class.
// *** It is now obsolete ***

#define ClassImpQ(name) \
   ClassImp(name)

#endif
 TQObject.h:1
 TQObject.h:2
 TQObject.h:3
 TQObject.h:4
 TQObject.h:5
 TQObject.h:6
 TQObject.h:7
 TQObject.h:8
 TQObject.h:9
 TQObject.h:10
 TQObject.h:11
 TQObject.h:12
 TQObject.h:13
 TQObject.h:14
 TQObject.h:15
 TQObject.h:16
 TQObject.h:17
 TQObject.h:18
 TQObject.h:19
 TQObject.h:20
 TQObject.h:21
 TQObject.h:22
 TQObject.h:23
 TQObject.h:24
 TQObject.h:25
 TQObject.h:26
 TQObject.h:27
 TQObject.h:28
 TQObject.h:29
 TQObject.h:30
 TQObject.h:31
 TQObject.h:32
 TQObject.h:33
 TQObject.h:34
 TQObject.h:35
 TQObject.h:36
 TQObject.h:37
 TQObject.h:38
 TQObject.h:39
 TQObject.h:40
 TQObject.h:41
 TQObject.h:42
 TQObject.h:43
 TQObject.h:44
 TQObject.h:45
 TQObject.h:46
 TQObject.h:47
 TQObject.h:48
 TQObject.h:49
 TQObject.h:50
 TQObject.h:51
 TQObject.h:52
 TQObject.h:53
 TQObject.h:54
 TQObject.h:55
 TQObject.h:56
 TQObject.h:57
 TQObject.h:58
 TQObject.h:59
 TQObject.h:60
 TQObject.h:61
 TQObject.h:62
 TQObject.h:63
 TQObject.h:64
 TQObject.h:65
 TQObject.h:66
 TQObject.h:67
 TQObject.h:68
 TQObject.h:69
 TQObject.h:70
 TQObject.h:71
 TQObject.h:72
 TQObject.h:73
 TQObject.h:74
 TQObject.h:75
 TQObject.h:76
 TQObject.h:77
 TQObject.h:78
 TQObject.h:79
 TQObject.h:80
 TQObject.h:81
 TQObject.h:82
 TQObject.h:83
 TQObject.h:84
 TQObject.h:85
 TQObject.h:86
 TQObject.h:87
 TQObject.h:88
 TQObject.h:89
 TQObject.h:90
 TQObject.h:91
 TQObject.h:92
 TQObject.h:93
 TQObject.h:94
 TQObject.h:95
 TQObject.h:96
 TQObject.h:97
 TQObject.h:98
 TQObject.h:99
 TQObject.h:100
 TQObject.h:101
 TQObject.h:102
 TQObject.h:103
 TQObject.h:104
 TQObject.h:105
 TQObject.h:106
 TQObject.h:107
 TQObject.h:108
 TQObject.h:109
 TQObject.h:110
 TQObject.h:111
 TQObject.h:112
 TQObject.h:113
 TQObject.h:114
 TQObject.h:115
 TQObject.h:116
 TQObject.h:117
 TQObject.h:118
 TQObject.h:119
 TQObject.h:120
 TQObject.h:121
 TQObject.h:122
 TQObject.h:123
 TQObject.h:124
 TQObject.h:125
 TQObject.h:126
 TQObject.h:127
 TQObject.h:128
 TQObject.h:129
 TQObject.h:130
 TQObject.h:131
 TQObject.h:132
 TQObject.h:133
 TQObject.h:134
 TQObject.h:135
 TQObject.h:136
 TQObject.h:137
 TQObject.h:138
 TQObject.h:139
 TQObject.h:140
 TQObject.h:141
 TQObject.h:142
 TQObject.h:143
 TQObject.h:144
 TQObject.h:145
 TQObject.h:146
 TQObject.h:147
 TQObject.h:148
 TQObject.h:149
 TQObject.h:150
 TQObject.h:151
 TQObject.h:152
 TQObject.h:153
 TQObject.h:154
 TQObject.h:155
 TQObject.h:156
 TQObject.h:157
 TQObject.h:158
 TQObject.h:159
 TQObject.h:160
 TQObject.h:161
 TQObject.h:162
 TQObject.h:163
 TQObject.h:164
 TQObject.h:165
 TQObject.h:166
 TQObject.h:167
 TQObject.h:168
 TQObject.h:169
 TQObject.h:170
 TQObject.h:171
 TQObject.h:172
 TQObject.h:173
 TQObject.h:174
 TQObject.h:175
 TQObject.h:176
 TQObject.h:177
 TQObject.h:178
 TQObject.h:179
 TQObject.h:180
 TQObject.h:181
 TQObject.h:182
 TQObject.h:183
 TQObject.h:184
 TQObject.h:185
 TQObject.h:186
 TQObject.h:187
 TQObject.h:188
 TQObject.h:189
 TQObject.h:190
 TQObject.h:191
 TQObject.h:192
 TQObject.h:193
 TQObject.h:194
 TQObject.h:195
 TQObject.h:196
 TQObject.h:197
 TQObject.h:198
 TQObject.h:199
 TQObject.h:200
 TQObject.h:201
 TQObject.h:202
 TQObject.h:203
 TQObject.h:204
 TQObject.h:205
 TQObject.h:206
 TQObject.h:207
 TQObject.h:208
 TQObject.h:209
 TQObject.h:210
 TQObject.h:211
 TQObject.h:212
 TQObject.h:213
 TQObject.h:214
 TQObject.h:215
 TQObject.h:216
 TQObject.h:217
 TQObject.h:218
 TQObject.h:219
 TQObject.h:220
 TQObject.h:221
 TQObject.h:222
 TQObject.h:223
 TQObject.h:224
 TQObject.h:225
 TQObject.h:226
 TQObject.h:227
 TQObject.h:228
 TQObject.h:229
 TQObject.h:230
 TQObject.h:231
 TQObject.h:232
 TQObject.h:233
 TQObject.h:234
 TQObject.h:235
 TQObject.h:236
 TQObject.h:237
 TQObject.h:238