ROOT  6.06/09
Reference Guide
TQObject.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Valeriy Onuchin & Fons Rademakers 15/10/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TQObject
13 #define ROOT_TQObject
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // This is the ROOT implementation of the Qt object communication //
18 // mechanism (see also http://www.troll.no/qt/metaobjects.html) //
19 // //
20 // Signals and slots are used for communication between objects. //
21 // When an object has changed in some way that might be interesting //
22 // for the outside world, it emits a signal to tell whoever is //
23 // listening. All slots that are connected to this signal will be //
24 // activated (called). It is even possible to connect a signal //
25 // directly to another signal (this will emit the second signal //
26 // immediately whenever the first is emitted.) There is no limitation //
27 // on the number of slots that can be connected to a signal. //
28 // The slots will be activated in the order they were connected //
29 // to the signal. This mechanism allows objects to be easily reused, //
30 // because the object that emits a signal does not need to know //
31 // to what the signals are connected to. //
32 // Together, signals and slots make up a powerfull component //
33 // programming mechanism. //
34 // //
35 // This implementation is provided by //
36 // Valeriy Onuchin (onuchin@sirius.ihep.su). //
37 // //
38 //////////////////////////////////////////////////////////////////////////
39 
40 #ifndef ROOT_TString
41 #include "TString.h"
42 #endif
43 #ifndef ROOT_TList
44 #include "TList.h"
45 #endif
46 
47 class TObject;
48 class TQConnection;
49 class TClass;
50 
51 R__EXTERN void *gTQSender; // the latest sender object
52 
53 class TQObject {
54 
55 friend class TQConnection;
56 
57 protected:
58  TList *fListOfSignals; //! list of signals from this object
59  TList *fListOfConnections; //! list of connections to this object
60  Bool_t fSignalsBlocked; //! flag used for suppression of signals
61 
62  static Bool_t fgAllSignalsBlocked; // flag used for suppression of all signals
63 
64  virtual void *GetSender() { return this; }
65  virtual const char *GetSenderClassName() const { return ""; }
66 
67  static Bool_t ConnectToClass(TQObject *sender,
68  const char *signal,
69  TClass *receiver_class,
70  void *receiver,
71  const char *slot);
72 
73  static Bool_t ConnectToClass(const char *sender_class,
74  const char *signal,
75  TClass *receiver_class,
76  void *receiver,
77  const char *slot);
78 
79  static Int_t CheckConnectArgs(TQObject *sender,
80  TClass *sender_class, const char *signal,
81  TClass *receiver_class, const char *slot);
82 
83  static TString CompressName(const char *method_name);
84 
85 private:
86  TQObject(const TQObject& tqo); // not implemented
87  TQObject& operator=(const TQObject& tqo); // not implemented
88 
89 public:
90  TQObject();
91  virtual ~TQObject();
92 
94  TList *GetListOfSignals() const { return fListOfSignals; }
96 
99  { Bool_t ret = fSignalsBlocked; fSignalsBlocked = b; return ret; }
100 
101  void CollectClassSignalLists(TList& list, TClass* cls);
102 
103  template <typename... T> void EmitVA(const char *signal_name, Int_t /* nargs */, const T&... params);
104  // void EmitVA(const char *signal, Int_t nargs, ...);
105  void EmitVA(const char *signal, Int_t nargs, va_list va) = delete;
106  void Emit(const char *signal);
107  void Emit(const char *signal, Long_t *paramArr);
108  void Emit(const char *signal, const char *params);
109  void Emit(const char *signal, Double_t param);
110  void Emit(const char *signal, Long_t param);
111  void Emit(const char *signal, Long64_t param);
112  void Emit(const char *signal, Bool_t param)
113  { Emit(signal, (Long_t)param); }
114  void Emit(const char *signal, Char_t param)
115  { Emit(signal, (Long_t)param); }
116  void Emit(const char *signal, UChar_t param)
117  { Emit(signal, (Long_t)param); }
118  void Emit(const char *signal, Short_t param)
119  { Emit(signal, (Long_t)param); }
120  void Emit(const char *signal, UShort_t param)
121  { Emit(signal, (Long_t)param); }
122  void Emit(const char *signal, Int_t param)
123  { Emit(signal, (Long_t)param); }
124  void Emit(const char *signal, UInt_t param)
125  { Emit(signal, (Long_t)param); }
126  void Emit(const char *signal, ULong_t param)
127  { Emit(signal, (Long_t)param); }
128  void Emit(const char *signal, ULong64_t param)
129  { Emit(signal, (Long64_t) param); }
130  void Emit(const char *signal, Float_t param)
131  { Emit(signal, (Double_t)param); }
132 
133  Bool_t Connect(const char *signal,
134  const char *receiver_class,
135  void *receiver,
136  const char *slot);
137 
138  Bool_t Disconnect(const char *signal = 0,
139  void *receiver = 0,
140  const char *slot = 0);
141 
142  virtual void HighPriority(const char *signal_name,
143  const char *slot_name = 0);
144 
145  virtual void LowPriority(const char *signal_name,
146  const char *slot_name = 0);
147 
148  virtual Bool_t HasConnection(const char *signal_name) const;
149  virtual Int_t NumberOfSignals() const;
150  virtual Int_t NumberOfConnections() const;
151  virtual void Connected(const char * /*signal_name*/) { }
152  virtual void Disconnected(const char * /*signal_name*/) { }
153 
154  virtual void Destroyed()
155  { Emit("Destroyed()"); } // *SIGNAL*
156  virtual void ChangedBy(const char *method)
157  { Emit("ChangedBy(char*)", method); } // *SIGNAL*
158  virtual void Message(const char *msg)
159  { Emit("Message(char*)", msg); } // *SIGNAL*
160 
161  static Bool_t Connect(TQObject *sender,
162  const char *signal,
163  const char *receiver_class,
164  void *receiver,
165  const char *slot);
166 
167  static Bool_t Connect(const char *sender_class,
168  const char *signal,
169  const char *receiver_class,
170  void *receiver,
171  const char *slot);
172 
173  static Bool_t Disconnect(TQObject *sender,
174  const char *signal = 0,
175  void *receiver = 0,
176  const char *slot = 0);
177 
178  static Bool_t Disconnect(const char *class_name,
179  const char *signal,
180  void *receiver = 0,
181  const char *slot = 0);
182 
183  static Bool_t AreAllSignalsBlocked();
184  static Bool_t BlockAllSignals(Bool_t b);
185 
186  ClassDef(TQObject,1) //Base class for object communication mechanism
187 };
188 
189 
190 class TQObjSender : public TQObject {
191 
192 protected:
193  void *fSender; //delegation object
194  TString fSenderClass; //class name of delegation object
195 
196  virtual void *GetSender() { return fSender; }
197  virtual const char *GetSenderClassName() const { return fSenderClass; }
198 
199 private:
200  TQObjSender(const TQObjSender&); // not implemented
201  TQObjSender& operator=(const TQObjSender&); // not implemented
202 
203 public:
204  TQObjSender() : TQObject(), fSender(0), fSenderClass() { }
205  virtual ~TQObjSender() { Disconnect(); }
206 
207  virtual void SetSender(void *sender) { fSender = sender; }
208  void SetSenderClassName(const char *sclass = "") { fSenderClass = sclass; }
209 
210  ClassDef(TQObjSender,0) //Used to "delegate" TQObject functionality
211  //to interpreted classes, see also RQ_OBJECT.h
212 };
213 
214 #ifndef ROOT_TQConnection
215 #include "TQObjectEmitVA.h"
216 #endif
217 
218 // Global function which simplifies making connections in interpreted
219 // ROOT session
220 //
221 // ConnectCINT - connects to interpreter(CINT) command
222 
223 extern Bool_t ConnectCINT(TQObject *sender, const char *signal,
224  const char *slot);
225 
226 #ifdef G__DICTIONARY
227 // This include makes it possible to have a single connection
228 // from all objects of the same class but is only needed in
229 // the dictionary.
230 #ifndef ROOT_TQClass
231 #include "TQClass.h"
232 #endif
233 #endif
234 
235 
236 //---- ClassImpQ macro ----------------------------------------------
237 //
238 // This macro used to correspond to the ClassImp macro and should be used
239 // for classes derived from TQObject instead of the ClassImp macro.
240 // This macro makes it possible to have a single connection from
241 // all objects of the same class.
242 // *** It is now obsolete ***
243 
244 #define ClassImpQ(name) \
245  ClassImp(name)
246 
247 #endif
Bool_t ConnectCINT(TQObject *sender, const char *signal, const char *slot)
Global function which simplifies making connection in interpreted ROOT session.
Definition: TQObject.cxx:1335
TQObjSender & operator=(const TQObjSender &)
static Bool_t BlockAllSignals(Bool_t b)
Block or unblock all signals. Returns the previous block status.
Definition: TQObject.cxx:1323
TQObject()
TQObject Constructor.
Definition: TQObject.cxx:391
virtual void * GetSender()
Definition: TQObject.h:196
long long Long64_t
Definition: RtypesCore.h:69
static Int_t CheckConnectArgs(TQObject *sender, TClass *sender_class, const char *signal, TClass *receiver_class, const char *slot)
Checking of consitency of sender/receiver methods/arguments.
Definition: TQObject.cxx:179
void Emit(const char *signal, Float_t param)
Definition: TQObject.h:130
void Emit(const char *signal, Char_t param)
Definition: TQObject.h:114
float Float_t
Definition: RtypesCore.h:53
virtual void * GetSender()
Definition: TQObject.h:64
R__EXTERN void * gTQSender
Definition: TQObject.h:49
double T(double x)
Definition: ChebyshevPol.h:34
void EmitVA(const char *signal_name, Int_t, const T &...params)
unsigned short UShort_t
Definition: RtypesCore.h:36
TList * fListOfSignals
Definition: TQObject.h:58
virtual const char * GetSenderClassName() const
Definition: TQObject.h:65
Bool_t BlockSignals(Bool_t b)
Definition: TQObject.h:98
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:53
TList * GetListOfConnections() const
Definition: TQObject.h:95
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void Emit(const char *signal, Short_t param)
Definition: TQObject.h:118
void Emit(const char *signal, UChar_t param)
Definition: TQObject.h:116
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual Int_t NumberOfSignals() const
Return number of signals for this object.
Definition: TQObject.cxx:537
void Emit(const char *signal, Int_t param)
Definition: TQObject.h:122
void * fSender
Definition: TQObject.h:193
TList * GetListOfSignals() const
Definition: TQObject.h:94
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:559
A doubly linked list.
Definition: TList.h:47
virtual Bool_t HasConnection(const char *signal_name) const
Return true if there is any object connected to this signal.
Definition: TQObject.cxx:523
TList * fListOfConnections
list of signals from this object
Definition: TQObject.h:59
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:1135
void SetSenderClassName(const char *sclass="")
Definition: TQObject.h:208
static Bool_t fgAllSignalsBlocked
flag used for suppression of signals
Definition: TQObject.h:62
TQObject & operator=(const TQObject &tqo)
TQConnection class is an internal class, used in the object communication mechanism.
Definition: TQConnection.h:46
unsigned int UInt_t
Definition: RtypesCore.h:42
static Bool_t ConnectToClass(TQObject *sender, const char *signal, TClass *receiver_class, void *receiver, const char *slot)
Create connection between sender and receiver.
Definition: TQObject.cxx:829
short Short_t
Definition: RtypesCore.h:35
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual ~TQObject()
TQObject Destructor.
Definition: TQObject.cxx:402
static TString CompressName(const char *method_name)
Bool_t fSignalsBlocked
list of connections to this object
Definition: TQObject.h:60
long Long_t
Definition: RtypesCore.h:50
virtual void Message(const char *msg)
Definition: TQObject.h:158
virtual void Destroyed()
Definition: TQObject.h:154
double Double_t
Definition: RtypesCore.h:55
Bool_t AreSignalsBlocked() const
Definition: TQObject.h:97
unsigned long long ULong64_t
Definition: RtypesCore.h:70
static Bool_t AreAllSignalsBlocked()
Returns true if all signals are blocked.
Definition: TQObject.cxx:1315
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual void Disconnected(const char *)
Definition: TQObject.h:152
TString fSenderClass
Definition: TQObject.h:194
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Definition: TQObject.cxx:1293
TList * GetListOfClassSignals() const
Returns pointer to list of signals of this class.
Definition: TQObject.cxx:433
Mother of all ROOT objects.
Definition: TObject.h:58
void Emit(const char *signal, UInt_t param)
Definition: TQObject.h:124
void Emit(const char *signal, ULong64_t param)
Definition: TQObject.h:128
virtual ~TQObjSender()
Definition: TQObject.h:205
#define R__EXTERN
Definition: DllImport.h:27
char Char_t
Definition: RtypesCore.h:29
virtual void SetSender(void *sender)
Definition: TQObject.h:207
virtual void ChangedBy(const char *method)
Definition: TQObject.h:156
virtual void Connected(const char *)
Definition: TQObject.h:151
virtual const char * GetSenderClassName() const
Definition: TQObject.h:197
void Emit(const char *signal, UShort_t param)
Definition: TQObject.h:120
void Emit(const char *signal, ULong_t param)
Definition: TQObject.h:126
unsigned char UChar_t
Definition: RtypesCore.h:34
virtual void LowPriority(const char *signal_name, const char *slot_name=0)
Definition: TQObject.cxx:501
virtual Int_t NumberOfConnections() const
Return number of connections for this object.
Definition: TQObject.cxx:547
void CollectClassSignalLists(TList &list, TClass *cls)
Collect class signal lists from class cls and all its base-classes.
Definition: TQObject.cxx:449
virtual void HighPriority(const char *signal_name, const char *slot_name=0)
Definition: TQObject.cxx:475
void Emit(const char *signal, Bool_t param)
Definition: TQObject.h:112