Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGlobal.h
Go to the documentation of this file.
1// @(#)root/meta:$Id$
2// Author: Rene Brun 13/11/95
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_TGlobal
13#define ROOT_TGlobal
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TGlobal //
19// //
20// Global variables class (global variables are obtained from CINT). //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TDictionary.h"
25
26#include <functional>
27
28class TGlobal : public TDictionary {
29
30private:
31 DataMemberInfo_t *fInfo; //!pointer to CINT data member info
32
33public:
34 TGlobal(DataMemberInfo_t *info = nullptr);
35 TGlobal (const TGlobal &);
36 TGlobal &operator=(const TGlobal &);
37
38 virtual ~TGlobal();
39 virtual Int_t GetArrayDim() const;
40 virtual DeclId_t GetDeclId() const;
41 virtual Int_t GetMaxIndex(Int_t dim) const;
42 virtual void *GetAddress() const;
43 virtual const char *GetTypeName() const;
44 virtual const char *GetFullTypeName() const;
45 virtual Bool_t IsValid();
46 Long_t Property() const override;
47 virtual bool Update(DataMemberInfo_t *info);
48
49 ClassDefOverride(TGlobal,2) //Global variable class
50};
51
52// Class to map the "funcky" globals and be able to add them to the list of globals.
54public:
55 typedef void *(*GlobalFunc_t)();
56 typedef std::function<void *()> GlobalFunctor_t;
57
58 TGlobalMappedFunction(const char *name, const char *type, GlobalFunc_t funcPtr);
59
60 virtual ~TGlobalMappedFunction() = default;
61 Int_t GetArrayDim() const override { return 0; }
62 DeclId_t GetDeclId() const override { return (DeclId_t)(fFuncPtr); } // Used as DeclId because of uniqueness
63 Int_t GetMaxIndex(Int_t /*dim*/) const override { return -1; }
64 void *GetAddress() const override { return !fFunctor ? (*fFuncPtr)() : fFunctor(); }
65 const char *GetTypeName() const override { return GetTitle(); }
66 const char *GetFullTypeName() const override { return GetTitle(); }
67 Long_t Property() const override { return 0; }
68 bool Update(DataMemberInfo_t * /*info*/) override { return false; }
69
70 static void Add(TGlobalMappedFunction *gmf);
71
72 template <typename GlobFunc>
73 static void MakeFunctor(const char *name, const char *type, GlobFunc &func)
74 {
75 auto glob = new TGlobalMappedFunction(name, type, (GlobalFunc_t)((void *)&func));
76 glob->fFunctor = [&func] {
77 auto &res = func();
78 return (void *)(&res);
79 };
80 Add(glob);
81 }
82
83 template <typename GlobFunc>
84 static void MakeFunctor(const char *name, const char *type, GlobFunc &func, GlobalFunctor_t functor)
85 {
86 auto glob = new TGlobalMappedFunction(name, type, (GlobalFunc_t)((void *)&func));
87 glob->fFunctor = functor;
88 Add(glob);
89 }
90
91private:
92 GlobalFunc_t fFuncPtr{nullptr}; // Function to call to get the address
93
94 GlobalFunctor_t fFunctor; // functor which correctly returns pointer
95
97 // Some of the special ones are created before the list is create e.g gFile
98 // We need to buffer them.
100
101 friend class TROOT;
102};
103
104#endif
long Long_t
Definition RtypesCore.h:54
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
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
char name[80]
Definition TGX11.cxx:110
This class defines an abstract interface that must be implemented by all classes that contain diction...
const void * DeclId_t
static void Add(TGlobalMappedFunction *gmf)
Add to GetEarlyRegisteredGlobals() if gROOT is not yet initialized; add to gROOT->GetListOfGlobals() ...
Definition TGlobal.cxx:205
DeclId_t GetDeclId() const override
Definition TGlobal.h:62
GlobalFunc_t fFuncPtr
Definition TGlobal.h:92
std::function< void *()> GlobalFunctor_t
Definition TGlobal.h:56
void *(* GlobalFunc_t)()
Definition TGlobal.h:55
const char * GetTypeName() const override
Get type of global variable, e,g.: "class TDirectory*" -> "TDirectory".
Definition TGlobal.h:65
Int_t GetArrayDim() const override
Return number of array dimensions.
Definition TGlobal.h:61
static void MakeFunctor(const char *name, const char *type, GlobFunc &func)
Definition TGlobal.h:73
const char * GetFullTypeName() const override
Get full type description of global variable, e,g.: "class TDirectory*".
Definition TGlobal.h:66
static TList & GetEarlyRegisteredGlobals()
Returns list collected globals Used to storeTGlobalMappedFunctions from other libs,...
Definition TGlobal.cxx:189
bool Update(DataMemberInfo_t *) override
Update the TFunction to reflect the new info.
Definition TGlobal.h:68
static void MakeFunctor(const char *name, const char *type, GlobFunc &func, GlobalFunctor_t functor)
Definition TGlobal.h:84
Int_t GetMaxIndex(Int_t) const override
Return maximum index for array dimension "dim".
Definition TGlobal.h:63
virtual ~TGlobalMappedFunction()=default
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
Definition TGlobal.h:67
TGlobalMappedFunction & operator=(const TGlobal &)=delete
void * GetAddress() const override
Return address of global.
Definition TGlobal.h:64
GlobalFunctor_t fFunctor
Definition TGlobal.h:94
Global variables class (global variables are obtained from CINT).
Definition TGlobal.h:28
virtual DeclId_t GetDeclId() const
Definition TGlobal.cxx:97
virtual Int_t GetArrayDim() const
Return number of array dimensions.
Definition TGlobal.cxx:89
virtual const char * GetTypeName() const
Get type of global variable, e,g.: "class TDirectory*" -> "TDirectory".
Definition TGlobal.cxx:115
virtual ~TGlobal()
TGlobal dtor deletes adopted CINT DataMemberInfo object.
Definition TGlobal.cxx:73
DataMemberInfo_t * fInfo
Definition TGlobal.h:31
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
Definition TGlobal.cxx:164
virtual Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
Definition TGlobal.cxx:105
virtual Bool_t IsValid()
Return true if this global object is pointing to a currently loaded global.
Definition TGlobal.cxx:135
TGlobal & operator=(const TGlobal &)
Assignment operator.
Definition TGlobal.cxx:53
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
Definition TGlobal.cxx:152
virtual void * GetAddress() const
Return address of global.
Definition TGlobal.cxx:81
virtual const char * GetFullTypeName() const
Get full type description of global variable, e,g.: "class TDirectory*".
Definition TGlobal.cxx:124
A doubly linked list.
Definition TList.h:38
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
ROOT top level object description.
Definition TROOT.h:94