ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROOT_TTable
17 #include "TTable.h"
18 #endif
19 
20 //////////////////////////////////////////////////////
21 //
22 // Class TIndexTable
23 // Iterator of the table with extra index array
24 //
25 //////////////////////////////////////////////////////
26 
27 
28 class TIndexTable : public TTable {
29 protected:
30  const TTable *fRefTable;
31 public:
32  class iterator {
33  protected:
34  const TTable *fTable;
35  const int *fCurrentRow;
37  public:
38  iterator(const TTable &t, const int &rowPtr): fTable(&t), fCurrentRow(&rowPtr){}
39  iterator(const TTable &t): fTable(&t),fCurrentRow(0){}
41  iterator &operator=(const iterator& iter) {fTable = iter.fTable; fCurrentRow = iter.fCurrentRow; return *this;}
42  iterator &operator++() { if (fCurrentRow) ++fCurrentRow; return *this;}
43  void operator++(int) { if (fCurrentRow) fCurrentRow++;}
44  iterator &operator--() { if (fCurrentRow) --fCurrentRow; return *this;}
45  void operator--(int) { if (fCurrentRow) fCurrentRow--;}
46  iterator &operator+(Int_t idx) { if (fCurrentRow) fCurrentRow+=idx; return *this;}
47  iterator &operator-(Int_t idx) { if (fCurrentRow) fCurrentRow-=idx; return *this;}
48  Int_t operator-(const iterator &it) const { return fCurrentRow-it.fCurrentRow; }
49  void *operator *(){ return (void *)(fTable?((char *)fTable->GetArray())+(*fCurrentRow)*(fTable->GetRowSize()):0);}
50  operator int() { return *fCurrentRow;}
51  Bool_t operator==(const iterator &t) const { return (fCurrentRow == t.fCurrentRow); }
52  Bool_t operator!=(const iterator &t) const { return !operator==(t); }
53  };
54  TIndexTable(const TTable *table);
55  TIndexTable(const TIndexTable &indx): TTable(indx),fRefTable(indx.fRefTable) {}
56  int *GetTable(Int_t i=0);
57  Bool_t IsValid() const;
58  void push_back(Long_t next);
59 
60  const TTable *Table() const;
61  iterator begin() { return ((const TIndexTable *)this)->begin();}
62  iterator begin() const { return GetNRows() ? iterator(*Table(),*GetTable(0)):end();}
63  iterator end() { return ((const TIndexTable *)this)->end(); }
64  iterator end() const {Long_t i = GetNRows(); return i? iterator(*Table(), *GetTable(i)):iterator(*this);}
65 
66 protected:
68 
69 // define ClassDefTable(TIndexTable,int)
70 protected:
72  virtual TTableDescriptor *GetDescriptorPointer() const;
73  virtual void SetDescriptorPointer(TTableDescriptor *list);
74 public:
75  TIndexTable() : TTable("TIndexTable",sizeof(int)), fRefTable(0) {SetType("int");}
76  TIndexTable(const char *name) : TTable(name,sizeof(int)), fRefTable(0) {SetType("int");}
77  TIndexTable(Int_t n) : TTable("TIndexTable",n,sizeof(int)), fRefTable(0) {SetType("int");}
78  TIndexTable(const char *name,Int_t n) : TTable(name,n,sizeof(int)), fRefTable(0) {SetType("int");}
79  virtual ~TIndexTable() {}
80  const int *GetTable(Int_t i=0) const;
81  int &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }
82  const int &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const int *)(GetTable(i))); }
83  ClassDef(TIndexTable,4) // "Index" array for TTable object
84 };
85 
86 //___________________________________________________________________________________________________________
87 inline int *TIndexTable::GetTable(Int_t i) { return ((int *)GetArray())+i;}
88 //___________________________________________________________________________________________________________
89 inline const int *TIndexTable::GetTable(Int_t i) const { return ((int *)GetArray())+i;}
90 //___________________________________________________________________________________________________________
92 {
93  // Check whether all "map" values do belong the table
94  const TTable *cont= Table();
95  if (!cont) return kFALSE;
96 
97  iterator i = begin();
98  iterator finish = end();
99  Int_t totalSize = cont->GetNRows();
100 
101  for (; i != finish; i++) {
102  int th = i;
103  if ( th == -1 || (0 <= th && th < totalSize) ) continue;
104  return kFALSE;
105  }
106  return kTRUE;
107 }
108 //___________________________________________________________________________________________________________
109 inline void TIndexTable::push_back(Long_t next){ AddAt(&next); }
110 
111 #endif
int & operator[](Int_t i)
Definition: TIndexTable.h:81
void * GetArray() const
Definition: TTable.h:284
TIndexTable(const char *name)
Definition: TIndexTable.h:76
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
#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
iterator begin() const
Definition: TIndexTable.h:62
TIndexTable(Int_t n)
Definition: TIndexTable.h:77
iterator & operator++()
Definition: TIndexTable.h:42
Int_t operator-(const iterator &it) const
Definition: TIndexTable.h:48
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
iterator & operator--()
Definition: TIndexTable.h:44
iterator(const TTable &t, const int &rowPtr)
Definition: TIndexTable.h:38
static TTableDescriptor * fgColDescriptors
Definition: TIndexTable.h:71
iterator end() const
Definition: TIndexTable.h:64
Bool_t operator==(const iterator &t) const
Definition: TIndexTable.h:51
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual ~TIndexTable()
Definition: TIndexTable.h:79
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
const TTable * fRefTable
Definition: TIndexTable.h:30
iterator & operator=(const iterator &iter)
Definition: TIndexTable.h:41
Bool_t IsValid() const
Definition: TIndexTable.h:91
const TTable * Table() const
to be documented
virtual void SetDescriptorPointer(TTableDescriptor *list)
set table descriptor
iterator & operator-(Int_t idx)
Definition: TIndexTable.h:47
iterator & operator+(Int_t idx)
Definition: TIndexTable.h:46
const int * fCurrentRow
Definition: TIndexTable.h:35
void push_back(Long_t next)
Definition: TIndexTable.h:109
TThread * t[5]
Definition: threadsh1.C:13
iterator(const iterator &iter)
Definition: TIndexTable.h:40
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1983
iterator begin()
Definition: TIndexTable.h:61
iterator(const TTable &t)
Definition: TIndexTable.h:39
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1392
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:1126
const int & operator[](Int_t i) const
Definition: TIndexTable.h:82
Bool_t operator!=(const iterator &t) const
Definition: TIndexTable.h:52
long Long_t
Definition: RtypesCore.h:50
TIndexTable(const char *name, Int_t n)
Definition: TIndexTable.h:78
const TTable * fTable
Definition: TIndexTable.h:34
TIndexTable(const TIndexTable &indx)
Definition: TIndexTable.h:55
Definition: TTable.h:52
#define name(a, b)
Definition: linkTestLib0.cpp:5
static TTableDescriptor * CreateDescriptor()
to be documented
Definition: TIndexTable.cxx:92
int * GetTable(Int_t i=0)
Definition: TIndexTable.h:87
iterator end()
Definition: TIndexTable.h:63
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
virtual TTableDescriptor * GetDescriptorPointer() const
return column descriptor