1 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include "TROOT.h" 5 #include "TClass.h" 6 #include "TBaseClass.h" 7 #include "TDataMember.h" 8 #include "TMethod.h" 9 #include "TMethodArg.h" 10 #include "TDataType.h" 11 #include "Api.h" 12 #include "TBrowser.h" 13 #include "TMemberInspector.h" 14 #include "TError.h" 15 #include "StAutoBrowse.h" 16 17 class StAutoInspector : public TMemberInspector { 18 public: 19 StAutoInspector(TBrowser *b){fBrowser=b;fCount=0;}; 20 virtual ~StAutoInspector(){}; 21 virtual void Inspect(TClass* cl, const char* parent, const char* name, const void* addr); 22 23 Int_t fCount; 24 TBrowser *fBrowser; 25 }; 26 //______________________________________________________________________________ 27 void StAutoInspector::Inspect(TClass* kl, const char* tit , const char* name, const void* addr) 28 { 29 if(tit && strchr(tit,'.')) return ; 30 if (fCount && !fBrowser) return; 31 32 TString ts; 33 34 if (!kl) return; 35 if (*(kl->GetName()) == 'T') return; 36 if (*name == '*') name++; 37 int ln = strcspn(name,"[ "); 38 TString iname(name,ln); 39 40 G__ClassInfo *classInfo = (G__ClassInfo*) kl->GetClassInfo(); 41 if (!classInfo) return; 42 G__ClassInfo &cl = *classInfo; 43 44 45 // Browse data members 46 G__DataMemberInfo m(cl); 47 TString mname; 48 49 int found=0; 50 while (m.Next()) { // MemberLoop 51 mname = m.Name(); 52 mname.ReplaceAll("*",""); 53 if ((found = (iname==mname))) break; 54 } 55 assert(found); 56 57 // we skip: non TObjects 58 // - the member G__virtualinfo inserted by the CINT RTTI system 59 60 long prop = m.Property() | m.Type()->Property(); 61 if (prop & G__BIT_ISSTATIC) return; 62 if (prop & G__BIT_ISFUNDAMENTAL) return; 63 if (prop & G__BIT_ISENUM) return; 64 if (strcmp(m.Type()->Fullname(),"TObject") && !m.Type()->IsBase("TObject")) 65 return; 66 if (mname == "G__virtualinfo") return; 67 68 int size = sizeof(void*); 69 if (!(prop&G__BIT_ISPOINTER)) size = m.Type()->Size(); 70 71 int nmax = 1; 72 if (prop & G__BIT_ISARRAY) { 73 for (int dim = 0; dim < m.ArrayDim(); dim++) nmax *= m.MaxIndex(dim); 74 } 75 76 for(int i=0; i<nmax; i++) { 77 char *ptr = (char*)addr + i*size; 78 TObject *obj = (prop&G__BIT_ISPOINTER) ? *((TObject**)ptr) : (TObject*)ptr; 79 if (!obj) continue; 80 fCount++; 81 if (!fBrowser) return; 82 const char *bwname = obj->GetName(); 83 if (!bwname[0] || strcmp(bwname,obj->ClassName())==0) { 84 bwname = name; 85 if (strcmp(bwname,"fOrBrowser")==0) { 86 ts.Replace(0,999,tit,strlen(tit)-1); 87 bwname = (const char*)ts; 88 } else { 89 int l = strcspn(bwname,"[ "); 90 if (bwname[l]=='[') { 91 char cbuf[12]; sprintf(cbuf,"[%02d]",i); 92 ts.Replace(0,999,bwname,l); 93 ts += cbuf; 94 bwname = (const char*)ts; 95 } 96 } 97 } 98 99 fBrowser->Add(obj,bwname); 100 } 101 102 } 103 104 //______________________________________________________________________________ 105 Int_t StAutoBrowse::Browse(TObject *obj,TBrowser *browser) 106 { 107 if(!obj) return 0; 108 StAutoInspector insp(browser); 109 #if ROOT_VERSION_CODE < 334597 110 char cbuf[1000]; *cbuf=0; 111 112 ((TObject*)obj)->ShowMembers(insp,cbuf); 113 #else 114 ((TObject*)obj)->ShowMembers(insp); 115 #endif 116 return insp.fCount; 117 } 118