forked from openPMD/openPMD-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatatype.hpp
723 lines (670 loc) · 22.9 KB
/
Datatype.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/* Copyright 2017-2020 Fabian Koller and Franz Poeschel
*
* This file is part of openPMD-api.
*
* openPMD-api is free software: you can redistribute it and/or modify
* it under the terms of of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* openPMD-api is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with openPMD-api.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <array>
#include <cstdint>
#include <iosfwd>
#include <memory>
#include <type_traits>
#include <vector>
#include <tuple>
#include <climits>
#include <map>
#include <string>
namespace openPMD
{
/** Concrete datatype of an object available at runtime.
*/
enum class Datatype : int
{
CHAR = 0, UCHAR, // SCHAR,
SHORT, INT, LONG, LONGLONG,
USHORT, UINT, ULONG, ULONGLONG,
FLOAT, DOUBLE, LONG_DOUBLE,
STRING,
VEC_CHAR,
VEC_SHORT,
VEC_INT,
VEC_LONG,
VEC_LONGLONG,
VEC_UCHAR,
VEC_USHORT,
VEC_UINT,
VEC_ULONG,
VEC_ULONGLONG,
VEC_FLOAT,
VEC_DOUBLE,
VEC_LONG_DOUBLE,
VEC_STRING,
ARR_DBL_7,
BOOL,
DATATYPE = 1000,
UNDEFINED
}; // Datatype
/**
* @brief All openPMD datatypes defined in Datatype,
* listed in order in a vector.
*
*/
extern std::vector< Datatype > openPMD_Datatypes;
/** @brief Fundamental equivalence check for two given types T and U.
*
* This checks whether the fundamental datatype (i.e. that of a single value
* indicated by a (multi-)pointer, a C-style array or a scalar) of one type
* equals the fundamendtal datatype of another type.
*
* @tparam T first type
* @tparam U second type
*/
template<
typename T,
typename U
>
struct decay_equiv :
std::is_same<
typename std::remove_pointer<
typename std::remove_cv<
typename std::decay<
typename std::remove_all_extents< T >::type
>::type
>::type
>::type,
typename std::remove_pointer<
typename std::remove_cv<
typename std::decay<
typename std::remove_all_extents< U >::type
>::type
>::type
>::type
>::type
{ };
#if __cplusplus >= 201402L
template<
typename T,
typename U
>
constexpr bool decay_equiv_v = decay_equiv< T, U >::value;
#endif
template< typename T >
inline
#if __cplusplus >= 201402L
constexpr
#endif
Datatype
determineDatatype()
{
using DT = Datatype;
if( decay_equiv< T, char >::value ){ return DT::CHAR; }
else if( decay_equiv< T, unsigned char >::value ){ return DT::UCHAR; }
else if( decay_equiv< T, short >::value ){ return DT::SHORT; }
else if( decay_equiv< T, int >::value ){ return DT::INT; }
else if( decay_equiv< T, long >::value ){ return DT::LONG; }
else if( decay_equiv< T, long long >::value ){ return DT::LONGLONG; }
else if( decay_equiv< T, unsigned short >::value ){ return DT::USHORT; }
else if( decay_equiv< T, unsigned int >::value ){ return DT::UINT; }
else if( decay_equiv< T, unsigned long >::value ){ return DT::ULONG; }
else if( decay_equiv< T, unsigned long long >::value ){ return DT::ULONGLONG; }
else if( decay_equiv< T, float >::value ){ return DT::FLOAT; }
else if( decay_equiv< T, double >::value ){ return DT::DOUBLE; }
else if( decay_equiv< T, long double >::value ){ return DT::LONG_DOUBLE; }
else if( decay_equiv< T, std::string >::value ){ return DT::STRING; }
else if( decay_equiv< T, std::vector< char > >::value ){ return DT::VEC_CHAR; }
else if( decay_equiv< T, std::vector< short > >::value ){ return DT::VEC_SHORT; }
else if( decay_equiv< T, std::vector< int > >::value ){ return DT::VEC_INT; }
else if( decay_equiv< T, std::vector< long > >::value ){ return DT::VEC_LONG; }
else if( decay_equiv< T, std::vector< long long > >::value ){ return DT::VEC_LONGLONG; }
else if( decay_equiv< T, std::vector< unsigned char > >::value ){ return DT::VEC_UCHAR; }
else if( decay_equiv< T, std::vector< unsigned short > >::value ){ return DT::VEC_USHORT; }
else if( decay_equiv< T, std::vector< unsigned int > >::value ){ return DT::VEC_UINT; }
else if( decay_equiv< T, std::vector< unsigned long > >::value ){ return DT::VEC_ULONG; }
else if( decay_equiv< T, std::vector< unsigned long long > >::value ){ return DT::VEC_ULONGLONG; }
else if( decay_equiv< T, std::vector< float > >::value ){ return DT::VEC_FLOAT; }
else if( decay_equiv< T, std::vector< double > >::value ){ return DT::VEC_DOUBLE; }
else if( decay_equiv< T, std::vector< long double > >::value ){ return DT::VEC_LONG_DOUBLE; }
else if( decay_equiv< T, std::vector< std::string > >::value ){ return DT::VEC_STRING; }
else if( decay_equiv< T, std::array< double, 7 > >::value ){ return DT::ARR_DBL_7; }
else if( decay_equiv< T, bool >::value ){ return DT::BOOL; }
else return Datatype::UNDEFINED;
}
template< typename T >
inline
#if __cplusplus >= 201402L
constexpr
#endif
Datatype
determineDatatype(std::shared_ptr< T >)
{
using DT = Datatype;
if( decay_equiv< T, char >::value ){ return DT::CHAR; }
else if( decay_equiv< T, unsigned char >::value ){ return DT::UCHAR; }
else if( decay_equiv< T, short >::value ){ return DT::SHORT; }
else if( decay_equiv< T, int >::value ){ return DT::INT; }
else if( decay_equiv< T, long >::value ){ return DT::LONG; }
else if( decay_equiv< T, long long >::value ){ return DT::LONGLONG; }
else if( decay_equiv< T, unsigned short >::value ){ return DT::USHORT; }
else if( decay_equiv< T, unsigned int >::value ){ return DT::UINT; }
else if( decay_equiv< T, unsigned long >::value ){ return DT::ULONG; }
else if( decay_equiv< T, unsigned long long >::value ){ return DT::ULONGLONG; }
else if( decay_equiv< T, float >::value ){ return DT::FLOAT; }
else if( decay_equiv< T, double >::value ){ return DT::DOUBLE; }
else if( decay_equiv< T, long double >::value ){ return DT::LONG_DOUBLE; }
else if( decay_equiv< T, std::string >::value ){ return DT::STRING; }
else if( decay_equiv< T, std::vector< char > >::value ){ return DT::VEC_CHAR; }
else if( decay_equiv< T, std::vector< short > >::value ){ return DT::VEC_SHORT; }
else if( decay_equiv< T, std::vector< int > >::value ){ return DT::VEC_INT; }
else if( decay_equiv< T, std::vector< long > >::value ){ return DT::VEC_LONG; }
else if( decay_equiv< T, std::vector< long long > >::value ){ return DT::VEC_LONGLONG; }
else if( decay_equiv< T, std::vector< unsigned char > >::value ){ return DT::VEC_UCHAR; }
else if( decay_equiv< T, std::vector< unsigned short > >::value ){ return DT::VEC_USHORT; }
else if( decay_equiv< T, std::vector< unsigned int > >::value ){ return DT::VEC_UINT; }
else if( decay_equiv< T, std::vector< unsigned long > >::value ){ return DT::VEC_ULONG; }
else if( decay_equiv< T, std::vector< unsigned long long > >::value ){ return DT::VEC_ULONGLONG; }
else if( decay_equiv< T, std::vector< float > >::value ){ return DT::VEC_FLOAT; }
else if( decay_equiv< T, std::vector< double > >::value ){ return DT::VEC_DOUBLE; }
else if( decay_equiv< T, std::vector< long double > >::value ){ return DT::VEC_LONG_DOUBLE; }
else if( decay_equiv< T, std::vector< std::string > >::value ){ return DT::VEC_STRING; }
else if( decay_equiv< T, std::array< double, 7 > >::value ){ return DT::ARR_DBL_7; }
else if( decay_equiv< T, bool >::value ){ return DT::BOOL; }
else return DT::UNDEFINED;
}
/** Return number of bytes representing a Datatype
*
* @param d Datatype
* @return number of bytes
*/
inline size_t
toBytes( Datatype d )
{
using DT = Datatype;
switch( d )
{
case DT::CHAR:
case DT::VEC_CHAR:
case DT::STRING:
case DT::VEC_STRING:
return sizeof(char);
case DT::UCHAR:
case DT::VEC_UCHAR:
return sizeof(unsigned char);
// case DT::SCHAR:
// case DT::VEC_SCHAR:
// return sizeof(signed char);
// break;
case DT::SHORT:
case DT::VEC_SHORT:
return sizeof(short);
case DT::INT:
case DT::VEC_INT:
return sizeof(int);
case DT::LONG:
case DT::VEC_LONG:
return sizeof(long);
case DT::LONGLONG:
case DT::VEC_LONGLONG:
return sizeof(long long);
case DT::USHORT:
case DT::VEC_USHORT:
return sizeof(unsigned short);
case DT::UINT:
case DT::VEC_UINT:
return sizeof(unsigned int);
case DT::ULONG:
case DT::VEC_ULONG:
return sizeof(unsigned long);
case DT::ULONGLONG:
case DT::VEC_ULONGLONG:
return sizeof(unsigned long long);
case DT::FLOAT:
case DT::VEC_FLOAT:
return sizeof(float);
case DT::DOUBLE:
case DT::VEC_DOUBLE:
case DT::ARR_DBL_7:
return sizeof(double);
case DT::LONG_DOUBLE:
case DT::VEC_LONG_DOUBLE:
return sizeof(long double);
case DT::BOOL:
return sizeof(bool);
case DT::DATATYPE:
case DT::UNDEFINED:
default:
throw std::runtime_error("toBytes: Invalid datatype!");
}
}
/** Return number of bits representing a Datatype
*
* @param d Datatype
* @return number of bits
*/
inline size_t
toBits( Datatype d )
{
return toBytes( d ) * CHAR_BIT;
}
/** Compare if a Datatype is a vector type
*
* @param d Datatype to test
* @return true if vector type, else false
*/
inline bool
isVector( Datatype d )
{
using DT = Datatype;
switch( d )
{
case DT::VEC_CHAR:
case DT::VEC_SHORT:
case DT::VEC_INT:
case DT::VEC_LONG:
case DT::VEC_LONGLONG:
case DT::VEC_UCHAR:
case DT::VEC_USHORT:
case DT::VEC_UINT:
case DT::VEC_ULONG:
case DT::VEC_ULONGLONG:
case DT::VEC_FLOAT:
case DT::VEC_DOUBLE:
case DT::VEC_LONG_DOUBLE:
case DT::VEC_STRING:
return true;
default:
return false;
}
}
/** Compare if a Datatype is a floating point type
*
* Equivalent to std::is_floating_point including our vector types
*
* @param d Datatype to test
* @return true if floating point, otherwise false
*/
inline bool
isFloatingPoint( Datatype d )
{
using DT = Datatype;
switch( d )
{
case DT::FLOAT:
case DT::VEC_FLOAT:
case DT::DOUBLE:
case DT::VEC_DOUBLE:
case DT::LONG_DOUBLE:
case DT::VEC_LONG_DOUBLE:
return true;
default:
return false;
}
}
/** Compare if a type is a floating point type
*
* Just std::is_floating_point but also valid for std::vector< > types
*
* @tparam T type to test
* @return true if floating point, otherwise false
*/
template< typename T >
inline bool
isFloatingPoint()
{
Datatype dtype = determineDatatype< T >();
return isFloatingPoint( dtype );
}
/** Compare if a Datatype is an integer type
*
* contrary to std::is_integer, the types bool and char types are not
* considered ints in this function
*
* @param d Datatype to test
* @return std::tuple<bool, bool> with isInteger and isSigned result
*/
inline std::tuple< bool, bool >
isInteger( Datatype d )
{
using DT = Datatype;
switch( d )
{
case DT::SHORT:
case DT::VEC_SHORT:
case DT::INT:
case DT::VEC_INT:
case DT::LONG:
case DT::VEC_LONG:
case DT::LONGLONG:
case DT::VEC_LONGLONG:
return std::make_tuple( true, true );
case DT::USHORT:
case DT::VEC_USHORT:
case DT::UINT:
case DT::VEC_UINT:
case DT::ULONG:
case DT::VEC_ULONG:
case DT::ULONGLONG:
case DT::VEC_ULONGLONG:
return std::make_tuple( true, false );
default:
return std::make_tuple( false, false );
}
}
/** Compare if a type is an integer type
*
* contrary to std::is_integer, the types bool and char types are not
* considered ints in this function
*
* @tparam T type to test
* @return std::tuple<bool, bool> with isInteger and isSigned result
*/
template< typename T >
inline std::tuple< bool, bool >
isInteger()
{
Datatype dtype = determineDatatype< T >();
return isInteger( dtype );
}
/** Compare if a Datatype is equivalent to a floating point type
*
* @tparam T_FP floating point type to compare
* @param d Datatype to compare
* @return true if both types are floating point and same bitness, else false
*/
template< typename T_FP >
inline bool
isSameFloatingPoint( Datatype d )
{
// template
bool tt_is_fp = isFloatingPoint< T_FP >();
// Datatype
bool dt_is_fp = isFloatingPoint( d );
if(
tt_is_fp &&
dt_is_fp &&
toBits( d ) == toBits( determineDatatype< T_FP >() )
)
return true;
else
return false;
}
/** Compare if a Datatype is equivalent to an integer type
*
* @tparam T_Int signed or unsigned integer type to compare
* @param d Datatype to compare
* @return true if both types are integers, same signed and same bitness, else false
*/
template< typename T_Int >
inline bool
isSameInteger( Datatype d )
{
// template
bool tt_is_int, tt_is_sig;
std::tie(tt_is_int, tt_is_sig) = isInteger< T_Int >();
// Datatype
bool dt_is_int, dt_is_sig;
std::tie(dt_is_int, dt_is_sig) = isInteger( d );
if(
tt_is_int &&
dt_is_int &&
tt_is_sig == dt_is_sig &&
toBits( d ) == toBits( determineDatatype< T_Int >() )
)
return true;
else
return false;
}
/** Comparison for two Datatypes
*
* Besides returning true for the same types, identical implementations on
* some platforms, e.g. if long and long long are the same or double and
* long double will also return true.
*/
inline bool
isSame( openPMD::Datatype const d, openPMD::Datatype const e )
{
// exact same type
if( static_cast<int>(d) == static_cast<int>(e) )
return true;
bool d_is_vec = isVector( d );
bool e_is_vec = isVector( e );
// same int
bool d_is_int, d_is_sig;
std::tie(d_is_int, d_is_sig) = isInteger( d );
bool e_is_int, e_is_sig;
std::tie(e_is_int, e_is_sig) = isInteger( e );
if(
d_is_int &&
e_is_int &&
d_is_vec == e_is_vec &&
d_is_sig == e_is_sig &&
toBits( d ) == toBits( e )
)
return true;
// same float
bool d_is_fp = isFloatingPoint( d );
bool e_is_fp = isFloatingPoint( e );
if(
d_is_fp &&
e_is_fp &&
d_is_vec == e_is_vec &&
toBits( d ) == toBits( e )
)
return true;
return false;
}
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#define OPENPMD_TEMPLATE_OPERATOR operator
#else
#define OPENPMD_TEMPLATE_OPERATOR template operator
#endif
/**
* Generalizes switching over an openPMD datatype.
*
* Will call the functor passed
* to it using the C++ internal datatype corresponding to the openPMD datatype
* as template parameter for the templated <operator()>().
*
* @tparam ReturnType The functor's return type.
* @tparam Action The functor's type.
* @tparam Args The functors argument types.
* @param dt The openPMD datatype.
* @param action The functor.
* @param args The functor's arguments.
* @return The return value of the functor, when calling its <operator()>() with
* the passed arguments and the template parameter type corresponding to the
* openPMD type.
*/
template < typename ReturnType = void, typename Action, typename... Args >
ReturnType switchType( Datatype dt, Action action, Args &&... args )
{
switch ( dt )
{
case Datatype::CHAR:
return action.OPENPMD_TEMPLATE_OPERATOR( )< char >(
std::forward< Args >( args )... );
case Datatype::UCHAR:
return action.OPENPMD_TEMPLATE_OPERATOR( )< unsigned char >(
std::forward< Args >( args )... );
case Datatype::SHORT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< short >(
std::forward< Args >( args )... );
case Datatype::INT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< int >(
std::forward< Args >( args )... );
case Datatype::LONG:
return action.OPENPMD_TEMPLATE_OPERATOR( )< long >(
std::forward< Args >( args )... );
case Datatype::LONGLONG:
return action.OPENPMD_TEMPLATE_OPERATOR( )< long long >(
std::forward< Args >( args )... );
case Datatype::USHORT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< unsigned short >(
std::forward< Args >( args )... );
case Datatype::UINT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< unsigned int >(
std::forward< Args >( args )... );
case Datatype::ULONG:
return action.OPENPMD_TEMPLATE_OPERATOR( )< unsigned long >(
std::forward< Args >( args )... );
case Datatype::ULONGLONG:
return action.OPENPMD_TEMPLATE_OPERATOR( )< unsigned long long >(
std::forward< Args >( args )... );
case Datatype::FLOAT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< float >(
std::forward< Args >( args )... );
case Datatype::DOUBLE:
return action.OPENPMD_TEMPLATE_OPERATOR( )< double >(
std::forward< Args >( args )... );
case Datatype::LONG_DOUBLE:
return action.OPENPMD_TEMPLATE_OPERATOR( )< long double >(
std::forward< Args >( args )... );
case Datatype::STRING:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::string >(
std::forward< Args >( args )... );
case Datatype::VEC_CHAR:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< char > >(
std::forward< Args >( args )... );
case Datatype::VEC_SHORT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< short > >(
std::forward< Args >( args )... );
case Datatype::VEC_INT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< int > >(
std::forward< Args >( args )... );
case Datatype::VEC_LONG:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< long > >(
std::forward< Args >( args )... );
case Datatype::VEC_LONGLONG:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< long long > >(
std::forward< Args >( args )... );
case Datatype::VEC_UCHAR:
return action
.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned char > >(
std::forward< Args >( args )... );
case Datatype::VEC_USHORT:
return action
.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned short > >(
std::forward< Args >( args )... );
case Datatype::VEC_UINT:
return action
.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned int > >(
std::forward< Args >( args )... );
case Datatype::VEC_ULONG:
return action
.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned long > >(
std::forward< Args >( args )... );
case Datatype::VEC_ULONGLONG:
return action
.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned long long > >(
std::forward< Args >( args )... );
case Datatype::VEC_FLOAT:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< float > >(
std::forward< Args >( args )... );
case Datatype::VEC_DOUBLE:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< double > >(
std::forward< Args >( args )... );
case Datatype::VEC_LONG_DOUBLE:
return action
.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< long double > >(
std::forward< Args >( args )... );
case Datatype::VEC_STRING:
return action
.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< std::string > >(
std::forward< Args >( args )... );
case Datatype::ARR_DBL_7:
return action.OPENPMD_TEMPLATE_OPERATOR( )< std::array< double, 7 > >(
std::forward< Args >( args )... );
case Datatype::BOOL:
return action.OPENPMD_TEMPLATE_OPERATOR( )< bool >(
std::forward< Args >( args )... );
case Datatype::DATATYPE:
return action.OPENPMD_TEMPLATE_OPERATOR( )< 1000 >(
std::forward< Args >( args )... );
case Datatype::UNDEFINED:
return action.OPENPMD_TEMPLATE_OPERATOR( )< 0 >(
std::forward< Args >( args )... );
default:
throw std::runtime_error(
"Internal error: Encountered unknown datatype (switchType) ->" +
std::to_string( static_cast< int >( dt ) ) );
}
}
#undef OPENPMD_TEMPLATE_OPERATOR
namespace detail {
template<typename T>
struct BasicDatatypeHelper {
Datatype m_dt = determineDatatype<T>();
};
template<typename T>
struct BasicDatatypeHelper<std::vector<T>> {
Datatype m_dt = BasicDatatypeHelper<T>{}.m_dt;
};
template<typename T, long n>
struct BasicDatatypeHelper<std::array<T, n>> {
Datatype m_dt = BasicDatatypeHelper<T>{}.m_dt;
};
struct BasicDatatype {
template <typename T>
Datatype operator()();
template <int n>
Datatype operator()();
};
}
/**
* @brief basicDatatype Strip openPMD Datatype of std::vector, std::array et. al.
* @param dt The "full" Datatype.
* @return The "inner" Datatype.
*/
Datatype basicDatatype(Datatype dt);
Datatype toVectorType(Datatype dt);
std::string datatypeToString( Datatype dt );
Datatype stringToDatatype( std::string s );
std::string datatypeToString( Datatype dt );
Datatype stringToDatatype( std::string s );
void
warnWrongDtype(std::string const& key,
Datatype store,
Datatype request);
std::ostream&
operator<<(std::ostream&, openPMD::Datatype const&);
} // namespace openPMD
#if !defined(_MSC_VER)
/** Comparison Operator for Datatype
*
* Overwrite the builtin default comparison which would only match exact same
* Datatype.
*
* Broken in MSVC < 19.11 (before Visual Studio 2017.3)
* https://stackoverflow.com/questions/44515148/why-is-operator-overload-of-enum-ambiguous-in-msvc
*
* @see openPMD::isSame
*
* @{
*/
inline bool
operator==( openPMD::Datatype d, openPMD::Datatype e )
{
return openPMD::isSame(d, e);
}
inline bool
operator!=( openPMD::Datatype d, openPMD::Datatype e )
{
return !(d == e);
}
/** @}
*/
#endif