Logo ROOT  
Reference Guide
TVirtualQConnection.h
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Vassil Vassilev 23/01/2017
3
4/*************************************************************************
5 * Copyright (C) 1995-2017, 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_TVirtualQConnection
13#define ROOT_TVirtualQConnection
14
15#include "TList.h"
16#include "TInterpreter.h"
17
18/// Mediates the link between the signal and the slot. It decouples the setting of
19/// arguments and sending a signal.
20///
21/// There are three different modes in argument setting required by TQObject's Emit/EmitVA:
22/// setting integral types, setting array types and setting const char*.
23class TVirtualQConnection : public TList {
24protected:
25 virtual CallFunc_t *GetSlotCallFunc() const = 0;
26 virtual void SetArg(Long_t) = 0;
27 virtual void SetArg(ULong_t) = 0;
28 virtual void SetArg(Float_t) = 0;
29 virtual void SetArg(Double_t) = 0;
30 virtual void SetArg(Long64_t) = 0;
31 virtual void SetArg(ULong64_t) = 0;
32
33 // Note: sets argument list (for potentially more than one arg).
34 virtual void SetArg(const Long_t *, Int_t = -1) = 0;
35 virtual void SetArg(const char *) = 0;
36 void SetArg(const void *ptr) { SetArg((Long_t)ptr); };
37
38 // We should 'widen' all types to one of the SetArg overloads.
39 template <class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
40 void SetArg(const T& val)
41 {
42 if (std::is_signed<T>::value)
43 SetArg((Long_t)val);
44 else
45 SetArg((ULong_t)val);
46 }
47
48 // We pass arrays as Lont_t*. In the template instance we can deduce their
49 // size, too.
50 template <class T, class = typename std::enable_if<std::is_array<T>::value>::type>
51 void SetArg(const T* val)
52 {
53 constexpr size_t size = sizeof(val)/sizeof(val[0]);
54 static_assert(size > 0, "The array must have at least one element!");
55 SetArg((Long_t*)val, size);
56 }
57
58 void SetArgsImpl() {} // SetArgsImpl terminator
59 template <typename T, typename... Ts> void SetArgsImpl(const T& arg, const Ts&... tail)
60 {
61 SetArg(arg);
62 SetArgsImpl(tail...);
63 }
64public:
65 virtual void SendSignal() = 0;
66
67 /// Unpacks the template parameter type and sets arguments of integral and array (scalar) type.
68 ///
69 template <typename... T> void SetArgs(const T&... args)
70 {
71 // Do not reset the arguments if we have no arguments to reset with.
72 // This is essential in order to support cases like:
73 // void f(int) {}; TQObject::Connect (... "f(int=12");
74 // The implementation will see we create a slot which has a 'default'
75 // argument and create a CallFunc with preset argument values to later call.
76 if (!sizeof...(args)) return;
77 gInterpreter->CallFunc_ResetArg(GetSlotCallFunc());
78 SetArgsImpl(args...);
79 }
80
81 /// Sets an array of arguments passed as a pointer type and size. If nargs is not specified
82 /// the number of arguments expected by the slot is used.
83 ///
84 void SetArgs(const Long_t* argArray, Int_t nargs = -1)
85 {
86 SetArg(argArray, nargs);
87 }
88};
89
90#endif
unsigned long ULong_t
Definition: RtypesCore.h:53
long Long_t
Definition: RtypesCore.h:52
double Double_t
Definition: RtypesCore.h:57
long long Long64_t
Definition: RtypesCore.h:71
unsigned long long ULong64_t
Definition: RtypesCore.h:72
float Float_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
#define gInterpreter
Definition: TInterpreter.h:556
A doubly linked list.
Definition: TList.h:44
Mediates the link between the signal and the slot.
virtual void SetArg(const char *)=0
virtual void SetArg(Float_t)=0
virtual void SetArg(Long_t)=0
virtual void SetArg(const Long_t *, Int_t=-1)=0
void SetArg(const T &val)
void SetArg(const void *ptr)
virtual CallFunc_t * GetSlotCallFunc() const =0
void SetArgs(const T &... args)
Unpacks the template parameter type and sets arguments of integral and array (scalar) type.
virtual void SetArg(ULong64_t)=0
virtual void SendSignal()=0
virtual void SetArg(Long64_t)=0
virtual void SetArg(ULong_t)=0
void SetArgs(const Long_t *argArray, Int_t nargs=-1)
Sets an array of arguments passed as a pointer type and size.
void SetArgsImpl(const T &arg, const Ts &... tail)
void SetArg(const T *val)
virtual void SetArg(Double_t)=0
double T(double x)
Definition: ChebyshevPol.h:34