Logo ROOT   6.16/01
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//////////////////////////////////////////////////////////////////////////
18class TGenericTable : public TTable {
19protected:
24
25public:
26 class iterator {
27 protected:
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;}
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
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:324
iterator & operator+(Int_t idx)
Definition: TGenericTable.h:41
Int_t operator-(const iterator &it) const
Definition: TGenericTable.h:43
iterator(const iterator &iter)
Definition: TGenericTable.h:35
iterator(const TTable &t)
Definition: TGenericTable.h:34
iterator & operator=(const iterator &iter)
Definition: TGenericTable.h:36
Bool_t operator==(const iterator &t) const
Definition: TGenericTable.h:45
iterator(UInt_t size, char &rowPtr)
Definition: TGenericTable.h:32
Bool_t operator!=(const iterator &t) const
Definition: TGenericTable.h:46
iterator & operator-(Int_t idx)
Definition: TGenericTable.h:42
iterator(const TTable &t, char &rowPtr)
Definition: TGenericTable.h:33
void SetGenericType()
Definition: TGenericTable.h:23
iterator end()
Definition: TGenericTable.h:69
TTableDescriptor * fColDescriptors
Definition: TGenericTable.h:20
virtual TTableDescriptor * GetDescriptorPointer() const
to be documented
Definition: TGenericTable.h:21
char & operator[](Int_t i)
Definition: TGenericTable.h:65
char * GetTable(Int_t i=0) const
Definition: TGenericTable.h:62
TTableDescriptor * GetTableDescriptors() const
protected: create a new TTableDescriptor descriptor for this table
Definition: TGenericTable.h:63
TGenericTable(const TTableDescriptor &dsc, const char *name)
virtual void SetDescriptorPointer(TTableDescriptor *list)
to be documented
Definition: TGenericTable.h:22
const char & operator[](Int_t i) const
Definition: TGenericTable.h:66
iterator begin()
Definition: TGenericTable.h:67
virtual ~TGenericTable()
destructor
TTableDescriptor * GetRowDescriptors() const
to be documented
Definition: TGenericTable.h:64
iterator end() const
Definition: TGenericTable.h:70
iterator begin() const
Definition: TGenericTable.h:68
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Definition: TTable.h:48
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1394
void * GetArray() const
Definition: TTable.h:280
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1972
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1387
const Int_t n
Definition: legend1.C:16