Tatooine
data_type.h
Go to the documentation of this file.
1#ifndef TATOOINE_GEOMETRY_VTK_XML_DATA_TYPE_H
2#define TATOOINE_GEOMETRY_VTK_XML_DATA_TYPE_H
3//==============================================================================
4#include <tatooine/concepts.h>
5
6#include <cstring>
7#include <ostream>
8//==============================================================================
9namespace tatooine::vtk::xml {
10//==============================================================================
11enum class data_type {
12 int8,
13 uint8,
14 int16,
15 uint16,
16 int32,
17 uint32,
18 int64,
19 uint64,
20 float32,
21 float64,
23};
24//------------------------------------------------------------------------------
25auto visit(data_type dt, auto&& f) {
26 switch (dt) {
27 case data_type::int8:
28 if constexpr (std::invocable<decltype(f), std::int8_t>) {
29 f(std::int8_t{});
30 }
31 break;
33 if constexpr (std::invocable<decltype(f), std::uint8_t>) {
34 f(std::uint8_t{});
35 }
36 break;
38 if constexpr (std::invocable<decltype(f), std::int16_t>) {
39 f(std::int16_t{});
40 }
41 break;
43 if constexpr (std::invocable<decltype(f), std::uint16_t>) {
44 f(std::uint16_t{});
45 }
46 break;
48 if constexpr (std::invocable<decltype(f), std::int32_t>) {
49 f(std::int32_t{});
50 }
51 break;
53 if constexpr (std::invocable<decltype(f), std::uint32_t>) {
54 f(std::uint32_t{});
55 }
56 break;
58 if constexpr (std::invocable<decltype(f), std::int64_t>) {
59 f(std::int64_t{});
60 }
61 break;
63 if constexpr (std::invocable<decltype(f), std::uint64_t>) {
64 f(std::uint64_t{});
65 }
66 break;
68 if constexpr (std::invocable<decltype(f), float>) {
69 f(float{});
70 }
71 break;
73 if constexpr (std::invocable<decltype(f), double>) {
74 f(double{});
75 }
76 break;
78 default:
79 break;
80 }
81}
82auto parse_data_type(char const* str) -> data_type;
83auto to_string(data_type const t) -> std::string_view;
84auto size(data_type const dt) -> std::size_t;
85auto operator<<(std::ostream&, data_type const) -> std::ostream&;
86//------------------------------------------------------------------------------
87template <typename T>
88static auto constexpr to_data_type() {
89 if constexpr (is_same<std::int8_t, T>) {
90 return data_type::int8;
91 } else if constexpr (is_same<T, std::uint8_t>) {
92 return data_type::uint8;
93 } else if constexpr (is_same<T, std::int16_t>) {
94 return data_type::int16;
95 } else if constexpr (is_same<T, std::uint16_t>) {
96 return data_type::uint16;
97 } else if constexpr (is_same<T, std::int32_t>) {
98 return data_type::int32;
99 } else if constexpr (is_same<T, std::uint32_t>) {
100 return data_type::uint32;
101 } else if constexpr (is_same<T, std::int64_t>) {
102 return data_type::int64;
103 } else if constexpr (is_same<T, std::uint64_t>) {
104 return data_type::uint64;
105 } else if constexpr (is_same<T, float>) {
106 return data_type::float32;
107 } else if constexpr (is_same<T, double>) {
108 return data_type::float64;
109 } else {
110 return data_type::unknown;
111 }
112}
113//==============================================================================
114} // namespace tatooine::vtk::xml
115//==============================================================================
116#endif
Definition: byte_order.h:6
auto to_string(data_type const t) -> std::string_view
static auto constexpr to_data_type()
Definition: data_type.h:88
auto size(data_type const dt) -> std::size_t
auto operator<<(std::ostream &, data_type const) -> std::ostream &
data_type
Definition: data_type.h:11
auto parse_data_type(char const *str) -> data_type
constexpr auto visit(Visitor &&visitor, Variant0 &&variant0, Variant1 &&variant1, Variants &&... variants) -> void
Definition: visit.h:14