Commit 6327d214 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

add mapping for Vtk::DataTypes to real types

parent 315e5f7e
......@@ -6,6 +6,7 @@
#include <vector>
#include <dune/common/ftraits.hh>
#include <dune/common/typelist.hh>
#include <dune/geometry/type.hh>
namespace Dune
......@@ -74,25 +75,69 @@ namespace Dune
{
static std::map<std::string, DataTypes> to_datatype; // String -> DataTypes
template <class T> struct Type {};
static constexpr DataTypes typeImpl (Type<std::int8_t>) { return INT8; }
static constexpr DataTypes typeImpl (Type<std::uint8_t>) { return UINT8; }
static constexpr DataTypes typeImpl (Type<std::int16_t>) { return INT16; }
static constexpr DataTypes typeImpl (Type<std::uint16_t>) { return UINT16; }
static constexpr DataTypes typeImpl (Type<std::int32_t>) { return INT32; }
static constexpr DataTypes typeImpl (Type<std::uint32_t>) { return UINT32; }
static constexpr DataTypes typeImpl (Type<std::int64_t>) { return INT64; }
static constexpr DataTypes typeImpl (Type<std::uint64_t>) { return UINT64; }
static constexpr DataTypes typeImpl (Type<float>) { return FLOAT32; }
static constexpr DataTypes typeImpl (Type<double>) { return FLOAT64; }
static constexpr DataTypes typeImpl (Type<long double>) { return FLOAT64; }
static constexpr DataTypes typeImpl (MetaType<std::int8_t>) { return INT8; }
static constexpr DataTypes typeImpl (MetaType<std::uint8_t>) { return UINT8; }
static constexpr DataTypes typeImpl (MetaType<std::int16_t>) { return INT16; }
static constexpr DataTypes typeImpl (MetaType<std::uint16_t>) { return UINT16; }
static constexpr DataTypes typeImpl (MetaType<std::int32_t>) { return INT32; }
static constexpr DataTypes typeImpl (MetaType<std::uint32_t>) { return UINT32; }
static constexpr DataTypes typeImpl (MetaType<std::int64_t>) { return INT64; }
static constexpr DataTypes typeImpl (MetaType<std::uint64_t>) { return UINT64; }
static constexpr DataTypes typeImpl (MetaType<float>) { return FLOAT32; }
static constexpr DataTypes typeImpl (MetaType<double>) { return FLOAT64; }
static constexpr DataTypes typeImpl (MetaType<long double>) { return FLOAT64; }
template <class T>
static constexpr DataTypes type () { return typeImpl(Type<typename FieldTraits<T>::field_type>{}); }
static constexpr DataTypes type () { return typeImpl(MetaType<typename FieldTraits<T>::field_type>{}); }
};
/// Map a given enum DataType to a type passed to Caller as \ref MetaType
template <class Caller>
void mapDataTypes (Vtk::DataTypes t, Caller caller)
{
switch (t) {
case INT8: caller(MetaType<std::int8_t>{}); break;
case UINT8: caller(MetaType<std::uint8_t>{}); break;
case INT16: caller(MetaType<std::int16_t>{}); break;
case UINT16: caller(MetaType<std::uint16_t>{}); break;
case INT32: caller(MetaType<std::int32_t>{}); break;
case UINT32: caller(MetaType<std::uint32_t>{}); break;
case INT64: caller(MetaType<std::int64_t>{}); break;
case UINT64: caller(MetaType<std::uint64_t>{}); break;
case FLOAT32: caller(MetaType<float>{}); break;
case FLOAT64: caller(MetaType<double>{}); break;
default:
VTK_ASSERT_MSG(false, "Unsupported type " << to_string(t));
break;
}
}
/// Map two DataTypes as type parameters to the Caller
template <class Caller>
void mapDataTypes (Vtk::DataTypes t1, Vtk::DataTypes t2, Caller caller)
{
mapDataTypes(t1, [&](auto type1) {
mapDataTypes(t2, [&](auto type2) {
caller(type1, type2);
});
});
}
/// Map three DataTypes as type parameters to the Caller
template <class Caller>
void mapDataTypes (Vtk::DataTypes t1, Vtk::DataTypes t2, Vtk::DataTypes t3, Caller caller)
{
mapDataTypes(t1, [&](auto type1) {
mapDataTypes(t2, [&](auto type2) {
mapDataTypes(t3, [&](auto type3) {
caller(type1, type2, type3);
});
});
});
}
/// Mapping of Dune geometry types to VTK cell types
class CellType
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment