ROOT  6.06/09
Reference Guide
TBaseClass.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Fons Rademakers 08/02/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 #include "TBaseClass.h"
13 #include "TClass.h"
14 #include "TInterpreter.h"
15 #include <limits.h>
16 
17 #include "TVirtualMutex.h" // For R__LOCKGUARD
18 
19 /** \class TBaseClass
20 Each class (see TClass) has a linked list of its base class(es).
21 This class describes one single base class.
22 The base class info is obtained via the CINT api.
23  see class TCling.
24 
25 The base class information is used a.o. in to find all inherited methods.
26 */
27 
28 
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// Default TBaseClass ctor. TBaseClasses are constructed in TClass
33 /// via a call to TCling::CreateListOfBaseClasses().
34 
35 TBaseClass::TBaseClass(BaseClassInfo_t *info, TClass *cl) :
36  TDictionary(), fInfo(info), fClass(cl), fDelta(INT_MAX),
37  fProperty(-1), fSTLType(-1)
38 {
39  if (fInfo) SetName(gCling->BaseClassInfo_FullName(fInfo));
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// TBaseClass dtor deletes adopted CINT BaseClassInfo object.
44 
46 {
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Called by the browser, to browse a baseclass.
52 
54 {
56  if (c) c->Browse(b);
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Get pointer to the base class TClass.
61 
63 {
64  if (!fClassPtr) {
66  else fClassPtr = TClass::GetClass(fName, load);
67  }
68  return fClassPtr;
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Get offset from "this" to part of base class.
73 
75 {
76  // Initialized to INT_MAX to signal that it's unset; -1 is a valid value
77  // meaning "cannot calculate base offset".
78  if (fDelta == INT_MAX) {
80  if (Property() & kIsVirtualBase)
81  fDelta = -1;
82  else if (fInfo)
84  }
85  return fDelta;
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Get base class description (comment).
90 
91 const char *TBaseClass::GetTitle() const
92 {
93  TClass *c = ((TBaseClass *)this)->GetClassPointer();
94  return c ? c->GetTitle() : "";
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Return which type (if any) of STL container the data member is.
99 
101 {
102  // fSTLType is -1 if not yet evaluated.
103  // fSTLType is -2 if no fInfo was available.
104 
105  if (fSTLType < 0) {
106  if (!fInfo) {
107  fSTLType = -2;
108  } else {
109  const char *type = gCling->BaseClassInfo_TmpltName(fInfo);
110  if (!type) fSTLType = ROOT::kNotSTL;
111  else if (!strcmp(type, "vector")) fSTLType = ROOT::kSTLvector;
112  else if (!strcmp(type, "list")) fSTLType = ROOT::kSTLlist;
113  else if (!strcmp(type, "forward_list")) fSTLType = ROOT::kSTLforwardlist;
114  else if (!strcmp(type, "deque")) fSTLType = ROOT::kSTLdeque;
115  else if (!strcmp(type, "map")) fSTLType = ROOT::kSTLmap;
116  else if (!strcmp(type, "multimap")) fSTLType = ROOT::kSTLmultimap;
117  else if (!strcmp(type, "set")) fSTLType = ROOT::kSTLset;
118  else if (!strcmp(type, "multiset")) fSTLType = ROOT::kSTLmultiset;
119  else if (!strcmp(type, "unordered_set")) fSTLType = ROOT::kSTLunorderedset;
120  else if (!strcmp(type, "unordered_multiset")) fSTLType = ROOT::kSTLunorderedmultiset;
121  else if (!strcmp(type, "unordered_map")) fSTLType = ROOT::kSTLunorderedmap;
122  else if (!strcmp(type, "unordered_multimap")) fSTLType = ROOT::kSTLunorderedmultimap;
123  else fSTLType = ROOT::kNotSTL;
124  }
125  }
126  if (fSTLType == -2) return ROOT::kNotSTL;
127  return (ROOT::ESTLType) fSTLType;
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Get property description word. For meaning of bits see EProperty.
132 
134 {
135  if (fProperty == -1 && fInfo) {
138  }
139  return fProperty;
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Stream an object of TBaseClass. Triggers the calculation of the
144 /// cache variables to store them.
145 
146 void TBaseClass::Streamer(TBuffer& b) {
147  if (b.IsReading()) {
148  b.ReadClassBuffer(Class(), this);
149  } else {
150  // Writing.
151  // Calculate cache properties first.
152  GetDelta();
153  Property();
154  IsSTLContainer();
155  b.WriteClassBuffer(Class(), this);
156  }
157 }
virtual const char * BaseClassInfo_TmpltName(BaseClassInfo_t *) const
Definition: TInterpreter.h:395
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
ESTLType
Definition: ESTLType.h:28
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual Long_t BaseClassInfo_Property(BaseClassInfo_t *) const
Definition: TInterpreter.h:390
Bool_t IsReading() const
Definition: TBuffer.h:81
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
Definition: TBaseClass.cxx:62
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void BaseClassInfo_Delete(BaseClassInfo_t *) const
Definition: TInterpreter.h:383
const char * GetTitle() const
Get base class description (comment).
Definition: TBaseClass.cxx:91
void Class()
Definition: Class.C:29
Int_t GetDelta()
Get offset from "this" to part of base class.
Definition: TBaseClass.cxx:74
TClassRef fClassPtr
pointer to CINT base class info
Definition: TBaseClass.h:43
TClass * fClass
pointer to the foreign object
Int_t fProperty
Definition: TBaseClass.h:46
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual const char * BaseClassInfo_FullName(BaseClassInfo_t *) const
Definition: TInterpreter.h:393
This class defines an abstract interface that must be implemented by all classes that contain diction...
Definition: TDictionary.h:162
virtual void Browse(TBrowser *b)
This method is called by a browser to get the class information.
Definition: TClass.cxx:1916
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
TString fName
Definition: TNamed.h:36
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:35
Int_t fDelta
pointer to parent class
Definition: TBaseClass.h:45
long Long_t
Definition: RtypesCore.h:50
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
BaseClassInfo_t * fInfo
Definition: TBaseClass.h:42
int type
Definition: TGX11.cxx:120
virtual ~TBaseClass()
TBaseClass dtor deletes adopted CINT BaseClassInfo object.
Definition: TBaseClass.cxx:45
ClassImp(TBaseClass) TBaseClass
Default TBaseClass ctor.
Definition: TBaseClass.cxx:29
#define R__LOCKGUARD(mutex)
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TBaseClass.cxx:133
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2881
ROOT::ESTLType IsSTLContainer()
Return which type (if any) of STL container the data member is.
Definition: TBaseClass.cxx:100
virtual ClassInfo_t * BaseClassInfo_ClassInfo(BaseClassInfo_t *) const =0
virtual Long_t BaseClassInfo_Offset(BaseClassInfo_t *, void *=0, bool=true) const
Definition: TInterpreter.h:389
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:504
virtual void Browse(TBrowser *b)
Called by the browser, to browse a baseclass.
Definition: TBaseClass.cxx:53
gr SetName("gr")
Int_t fSTLType
Definition: TBaseClass.h:47