TGenericTable.h

Go to the documentation of this file.
00001 // @(#)root/table:$Id: TGenericTable.h 27157 2009-01-15 14:05:12Z brun $
00002 // Author: Valery Fine(fine@bnl.gov)   30/06/2001
00003 
00004 #ifndef ROOT_TGenericTable
00005 #define ROOT_TGenericTable
00006 
00007 #include "TTable.h"
00008 
00009 //////////////////////////////////////////////////////////////////////////
00010 //                                                                      //
00011 //  TGenericTable                                                       //
00012 //                                                                      //
00013 //  This is the class to represent the array of C-struct                //
00014 //  defined at run-time                                                 //
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    // Create TGenericTable by C structure name provided
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    // Create TGenericTable by TTableDescriptor pointer
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) // Generic array of C-structure (a'la STL vector)
00071 };
00072  
00073 #endif

Generated on Tue Jul 5 14:26:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1