1    	/* @(#)root/table:$Id$ */
2    	
3    	/*************************************************************************
4    	 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
5    	 * All rights reserved.                                                  *
6    	 *                                                                       *
7    	 * For the licensing terms see $ROOTSYS/LICENSE.                         *
8    	 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
9    	 *************************************************************************/
10   	
11   	#ifndef ROOT_Ttypes
12   	#define ROOT_Ttypes
13   	
14   	//////////////////////////////////////////////////////////////////////////
15   	//                                                                      //
16   	// Stypes                                                               //
17   	//                                                                      //
18   	// Basic types used by STAF - ROOT interface.                           //
19   	//                                                                      //
20   	// This header file contains the set of the macro definitions           //
21   	// to generate a ROOT dictionary for "pure" C-strucutre the way ROOT    //
22   	// does it for the "normal" C++ classes                                 //
23   	//                                                                      //
24   	//////////////////////////////////////////////////////////////////////////
25   	
26   	#include "Rtypes.h"
27   	
28   	#ifdef ANSICPP
29   	#   define _QUOTE2_(name1,name2) _QUOTE_(name1##name2)
30   	#else
31   	#   define _QUOTE2_(name1,name2) _QUOTE_(_NAME1_(name1)name2)
32   	#endif
33   	
34   	// #if ROOT_VERSION_CODE >= ROOT_VERSION(3,03,5)
35   	
36   	//___________________________________________________________________
37   	#define _TableClassImp_(className,structName)
38   	
39   	//___________________________________________________________________
40   	#define TableClassStreamerImp(className)                            \
41   	void className::Streamer(TBuffer &R__b) {                           \
42   	   TTable::Streamer(R__b); }
43   	
44   	//___________________________________________________________________
45   	#define TableClassImp(className,structName)                         \
46   	   const char* className::TableDictionary()                         \
47   	   {return TTable::TableDictionary(_QUOTE_(className),_QUOTE_(structName),fgColDescriptors);}\
48   	   _TableClassImp_(className,structName)
49   	
50   	//___________________________________________________________________
51   	#define TableClassImpl(className,structName)                        \
52   	  TTableDescriptor *className::fgColDescriptors = 0;                \
53   	  TableClassImp(className,structName)                               \
54   	  TableClassStreamerImp(className)
55   	
56   	
57   	#define TableImpl(name)                                            \
58   	  TTableDescriptor *_NAME2_(St_,name)::fgColDescriptors = 0;       \
59   	  TableClassImp(_NAME2_(St_,name), _NAME2_(name,_st))              \
60   	  TableClassStreamerImp(_NAME2_(St_,name))
61   	
62   	#define TableImp(name)  TableClassImp(_NAME2_(St_,name),_QUOTE2_(St_,name))
63   	
64   	#define ClassDefTable(className,structName)         \
65   	  public:                                           \
66   	     static const char* TableDictionary();          \
67   	  protected:                                        \
68   	     static TTableDescriptor *fgColDescriptors;     \
69   	     virtual TTableDescriptor *GetDescriptorPointer() const { return fgColDescriptors;}                 \
70   	virtual void SetDescriptorPointer(TTableDescriptor *list)  { fgColDescriptors = list;}                  \
71   	  public:                                           \
72   	    typedef structName* iterator;                   \
73   	    className() : TTable(_QUOTE_(className),sizeof(structName))    {SetType(_QUOTE_(structName));}      \
74   	    className(const char *name) : TTable(name,sizeof(structName)) {SetType(_QUOTE_(structName));}     \
75   	    className(Int_t n) : TTable(_QUOTE_(className),n,sizeof(structName)) {SetType(_QUOTE_(structName));}\
76   	    className(const char *name,Int_t n) : TTable(name,n,sizeof(structName)) {SetType(_QUOTE_(structName));}\
77   	    structName *GetTable(Int_t i=0) const { return ((structName *)GetArray())+i;}                       \
78   	    structName &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }             \
79   	    const structName &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const structName *)(GetTable(i))); } \
80   	    structName *begin() const  {                      return GetNRows()? GetTable(0):0;}\
81   	    structName *end()   const  {Long_t i = GetNRows(); return          i? GetTable(i):0;}
82   	
83   	// -- The member function "begin()" returns a pointer to the first table row
84   	//   (or just zero if the table is empty).
85   	// -- The member function "end()" returns a pointer to the last+1 table row
86   	//   (or just zero if the table is empty).
87   	
88   	//  protected:
89   	//    _NAME2_(className,C)() : TChair() {;}
90   	//  public:
91   	//    _NAME2_(className,C)(className *tableClass) : TChair(tableClass) {;}
92   	
93   	#define ClassDefineChair(classChairName,classTableName,structName)    \
94   	  public:                                               \
95   	    typedef structName* iterator;                       \
96   	    structName *GetTable(Int_t i) const  {              \
97   	              if (fLastIndx != UInt_t(i)) {             \
98   	                ((classChairName *)this)->fLastIndx = i;        \
99   	                ((classChairName *)this)->fLastRow =            \
100  	                  ((classTableName *)GetThisTable())->GetTable(i);    \
101  	           }; return (structName *)fLastRow; };          \
102  	    structName &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }    \
103  	    const structName &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const structName *)(GetTable(i))); }\
104  	    structName *begin() const  {                      return GetNRows()? GetTable(0):0;}\
105  	    structName *end()   const  {Int_t i = GetNRows(); return          i? GetTable(i):0;}
106  	
107  	//
108  	//    ClassDefineChair(_NAME2_(className,C),className,structName)
109  	//    We have to define this macro in full because RootCint doesn't provide the deep CPP evaluation
110  	//    V.Fine 17/12/2003 
111  	#define ClassDefChair(className,structName)             \
112  	  public:                                               \
113  	    typedef structName* iterator;                       \
114  	    structName *GetTable(Int_t i) const  {              \
115  	              if (fLastIndx != UInt_t(i)) {             \
116  	                ((_NAME2_(className,C) *)this)->fLastIndx = i;        \
117  	                ((_NAME2_(className,C) *)this)->fLastRow =            \
118  	                  ((className *)GetThisTable())->GetTable(i);              \
119  	           }; return (structName *)fLastRow; }          \
120  	    structName &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }    \
121  	    const structName &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const structName *)(GetTable(i))); }\
122  	    structName *begin() const  {                      return GetNRows()? GetTable(0):0;}\
123  	    structName *end()   const  {Int_t i = GetNRows(); return          i? GetTable(i):0;}
124  	
125  	
126  	namespace ROOT {
127  	   template <class T> class TTableInitBehavior: public TDefaultInitBehavior {
128  	   public:
129  	      static const char* fgStructName; // Need to be instantiated
130  	      virtual TClass *CreateClass(const char *cname, Version_t id,
131  	                                  const type_info &info, TVirtualIsAProxy *isa,
132  	                                  ShowMembersFunc_t show,
133  	                                  const char *dfil, const char *ifil,
134  	                                  Int_t dl, Int_t il) const
135  	      {
136  	         TClass *cl = TDefaultInitBehavior::CreateClass(cname, id, info, isa, show,
137  	                                                        dfil, ifil,dl, il);
138  	         fgStructName = T::TableDictionary();
139  	         return cl;
140  	      }
141  	      virtual void Unregister(const char* classname) const
142  	      {
143  	         TDefaultInitBehavior::Unregister(classname);
144  	         TDefaultInitBehavior::Unregister(fgStructName);
145  	      }
146  	   };
147  	   template <class T> const char * TTableInitBehavior<T >::fgStructName = 0;
148  	}
149  	
150  	class TTable;
151  	namespace ROOT {
152  	   template <class RootClass>
153  	      const ROOT::TTableInitBehavior<RootClass> *DefineBehavior(TTable*, RootClass*)
154  	      {
155  	         static ROOT::TTableInitBehavior<RootClass> behave;
156  	         return &behave;
157  	      }
158  	}
159  	
160  	#endif
161