00001
00002
00003
00004 #ifndef ROOT_TGenericTable
00005 #define ROOT_TGenericTable
00006
00007 #include "TTable.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 class TGenericTable : public TTable {
00018 protected:
00019 TTableDescriptor *fColDescriptors;
00020 virtual TTableDescriptor *GetDescriptorPointer() const { return fColDescriptors;}
00021 virtual void SetDescriptorPointer(TTableDescriptor *list) { fColDescriptors = list;}
00022 void SetGenericType(){ TTable::SetType(GetDescriptorPointer()->GetName()); }
00023
00024 public:
00025 class iterator {
00026 protected:
00027 UInt_t fRowSize;
00028 char *fCurrentRow;
00029 iterator(): fRowSize(0), fCurrentRow(0) {}
00030 public:
00031 iterator(UInt_t size, char &rowPtr): fRowSize(size), fCurrentRow(&rowPtr){}
00032 iterator(const TTable &t, char &rowPtr): fRowSize(t.GetRowSize()), fCurrentRow(&rowPtr){}
00033 iterator(const TTable &t): fRowSize(t.GetRowSize()), fCurrentRow(0){}
00034 iterator(const iterator& iter) : fRowSize (iter.fRowSize), fCurrentRow(iter.fCurrentRow){}
00035 iterator &operator=(const iterator& iter) { fRowSize = iter.fRowSize; fCurrentRow = iter.fCurrentRow; return *this;}
00036 iterator &operator++() { if (fCurrentRow) fCurrentRow+=fRowSize; return *this;}
00037 void operator++(int) { if (fCurrentRow) fCurrentRow+=fRowSize;}
00038 iterator &operator--() { if (fCurrentRow) fCurrentRow-=fRowSize; return *this;}
00039 void operator--(int) { if (fCurrentRow) fCurrentRow-=fRowSize;}
00040 iterator &operator+(Int_t idx) { if (fCurrentRow) fCurrentRow+=idx*fRowSize; return *this;}
00041 iterator &operator-(Int_t idx) { if (fCurrentRow) fCurrentRow-=idx*fRowSize; return *this;}
00042 Int_t operator-(const iterator &it) const { return (fCurrentRow-it.fCurrentRow)/fRowSize; }
00043 char *operator *(){ return fCurrentRow;}
00044 Bool_t operator==(const iterator &t) const { return (fCurrentRow == t.fCurrentRow); }
00045 Bool_t operator!=(const iterator &t) const { return !operator==(t); }
00046 };
00047 TGenericTable() : TTable("TGenericTable",-1), fColDescriptors(0) {SetType("generic");}
00048
00049
00050 TGenericTable(const char *structName, const char *name);
00051 TGenericTable(const char *structName, Int_t n);
00052 TGenericTable(const char *structName, const char *name,Int_t n);
00053
00054
00055 TGenericTable(const TTableDescriptor &dsc, const char *name);
00056 TGenericTable(const TTableDescriptor &dsc, Int_t n);
00057 TGenericTable(const TTableDescriptor &dsc,const char *name,Int_t n);
00058
00059 virtual ~TGenericTable();
00060
00061 char *GetTable(Int_t i=0) const { return ((char *)GetArray())+i*GetRowSize();}
00062 TTableDescriptor *GetTableDescriptors() const { return GetDescriptorPointer();}
00063 TTableDescriptor *GetRowDescriptors() const { return GetDescriptorPointer();}
00064 char &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }
00065 const char &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const char *)(GetTable(i))); }
00066 iterator begin() { return ((const TGenericTable *)this)->begin();}
00067 iterator begin() const { return GetNRows() ? iterator(*this, *GetTable(0)):end();}
00068 iterator end() { return ((const TGenericTable *)this)->end(); }
00069 iterator end() const {Long_t i = GetNRows(); return i? iterator(*this, *GetTable(i)):iterator(*this);}
00070 ClassDef(TGenericTable,4)
00071 };
00072
00073 #endif