Logo ROOT   6.10/09
Reference Guide
Ttypes.h
Go to the documentation of this file.
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 #ifndef _QUOTE2_
29 # ifdef ANSICPP
30 # define _QUOTE2_(name1,name2) _QUOTE_(name1##name2)
31 #else
32 # define _QUOTE2_(name1,name2) _QUOTE_(_NAME1_(name1)name2)
33 # endif
34 #endif
35 
36 // #if ROOT_VERSION_CODE >= ROOT_VERSION(3,03,5)
37 
38 //___________________________________________________________________
39 #define _TableClassImp_(className,structName)
40 
41 //___________________________________________________________________
42 #define TableClassStreamerImp(className) \
43 void className::Streamer(TBuffer &R__b) { \
44  TTable::Streamer(R__b); }
45 
46 //___________________________________________________________________
47 #define TableClassImp(className,structName) \
48  const char* className::TableDictionary() \
49  {return TTable::TableDictionary(_QUOTE_(className),_QUOTE_(structName),fgColDescriptors);}\
50  _TableClassImp_(className,structName)
51 
52 //___________________________________________________________________
53 #define TableClassImpl(className,structName) \
54  TTableDescriptor *className::fgColDescriptors = 0; \
55  TableClassImp(className,structName) \
56  TableClassStreamerImp(className)
57 
58 
59 #define TableImpl(name) \
60  TTableDescriptor *_NAME2_(St_,name)::fgColDescriptors = 0; \
61  TableClassImp(_NAME2_(St_,name), _NAME2_(name,_st)) \
62  TableClassStreamerImp(_NAME2_(St_,name))
63 
64 #define TableImp(name) TableClassImp(_NAME2_(St_,name),_QUOTE2_(St_,name))
65 
66 #define ClassDefTable(className,structName) \
67  public: \
68  static const char* TableDictionary(); \
69  protected: \
70  static TTableDescriptor *fgColDescriptors; \
71  virtual TTableDescriptor *GetDescriptorPointer() const { return fgColDescriptors;} \
72 virtual void SetDescriptorPointer(TTableDescriptor *list) { fgColDescriptors = list;} \
73  public: \
74  typedef structName* iterator; \
75  className() : TTable(_QUOTE_(className),sizeof(structName)) {SetType(_QUOTE_(structName));} \
76  className(const char *name) : TTable(name,sizeof(structName)) {SetType(_QUOTE_(structName));} \
77  className(Int_t n) : TTable(_QUOTE_(className),n,sizeof(structName)) {SetType(_QUOTE_(structName));}\
78  className(const char *name,Int_t n) : TTable(name,n,sizeof(structName)) {SetType(_QUOTE_(structName));}\
79  structName *GetTable(Int_t i=0) const { return ((structName *)GetArray())+i;} \
80  structName &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); } \
81  const structName &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const structName *)(GetTable(i))); } \
82  structName *begin() const { return GetNRows()? GetTable(0):0;}\
83  structName *end() const {Long_t i = GetNRows(); return i? GetTable(i):0;}
84 
85 // -- The member function "begin()" returns a pointer to the first table row
86 // (or just zero if the table is empty).
87 // -- The member function "end()" returns a pointer to the last+1 table row
88 // (or just zero if the table is empty).
89 
90 // protected:
91 // _NAME2_(className,C)() : TChair() {;}
92 // public:
93 // _NAME2_(className,C)(className *tableClass) : TChair(tableClass) {;}
94 
95 #define ClassDefineChair(classChairName,classTableName,structName) \
96  public: \
97  typedef structName* iterator; \
98  structName *GetTable(Int_t i) const { \
99  if (fLastIndx != UInt_t(i)) { \
100  ((classChairName *)this)->fLastIndx = i; \
101  ((classChairName *)this)->fLastRow = \
102  ((classTableName *)GetThisTable())->GetTable(i); \
103  }; return (structName *)fLastRow; }; \
104  structName &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); } \
105  const structName &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const structName *)(GetTable(i))); }\
106  structName *begin() const { return GetNRows()? GetTable(0):0;}\
107  structName *end() const {Int_t i = GetNRows(); return i? GetTable(i):0;}
108 
109 //
110 // ClassDefineChair(_NAME2_(className,C),className,structName)
111 // We have to define this macro in full because RootCint doesn't provide the deep CPP evaluation
112 // V.Fine 17/12/2003
113 #define ClassDefChair(className,structName) \
114  public: \
115  typedef structName* iterator; \
116  structName *GetTable(Int_t i) const { \
117  if (fLastIndx != UInt_t(i)) { \
118  ((_NAME2_(className,C) *)this)->fLastIndx = i; \
119  ((_NAME2_(className,C) *)this)->fLastRow = \
120  ((className *)GetThisTable())->GetTable(i); \
121  }; return (structName *)fLastRow; } \
122  structName &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); } \
123  const structName &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const structName *)(GetTable(i))); }\
124  structName *begin() const { return GetNRows()? GetTable(0):0;}\
125  structName *end() const {Int_t i = GetNRows(); return i? GetTable(i):0;}
126 
127 
128 class TTable;
129 
130 namespace ROOT {
131 namespace Internal {
132  template <class T> class TTableInitBehavior: public TDefaultInitBehavior {
133  public:
134  static const char* fgStructName; // Need to be instantiated
135  virtual TClass *CreateClass(const char *cname, Version_t id,
136  const std::type_info &info, TVirtualIsAProxy *isa,
137  const char *dfil, const char *ifil,
138  Int_t dl, Int_t il) const
139  {
140  TClass *cl = TDefaultInitBehavior::CreateClass(cname, id, info, isa,
141  dfil, ifil,dl, il);
142  fgStructName = T::TableDictionary();
143  return cl;
144  }
145  virtual void Unregister(const char* classname) const
146  {
148  TDefaultInitBehavior::Unregister(fgStructName);
149  }
150  };
151  template <class T> const char * TTableInitBehavior<T >::fgStructName = 0;
152 
153  template <class RootClass>
155  {
156  static TTableInitBehavior<RootClass> behave;
157  return &behave;
158  }
159 }
160 }
161 
162 #endif
virtual void Unregister(const char *classname) const
Definition: Rtypes.h:165
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
short Version_t
Definition: RtypesCore.h:61
virtual void Unregister(const char *classname) const
Definition: Ttypes.h:145
int Int_t
Definition: RtypesCore.h:41
const TInitBehavior * DefineBehavior(void *, void *)
virtual TClass * CreateClass(const char *cname, Version_t id, const std::type_info &info, TVirtualIsAProxy *isa, const char *dfil, const char *ifil, Int_t dl, Int_t il) const
Definition: Ttypes.h:135
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
Definition: TTable.h:48
static const char * fgStructName
Definition: Ttypes.h:134
virtual TClass * CreateClass(const char *cname, Version_t id, const std::type_info &info, TVirtualIsAProxy *isa, const char *dfil, const char *ifil, Int_t dl, Int_t il) const
Definition: Rtypes.h:169