From aaeb3df4b7d966b8f26a6e71abbc9fad340e8833 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Sun, 26 Jan 2020 22:03:49 +0100 Subject: [PATCH] Fix type label deduction in VTKWriter fix #15 --- src/output/VTKWriter.hpp | 73 +++++++--------------------------------- 1 file changed, 13 insertions(+), 60 deletions(-) diff --git a/src/output/VTKWriter.hpp b/src/output/VTKWriter.hpp index 4656a1839..acd10acd5 100644 --- a/src/output/VTKWriter.hpp +++ b/src/output/VTKWriter.hpp @@ -85,6 +85,19 @@ class VTKWriter template <typename DataType> struct VTKType { + inline const static std::string name = [] { + static_assert(std::is_arithmetic_v<DataType>, "invalid data type"); + + if constexpr (std::is_integral_v<DataType>) { + if constexpr (std::is_unsigned_v<DataType>) { + return "UInt" + std::to_string(sizeof(DataType) * 8); + } else { + return "UInt" + std::to_string(sizeof(DataType) * 8); + } + } else if constexpr (std::is_floating_point_v<DataType>) { + return "Float" + std::to_string(sizeof(DataType) * 8); + } + }(); }; template <typename DataType> @@ -360,64 +373,4 @@ class VTKWriter ~VTKWriter() = default; }; -template <> -struct VTKWriter::VTKType<int8_t> -{ - inline const static std::string name{"Int8"}; -}; - -template <> -struct VTKWriter::VTKType<uint8_t> -{ - inline const static std::string name{"UInt8"}; -}; - -template <> -struct VTKWriter::VTKType<int16_t> -{ - inline const static std::string name{"Int16"}; -}; - -template <> -struct VTKWriter::VTKType<uint16_t> -{ - inline const static std::string name{"UInt16"}; -}; - -template <> -struct VTKWriter::VTKType<int32_t> -{ - inline const static std::string name{"Int32"}; -}; - -template <> -struct VTKWriter::VTKType<uint32_t> -{ - inline const static std::string name{"UInt32"}; -}; - -template <> -struct VTKWriter::VTKType<int64_t> -{ - inline const static std::string name{"Int64"}; -}; - -template <> -struct VTKWriter::VTKType<uint64_t> -{ - inline const static std::string name{"UInt64"}; -}; - -template <> -struct VTKWriter::VTKType<float> -{ - inline const static std::string name{"Float32"}; -}; - -template <> -struct VTKWriter::VTKType<double> -{ - inline const static std::string name{"Float64"}; -}; - #endif // VTK_WRITER_HPP -- GitLab