ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
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){}
36  iterator &operator=(const iterator& iter) { fRowSize = iter.fRowSize; fCurrentRow = iter.fCurrentRow; return *this;}
37  iterator &operator++() { if (fCurrentRow) fCurrentRow+=fRowSize; return *this;}
39  iterator &operator--() { if (fCurrentRow) fCurrentRow-=fRowSize; return *this;}
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);
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
void * GetArray() const
Definition: TTable.h:284
iterator & operator=(const iterator &iter)
Definition: TGenericTable.h:36
char & operator[](Int_t i)
Definition: TGenericTable.h:65
Int_t operator-(const iterator &it) const
Definition: TGenericTable.h:43
virtual void SetDescriptorPointer(TTableDescriptor *list)
to be documented
Definition: TGenericTable.h:22
#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:21
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TTableDescriptor * fColDescriptors
Definition: TGenericTable.h:20
iterator begin() const
Definition: TGenericTable.h:68
Bool_t operator!=(const iterator &t) const
Definition: TGenericTable.h:46
const char & operator[](Int_t i) const
Definition: TGenericTable.h:66
#define ClassDef(name, id)
Definition: Rtypes.h:254
iterator end() const
Definition: TGenericTable.h:70
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
iterator(const TTable &t)
Definition: TGenericTable.h:34
Bool_t operator==(const iterator &t) const
Definition: TGenericTable.h:45
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
TThread * t[5]
Definition: threadsh1.C:13
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:23
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
char * GetTable(Int_t i=0) const
Definition: TGenericTable.h:62
iterator(const TTable &t, char &rowPtr)
Definition: TGenericTable.h:33
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:42
TTableDescriptor * GetRowDescriptors() const
to be documented
Definition: TGenericTable.h:64
TTableDescriptor * GetTableDescriptors() const
Definition: TGenericTable.h:63
iterator begin()
Definition: TGenericTable.h:67
const Int_t n
Definition: legend1.C:16