ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Rtypes.h
Go to the documentation of this file.
1 /* @(#)root/base:$Id$ */
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2014, 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_Rtypes
12 #define ROOT_Rtypes
13 
14 //////////////////////////////////////////////////////////////////////////
15 // //
16 // Rtypes //
17 // //
18 // Basic types used by ROOT; ClassDef macros. //
19 // //
20 //////////////////////////////////////////////////////////////////////////
21 
22 
23 #ifndef ROOT_RtypesCore
24 #include "RtypesCore.h"
25 #endif
26 #ifndef ROOT_DllImport
27 #include "DllImport.h"
28 #endif
29 #ifndef ROOT_Rtypeinfo
30 #include "Rtypeinfo.h"
31 #endif
32 
33 #include <stdio.h>
34 #include <string.h>
35 #include "snprintf.h" // part of stdio.h on systems that have it
36 #include "strlcpy.h" // part of string.h on systems that have it
37 #include <atomic>
38 
39 
40 //---- forward declared class types --------------------------------------------
41 
42 class TClass;
43 class TBuffer;
44 class TDirectory;
45 class TMemberInspector;
46 class TObject;
47 class TNamed;
48 class TCollection;
49 class TFileMergeInfo;
50 class TString;
51 
52 //Moved from TSystem.
55  kMAXPATHLEN = 8192,
56  kBUFFERSIZE = 8192,
57  kItimerResolution = 10 // interval-timer resolution in ms
58 };
59 
60 enum EColor { kWhite =0, kBlack =1, kGray=920,
61  kRed =632, kGreen =416, kBlue=600, kYellow=400, kMagenta=616, kCyan=432,
62  kOrange=800, kSpring=820, kTeal=840, kAzure =860, kViolet =880, kPink=900 };
63 
64 // There is several streamer concepts.
65 class TClassStreamer; // Streamer functor for a class
66 class TMemberStreamer; // Streamer functor for a data member
67 typedef void (*ClassStreamerFunc_t)(TBuffer&, void*); // Streamer function for a class
68 typedef void (*ClassConvStreamerFunc_t)(TBuffer&, void*, const TClass*); // Streamer function for a class with conversion.
69 typedef void (*MemberStreamerFunc_t)(TBuffer&, void*, Int_t); // Streamer function for a data member
70 
71 // This class is used to implement proxy around collection classes.
73 
74 typedef void (*VoidFuncPtr_t)(); //pointer to void function
75 typedef TClass* (*DictFuncPtr_t)(); //pointer to dictionary function
76 // NOTE: the previous name must be changed.
77 
78 
79 //---- constants ---------------------------------------------------------------
80 
81 #ifndef NULL
82 #define NULL 0
83 #endif
84 
85 #ifndef R__NULLPTR
86 #ifndef nullptr
87 #define nullptr 0
88 #endif
89 #endif
90 
91 const Bool_t kTRUE = true;
92 const Bool_t kFALSE = false;
93 
94 const Int_t kMaxUChar = 256;
95 const Int_t kMaxChar = kMaxUChar >> 1;
96 const Int_t kMinChar = -kMaxChar - 1;
97 
98 const Int_t kMaxUShort = 65534;
99 const Int_t kMaxShort = kMaxUShort >> 1;
100 const Int_t kMinShort = -kMaxShort - 1;
101 
102 const UInt_t kMaxUInt = UInt_t(~0);
103 const Int_t kMaxInt = Int_t(kMaxUInt >> 1);
104 const Int_t kMinInt = -kMaxInt - 1;
105 
108 const Long_t kMinLong = -kMaxLong - 1;
109 
113 
114 const size_t kBitsPerByte = 8;
115 const Ssiz_t kNPOS = ~(Ssiz_t)0;
116 
117 
118 //--- bit manipulation ---------------------------------------------------------
119 
120 #define BIT(n) (1ULL << (n))
121 #define SETBIT(n,i) ((n) |= BIT(i))
122 #define CLRBIT(n,i) ((n) &= ~BIT(i))
123 #define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
124 
125 
126 //---- debug global ------------------------------------------------------------
127 
129 
130 
131 //---- ClassDef macros ---------------------------------------------------------
132 
133 typedef void (*ShowMembersFunc_t)(const void *obj, TMemberInspector &R__insp, Bool_t isTransient);
134 class TVirtualIsAProxy;
135 typedef TClass *(*IsAGlobalFunc_t)(const TClass*, const void *obj);
136 
137 // TBuffer.h declares and implements the following 2 operators
138 template <class Tmpl> TBuffer &operator>>(TBuffer &buf, Tmpl *&obj);
139 template <class Tmpl> TBuffer &operator<<(TBuffer &buf, const Tmpl *obj);
140 
141 // This might get used if we implement setting a class version.
142 // template <class RootClass> Short_t GetClassVersion(RootClass *);
143 
144 namespace ROOT {
145 
146  class TGenericClassInfo;
147  typedef void *(*NewFunc_t)(void *);
148  typedef void *(*NewArrFunc_t)(Long_t size, void *arena);
149  typedef void (*DelFunc_t)(void *);
150  typedef void (*DelArrFunc_t)(void *);
151  typedef void (*DesFunc_t)(void *);
152  typedef void (*DirAutoAdd_t)(void *, TDirectory *);
153  typedef Long64_t (*MergeFunc_t)(void *, TCollection *, TFileMergeInfo *);
155 
156  template <class RootClass> Short_t SetClassVersion(RootClass *);
157 
158  extern TClass *CreateClass(const char *cname, Version_t id,
159  const type_info &info, TVirtualIsAProxy *isa,
160  const char *dfil, const char *ifil,
161  Int_t dl, Int_t il);
162  extern void AddClass(const char *cname, Version_t id, const type_info &info,
163  DictFuncPtr_t dict, Int_t pragmabits);
164  extern void RemoveClass(const char *cname);
165  extern void ResetClassVersion(TClass*, const char*, Short_t);
166  extern void AddClassAlternate(const char *normName, const char *alternate);
167 
168  extern TNamed *RegisterClassTemplate(const char *name,
169  const char *file, Int_t line);
170 
171  extern void Class_ShowMembers(TClass *cl, const void *obj, TMemberInspector&);
172 
173 #if 0
174  // This function is only implemented in the dictionary file.
175  // The parameter is 'only' for overloading resolution.
176  // Used to be a template <class T> TGenericClassInfo *GenerateInitInstance(const T*);
177  template <class T> TGenericClassInfo *GetClassInfo(const T* t) {
178  TGenericClassInfo *GenerateInitInstance(const T*);
179  return CreateInitInstance(t);
180  };
181 #endif
182 
183  namespace Internal {
185  // This class defines the interface for the class registration and
186  // the TClass creation. To modify the default behavior, one would
187  // inherit from this class and overload ROOT::DefineBehavior().
188  // See TQObject.h and table/inc/Ttypes.h for examples.
189  public:
190  virtual ~TInitBehavior() { }
191 
192  virtual void Register(const char *cname, Version_t id,
193  const type_info &info,
194  DictFuncPtr_t dict, Int_t pragmabits) const = 0;
195  virtual void Unregister(const char *classname) const = 0;
196  virtual TClass *CreateClass(const char *cname, Version_t id,
197  const type_info &info, TVirtualIsAProxy *isa,
198  const char *dfil, const char *ifil,
199  Int_t dl, Int_t il) const = 0;
200  };
201 
203  public:
204  virtual void Register(const char *cname, Version_t id,
205  const type_info &info,
206  DictFuncPtr_t dict, Int_t pragmabits) const {
207  ROOT::AddClass(cname, id, info, dict, pragmabits);
208  }
209 
210  virtual void Unregister(const char *classname) const {
211  ROOT::RemoveClass(classname);
212  }
213 
214  virtual TClass *CreateClass(const char *cname, Version_t id,
215  const type_info &info, TVirtualIsAProxy *isa,
216  const char *dfil, const char *ifil,
217  Int_t dl, Int_t il) const {
218  return ROOT::CreateClass(cname, id, info, isa, dfil, ifil, dl, il);
219  }
220  };
221 
222  const TInitBehavior *DefineBehavior(void * /*parent_type*/,
223  void * /*actual_type*/);
224  } // namespace Internal
225 
226 } // namespace ROOT
227 
228 // The macros below use TGenericClassInfo, so let's ensure it is included
229 #ifndef ROOT_TGenericClassInfo
230 #include "TGenericClassInfo.h"
231 #endif
232 
233 typedef std::atomic<TClass*> atomic_TClass_ptr;
234 
235 // Common part of ClassDef definition.
236 // DeclFileLine() is not part of it since CINT uses that as trigger for
237 // the class comment string.
238 #define _ClassDef_(name,id, virtual_keyword, overrd) \
239 private: \
240  static atomic_TClass_ptr fgIsA; \
241 public: \
242  static TClass *Class(); \
243  static const char *Class_Name(); \
244  static Version_t Class_Version() { return id; } \
245  static TClass *Dictionary(); \
246  virtual_keyword TClass *IsA() const overrd { return name::Class(); } \
247  virtual_keyword void ShowMembers(TMemberInspector&insp) const overrd { ::ROOT::Class_ShowMembers(name::Class(), this, insp); } \
248  virtual_keyword void Streamer(TBuffer&) overrd; \
249  void StreamerNVirtual(TBuffer&ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \
250  static const char *DeclFileName() { return __FILE__; } \
251  static int ImplFileLine(); \
252  static const char *ImplFileName();
253 
254 #define ClassDef(name,id) \
255  _ClassDef_(name,id,virtual,) \
256  static int DeclFileLine() { return __LINE__; }
257 
258 #define ClassDefOverride(name,id) \
259  _ClassDef_(name,id,,override) \
260  static int DeclFileLine() { return __LINE__; }
261 
262 #define ClassDefNV(name,id) \
263  _ClassDef_(name,id,,) \
264  static int DeclFileLine() { return __LINE__; }
265 
266 #define R__UseDummy(name) \
267  class _NAME2_(name,_c) { public: _NAME2_(name,_c)() { if (name) { } } }
268 
269 
270 #define ClassImpUnique(name,key) \
271  namespace ROOT { \
272  TGenericClassInfo *GenerateInitInstance(const name*); \
273  namespace { \
274  static int _R__UNIQUE_(_NAME2_(R__dummyint,key)) = \
275  GenerateInitInstance((name*)0x0)->SetImplFile(__FILE__, __LINE__); \
276  R__UseDummy(_R__UNIQUE_(_NAME2_(R__dummyint,key))); \
277  } \
278  }
279 #define ClassImp(name) ClassImpUnique(name,default)
280 
281 // Macro for Namespace
282 
283 #define NamespaceImpUnique(name,key) \
284  namespace name { \
285  namespace ROOT { \
286  ::ROOT::TGenericClassInfo *GenerateInitInstance(); \
287  namespace { \
288  static int _R__UNIQUE_(_NAME2_(R__dummyint,key)) = \
289  GenerateInitInstance()->SetImplFile(__FILE__, __LINE__); \
290  R__UseDummy(_R__UNIQUE_(_NAME2_(R__dummyint,key))); \
291  } \
292  } \
293  }
294 #define NamespaceImp(name) NamespaceImpUnique(name,default)
295 
296 //---- ClassDefT macros for templates with one template argument ---------------
297 // ClassDefT corresponds to ClassDef
298 // ClassDefT2 goes in the same header as ClassDefT but must be
299 // outside the class scope
300 // ClassImpT corresponds to ClassImp
301 
302 
303 // This ClassDefT is stricly redundant and is kept only for
304 // backward compatibility.
305 
306 #define ClassDefT(name,id) \
307  _ClassDef_(name,id,virtual,) \
308  static int DeclFileLine() { return __LINE__; }
309 
310 #define ClassDefTNV(name,id) \
311  _ClassDef_(name,id,virtual,) \
312  static int DeclFileLine() { return __LINE__; }
313 
314 
315 #define ClassDefT2(name,Tmpl)
316 
317 
318 
319 #define templateClassImpUnique(name,key) \
320  namespace ROOT { \
321  static TNamed *_R__UNIQUE_(_NAME2_(R__dummyholder,key)) = \
322  ROOT::RegisterClassTemplate(_QUOTE_(name), __FILE__, __LINE__); \
323  R__UseDummy(_R__UNIQUE_(_NAME2_(R__dummyholder,key))); \
324  }
325 #define templateClassImp(name) templateClassImpUnique(name,default)
326 
327 #define ClassImpT(name,Tmpl) templateClassImp(name)
328 
329 //---- ClassDefT macros for templates with two template arguments --------------
330 // ClassDef2T2 goes in the same header as ClassDefT but must be
331 // outside the class scope
332 // ClassImp2T corresponds to ClassImpT
333 
334 #define ClassDef2T2(name,Tmpl1,Tmpl2)
335 #define ClassImp2T(name,Tmpl1,Tmpl2) templateClassImp(name)
336 
337 
338 //---- ClassDefT macros for templates with three template arguments ------------
339 // ClassDef3T2 goes in the same header as ClassDefT but must be
340 // outside the class scope
341 // ClassImp3T corresponds to ClassImpT
342 
343 #define ClassDef3T2(name,Tmpl1,Tmpl2,Tmpl3)
344 #define ClassImp3T(name,Tmpl1,Tmpl2,Tmpl3) templateClassImp(name)
345 
346 
347 //---- Macro to set the class version of non instrumented classes --------------
348 
349 #define RootClassVersion(name,VersionNumber) \
350 namespace ROOT { \
351  TGenericClassInfo *GenerateInitInstance(const name*); \
352  static Short_t _R__UNIQUE_(R__dummyVersionNumber) = \
353  GenerateInitInstance((name*)0x0)->SetVersion(VersionNumber); \
354  R__UseDummy(_R__UNIQUE_(R__dummyVersionNumber)); \
355 }
356 
357 #define RootStreamer(name,STREAMER) \
358 namespace ROOT { \
359  TGenericClassInfo *GenerateInitInstance(const name*); \
360  static Short_t _R__UNIQUE_(R__dummyStreamer) = \
361  GenerateInitInstance((name*)0x0)->SetStreamer(STREAMER); \
362  R__UseDummy(_R__UNIQUE_(R__dummyStreamer)); \
363 }
364 
365 //---- Macro to load a library into the interpreter --------------
366 // Call as R__LOAD_LIBRARY(libEvent)
367 // This macro intentionally does not take string as argument, to
368 // prevent compilation errors with complex diagnostics due to
369 // TString BAD_DO_NOT_TRY = "lib";
370 // R__LOAD_LIBRARY(BAD_DO_NOT_TRY + "BAD_DO_NOT_TRY.so") // ERROR!
371 #define _R_PragmaStr(x) _Pragma(#x)
372 #ifdef __CLING__
373 # define R__LOAD_LIBRARY(LIBRARY) _R_PragmaStr(cling load ( #LIBRARY ))
374 # define R__ADD_INCLUDE_PATH(PATH) _R_PragmaStr(cling add_include_path ( #PATH ))
375 # define R__ADD_LIBRARY_PATH(PATH) _R_PragmaStr(cling add_library_path ( #PATH ))
376 #elif defined(R__WIN32)
377 # define R__LOAD_LIBRARY(LIBRARY) _R_PragmaStr(comment(lib, #LIBRARY))
378 # define R__ADD_INCLUDE_PATH(PATH) _R_PragmaStr(comment(path, #PATH))
379 # define R__ADD_LIBRARY_PATH(PATH) _R_PragmaStr(comment(path, #PATH))
380 #else
381 // No way to inform linker though preprocessor :-(
382 // We could even inform the user:
383 /*
384 # define R__LOAD_LIBRARY(LIBRARY) \
385  _R_PragmaStr(message "Compiler cannot handle linking against " #LIBRARY \
386  ". Use -L and -l instead.")
387 */
388 # define R__LOAD_LIBRARY(LIBRARY)
389 # define R__ADD_INCLUDE_PATH(PATH)
390 # define R__ADD_LIBRARY_PATH(PATH)
391 #endif
392 
393 #endif
const Int_t kMinInt
Definition: Rtypes.h:104
const Long_t kMinLong
Definition: Rtypes.h:108
TClass *(* DictFuncPtr_t)()
Definition: Rtypes.h:75
void(* MemberStreamerFunc_t)(TBuffer &, void *, Int_t)
Definition: Rtypes.h:69
long long Long64_t
Definition: RtypesCore.h:69
short Version_t
Definition: RtypesCore.h:61
TLine * line
Definition: Rtypes.h:61
const Long64_t kMinLong64
Definition: Rtypes.h:112
const ULong64_t kMaxULong64
Definition: Rtypes.h:110
Definition: Rtypes.h:60
Definition: Rtypes.h:60
Definition: Rtypes.h:62
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual void Register(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits) const
Definition: Rtypes.h:204
Basic string class.
Definition: TString.h:137
void AddClass(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Global function called by the ctor of a class's init class (see the ClassImp macro).
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Definition: Rtypes.h:61
Definition: Rtypes.h:61
Abstract base class for accessing the data-members of a class.
ESysConstants
Definition: Rtypes.h:53
const TInitBehavior * DefineBehavior(void *, void *)
const UInt_t kMaxUInt
Definition: Rtypes.h:102
void(* DirAutoAdd_t)(void *, TDirectory *)
Definition: Rtypes.h:152
TBuffer & operator>>(TBuffer &buf, Tmpl *&obj)
Definition: TBuffer.h:370
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition: TBuffer.h:386
TTree * T
Definition: Rtypes.h:62
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Long64_t(* MergeFunc_t)(void *, TCollection *, TFileMergeInfo *)
Definition: Rtypes.h:153
void AddClassAlternate(const char *normName, const char *alternate)
Global function called by GenerateInitInstance.
void(* ResetAfterMergeFunc_t)(void *, TFileMergeInfo *)
Definition: Rtypes.h:154
const Int_t kMinChar
Definition: Rtypes.h:96
Definition: Rtypes.h:62
const Long_t kMaxLong
Definition: Rtypes.h:107
virtual void Unregister(const char *classname) const
Definition: Rtypes.h:210
EColor
Definition: Rtypes.h:60
const Long64_t kMaxLong64
Definition: Rtypes.h:111
Definition: Rtypes.h:60
TClass * CreateClass(const char *cname, Version_t id, const type_info &info, TVirtualIsAProxy *isa, const char *dfil, const char *ifil, Int_t dl, Int_t il)
Global function called by a class' static Dictionary() method (see the ClassDef macro).
Definition: TClass.cxx:5393
TThread * t[5]
Definition: threadsh1.C:13
void ResetClassVersion(TClass *, const char *, Short_t)
Global function to update the version number.
const Int_t kMaxChar
Definition: Rtypes.h:95
void RemoveClass(const char *cname)
Global function called by the dtor of a class's init class (see the ClassImp macro).
Definition: Rtypes.h:62
Collection abstract base class.
Definition: TCollection.h:48
virtual TClass * CreateClass(const char *cname, Version_t id, const type_info &info, TVirtualIsAProxy *isa, const char *dfil, const char *ifil, Int_t dl, Int_t il) const
Definition: Rtypes.h:214
unsigned int UInt_t
Definition: RtypesCore.h:42
short Short_t
Definition: RtypesCore.h:35
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
std::atomic< TClass * > atomic_TClass_ptr
Definition: Rtypes.h:233
const Int_t kMaxUShort
Definition: Rtypes.h:98
Short_t SetClassVersion(RootClass *)
virtual void Unregister(const char *classname) const =0
TEllipse dict(9, 20, 3, 1.5)
void(* DesFunc_t)(void *)
Definition: Rtypes.h:151
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
tuple file
Definition: fildir.py:20
const ULong_t kMaxULong
Definition: Rtypes.h:106
Describe directory structure in memory.
Definition: TDirectory.h:44
void(* ClassStreamerFunc_t)(TBuffer &, void *)
Definition: Rtypes.h:67
void(* VoidFuncPtr_t)()
Definition: Rtypes.h:74
unsigned long long ULong64_t
Definition: RtypesCore.h:70
unsigned long ULong_t
Definition: RtypesCore.h:51
void(* DelArrFunc_t)(void *)
Definition: Rtypes.h:150
Definition: Rtypes.h:61
const Int_t kMaxShort
Definition: Rtypes.h:99
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
const Int_t kMaxInt
Definition: Rtypes.h:103
#define R__EXTERN
Definition: DllImport.h:27
typedef void((*Func_t)())
void(* ClassConvStreamerFunc_t)(TBuffer &, void *, const TClass *)
Definition: Rtypes.h:68
const Ssiz_t kNPOS
Definition: Rtypes.h:115
const size_t kBitsPerByte
Definition: Rtypes.h:114
void(* ShowMembersFunc_t)(const void *obj, TMemberInspector &R__insp, Bool_t isTransient)
Definition: Rtypes.h:133
Definition: Rtypes.h:62
const Int_t kMinShort
Definition: Rtypes.h:100
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
Definition: Rtypes.h:61
const Bool_t kTRUE
Definition: Rtypes.h:91
TNamed * RegisterClassTemplate(const char *name, const char *file, Int_t line)
Global function to register the implementation file and line of a class template (i.e.
TObject * obj
virtual void Register(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits) const =0
virtual TClass * CreateClass(const char *cname, Version_t id, const type_info &info, TVirtualIsAProxy *isa, const char *dfil, const char *ifil, Int_t dl, Int_t il) const =0
void(* DelFunc_t)(void *)
Definition: Rtypes.h:149
Definition: Rtypes.h:62
const Int_t kMaxUChar
Definition: Rtypes.h:94
void Class_ShowMembers(TClass *cl, const void *obj, TMemberInspector &)
Indirect call to the implementation of ShowMember allowing [forward] declaration with out a full defi...
Definition: TClass.cxx:498