ROOT  6.06/09
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 
9 //////////////////////////////////////////////////////////////////////////
10 // //
11 // TGenericTable //
12 // //
13 // This is the class to represent the array of C-struct //
14 // defined at run-time //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 class TGenericTable : public TTable {
18 protected:
21  virtual void SetDescriptorPointer(TTableDescriptor *list) { fColDescriptors = list;}
23 
24 public:
25  class iterator {
26  protected:
28  char *fCurrentRow;
29  iterator(): fRowSize(0), fCurrentRow(0) {}
30  public:
31  iterator(UInt_t size, char &rowPtr): fRowSize(size), fCurrentRow(&rowPtr){}
32  iterator(const TTable &t, char &rowPtr): fRowSize(t.GetRowSize()), fCurrentRow(&rowPtr){}
33  iterator(const TTable &t): fRowSize(t.GetRowSize()), fCurrentRow(0){}
34  iterator(const iterator& iter) : fRowSize (iter.fRowSize), fCurrentRow(iter.fCurrentRow){}
35  iterator &operator=(const iterator& iter) { fRowSize = iter.fRowSize; fCurrentRow = iter.fCurrentRow; return *this;}
36  iterator &operator++() { if (fCurrentRow) fCurrentRow+=fRowSize; return *this;}
37  void operator++(int) { if (fCurrentRow) fCurrentRow+=fRowSize;}
38  iterator &operator--() { if (fCurrentRow) fCurrentRow-=fRowSize; return *this;}
39  void operator--(int) { if (fCurrentRow) fCurrentRow-=fRowSize;}
40  iterator &operator+(Int_t idx) { if (fCurrentRow) fCurrentRow+=idx*fRowSize; return *this;}
41  iterator &operator-(Int_t idx) { if (fCurrentRow) fCurrentRow-=idx*fRowSize; return *this;}
42  Int_t operator-(const iterator &it) const { return (fCurrentRow-it.fCurrentRow)/fRowSize; }
43  char *operator *(){ return fCurrentRow;}
44  Bool_t operator==(const iterator &t) const { return (fCurrentRow == t.fCurrentRow); }
45  Bool_t operator!=(const iterator &t) const { return !operator==(t); }
46  };
47  TGenericTable() : TTable("TGenericTable",-1), fColDescriptors(0) {SetType("generic");}
48 
49  // Create TGenericTable by C structure name provided
50  TGenericTable(const char *structName, const char *name);
51  TGenericTable(const char *structName, Int_t n);
52  TGenericTable(const char *structName, const char *name,Int_t n);
53 
54  // Create TGenericTable by TTableDescriptor pointer
55  TGenericTable(const TTableDescriptor &dsc, const char *name);
57  TGenericTable(const TTableDescriptor &dsc,const char *name,Int_t n);
58 
59  virtual ~TGenericTable();
60 
61  char *GetTable(Int_t i=0) const { return ((char *)GetArray())+i*GetRowSize();}
64  char &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }
65  const char &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const char *)(GetTable(i))); }
66  iterator begin() { return ((const TGenericTable *)this)->begin();}
67  iterator begin() const { return GetNRows() ? iterator(*this, *GetTable(0)):end();}
68  iterator end() { return ((const TGenericTable *)this)->end(); }
69  iterator end() const {Long_t i = GetNRows(); return i? iterator(*this, *GetTable(i)):iterator(*this);}
70  ClassDef(TGenericTable,4) // Generic array of C-structure (a'la STL vector)
71 };
72 
73 #endif
iterator end()
Definition: TGenericTable.h:68
void * GetArray() const
Definition: TTable.h:284
iterator & operator=(const iterator &iter)
Definition: TGenericTable.h:35
char & operator[](Int_t i)
Definition: TGenericTable.h:64
Int_t operator-(const iterator &it) const
Definition: TGenericTable.h:42
virtual void SetDescriptorPointer(TTableDescriptor *list)
to be documented
Definition: TGenericTable.h:21
#define assert(cond)
Definition: unittest.h:542
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1399
virtual TTableDescriptor * GetDescriptorPointer() const
to be documented
Definition: TGenericTable.h:20
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TTableDescriptor * fColDescriptors
Definition: TGenericTable.h:19
iterator begin() const
Definition: TGenericTable.h:67
Bool_t operator!=(const iterator &t) const
Definition: TGenericTable.h:45
const char & operator[](Int_t i) const
Definition: TGenericTable.h:65
#define ClassDef(name, id)
Definition: Rtypes.h:254
iterator end() const
Definition: TGenericTable.h:69
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
iterator(const TTable &t)
Definition: TGenericTable.h:33
Bool_t operator==(const iterator &t) const
Definition: TGenericTable.h:44
iterator(const iterator &iter)
Definition: TGenericTable.h:34
iterator & operator+(Int_t idx)
Definition: TGenericTable.h:40
iterator(UInt_t size, char &rowPtr)
Definition: TGenericTable.h:31
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1983
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1392
unsigned int UInt_t
Definition: RtypesCore.h:42
void SetGenericType()
Definition: TGenericTable.h:22
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
char * GetTable(Int_t i=0) const
Definition: TGenericTable.h:61
iterator(const TTable &t, char &rowPtr)
Definition: TGenericTable.h:32
long Long_t
Definition: RtypesCore.h:50
Definition: TTable.h:52
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual ~TGenericTable()
destructor
iterator & operator-(Int_t idx)
Definition: TGenericTable.h:41
TTableDescriptor * GetRowDescriptors() const
to be documented
Definition: TGenericTable.h:63
TTableDescriptor * GetTableDescriptors() const
Definition: TGenericTable.h:62
iterator begin()
Definition: TGenericTable.h:66
const Int_t n
Definition: legend1.C:16