Logo ROOT   6.16/01
Reference Guide
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 virtual Long_t Property() const;
47 virtual bool Update(DataMemberInfo_t *info);
48
49 ClassDef(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
int Int_t
Definition: RtypesCore.h:41
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:324
int type
Definition: TGX11.cxx:120
This class defines an abstract interface that must be implemented by all classes that contain diction...
Definition: TDictionary.h:159
const void * DeclId_t
Definition: TDictionary.h:206
static void Add(TGlobalMappedFunction *gmf)
Add to GetEarlyRegisteredGlobals() if gROOT is not yet initialized; add to gROOT->GetListOfGlobals() ...
Definition: TGlobal.cxx:201
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
TGlobalMappedFunction(const char *name, const char *type, GlobalFunc_t funcPtr)
Constructor.
Definition: TGlobal.cxx:175
void *(* GlobalFunc_t)()
Definition: TGlobal.h:55
const char * GetTypeName() const override
Get type of global variable, e,g.
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:185
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:93
virtual Int_t GetArrayDim() const
Return number of array dimensions.
Definition: TGlobal.cxx:85
TGlobal(DataMemberInfo_t *info=nullptr)
pointer to CINT data member info
Definition: TGlobal.cxx:30
virtual const char * GetTypeName() const
Get type of global variable, e,g.
Definition: TGlobal.cxx:111
virtual ~TGlobal()
TGlobal dtor deletes adopted CINT DataMemberInfo object.
Definition: TGlobal.cxx:69
DataMemberInfo_t * fInfo
Definition: TGlobal.h:31
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
Definition: TGlobal.cxx:160
virtual Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TGlobal.cxx:148
virtual Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
Definition: TGlobal.cxx:101
virtual Bool_t IsValid()
Return true if this global object is pointing to a currently loaded global.
Definition: TGlobal.cxx:131
TGlobal & operator=(const TGlobal &)
Assignment operator.
Definition: TGlobal.cxx:53
virtual void * GetAddress() const
Return address of global.
Definition: TGlobal.cxx:77
virtual const char * GetFullTypeName() const
Get full type description of global variable, e,g.: "class TDirectory*".
Definition: TGlobal.cxx:120
A doubly linked list.
Definition: TList.h:44
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
ROOT top level object description.
Definition: TROOT.h:100
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151