8#include "reflection.hpp"
9#include "../macros.hpp"
20#if HI_COMPILER == HI_CC_MSVC
27hi_export_module(hikogui.utility.endian);
33hi_warning_ignore_msvc(26472);
35hi_export
namespace hi {
inline namespace v1 {
39template<std::
integral T>
42 if constexpr (std::endian::native == std::endian::little) {
45 return std::byteswap(x);
51template<std::
integral T>
54 if constexpr (std::endian::native == std::endian::big) {
57 return std::byteswap(x);
63template<std::
integral T>
66 if constexpr (std::endian::native == std::endian::little) {
69 return std::byteswap(x);
75template<std::
integral T>
78 if constexpr (std::endian::native == std::endian::big) {
81 return std::byteswap(x);
92template<std::
integral Out, std::endian Endian = std::endian::native,
typename In>
95 if constexpr (
Endian != std::endian::native) {
109template<std::
integral T, std::endian Endian = std::endian::native>
113 if constexpr (
Endian != std::endian::native) {
114 value = std::byteswap(value);
125template<std::
integral T>
137template<std::
integral T,
byte_like B>
149template<std::
integral T>
161template<std::
integral T>
173template<std::
integral T,
byte_like B>
185template<std::
integral T>
206template<
unsigned int NumBits,
byte_like B>
211 constexpr auto num_bits =
NumBits;
217 std::conditional_t<num_bytes <
sizeof(
unsigned short),
unsigned short,
218 std::conditional_t<num_bytes <
sizeof(
unsigned int),
unsigned int,
219 std::conditional_t<num_bytes <
sizeof(
unsigned long),
unsigned long,
unsigned long long>>>;
228 if constexpr (num_bits ==
CHAR_BIT) {
241 if constexpr (num_bytes ==
sizeof(value_type)) {
258template<std::endian Endian = std::endian::native, std::
integral T,
byte_like B>
259constexpr void store(T value, B
const *
dst)
noexcept
261 if constexpr (
Endian != std::endian::native) {
262 value = std::byteswap(value);
267template<std::endian Endian = std::endian::native, std::
integral T>
268constexpr void store(T value,
void const *
dst)
noexcept
270 if constexpr (
Endian != std::endian::native) {
271 value = std::byteswap(value);
276template<std::
integral T,
byte_like B>
277constexpr void store_le(T value, B
const *
dst)
noexcept
282template<std::
integral T>
283inline void store_le(T value,
void const *
dst)
noexcept
288template<std::
integral T,
byte_like B>
289constexpr void store_be(T value, B
const *
dst)
noexcept
294template<std::
integral T>
295inline void store_be(T value,
void const *
dst)
noexcept
300template<
typename T, std::endian E, std::
size_t A = alignof(T)>
302 using value_type = T;
303 constexpr static std::endian endian = E;
306 alignas(A) std::byte _value[
sizeof(T)];
308 [[
nodiscard]]
constexpr value_type operator*()
const noexcept
313 constexpr endian_buf_t& operator=(value_type x)
noexcept
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr T big_to_native(T x)
Convert an integral from big-to-native endian.
Definition endian.hpp:52
constexpr T native_to_little(T x)
Convert an integral from native-to-little endian.
Definition endian.hpp:64
constexpr T load_be(T const *src) noexcept
Load of a numeric value encoded in big-endian format.
Definition endian.hpp:162
constexpr T little_to_native(T x)
Convert an integral from little-to-native endian.
Definition endian.hpp:40
constexpr T load_le(T const *src) noexcept
Load of a numeric value encoded in little-endian format.
Definition endian.hpp:126
constexpr Out load(In const *src) noexcept
Unaligned Load of a numeric value from an array.
Definition endian.hpp:93
constexpr T native_to_big(T x)
Convert an integral from native-to-big endian.
Definition endian.hpp:76
constexpr auto load_bits_be(B const *src, size_t bit_index) noexcept
Unaligned load bits from a big-endian buffer at a bit-offset.
Definition endian.hpp:207
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Horizontal/Vertical alignment combination.
Definition alignment.hpp:242
Definition endian.hpp:301