summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-01-18 17:59:14 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-01-18 17:59:14 +0100
commit5b753ed3b632072697bdbf6912ccefcc6a22f4d0 (patch)
treed0174a6a21ff5c4e2374dce23cb1dbc07262c61f
parent68351c6de75ee4ca835c57b223335c6df4f6a9d0 (diff)
a
-rw-r--r--serialize/packbits-read.cpp11
-rw-r--r--serialize/packbits-read.hpp16
-rw-r--r--serialize/packbits-write.hpp2
3 files changed, 21 insertions, 8 deletions
diff --git a/serialize/packbits-read.cpp b/serialize/packbits-read.cpp
index d71d06ac..aa5cccfe 100644
--- a/serialize/packbits-read.cpp
+++ b/serialize/packbits-read.cpp
@@ -84,10 +84,8 @@ constexpr bool test4()
{
static_assert(lowbits<uint32_t, 17> == 0x1ffffU);
- f32<17> a;
- f32<14> b;
- f32< 1> c;
//auto tuple = std::tuple<f32<17>&, f32<14>&, f32<1>&>{a, b, c};
+ f32<17> a; f32<14> b; f32< 1> c;
auto tuple = std::tie(a, b, c);
read_(tuple, input<uint32_t, 32>{(uint32_t)-1}, std::make_index_sequence<3>{});
fm_assert(a == lowbits<uint32_t, 17>);
@@ -112,6 +110,13 @@ constexpr bool test4()
//read_(std::tie(a), input<uint8_t, 8>{3}, std::index_sequence<0>{}); fm_assert(a == 3);
//f8<1> d; read_(std::tie(d), input<uint8_t, 8>{1}, std::index_sequence<>{});
}
+ {
+ f8<1> a; f8<3> b; f8<2> c;
+ pack_read(std::tie(a, b, c), uint8_t{0b101011});
+ fm_assert(a == 0b1);
+ fm_assert(b == 0b101);
+ fm_assert(c == 0b10);
+ }
return true;
}
diff --git a/serialize/packbits-read.hpp b/serialize/packbits-read.hpp
index 9e5f0cc8..1d7056c3 100644
--- a/serialize/packbits-read.hpp
+++ b/serialize/packbits-read.hpp
@@ -38,7 +38,7 @@ struct input
template<size_t N> using next = typename next_<N>::type;
template<size_t N>
- constexpr T get() const
+ constexpr CORRADE_ALWAYS_INLINE T get() const
{
static_assert(N > 0);
static_assert(N <= sizeof(T)*8);
@@ -81,7 +81,7 @@ template<typename T> struct is_input_field : std::bool_constant<false> {};
template<std::unsigned_integral T, size_t N> struct is_input_field<input_field<T, N>> : std::bool_constant<true> { static_assert(N > 0); };
template<std::unsigned_integral T, typename Tuple, size_t Left, size_t I, size_t... Is>
-constexpr void read_(Tuple&& tuple, input<T, Left> st, std::index_sequence<I, Is...>)
+constexpr CORRADE_ALWAYS_INLINE void read_(Tuple&& tuple, input<T, Left> st, std::index_sequence<I, Is...>)
{
using U = std::decay_t<Tuple>;
static_assert(Left <= sizeof(T)*8);
@@ -99,7 +99,7 @@ constexpr void read_(Tuple&& tuple, input<T, Left> st, std::index_sequence<I, Is
}
template<std::unsigned_integral T, typename Tuple, size_t Left>
-constexpr void read_(Tuple&&, input<T, Left> st, std::index_sequence<>)
+constexpr CORRADE_ALWAYS_INLINE void read_(Tuple&&, input<T, Left> st, std::index_sequence<>)
{
if (!st.check_zero()) [[unlikely]]
throw_on_read_nonzero();
@@ -109,6 +109,14 @@ constexpr void read_(Tuple&&, input<T, Left> st, std::index_sequence<>)
namespace floormat {
-
+template<std::unsigned_integral T, typename Tuple>
+constexpr void pack_read(Tuple&& tuple, T value)
+{
+ constexpr size_t nbits = sizeof(T)*8,
+ tuple_size = std::tuple_size_v<std::decay_t<Tuple>>;
+ Pack_impl::read_(std::forward<Tuple>(tuple),
+ Pack_impl::input<T, nbits>{value},
+ std::make_index_sequence<tuple_size>{});
+}
} // namespace floormat
diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp
index 234b1632..12e202ac 100644
--- a/serialize/packbits-write.hpp
+++ b/serialize/packbits-write.hpp
@@ -62,7 +62,7 @@ constexpr CORRADE_ALWAYS_INLINE T write_(const Tuple&, output<T, Capacity, Left>
namespace floormat {
template<std::unsigned_integral T, size_t... Sizes>
-constexpr T pack_write(const std::tuple<Pack_impl::output_field<T, Sizes>...>& tuple)
+[[nodiscard]] constexpr T pack_write(const std::tuple<Pack_impl::output_field<T, Sizes>...>& tuple)
{
constexpr size_t nbits = sizeof(T)*8;
return Pack_impl::write_(tuple, Pack_impl::output<T, nbits, nbits>{T{0}}, make_reverse_index_sequence<sizeof...(Sizes)>{});