Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 Longptr_t *, Int_t = -1) = 0;
35 virtual void SetArg(const char *) = 0;
36 void SetArg(const void *ptr) { SetArg((Longptr_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((Longptr_t)val);
44 else
45 SetArg((ULongptr_t)val);
46 }
47
48 void SetArgsImpl() {} // SetArgsImpl terminator
49 template <typename T, typename... Ts> void SetArgsImpl(const T& arg, const Ts&... tail)
50 {
51 SetArg(arg);
52 SetArgsImpl(tail...);
53 }
54public:
55 virtual void SendSignal() = 0;
56
57 /// Unpacks the template parameter type and sets arguments of integral and array (scalar) type.
58 ///
59 template <typename... T> void SetArgs(const T&... args)
60 {
61 // Do not reset the arguments if we have no arguments to reset with.
62 // This is essential in order to support cases like:
63 // void f(int) {}; TQObject::Connect (... "f(int=12");
64 // The implementation will see we create a slot which has a 'default'
65 // argument and create a CallFunc with preset argument values to later call.
66 if (!sizeof...(args)) return;
67 gInterpreter->CallFunc_ResetArg(GetSlotCallFunc());
68 SetArgsImpl(args...);
69 }
70
71 /// Sets an array of arguments passed as a pointer type and size. If nargs is not specified
72 /// the number of arguments expected by the slot is used.
73 ///
74 void SetArgs(const Longptr_t* argArray, Int_t nargs = -1)
75 {
76 SetArg(argArray, nargs);
77 }
78};
79
80#endif
long Longptr_t
Definition RtypesCore.h:82
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
unsigned long ULongptr_t
Definition RtypesCore.h:83
float Float_t
Definition RtypesCore.h:57
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
#define gInterpreter
A doubly linked list.
Definition TList.h:38
Mediates the link between the signal and the slot.
virtual void SetArg(const Longptr_t *, Int_t=-1)=0
virtual void SetArg(const char *)=0
virtual void SetArg(Float_t)=0
virtual void SetArg(Long_t)=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 Longptr_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)
virtual void SetArg(Double_t)=0