StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StArchInfo.h
1 
10 #ifndef StArchInfo_h
11 #define StArchInfo_h
12 
13 #include <stdlib.h>
14 
15 #include "TNamed.h"
16 
17 #if !defined(__LITTLE_ENDIAN)
18 # define __LITTLE_ENDIAN 1234
19 #endif
20 #if !defined(__BIG_ENDIAN)
21 # define __BIG_ENDIAN 4321
22 #endif
23 #if !defined(__PDP_ENDIAN)
24 # define __PDP_ENDIAN 3412
25 #endif
26 
27 
28 
29 class StArchInfo :public TNamed {
30  public:
31  StArchInfo();
32  ~StArchInfo();
33 
34 
35  Bool_t isBigEndian();
36  Bool_t isLittleEndian();
37  Int_t Endian();
38 
40  template<typename T> static long align(const T &)
41  {
42  return align<T>();
43  }
44 
46 
51  template<typename T> static int align()
52  {
53  static int done = -1;
54  if (done<0) {
55  struct { char c; T test; } probe;
56  done = ((char*)&probe.test)-&probe.c;
57  }
58  return done;
59  }
60 
62 
67  template <typename C, typename T> static int padding(const T&offset)
68  {
69  long offchar = (long)&offset;
70  long alg = align<C>();
71  return int((alg + ((offchar - 1) & ~(alg - 1))) - offchar);
72  }
73 
75 
80  template <typename T, typename C> static int padding(const T&offset, const C&)
81  {
82  return padding<C,T>(offset);
83  }
84  private:
85  Int_t fEndian;
86 
87  ClassDef(StArchInfo,0)
88 };
89 
90 #endif
Bool_t isBigEndian()
Returns true/false if endianess is/ins&#39;t Big.
Definition: StArchInfo.cxx:30
StArchInfo()
Constructor, initialize variables.
Definition: StArchInfo.cxx:16
static int padding(const T &offset, const C &)
This is an overloaded member function, provided for convenience.
Definition: StArchInfo.h:80
static long align(const T &)
Returns the number of bytes the type T has to be align to.
Definition: StArchInfo.h:40
static int align()
This is an overloaded member function, provided for convenience.
Definition: StArchInfo.h:51
static int padding(const T &offset)
Returns the number of bytes to be added to the offset of the T type to get the C type proper aligned...
Definition: StArchInfo.h:67
Bool_t isLittleEndian()
Returns true/false if endianess is/ins&#39;t Little.
Definition: StArchInfo.cxx:36
~StArchInfo()
Destructore - NOOP.
Definition: StArchInfo.cxx:23