33 #include <type_traits> 40 constexpr
int LOWEST_DATATYPE = 0;
41 constexpr
int HIGHEST_DATATYPE = 1000;
47 CHAR = LOWEST_DATATYPE,
85 DATATYPE = HIGHEST_DATATYPE,
106 template <
typename T,
typename U>
109 typename std::remove_pointer<typename std::remove_cv<
110 typename std::decay<typename std::remove_all_extents<T>::type>::
112 typename std::remove_pointer<typename std::remove_cv<
113 typename std::decay<typename std::remove_all_extents<U>::type>::
114 type>::type>::type>::type
117 template <
typename T,
typename U>
120 template <
typename T>
121 inline constexpr
Datatype determineDatatype()
162 return DT::ULONGLONG;
174 return DT::LONG_DOUBLE;
184 else if (
decay_equiv<
T, std::complex<long double>>::value)
186 return DT::CLONG_DOUBLE;
198 return DT::VEC_SHORT;
210 return DT::VEC_LONGLONG;
212 else if (
decay_equiv<
T, std::vector<unsigned char>>::value)
214 return DT::VEC_UCHAR;
216 else if (
decay_equiv<
T, std::vector<unsigned short>>::value)
218 return DT::VEC_USHORT;
220 else if (
decay_equiv<
T, std::vector<unsigned int>>::value)
224 else if (
decay_equiv<
T, std::vector<unsigned long>>::value)
226 return DT::VEC_ULONG;
228 else if (
decay_equiv<
T, std::vector<unsigned long long>>::value)
230 return DT::VEC_ULONGLONG;
234 return DT::VEC_FLOAT;
238 return DT::VEC_DOUBLE;
240 else if (
decay_equiv<
T, std::vector<long double>>::value)
242 return DT::VEC_LONG_DOUBLE;
244 else if (
decay_equiv<
T, std::vector<std::complex<float>>>::value)
246 return DT::VEC_CFLOAT;
248 else if (
decay_equiv<
T, std::vector<std::complex<double>>>::value)
250 return DT::VEC_CDOUBLE;
252 else if (
decay_equiv<
T, std::vector<std::complex<long double>>>::value)
254 return DT::VEC_CLONG_DOUBLE;
256 else if (
decay_equiv<
T, std::vector<std::string>>::value)
258 return DT::VEC_STRING;
262 return DT::ARR_DBL_7;
269 return Datatype::UNDEFINED;
272 template <
typename T>
273 inline constexpr
Datatype determineDatatype(std::shared_ptr<T>)
314 return DT::ULONGLONG;
326 return DT::LONG_DOUBLE;
336 else if (
decay_equiv<
T, std::complex<long double>>::value)
338 return DT::CLONG_DOUBLE;
350 return DT::VEC_SHORT;
362 return DT::VEC_LONGLONG;
364 else if (
decay_equiv<
T, std::vector<unsigned char>>::value)
366 return DT::VEC_UCHAR;
368 else if (
decay_equiv<
T, std::vector<unsigned short>>::value)
370 return DT::VEC_USHORT;
372 else if (
decay_equiv<
T, std::vector<unsigned int>>::value)
376 else if (
decay_equiv<
T, std::vector<unsigned long>>::value)
378 return DT::VEC_ULONG;
380 else if (
decay_equiv<
T, std::vector<unsigned long long>>::value)
382 return DT::VEC_ULONGLONG;
386 return DT::VEC_FLOAT;
390 return DT::VEC_DOUBLE;
392 else if (
decay_equiv<
T, std::vector<long double>>::value)
394 return DT::VEC_LONG_DOUBLE;
396 else if (
decay_equiv<
T, std::vector<std::complex<float>>>::value)
398 return DT::VEC_CFLOAT;
400 else if (
decay_equiv<
T, std::vector<std::complex<double>>>::value)
402 return DT::VEC_CDOUBLE;
404 else if (
decay_equiv<
T, std::vector<std::complex<long double>>>::value)
406 return DT::VEC_CLONG_DOUBLE;
408 else if (
decay_equiv<
T, std::vector<std::string>>::value)
410 return DT::VEC_STRING;
414 return DT::ARR_DBL_7;
421 return DT::UNDEFINED;
441 return sizeof(
unsigned char);
447 return sizeof(short);
455 case DT::VEC_LONGLONG:
456 return sizeof(
long long);
459 return sizeof(
unsigned short);
462 return sizeof(
unsigned int);
465 return sizeof(
unsigned long);
467 case DT::VEC_ULONGLONG:
468 return sizeof(
unsigned long long);
471 return sizeof(float);
475 return sizeof(double);
476 case DT::LONG_DOUBLE:
477 case DT::VEC_LONG_DOUBLE:
478 return sizeof(
long double);
481 return sizeof(float) * 2;
483 case DT::VEC_CDOUBLE:
484 return sizeof(double) * 2;
485 case DT::CLONG_DOUBLE:
486 case DT::VEC_CLONG_DOUBLE:
487 return sizeof(
long double) * 2;
493 throw std::runtime_error(
"toBytes: Invalid datatype!");
522 case DT::VEC_LONGLONG:
527 case DT::VEC_ULONGLONG:
530 case DT::VEC_LONG_DOUBLE:
532 case DT::VEC_CDOUBLE:
533 case DT::VEC_CLONG_DOUBLE:
558 case DT::LONG_DOUBLE:
559 case DT::VEC_LONG_DOUBLE:
583 case DT::VEC_CDOUBLE:
584 case DT::CLONG_DOUBLE:
585 case DT::VEC_CLONG_DOUBLE:
599 template <
typename T>
602 Datatype dtype = determineDatatype<T>();
614 template <
typename T>
617 Datatype dtype = determineDatatype<T>();
643 case DT::VEC_LONGLONG:
644 return std::make_tuple(
true,
true);
652 case DT::VEC_ULONGLONG:
653 return std::make_tuple(
true,
false);
655 return std::make_tuple(
false,
false);
667 template <
typename T>
670 Datatype dtype = determineDatatype<T>();
681 template <
typename T_FP>
685 bool tt_is_fp = isFloatingPoint<T_FP>();
690 if (tt_is_fp && dt_is_fp &&
toBits(d) ==
toBits(determineDatatype<T_FP>()))
703 template <
typename T_CFP>
707 bool tt_is_cfp = isComplexFloatingPoint<T_CFP>();
712 if (tt_is_cfp && dt_is_cfp &&
726 template <
typename T_Int>
730 bool tt_is_int, tt_is_sig;
731 std::tie(tt_is_int, tt_is_sig) = isInteger<T_Int>();
734 bool dt_is_int, dt_is_sig;
735 std::tie(dt_is_int, dt_is_sig) =
isInteger(d);
737 if (tt_is_int && dt_is_int && tt_is_sig == dt_is_sig &&
753 if (static_cast<int>(d) == static_cast<int>(e))
760 bool d_is_int, d_is_sig;
761 std::tie(d_is_int, d_is_sig) =
isInteger(d);
762 bool e_is_int, e_is_sig;
763 std::tie(e_is_int, e_is_sig) =
isInteger(e);
764 if (d_is_int && e_is_int && d_is_vec == e_is_vec && d_is_sig == e_is_sig &&
772 if (d_is_fp && e_is_fp && d_is_vec == e_is_vec &&
toBits(d) ==
toBits(e))
779 if (d_is_cfp && e_is_cfp && d_is_vec == e_is_vec &&
toBits(d) ==
toBits(e))
787 template <
typename T>
790 Datatype m_dt = determineDatatype<T>();
793 template <
typename T>
799 template <
typename T, std::
size_t n>
807 template <
typename T>
825 std::string datatypeToString(
Datatype dt);
827 Datatype stringToDatatype(std::string s);
829 void warnWrongDtype(std::string
const &key,
Datatype store,
Datatype request);
835 #if !defined(_MSC_VER) bool isVector(Datatype d)
Compare if a Datatype is a vector type.
Definition: Datatype.hpp:512
std::vector< Datatype > openPMD_Datatypes
All openPMD datatypes defined in Datatype, listed in order in a vector.
Definition: Datatype.cpp:222
bool isSameFloatingPoint(Datatype d)
Compare if a Datatype is equivalent to a floating point type.
Definition: Datatype.hpp:682
bool isSameComplexFloatingPoint(Datatype d)
Compare if a Datatype is equivalent to a complex floating point type.
Definition: Datatype.hpp:704
bool isSameInteger(Datatype d)
Compare if a Datatype is equivalent to an integer type.
Definition: Datatype.hpp:727
Fundamental equivalence check for two given types T and U.
Definition: Datatype.hpp:107
bool isComplexFloatingPoint(Datatype d)
Compare if a Datatype is a complex floating point type.
Definition: Datatype.hpp:574
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Definition: Container.cpp:50
size_t toBits(Datatype d)
Return number of bits representing a Datatype.
Definition: Datatype.hpp:502
Definition: Datatype.hpp:788
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:237
size_t toBytes(Datatype d)
Return number of bytes representing a Datatype.
Definition: Datatype.hpp:429
Definition: Datatype.hpp:805
bool isFloatingPoint(Datatype d)
Compare if a Datatype is a floating point type.
Definition: Datatype.hpp:548
std::tuple< bool, bool > isInteger(Datatype d)
Compare if a Datatype is an integer type.
Definition: Datatype.hpp:630
bool isSame(openPMD::Datatype const d, openPMD::Datatype const e)
Comparison for two Datatypes.
Definition: Datatype.hpp:750