A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove
unaligned_type.h

unaligned_type

20.23.0
constexpr from 20.26.0

A wrapper for fundamental types around unaligned internal storage.
Allows big and little endian storage.

template <typename T, int Endian>
class unaligned_type

Where Endian is etl::endian::big or etl::endian::little.
____________________________________________________________________________________________________

For C++11 or above

template <typename T, int Endian>
using unaligned_type_t = typename etl::unaligned_type<T, Endian>::type;
____________________________________________________________________________________________________

For C++17 or above

template <typename T, int Endian>
constexpr size_t unaligned_type_v = etl::unaligned_type<T, Endian>::Size;
____________________________________________________________________________________________________
The following types are predefined.

Host order

Only defined if ETL_ENDIANNESS_IS_CONSTEXPR

host_char_t
host_schar_t
host_uchar_t
host_short_t
host_ushort_t
host_int_t
host_uint_t
host_long_t
host_ulong_t
host_long_long_t
host_ulong_long_t
host_int8_t       ETL_USING_8BIT_TYPES
host_uint8_t      ETL_USING_8BIT_TYPES
host_int16_t
host_uint16_t
host_int32_t
host_uint32_t
host_int64_t      ETL_USING_64BIT_TYPES
host_uint64_t     ETL_USING_64BIT_TYPES
host_float_t
host_double_t
host_long_double_t
____________________________________________________________________________________________________

Little Endian


le_char_t
le_schar_t
le_uchar_t
le_short_t
le_ushort_t
le_int_t
le_uint_t
le_long_t
le_ulong_t
le_long_long_t
le_ulong_long_t
le_int8_t       ETL_USING_8BIT_TYPES
le_uint8_t      ETL_USING_8BIT_TYPES
le_int16_t
le_uint16_t
le_int32_t
le_uint32_t
le_int64_t      ETL_USING_64BIT_TYPES
le_uint64_t     ETL_USING_64BIT_TYPES
le_float_t
le_double_t
le_long_double_t
____________________________________________________________________________________________________

Big Endian


be_char_t
be_schar_t
be_uchar_t
be_short_t
be_ushort_t
be_int_t
be_uint_t
be_long_t
be_ulong_t
be_long_long_t
be_ulong_long_t
be_int8_t       ETL_USING_8BIT_TYPES
be_uint8_t      ETL_USING_8BIT_TYPES
be_int16_t
be_uint16_t
be_int32_t
be_uint32_t
be_int64_t      ETL_USING_64BIT_TYPES
be_uint64_t     ETL_USING_64BIT_TYPES
be_float_t
be_double_t
be_long_double_t
____________________________________________________________________________________________________

Network Order

Synonym for Big Endian


using net_char_t        = be_char_t
using net_schar_t       = be_schar_t
using net_uchar_t       = be_uchar_t
using net_short_t       = be_short_t
using net_ushort_t      = be_ushort_t
using net_int_t         = be_int_t
using be_uint_t         = net_uint_t
using net_long_t        = be_long_t      
using net_ulong_t       = be_ulong_t
using net_long_long_t   = be_long_long_t 
using net_ulong_long_t  = be_ulong_long_t
using net_int8_t        = be_int8_t       ETL_USING_8BIT_TYPES
using net_uint8_t       = be_uint8_t      ETL_USING_8BIT_TYPES
using net_int16_t       = be_int16_t
using net_uint16_t      = be_uint16_t
using net_int32_t       = be_int32_t      
using net_uint32_t      = be_uint32_t
using net_int64_t       = be_int64_t      ETL_USING_64BIT_TYPES
using net_uint64_t      = be_uint64_t     ETL_USING_64BIT_TYPES
using net_float_t       = be_float_t
using net_double_t      = be_double_t
using net_long_double_t = be_long_double_t
____________________________________________________________________________________________________

Constants

int Endian  The endianness of the type.
size_t Size The size, in char, of the type.
____________________________________________________________________________________________________

Constructors


ETL_CONSTEXPR unaligned_type()
Constructs an uninitialised unaligned_type.
____________________________________________________________________________________________________
unaligned_type(T value)
Constructs with the supplied value.
____________________________________________________________________________________________________
template <int Endian_Other>
unaligned_type(const unaligned_type<T, Endian_Other>& other)
Constructs from another unaligned_type.
The endianness is converted, if necessary.
____________________________________________________________________________________________________

Member types


using pointer                = char*;
using const_pointer          = const char*;
using iterator               = char*;
using const_iterator         = const char*;
using reverse_iterator       = etl::reverse_iterator<iterator>;
using const_reverse_iterator = etl::reverse_iterator<const_iterator>;
____________________________________________________________________________________________________

Member functions


pointer data()
Pointer to the beginning of the storage.

ETL_CONSTEXPR14 const_pointer data() const
Const pointer to the beginning of the storage.
____________________________________________________________________________________________________
ETL_CONSTEXPR14 size_t size() const
Size of the storage.
____________________________________________________________________________________________________
iterator begin()
Iterator to the beginning of the storage.

ETL_CONSTEXPR14 const_iterator begin() const
Const iterator to the beginning of the storage.

ETL_CONSTEXPR14 const_iterator cbegin() const
Const iterator to the beginning of the storage.
____________________________________________________________________________________________________
reverse_iterator rbegin()
Reverse iterator to the beginning of the storage.

ETL_CONSTEXPR14 const_reverse_iterator rbegin() const
Const reverse iterator to the beginning of the storage.

ETL_CONSTEXPR14 const_reverse_iterator crbegin() const
Const reverse iterator to the beginning of the storage.
____________________________________________________________________________________________________
iterator end()
Iterator to the end of the storage.

ETL_CONSTEXPR14 const_iterator end() const
Const iterator to the end of the storage.

ETL_CONSTEXPR14 const_iterator cend() const
Const iterator to the end of the storage.
____________________________________________________________________________________________________
reverse_iterator rend()
Reverse iterator to the end of the storage.

ETL_CONSTEXPR14 const_reverse_iterator rend() const
Const reverse iterator to the end of the storage.

ETL_CONSTEXPR14 const_reverse_iterator crend() const
Const reverse iterator to the end of the storage.
____________________________________________________________________________________________________
char& operator[](int i)
Index operator.

ETL_CONSTEXPR14 const char& operator[](int i) const
Const index operator.
____________________________________________________________________________________________________
ETL_CONSTEXPR14 unaligned_type& operator =(T value)
Assignment operator.
____________________________________________________________________________________________________
ETL_CONSTEXPR14 operator T() const
Conversion operator.
____________________________________________________________________________________________________
ETL_CONSTEXPR14 T value() const
Gets the value.
____________________________________________________________________________________________________
template <int Endian_Other>
ETL_CONSTEXPR14 unaligned_type& operator =(const unaligned_type<T, Endian_Other>& other)
Assignment operator from other endianness.
____________________________________________________________________________________________________
ETL_CONSTEXPR14 bool operator ==(const unaligned_type& lhs, const unaligned_type& rhs)
Equality operator.

ETL_CONSTEXPR14 bool operator ==(const unaligned_type& lhs, T rhs)
Equality operator.

ETL_CONSTEXPR14 bool operator ==(T lhs, const unaligned_type& rhs)
Equality operator.
____________________________________________________________________________________________________
ETL_CONSTEXPR14 bool operator !=(const unaligned_type& lhs, T rhs)
Inequality operator.

ETL_CONSTEXPR14 bool operator !=(const unaligned_type& lhs, const unaligned_type& rhs)
Inequality operator.

ETL_CONSTEXPR14 bool operator !=(T lhs, const unaligned_type& rhs)
Inequality operator.