Logo ROOT  
Reference Guide
TGlobal.cxx
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 /** \class TGlobal
13 Global variables class (global variables are obtained from CINT).
14 This class describes the attributes of a global variable.
15 The TROOT class contains a list of all currently defined global
16 variables (accessible via TROOT::GetListOfGlobals()).
17 */
18 
19 #include "TGlobal.h"
20 #include "TInterpreter.h"
21 #include "TList.h"
22 #include "TROOT.h"
23 
24 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Default TGlobal ctor.
29 
30 TGlobal::TGlobal(DataMemberInfo_t *info) : TDictionary(), fInfo(info)
31 {
32  if (fInfo) {
35  }
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Copy constructor
40 
41 TGlobal::TGlobal(const TGlobal &rhs) : TDictionary( ), fInfo(nullptr)
42 {
43  if (rhs.fInfo) {
47  }
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Assignment operator.
52 
54 {
55  if (this != &rhs) {
57  if (rhs.fInfo) {
61  }
62  }
63  return *this;
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// TGlobal dtor deletes adopted CINT DataMemberInfo object.
68 
70 {
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Return address of global.
76 
77 void *TGlobal::GetAddress() const
78 {
79  return (void *)gCling->DataMemberInfo_Offset(fInfo);
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Return number of array dimensions.
84 
86 {
87  if (!fInfo) return 0;
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 
94 {
95  return gInterpreter->GetDeclId(fInfo);
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Return maximum index for array dimension "dim".
100 
102 {
103  if (!fInfo) return 0;
104  return gCling->DataMemberInfo_MaxIndex(fInfo,dim);
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Get type of global variable, e,g.: "class TDirectory*" -> "TDirectory".
109 /// Result needs to be used or copied immediately.
110 
111 const char *TGlobal::GetTypeName() const
112 {
113  if (!fInfo) return nullptr;
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Get full type description of global variable, e,g.: "class TDirectory*".
119 
120 const char *TGlobal::GetFullTypeName() const
121 {
122  if (!fInfo) return nullptr;
124 }
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 /// Return true if this global object is pointing to a currently
128 /// loaded global. If a global is unloaded after the TGlobal
129 /// is created, the TGlobal will be set to be invalid.
130 
132 {
133  // Register the transaction when checking the validity of the object.
135  DeclId_t newId = gInterpreter->GetDataMember(0, fName);
136  if (newId) {
137  DataMemberInfo_t *info = gInterpreter->DataMemberInfo_Factory(newId, 0);
138  Update(info);
139  }
140  return newId != 0;
141  }
142  return fInfo != 0;
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Get property description word. For meaning of bits see EProperty.
147 
149 {
150  if (!fInfo) return 0;
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Update the TFunction to reflect the new info.
156 ///
157 /// This can be used to implement unloading (info == 0) and then reloading
158 /// (info being the 'new' decl address).
159 
160 Bool_t TGlobal::Update(DataMemberInfo_t *info)
161 {
163  fInfo = info;
164  if (fInfo) {
167  }
168  return kTRUE;
169 }
170 
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Constructor
174 
175 TGlobalMappedFunction::TGlobalMappedFunction(const char *name, const char *type, GlobalFunc_t funcPtr)
176  : fFuncPtr(funcPtr)
177 {
179 }
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Returns list collected globals
183 /// Used to storeTGlobalMappedFunctions from other libs, before gROOT was initialized
184 
186 {
187  // Used to storeTGlobalMappedFunctions from other libs, before gROOT was initialized
188  static TList fEarlyRegisteredGlobals;
189  // For thread-safe setting of SetOwner(kTRUE).
190  static bool earlyRegisteredGlobalsSetOwner
191  = (fEarlyRegisteredGlobals.SetOwner(kTRUE), true);
192  (void) earlyRegisteredGlobalsSetOwner; // silence unused var
193 
194  return fEarlyRegisteredGlobals;
195 }
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Add to GetEarlyRegisteredGlobals() if gROOT is not yet initialized; add to
199 /// gROOT->GetListOfGlobals() otherwise.
200 
202 {
203  // Use "gCling" as synonym for "gROOT is initialized"
204  if (gCling) {
205  gROOT->GetListOfGlobals()->Add(gmf);
206  } else {
208  }
209 }
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
TInterpreter::DataMemberInfo_ArrayDim
virtual int DataMemberInfo_ArrayDim(DataMemberInfo_t *) const
Definition: TInterpreter.h:455
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TNamed::SetNameTitle
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition: TNamed.cxx:154
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
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
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TInterpreter::DataMemberInfo_Offset
virtual Long_t DataMemberInfo_Offset(DataMemberInfo_t *) const
Definition: TInterpreter.h:463
TGlobal::Property
virtual Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TGlobal.cxx:148
TCollection::SetOwner
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Definition: TCollection.cxx:746
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:560
TGlobal::GetArrayDim
virtual Int_t GetArrayDim() const
Return number of array dimensions.
Definition: TGlobal.cxx:85
TNamed::fName
TString fName
Definition: TNamed.h:32
TList.h
TGlobal
Global variables class (global variables are obtained from CINT).
Definition: TGlobal.h:28
TInterpreter::DataMemberInfo_MaxIndex
virtual int DataMemberInfo_MaxIndex(DataMemberInfo_t *, Int_t) const
Definition: TInterpreter.h:461
TInterpreter::DataMemberInfo_TypeName
virtual const char * DataMemberInfo_TypeName(DataMemberInfo_t *) const
Definition: TInterpreter.h:467
bool
TGlobalMappedFunction::GetEarlyRegisteredGlobals
static TList & GetEarlyRegisteredGlobals()
Returns list collected globals Used to storeTGlobalMappedFunctions from other libs,...
Definition: TGlobal.cxx:185
TROOT.h
TGlobalMappedFunction
Definition: TGlobal.h:53
TDictionary::DeclId_t
const void * DeclId_t
Definition: TDictionary.h:223
TInterpreter::DataMemberInfo_Title
virtual const char * DataMemberInfo_Title(DataMemberInfo_t *) const
Definition: TInterpreter.h:470
Long_t
long Long_t
Definition: RtypesCore.h:54
TGlobal::GetAddress
virtual void * GetAddress() const
Return address of global.
Definition: TGlobal.cxx:77
TInterpreter::DataMemberInfo_Property
virtual Long_t DataMemberInfo_Property(DataMemberInfo_t *) const
Definition: TInterpreter.h:464
TGlobal::GetTypeName
virtual const char * GetTypeName() const
Get type of global variable, e,g.
Definition: TGlobal.cxx:111
TGlobal.h
TInterpreter::DataMemberInfo_Name
virtual const char * DataMemberInfo_Name(DataMemberInfo_t *) const
Definition: TInterpreter.h:469
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TInterpreter::DataMemberInfo_FactoryCopy
virtual DataMemberInfo_t * DataMemberInfo_FactoryCopy(DataMemberInfo_t *) const
Definition: TInterpreter.h:459
void
typedef void((*Func_t)())
TDictionary
This class defines an abstract interface that must be implemented by all classes that contain diction...
Definition: TDictionary.h:167
TInterpreter::DataMemberInfo_Delete
virtual void DataMemberInfo_Delete(DataMemberInfo_t *) const
Definition: TInterpreter.h:456
TInterpreter.h
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TGlobal::operator=
TGlobal & operator=(const TGlobal &)
Assignment operator.
Definition: TGlobal.cxx:53
gCling
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:561
name
char name[80]
Definition: TGX11.cxx:110
TDictionary::UpdateInterpreterStateMarker
Bool_t UpdateInterpreterStateMarker()
the Cling ID of the transaction that last updated the object
Definition: TDictionary.cxx:109
type
int type
Definition: TGX11.cxx:121
TGlobal::fInfo
DataMemberInfo_t * fInfo
Definition: TGlobal.h:31
TGlobal::Update
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
Definition: TGlobal.cxx:160
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
TInterpreter::TypeName
virtual const char * TypeName(const char *s)=0
TGlobal::IsValid
virtual Bool_t IsValid()
Return true if this global object is pointing to a currently loaded global.
Definition: TGlobal.cxx:131
TList
A doubly linked list.
Definition: TList.h:44
gROOT
#define gROOT
Definition: TROOT.h:406
int