1    	/* @(#)root/base:$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_Rtypes
12   	#define ROOT_Rtypes
13   	
14   	//////////////////////////////////////////////////////////////////////////
15   	//                                                                      //
16   	// Rtypes                                                               //
17   	//                                                                      //
18   	// Basic types used by ROOT.                                            //
19   	//                                                                      //
20   	//////////////////////////////////////////////////////////////////////////
21   	
22   	
23   	#ifndef ROOT_RConfig
24   	#include "RConfig.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   	#if __cplusplus >= 201103L
38   	#include <atomic>
39   	#endif
40   	
41   	
42   	//---- forward declared class types --------------------------------------------
43   	
44   	class TClass;
45   	class TBuffer;
46   	class TDirectory;
47   	class TMemberInspector;
48   	class TObject;
49   	class TNamed;
50   	class TRootIOCtor;
51   	class TCollection;
52   	class TFileMergeInfo;
53   	class TString;
54   	
55   	//---- types -------------------------------------------------------------------
56   	
57   	typedef char           Char_t;      //Signed Character 1 byte (char)
58   	typedef unsigned char  UChar_t;     //Unsigned Character 1 byte (unsigned char)
59   	typedef short          Short_t;     //Signed Short integer 2 bytes (short)
60   	typedef unsigned short UShort_t;    //Unsigned Short integer 2 bytes (unsigned short)
61   	#ifdef R__INT16
62   	typedef long           Int_t;       //Signed integer 4 bytes
63   	typedef unsigned long  UInt_t;      //Unsigned integer 4 bytes
64   	#else
65   	typedef int            Int_t;       //Signed integer 4 bytes (int)
66   	typedef unsigned int   UInt_t;      //Unsigned integer 4 bytes (unsigned int)
67   	#endif
68   	#ifdef R__B64    // Note: Long_t and ULong_t are currently not portable types
69   	typedef int            Seek_t;      //File pointer (int)
70   	typedef long           Long_t;      //Signed long integer 8 bytes (long)
71   	typedef unsigned long  ULong_t;     //Unsigned long integer 8 bytes (unsigned long)
72   	#else
73   	typedef int            Seek_t;      //File pointer (int)
74   	typedef long           Long_t;      //Signed long integer 4 bytes (long)
75   	typedef unsigned long  ULong_t;     //Unsigned long integer 4 bytes (unsigned long)
76   	#endif
77   	typedef float          Float_t;     //Float 4 bytes (float)
78   	typedef float          Float16_t;   //Float 4 bytes written with a truncated mantissa
79   	typedef double         Double_t;    //Double 8 bytes
80   	typedef double         Double32_t;  //Double 8 bytes in memory, written as a 4 bytes float
81   	typedef long double    LongDouble_t;//Long Double
82   	typedef char           Text_t;      //General string (char)
83   	typedef bool           Bool_t;      //Boolean (0=false, 1=true) (bool)
84   	typedef unsigned char  Byte_t;      //Byte (8 bits) (unsigned char)
85   	typedef short          Version_t;   //Class version identifier (short)
86   	typedef const char     Option_t;    //Option string (const char)
87   	typedef int            Ssiz_t;      //String size (int)
88   	typedef float          Real_t;      //TVector and TMatrix element type (float)
89   	#if defined(R__WIN32) && !defined(__CINT__)
90   	typedef __int64          Long64_t;  //Portable signed long integer 8 bytes
91   	typedef unsigned __int64 ULong64_t; //Portable unsigned long integer 8 bytes
92   	#else
93   	typedef long long          Long64_t; //Portable signed long integer 8 bytes
94   	typedef unsigned long long ULong64_t;//Portable unsigned long integer 8 bytes
95   	#endif
96   	typedef double         Axis_t;      //Axis values type (double)
97   	typedef double         Stat_t;      //Statistics type (double)
98   	
99   	typedef short          Font_t;      //Font number (short)
100  	typedef short          Style_t;     //Style number (short)
101  	typedef short          Marker_t;    //Marker number (short)
102  	typedef short          Width_t;     //Line width (short)
103  	typedef short          Color_t;     //Color number (short)
104  	typedef short          SCoord_t;    //Screen coordinates (short)
105  	typedef double         Coord_t;     //Pad world coordinates (double)
106  	typedef float          Angle_t;     //Graphics angle (float)
107  	typedef float          Size_t;      //Attribute size (float)
108  	
109  	enum EColor { kWhite =0,   kBlack =1,   kGray=920,
110  	              kRed   =632, kGreen =416, kBlue=600, kYellow=400, kMagenta=616, kCyan=432,
111  	              kOrange=800, kSpring=820, kTeal=840, kAzure =860, kViolet =880, kPink=900 };
112  	
113  	// There is several streamer concepts.
114  	class TClassStreamer;   // Streamer functor for a class
115  	class TMemberStreamer;  // Streamer functor for a data member
116  	typedef void (*ClassStreamerFunc_t)(TBuffer&, void*);  // Streamer function for a class
117  	typedef void (*MemberStreamerFunc_t)(TBuffer&, void*, Int_t); // Streamer function for a data member
118  	
119  	// This class is used to implement proxy around collection classes.
120  	class TVirtualCollectionProxy;
121  	
122  	typedef void (*VoidFuncPtr_t)();  //pointer to void function
123  	
124  	
125  	//---- constants ---------------------------------------------------------------
126  	
127  	#ifndef NULL
128  	#define NULL 0
129  	#endif
130  	
131  	#ifndef R__NULLPTR
132  	#ifndef nullptr
133  	#define nullptr 0
134  	#endif
135  	#endif
136  	
137  	const Bool_t kTRUE  = true;
138  	const Bool_t kFALSE = false;
139  	
140  	const Int_t     kMaxUChar    = 256;
141  	const Int_t     kMaxChar     = kMaxUChar >> 1;
142  	const Int_t     kMinChar     = -kMaxChar - 1;
143  	
144  	const Int_t     kMaxUShort   = 65534;
145  	const Int_t     kMaxShort    = kMaxUShort >> 1;
146  	const Int_t     kMinShort    = -kMaxShort - 1;
147  	
148  	const UInt_t    kMaxUInt     = UInt_t(~0);
149  	const Int_t     kMaxInt      = Int_t(kMaxUInt >> 1);
150  	const Int_t     kMinInt      = -kMaxInt - 1;
151  	
152  	const ULong_t   kMaxULong    = ULong_t(~0);
153  	const Long_t    kMaxLong     = Long_t(kMaxULong >> 1);
154  	const Long_t    kMinLong     = -kMaxLong - 1;
155  	
156  	const ULong64_t kMaxULong64  = ULong64_t(~0LL);
157  	const Long64_t  kMaxLong64   = Long64_t(kMaxULong64 >> 1);
158  	const Long64_t  kMinLong64   = -kMaxLong64 - 1;
159  	
160  	const size_t    kBitsPerByte = 8;
161  	const Ssiz_t    kNPOS        = ~(Ssiz_t)0;
162  	
163  	
164  	//--- bit manipulation ---------------------------------------------------------
165  	
166  	#define BIT(n)       (1ULL << (n))
167  	#define SETBIT(n,i)  ((n) |= BIT(i))
168  	#define CLRBIT(n,i)  ((n) &= ~BIT(i))
169  	#define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
170  	
171  	
172  	//---- debug global ------------------------------------------------------------
173  	
174  	R__EXTERN Int_t gDebug;
175  	
176  	
177  	//---- ClassDef macros ---------------------------------------------------------
178  	
179  	typedef void (*ShowMembersFunc_t)(void *obj, TMemberInspector &R__insp);
180  	class TVirtualIsAProxy;
181  	typedef TClass *(*IsAGlobalFunc_t)(const TClass*, const void *obj);
182  	
183  	// TBuffer.h declares and implements the following 2 operators
184  	template <class Tmpl> TBuffer &operator>>(TBuffer &buf, Tmpl *&obj);
185  	template <class Tmpl> TBuffer &operator<<(TBuffer &buf, const Tmpl *obj);
186  	
187  	// This might get used if we implement setting a class version.
188  	// template <class RootClass> Short_t GetClassVersion(RootClass *);
189  	
190  	namespace ROOT {
191  	
192  	   class TGenericClassInfo;
193  	   typedef void *(*NewFunc_t)(void *);
194  	   typedef void *(*NewArrFunc_t)(Long_t size, void *arena);
195  	   typedef void  (*DelFunc_t)(void *);
196  	   typedef void  (*DelArrFunc_t)(void *);
197  	   typedef void  (*DesFunc_t)(void *);
198  	   typedef void  (*DirAutoAdd_t)(void *, TDirectory *);
199  	   typedef Long64_t (*MergeFunc_t)(void *, TCollection *, TFileMergeInfo *);
200  	   typedef void  (*ResetAfterMergeFunc_t)(void *, TFileMergeInfo *);
201  	
202  	   template <class RootClass> Short_t SetClassVersion(RootClass *);
203  	
204  	   extern TClass *CreateClass(const char *cname, Version_t id,
205  	                              const type_info &info, TVirtualIsAProxy *isa,
206  	                              ShowMembersFunc_t show,
207  	                              const char *dfil, const char *ifil,
208  	                              Int_t dl, Int_t il);
209  	   extern void AddClass(const char *cname, Version_t id, const type_info &info,
210  	                        VoidFuncPtr_t dict, Int_t pragmabits);
211  	   extern void RemoveClass(const char *cname);
212  	   extern void ResetClassVersion(TClass*, const char*, Short_t);
213  	
214  	   extern TNamed *RegisterClassTemplate(const char *name,
215  	                                        const char *file, Int_t line);
216  	
217  	
218  	#if 0
219  	   // This function is only implemented in the dictionary file.
220  	   // The parameter is 'only' for overloading resolution.
221  	   // Used to be a template <class T> TGenericClassInfo *GenerateInitInstance(const T*);
222  	   template <class T> TGenericClassInfo *GetClassInfo(const T* t) {
223  	      TGenericClassInfo *GenerateInitInstance(const T*);
224  	      return CreateInitInstance(t);
225  	   };
226  	#endif
227  	
228  	   class TInitBehavior {
229  	      // This class defines the interface for the class registration and
230  	      // the TClass creation. To modify the default behavior, one would
231  	      // inherit from this class and overload ROOT::DefineBehavior().
232  	      // See TQObject.h and table/inc/Ttypes.h for examples.
233  	   public:
234  	      virtual ~TInitBehavior() { }
235  	      virtual void Register(const char *cname, Version_t id, const type_info &info,
236  	                            VoidFuncPtr_t dict, Int_t pragmabits) const = 0;
237  	      virtual void Unregister(const char *classname) const = 0;
238  	      virtual TClass *CreateClass(const char *cname, Version_t id,
239  	                                  const type_info &info, TVirtualIsAProxy *isa,
240  	                                  ShowMembersFunc_t show,
241  	                                  const char *dfil, const char *ifil,
242  	                                  Int_t dl, Int_t il) const = 0;
243  	   };
244  	
245  	   class TDefaultInitBehavior : public TInitBehavior {
246  	   public:
247  	      virtual void Register(const char *cname, Version_t id, const type_info &info,
248  	                            VoidFuncPtr_t dict, Int_t pragmabits) const {
249  	         ROOT::AddClass(cname, id, info, dict, pragmabits);
250  	      }
251  	      virtual void Unregister(const char *classname) const {
252  	         ROOT::RemoveClass(classname);
253  	      }
254  	      virtual TClass *CreateClass(const char *cname, Version_t id,
255  	                                  const type_info &info, TVirtualIsAProxy *isa,
256  	                                  ShowMembersFunc_t show,
257  	                                  const char *dfil, const char *ifil,
258  	                                  Int_t dl, Int_t il) const {
259  	         return ROOT::CreateClass(cname, id, info, isa, show, dfil, ifil, dl, il);
260  	      }
261  	   };
262  	
263  	   const TInitBehavior *DefineBehavior(void * /*parent_type*/,
264  	                                       void * /*actual_type*/);
265  	
266  	} // End of namespace ROOT
267  	
268  	// The macros below use TGenericClassInfo, so let's ensure it is included
269  	#ifndef ROOT_TGenericClassInfo
270  	#include "TGenericClassInfo.h"
271  	#endif
272  	
273  	#if __cplusplus >= 201103L
274  	typedef std::atomic<TClass*> atomic_TClass_ptr;
275  	#else
276  	typedef TClass* atomic_TClass_ptr;
277  	#endif
278  	// Common part of ClassDef definition.
279  	// DeclFileLine() is not part of it since CINT uses that as trigger for
280  	// the class comment string.
281  	#define _ClassDef_(name,id) \
282  	private: \
283  	   static atomic_TClass_ptr fgIsA; \
284  	public: \
285  	   static TClass *Class(); \
286  	   static const char *Class_Name(); \
287  	   static Version_t Class_Version() { return id; } \
288  	   static void Dictionary(); \
289  	   virtual TClass *IsA() const { return name::Class(); } \
290  	   virtual void ShowMembers(TMemberInspector&); \
291  	   virtual void Streamer(TBuffer&); \
292  	   void StreamerNVirtual(TBuffer&ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \
293  	   static const char *DeclFileName() { return __FILE__; } \
294  	   static int ImplFileLine(); \
295  	   static const char *ImplFileName();
296  	
297  	// Version without any virtual functions.
298  	#define _ClassDefNV_(name,id) \
299  	private: \
300  	static atomic_TClass_ptr fgIsA; \
301  	public: \
302  	static TClass *Class(); \
303  	static const char *Class_Name(); \
304  	static Version_t Class_Version() { return id; } \
305  	static void Dictionary(); \
306  	TClass *IsA() const { return name::Class(); } \
307  	void ShowMembers(TMemberInspector&); \
308  	void Streamer(TBuffer&); \
309  	void StreamerNVirtual(TBuffer &ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \
310  	static const char *DeclFileName() { return __FILE__; } \
311  	static int ImplFileLine(); \
312  	static const char *ImplFileName();
313  	
314  	
315  	#if !defined(R__CONCRETE_INPUT_OPERATOR)
316  	#if !defined(R__ACCESS_IN_SYMBOL) || defined(__CINT__)
317  	
318  	#define ClassDef(name,id) \
319  	   _ClassDef_(name,id) \
320  	   static int DeclFileLine() { return __LINE__; }
321  	
322  	#define ClassDefNV(name,id) \
323  	   _ClassDefNV_(name,id) \
324  	   static int DeclFileLine() { return __LINE__; }
325  	
326  	#else
327  	
328  	#define ClassDef(name,id) \
329  	   _ClassDef_(name,id) \
330  	   friend void ROOT__ShowMembersFunc(name*, TMemberInspector&); \
331  	   static int DeclFileLine() { return __LINE__; }
332  	
333  	#define ClassDefNV(name,id) \
334  	   _ClassDefNV_(name,id) \
335  	   friend void ROOT__ShowMembersFunc(name*, TMemberInspector&); \
336  	   static int DeclFileLine() { return __LINE__; }
337  	
338  	#endif
339  	
340  	#else
341  	
342  	#define ClassDef(name,id) \
343  	   _ClassDef_(name,id) \
344  	   friend TBuffer &operator>>(TBuffer&, name *&); \
345  	   friend TBuffer &operator>>(TBuffer&, const name *&); \
346  	   static int DeclFileLine() { return __LINE__; }
347  	
348  	#define ClassDefNV(name,id) \
349  	   _ClassDefNV_(name,id) \
350  	   friend TBuffer &operator>>(TBuffer&, name *&); \
351  	   friend TBuffer &operator>>(TBuffer&, const name *&); \
352  	   static int DeclFileLine() { return __LINE__; }
353  	
354  	#endif
355  	
356  	#define R__UseDummy(name) \
357  	   class _NAME2_(name,_c) { public: _NAME2_(name,_c)() { if (name) { } } }
358  	
359  	
360  	#if defined(__CINT__)
361  	#define ClassImpUnique(name,key)
362  	#define ClassImp(name)
363  	#else
364  	#define ClassImpUnique(name,key) \
365  	   namespace ROOTDict { \
366  	      ::ROOT::TGenericClassInfo *GenerateInitInstance(const name*); \
367  	      static int _R__UNIQUE_(_NAME2_(R__dummyint,key)) = \
368  	         GenerateInitInstance(( name*)0x0)->SetImplFile(__FILE__, __LINE__); \
369  	      R__UseDummy(_R__UNIQUE_(_NAME2_(R__dummyint,key))); \
370  	   }
371  	#define ClassImp(name) ClassImpUnique(name,default)
372  	#endif
373  	
374  	// Macro for Namespace
375  	
376  	#if defined(__CINT__)
377  	#define NamespaceImpUnique(name,key)
378  	#define NamespaceImp(name)
379  	#else
380  	#define NamespaceImpUnique(name,key) \
381  	   namespace name { \
382  	      namespace ROOTDict { \
383  	         ::ROOT::TGenericClassInfo *GenerateInitInstance(); \
384  	         static int _R__UNIQUE_(_NAME2_(R__dummyint,key)) = \
385  	            GenerateInitInstance()->SetImplFile(__FILE__, __LINE__); \
386  	         R__UseDummy(_R__UNIQUE_(_NAME2_(R__dummyint,key))); \
387  	      } \
388  	   }
389  	#define NamespaceImp(name) NamespaceImpUnique(name,default)
390  	#endif
391  	
392  	//---- ClassDefT macros for templates with one template argument ---------------
393  	// ClassDefT  corresponds to ClassDef
394  	// ClassDefT2 goes in the same header as ClassDefT but must be
395  	//            outside the class scope
396  	// ClassImpT  corresponds to ClassImp
397  	
398  	
399  	// This ClassDefT is stricly redundant and is kept only for
400  	// backward compatibility. Using #define ClassDef ClassDefT is confusing
401  	// the CINT parser.
402  	#if !defined(R__ACCESS_IN_SYMBOL) || defined(__CINT__)
403  	
404  	#define ClassDefT(name,id) \
405  	   _ClassDef_(name,id) \
406  	   static int DeclFileLine() { return __LINE__; }
407  	
408  	#define ClassDefTNV(name,id) \
409  	   _ClassDefNV_(name,id) \
410  	   static int DeclFileLine() { return __LINE__; }
411  	
412  	
413  	#else
414  	
415  	#define ClassDefT(name,id) \
416  	   _ClassDef_(name,id) \
417  	   friend void ROOT__ShowMembersFunc(name *obj, TMemberInspector &R__insp); \
418  	   static int DeclFileLine() { return __LINE__; }
419  	
420  	#define ClassDefTNV(name,id) \
421  	   _ClassDefNV_(name,id) \
422  	   friend void ROOT__ShowMembersFunc(name *obj, TMemberInspector &R__insp); \
423  	   static int DeclFileLine() { return __LINE__; }
424  	
425  	#endif
426  	
427  	#define ClassDefT2(name,Tmpl)
428  	
429  	
430  	
431  	#if defined(__CINT__)
432  	#define templateClassImpUnique(name,key)
433  	#define templateClassImp(name)
434  	#else
435  	#define templateClassImpUnique(name,key) \
436  	   namespace ROOTDict { \
437  	      static TNamed *_R__UNIQUE_(_NAME2_(R__dummyholder,key)) = \
438  	         ROOT::RegisterClassTemplate(_QUOTE_(name), __FILE__, __LINE__); \
439  	      R__UseDummy(_R__UNIQUE_(_NAME2_(R__dummyholder,key))); \
440  	   }
441  	#define templateClassImp(name) templateClassImpUnique(name,default)
442  	#endif
443  	
444  	#define ClassImpT(name,Tmpl) templateClassImp(name)
445  	
446  	//---- ClassDefT macros for templates with two template arguments --------------
447  	// ClassDef2T2 goes in the same header as ClassDefT but must be
448  	//             outside the class scope
449  	// ClassImp2T  corresponds to ClassImpT
450  	
451  	#define ClassDef2T2(name,Tmpl1,Tmpl2)
452  	#define ClassImp2T(name,Tmpl1,Tmpl2) templateClassImp(name)
453  	
454  	
455  	//---- ClassDefT macros for templates with three template arguments ------------
456  	// ClassDef3T2 goes in the same header as ClassDefT but must be
457  	//             outside the class scope
458  	// ClassImp3T  corresponds to ClassImpT
459  	
460  	#define ClassDef3T2(name,Tmpl1,Tmpl2,Tmpl3)
461  	#define ClassImp3T(name,Tmpl1,Tmpl2,Tmpl3) templateClassImp(name)
462  	
463  	
464  	//---- Macro to set the class version of non instrumented classes --------------
465  	
466  	#define RootClassVersion(name,VersionNumber) \
467  	namespace ROOTDict { \
468  	   ::ROOT::TGenericClassInfo *GenerateInitInstance(const name*); \
469  	   static Short_t _R__UNIQUE_(R__dummyVersionNumber) = \
470  	           GenerateInitInstance((name*)0x0)->SetVersion(VersionNumber); \
471  	   R__UseDummy(_R__UNIQUE_(R__dummyVersionNumber)); \
472  	}
473  	
474  	#if defined(__CINT__)
475  	#define RootStreamer(name,STREAMER)
476  	#else
477  	#define RootStreamer(name,STREAMER)                                  \
478  	namespace ROOTDict {                                                 \
479  	   ::ROOT::TGenericClassInfo *GenerateInitInstance(const name*);     \
480  	   static Short_t _R__UNIQUE_(R__dummyStreamer) =                    \
481  	           GenerateInitInstance((name*)0x0)->SetStreamer(STREAMER);  \
482  	   R__UseDummy(_R__UNIQUE_(R__dummyStreamer));                       \
483  	}
484  	#endif
485  	
486  	#endif
487