31#ifndef ETL_UNALIGNED_TYPE_INCLUDED
32#define ETL_UNALIGNED_TYPE_INCLUDED
49#if ETL_USING_CPP20 && ETL_USING_STL
80 namespace private_unaligned_type
87 template <
size_t Size_,
typename TDerivedType>
93 typedef unsigned char storage_type;
94 typedef storage_type* pointer;
95 typedef const storage_type* const_pointer;
97 typedef const storage_type* const_iterator;
127 const_pointer data()
const
143 const_iterator
begin()
const
151 const_iterator
cbegin()
const
167 const_reverse_iterator
rbegin()
const
175 const_reverse_iterator
crbegin()
const
191 const_iterator
end()
const
199 const_iterator
cend()
const
215 const_reverse_iterator
rend()
const
223 const_reverse_iterator
crend()
const
231 storage_type& operator[](
int i)
239 const storage_type& operator[](
int i)
const
268 template <
size_t Size_>
283 unsigned char storage[
Size_];
291 template <
size_t Size_>
308 : storage(
other.storage)
315 storage =
other.storage;
320 unsigned char* storage;
326 template <
size_t Size_,
int Endian_,
bool Is_Integral>
333 template <
size_t Size_,
int Endian_>
338 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::storage_type storage_type;
339 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::pointer pointer;
340 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::const_pointer const_pointer;
343 template <
typename T>
344 static void copy_value_to_store(
const T& value, pointer
store)
348#if ETL_HAS_CONSTEXPR_ENDIANESS
349 if ETL_IF_CONSTEXPR(Endian_ == etl::endianness::value())
351 if (Endian_ != etl::endianness::value())
359 template <
typename T>
360 static void copy_store_to_value(const_pointer
store,
T& value)
364#if ETL_HAS_CONSTEXPR_ENDIANESS
365 if ETL_IF_CONSTEXPR(
Endian == etl::endianness::value())
367 if (Endian_ != etl::endianness::value())
375 static void copy_store_to_store(const_pointer
src,
int endian_src, pointer
dst)
390 template <
size_t Size_,
int Endian_>
395 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::storage_type storage_type;
396 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::pointer pointer;
397 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::const_pointer const_pointer;
400 template <
typename T>
401 static void copy_value_to_store(
const T& value, pointer
store)
405#if ETL_HAS_CONSTEXPR_ENDIANESS
406 if ETL_IF_CONSTEXPR(Endian_ == etl::endianness::value())
408 if (Endian_ != etl::endianness::value())
416 template <
typename T>
417 static void copy_store_to_value(const_pointer
store,
T& value)
421#if ETL_HAS_CONSTEXPR_ENDIANESS
422 if ETL_IF_CONSTEXPR(
Endian == etl::endianness::value())
424 if (Endian_ != etl::endianness::value())
427 etl::reverse(
reinterpret_cast<pointer
>(&value),
reinterpret_cast<pointer
>(&value) +
Size_);
432 static void copy_store_to_store(const_pointer
src,
int endian_src, pointer
dst)
450 template <
typename T,
int Endian_>
457 typedef T value_type;
461 typedef typename private_unaligned_type::unaligned_type_storage<
sizeof(
T)>::storage_type storage_type;
462 typedef typename private_unaligned_type::unaligned_type_storage<
sizeof(
T)>::pointer pointer;
463 typedef typename private_unaligned_type::unaligned_type_storage<
sizeof(
T)>::const_pointer const_pointer;
464 typedef typename private_unaligned_type::unaligned_type_storage<
sizeof(
T)>::iterator iterator;
465 typedef typename private_unaligned_type::unaligned_type_storage<
sizeof(
T)>::const_iterator const_iterator;
466 typedef typename private_unaligned_type::unaligned_type_storage<
sizeof(
T)>::reverse_iterator reverse_iterator;
467 typedef typename private_unaligned_type::unaligned_type_storage<
sizeof(
T)>::const_reverse_iterator const_reverse_iterator;
469 static ETL_CONSTANT
int Endian = Endian_;
470 static ETL_CONSTANT
size_t Size =
sizeof(
T);
484 unaligned_copy::copy_value_to_store(value, this->storage);
492 etl::copy_n(
reinterpret_cast<const char*
>(address),
sizeof(
T), this->storage);
502 etl::copy_n(
reinterpret_cast<const char*
>(address),
sizeof(
T), this->storage);
510 unaligned_copy::copy_store_to_store(
other.data(),
Endian,
this->storage);
516 template <
int Endian_Other>
527 unaligned_copy::copy_value_to_store(value, this->storage);
537 unaligned_copy::copy_store_to_store(
other.data(), Endian_,
this->storage);
545 template <
int Endian_Other>
560 unaligned_copy::copy_store_to_value(this->storage, value);
572 unaligned_copy::copy_store_to_value(this->storage, value);
578 template <
typename T,
int Endian_>
579 ETL_CONSTANT
int unaligned_type<T, Endian_>::Endian;
581 template <
typename T,
int Endian_>
582 ETL_CONSTANT
size_t unaligned_type<T, Endian_>::Size;
591 template <
typename T,
int Endian_>
598 template <
typename U,
int Endian_Other>
601 typedef T value_type;
605 typedef typename private_unaligned_type::unaligned_type_storage_ext<
sizeof(
T)>::storage_type storage_type;
606 typedef typename private_unaligned_type::unaligned_type_storage_ext<
sizeof(
T)>::pointer pointer;
607 typedef typename private_unaligned_type::unaligned_type_storage_ext<
sizeof(
T)>::const_pointer const_pointer;
608 typedef typename private_unaligned_type::unaligned_type_storage_ext<
sizeof(
T)>::iterator iterator;
609 typedef typename private_unaligned_type::unaligned_type_storage_ext<
sizeof(
T)>::const_iterator const_iterator;
610 typedef typename private_unaligned_type::unaligned_type_storage_ext<
sizeof(
T)>::reverse_iterator reverse_iterator;
611 typedef typename private_unaligned_type::unaligned_type_storage_ext<
sizeof(
T)>::const_reverse_iterator const_reverse_iterator;
613 static ETL_CONSTANT
int Endian = Endian_;
614 static ETL_CONSTANT
size_t Size =
sizeof(
T);
630 unaligned_copy::copy_value_to_store(value, this->storage);
636 template <
int Endian_Other>
650 other.storage = ETL_NULLPTR;
656 template <
int Endian_Other>
663 etl::reverse(this->
begin(), this->
end());
666 other.storage = ETL_NULLPTR;
675 unaligned_copy::copy_value_to_store(value, this->storage);
685 unaligned_copy::copy_store_to_store(
other.data(),
Endian,
this->storage);
693 template <
int Endian_Other>
707 this->storage =
other.storage;
708 other.storage = ETL_NULLPTR;
716 template <
int Endian_Other>
719 this->storage =
other.storage;
724 etl::reverse(this->
begin(), this->
end());
727 other.storage = ETL_NULLPTR;
740 unaligned_copy::copy_store_to_value(this->storage, value);
752 unaligned_copy::copy_store_to_value(this->storage, value);
777#if ETL_HAS_CONSTEXPR_ENDIANNESS
790#if ETL_USING_8BIT_TYPES
798#if ETL_USING_64BIT_TYPES
819#if ETL_USING_8BIT_TYPES
827#if ETL_USING_64BIT_TYPES
847#if ETL_USING_8BIT_TYPES
855#if ETL_USING_64BIT_TYPES
864 typedef be_char_t net_char_t;
865 typedef be_schar_t net_schar_t;
866 typedef be_uchar_t net_uchar_t;
867 typedef be_short_t net_short_t;
868 typedef be_ushort_t net_ushort_t;
869 typedef be_int_t net_int_t;
870 typedef be_uint_t net_uint_t;
871 typedef be_long_t net_long_t;
872 typedef be_ulong_t net_ulong_t;
873 typedef be_long_long_t net_long_long_t;
874 typedef be_ulong_long_t net_ulong_long_t;
875#if ETL_USING_8BIT_TYPES
879 typedef be_int16_t net_int16_t;
880 typedef be_uint16_t net_uint16_t;
881 typedef be_int32_t net_int32_t;
882 typedef be_uint32_t net_uint32_t;
883#if ETL_USING_64BIT_TYPES
884 typedef be_int64_t net_int64_t;
885 typedef be_uint64_t net_uint64_t;
887 typedef be_float_t net_float_t;
888 typedef be_double_t net_double_t;
889 typedef be_long_double_t net_long_double_t;
892 template <
typename T,
int Endian>
897 template <
typename T,
int Endian>
901#if ETL_HAS_CONSTEXPR_ENDIANNESS
914#if ETL_USING_8BIT_TYPES
922#if ETL_USING_64BIT_TYPES
943 #if ETL_USING_8BIT_TYPES
951 #if ETL_USING_64BIT_TYPES
971 #if ETL_USING_8BIT_TYPES
979 #if ETL_USING_64BIT_TYPES
988 typedef be_char_ext_t net_char_ext_t;
989 typedef be_schar_ext_t net_schar_ext_t;
990 typedef be_uchar_ext_t net_uchar_ext_t;
991 typedef be_short_ext_t net_short_ext_t;
992 typedef be_ushort_ext_t net_ushort_ext_t;
993 typedef be_int_ext_t net_int_ext_t;
994 typedef be_uint_ext_t net_uint_ext_t;
995 typedef be_long_ext_t net_long_ext_t;
996 typedef be_ulong_ext_t net_ulong_ext_t;
997 typedef be_long_long_ext_t net_long_long_ext_t;
998 typedef be_ulong_long_ext_t net_ulong_long_ext_t;
999#if ETL_USING_8BIT_TYPES
1003 typedef be_int16_ext_t net_int16_ext_t;
1004 typedef be_uint16_ext_t net_uint16_ext_t;
1005 typedef be_int32_ext_t net_int32_ext_t;
1006 typedef be_uint32_ext_t net_uint32_ext_t;
1007#if ETL_USING_64BIT_TYPES
1008 typedef be_int64_ext_t net_int64_ext_t;
1009 typedef be_uint64_ext_t net_uint64_ext_t;
1011 typedef be_float_ext_t net_float_ext_t;
1012 typedef be_double_ext_t net_double_ext_t;
1013 typedef be_long_double_ext_t net_long_double_ext_t;
1016 template <
typename T,
int Endian>
1021 template <
typename T,
int Endian>
Unaligned copy.
Definition unaligned_type.h:327
Definition iterator.h:228
Buffer size exception.
Definition unaligned_type.h:71
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value &&etl::is_unsigned< T >::value &&(etl::integral_limits< T >::bits==16U), T >::type reverse_bytes(T value)
Definition binary.h:740
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
is_floating_point
Definition type_traits_generator.h:1070
is_integral
Definition type_traits_generator.h:1040
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR TContainer::reverse_iterator rend(TContainer &container)
Definition iterator.h:1114
ETL_CONSTEXPR TContainer::const_reverse_iterator crbegin(const TContainer &container)
Definition iterator.h:1104
ETL_CONSTEXPR TContainer::reverse_iterator rbegin(TContainer &container)
Definition iterator.h:1084
ETL_CONSTEXPR TContainer::const_iterator cbegin(const TContainer &container)
Definition iterator.h:982
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition iterator.h:962
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
ETL_CONSTEXPR TContainer::const_reverse_iterator crend(const TContainer &container)
Definition iterator.h:1134
ETL_CONSTEXPR TContainer::const_iterator cend(const TContainer &container)
Definition iterator.h:1012
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:992
iterator
Definition iterator.h:399
Definition unaligned_type.h:58