Logo ROOT   6.12/07
Reference Guide
TGenericTable.h
Go to the documentation of this file.
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@bnl.gov) 30/06/2001
3 
4 #ifndef ROOT_TGenericTable
5 #define ROOT_TGenericTable
6 
7 #include "TTable.h"
8 #include "TTableDescriptor.h"
9 
10 //////////////////////////////////////////////////////////////////////////
11 // //
12 // TGenericTable //
13 // //
14 // This is the class to represent the array of C-struct //
15 // defined at run-time //
16 // //
17 //////////////////////////////////////////////////////////////////////////
18 class TGenericTable : public TTable {
19 protected:
22  virtual void SetDescriptorPointer(TTableDescriptor *list) { fColDescriptors = list;}
24 
25 public:
26  class iterator {
27  protected:
29  char *fCurrentRow;
30  iterator(): fRowSize(0), fCurrentRow(0) {}
31  public:
32  iterator(UInt_t size, char &rowPtr): fRowSize(size), fCurrentRow(&rowPtr){}
33  iterator(const TTable &t, char &rowPtr): fRowSize(t.GetRowSize()), fCurrentRow(&rowPtr){}
34  iterator(const TTable &t): fRowSize(t.GetRowSize()), fCurrentRow(0){}
35  iterator(const iterator& iter) : fRowSize (iter.fRowSize), fCurrentRow(iter.fCurrentRow){}
36  iterator &operator=(const iterator& iter) { fRowSize = iter.fRowSize; fCurrentRow = iter.fCurrentRow; return *this;}
37  iterator &operator++() { if (fCurrentRow) fCurrentRow+=fRowSize; return *this;}
38  void operator++(int) { if (fCurrentRow) fCurrentRow+=fRowSize;}
39  iterator &operator--() { if (fCurrentRow) fCurrentRow-=fRowSize; return *this;}
40  void operator--(int) { if (fCurrentRow) fCurrentRow-=fRowSize;}
41  iterator &operator+(Int_t idx) { if (fCurrentRow) fCurrentRow+=idx*fRowSize; return *this;}
42  iterator &operator-(Int_t idx) { if (fCurrentRow) fCurrentRow-=idx*fRowSize; return *this;}
43  Int_t operator-(const iterator &it) const { return (fCurrentRow-it.fCurrentRow)/fRowSize; }
44  char *operator *(){ return fCurrentRow;}
45  Bool_t operator==(const iterator &t) const { return (fCurrentRow == t.fCurrentRow); }
46  Bool_t operator!=(const iterator &t) const { return !operator==(t); }
47  };
48  TGenericTable() : TTable("TGenericTable",-1), fColDescriptors(0) {SetType("generic");}
49 
50  // Create TGenericTable by C structure name provided
51  TGenericTable(const char *structName, const char *name);
52  TGenericTable(const char *structName, Int_t n);
53  TGenericTable(const char *structName, const char *name,Int_t n);
54 
55  // Create TGenericTable by TTableDescriptor pointer
56  TGenericTable(const TTableDescriptor &dsc, const char *name);
57  TGenericTable(const TTableDescriptor &dsc, Int_t n);
58  TGenericTable(const TTableDescriptor &dsc,const char *name,Int_t n);
59 
60  virtual ~TGenericTable();
61 
62  char *GetTable(Int_t i=0) const { return ((char *)GetArray())+i*GetRowSize();}
65  char &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }
66  const char &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const char *)(GetTable(i))); }
67  iterator begin() { return ((const TGenericTable *)this)->begin();}
68  iterator begin() const { return GetNRows() ? iterator(*this, *GetTable(0)):end();}
69  iterator end() { return ((const TGenericTable *)this)->end(); }
70  iterator end() const {Long_t i = GetNRows(); return i? iterator(*this, *GetTable(i)):iterator(*this);}
71  ClassDef(TGenericTable,4) // Generic array of C-structure (a'la STL vector)
72 };
73 
74 #endif
iterator end()
Definition: TGenericTable.h:69
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Bool_t operator!=(const iterator &t) const
Definition: TGenericTable.h:46
iterator & operator=(const iterator &iter)
Definition: TGenericTable.h:36
virtual TTableDescriptor * GetDescriptorPointer() const
to be documented
Definition: TGenericTable.h:21
char & operator[](Int_t i)
Definition: TGenericTable.h:65
TTableDescriptor * GetRowDescriptors() const
to be documented
Definition: TGenericTable.h:64
virtual void SetDescriptorPointer(TTableDescriptor *list)
to be documented
Definition: TGenericTable.h:22
TTableDescriptor * GetTableDescriptors() const
protected: create a new TTableDescriptor descriptor for this table
Definition: TGenericTable.h:63
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TTableDescriptor * fColDescriptors
Definition: TGenericTable.h:20
#define ClassDef(name, id)
Definition: Rtypes.h:320
iterator begin() const
Definition: TGenericTable.h:68
iterator(const TTable &t)
Definition: TGenericTable.h:34
iterator(const iterator &iter)
Definition: TGenericTable.h:35
iterator & operator+(Int_t idx)
Definition: TGenericTable.h:41
iterator(UInt_t size, char &rowPtr)
Definition: TGenericTable.h:32
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1972
unsigned int UInt_t
Definition: RtypesCore.h:42
void SetGenericType()
Definition: TGenericTable.h:23
iterator end() const
Definition: TGenericTable.h:70
void * GetArray() const
Definition: TTable.h:280
const char & operator[](Int_t i) const
Definition: TGenericTable.h:66
Bool_t operator==(const iterator &t) const
Definition: TGenericTable.h:45
iterator(const TTable &t, char &rowPtr)
Definition: TGenericTable.h:33
long Long_t
Definition: RtypesCore.h:50
Int_t operator-(const iterator &it) const
Definition: TGenericTable.h:43
Definition: TTable.h:48
virtual ~TGenericTable()
destructor
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1387
iterator & operator-(Int_t idx)
Definition: TGenericTable.h:42
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1394
char * GetTable(Int_t i=0) const
Definition: TGenericTable.h:62
iterator begin()
Definition: TGenericTable.h:67
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109