diff options
Diffstat (limited to 'serialize/packbits-read.hpp')
| -rw-r--r-- | serialize/packbits-read.hpp | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/serialize/packbits-read.hpp b/serialize/packbits-read.hpp index 362ec604..67b2efcb 100644 --- a/serialize/packbits-read.hpp +++ b/serialize/packbits-read.hpp @@ -1,11 +1,37 @@ #pragma once -#include "packbits.hpp" #include <type_traits> #include <concepts> #include <tuple> +#include <utility> #include "compat/assert.hpp" -namespace floormat::detail_Pack { +namespace floormat::detail_Pack_input { + +template<std::unsigned_integral T, size_t N> +struct input_bits final +{ + static_assert(std::is_fundamental_v<T>); + static_assert(N > 0); + static_assert(N < sizeof(T)*8); + + using type = T; +}; + +template<std::unsigned_integral T, size_t N> +struct make_tuple_type_ +{ + template<size_t> using index_to_type = T; + template<typename> struct aux; + template<size_t... Is> struct aux<std::index_sequence<Is...>> + { + static_assert(sizeof...(Is) > 0); + using type = std::tuple<index_to_type<Is>...>; + }; + using Seq = typename aux<std::make_index_sequence<N>>::type; +}; +template<std::unsigned_integral T, size_t N> using make_tuple_type = typename make_tuple_type_<T, N>::Seq; + +template<typename... Ts> struct empty_pack_tuple {}; template<std::unsigned_integral T, size_t CAPACITY> struct input @@ -57,16 +83,16 @@ struct input<T, 0> template<size_t N> struct next { - static_assert(N == 0, "reading past the end"); - static_assert(N != 0, "reading past the end"); + static_assert(N == (size_t)-1, "reading past the end"); + static_assert(N != (size_t)-1); }; }; template<std::unsigned_integral T, typename Place, size_t Left, size_t I, size_t... Is, size_t Size, typename... Sizes> -constexpr void read(Place& p, input<T, Left> st, std::index_sequence<I, Is...>, empty_pack_tuple<bits<T, Size>, Sizes...>) +constexpr void read(Place& p, input<T, Left> st, std::index_sequence<I, Is...>, empty_pack_tuple<input_bits<T, Size>, Sizes...>) { static_assert(sizeof...(Is) == sizeof...(Sizes)); - static_assert(Size <= Left, "too many bits requested"); + static_assert(Size <= Left, "data type too small"); static_assert(I < std::tuple_size_v<Place>, "too few tuple members"); using S = input<T, Left>; using next_type = typename S::template next<Size>; @@ -85,9 +111,9 @@ template<std::unsigned_integral T, typename Place, size_t Left, size_t... Is, ty requires(sizeof...(Is) != sizeof...(Sizes)) constexpr void read(Place&, input<T, Left>, std::index_sequence<Is...>, empty_pack_tuple<Sizes...>) = delete; -template<std::unsigned_integral T, size_t... Ns> using make_pack = empty_pack_tuple<bits<T, Ns>...>; +template<std::unsigned_integral T, size_t... Ns> using make_pack = empty_pack_tuple<input_bits<T, Ns>...>; -} // namespace floormat::detail_Pack +} // namespace floormat::detail_Pack_input namespace floormat::pack { |
