Embedded Template Library 1.0
Loading...
Searching...
No Matches
unaligned_type.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2022 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_UNALIGNED_TYPE_INCLUDED
32#define ETL_UNALIGNED_TYPE_INCLUDED
33
37
38#include "platform.h"
39#include "algorithm.h"
40#include "array.h"
41#include "binary.h"
42#include "bit.h"
43#include "endianness.h"
44#include "exception.h"
45#include "file_error_numbers.h"
46#include "iterator.h"
47#include "type_traits.h"
48
49#if ETL_USING_CPP20 && ETL_USING_STL
50 #include <bit>
51#endif
52
53#include <string.h>
54
55namespace etl
56{
57 struct unaligned_type_exception : public etl::exception
58 {
59 public:
60
61 unaligned_type_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
62 : exception(reason_, file_name_, line_number_)
63 {
64 }
65 };
66
67 //***************************************************************************
69 //***************************************************************************
70 class unaligned_type_buffer_size : public unaligned_type_exception
71 {
72 public:
73
74 unaligned_type_buffer_size(string_type file_name_, numeric_type line_number_)
75 : unaligned_type_exception(ETL_ERROR_TEXT("unaligned_type:buffer size", ETL_UNALIGNED_TYPE_FILE_ID"A"), file_name_, line_number_)
76 {
77 }
78 };
79
80 namespace private_unaligned_type
81 {
82 //*************************************************************************
87 //*************************************************************************
88 template <size_t Size_, typename TDerivedType>
89 ETL_PACKED_CLASS(unaligned_type_common)
90 {
91 public:
92
93 typedef TDerivedType derived_type;
94 typedef unsigned char storage_type;
95 typedef storage_type* pointer;
96 typedef const storage_type* const_pointer;
97 typedef storage_type* iterator;
98 typedef const storage_type* const_iterator;
100 typedef etl::reverse_iterator<const_iterator> const_reverse_iterator;
101
102 //*************************************************************************
104 //*************************************************************************
105 unaligned_type_common() {}
106
107 //*************************************************************************
109 //*************************************************************************
110 size_t size() const
111 {
112 return Size_;
113 }
114
115 //*************************************************************************
117 //*************************************************************************
118 pointer data()
119 {
120 return get_storage();
121 }
122
123 //*************************************************************************
125 //*************************************************************************
126 const_pointer data() const
127 {
128 return get_storage();
129 }
130
131 //*************************************************************************
133 //*************************************************************************
135 {
136 return iterator(get_storage());
137 }
138
139 //*************************************************************************
141 //*************************************************************************
142 const_iterator begin() const
143 {
144 return const_iterator(get_storage());
145 }
146
147 //*************************************************************************
149 //*************************************************************************
150 const_iterator cbegin() const
151 {
152 return const_iterator(get_storage());
153 }
154
155 //*************************************************************************
157 //*************************************************************************
159 {
160 return reverse_iterator(get_storage() + Size_);
161 }
162
163 //*************************************************************************
165 //*************************************************************************
166 const_reverse_iterator rbegin() const
167 {
168 return const_reverse_iterator(get_storage() + Size_);
169 }
170
171 //*************************************************************************
173 //*************************************************************************
174 const_reverse_iterator crbegin() const
175 {
176 return const_reverse_iterator(get_storage() + Size_);
177 }
178
179 //*************************************************************************
181 //*************************************************************************
182 iterator end()
183 {
184 return iterator(get_storage() + Size_);
185 }
186
187 //*************************************************************************
189 //*************************************************************************
190 const_iterator end() const
191 {
192 return const_iterator(get_storage() + Size_);
193 }
194
195 //*************************************************************************
197 //*************************************************************************
198 const_iterator cend() const
199 {
200 return const_iterator(get_storage() + Size_);
201 }
202
203 //*************************************************************************
205 //*************************************************************************
207 {
208 return reverse_iterator(get_storage());
209 }
210
211 //*************************************************************************
213 //*************************************************************************
214 const_reverse_iterator rend() const
215 {
216 return const_reverse_iterator(get_storage());
217 }
218
219 //*************************************************************************
221 //*************************************************************************
222 const_reverse_iterator crend() const
223 {
224 return const_reverse_iterator(get_storage());
225 }
226
227 //*************************************************************************
229 //*************************************************************************
230 storage_type& operator[](int i)
231 {
232 return get_storage()[i];
233 }
234
235 //*************************************************************************
237 //*************************************************************************
238 const storage_type& operator[](int i) const
239 {
240 return get_storage()[i];
241 }
242
243 private:
244
245 //*************************************************************************
247 //*************************************************************************
248 pointer get_storage()
249 {
250 return static_cast<derived_type*>(this)->storage;
251 }
252
253 //*************************************************************************
255 //*************************************************************************
256 const_pointer get_storage() const
257 {
258 return static_cast<const derived_type*>(this)->storage;
259 }
260 };
261 ETL_END_PACKED
262
263 //*************************************************************************
268 //*************************************************************************
269 template <size_t Size_>
270 ETL_PACKED_CLASS(unaligned_type_storage)
271 : public unaligned_type_common<Size_, unaligned_type_storage<Size_> >
272 {
273 public:
274
275 friend class unaligned_type_common<Size_, unaligned_type_storage<Size_> >;
276
277 protected:
278
279 //*******************************
280 unaligned_type_storage()
281 : storage()
282 {
283 }
284
285 unsigned char storage[Size_];
286 };
287 ETL_END_PACKED
288
289 //*************************************************************************
294 //*************************************************************************
295 template <size_t Size_>
296 ETL_PACKED_CLASS(unaligned_type_storage_ext)
297 : public unaligned_type_common<Size_, unaligned_type_storage_ext<Size_> >
298 {
299 public:
300
301 friend class unaligned_type_common<Size_, unaligned_type_storage_ext<Size_> >;
302
303 protected:
304
305 //*******************************
306 unaligned_type_storage_ext(unsigned char* storage_)
307 : storage(storage_)
308 {
309 }
310
311 //*******************************
312 unaligned_type_storage_ext(const unaligned_type_storage_ext<Size_>& other)
313 : storage(other.storage)
314 {
315 }
316
317 //*******************************
318 unaligned_type_storage_ext& operator=(const unaligned_type_storage_ext<Size_>& other)
319 {
320 storage = other.storage;
321
322 return *this;
323 }
324
325 unsigned char* storage;
326 };
327 ETL_END_PACKED
328
329 //*************************************************************************
331 //*************************************************************************
332 template <size_t Size_, int Endian_, bool Is_Integral>
334
335 //*************************************************************************
338 //*************************************************************************
339 template <size_t Size_, int Endian_>
340 ETL_PACKED_CLASS(unaligned_copy)<Size_, Endian_, true>
341 {
342 public:
343
344 typedef typename private_unaligned_type::unaligned_type_storage< Size_>::storage_type storage_type;
345 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::pointer pointer;
346 typedef typename private_unaligned_type::unaligned_type_storage< Size_>::const_pointer const_pointer;
347
348 //*******************************
349 template <typename T>
350 static void copy_value_to_store(const T& value, pointer store)
351 {
352 memcpy(store, &value, Size_);
353
354#if ETL_HAS_CONSTEXPR_ENDIANNESS
355 if ETL_IF_CONSTEXPR (Endian_ != etl::endianness::value())
356#else
357 if (Endian_ != etl::endianness::value())
358#endif
359 {
360 etl::reverse(store, store + Size_);
361 }
362 }
363
364 //*******************************
365 template <typename T>
366 static void copy_store_to_value(const_pointer store, T & value)
367 {
368 memcpy(&value, store, Size_);
369
370#if ETL_HAS_CONSTEXPR_ENDIANNESS
371 if ETL_IF_CONSTEXPR (Endian_ != etl::endianness::value())
372#else
373 if (Endian_ != etl::endianness::value())
374#endif
375 {
376 value = etl::reverse_bytes(value);
377 }
378 }
379
380 //*******************************
381 static void copy_store_to_store(const_pointer src, int endian_src, pointer dst)
382 {
383 memcpy(dst, src, Size_);
384
385 if (Endian_ != endian_src)
386 {
387 etl::reverse(dst, dst + Size_);
388 }
389 }
390 };
391 ETL_END_PACKED
392
393 //*************************************************************************
396 //*************************************************************************
397 template <size_t Size_, int Endian_>
398 ETL_PACKED_CLASS(unaligned_copy)<Size_, Endian_, false>
399 {
400 public:
401
402 typedef typename private_unaligned_type::unaligned_type_storage< Size_>::storage_type storage_type;
403 typedef typename private_unaligned_type::unaligned_type_storage<Size_>::pointer pointer;
404 typedef typename private_unaligned_type::unaligned_type_storage< Size_>::const_pointer const_pointer;
405
406 //*******************************
407 template <typename T>
408 static void copy_value_to_store(const T& value, pointer store)
409 {
410 memcpy(store, &value, Size_);
411
412#if ETL_HAS_CONSTEXPR_ENDIANNESS
413 if ETL_IF_CONSTEXPR (Endian_ != etl::endianness::value())
414#else
415 if (Endian_ != etl::endianness::value())
416#endif
417 {
418 etl::reverse(store, store + Size_);
419 }
420 }
421
422 //*******************************
423 template <typename T>
424 static void copy_store_to_value(const_pointer store, T & value)
425 {
426 memcpy(&value, store, Size_);
427
428#if ETL_HAS_CONSTEXPR_ENDIANNESS
429 if ETL_IF_CONSTEXPR (Endian_ != etl::endianness::value())
430#else
431 if (Endian_ != etl::endianness::value())
432#endif
433 {
434 etl::reverse(reinterpret_cast<pointer>(&value), reinterpret_cast<pointer>(&value) + Size_);
435 }
436 }
437
438 //*******************************
439 static void copy_store_to_store(const_pointer src, int endian_src, pointer dst)
440 {
441 memcpy(dst, src, Size_);
442
443 if (Endian_ != endian_src)
444 {
445 etl::reverse(dst, dst + Size_);
446 }
447 }
448 };
449 ETL_END_PACKED
450 } // namespace private_unaligned_type
451
452 //*************************************************************************
457 //*************************************************************************
458 template <typename T, int Endian_>
459 ETL_PACKED_CLASS(unaligned_type)
460 : public private_unaligned_type::unaligned_type_storage<sizeof(T)>
461 {
462 public:
463
464 ETL_STATIC_ASSERT(etl::is_integral<T>::value || etl::is_floating_point<T>::value, "Unaligned type must be integral or floating point");
465
466 typedef T value_type;
467
468 typedef private_unaligned_type::unaligned_copy< sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;
469
470 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::storage_type storage_type;
471 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::pointer pointer;
472 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_pointer const_pointer;
473 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::iterator iterator;
474 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_iterator const_iterator;
475 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::reverse_iterator reverse_iterator;
476 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_reverse_iterator const_reverse_iterator;
477
478 static ETL_CONSTANT int Endian = Endian_;
479 static ETL_CONSTANT size_t Size = sizeof(T);
480
481 //*************************************************************************
483 //*************************************************************************
484 unaligned_type() {}
485
486 //*************************************************************************
488 //*************************************************************************
489 unaligned_type(T value)
490 {
491 unaligned_copy::copy_value_to_store(value, this->storage);
492 }
493
494 //*************************************************************************
496 //*************************************************************************
497 unaligned_type(const void* address)
498 {
499 etl::copy_n(reinterpret_cast<const unsigned char*>(address), sizeof(T), this->storage);
500 }
501
502 //*************************************************************************
504 //*************************************************************************
505 unaligned_type(const void* address, size_t buffer_size)
506 {
507 ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::unaligned_type_buffer_size));
508
509 etl::copy_n(reinterpret_cast<const unsigned char*>(address), sizeof(T), this->storage);
510 }
511
512 //*************************************************************************
514 //*************************************************************************
515 unaligned_type(const unaligned_type<T, Endian>& other)
516 {
517 unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);
518 }
519
520 //*************************************************************************
522 //*************************************************************************
523 template <int Endian_Other>
524 unaligned_type(const unaligned_type<T, Endian_Other>& other)
525 {
526 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
527 }
528
529 //*************************************************************************
531 //*************************************************************************
532 unaligned_type& operator=(T value)
533 {
534 unaligned_copy::copy_value_to_store(value, this->storage);
535
536 return *this;
537 }
538
539 //*************************************************************************
541 //*************************************************************************
542 unaligned_type& operator=(const unaligned_type<T, Endian_>& other)
543 {
544 unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage);
545
546 return *this;
547 }
548
549 //*************************************************************************
551 //*************************************************************************
552 template <int Endian_Other>
553 unaligned_type& operator=(const unaligned_type<T, Endian_Other>& other)
554 {
555 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
556
557 return *this;
558 }
559
560 //*************************************************************************
562 //*************************************************************************
563 operator T() const
564 {
565 T value = T();
566
567 unaligned_copy::copy_store_to_value(this->storage, value);
568
569 return value;
570 }
571
572 //*************************************************************************
574 //*************************************************************************
575 T value() const
576 {
577 T value = T();
578
579 unaligned_copy::copy_store_to_value(this->storage, value);
580
581 return value;
582 }
583 };
584 ETL_END_PACKED
585
586 template <typename T, int Endian_>
587 ETL_CONSTANT int unaligned_type<T, Endian_>::Endian;
588
589 template <typename T, int Endian_>
590 ETL_CONSTANT size_t unaligned_type<T, Endian_>::Size;
591
592 //*************************************************************************
598 //*************************************************************************
599 template <typename T, int Endian_>
600 ETL_PACKED_CLASS(unaligned_type_ext)
601 : public private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>
602 {
603 public:
604
605 ETL_STATIC_ASSERT(etl::is_integral<T>::value || etl::is_floating_point<T>::value, "Unaligned type must be integral or floating point");
606
607 template <typename U, int Endian_Other>
608 friend class unaligned_type_ext;
609
610 typedef T value_type;
611
612 typedef private_unaligned_type::unaligned_copy< sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;
613
614 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::storage_type storage_type;
615 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::pointer pointer;
616 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_pointer const_pointer;
617 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::iterator iterator;
618 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_iterator const_iterator;
619 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::reverse_iterator reverse_iterator;
620 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_reverse_iterator const_reverse_iterator;
621
622 static ETL_CONSTANT int Endian = Endian_;
623 static ETL_CONSTANT size_t Size = sizeof(T);
624
625 //*************************************************************************
627 //*************************************************************************
628 unaligned_type_ext(pointer storage_)
629 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
630 {
631 }
632
633 //*************************************************************************
635 //*************************************************************************
636 unaligned_type_ext(T value, pointer storage_)
637 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
638 {
639 unaligned_copy::copy_value_to_store(value, this->storage);
640 }
641
642 //*************************************************************************
644 //*************************************************************************
645 template <int Endian_Other>
646 unaligned_type_ext(const unaligned_type_ext<T, Endian_Other>& other, pointer storage_)
647 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
648 {
649 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
650 }
651
652#if ETL_USING_CPP11
653 //*************************************************************************
655 //*************************************************************************
656 unaligned_type_ext(unaligned_type_ext<T, Endian> && other)
657 : private_unaligned_type::unaligned_type_storage_ext<Size>(other.storage)
658 {
659 other.storage = ETL_NULLPTR;
660 }
661
662 //*************************************************************************
664 //*************************************************************************
665 template <int Endian_Other>
666 unaligned_type_ext(unaligned_type_ext<T, Endian_Other> && other)
667 : private_unaligned_type::unaligned_type_storage_ext<Size>(other.storage)
668 {
669 // If we're constructing from a different endianess then we need to
670 // reverse the data order.
671 if (Endian != Endian_Other)
672 {
673 etl::reverse(this->begin(), this->end());
674 }
675
676 other.storage = ETL_NULLPTR;
677 }
678#endif
679
680 //*************************************************************************
682 //*************************************************************************
683 unaligned_type_ext& operator=(T value)
684 {
685 unaligned_copy::copy_value_to_store(value, this->storage);
686
687 return *this;
688 }
689
690 //*************************************************************************
692 //*************************************************************************
693 unaligned_type_ext& operator=(const unaligned_type_ext<T, Endian>& other)
694 {
695 unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);
696
697 return *this;
698 }
699
700 //*************************************************************************
702 //*************************************************************************
703 template <int Endian_Other>
704 unaligned_type_ext& operator=(const unaligned_type_ext<T, Endian_Other>& other)
705 {
706 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
707
708 return *this;
709 }
710
711#if ETL_USING_CPP11
712 //*************************************************************************
714 //*************************************************************************
715 unaligned_type_ext& operator=(unaligned_type_ext<T, Endian>&& other)
716 {
717 this->storage = other.storage;
718 other.storage = ETL_NULLPTR;
719
720 return *this;
721 }
722
723 //*************************************************************************
725 //*************************************************************************
726 template <int Endian_Other>
727 unaligned_type_ext& operator=(unaligned_type_ext<T, Endian_Other>&& other)
728 {
729 this->storage = other.storage;
730
731 // If we're assigning from a different endianess then we need to reverse
732 // the data order.
733 if (Endian != Endian_Other)
734 {
735 etl::reverse(this->begin(), this->end());
736 }
737
738 other.storage = ETL_NULLPTR;
739
740 return *this;
741 }
742#endif
743
744 //*************************************************************************
746 //*************************************************************************
747 operator T() const
748 {
749 T value = T();
750
751 unaligned_copy::copy_store_to_value(this->storage, value);
752
753 return value;
754 }
755
756 //*************************************************************************
758 //*************************************************************************
759 T value() const
760 {
761 T value = T();
762
763 unaligned_copy::copy_store_to_value(this->storage, value);
764
765 return value;
766 }
767
768 //*************************************************************************
770 //*************************************************************************
771 void set_storage(pointer storage_)
772 {
773 this->storage = storage_;
774 }
775
776 private:
777
778 unaligned_type_ext() ETL_DELETE;
779 };
780 ETL_END_PACKED
781
782 template <typename T, int Endian_>
783 ETL_CONSTANT int unaligned_type_ext<T, Endian_>::Endian;
784
785 template <typename T, int Endian_>
786 ETL_CONSTANT size_t unaligned_type_ext<T, Endian_>::Size;
787
788#if ETL_HAS_CONSTEXPR_ENDIANNESS
789 // Host order
790 typedef unaligned_type<char, etl::endianness::value()> host_char_t;
791 typedef unaligned_type<signed char, etl::endianness::value()> host_schar_t;
792 typedef unaligned_type<unsigned char, etl::endianness::value()> host_uchar_t;
793 typedef unaligned_type<short, etl::endianness::value()> host_short_t;
794 typedef unaligned_type<unsigned short, etl::endianness::value()> host_ushort_t;
795 typedef unaligned_type<int, etl::endianness::value()> host_int_t;
796 typedef unaligned_type<unsigned int, etl::endianness::value()> host_uint_t;
797 typedef unaligned_type<long, etl::endianness::value()> host_long_t;
798 typedef unaligned_type<unsigned long, etl::endianness::value()> host_ulong_t;
799 typedef unaligned_type<long long, etl::endianness::value()> host_long_long_t;
800 typedef unaligned_type<unsigned long long, etl::endianness::value()> host_ulong_long_t;
801 #if ETL_USING_8BIT_TYPES
802 typedef unaligned_type<int8_t, etl::endianness::value()> host_int8_t;
803 typedef unaligned_type<uint8_t, etl::endianness::value()> host_uint8_t;
804 #endif
805 typedef unaligned_type<int16_t, etl::endianness::value()> host_int16_t;
806 typedef unaligned_type<uint16_t, etl::endianness::value()> host_uint16_t;
807 typedef unaligned_type<int32_t, etl::endianness::value()> host_int32_t;
808 typedef unaligned_type<uint32_t, etl::endianness::value()> host_uint32_t;
809 #if ETL_USING_64BIT_TYPES
810 typedef unaligned_type<int64_t, etl::endianness::value()> host_int64_t;
811 typedef unaligned_type<uint64_t, etl::endianness::value()> host_uint64_t;
812 #endif
813 typedef unaligned_type<float, etl::endianness::value()> host_float_t;
814 typedef unaligned_type<double, etl::endianness::value()> host_double_t;
815 typedef unaligned_type<long double, etl::endianness::value()> host_long_double_t;
816#endif
817
818 // Little Endian
819 typedef unaligned_type<char, etl::endian::little> le_char_t;
820 typedef unaligned_type<signed char, etl::endian::little> le_schar_t;
821 typedef unaligned_type<unsigned char, etl::endian::little> le_uchar_t;
822 typedef unaligned_type<short, etl::endian::little> le_short_t;
823 typedef unaligned_type<unsigned short, etl::endian::little> le_ushort_t;
824 typedef unaligned_type<int, etl::endian::little> le_int_t;
825 typedef unaligned_type<unsigned int, etl::endian::little> le_uint_t;
826 typedef unaligned_type<long, etl::endian::little> le_long_t;
827 typedef unaligned_type<unsigned long, etl::endian::little> le_ulong_t;
828 typedef unaligned_type<long long, etl::endian::little> le_long_long_t;
829 typedef unaligned_type<unsigned long long, etl::endian::little> le_ulong_long_t;
830#if ETL_USING_8BIT_TYPES
831 typedef unaligned_type<int8_t, etl::endian::little> le_int8_t;
832 typedef unaligned_type<uint8_t, etl::endian::little> le_uint8_t;
833#endif
834 typedef unaligned_type<int16_t, etl::endian::little> le_int16_t;
835 typedef unaligned_type<uint16_t, etl::endian::little> le_uint16_t;
836 typedef unaligned_type<int32_t, etl::endian::little> le_int32_t;
837 typedef unaligned_type<uint32_t, etl::endian::little> le_uint32_t;
838#if ETL_USING_64BIT_TYPES
839 typedef unaligned_type<int64_t, etl::endian::little> le_int64_t;
840 typedef unaligned_type<uint64_t, etl::endian::little> le_uint64_t;
841#endif
842 typedef unaligned_type<float, etl::endian::little> le_float_t;
843 typedef unaligned_type<double, etl::endian::little> le_double_t;
844 typedef unaligned_type<long double, etl::endian::little> le_long_double_t;
845
846 // Big Endian
847 typedef unaligned_type<char, etl::endian::big> be_char_t;
848 typedef unaligned_type<signed char, etl::endian::big> be_schar_t;
849 typedef unaligned_type<unsigned char, etl::endian::big> be_uchar_t;
850 typedef unaligned_type<short, etl::endian::big> be_short_t;
851 typedef unaligned_type<unsigned short, etl::endian::big> be_ushort_t;
852 typedef unaligned_type<int, etl::endian::big> be_int_t;
853 typedef unaligned_type<unsigned int, etl::endian::big> be_uint_t;
854 typedef unaligned_type<long, etl::endian::big> be_long_t;
855 typedef unaligned_type<unsigned long, etl::endian::big> be_ulong_t;
856 typedef unaligned_type<long long, etl::endian::big> be_long_long_t;
857 typedef unaligned_type<unsigned long long, etl::endian::big> be_ulong_long_t;
858#if ETL_USING_8BIT_TYPES
859 typedef unaligned_type<int8_t, etl::endian::big> be_int8_t;
860 typedef unaligned_type<uint8_t, etl::endian::big> be_uint8_t;
861#endif
862 typedef unaligned_type<int16_t, etl::endian::big> be_int16_t;
863 typedef unaligned_type<uint16_t, etl::endian::big> be_uint16_t;
864 typedef unaligned_type<int32_t, etl::endian::big> be_int32_t;
865 typedef unaligned_type<uint32_t, etl::endian::big> be_uint32_t;
866#if ETL_USING_64BIT_TYPES
867 typedef unaligned_type<int64_t, etl::endian::big> be_int64_t;
868 typedef unaligned_type<uint64_t, etl::endian::big> be_uint64_t;
869#endif
870 typedef unaligned_type<float, etl::endian::big> be_float_t;
871 typedef unaligned_type<double, etl::endian::big> be_double_t;
872 typedef unaligned_type<long double, etl::endian::big> be_long_double_t;
873
874 // Network Order
875 typedef be_char_t net_char_t;
876 typedef be_schar_t net_schar_t;
877 typedef be_uchar_t net_uchar_t;
878 typedef be_short_t net_short_t;
879 typedef be_ushort_t net_ushort_t;
880 typedef be_int_t net_int_t;
881 typedef be_uint_t net_uint_t;
882 typedef be_long_t net_long_t;
883 typedef be_ulong_t net_ulong_t;
884 typedef be_long_long_t net_long_long_t;
885 typedef be_ulong_long_t net_ulong_long_t;
886#if ETL_USING_8BIT_TYPES
887 typedef be_int8_t net_int8_t;
888 typedef be_uint8_t net_uint8_t;
889#endif
890 typedef be_int16_t net_int16_t;
891 typedef be_uint16_t net_uint16_t;
892 typedef be_int32_t net_int32_t;
893 typedef be_uint32_t net_uint32_t;
894#if ETL_USING_64BIT_TYPES
895 typedef be_int64_t net_int64_t;
896 typedef be_uint64_t net_uint64_t;
897#endif
898 typedef be_float_t net_float_t;
899 typedef be_double_t net_double_t;
900 typedef be_long_double_t net_long_double_t;
901
902#if ETL_USING_CPP11
903 template <typename T, int Endian>
904 using unaligned_type_t = typename etl::unaligned_type<T, Endian>::type;
905#endif
906
907#if ETL_USING_CPP17
908 template <typename T, int Endian>
909 constexpr size_t unaligned_type_v = etl::unaligned_type<T, Endian>::Size;
910#endif
911
912#if ETL_HAS_CONSTEXPR_ENDIANNESS
913 // Host order
914 typedef unaligned_type_ext<char, etl::endianness::value()> host_char_ext_t;
915 typedef unaligned_type_ext<signed char, etl::endianness::value()> host_schar_ext_t;
916 typedef unaligned_type_ext<unsigned char, etl::endianness::value()> host_uchar_ext_t;
917 typedef unaligned_type_ext<short, etl::endianness::value()> host_short_ext_t;
918 typedef unaligned_type_ext<unsigned short, etl::endianness::value()> host_ushort_ext_t;
919 typedef unaligned_type_ext<int, etl::endianness::value()> host_int_ext_t;
920 typedef unaligned_type_ext<unsigned int, etl::endianness::value()> host_uint_ext_t;
921 typedef unaligned_type_ext<long, etl::endianness::value()> host_long_ext_t;
922 typedef unaligned_type_ext<unsigned long, etl::endianness::value()> host_ulong_ext_t;
923 typedef unaligned_type_ext<long long, etl::endianness::value()> host_long_long_ext_t;
924 typedef unaligned_type_ext<unsigned long long, etl::endianness::value()> host_ulong_long_ext_t;
925 #if ETL_USING_8BIT_TYPES
926 typedef unaligned_type_ext<int8_t, etl::endianness::value()> host_int8_ext_t;
927 typedef unaligned_type_ext<uint8_t, etl::endianness::value()> host_uint8_ext_t;
928 #endif
929 typedef unaligned_type_ext<int16_t, etl::endianness::value()> host_int16_ext_t;
930 typedef unaligned_type_ext<uint16_t, etl::endianness::value()> host_uint16_ext_t;
931 typedef unaligned_type_ext<int32_t, etl::endianness::value()> host_int32_ext_t;
932 typedef unaligned_type_ext<uint32_t, etl::endianness::value()> host_uint32_ext_t;
933 #if ETL_USING_64BIT_TYPES
934 typedef unaligned_type_ext<int64_t, etl::endianness::value()> host_int64_ext_t;
935 typedef unaligned_type_ext<uint64_t, etl::endianness::value()> host_uint64_ext_t;
936 #endif
937 typedef unaligned_type_ext<float, etl::endianness::value()> host_float_ext_t;
938 typedef unaligned_type_ext<double, etl::endianness::value()> host_double_ext_t;
939 typedef unaligned_type_ext<long double, etl::endianness::value()> host_long_double_ext_t;
940#endif
941
942 // Little Endian
943 typedef unaligned_type_ext<char, etl::endian::little> le_char_ext_t;
944 typedef unaligned_type_ext<signed char, etl::endian::little> le_schar_ext_t;
945 typedef unaligned_type_ext<unsigned char, etl::endian::little> le_uchar_ext_t;
946 typedef unaligned_type_ext<short, etl::endian::little> le_short_ext_t;
947 typedef unaligned_type_ext<unsigned short, etl::endian::little> le_ushort_ext_t;
948 typedef unaligned_type_ext<int, etl::endian::little> le_int_ext_t;
949 typedef unaligned_type_ext<unsigned int, etl::endian::little> le_uint_ext_t;
950 typedef unaligned_type_ext<long, etl::endian::little> le_long_ext_t;
951 typedef unaligned_type_ext<unsigned long, etl::endian::little> le_ulong_ext_t;
952 typedef unaligned_type_ext<long long, etl::endian::little> le_long_long_ext_t;
953 typedef unaligned_type_ext<unsigned long long, etl::endian::little> le_ulong_long_ext_t;
954#if ETL_USING_8BIT_TYPES
955 typedef unaligned_type_ext<int8_t, etl::endian::little> le_int8_ext_t;
956 typedef unaligned_type_ext<uint8_t, etl::endian::little> le_uint8_ext_t;
957#endif
958 typedef unaligned_type_ext<int16_t, etl::endian::little> le_int16_ext_t;
959 typedef unaligned_type_ext<uint16_t, etl::endian::little> le_uint16_ext_t;
960 typedef unaligned_type_ext<int32_t, etl::endian::little> le_int32_ext_t;
961 typedef unaligned_type_ext<uint32_t, etl::endian::little> le_uint32_ext_t;
962#if ETL_USING_64BIT_TYPES
963 typedef unaligned_type_ext<int64_t, etl::endian::little> le_int64_ext_t;
964 typedef unaligned_type_ext<uint64_t, etl::endian::little> le_uint64_ext_t;
965#endif
966 typedef unaligned_type_ext<float, etl::endian::little> le_float_ext_t;
967 typedef unaligned_type_ext<double, etl::endian::little> le_double_ext_t;
968 typedef unaligned_type_ext<long double, etl::endian::little> le_long_double_ext_t;
969
970 // Big Endian
971 typedef unaligned_type_ext<char, etl::endian::big> be_char_ext_t;
972 typedef unaligned_type_ext<signed char, etl::endian::big> be_schar_ext_t;
973 typedef unaligned_type_ext<unsigned char, etl::endian::big> be_uchar_ext_t;
974 typedef unaligned_type_ext<short, etl::endian::big> be_short_ext_t;
975 typedef unaligned_type_ext<unsigned short, etl::endian::big> be_ushort_ext_t;
976 typedef unaligned_type_ext<int, etl::endian::big> be_int_ext_t;
977 typedef unaligned_type_ext<unsigned int, etl::endian::big> be_uint_ext_t;
978 typedef unaligned_type_ext<long, etl::endian::big> be_long_ext_t;
979 typedef unaligned_type_ext<unsigned long, etl::endian::big> be_ulong_ext_t;
980 typedef unaligned_type_ext<long long, etl::endian::big> be_long_long_ext_t;
981 typedef unaligned_type_ext<unsigned long long, etl::endian::big> be_ulong_long_ext_t;
982#if ETL_USING_8BIT_TYPES
983 typedef unaligned_type_ext<int8_t, etl::endian::big> be_int8_ext_t;
984 typedef unaligned_type_ext<uint8_t, etl::endian::big> be_uint8_ext_t;
985#endif
986 typedef unaligned_type_ext<int16_t, etl::endian::big> be_int16_ext_t;
987 typedef unaligned_type_ext<uint16_t, etl::endian::big> be_uint16_ext_t;
988 typedef unaligned_type_ext<int32_t, etl::endian::big> be_int32_ext_t;
989 typedef unaligned_type_ext<uint32_t, etl::endian::big> be_uint32_ext_t;
990#if ETL_USING_64BIT_TYPES
991 typedef unaligned_type_ext<int64_t, etl::endian::big> be_int64_ext_t;
992 typedef unaligned_type_ext<uint64_t, etl::endian::big> be_uint64_ext_t;
993#endif
994 typedef unaligned_type_ext<float, etl::endian::big> be_float_ext_t;
995 typedef unaligned_type_ext<double, etl::endian::big> be_double_ext_t;
996 typedef unaligned_type_ext<long double, etl::endian::big> be_long_double_ext_t;
997
998 // Network Order
999 typedef be_char_ext_t net_char_ext_t;
1000 typedef be_schar_ext_t net_schar_ext_t;
1001 typedef be_uchar_ext_t net_uchar_ext_t;
1002 typedef be_short_ext_t net_short_ext_t;
1003 typedef be_ushort_ext_t net_ushort_ext_t;
1004 typedef be_int_ext_t net_int_ext_t;
1005 typedef be_uint_ext_t net_uint_ext_t;
1006 typedef be_long_ext_t net_long_ext_t;
1007 typedef be_ulong_ext_t net_ulong_ext_t;
1008 typedef be_long_long_ext_t net_long_long_ext_t;
1009 typedef be_ulong_long_ext_t net_ulong_long_ext_t;
1010#if ETL_USING_8BIT_TYPES
1011 typedef be_int8_ext_t net_int8_ext_t;
1012 typedef be_uint8_ext_t net_uint8_ext_t;
1013#endif
1014 typedef be_int16_ext_t net_int16_ext_t;
1015 typedef be_uint16_ext_t net_uint16_ext_t;
1016 typedef be_int32_ext_t net_int32_ext_t;
1017 typedef be_uint32_ext_t net_uint32_ext_t;
1018#if ETL_USING_64BIT_TYPES
1019 typedef be_int64_ext_t net_int64_ext_t;
1020 typedef be_uint64_ext_t net_uint64_ext_t;
1021#endif
1022 typedef be_float_ext_t net_float_ext_t;
1023 typedef be_double_ext_t net_double_ext_t;
1024 typedef be_long_double_ext_t net_long_double_ext_t;
1025
1026#if ETL_USING_CPP11
1027 template <typename T, int Endian>
1028 using unaligned_type_ext_t = typename etl::unaligned_type_ext<T, Endian>::type;
1029#endif
1030
1031#if ETL_USING_CPP17
1032 template <typename T, int Endian>
1033 constexpr size_t unaligned_type_ext_t_v = etl::unaligned_type_ext<T, Endian>::Size;
1034#endif
1035} // namespace etl
1036
1037#endif
Unaligned copy.
Definition unaligned_type.h:333
Definition iterator.h:252
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:745
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
Definition exception.h:59
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR TContainer::reverse_iterator rend(TContainer &container)
Definition iterator.h:1119
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition iterator.h:1228
ETL_CONSTEXPR TContainer::const_reverse_iterator crbegin(const TContainer &container)
Definition iterator.h:1109
ETL_CONSTEXPR TContainer::reverse_iterator rbegin(TContainer &container)
Definition iterator.h:1089
ETL_CONSTEXPR TContainer::const_iterator cbegin(const TContainer &container)
Definition iterator.h:987
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1192
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition iterator.h:967
ETL_PACKED_CLASS(unaligned_type) ETL_END_PACKED ETL_CONSTANT int unaligned_type< T, Endian_ >::Endian
Allows an arithmetic type to be stored at an unaligned address.
Definition unaligned_type.h:459
ETL_CONSTEXPR TContainer::const_reverse_iterator crend(const TContainer &container)
Definition iterator.h:1139
ETL_CONSTEXPR TContainer::const_iterator cend(const TContainer &container)
Definition iterator.h:1017
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition iterator.h:997
iterator
Definition iterator.h:424
ETL_PACKED_CLASS(unaligned_type_common)
Definition unaligned_type.h:89