00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include "TROOT.h"
00005 #include "TClass.h"
00006 #include "TBaseClass.h"
00007 #include "TDataMember.h"
00008 #include "TMethod.h"
00009 #include "TMethodArg.h"
00010 #include "TDataType.h"
00011 #include "Api.h"
00012 #include "TBrowser.h"
00013 #include "TMemberInspector.h"
00014 #include "TError.h"
00015 #include "StAutoBrowse.h"
00016
00017 class StAutoInspector : public TMemberInspector {
00018 public:
00019 StAutoInspector(TBrowser *b){fBrowser=b;fCount=0;};
00020 virtual ~StAutoInspector(){};
00021 virtual void Inspect(TClass* cl, const char* parent, const char* name, const void* addr);
00022
00023 Int_t fCount;
00024 TBrowser *fBrowser;
00025 };
00026
00027 void StAutoInspector::Inspect(TClass* kl, const char* tit , const char* name, const void* addr)
00028 {
00029 if(tit && strchr(tit,'.')) return ;
00030 if (fCount && !fBrowser) return;
00031
00032 TString ts;
00033
00034 if (!kl) return;
00035 if (*(kl->GetName()) == 'T') return;
00036 if (*name == '*') name++;
00037 int ln = strcspn(name,"[ ");
00038 TString iname(name,ln);
00039
00040 G__ClassInfo *classInfo = (G__ClassInfo*) kl->GetClassInfo();
00041 if (!classInfo) return;
00042 G__ClassInfo &cl = *classInfo;
00043
00044
00045
00046 G__DataMemberInfo m(cl);
00047 TString mname;
00048
00049 int found=0;
00050 while (m.Next()) {
00051 mname = m.Name();
00052 mname.ReplaceAll("*","");
00053 if ((found = (iname==mname))) break;
00054 }
00055 assert(found);
00056
00057
00058
00059
00060 long prop = m.Property() | m.Type()->Property();
00061 if (prop & G__BIT_ISSTATIC) return;
00062 if (prop & G__BIT_ISFUNDAMENTAL) return;
00063 if (prop & G__BIT_ISENUM) return;
00064 if (strcmp(m.Type()->Fullname(),"TObject") && !m.Type()->IsBase("TObject"))
00065 return;
00066 if (mname == "G__virtualinfo") return;
00067
00068 int size = sizeof(void*);
00069 if (!(prop&G__BIT_ISPOINTER)) size = m.Type()->Size();
00070
00071 int nmax = 1;
00072 if (prop & G__BIT_ISARRAY) {
00073 for (int dim = 0; dim < m.ArrayDim(); dim++) nmax *= m.MaxIndex(dim);
00074 }
00075
00076 for(int i=0; i<nmax; i++) {
00077 char *ptr = (char*)addr + i*size;
00078 TObject *obj = (prop&G__BIT_ISPOINTER) ? *((TObject**)ptr) : (TObject*)ptr;
00079 if (!obj) continue;
00080 fCount++;
00081 if (!fBrowser) return;
00082 const char *bwname = obj->GetName();
00083 if (!bwname[0] || strcmp(bwname,obj->ClassName())==0) {
00084 bwname = name;
00085 if (strcmp(bwname,"fOrBrowser")==0) {
00086 ts.Replace(0,999,tit,strlen(tit)-1);
00087 bwname = (const char*)ts;
00088 } else {
00089 int l = strcspn(bwname,"[ ");
00090 if (bwname[l]=='[') {
00091 char cbuf[12]; sprintf(cbuf,"[%02d]",i);
00092 ts.Replace(0,999,bwname,l);
00093 ts += cbuf;
00094 bwname = (const char*)ts;
00095 }
00096 }
00097 }
00098
00099 fBrowser->Add(obj,bwname);
00100 }
00101
00102 }
00103
00104
00105 Int_t StAutoBrowse::Browse(TObject *obj,TBrowser *browser)
00106 {
00107 if(!obj) return 0;
00108 char cbuf[1000]; *cbuf=0;
00109
00110 StAutoInspector insp(browser);
00111 ((TObject*)obj)->ShowMembers(insp,cbuf);
00112 return insp.fCount;
00113 }