Logo ROOT   6.12/07
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 
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 0;
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 0;
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 
172 {
173  // Used to storeTGlobalMappedFunctions from other libs, before gROOT was initialized
174  static TList fEarlyRegisteredGlobals;
175  // For thread-safe setting of SetOwner(kTRUE).
176  static bool earlyRegisteredGlobalsSetOwner
177  = (fEarlyRegisteredGlobals.SetOwner(kTRUE), true);
178  (void) earlyRegisteredGlobalsSetOwner; // silence unused var
179 
180  return fEarlyRegisteredGlobals;
181 }
182 
184 {
185  // Add to GetEarlyRegisteredGlobals() if gROOT is not yet initialized; add to
186  // gROOT->GetListOfGlobals() otherwise.
187 
188  // Use "gCling" as synonym for "gROOT is initialized"
189  if (gCling) {
190  gROOT->GetListOfGlobals()->Add(gmf);
191  } else {
192  GetEarlyRegisteredGlobals().Add(gmf);
193  }
194 }
virtual DeclId_t GetDeclId() const
Definition: TGlobal.cxx:93
DataMemberInfo_t * fInfo
Definition: TGlobal.h:30
virtual Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
Definition: TGlobal.cxx:101
virtual ~TGlobal()
TGlobal dtor deletes adopted CINT DataMemberInfo object.
Definition: TGlobal.cxx:69
virtual const char * GetFullTypeName() const
Get full type description of global variable, e,g.: "class TDirectory*".
Definition: TGlobal.cxx:120
Bool_t UpdateInterpreterStateMarker()
the Cling ID of the transaction that last updated the object
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual DataMemberInfo_t * DataMemberInfo_FactoryCopy(DataMemberInfo_t *) const
Definition: TInterpreter.h:426
#define gROOT
Definition: TROOT.h:402
virtual void * GetAddress() const
Return address of global.
Definition: TGlobal.cxx:77
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define gInterpreter
Definition: TInterpreter.h:526
const void * DeclId_t
Definition: TDictionary.h:205
virtual Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TGlobal.cxx:148
static TList & GetEarlyRegisteredGlobals()
Definition: TGlobal.cxx:171
virtual const char * DataMemberInfo_Title(DataMemberInfo_t *) const
Definition: TInterpreter.h:437
virtual Long_t DataMemberInfo_Property(DataMemberInfo_t *) const
Definition: TInterpreter.h:431
virtual const char * TypeName(const char *s)=0
A doubly linked list.
Definition: TList.h:44
virtual int DataMemberInfo_MaxIndex(DataMemberInfo_t *, Int_t) const
Definition: TInterpreter.h:428
virtual const char * DataMemberInfo_TypeName(DataMemberInfo_t *) const
Definition: TInterpreter.h:434
virtual void DataMemberInfo_Delete(DataMemberInfo_t *) const
Definition: TInterpreter.h:423
This class defines an abstract interface that must be implemented by all classes that contain diction...
Definition: TDictionary.h:158
virtual Bool_t IsValid()
Return true if this global object is pointing to a currently loaded global.
Definition: TGlobal.cxx:131
Global variables class (global variables are obtained from CINT).
Definition: TGlobal.h:27
virtual Int_t GetArrayDim() const
Return number of array dimensions.
Definition: TGlobal.cxx:85
TString fName
Definition: TNamed.h:32
virtual Long_t DataMemberInfo_Offset(DataMemberInfo_t *) const
Definition: TInterpreter.h:430
long Long_t
Definition: RtypesCore.h:50
static void Add(TGlobalMappedFunction *gmf)
Definition: TGlobal.cxx:183
virtual const char * GetTypeName() const
Get type of global variable, e,g.
Definition: TGlobal.cxx:111
#define ClassImp(name)
Definition: Rtypes.h:359
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
Definition: TGlobal.cxx:160
virtual const char * DataMemberInfo_Name(DataMemberInfo_t *) const
Definition: TInterpreter.h:436
typedef void((*Func_t)())
TGlobal & operator=(const TGlobal &)
Assignment operator.
Definition: TGlobal.cxx:53
virtual int DataMemberInfo_ArrayDim(DataMemberInfo_t *) const
Definition: TInterpreter.h:422
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:528
TGlobal(DataMemberInfo_t *info=0)
pointer to CINT data member info
Definition: TGlobal.cxx:30
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const Bool_t kTRUE
Definition: RtypesCore.h:87