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