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