pabigot
0.1.1
C++ support classes
|
Go to the documentation of this file. 9 #ifndef PABIGOT_BYTEORDER_HPP 10 #define PABIGOT_BYTEORDER_HPP 17 #include <type_traits> 74 static constexpr
wchar_t BOM = u
'\uFFFE';
86 class U =
typename std::make_unsigned<T>::type>
90 return external::ccbysa30::bswap<T>(v);
120 && !is_constexpr_swappable_v<T>};
131 && !is_alias_swappable_v<T>};
139 template <
typename T>
140 constexpr
typename std::enable_if<details::is_constexpr_swappable_v<T>, T>::type
148 template <
typename T>
149 typename std::enable_if<details::is_alias_swappable_v<T>, T>::type
154 uint8_t raw[
sizeof(t)];
156 std::reverse(u.raw, u.raw +
sizeof(u.raw));
165 template <
typename T>
166 typename std::enable_if<details::is_other_swappable_v<T>, T>::type
169 static_assert(1 ==
sizeof(*t.begin()),
"cannot byte-swap sequences with non-octet values");
171 std::reverse(value.begin(), value.end());
179 template <
typename T,
181 constexpr
typename std::enable_if<details::is_constexpr_swappable_v<T>
192 template <
typename T,
194 typename std::enable_if<!details::is_constexpr_swappable_v<T>
205 template <
typename T,
207 constexpr
typename std::enable_if<details::is_constexpr_swappable_v<T>
218 template <
typename T,
220 typename std::enable_if<!details::is_constexpr_swappable_v<T>
231 template <
typename T>
232 constexpr
typename std::enable_if<details::is_constexpr_swappable_v<T>, T>::type
235 return hostswap<T, byte_order_enum::little_endian>(v);
239 template <
typename T>
240 typename std::enable_if<!details::is_constexpr_swappable_v<T>, T>::type
243 return hostswap<T, byte_order_enum::little_endian>(v);
250 template <
typename T>
251 constexpr
typename std::enable_if<details::is_constexpr_swappable_v<T>, T>::type
254 return hostswap<T, byte_order_enum::big_endian>(v);
258 template <
typename T>
259 typename std::enable_if<!details::is_constexpr_swappable_v<T>, T>::type
262 return hostswap<T, byte_order_enum::big_endian>(v);
269 template <
typename T>
270 constexpr
typename std::enable_if<details::is_constexpr_swappable_v<T>, T>::type
277 template <
typename T>
278 typename std::enable_if<!details::is_constexpr_swappable_v<T>, T>::type
288 template <
typename T>
289 constexpr
typename std::enable_if<details::is_constexpr_swappable_v<T>, T>::type
296 template <
typename T>
297 typename std::enable_if<!details::is_constexpr_swappable_v<T>, T>::type
346 memset(begin_, 0, end_ - begin_);
374 return bp_ ? begin_ :
nullptr;
382 const void*
end () const noexcept
384 return bp_ ? bp_ :
nullptr;
392 return bp_ ? (bp_ - begin_) : 0U;
400 return bp_ ? (end_ - bp_) : 0U;
406 return end_ - begin_;
439 return bp_ ? (static_cast<size_type>(end_ - bp_) >= s) :
false;
456 memmove(dp, sp, span);
472 template <
typename T>
475 return append(&value,
sizeof(value));
480 template <
typename T>
488 template <
typename T>
495 friend class oob_helper;
498 uint8_t*
const begin_;
505 uint8_t* bp_ =
nullptr;
const void * begin() const noexcept
Get a pointer to the start of buffer.
Definition: byteorder.hpp:372
Representation for PDP byte order.
Infrastructure to fill an octet buffer with data.
Definition: byteorder.hpp:310
bool append(const void *sp, size_type span) noexcept
Append a value to the buffer.
Definition: byteorder.hpp:452
constexpr bool is_constexpr_swappable_v
Category identifying types that can be constexpr swapped.
Definition: byteorder.hpp:103
constexpr std::enable_if< details::is_constexpr_swappable_v< T >, T >::type host_x_be(const T &v)
Convert between host and big-endian byte order.
Definition: byteorder.hpp:252
octets_helper(uint8_t *begin, size_type count)
Reference an octet sequence into which data will be written.
Definition: byteorder.hpp:334
constexpr byte_order_enum host_byte_order()
Return the byte_order_enum value for the host.
Definition: byteorder.hpp:56
constexpr std::enable_if< details::is_constexpr_swappable_v< T >, T >::type byteswap(const T &t)
Byte-swap values at compile-time.
Definition: byteorder.hpp:141
General-use material that applies to all of pabigot.
Material from external sources with CC-BY-SA-3.0 licensing.
const void * end() const noexcept
Get a pointer to the end of the filled part of the buffer.
Definition: byteorder.hpp:382
static constexpr wchar_t BOM
The Unicode byte order marker.
Definition: byteorder.hpp:74
const size_type size() const noexcept
Number of octets stored in the buffer.
Definition: byteorder.hpp:390
Representation for a host using little-endian order.
byte_order_enum
Enumeration of constants representing various known byte orders.
Definition: byteorder.hpp:31
std::enable_if< details::is_other_swappable_v< T >, T >::type byteswap(const T &t)
Byte-swap values by creating a copy and using std::reverse.
Definition: byteorder.hpp:167
void invalidate() noexcept
Explicitly mark the buffer invalid.
Definition: byteorder.hpp:364
const size_type max_size() const noexcept
Maximum number of octets supported by the buffer.
Definition: byteorder.hpp:404
const bool valid() const noexcept
Indicates whether advance() caused an error.
Definition: byteorder.hpp:355
bool append(const T &value) noexcept
Append a value to the buffer.
Definition: byteorder.hpp:473
Representation for a host using big-endian order.
const size_type available() const noexcept
Number of unused octets available in the buffer.
Definition: byteorder.hpp:398
octets_helper(uint8_t *begin, uint8_t *end)
Reference an octet range into which data will be written.
Definition: byteorder.hpp:321
constexpr bool is_other_swappable_v
Category identifying types that can be swapped by using std::reverse on a copy.
Definition: byteorder.hpp:130
std::size_t size_type
Type used for span values.
Definition: byteorder.hpp:314
Representation for network byte order, which is big-endian.
Root for all pabigot namespaces.
Definition: gap.hpp:15
constexpr std::enable_if< details::is_constexpr_swappable_v< T >, T >::type host_x_le(const T &v)
Convert between host and little-endian byte order.
Definition: byteorder.hpp:233
constexpr std::enable_if< details::is_constexpr_swappable_v< T >, T >::type be_x_le(const T &v)
Convert between big-endian and little-endian byte order.
Definition: byteorder.hpp:271
bool append_le(const T &value) noexcept
As with append() but stores the value converted to little-endian byte order.
Definition: byteorder.hpp:489
void * advance(size_type s) noexcept
Allocate a region and return a pointer to it or a nullptr if the advance went too far.
Definition: byteorder.hpp:418
bool append_be(const T &value) noexcept
As with append() but stores the value converted to big-endian byte order.
Definition: byteorder.hpp:481
bool can_advance(size_type s) const noexcept
Indicate whether advance() would succeed for a given span.
Definition: byteorder.hpp:437
constexpr std::enable_if< details::is_constexpr_swappable_v< T > &&(host_byte_order()==endian), T >::type hostswap(const T &t)
constexpr-selected byte swap between host and endian.
Definition: byteorder.hpp:183
void reset() noexcept
Remove all content from the buffer.
Definition: byteorder.hpp:343
constexpr std::enable_if< details::is_constexpr_swappable_v< T >, T >::type host_x_network(const T &v)
Convert between host and network byte order.
Definition: byteorder.hpp:290
constexpr bool is_alias_swappable_v
Category identifying types that can swapped by alias with a byte array.
Definition: byteorder.hpp:119