ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TMemberInspector.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 15/07/96
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 TMemberInspector
13 
14 Abstract base class for accessing the data-members of a class.
15 Classes derived from this class can be given as argument to the
16 ShowMembers() methods of ROOT classes. This feature facilitates
17 the writing of class browsers and inspectors.
18 */
19 
20 #include "TMemberInspector.h"
21 #include "TInterpreter.h"
22 #include "TClassEdit.h"
23 #include "TClass.h"
24 #include "TError.h"
25 
26 class TMemberInspector::TParentBuf {
27 private:
28  std::vector<char> fBuf;
29  Ssiz_t fLen;
30 public:
31  TParentBuf(): fBuf(1024), fLen(0) {}
32  Ssiz_t GetLength() const { return fLen; }
33  void Append(const char*);
34  void Remove(Ssiz_t startingAt);
35  operator const char*() const { return &fBuf[0]; }
36 };
37 
38 void TMemberInspector::TParentBuf::Append(const char* add)
39 {
40  // Add "add" to string
41  if (!add || !add[0]) return;
42  Ssiz_t addlen = strlen(add);
43  fBuf.reserve(fLen + addlen);
44  const char* i = add;
45  while (*i) {
46  fBuf[fLen++] = *i;
47  ++i;
48  }
49  fBuf[fLen] = 0;
50 }
51 
52 void TMemberInspector::TParentBuf::Remove(Ssiz_t startingAt)
53 {
54  // Remove characters starting at "startingAt"
55  fLen = startingAt;
56  fBuf[startingAt] = 0;
57 }
58 
60 
62  fObjectPointerState(kUnset)
63 {
64  // Construct a member inspector
65 
66  fParent = new TParentBuf();
67 }
68 
70  // Destruct a member inspector
71  delete fParent;
72 }
73 
74 const char* TMemberInspector::GetParent() const
75 {
76  // Get the parent string.
77  return *fParent;
78 }
79 
81 {
82  // Get the length of the parent string.
83  return fParent->GetLength();
84 }
85 
87 {
88  // Append "name" to the parent string.
89  fParent->Append(name);
90 }
91 
93 {
94  // Remove trailing characters starting at "startingAt".
95  fParent->Remove(startingAt);
96 }
97 
98 void TMemberInspector::Inspect(TClass *, const char *, const char *, const void *)
99 {
100  // Obsolete signature
101  Fatal("Inspect","This version of Inspect is obsolete");
102 }
103 
104 void TMemberInspector::GenericShowMembers(const char *topClassName, const void *obj,
105  Bool_t isTransient) {
106  // Call ShowMember() on obj.
107 
108  // This could be faster if we implemented this either as a templated
109  // function or by rootcint-generated code using the typeid (i.e. the
110  // difference is a lookup in a TList instead of in a map).
111 
112  // To avoid a spurious error message in case the data member is
113  // transient and does not have a dictionary we check first.
114  if (isTransient) {
115  if (!TClassEdit::IsSTLCont(topClassName)) {
116  ClassInfo_t *b = gInterpreter->ClassInfo_Factory(topClassName);
117  Bool_t isloaded = gInterpreter->ClassInfo_IsLoaded(b);
118  gInterpreter->ClassInfo_Delete(b);
119  if (!isloaded) return;
120  }
121  }
122 
123  TClass *top = TClass::GetClass(topClassName);
124  if (top) {
125  top->CallShowMembers(obj, *this, isTransient);
126  } else {
127  // This might be worth an error message
128  }
129 }
130 
131 void TMemberInspector::InspectMember(const TObject& obj, const char* name, Bool_t isTransient)
132 {
133  // Routine driving the visiting of the class information/data members.
134 
135  InspectMember<TObject>(obj, name, isTransient);
136 }
137 
138 void TMemberInspector::InspectMember(const char* topclassname, const void* pobj,
139  const char* name, Bool_t isTransient)
140 {
141  // Routine driving the visiting of the class information/data members.
142 
143  Ssiz_t len = fParent->GetLength();
144  fParent->Append(name);
145  GenericShowMembers(topclassname, pobj, isTransient);
146  fParent->Remove(len);
147 }
148 
149 void TMemberInspector::InspectMember(TClass* cl, const void* pobj, const char* name, Bool_t isTransient)
150 {
151  // Routine driving the visiting of the class information/data members.
152 
153  Ssiz_t len = fParent->GetLength();
154  fParent->Append(name);
155  cl->CallShowMembers(pobj, *this, isTransient);
156  fParent->Remove(len);
157 }
TParentBuf * fParent
void GenericShowMembers(const char *topClassName, const void *obj, Bool_t transientMember)
Ssiz_t GetParentLen() const
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
void Fatal(const char *location, const char *msgfmt,...)
bool Bool_t
Definition: RtypesCore.h:59
#define gInterpreter
Definition: TInterpreter.h:502
Abstract base class for accessing the data-members of a class.
ClassImp(TMemberInspector) TMemberInspector
const Int_t kUnset
Definition: TError.h:37
virtual ~TMemberInspector()
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void AddToParent(const char *name)
Bool_t CallShowMembers(const void *obj, TMemberInspector &insp, Bool_t isTransient=kFALSE) const
Call ShowMembers() on the obj of this class type, passing insp and parent.
Definition: TClass.cxx:2107
int Ssiz_t
Definition: RtypesCore.h:63
void RemoveFromParent(Ssiz_t startingAt)
const char * GetParent() const
void InspectMember(const T &obj, const char *name, Bool_t isTransient)
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:2801
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void Inspect(TClass *cl, const char *parent, const char *name, const void *addr)
TObject * obj