Go to the documentation of this file.
9 #ifndef EAGINE_BYTESET_HPP
10 #define EAGINE_BYTESET_HPP
15 #include <type_traits>
24 template <std::
size_t N>
27 static_assert(N > 0,
"byteset size must be greater than zero");
54 constexpr
byteset() noexcept = default;
59 typename = std::enable_if_t<
60 (sizeof...(B) == N) && (sizeof...(B) != 0) &&
61 std::conjunction_v<std::true_type, std::is_convertible<B,
value_type>...>>>
62 explicit constexpr
byteset(B... b) noexcept
69 std::enable_if_t<(
sizeof(UInt) >= N) && std::is_integral_v<UInt>>>
70 constexpr
byteset(std::index_sequence<I...>, UInt init) noexcept
71 : _bytes{
value_type((init >> (8 * (N - I - 1))) & 0xFFU)...} {}
76 typename = std::enable_if_t<
77 (
sizeof(UInt) >= N) && std::is_integral_v<UInt> &&
78 std::is_unsigned_v<UInt>>>
79 explicit constexpr
byteset(UInt init) noexcept
80 :
byteset(std::make_index_sequence<N>(), init) {}
129 return _bytes[N - 1];
135 return _bytes[N - 1];
158 friend constexpr
auto compare(
const byteset& a,
const byteset& b) noexcept {
159 return _do_cmp(a, b, std::make_index_sequence<N>{});
163 friend constexpr
auto
165 return compare(a, b) == 0;
169 friend constexpr
auto
171 return compare(a, b) != 0;
175 friend constexpr
auto
177 return compare(a, b) < 0;
181 friend constexpr
auto
183 return compare(a, b) <= 0;
187 friend constexpr
auto
189 return compare(a, b) > 0;
193 friend constexpr
auto
195 return compare(a, b) >= 0;
201 typename = std::enable_if_t<
202 (
sizeof(UInt) >= N) && (
203 #if __SIZEOF_INT128__
204 std::is_same_v<UInt, __uint128_t> ||
205 std::is_same_v<UInt, __int128_t> ||
207 std::is_integral_v<UInt>)>>
208 constexpr
auto as(UInt i = 0)
const noexcept {
209 return _push_back_to(i, 0);
215 template <
typename UInt>
216 constexpr
auto _push_back_to(UInt state, std::size_t i)
const noexcept
219 return (i < N) ? _push_back_to((state << CHAR_BIT) | _bytes[i], i + 1)
225 return (a == b) ? 0 : (a < b) ? -1 : 1;
228 static constexpr
auto
229 _do_cmp(
const byteset&,
const byteset&, std::index_sequence<>) noexcept
234 template <std::size_t I, std::size_t... In>
235 static constexpr
auto _do_cmp(
238 std::index_sequence<I, In...>) noexcept ->
int {
239 return (a._bytes[I] == b._bytes[I])
240 ? _do_cmp(a, b, std::index_sequence<In...>{})
241 : _cmp_byte(a._bytes[I], b._bytes[I]);
247 #endif // EAGINE_BYTESET_HPP
value_type & reference
Alias for element reference type.
Definition: byteset.hpp:36
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21
constexpr auto end() const noexcept -> const_iterator
Returns a const iterator past the end of the byte sequence.
Definition: byteset.hpp:154
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
constexpr friend auto operator>=(const byteset &a, const byteset &b) noexcept
Greater-equal comparison.
Definition: byteset.hpp:194
auto end() noexcept -> iterator
Returns an iterator past the end of the byte sequence.
Definition: byteset.hpp:144
constexpr friend auto operator==(const byteset &a, const byteset &b) noexcept
Equality comparison.
Definition: byteset.hpp:164
const value_type * const_iterator
Alias for const iterator type.
Definition: byteset.hpp:51
constexpr byteset() noexcept=default
Default constructor.
constexpr auto data() const noexcept -> const_pointer
Returns a const pointer to the byte sequence start.
Definition: byteset.hpp:90
value_type * pointer
Alias for pointer to element type.
Definition: byteset.hpp:42
unsigned char byte
Byte type alias.
Definition: types.hpp:24
auto data() noexcept -> pointer
Returns a pointer to the byte sequence start.
Definition: byteset.hpp:84
constexpr friend auto operator<(const byteset &a, const byteset &b) noexcept
Less-than comparison.
Definition: byteset.hpp:176
span_size_t size_type
Alias for size type.
Definition: byteset.hpp:30
constexpr auto size() const noexcept -> size_type
Returns the count of bytes in the stored sequence.
Definition: byteset.hpp:95
constexpr friend auto operator>(const byteset &a, const byteset &b) noexcept
Greater-than comparison.
Definition: byteset.hpp:188
constexpr friend auto operator<=(const byteset &a, const byteset &b) noexcept
Less-equal comparison.
Definition: byteset.hpp:182
const value_type * const_pointer
Alias for pointer to const element type.
Definition: byteset.hpp:45
Class storing a sequence of bytes converting them to and from unsigned integer.
Definition: byteset.hpp:25
constexpr auto begin() const noexcept -> const_iterator
Returns a const iterator to the start of the byte sequence.
Definition: byteset.hpp:149
constexpr auto operator[](size_type i) const noexcept -> const_reference
Subscript operator.
Definition: byteset.hpp:110
constexpr auto back() noexcept -> reference
Returns the last byte in the sequence.
Definition: byteset.hpp:128
constexpr auto as(UInt i=0) const noexcept
Converts the byte sequence into an unsigned integer value.
Definition: byteset.hpp:208
constexpr auto block() const noexcept -> memory::const_block
Creates a const view over the stored sequence of bytes.
Definition: byteset.hpp:100
constexpr auto front() noexcept -> reference
Returns the first byte in the sequence.
Definition: byteset.hpp:116
byte value_type
Alias for element value type.
Definition: byteset.hpp:33
constexpr auto operator[](size_type i) noexcept -> reference
Subscript operator.
Definition: byteset.hpp:105
const value_type & const_reference
Alias for const reference type.
Definition: byteset.hpp:39
constexpr byteset(UInt init) noexcept
Construiction from unsigned integer that is then split into bytes.
Definition: byteset.hpp:79
constexpr auto back() const noexcept -> const_reference
Returns the last byte in the sequence.
Definition: byteset.hpp:134
constexpr friend auto operator!=(const byteset &a, const byteset &b) noexcept
Non-equality comparison.
Definition: byteset.hpp:170
constexpr auto front() const noexcept -> const_reference
Returns the first byte in the sequence.
Definition: byteset.hpp:122
value_type * iterator
Alias for iterator type.
Definition: byteset.hpp:48
auto begin() noexcept -> iterator
Returns an iterator to the start of the byte sequence.
Definition: byteset.hpp:139