UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
scalar_type.hpp
1
41#ifndef UFO_UTILITY_SCALAR_TYPE_HPP
42#define UFO_UTILITY_SCALAR_TYPE_HPP
43
44// STL
45#include <concepts>
46#include <cstdint>
47#include <format>
48#include <ostream>
49#include <string_view>
50#include <utility>
51
52namespace ufo
53{
61enum class ScalarType : std::uint8_t {
62 INT8 = 0,
63 UINT8 = 1,
64 INT16 = 2,
65 UINT16 = 3,
66 INT32 = 4,
67 UINT32 = 5,
68 INT64 = 6,
69 UINT64 = 7,
70 FLOAT32 = 8,
71 FLOAT64 = 9,
72 UNKNOWN = 10
73};
74
81[[nodiscard]] constexpr std::string_view toString(ScalarType type) noexcept
82{
83 using enum ScalarType;
84 switch (type) {
85 case INT8: return "INT8";
86 case UINT8: return "UINT8";
87 case INT16: return "INT16";
88 case UINT16: return "UINT16";
89 case INT32: return "INT32";
90 case UINT32: return "UINT32";
91 case INT64: return "INT64";
92 case UINT64: return "UINT64";
93 case FLOAT32: return "FLOAT32";
94 case FLOAT64: return "FLOAT64";
95 case UNKNOWN: return "UNKNOWN";
96 }
97 std::unreachable();
98}
99
103inline std::ostream& operator<<(std::ostream& os, ScalarType type)
104{
105 return os << toString(type);
106}
107
108namespace detail
109{
116template <class T>
117consteval ScalarType scalarTypeOf() noexcept
118{
119 using enum ScalarType;
120 if constexpr (std::same_as<T, std::int8_t>) {
121 return INT8;
122 } else if constexpr (std::same_as<T, std::uint8_t>) {
123 return UINT8;
124 } else if constexpr (std::same_as<T, std::int16_t>) {
125 return INT16;
126 } else if constexpr (std::same_as<T, std::uint16_t>) {
127 return UINT16;
128 } else if constexpr (std::same_as<T, std::int32_t>) {
129 return INT32;
130 } else if constexpr (std::same_as<T, std::uint32_t>) {
131 return UINT32;
132 } else if constexpr (std::same_as<T, std::int64_t>) {
133 return INT64;
134 } else if constexpr (std::same_as<T, std::uint64_t>) {
135 return UINT64;
136 } else if constexpr (std::same_as<T, float>) {
137 return FLOAT32;
138 } else if constexpr (std::same_as<T, double>) {
139 return FLOAT64;
140 } else {
141 return UNKNOWN;
142 }
143}
144} // namespace detail
145
150template <class T>
151constexpr inline ScalarType scalar_type_v = detail::scalarTypeOf<T>();
152
153} // namespace ufo
154
155template <>
156struct std::formatter<ufo::ScalarType> : std::formatter<std::string_view> {
157 auto format(ufo::ScalarType type, std::format_context& ctx) const
158 {
159 return std::formatter<std::string_view>::format(ufo::toString(type), ctx);
160 }
161};
162
163#endif // UFO_UTILITY_SCALAR_TYPE_HPP
All vision-related classes and functions.
Definition cloud.hpp:49
constexpr std::string_view toString(ScalarType type) noexcept
Returns a human-readable string for a ScalarType value.
ScalarType
Tag identifying the primitive scalar type of a data channel.
@ FLOAT64
64-bit IEEE 754 floating-point (double).
@ UINT32
Unsigned 32-bit integer (std::uint32_t).
@ UINT16
Unsigned 16-bit integer (std::uint16_t).
@ INT64
Signed 64-bit integer (std::int64_t).
@ INT16
Signed 16-bit integer (std::int16_t).
@ INT32
Signed 32-bit integer (std::int32_t).
@ UINT64
Unsigned 64-bit integer (std::uint64_t).
@ FLOAT32
32-bit IEEE 754 floating-point (float).
@ UINT8
Unsigned 8-bit integer (std::uint8_t).
@ INT8
Signed 8-bit integer (std::int8_t).
@ UNKNOWN
Unrecognised or missing file extension.
constexpr ScalarType scalar_type_v
The ScalarType enumerator for T, or ScalarType::UNKNOWN if T is not a recognised scalar type.