23 #include "openPMD/Datatype.hpp" 26 #include <type_traits> 32 #if defined( _MSC_VER ) && !defined( __INTEL_COMPILER ) && !defined( __clang__ ) 33 #define OPENPMD_TEMPLATE_OPERATOR operator 35 #define OPENPMD_TEMPLATE_OPERATOR template operator 50 template<
typename T,
typename =
void >
53 static constexpr
bool value =
false;
56 template<
typename T >
59 void_t< decltype(
std::string( std::declval< T >().errorMsg ) ) > >
61 static constexpr
bool value =
true;
84 static ReturnType call( Action action, Args &&... )
88 "[switchType] Action needs either an errorMsg member of type " 89 "std::string or operator()<unsigned>() overloads." );
90 throw std::runtime_error(
91 "[" + std::string( action.errorMsg ) +
"] Unknown Datatype." );
95 template<
int n,
typename ReturnType,
typename Action,
typename... Args >
102 typename
std::enable_if< !HasErrorMessageMember< Action >::value >::type,
105 static ReturnType call( Action action, Args &&... args )
107 return action.OPENPMD_TEMPLATE_OPERATOR()< n >(
108 std::forward< Args >( args )... );
130 template<
typename Action,
typename... Args >
132 action.OPENPMD_TEMPLATE_OPERATOR() <
char >
133 ( std::forward< Args >( args )... ) )
135 using ReturnType = decltype(
136 action.OPENPMD_TEMPLATE_OPERATOR() <
char >
137 ( std::forward< Args >( args )... ) );
141 return action.OPENPMD_TEMPLATE_OPERATOR()<
char >(
142 std::forward< Args >( args )... );
143 case Datatype::UCHAR:
144 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned char >(
145 std::forward< Args >( args )... );
146 case Datatype::SHORT:
147 return action.OPENPMD_TEMPLATE_OPERATOR()<
short >(
148 std::forward< Args >( args )... );
150 return action.OPENPMD_TEMPLATE_OPERATOR()<
int >(
151 std::forward< Args >( args )... );
153 return action.OPENPMD_TEMPLATE_OPERATOR()<
long >(
154 std::forward< Args >( args )... );
155 case Datatype::LONGLONG:
156 return action.OPENPMD_TEMPLATE_OPERATOR()<
long long >(
157 std::forward< Args >( args )... );
158 case Datatype::USHORT:
159 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned short >(
160 std::forward< Args >( args )... );
162 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned int >(
163 std::forward< Args >( args )... );
164 case Datatype::ULONG:
165 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned long >(
166 std::forward< Args >( args )... );
167 case Datatype::ULONGLONG:
168 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned long long >(
169 std::forward< Args >( args )... );
170 case Datatype::FLOAT:
171 return action.OPENPMD_TEMPLATE_OPERATOR()<
float >(
172 std::forward< Args >( args )... );
173 case Datatype::DOUBLE:
174 return action.OPENPMD_TEMPLATE_OPERATOR()<
double >(
175 std::forward< Args >( args )... );
176 case Datatype::LONG_DOUBLE:
177 return action.OPENPMD_TEMPLATE_OPERATOR()<
long double >(
178 std::forward< Args >( args )... );
179 case Datatype::CFLOAT:
180 return action.OPENPMD_TEMPLATE_OPERATOR()< std::complex< float > >(
181 std::forward< Args >( args )... );
182 case Datatype::CDOUBLE:
183 return action.OPENPMD_TEMPLATE_OPERATOR()< std::complex< double > >(
184 std::forward< Args >( args )... );
185 case Datatype::CLONG_DOUBLE:
187 .OPENPMD_TEMPLATE_OPERATOR()< std::complex< long double > >(
188 std::forward< Args >( args )... );
189 case Datatype::STRING:
190 return action.OPENPMD_TEMPLATE_OPERATOR()< std::string >(
191 std::forward< Args >( args )... );
192 case Datatype::VEC_CHAR:
193 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< char > >(
194 std::forward< Args >( args )... );
195 case Datatype::VEC_SHORT:
196 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< short > >(
197 std::forward< Args >( args )... );
198 case Datatype::VEC_INT:
199 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< int > >(
200 std::forward< Args >( args )... );
201 case Datatype::VEC_LONG:
202 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< long > >(
203 std::forward< Args >( args )... );
204 case Datatype::VEC_LONGLONG:
205 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< long long > >(
206 std::forward< Args >( args )... );
207 case Datatype::VEC_UCHAR:
209 .OPENPMD_TEMPLATE_OPERATOR()< std::vector< unsigned char > >(
210 std::forward< Args >( args )... );
211 case Datatype::VEC_USHORT:
213 .OPENPMD_TEMPLATE_OPERATOR()< std::vector< unsigned short > >(
214 std::forward< Args >( args )... );
215 case Datatype::VEC_UINT:
217 .OPENPMD_TEMPLATE_OPERATOR()< std::vector< unsigned int > >(
218 std::forward< Args >( args )... );
219 case Datatype::VEC_ULONG:
221 .OPENPMD_TEMPLATE_OPERATOR()< std::vector< unsigned long > >(
222 std::forward< Args >( args )... );
223 case Datatype::VEC_ULONGLONG:
225 .OPENPMD_TEMPLATE_OPERATOR()< std::vector< unsigned long long > >(
226 std::forward< Args >( args )... );
227 case Datatype::VEC_FLOAT:
228 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< float > >(
229 std::forward< Args >( args )... );
230 case Datatype::VEC_DOUBLE:
231 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< double > >(
232 std::forward< Args >( args )... );
233 case Datatype::VEC_LONG_DOUBLE:
234 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< long double > >(
235 std::forward< Args >( args )... );
236 case Datatype::VEC_CFLOAT:
237 return action.OPENPMD_TEMPLATE_OPERATOR()<
238 std::vector< std::complex< float > > >(
239 std::forward< Args >( args )... );
240 case Datatype::VEC_CDOUBLE:
241 return action.OPENPMD_TEMPLATE_OPERATOR()<
242 std::vector< std::complex< double > > >(
243 std::forward< Args >( args )... );
244 case Datatype::VEC_CLONG_DOUBLE:
245 return action.OPENPMD_TEMPLATE_OPERATOR()<
246 std::vector< std::complex< long double > > >(
247 std::forward< Args >( args )... );
248 case Datatype::VEC_STRING:
249 return action.OPENPMD_TEMPLATE_OPERATOR()< std::vector< std::string > >(
250 std::forward< Args >( args )... );
251 case Datatype::ARR_DBL_7:
252 return action.OPENPMD_TEMPLATE_OPERATOR()< std::array< double, 7 > >(
253 std::forward< Args >( args )... );
255 return action.OPENPMD_TEMPLATE_OPERATOR()<
bool >(
256 std::forward< Args >( args )... );
257 case Datatype::DATATYPE:
264 call( std::move( action ), std::forward< Args >( args )... );
265 case Datatype::UNDEFINED:
272 call( std::move( action ), std::forward< Args >( args )... );
274 throw std::runtime_error(
275 "Internal error: Encountered unknown datatype (switchType) ->" +
276 std::to_string( static_cast< int >( dt ) ) );
298 template<
typename Action,
typename... Args >
301 action.OPENPMD_TEMPLATE_OPERATOR() <
char >
302 ( std::forward< Args >( args )... ) )
304 using ReturnType = decltype(
305 action.OPENPMD_TEMPLATE_OPERATOR() <
char >
306 ( std::forward< Args >( args )... ) );
310 return action.OPENPMD_TEMPLATE_OPERATOR()<
char >(
311 std::forward< Args >( args )... );
312 case Datatype::UCHAR:
313 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned char >(
314 std::forward< Args >( args )... );
315 case Datatype::SHORT:
316 return action.OPENPMD_TEMPLATE_OPERATOR()<
short >(
317 std::forward< Args >( args )... );
319 return action.OPENPMD_TEMPLATE_OPERATOR()<
int >(
320 std::forward< Args >( args )... );
322 return action.OPENPMD_TEMPLATE_OPERATOR()<
long >(
323 std::forward< Args >( args )... );
324 case Datatype::LONGLONG:
325 return action.OPENPMD_TEMPLATE_OPERATOR()<
long long >(
326 std::forward< Args >( args )... );
327 case Datatype::USHORT:
328 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned short >(
329 std::forward< Args >( args )... );
331 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned int >(
332 std::forward< Args >( args )... );
333 case Datatype::ULONG:
334 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned long >(
335 std::forward< Args >( args )... );
336 case Datatype::ULONGLONG:
337 return action.OPENPMD_TEMPLATE_OPERATOR()<
unsigned long long >(
338 std::forward< Args >( args )... );
339 case Datatype::FLOAT:
340 return action.OPENPMD_TEMPLATE_OPERATOR()<
float >(
341 std::forward< Args >( args )... );
342 case Datatype::DOUBLE:
343 return action.OPENPMD_TEMPLATE_OPERATOR()<
double >(
344 std::forward< Args >( args )... );
345 case Datatype::LONG_DOUBLE:
346 return action.OPENPMD_TEMPLATE_OPERATOR()<
long double >(
347 std::forward< Args >( args )... );
348 case Datatype::CFLOAT:
349 return action.OPENPMD_TEMPLATE_OPERATOR()< std::complex< float > >(
350 std::forward< Args >( args )... );
351 case Datatype::CDOUBLE:
352 return action.OPENPMD_TEMPLATE_OPERATOR()< std::complex< double > >(
353 std::forward< Args >( args )... );
354 case Datatype::CLONG_DOUBLE:
356 .OPENPMD_TEMPLATE_OPERATOR()< std::complex< long double > >(
357 std::forward< Args >( args )... );
358 case Datatype::STRING:
359 return action.OPENPMD_TEMPLATE_OPERATOR()< std::string >(
360 std::forward< Args >( args )... );
362 return action.OPENPMD_TEMPLATE_OPERATOR()<
bool >(
363 std::forward< Args >( args )... );
364 case Datatype::DATATYPE:
371 call( std::move( action ), std::forward< Args >( args )... );
372 case Datatype::UNDEFINED:
379 call( std::move( action ), std::forward< Args >( args )... );
381 throw std::runtime_error(
382 "Internal error: Encountered unknown datatype (switchType) ->" +
383 std::to_string( static_cast< int >( dt ) ) );
386 #undef OPENPMD_TEMPLATE_OPERATOR auto switchType(Datatype dt, Action action, Args &&... args) -> decltype(action. template operator()< char >(std::forward< Args >(args)...))
Generalizes switching over an openPMD datatype.
Definition: DatatypeHelpers.hpp:131
Purpose of this struct is to detect at compile time whether Action::template operator()<0>() exists...
Definition: DatatypeHelpers.hpp:82
auto switchNonVectorType(Datatype dt, Action action, Args &&... args) -> decltype(action. template operator()< char >(std::forward< Args >(args)...))
Generalizes switching over an openPMD datatype.
Definition: DatatypeHelpers.hpp:299
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Definition: Container.cpp:51
Definition: DatatypeHelpers.hpp:51
Public definitions of openPMD-api.
Definition: Date.cpp:29