Skip to content

Commit

Permalink
Add determineDatatypeContiguous, rename determineDatatypeRaw
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jun 17, 2022
1 parent 2e866a2 commit 4b852e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 155 deletions.
2 changes: 1 addition & 1 deletion examples/3_write_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char *argv[])
cout << "Created a scalar mesh Record with all required openPMD "
"attributes\n";

Datatype datatype = determineDatatype(global_data.data());
Datatype datatype = determineDatatypeContiguous(global_data);
Extent extent = {size, size};
Dataset dataset = Dataset(datatype, extent);
cout << "Created a Dataset of size " << dataset.extent[0] << 'x'
Expand Down
2 changes: 1 addition & 1 deletion examples/3b_write_resizable_particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main()
std::vector<double> y{-2., -3., -4., -5., -6.};

// both x and y the same type, otherwise we use two distinct datasets
Datatype dtype = determineDatatype(x.data());
Datatype dtype = determineDatatypeContiguous(x);
Extent size = {x.size()};
auto dataset = Dataset(dtype, size, "{ \"resizable\": true }");

Expand Down
171 changes: 18 additions & 153 deletions include/openPMD/Datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
#pragma once

#include "openPMD/auxiliary/TypeTraits.hpp"

#include <array>
#include <climits>
#include <complex>
Expand Down Expand Up @@ -275,169 +277,32 @@ inline constexpr Datatype determineDatatype()
}

template <typename T>
inline constexpr Datatype determineDatatype(T const *)
inline constexpr Datatype determineDatatype(std::shared_ptr<T>)
{
return determineDatatype<T>();
}

template <typename T>
inline constexpr Datatype determineDatatype(std::shared_ptr<T>)
inline constexpr Datatype determineDatatypeRaw(T const *)
{
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, signed char>::value)
{
return DT::SCHAR;
}
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::complex<float>>::value)
{
return DT::CFLOAT;
}
else if (decay_equiv<T, std::complex<double>>::value)
{
return DT::CDOUBLE;
}
else if (decay_equiv<T, std::complex<long double>>::value)
{
return DT::CLONG_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<signed char>>::value)
{
return DT::VEC_SCHAR;
}
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::complex<float>>>::value)
{
return DT::VEC_CFLOAT;
}
else if (decay_equiv<T, std::vector<std::complex<double>>>::value)
{
return DT::VEC_CDOUBLE;
}
else if (decay_equiv<T, std::vector<std::complex<long double>>>::value)
{
return DT::VEC_CLONG_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 determineDatatype<T>();
}

template <typename T_ContiguousContainer>
inline constexpr Datatype determineDatatypeContiguous(T_ContiguousContainer &&)
{
using T_ContiguousContainer_stripped =
std::remove_reference_t<T_ContiguousContainer>;
if constexpr (auxiliary::IsContiguousContainer_v<
T_ContiguousContainer_stripped>)
{
return DT::ARR_DBL_7;
return determineDatatype<
typename T_ContiguousContainer_stripped::value_type>();
}
else if (decay_equiv<T, bool>::value)
else
{
return DT::BOOL;
return Datatype::UNDEFINED;
}
else
return DT::UNDEFINED;
}

/** Return number of bytes representing a Datatype
Expand Down

0 comments on commit 4b852e2

Please sign in to comment.