Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RQ_OBJECT.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_RQ_OBJECT
13#define ROOT_RQ_OBJECT
14
15#include <TQObject.h>
16#include <Varargs.h>
17
18
19//---- RQ_OBJECT macro -----------------------------------------------
20//
21// Macro is used to delegate TQObject methods to other classes
22// Example:
23//
24// #include "RQ_OBJECT.h"
25//
26// class A {
27// RQ_OBJECT("A")
28// private:
29// Int_t fValue;
30// public:
31// A() : fValue(0) { }
32// ~A() { }
33//
34// void SetValue(Int_t value)
35// void PrintValue() const { printf("value=%d\n", fValue); }
36// Int_t GetValue() const { return fValue; }
37// };
38//
39// void A::SetValue(Int_t value)
40// {
41// // Sets new value
42//
43// // to prevent infinite looping in the case
44// // of cyclic connections
45// if (value != fValue) {
46// fValue = value;
47// Emit("SetValue(Int_t)", fValue);
48// }
49// }
50//
51// Load this class into root session and try the folllowing:
52//
53// a = new A();
54// b = new A();
55//
56// Here is one way to connect two of these objects together:
57//
58// a->Connect("SetValue(Int_t)", "A", b, "SetValue(Int_t)");
59//
60// Calling a->SetValue(79) will make a emit a signal, which b
61// will receive, i.e. b->SetValue(79) is invoked. b will in
62// turn emit the same signal, which nobody receives, since no
63// slot has been connected to it, so it disappears into hyperspace.
64//
65
66#define RQ_OBJECT1(sender_class)\
67private:\
68TQObjSender fQObject;\
69public:\
70TList *GetListOfSignals() const {return fQObject.GetListOfSignals();}\
71Bool_t Connect(const char *sig,const char *cl,void *rcvr,const char *slt)\
72{fQObject.SetSender(this);fQObject.SetSenderClassName(sender_class);return fQObject.Connect(sig,cl,rcvr,slt);}\
73Bool_t Disconnect(const char *sig=0,void *rcvr=0,const char *slt=0){return fQObject.Disconnect(sig,rcvr,slt);}\
74void HighPriority(const char *signal_name,const char *slot_name=0){fQObject.HighPriority(signal_name,slot_name);}\
75void LowPriority(const char *signal_name,const char *slot_name=0){fQObject.LowPriority(signal_name,slot_name);}\
76template <typename... T> void EmitVA(const char *signal_name, Int_t nargs, const T&... params) \
77{ fQObject.EmitVA(signal_name,nargs,params...); } \
78void Emit(const char *signal){EmitVA(signal, /*nargs*/0);} \
79template <typename T> void Emit(const char *signal, const T& arg) { EmitVA(signal, /*nargs*/ 1, arg); } \
80
81#define RQ_OBJECT2(sender_class)\
82void Destroyed(){Emit("Destroyed()");}\
83void ChangedBy(const char *method){Emit("ChangedBy(char*)",method);}\
84void Message(const char *msg){Emit("Message(char*)",msg);}\
85private:
86
87#define RQ_OBJECT(sender_class)\
88 RQ_OBJECT1(sender_class)\
89 RQ_OBJECT2(sender_class)
90
91#endif