Logo ROOT   6.14/05
Reference Guide
TIndexTable.h
Go to the documentation of this file.
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@bnl.gov) 01/03/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2001 [BNL] Brookhaven National Laboratory. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TIndexTable
14 #define ROOT_TIndexTable
15 
16 #include "TTable.h"
17 
18 //////////////////////////////////////////////////////
19 //
20 // Class TIndexTable
21 // Iterator of the table with extra index array
22 //
23 //////////////////////////////////////////////////////
24 
25 
26 class TIndexTable : public TTable {
27 protected:
28  const TTable *fRefTable;
29 public:
30  class iterator {
31  protected:
32  const TTable *fTable;
33  const int *fCurrentRow;
34  iterator(): fTable(0), fCurrentRow(0) {}
35  public:
36  iterator(const TTable &t, const int &rowPtr): fTable(&t), fCurrentRow(&rowPtr){}
37  iterator(const TTable &t): fTable(&t),fCurrentRow(0){}
38  iterator(const iterator& iter) : fTable(iter.fTable), fCurrentRow(iter.fCurrentRow){}
39  iterator &operator=(const iterator& iter) {fTable = iter.fTable; fCurrentRow = iter.fCurrentRow; return *this;}
40  iterator &operator++() { if (fCurrentRow) ++fCurrentRow; return *this;}
41  void operator++(int) { if (fCurrentRow) fCurrentRow++;}
42  iterator &operator--() { if (fCurrentRow) --fCurrentRow; return *this;}
43  void operator--(int) { if (fCurrentRow) fCurrentRow--;}
44  iterator &operator+(Int_t idx) { if (fCurrentRow) fCurrentRow+=idx; return *this;}
45  iterator &operator-(Int_t idx) { if (fCurrentRow) fCurrentRow-=idx; return *this;}
46  Int_t operator-(const iterator &it) const { return fCurrentRow-it.fCurrentRow; }
47  void *operator *(){ return (void *)(fTable?((char *)fTable->GetArray())+(*fCurrentRow)*(fTable->GetRowSize()):0);}
48  operator int() { return *fCurrentRow;}
49  Bool_t operator==(const iterator &t) const { return (fCurrentRow == t.fCurrentRow); }
50  Bool_t operator!=(const iterator &t) const { return !operator==(t); }
51  };
52  TIndexTable(const TTable *table);
53  TIndexTable(const TIndexTable &indx): TTable(indx),fRefTable(indx.fRefTable) {}
54  int *GetTable(Int_t i=0);
55  Bool_t IsValid() const;
56  void push_back(Long_t next);
57 
58  const TTable *Table() const;
59  iterator begin() { return ((const TIndexTable *)this)->begin();}
60  iterator begin() const { return GetNRows() ? iterator(*Table(),*GetTable(0)):end();}
61  iterator end() { return ((const TIndexTable *)this)->end(); }
62  iterator end() const {Long_t i = GetNRows(); return i? iterator(*Table(), *GetTable(i)):iterator(*this);}
63 
64 protected:
66 
67 // define ClassDefTable(TIndexTable,int)
68 protected:
70  virtual TTableDescriptor *GetDescriptorPointer() const;
71  virtual void SetDescriptorPointer(TTableDescriptor *list);
72 public:
73  TIndexTable() : TTable("TIndexTable",sizeof(int)), fRefTable(0) {SetType("int");}
74  TIndexTable(const char *name) : TTable(name,sizeof(int)), fRefTable(0) {SetType("int");}
75  TIndexTable(Int_t n) : TTable("TIndexTable",n,sizeof(int)), fRefTable(0) {SetType("int");}
76  TIndexTable(const char *name,Int_t n) : TTable(name,n,sizeof(int)), fRefTable(0) {SetType("int");}
77  virtual ~TIndexTable() {}
78  const int *GetTable(Int_t i=0) const;
79  int &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }
80  const int &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const int *)(GetTable(i))); }
81  ClassDef(TIndexTable,4) // "Index" array for TTable object
82 };
83 
84 //___________________________________________________________________________________________________________
85 inline int *TIndexTable::GetTable(Int_t i) { return ((int *)GetArray())+i;}
86 //___________________________________________________________________________________________________________
87 inline const int *TIndexTable::GetTable(Int_t i) const { return ((int *)GetArray())+i;}
88 //___________________________________________________________________________________________________________
90 {
91  // Check whether all "map" values do belong the table
92  const TTable *cont= Table();
93  if (!cont) return kFALSE;
94 
95  iterator i = begin();
96  iterator finish = end();
97  Int_t totalSize = cont->GetNRows();
98 
99  for (; i != finish; i++) {
100  int th = i;
101  if ( th == -1 || (0 <= th && th < totalSize) ) continue;
102  return kFALSE;
103  }
104  return kTRUE;
105 }
106 //___________________________________________________________________________________________________________
107 inline void TIndexTable::push_back(Long_t next){ AddAt(&next); }
108 
109 #endif
int & operator[](Int_t i)
Definition: TIndexTable.h:79
TIndexTable(const char *name)
Definition: TIndexTable.h:74
Bool_t IsValid() const
Definition: TIndexTable.h:89
iterator begin() const
Definition: TIndexTable.h:60
TIndexTable(Int_t n)
Definition: TIndexTable.h:75
iterator & operator++()
Definition: TIndexTable.h:40
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
iterator & operator--()
Definition: TIndexTable.h:42
iterator end() const
Definition: TIndexTable.h:62
iterator(const TTable &t, const int &rowPtr)
Definition: TIndexTable.h:36
static TTableDescriptor * fgColDescriptors
Definition: TIndexTable.h:69
Bool_t operator==(const iterator &t) const
Definition: TIndexTable.h:49
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual ~TIndexTable()
Definition: TIndexTable.h:77
Int_t operator-(const iterator &it) const
Definition: TIndexTable.h:46
const int & operator[](Int_t i) const
Definition: TIndexTable.h:80
const TTable * fRefTable
Definition: TIndexTable.h:28
Bool_t operator!=(const iterator &t) const
Definition: TIndexTable.h:50
iterator & operator=(const iterator &iter)
Definition: TIndexTable.h:39
virtual void SetDescriptorPointer(TTableDescriptor *list)
set table descriptor
iterator & operator-(Int_t idx)
Definition: TIndexTable.h:45
iterator & operator+(Int_t idx)
Definition: TIndexTable.h:44
const int * fCurrentRow
Definition: TIndexTable.h:33
void push_back(Long_t next)
Definition: TIndexTable.h:107
iterator(const iterator &iter)
Definition: TIndexTable.h:38
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1972
iterator begin()
Definition: TIndexTable.h:59
iterator(const TTable &t)
Definition: TIndexTable.h:37
virtual Int_t AddAt(const void *c)
Add the "row" at the GetNRows() position, and reallocate the table if neccesary, and return the row i...
Definition: TTable.cxx:1121
void * GetArray() const
Definition: TTable.h:280
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
TIndexTable(const char *name, Int_t n)
Definition: TIndexTable.h:76
const TTable * fTable
Definition: TIndexTable.h:32
TIndexTable(const TIndexTable &indx)
Definition: TIndexTable.h:53
Definition: TTable.h:48
virtual TTableDescriptor * GetDescriptorPointer() const
return column descriptor
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1387
static TTableDescriptor * CreateDescriptor()
to be documented
Definition: TIndexTable.cxx:92
int * GetTable(Int_t i=0)
Definition: TIndexTable.h:85
iterator end()
Definition: TIndexTable.h:61
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1394
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
const TTable * Table() const
to be documented
char name[80]
Definition: TGX11.cxx:109