// @(#)root/table:$Id$
// Author: Valery Fine(fine@bnl.gov)   13/03/2000

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TChair
#define ROOT_TChair

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TChair                                                              //
//                                                                      //
//  It is a base class to create a custom interface for TTable objects  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TTable.h"

class TChair : public TDataSet {

protected:

   TTable  *fTable;     // the "TTable" object this object is pthe proxy for
   ULong_t  fLastIndx;  // index pof the last used  table row;
   void    *fLastRow;   // pointer to the last used table row; fLastRow = table[fLastIndx]

         TTable *GetThisTable()       {return fTable; }
   const TTable *GetThisTable() const {return fTable; }
   static void  *GetOffset(const void *base,ULong_t offset) { return (void  *)((Char_t *)base + offset);}
   TChair() : fTable(0), fLastIndx(0), fLastRow(0) { ; }

public:

   TChair(TTable *table) : fTable(table),fLastIndx(0),fLastRow(0) { ; }
   TChair(const TChair &org) : TDataSet(org) {assert(0);}
//   TChair     &operator=(const TChair &rhs){ assert(0); return rhs;}
   virtual    ~TChair(){;}

   virtual     void       Adopt(Int_t n, void *array){GetThisTable()->Adopt(n,array);}
   virtual     void       AddAt(TDataSet *dataset,Int_t idx);
   virtual     void       AddAt(const void *c, Int_t i){GetThisTable()->AddAt(c,i);}
              const void *At(Int_t i) const {return GetThisTable()->At(i);}
   virtual     void       Browse(TBrowser *b){GetThisTable()->Browse(b);}
   virtual     void       CopySet(TChair &chair){GetThisTable()->CopySet(*chair.GetThisTable());}
               Int_t      CopyRows(const TChair *srcChair, Int_t srcRow=0, Int_t dstRow=0, Int_t nRows=0, Bool_t expand=kFALSE)
                          {return GetThisTable()->CopyRows(srcChair->GetThisTable(),srcRow,dstRow,nRows,expand);}
   virtual     void       Draw(Option_t *opt){GetThisTable()->Draw(opt);}
   virtual     TH1       *Draw(TCut varexp, TCut selection, Option_t *option="",
                          Int_t nentries=1000000000, Int_t firstentry=0)
                          {return GetThisTable()->Draw(varexp,selection,option,nentries,firstentry);}
   virtual     TH1       *Draw(const char *varexp, const char *selection, Option_t *option="",
                               Int_t nentries=1000000000, Int_t firstentry=0) {
                           return GetThisTable()->Draw(varexp,selection,option,nentries,firstentry);}
   virtual     Char_t    *GetArray() const    {return (Char_t *)GetThisTable()->GetArray();}
   virtual     TClass    *GetRowClass() const {return GetThisTable()->GetRowClass();}
   virtual     Long_t     GetNRows() const    {return GetThisTable()->GetNRows();}
   virtual     Long_t     GetRowSize() const  {return GetThisTable()->GetRowSize();}
   virtual     Long_t     GetTableSize() const{return GetThisTable()->GetTableSize();}
               const TTable  *Table() const {return fTable; }
   virtual     TTableDescriptor *GetRowDescriptors()   const {return GetThisTable()->GetRowDescriptors();}
   virtual     const Char_t       *GetType()             const {return GetThisTable()->GetType();}
   virtual     void       Fit(const char *formula ,const char *varexp, const char *selection="",Option_t *option="",Option_t *goption="",
                              Int_t nentries=1000000000, Int_t firstentry=0) {
                           GetThisTable()->Fit(formula,varexp,selection,option,goption,nentries,firstentry);}
   virtual     Long_t     HasData() const  { return GetThisTable()->HasData();}
   virtual     Bool_t     IsFolder() const { return GetThisTable()->IsFolder();}
   virtual     void       ls(Option_t *option="") const {GetThisTable()->ls(option);}
   virtual     void       ls(Int_t deep) const  {GetThisTable()->ls(deep);}
               Int_t      NaN()           {return GetThisTable()->NaN();}
   virtual     Char_t    *MakeExpression(const Char_t *expressions[],Int_t nExpressions)
                         {return GetThisTable()->MakeExpression(expressions,nExpressions);}
   virtual     Char_t    *Print(Char_t *buf,Int_t n) const { return GetThisTable()->Print(buf, n);}
   virtual     void       Print(Option_t *opt="")    const {GetThisTable()->Print(opt);}
   virtual  const Char_t *Print(Int_t row, Int_t rownumber=10,
                                const Char_t *colfirst="",const Char_t *collast="") const {
                           return GetThisTable()->Print(row,rownumber,colfirst,collast); }
   virtual  const Char_t *PrintHeader() const {return GetThisTable()->PrintHeader();}
   virtual  Int_t         Purge(Option_t *opt="")    {return GetThisTable()->Purge(opt);}

               void      *ReAllocate(Int_t newsize) { return GetThisTable()->ReAllocate(newsize); }
               void      *ReAllocate()              { return GetThisTable()->ReAllocate(); }
   virtual     void       SavePrimitive(std::ostream &out, Option_t *option="") {GetThisTable()->SavePrimitive(out,option);}

   virtual     void       Set(Int_t n)                                   {GetThisTable()->Set(n);}
   virtual     void       Set(Int_t n, Char_t *array)                    {GetThisTable()->Set(n,array);}
   virtual     void       SetNRows(Int_t n)                              {GetThisTable()->SetNRows(n);}
   virtual     void       Reset(Int_t c=0)                               {GetThisTable()->Reset(c) ;}
   virtual     void       Update()                                       {GetThisTable()->Update();}
   virtual     void       Update(TDataSet *set, UInt_t opt=0)            {GetThisTable()->Update(set,opt);}
               void      *operator[](Int_t i);
              const void *operator[](Int_t i) const;

   ClassDef(TChair,0)  // A base class to provide a user custom interface to TTable class objects
};

inline void  TChair::AddAt(TDataSet *dataset,Int_t idx)
{TDataSet::AddAt(dataset,idx);}

inline void *TChair::operator[](Int_t i)
{

//   if (!GetThisTable()->BoundsOk("TChair::operator[]", i))
//      i = 0;
    return (void *)((char *)GetArray()+i*GetRowSize());
}

inline const void *TChair::operator[](Int_t i) const
{
//   if (!GetThisTable()->BoundsOk("TChair::operator[]", i))
//      i = 0;
    return (const void *)((char *)GetArray()+i*GetRowSize());
}

// $Log: TChair.h,v $
// Revision 1.5  2006/07/03 16:10:46  brun
// from Axel:
// Change the signature of SavePrimitive from
//
//   void SavePrimitive(std::ofstream &out, Option_t *option);
// to
//   void SavePrimitive(std::ostream &out, Option_t *option = "");
//
// With this change one can do, eg
//    myhist.SavePrimitive(std::cout);
//
// WARNING: do rm -f tree/src/*.o
//
// Revision 1.4  2005/04/25 17:23:29  brun
// From Valeri Fine:
//
//   TChair.h:
//      - Make the "fTable" data-member to be "protected" (it was "private")
//        to facilitate the class reuse (thanks Y.Fisyak)
//
//   TColumnView.cxx:
//      - extra protection against of zero gPad
//
//   TPad.cxx
//     - initialize the "fPadView3D" data-member
//      (causes the crash within "table" package occasionally)
//
// Revision 1.3  2003/01/27 20:41:36  brun
// New version of the Table package by Valeri Fine.
// New classes TIndexTable TResponseIterator TResponseTable TTableMap
//
// Revision 1.1.1.2  2002/12/02 21:57:31  fisyak
// *** empty log message ***
//
// Revision 1.2  2002/12/02 18:50:05  rdm
// mega patch to remove almost all compiler warnings on MacOS X where the
// compiler is by default in pedantic mode (LHCb also like to use this option).
// The following issues have been fixed:
// - removal of unused arguments
// - comparison between signed and unsigned integers
// - not calling of base class copy ctor in copy ctor's
// To be done, the TGeo classes where we get still many hundred warnings of
// the above nature. List forwarded to Andrei.
//
// Revision 1.1  2002/05/27 16:26:59  rdm
// rename star to table.
//
// Revision 1.9  2001/02/07 08:18:15  brun
//
// New version of the STAR classes compiling with no warnings.
//
// Revision 1.1.1.3  2001/01/22 12:59:34  fisyak
// *** empty log message ***
//
// Revision 1.8  2001/01/19 07:22:54  brun
// A few changes in the STAR classes to remove some compiler warnings.
//
// Revision 1.2  2001/01/14 01:26:54  fine
// New implementation TTable::SavePrimitive and AsString
//
// Revision 1.1.1.2  2000/12/18 21:05:26  fisyak
// *** empty log message ***
//
// Revision 1.7  2000/12/13 15:13:53  brun
//       W A R N I N G   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//      ==================================================================
// A very long list of changes in this pre-release of version 3.00.
// We have modified the signature of many functions (in particular TObject)
// to introduce more constness in the system.
// You must change your code if your class derives from TObject and uses
// one of the modified functions such as ls, Print, Compare, Hash, etc.
// The modified functions in TObject have the following signature:
//    virtual TObject    *Clone() const;
//    virtual Int_t       Compare(const TObject *obj) const;
//    virtual void        Delete(Option_t *option=""); // *MENU*
//    virtual void        DrawClass() const; // *MENU*
//    virtual void        DrawClone(Option_t *option="") const; // *MENU*
//    virtual void        Dump() const; // *MENU*
//    virtual TObject    *FindObject(const TObject *obj) const;
//    virtual char       *GetObjectInfo(Int_t px, Int_t py) const;
//    virtual ULong_t     Hash() const;
//    virtual void        Inspect() const; // *MENU*
//    virtual Bool_t      IsEqual(const TObject *obj) const;
//    virtual void        ls(Option_t *option="") const;
//    virtual void        Print(Option_t *option="") const;
//
// A similar operation has been done with classes such as TH1, TVirtualPad,
// TTree, etc.
//
// Revision 1.6  2000/12/11 09:52:24  brun
// Functions ls declared const like in the base class
//
// Revision 1.5  2000/09/29 07:15:30  brun
// Remove unused function ReadGenericArray
//
// Revision 1.4  2000/09/05 09:21:24  brun
// The following headers and classes have been modified to take into account;
//   - the new signature of IsFolder (now const)
//   - the new TObject::FindObject
//   - the fact that the static functions of TObject have been moved to TROOT.
//
// Revision 1.3  2000/08/09 08:41:22  brun
// Import new versions of the STAR classes from Valery Fine
//
// Revision 1.4  2000/08/05 19:01:59  fisyak
// Merge
//
// Revision 1.3  2000/06/05 21:22:01  fisyak
// mergre with Rene's corrections
//
// Revision 1.1.1.2  2000/06/05 12:44:33  fisyak
// *** empty log message ***
//
// Revision 1.2  2000/06/05 08:01:03  brun
// Merge with valery's version
//
// Revision 1.2  2000/06/02 14:51:37  fine
// new helper class to browse tables has been introduced
//
// Revision 1.1.1.1  2000/05/19 12:46:09  fisyak
// CVS version of root 2.24.05 without history
//
// Revision 1.1.1.1  2000/05/16 17:00:49  rdm
// Initial import of ROOT into CVS
//
// Revision 1.1  2000/03/09 21:57:03  fine
// TChair class to be moved to ROOT later
//
// Revision 1.1  2000/02/28 03:42:24  fine
// New base class to provide a custom interface to the TTable objects
//

#endif
 TChair.h:1
 TChair.h:2
 TChair.h:3
 TChair.h:4
 TChair.h:5
 TChair.h:6
 TChair.h:7
 TChair.h:8
 TChair.h:9
 TChair.h:10
 TChair.h:11
 TChair.h:12
 TChair.h:13
 TChair.h:14
 TChair.h:15
 TChair.h:16
 TChair.h:17
 TChair.h:18
 TChair.h:19
 TChair.h:20
 TChair.h:21
 TChair.h:22
 TChair.h:23
 TChair.h:24
 TChair.h:25
 TChair.h:26
 TChair.h:27
 TChair.h:28
 TChair.h:29
 TChair.h:30
 TChair.h:31
 TChair.h:32
 TChair.h:33
 TChair.h:34
 TChair.h:35
 TChair.h:36
 TChair.h:37
 TChair.h:38
 TChair.h:39
 TChair.h:40
 TChair.h:41
 TChair.h:42
 TChair.h:43
 TChair.h:44
 TChair.h:45
 TChair.h:46
 TChair.h:47
 TChair.h:48
 TChair.h:49
 TChair.h:50
 TChair.h:51
 TChair.h:52
 TChair.h:53
 TChair.h:54
 TChair.h:55
 TChair.h:56
 TChair.h:57
 TChair.h:58
 TChair.h:59
 TChair.h:60
 TChair.h:61
 TChair.h:62
 TChair.h:63
 TChair.h:64
 TChair.h:65
 TChair.h:66
 TChair.h:67
 TChair.h:68
 TChair.h:69
 TChair.h:70
 TChair.h:71
 TChair.h:72
 TChair.h:73
 TChair.h:74
 TChair.h:75
 TChair.h:76
 TChair.h:77
 TChair.h:78
 TChair.h:79
 TChair.h:80
 TChair.h:81
 TChair.h:82
 TChair.h:83
 TChair.h:84
 TChair.h:85
 TChair.h:86
 TChair.h:87
 TChair.h:88
 TChair.h:89
 TChair.h:90
 TChair.h:91
 TChair.h:92
 TChair.h:93
 TChair.h:94
 TChair.h:95
 TChair.h:96
 TChair.h:97
 TChair.h:98
 TChair.h:99
 TChair.h:100
 TChair.h:101
 TChair.h:102
 TChair.h:103
 TChair.h:104
 TChair.h:105
 TChair.h:106
 TChair.h:107
 TChair.h:108
 TChair.h:109
 TChair.h:110
 TChair.h:111
 TChair.h:112
 TChair.h:113
 TChair.h:114
 TChair.h:115
 TChair.h:116
 TChair.h:117
 TChair.h:118
 TChair.h:119
 TChair.h:120
 TChair.h:121
 TChair.h:122
 TChair.h:123
 TChair.h:124
 TChair.h:125
 TChair.h:126
 TChair.h:127
 TChair.h:128
 TChair.h:129
 TChair.h:130
 TChair.h:131
 TChair.h:132
 TChair.h:133
 TChair.h:134
 TChair.h:135
 TChair.h:136
 TChair.h:137
 TChair.h:138
 TChair.h:139
 TChair.h:140
 TChair.h:141
 TChair.h:142
 TChair.h:143
 TChair.h:144
 TChair.h:145
 TChair.h:146
 TChair.h:147
 TChair.h:148
 TChair.h:149
 TChair.h:150
 TChair.h:151
 TChair.h:152
 TChair.h:153
 TChair.h:154
 TChair.h:155
 TChair.h:156
 TChair.h:157
 TChair.h:158
 TChair.h:159
 TChair.h:160
 TChair.h:161
 TChair.h:162
 TChair.h:163
 TChair.h:164
 TChair.h:165
 TChair.h:166
 TChair.h:167
 TChair.h:168
 TChair.h:169
 TChair.h:170
 TChair.h:171
 TChair.h:172
 TChair.h:173
 TChair.h:174
 TChair.h:175
 TChair.h:176
 TChair.h:177
 TChair.h:178
 TChair.h:179
 TChair.h:180
 TChair.h:181
 TChair.h:182
 TChair.h:183
 TChair.h:184
 TChair.h:185
 TChair.h:186
 TChair.h:187
 TChair.h:188
 TChair.h:189
 TChair.h:190
 TChair.h:191
 TChair.h:192
 TChair.h:193
 TChair.h:194
 TChair.h:195
 TChair.h:196
 TChair.h:197
 TChair.h:198
 TChair.h:199
 TChair.h:200
 TChair.h:201
 TChair.h:202
 TChair.h:203
 TChair.h:204
 TChair.h:205
 TChair.h:206
 TChair.h:207
 TChair.h:208
 TChair.h:209
 TChair.h:210
 TChair.h:211
 TChair.h:212
 TChair.h:213
 TChair.h:214
 TChair.h:215
 TChair.h:216
 TChair.h:217
 TChair.h:218
 TChair.h:219
 TChair.h:220
 TChair.h:221
 TChair.h:222
 TChair.h:223
 TChair.h:224
 TChair.h:225
 TChair.h:226
 TChair.h:227
 TChair.h:228
 TChair.h:229
 TChair.h:230
 TChair.h:231
 TChair.h:232
 TChair.h:233
 TChair.h:234
 TChair.h:235
 TChair.h:236
 TChair.h:237
 TChair.h:238
 TChair.h:239
 TChair.h:240
 TChair.h:241
 TChair.h:242
 TChair.h:243
 TChair.h:244
 TChair.h:245
 TChair.h:246
 TChair.h:247
 TChair.h:248
 TChair.h:249
 TChair.h:250
 TChair.h:251
 TChair.h:252
 TChair.h:253