|
TRLC Platform Library
1.0.0
Header-only C++ library for compile-time platform detection and abstraction
|
Byte order detection and utilities for cross-platform development. More...
#include <cstdint>#include <type_traits>Go to the source code of this file.
Classes | |
| struct | trlc::platform::EndiannessInfo |
| Comprehensive endianness information structure. More... | |
Namespaces | |
| trlc | |
| trlc::platform | |
| trlc::platform::detail | |
Macros | |
| #define | TRLC_ENDIAN_LITTLE (trlc::platform::isLittleEndian()) |
| Check if system is little-endian at compile time. More... | |
| #define | TRLC_ENDIAN_BIG (trlc::platform::isBigEndian()) |
| Check if system is big-endian at compile time. More... | |
| #define | TRLC_BYTE_SWAP(x) (trlc::platform::byteSwap(x)) |
| Swap bytes in a value. More... | |
| #define | TRLC_HTON(x) (trlc::platform::hostToNetwork(x)) |
| Convert value from host to network byte order. More... | |
| #define | TRLC_NTOH(x) (trlc::platform::networkToHost(x)) |
| Convert value from network to host byte order. More... | |
| #define | TRLC_HTONS(x) (trlc::platform::hostToNetworkShort(x)) |
| Host to network byte order for 16-bit values. More... | |
| #define | TRLC_HTONL(x) (trlc::platform::hostToNetworkLong(x)) |
| Host to network byte order for 32-bit values. More... | |
| #define | TRLC_NTOHS(x) (trlc::platform::networkToHostShort(x)) |
| Network to host byte order for 16-bit values. More... | |
| #define | TRLC_NTOHL(x) (trlc::platform::networkToHostLong(x)) |
| Network to host byte order for 32-bit values. More... | |
| #define | TRLC_ENDIANNESS_INCLUDED |
Enumerations | |
| enum class | trlc::platform::ByteOrder : int { trlc::platform::unknown = 0 , trlc::platform::little_endian , trlc::platform::big_endian , trlc::platform::mixed_endian } |
| Byte order enumeration. More... | |
Functions | |
| static ByteOrder | trlc::platform::detail::detectByteOrderCompileTime () |
| Compile-time endianness detection using preprocessor macros. More... | |
| ByteOrder | trlc::platform::detail::detectByteOrderRuntime () |
| Runtime endianness detection using union method. More... | |
| static ByteOrder | trlc::platform::getByteOrder () |
| Get the system's byte order. More... | |
| static EndiannessInfo | trlc::platform::getEndiannessInfo () |
| Get comprehensive endianness information. More... | |
| static bool | trlc::platform::isLittleEndian () |
| Check if system is little-endian. More... | |
| static bool | trlc::platform::isBigEndian () |
| Check if system is big-endian. More... | |
| static uint16_t | trlc::platform::detail::byteSwap16Impl (uint16_t value) |
| 16-bit byte swap implementation More... | |
| static uint32_t | trlc::platform::detail::byteSwap32Impl (uint32_t value) |
| 32-bit byte swap implementation More... | |
| static uint64_t | trlc::platform::detail::byteSwap64Impl (uint64_t value) |
| 64-bit byte swap implementation More... | |
| static uint16_t | trlc::platform::byteSwap16 (uint16_t value) |
| Swap bytes in a 16-bit value. More... | |
| static uint32_t | trlc::platform::byteSwap32 (uint32_t value) |
| Swap bytes in a 32-bit value. More... | |
| static uint64_t | trlc::platform::byteSwap64 (uint64_t value) |
| Swap bytes in a 64-bit value. More... | |
| template<typename Type > | |
| static Type | trlc::platform::byteSwap (Type value) |
| Generic byte swap function for integral types. More... | |
| template<typename Type > | |
| static Type | trlc::platform::hostToNetwork (Type value) |
| Convert from host byte order to network byte order (big-endian) More... | |
| template<typename Type > | |
| static Type | trlc::platform::networkToHost (Type value) |
| Convert from network byte order (big-endian) to host byte order. More... | |
| static uint16_t | trlc::platform::hostToNetworkShort (uint16_t hostshort) |
| Convert 16-bit value from host to network byte order. More... | |
| static uint32_t | trlc::platform::hostToNetworkLong (uint32_t hostlong) |
| Convert 32-bit value from host to network byte order. More... | |
| static uint16_t | trlc::platform::networkToHostShort (uint16_t netshort) |
| Convert 16-bit value from network to host byte order. More... | |
| static uint32_t | trlc::platform::networkToHostLong (uint32_t netlong) |
| Convert 32-bit value from network to host byte order. More... | |
| static bool | trlc::platform::areByteOrdersCompatible (ByteOrder order1, ByteOrder order2) |
| Check if two byte orders are compatible (no swapping needed) More... | |
| static ByteOrder | trlc::platform::getOppositeByteOrder (ByteOrder order) |
| Get the opposite byte order. More... | |
| template<typename Type > | |
| static Type | trlc::platform::convertByteOrder (Type value, ByteOrder from_order, ByteOrder to_order) |
| Convert value between specified byte orders. More... | |
Byte order detection and utilities for cross-platform development.
This header provides comprehensive endianness detection and byte manipulation utilities. It includes compile-time byte order detection, efficient byte swapping functions with compiler intrinsics, and network byte order conversion utilities.
Features:
Definition in file endianness.hpp.
| #define TRLC_BYTE_SWAP | ( | x | ) | (trlc::platform::byteSwap(x)) |
Swap bytes in a value.
Generic macro for byte swapping that works with any integral type.
| x | Value to byte swap |
Definition at line 538 of file endianness.hpp.
| #define TRLC_ENDIAN_BIG (trlc::platform::isBigEndian()) |
Check if system is big-endian at compile time.
Evaluates to true if the system uses big-endian byte order.
Definition at line 528 of file endianness.hpp.
| #define TRLC_ENDIAN_LITTLE (trlc::platform::isLittleEndian()) |
Check if system is little-endian at compile time.
Evaluates to true if the system uses little-endian byte order.
Definition at line 521 of file endianness.hpp.
| #define TRLC_ENDIANNESS_INCLUDED |
Definition at line 597 of file endianness.hpp.
| #define TRLC_HTON | ( | x | ) | (trlc::platform::hostToNetwork(x)) |
Convert value from host to network byte order.
| x | Value in host byte order |
Definition at line 546 of file endianness.hpp.
| #define TRLC_HTONL | ( | x | ) | (trlc::platform::hostToNetworkLong(x)) |
Host to network byte order for 32-bit values.
Equivalent to POSIX htonl().
| x | 32-bit value in host byte order |
Definition at line 574 of file endianness.hpp.
| #define TRLC_HTONS | ( | x | ) | (trlc::platform::hostToNetworkShort(x)) |
Host to network byte order for 16-bit values.
Equivalent to POSIX htons().
| x | 16-bit value in host byte order |
Definition at line 564 of file endianness.hpp.
| #define TRLC_NTOH | ( | x | ) | (trlc::platform::networkToHost(x)) |
Convert value from network to host byte order.
| x | Value in network byte order |
Definition at line 554 of file endianness.hpp.
| #define TRLC_NTOHL | ( | x | ) | (trlc::platform::networkToHostLong(x)) |
Network to host byte order for 32-bit values.
Equivalent to POSIX ntohl().
| x | 32-bit value in network byte order |
Definition at line 594 of file endianness.hpp.
| #define TRLC_NTOHS | ( | x | ) | (trlc::platform::networkToHostShort(x)) |
Network to host byte order for 16-bit values.
Equivalent to POSIX ntohs().
| x | 16-bit value in network byte order |
Definition at line 584 of file endianness.hpp.