StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TGenericTable.h
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 
11 // //
12 // TGenericTable //
13 // //
14 // This is the class to represent the array of C-struct //
15 // defined at run-time //
16 // //
18 class TGenericTable : public TTable {
19 protected:
20  TTableDescriptor *fColDescriptors;
21  virtual TTableDescriptor *GetDescriptorPointer() const { return fColDescriptors;}
22  virtual void SetDescriptorPointer(TTableDescriptor *list) { fColDescriptors = list;}
23  void SetGenericType(){ TTable::SetType(GetDescriptorPointer()->GetName()); }
24 
25 public:
26  class iterator {
27  protected:
28  UInt_t fRowSize;
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
virtual void SetDescriptorPointer(TTableDescriptor *list)
to be documented
Definition: TGenericTable.h:22
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1395
virtual TTableDescriptor * GetDescriptorPointer() const
to be documented
Definition: TGenericTable.h:21
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1973
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
Definition: TTable.h:48
virtual ~TGenericTable()
destructor
TTableDescriptor * GetRowDescriptors() const
to be documented
Definition: TGenericTable.h:64
TTableDescriptor * GetTableDescriptors() const
protected: create a new TTableDescriptor descriptor for this table
Definition: TGenericTable.h:63