27 #include <type_traits> 41 SHORT, INT, LONG, LONGLONG,
42 USHORT, UINT, ULONG, ULONGLONG,
43 FLOAT, DOUBLE, LONG_DOUBLE,
90 typename std::remove_pointer<
91 typename std::remove_cv<
93 typename std::remove_all_extents< T >::type
97 typename std::remove_pointer<
98 typename std::remove_cv<
100 typename std::remove_all_extents< U >::type
107 #if __cplusplus >= 201402L 115 template<
typename T >
117 #if __cplusplus >= 201402L 138 else if(
decay_equiv<
T, std::vector< char > >::value ){
return DT::VEC_CHAR; }
139 else if(
decay_equiv<
T, std::vector< short > >::value ){
return DT::VEC_SHORT; }
140 else if(
decay_equiv<
T, std::vector< int > >::value ){
return DT::VEC_INT; }
141 else if(
decay_equiv<
T, std::vector< long > >::value ){
return DT::VEC_LONG; }
142 else if(
decay_equiv<
T, std::vector< long long > >::value ){
return DT::VEC_LONGLONG; }
143 else if(
decay_equiv<
T, std::vector< unsigned char > >::value ){
return DT::VEC_UCHAR; }
144 else if(
decay_equiv<
T, std::vector< unsigned short > >::value ){
return DT::VEC_USHORT; }
145 else if(
decay_equiv<
T, std::vector< unsigned int > >::value ){
return DT::VEC_UINT; }
146 else if(
decay_equiv<
T, std::vector< unsigned long > >::value ){
return DT::VEC_ULONG; }
147 else if(
decay_equiv<
T, std::vector< unsigned long long > >::value ){
return DT::VEC_ULONGLONG; }
148 else if(
decay_equiv<
T, std::vector< float > >::value ){
return DT::VEC_FLOAT; }
149 else if(
decay_equiv<
T, std::vector< double > >::value ){
return DT::VEC_DOUBLE; }
150 else if(
decay_equiv<
T, std::vector< long double > >::value ){
return DT::VEC_LONG_DOUBLE; }
151 else if(
decay_equiv<
T, std::vector< std::string > >::value ){
return DT::VEC_STRING; }
152 else if(
decay_equiv<
T, std::array< double, 7 > >::value ){
return DT::ARR_DBL_7; }
154 else return Datatype::UNDEFINED;
157 template<
typename T >
159 #if __cplusplus >= 201402L 163 determineDatatype(std::shared_ptr< T >)
180 else if(
decay_equiv<
T, std::vector< char > >::value ){
return DT::VEC_CHAR; }
181 else if(
decay_equiv<
T, std::vector< short > >::value ){
return DT::VEC_SHORT; }
182 else if(
decay_equiv<
T, std::vector< int > >::value ){
return DT::VEC_INT; }
183 else if(
decay_equiv<
T, std::vector< long > >::value ){
return DT::VEC_LONG; }
184 else if(
decay_equiv<
T, std::vector< long long > >::value ){
return DT::VEC_LONGLONG; }
185 else if(
decay_equiv<
T, std::vector< unsigned char > >::value ){
return DT::VEC_UCHAR; }
186 else if(
decay_equiv<
T, std::vector< unsigned short > >::value ){
return DT::VEC_USHORT; }
187 else if(
decay_equiv<
T, std::vector< unsigned int > >::value ){
return DT::VEC_UINT; }
188 else if(
decay_equiv<
T, std::vector< unsigned long > >::value ){
return DT::VEC_ULONG; }
189 else if(
decay_equiv<
T, std::vector< unsigned long long > >::value ){
return DT::VEC_ULONGLONG; }
190 else if(
decay_equiv<
T, std::vector< float > >::value ){
return DT::VEC_FLOAT; }
191 else if(
decay_equiv<
T, std::vector< double > >::value ){
return DT::VEC_DOUBLE; }
192 else if(
decay_equiv<
T, std::vector< long double > >::value ){
return DT::VEC_LONG_DOUBLE; }
193 else if(
decay_equiv<
T, std::vector< std::string > >::value ){
return DT::VEC_STRING; }
194 else if(
decay_equiv<
T, std::array< double, 7 > >::value ){
return DT::ARR_DBL_7; }
196 else return DT::UNDEFINED;
217 return sizeof(
unsigned char);
224 return sizeof(short);
232 case DT::VEC_LONGLONG:
233 return sizeof(
long long);
236 return sizeof(
unsigned short);
239 return sizeof(
unsigned int);
242 return sizeof(
unsigned long);
244 case DT::VEC_ULONGLONG:
245 return sizeof(
unsigned long long);
248 return sizeof(float);
252 return sizeof(double);
253 case DT::LONG_DOUBLE:
254 case DT::VEC_LONG_DOUBLE:
255 return sizeof(
long double);
261 throw std::runtime_error(
"toBytes: Invalid datatype!");
273 return toBytes( d ) * CHAR_BIT;
292 case DT::VEC_LONGLONG:
297 case DT::VEC_ULONGLONG:
300 case DT::VEC_LONG_DOUBLE:
326 case DT::LONG_DOUBLE:
327 case DT::VEC_LONG_DOUBLE:
341 template<
typename T >
345 Datatype dtype = determineDatatype< T >();
358 inline std::tuple< bool, bool >
372 case DT::VEC_LONGLONG:
373 return std::make_tuple(
true,
true );
381 case DT::VEC_ULONGLONG:
382 return std::make_tuple(
true,
false );
384 return std::make_tuple(
false,
false );
396 template<
typename T >
397 inline std::tuple< bool, bool >
400 Datatype dtype = determineDatatype< T >();
411 template<
typename T_FP >
416 bool tt_is_fp = isFloatingPoint< T_FP >();
437 template<
typename T_Int >
442 bool tt_is_int, tt_is_sig;
443 std::tie(tt_is_int, tt_is_sig) = isInteger< T_Int >();
446 bool dt_is_int, dt_is_sig;
447 std::tie(dt_is_int, dt_is_sig) =
isInteger( d );
452 tt_is_sig == dt_is_sig &&
470 if( static_cast<int>(d) == static_cast<int>(e) )
477 bool d_is_int, d_is_sig;
478 std::tie(d_is_int, d_is_sig) =
isInteger( d );
479 bool e_is_int, e_is_sig;
480 std::tie(e_is_int, e_is_sig) =
isInteger( e );
484 d_is_vec == e_is_vec &&
485 d_is_sig == e_is_sig &&
497 d_is_vec == e_is_vec &&
505 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) 506 #define OPENPMD_TEMPLATE_OPERATOR operator 508 #define OPENPMD_TEMPLATE_OPERATOR template operator 528 template <
typename ReturnType = void,
typename Action,
typename... Args >
534 return action.OPENPMD_TEMPLATE_OPERATOR( )<
char >(
535 std::forward< Args >( args )... );
536 case Datatype::UCHAR:
537 return action.OPENPMD_TEMPLATE_OPERATOR( )<
unsigned char >(
538 std::forward< Args >( args )... );
539 case Datatype::SHORT:
540 return action.OPENPMD_TEMPLATE_OPERATOR( )<
short >(
541 std::forward< Args >( args )... );
543 return action.OPENPMD_TEMPLATE_OPERATOR( )<
int >(
544 std::forward< Args >( args )... );
546 return action.OPENPMD_TEMPLATE_OPERATOR( )<
long >(
547 std::forward< Args >( args )... );
548 case Datatype::LONGLONG:
549 return action.OPENPMD_TEMPLATE_OPERATOR( )<
long long >(
550 std::forward< Args >( args )... );
551 case Datatype::USHORT:
552 return action.OPENPMD_TEMPLATE_OPERATOR( )<
unsigned short >(
553 std::forward< Args >( args )... );
555 return action.OPENPMD_TEMPLATE_OPERATOR( )<
unsigned int >(
556 std::forward< Args >( args )... );
557 case Datatype::ULONG:
558 return action.OPENPMD_TEMPLATE_OPERATOR( )<
unsigned long >(
559 std::forward< Args >( args )... );
560 case Datatype::ULONGLONG:
561 return action.OPENPMD_TEMPLATE_OPERATOR( )<
unsigned long long >(
562 std::forward< Args >( args )... );
563 case Datatype::FLOAT:
564 return action.OPENPMD_TEMPLATE_OPERATOR( )<
float >(
565 std::forward< Args >( args )... );
566 case Datatype::DOUBLE:
567 return action.OPENPMD_TEMPLATE_OPERATOR( )<
double >(
568 std::forward< Args >( args )... );
569 case Datatype::LONG_DOUBLE:
570 return action.OPENPMD_TEMPLATE_OPERATOR( )<
long double >(
571 std::forward< Args >( args )... );
572 case Datatype::STRING:
573 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::string >(
574 std::forward< Args >( args )... );
575 case Datatype::VEC_CHAR:
576 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< char > >(
577 std::forward< Args >( args )... );
578 case Datatype::VEC_SHORT:
579 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< short > >(
580 std::forward< Args >( args )... );
581 case Datatype::VEC_INT:
582 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< int > >(
583 std::forward< Args >( args )... );
584 case Datatype::VEC_LONG:
585 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< long > >(
586 std::forward< Args >( args )... );
587 case Datatype::VEC_LONGLONG:
588 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< long long > >(
589 std::forward< Args >( args )... );
590 case Datatype::VEC_UCHAR:
592 .OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned char > >(
593 std::forward< Args >( args )... );
594 case Datatype::VEC_USHORT:
596 .OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned short > >(
597 std::forward< Args >( args )... );
598 case Datatype::VEC_UINT:
600 .OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned int > >(
601 std::forward< Args >( args )... );
602 case Datatype::VEC_ULONG:
604 .OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned long > >(
605 std::forward< Args >( args )... );
606 case Datatype::VEC_ULONGLONG:
608 .OPENPMD_TEMPLATE_OPERATOR( )< std::vector< unsigned long long > >(
609 std::forward< Args >( args )... );
610 case Datatype::VEC_FLOAT:
611 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< float > >(
612 std::forward< Args >( args )... );
613 case Datatype::VEC_DOUBLE:
614 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::vector< double > >(
615 std::forward< Args >( args )... );
616 case Datatype::VEC_LONG_DOUBLE:
618 .OPENPMD_TEMPLATE_OPERATOR( )< std::vector< long double > >(
619 std::forward< Args >( args )... );
620 case Datatype::VEC_STRING:
622 .OPENPMD_TEMPLATE_OPERATOR( )< std::vector< std::string > >(
623 std::forward< Args >( args )... );
624 case Datatype::ARR_DBL_7:
625 return action.OPENPMD_TEMPLATE_OPERATOR( )< std::array< double, 7 > >(
626 std::forward< Args >( args )... );
628 return action.OPENPMD_TEMPLATE_OPERATOR( )<
bool >(
629 std::forward< Args >( args )... );
630 case Datatype::DATATYPE:
631 return action.OPENPMD_TEMPLATE_OPERATOR( )< 1000 >(
632 std::forward< Args >( args )... );
633 case Datatype::UNDEFINED:
634 return action.OPENPMD_TEMPLATE_OPERATOR( )< 0 >(
635 std::forward< Args >( args )... );
637 throw std::runtime_error(
638 "Internal error: Encountered unknown datatype (switchType) ->" +
639 std::to_string( static_cast< int >( dt ) ) );
643 #undef OPENPMD_TEMPLATE_OPERATOR 648 Datatype m_dt = determineDatatype<T>();
656 template<
typename T,
long n>
662 template <
typename T>
679 std::string datatypeToString(
Datatype dt );
681 Datatype stringToDatatype( std::string s );
683 std::string datatypeToString(
Datatype dt );
685 Datatype stringToDatatype( std::string s );
688 warnWrongDtype(std::string
const& key,
697 #if !defined(_MSC_VER) bool isVector(Datatype d)
Compare if a Datatype is a vector type.
Definition: Datatype.hpp:282
std::vector< Datatype > openPMD_Datatypes
All openPMD datatypes defined in Datatype, listed in order in a vector.
Definition: Datatype.cpp:303
bool isSameFloatingPoint(Datatype d)
Compare if a Datatype is equivalent to a floating point type.
Definition: Datatype.hpp:413
bool isSameInteger(Datatype d)
Compare if a Datatype is equivalent to an integer type.
Definition: Datatype.hpp:439
std::tuple< bool, bool > isInteger(Datatype d)
Compare if a Datatype is an integer type.
Definition: Datatype.hpp:359
Fundamental equivalence check for two given types T and U.
Definition: Datatype.hpp:88
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:38
Definition: Container.cpp:51
size_t toBits(Datatype d)
Return number of bits representing a Datatype.
Definition: Datatype.hpp:271
Definition: Datatype.hpp:647
ReturnType switchType(Datatype dt, Action action, Args &&... args)
Generalizes switching over an openPMD datatype.
Definition: Datatype.hpp:529
Public definitions of openPMD-api.
Definition: Date.cpp:28
Datatype basicDatatype(Datatype dt)
basicDatatype Strip openPMD Datatype of std::vector, std::array et.
Definition: Datatype.cpp:339
size_t toBytes(Datatype d)
Return number of bytes representing a Datatype.
Definition: Datatype.hpp:205
Definition: Datatype.hpp:661
bool isFloatingPoint(Datatype d)
Compare if a Datatype is a floating point type.
Definition: Datatype.hpp:316
bool isSame(openPMD::Datatype const d, openPMD::Datatype const e)
Comparison for two Datatypes.
Definition: Datatype.hpp:467