Logo ROOT  
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 
28 class TGlobal : public TDictionary {
29 
30 private:
31  DataMemberInfo_t *fInfo; //!pointer to CINT data member info
32 
33 public:
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.
54 public:
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 
91 private:
92  GlobalFunc_t fFuncPtr{nullptr}; // Function to call to get the address
93 
94  GlobalFunctor_t fFunctor; // functor which correctly returns pointer
95 
96  TGlobalMappedFunction &operator=(const TGlobal &) = delete;
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
TGlobal::TGlobal
TGlobal(DataMemberInfo_t *info=nullptr)
pointer to CINT data member info
Definition: TGlobal.cxx:30
TGlobalMappedFunction::Add
static void Add(TGlobalMappedFunction *gmf)
Add to GetEarlyRegisteredGlobals() if gROOT is not yet initialized; add to gROOT->GetListOfGlobals() ...
Definition: TGlobal.cxx:201
TGlobal::~TGlobal
virtual ~TGlobal()
TGlobal dtor deletes adopted CINT DataMemberInfo object.
Definition: TGlobal.cxx:69
TGlobalMappedFunction::GetTypeName
const char * GetTypeName() const override
Get type of global variable, e,g.
Definition: TGlobal.h:65
TGlobalMappedFunction::Property
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
Definition: TGlobal.h:67
TGlobalMappedFunction::GetArrayDim
Int_t GetArrayDim() const override
Return number of array dimensions.
Definition: TGlobal.h:61
TGlobalMappedFunction::Update
bool Update(DataMemberInfo_t *) override
Update the TFunction to reflect the new info.
Definition: TGlobal.h:68
TGlobal::GetFullTypeName
virtual const char * GetFullTypeName() const
Get full type description of global variable, e,g.: "class TDirectory*".
Definition: TGlobal.cxx:120
TGlobal::GetMaxIndex
virtual Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
Definition: TGlobal.cxx:101
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
TGlobal::Property
virtual Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TGlobal.cxx:148
TGlobalMappedFunction::fFunctor
GlobalFunctor_t fFunctor
Definition: TGlobal.h:94
TGlobalMappedFunction::~TGlobalMappedFunction
virtual ~TGlobalMappedFunction()=default
TGlobal::GetArrayDim
virtual Int_t GetArrayDim() const
Return number of array dimensions.
Definition: TGlobal.cxx:85
TGlobalMappedFunction::operator=
TGlobalMappedFunction & operator=(const TGlobal &)=delete
TGlobalMappedFunction::GlobalFunctor_t
std::function< void *()> GlobalFunctor_t
Definition: TGlobal.h:56
TGlobalMappedFunction::GetDeclId
DeclId_t GetDeclId() const override
Definition: TGlobal.h:62
TDictionary::DeclId_t
const typedef void * DeclId_t
Definition: TDictionary.h:209
TGlobal
Definition: TGlobal.h:28
bool
TROOT
Definition: TROOT.h:94
TGlobalMappedFunction::GetEarlyRegisteredGlobals
static TList & GetEarlyRegisteredGlobals()
Returns list collected globals Used to storeTGlobalMappedFunctions from other libs,...
Definition: TGlobal.cxx:185
TGlobalMappedFunction::GlobalFunc_t
void *(* GlobalFunc_t)()
Definition: TGlobal.h:55
TGlobalMappedFunction::MakeFunctor
static void MakeFunctor(const char *name, const char *type, GlobFunc &func, GlobalFunctor_t functor)
Definition: TGlobal.h:84
TDictionary.h
TGlobalMappedFunction
Definition: TGlobal.h:53
TGlobalMappedFunction::MakeFunctor
static void MakeFunctor(const char *name, const char *type, GlobFunc &func)
Definition: TGlobal.h:73
ROOT::R::function
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
Long_t
long Long_t
Definition: RtypesCore.h:54
TGlobal::GetAddress
virtual void * GetAddress() const
Return address of global.
Definition: TGlobal.cxx:77
TGlobal::GetTypeName
virtual const char * GetTypeName() const
Get type of global variable, e,g.
Definition: TGlobal.cxx:111
TGlobalMappedFunction::GetFullTypeName
const char * GetFullTypeName() const override
Get full type description of global variable, e,g.: "class TDirectory*".
Definition: TGlobal.h:66
TDictionary
Definition: TDictionary.h:162
TGlobalMappedFunction::fFuncPtr
GlobalFunc_t fFuncPtr
Definition: TGlobal.h:92
TGlobal::operator=
TGlobal & operator=(const TGlobal &)
Assignment operator.
Definition: TGlobal.cxx:53
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
type
int type
Definition: TGX11.cxx:121
TGlobal::fInfo
DataMemberInfo_t * fInfo
Definition: TGlobal.h:37
TGlobal::Update
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
Definition: TGlobal.cxx:160
TGlobalMappedFunction::GetAddress
void * GetAddress() const override
Return address of global.
Definition: TGlobal.h:64
TGlobalMappedFunction::TGlobalMappedFunction
TGlobalMappedFunction(const char *name, const char *type, GlobalFunc_t funcPtr)
Constructor.
Definition: TGlobal.cxx:175
TGlobal::GetDeclId
virtual DeclId_t GetDeclId() const
Definition: TGlobal.cxx:93
TGlobalMappedFunction::GetMaxIndex
Int_t GetMaxIndex(Int_t) const override
Return maximum index for array dimension "dim".
Definition: TGlobal.h:63
TGlobal::IsValid
virtual Bool_t IsValid()
Return true if this global object is pointing to a currently loaded global.
Definition: TGlobal.cxx:131
TList
Definition: TList.h:44
int