MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
Endianness

Methods related to endianness of multi-byte data. More...

Namespaces

namespace  mtcore::endian
 

Functions

constexpr u16 mtcore::flip_endian_u16 (const u16 bytes)
 Flips the endianness of a u16.
 
constexpr char16_t mtcore::flip_endian_ch16 (const char16_t ch)
 Flips the endianness of a char16.
 
constexpr u32 mtcore::flip_endian_u32 (const u32 bytes)
 Flips the endianness of a u3.
 
constexpr char32_t mtcore::flip_endian_ch32 (const char32_t ch)
 Flips the endianness of a char32.
 
template<typename T>
constexpr auto mtcore::flip_endian (const T bytes)
 Flips the endian of a u16, char16, u32, or char32.
 

Variables

constexpr auto mtcore::endian::machine = std::endian::native
 endian of machine (alias for std::endian::native)
 
constexpr auto mtcore::endian::opposite = std::endian::native == std::endian::little ? std::endian::big : std::endian::little
 endian that is opposite of machine (opposite of std::endian::native)
 

Detailed Description

Methods related to endianness of multi-byte data.

Function Documentation

◆ flip_endian()

template<typename T>
auto mtcore::flip_endian ( const T bytes)
constexpr

Flips the endian of a u16, char16, u32, or char32.

Definition at line 80 of file byte_order.hpp.

80 {
81 static_assert(std::same_as<u16, T> || std::same_as<char16_t, T> || std::same_as<u32, T> ||
82 std::same_as<char32_t, T>);
83 if constexpr (std::is_same_v<u16, T>) {
84 return flip_endian_u16(bytes);
85 }
86 else if constexpr (std::is_same_v<char16_t, T>) {
87 return flip_endian_ch16(bytes);
88 }
89 else if constexpr (std::is_same_v<u32, T>) {
90 return flip_endian_u32(bytes);
91 }
92 else {
93 return flip_endian_ch32(bytes);
94 }
95 }
constexpr char32_t flip_endian_ch32(const char32_t ch)
Flips the endianness of a char32.
constexpr char16_t flip_endian_ch16(const char16_t ch)
Flips the endianness of a char16.
constexpr u16 flip_endian_u16(const u16 bytes)
Flips the endianness of a u16.
constexpr u32 flip_endian_u32(const u32 bytes)
Flips the endianness of a u3.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flip_endian_ch16()

char16_t mtcore::flip_endian_ch16 ( const char16_t ch)
constexpr

Flips the endianness of a char16.

Definition at line 55 of file byte_order.hpp.

55 {
56 return static_cast<u16>(flip_endian_u16(static_cast<u16>(ch)));
57 }
uint16_t u16
Alias for 16-bit unsigned ints.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flip_endian_ch32()

char32_t mtcore::flip_endian_ch32 ( const char32_t ch)
constexpr

Flips the endianness of a char32.

Definition at line 71 of file byte_order.hpp.

71 {
72 return static_cast<char32_t>(flip_endian_u32(static_cast<u32>(ch)));
73 }
uint32_t u32
Alias for 32-bit unsigned ints.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flip_endian_u16()

u16 mtcore::flip_endian_u16 ( const u16 bytes)
constexpr

Flips the endianness of a u16.

Definition at line 49 of file byte_order.hpp.

49{ return bytes << 8 | ((bytes >> 8) & 0xFF); }
Here is the caller graph for this function:

◆ flip_endian_u32()

u32 mtcore::flip_endian_u32 ( const u32 bytes)
constexpr

Flips the endianness of a u3.

Definition at line 63 of file byte_order.hpp.

63 {
64 return bytes << 24 | ((bytes << 8) & 0xFF0000) | ((bytes >> 8) & 0xFF00) | ((bytes >> 24) & 0xFF);
65 }
Here is the caller graph for this function:

Variable Documentation

◆ machine

auto mtcore::endian::machine = std::endian::native
constexpr

endian of machine (alias for std::endian::native)

Definition at line 37 of file byte_order.hpp.

◆ opposite

auto mtcore::endian::opposite = std::endian::native == std::endian::little ? std::endian::big : std::endian::little
constexpr

endian that is opposite of machine (opposite of std::endian::native)

Definition at line 42 of file byte_order.hpp.