Monarch  v3.8.2
Project 8 Data File Format Library
M3Types.hh
Go to the documentation of this file.
1 /*
2  * MTypes.hh
3  *
4  * Created on: Dec 4, 2014
5  * Author: nsoblath
6  */
7 
8 #ifndef M3TYPES_HH_
9 #define M3TYPES_HH_
10 
11 #include "M3Exception.hh"
12 
13 #include "H5Cpp.h"
14 
15 #include <inttypes.h>
16 #include <memory>
17 #include <mutex>
18 #include <string>
19 
20 namespace monarch3
21 {
22  typedef uint8_t byte_type;
23 
24  typedef uint64_t AcquisitionIdType;
25  typedef uint64_t RecordIdType;
26  typedef uint64_t TimeType;
27 
28  typedef std::shared_ptr< std::mutex > mutex_ptr;
29 
30  template<typename T, typename U>
31  struct is_same
32  {
33  static const bool value = false;
34  };
35 
36  template<typename T>
37  struct is_same<T,T> //specialization
38  {
39  static const bool value = true;
40  };
41 
42  template<bool> struct staticassert;
43  template<> struct staticassert<true> {}; //specialization
44 
45  template< typename T >
46  struct MH5Type
47  {
48  static H5::DataType Native( T )
49  {
50  throw M3Exception() << "Unknown native type requested";
51  }
52  static H5::DataType H5( T )
53  {
54  throw M3Exception() << "Unknown H5 type requested";
55  }
56  };
57 
58  template<>
59  struct MH5Type< bool >
60  {
61  static H5::DataType Native()
62  {
63  return H5::PredType::NATIVE_UINT8;
64  }
65  static H5::DataType H5()
66  {
67  return H5::PredType::STD_U8LE;
68  }
69  };
70 
71  template<>
72  struct MH5Type< int8_t >
73  {
74  static H5::DataType Native()
75  {
76  return H5::PredType::NATIVE_INT8;
77  }
78  static H5::DataType H5()
79  {
80  return H5::PredType::STD_I8LE;
81  }
82  };
83 
84  template<>
85  struct MH5Type< uint8_t >
86  {
87  static H5::DataType Native()
88  {
89  return H5::PredType::NATIVE_UINT8;
90  }
91  static H5::DataType H5()
92  {
93  return H5::PredType::STD_U8LE;
94  }
95  };
96 
97  template<>
98  struct MH5Type< int16_t >
99  {
100  static H5::DataType Native()
101  {
102  return H5::PredType::NATIVE_INT16;
103  }
104  static H5::DataType H5()
105  {
106  return H5::PredType::STD_I16LE;
107  }
108  };
109 
110  template<>
111  struct MH5Type< uint16_t >
112  {
113  static H5::DataType Native()
114  {
115  return H5::PredType::NATIVE_UINT16;
116  }
117  static H5::DataType H5()
118  {
119  return H5::PredType::STD_U16LE;
120  }
121  };
122 
123  template<>
124  struct MH5Type< int32_t >
125  {
126  static H5::DataType Native()
127  {
128  return H5::PredType::NATIVE_INT32;
129  }
130  static H5::DataType H5()
131  {
132  return H5::PredType::STD_I32LE;
133  }
134  };
135 
136  template<>
137  struct MH5Type< uint32_t >
138  {
139  static H5::DataType Native()
140  {
141  return H5::PredType::NATIVE_UINT32;
142  }
143  static H5::DataType H5()
144  {
145  return H5::PredType::STD_U32LE;
146  }
147  };
148 
149  template<>
150  struct MH5Type< int64_t >
151  {
152  static H5::DataType Native()
153  {
154  return H5::PredType::NATIVE_INT64;
155  }
156  static H5::DataType H5()
157  {
158  return H5::PredType::STD_I64LE;
159  }
160  };
161 
162  template<>
163  struct MH5Type< uint64_t >
164  {
165  static H5::DataType Native()
166  {
167  return H5::PredType::NATIVE_UINT64;
168  }
169  static H5::DataType H5()
170  {
171  return H5::PredType::STD_U64LE;
172  }
173  };
174 
175  template<>
176  struct MH5Type< float >
177  {
178  static H5::DataType Native()
179  {
180  return H5::PredType::NATIVE_FLOAT;
181  }
182  static H5::DataType H5()
183  {
184  return H5::PredType::IEEE_F32LE;
185  }
186  };
187 
188  template<>
189  struct MH5Type< double >
190  {
191  static H5::DataType Native()
192  {
193  return H5::PredType::NATIVE_DOUBLE;
194  }
195  static H5::DataType H5()
196  {
197  return H5::PredType::IEEE_F64LE;
198  }
199  };
200 
201  template<>
202  struct MH5Type< std::string >
203  {
204  static H5::DataType Native()
205  {
206  return H5::StrType( H5::PredType::NATIVE_CHAR, 0 );
207  }
208  static H5::DataType Native( const std::string& aString )
209  {
210  return H5::StrType( H5::PredType::NATIVE_CHAR, aString.length() + 1 );
211  }
212  static H5::DataType Native( size_t aSize )
213  {
214  return H5::StrType( H5::PredType::NATIVE_CHAR, aSize + 1 );
215  }
216  static H5::DataType H5()
217  {
218  return H5::StrType( H5::PredType::C_S1, 0 );
219  }
220  static H5::DataType H5( const std::string& aString )
221  {
222  return H5::StrType( H5::PredType::C_S1, aString.length() + 1 );
223  }
224  static H5::DataType H5( size_t aSize )
225  {
226  return H5::StrType( H5::PredType::C_S1, aSize + 1 );
227  }
228  };
229 
230 }
231 
232 #endif // MTYPES_HH_
static H5::DataType Native(T)
Definition: M3Types.hh:48
static H5::DataType H5()
Definition: M3Types.hh:91
static H5::DataType H5()
Definition: M3Types.hh:130
static H5::DataType H5()
Definition: M3Types.hh:117
static H5::DataType Native()
Definition: M3Types.hh:139
static H5::DataType Native()
Definition: M3Types.hh:178
static H5::DataType H5()
Definition: M3Types.hh:104
static H5::DataType Native()
Definition: M3Types.hh:74
STL namespace.
static H5::DataType Native()
Definition: M3Types.hh:113
static H5::DataType Native()
Definition: M3Types.hh:191
static H5::DataType Native()
Definition: M3Types.hh:126
uint8_t byte_type
Definition: M3Types.hh:22
static H5::DataType H5()
Definition: M3Types.hh:195
static H5::DataType H5()
Definition: M3Types.hh:156
static H5::DataType H5()
Definition: M3Types.hh:78
static const bool value
Definition: M3Types.hh:33
static H5::DataType Native()
Definition: M3Types.hh:152
static H5::DataType Native(size_t aSize)
Definition: M3Types.hh:212
uint64_t RecordIdType
Definition: M3Types.hh:25
static H5::DataType H5()
Definition: M3Types.hh:169
uint64_t TimeType
Definition: M3Types.hh:26
Specialized exception class for Monarch3.
Definition: M3Exception.hh:28
static H5::DataType Native()
Definition: M3Types.hh:204
static H5::DataType Native()
Definition: M3Types.hh:61
static H5::DataType H5(size_t aSize)
Definition: M3Types.hh:224
static H5::DataType Native()
Definition: M3Types.hh:100
static H5::DataType Native()
Definition: M3Types.hh:87
static H5::DataType H5(const std::string &aString)
Definition: M3Types.hh:220
static H5::DataType H5()
Definition: M3Types.hh:216
static H5::DataType H5()
Definition: M3Types.hh:143
static H5::DataType Native()
Definition: M3Types.hh:165
static H5::DataType Native(const std::string &aString)
Definition: M3Types.hh:208
uint64_t AcquisitionIdType
Definition: M3Types.hh:24
std::shared_ptr< std::mutex > mutex_ptr
Definition: M3Types.hh:28
static H5::DataType H5()
Definition: M3Types.hh:182
static H5::DataType H5(T)
Definition: M3Types.hh:52
static H5::DataType H5()
Definition: M3Types.hh:65