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 "type_traits.h"
40#include "endianness.h"
41#include "iterator.h"
42#include "algorithm.h"
43#include "bit.h"
44#include "binary.h"
45#include "array.h"
46#include "exception.h"
47#include "file_error_numbers.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 //*************************************************************************
86 //*************************************************************************
87 template <size_t Size_, typename TDerivedType>
88 ETL_PACKED_CLASS(unaligned_type_common)
89 {
90 public:
91
92 typedef TDerivedType derived_type;
93 typedef unsigned char storage_type;
94 typedef storage_type* pointer;
95 typedef const storage_type* const_pointer;
96 typedef storage_type* iterator;
97 typedef const storage_type* const_iterator;
99 typedef etl::reverse_iterator<const_iterator> const_reverse_iterator;
100
101 //*************************************************************************
103 //*************************************************************************
104 unaligned_type_common()
105 {
106 }
107
108 //*************************************************************************
110 //*************************************************************************
111 size_t size() const
112 {
113 return Size_;
114 }
115
116 //*************************************************************************
118 //*************************************************************************
119 pointer data()
120 {
121 return get_storage();
122 }
123
124 //*************************************************************************
126 //*************************************************************************
127 const_pointer data() const
128 {
129 return get_storage();
130 }
131
132 //*************************************************************************
134 //*************************************************************************
136 {
137 return iterator(get_storage());
138 }
139
140 //*************************************************************************
142 //*************************************************************************
143 const_iterator begin() const
144 {
145 return const_iterator(get_storage());
146 }
147
148 //*************************************************************************
150 //*************************************************************************
151 const_iterator cbegin() const
152 {
153 return const_iterator(get_storage());
154 }
155
156 //*************************************************************************
158 //*************************************************************************
160 {
161 return reverse_iterator(get_storage() + Size_);
162 }
163
164 //*************************************************************************
166 //*************************************************************************
167 const_reverse_iterator rbegin() const
168 {
169 return const_reverse_iterator(get_storage() + Size_);
170 }
171
172 //*************************************************************************
174 //*************************************************************************
175 const_reverse_iterator crbegin() const
176 {
177 return const_reverse_iterator(get_storage() + Size_);
178 }
179
180 //*************************************************************************
182 //*************************************************************************
183 iterator end()
184 {
185 return iterator(get_storage() + Size_);
186 }
187
188 //*************************************************************************
190 //*************************************************************************
191 const_iterator end() const
192 {
193 return const_iterator(get_storage() + Size_);
194 }
195
196 //*************************************************************************
198 //*************************************************************************
199 const_iterator cend() const
200 {
201 return const_iterator(get_storage() + Size_);
202 }
203
204 //*************************************************************************
206 //*************************************************************************
208 {
209 return reverse_iterator(get_storage());
210 }
211
212 //*************************************************************************
214 //*************************************************************************
215 const_reverse_iterator rend() const
216 {
217 return const_reverse_iterator(get_storage());
218 }
219
220 //*************************************************************************
222 //*************************************************************************
223 const_reverse_iterator crend() const
224 {
225 return const_reverse_iterator(get_storage());
226 }
227
228 //*************************************************************************
230 //*************************************************************************
231 storage_type& operator[](int i)
232 {
233 return get_storage()[i];
234 }
235
236 //*************************************************************************
238 //*************************************************************************
239 const storage_type& operator[](int i) const
240 {
241 return get_storage()[i];
242 }
243
244 private:
245
246 //*************************************************************************
248 //*************************************************************************
249 pointer get_storage()
250 {
251 return static_cast<derived_type*>(this)->storage;
252 }
253
254 //*************************************************************************
256 //*************************************************************************
257 const_pointer get_storage() const
258 {
259 return static_cast<const derived_type*>(this)->storage;
260 }
261 }; ETL_END_PACKED
262
263 //*************************************************************************
267 //*************************************************************************
268 template <size_t Size_>
269 ETL_PACKED_CLASS(unaligned_type_storage) : public unaligned_type_common<Size_, unaligned_type_storage<Size_> >
270 {
271 public:
272
273 friend class unaligned_type_common<Size_, unaligned_type_storage<Size_> >;
274
275 protected:
276
277 //*******************************
278 unaligned_type_storage()
279 : storage()
280 {
281 }
282
283 unsigned char storage[Size_];
284 }; ETL_END_PACKED
285
286 //*************************************************************************
290 //*************************************************************************
291 template <size_t Size_>
292 ETL_PACKED_CLASS(unaligned_type_storage_ext) : public unaligned_type_common<Size_, unaligned_type_storage_ext<Size_> >
293 {
294 public:
295
296 friend class unaligned_type_common<Size_, unaligned_type_storage_ext<Size_> >;
297
298 protected:
299
300 //*******************************
301 unaligned_type_storage_ext(unsigned char* storage_)
302 : storage(storage_)
303 {
304 }
305
306 //*******************************
307 unaligned_type_storage_ext(const unaligned_type_storage_ext<Size_>& other)
308 : storage(other.storage)
309 {
310 }
311
312 //*******************************
313 unaligned_type_storage_ext& operator =(const unaligned_type_storage_ext<Size_>& other)
314 {
315 storage = other.storage;
316
317 return *this;
318 }
319
320 unsigned char* storage;
321 }; ETL_END_PACKED
322
323 //*************************************************************************
325 //*************************************************************************
326 template <size_t Size_, int Endian_, bool Is_Integral>
328
329 //*************************************************************************
332 //*************************************************************************
333 template <size_t Size_, int Endian_>
334 ETL_PACKED_CLASS(unaligned_copy)<Size_, Endian_, true>
335 {
336 public:
337
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;
341
342 //*******************************
343 template <typename T>
344 static void copy_value_to_store(const T& value, pointer store)
345 {
346 memcpy(store, &value, Size_);
347
348#if ETL_HAS_CONSTEXPR_ENDIANESS
349 if ETL_IF_CONSTEXPR(Endian_ == etl::endianness::value())
350#else
351 if (Endian_ != etl::endianness::value())
352#endif
353 {
354 etl::reverse(store, store + Size_);
355 }
356 }
357
358 //*******************************
359 template <typename T>
360 static void copy_store_to_value(const_pointer store, T& value)
361 {
362 memcpy(&value, store, Size_);
363
364#if ETL_HAS_CONSTEXPR_ENDIANESS
365 if ETL_IF_CONSTEXPR(Endian == etl::endianness::value())
366#else
367 if (Endian_ != etl::endianness::value())
368#endif
369 {
370 value = etl::reverse_bytes(value);
371 }
372 }
373
374 //*******************************
375 static void copy_store_to_store(const_pointer src, int endian_src, pointer dst)
376 {
377 memcpy(dst, src, Size_);
378
379 if (Endian_ != endian_src)
380 {
381 etl::reverse(dst, dst + Size_);
382 }
383 }
384 }; ETL_END_PACKED
385
386 //*************************************************************************
389 //*************************************************************************
390 template <size_t Size_, int Endian_>
391 ETL_PACKED_CLASS(unaligned_copy)<Size_, Endian_, false>
392 {
393 public:
394
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;
398
399 //*******************************
400 template <typename T>
401 static void copy_value_to_store(const T& value, pointer store)
402 {
403 memcpy(store, &value, Size_);
404
405#if ETL_HAS_CONSTEXPR_ENDIANESS
406 if ETL_IF_CONSTEXPR(Endian_ == etl::endianness::value())
407#else
408 if (Endian_ != etl::endianness::value())
409#endif
410 {
411 etl::reverse(store, store + Size_);
412 }
413 }
414
415 //*******************************
416 template <typename T>
417 static void copy_store_to_value(const_pointer store, T& value)
418 {
419 memcpy(&value, store, Size_);
420
421#if ETL_HAS_CONSTEXPR_ENDIANESS
422 if ETL_IF_CONSTEXPR(Endian == etl::endianness::value())
423#else
424 if (Endian_ != etl::endianness::value())
425#endif
426 {
427 etl::reverse(reinterpret_cast<pointer>(&value), reinterpret_cast<pointer>(&value) + Size_);
428 }
429 }
430
431 //*******************************
432 static void copy_store_to_store(const_pointer src, int endian_src, pointer dst)
433 {
434 memcpy(dst, src, Size_);
435
436 if (Endian_ != endian_src)
437 {
438 etl::reverse(dst, dst + Size_);
439 }
440 }
441 }; ETL_END_PACKED
442 }
443
444 //*************************************************************************
449 //*************************************************************************
450 template <typename T, int Endian_>
451 ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage<sizeof(T)>
452 {
453 public:
454
455 ETL_STATIC_ASSERT(etl::is_integral<T>::value || etl::is_floating_point<T>::value, "Unaligned type must be integral or floating point");
456
457 typedef T value_type;
458
459 typedef private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;
460
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;
468
469 static ETL_CONSTANT int Endian = Endian_;
470 static ETL_CONSTANT size_t Size = sizeof(T);
471
472 //*************************************************************************
474 //*************************************************************************
475 unaligned_type()
476 {
477 }
478
479 //*************************************************************************
481 //*************************************************************************
482 unaligned_type(T value)
483 {
484 unaligned_copy::copy_value_to_store(value, this->storage);
485 }
486
487 //*************************************************************************
489 //*************************************************************************
490 unaligned_type(const void* address)
491 {
492 etl::copy_n(reinterpret_cast<const char*>(address), sizeof(T), this->storage);
493 }
494
495 //*************************************************************************
497 //*************************************************************************
498 unaligned_type(const void* address, size_t buffer_size)
499 {
500 ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::unaligned_type_buffer_size));
501
502 etl::copy_n(reinterpret_cast<const char*>(address), sizeof(T), this->storage);
503 }
504
505 //*************************************************************************
507 //*************************************************************************
508 unaligned_type(const unaligned_type<T, Endian>& other)
509 {
510 unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);
511 }
512
513 //*************************************************************************
515 //*************************************************************************
516 template <int Endian_Other>
517 unaligned_type(const unaligned_type<T, Endian_Other>& other)
518 {
519 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
520 }
521
522 //*************************************************************************
524 //*************************************************************************
525 unaligned_type& operator =(T value)
526 {
527 unaligned_copy::copy_value_to_store(value, this->storage);
528
529 return *this;
530 }
531
532 //*************************************************************************
534 //*************************************************************************
535 unaligned_type& operator =(const unaligned_type<T, Endian_>& other)
536 {
537 unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage);
538
539 return *this;
540 }
541
542 //*************************************************************************
544 //*************************************************************************
545 template <int Endian_Other>
546 unaligned_type& operator =(const unaligned_type<T, Endian_Other>& other)
547 {
548 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
549
550 return *this;
551 }
552
553 //*************************************************************************
555 //*************************************************************************
556 operator T() const
557 {
558 T value = T();
559
560 unaligned_copy::copy_store_to_value(this->storage, value);
561
562 return value;
563 }
564
565 //*************************************************************************
567 //*************************************************************************
568 T value() const
569 {
570 T value = T();
571
572 unaligned_copy::copy_store_to_value(this->storage, value);
573
574 return value;
575 }
576 }; ETL_END_PACKED
577
578 template <typename T, int Endian_>
579 ETL_CONSTANT int unaligned_type<T, Endian_>::Endian;
580
581 template <typename T, int Endian_>
582 ETL_CONSTANT size_t unaligned_type<T, Endian_>::Size;
583
584 //*************************************************************************
590 //*************************************************************************
591 template <typename T, int Endian_>
592 ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>
593 {
594 public:
595
596 ETL_STATIC_ASSERT(etl::is_integral<T>::value || etl::is_floating_point<T>::value, "Unaligned type must be integral or floating point");
597
598 template <typename U, int Endian_Other>
599 friend class unaligned_type_ext;
600
601 typedef T value_type;
602
603 typedef private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true> unaligned_copy;
604
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;
612
613 static ETL_CONSTANT int Endian = Endian_;
614 static ETL_CONSTANT size_t Size = sizeof(T);
615
616 //*************************************************************************
618 //*************************************************************************
619 unaligned_type_ext(pointer storage_)
620 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
621 {
622 }
623
624 //*************************************************************************
626 //*************************************************************************
627 unaligned_type_ext(T value, pointer storage_)
628 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
629 {
630 unaligned_copy::copy_value_to_store(value, this->storage);
631 }
632
633 //*************************************************************************
635 //*************************************************************************
636 template <int Endian_Other>
637 unaligned_type_ext(const unaligned_type_ext<T, Endian_Other>& other, pointer storage_)
638 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
639 {
640 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
641 }
642
643#if ETL_USING_CPP11
644 //*************************************************************************
646 //*************************************************************************
647 unaligned_type_ext(unaligned_type_ext<T, Endian>&& other)
648 : private_unaligned_type::unaligned_type_storage_ext<Size>(other.storage)
649 {
650 other.storage = ETL_NULLPTR;
651 }
652
653 //*************************************************************************
655 //*************************************************************************
656 template <int Endian_Other>
657 unaligned_type_ext(unaligned_type_ext<T, Endian_Other>&& other)
658 : private_unaligned_type::unaligned_type_storage_ext<Size>(other.storage)
659 {
660 // If we're constructing from a different endianess then we need to reverse the data order.
661 if (Endian != Endian_Other)
662 {
663 etl::reverse(this->begin(), this->end());
664 }
665
666 other.storage = ETL_NULLPTR;
667 }
668#endif
669
670 //*************************************************************************
672 //*************************************************************************
673 unaligned_type_ext& operator =(T value)
674 {
675 unaligned_copy::copy_value_to_store(value, this->storage);
676
677 return *this;
678 }
679
680 //*************************************************************************
682 //*************************************************************************
683 unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian>& other)
684 {
685 unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage);
686
687 return *this;
688 }
689
690 //*************************************************************************
692 //*************************************************************************
693 template <int Endian_Other>
694 unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian_Other>& other)
695 {
696 unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage);
697
698 return *this;
699 }
700
701#if ETL_USING_CPP11
702 //*************************************************************************
704 //*************************************************************************
705 unaligned_type_ext& operator =(unaligned_type_ext<T, Endian>&& other)
706 {
707 this->storage = other.storage;
708 other.storage = ETL_NULLPTR;
709
710 return *this;
711 }
712
713 //*************************************************************************
715 //*************************************************************************
716 template <int Endian_Other>
717 unaligned_type_ext& operator =(unaligned_type_ext<T, Endian_Other>&& other)
718 {
719 this->storage = other.storage;
720
721 // If we're assigning from a different endianess then we need to reverse the data order.
722 if (Endian != Endian_Other)
723 {
724 etl::reverse(this->begin(), this->end());
725 }
726
727 other.storage = ETL_NULLPTR;
728
729 return *this;
730 }
731#endif
732
733 //*************************************************************************
735 //*************************************************************************
736 operator T() const
737 {
738 T value = T();
739
740 unaligned_copy::copy_store_to_value(this->storage, value);
741
742 return value;
743 }
744
745 //*************************************************************************
747 //*************************************************************************
748 T value() const
749 {
750 T value = T();
751
752 unaligned_copy::copy_store_to_value(this->storage, value);
753
754 return value;
755 }
756
757 //*************************************************************************
759 //*************************************************************************
760 void set_storage(pointer storage_)
761 {
762 this->storage = storage_;
763 }
764
765 private:
766
767 unaligned_type_ext() ETL_DELETE;
768
769 }; ETL_END_PACKED
770
771 template <typename T, int Endian_>
772 ETL_CONSTANT int unaligned_type_ext<T, Endian_>::Endian;
773
774 template <typename T, int Endian_>
775 ETL_CONSTANT size_t unaligned_type_ext<T, Endian_>::Size;
776
777#if ETL_HAS_CONSTEXPR_ENDIANNESS
778 // Host order
779 typedef unaligned_type<char, etl::endianness::value()> host_char_t;
780 typedef unaligned_type<signed char, etl::endianness::value()> host_schar_t;
781 typedef unaligned_type<unsigned char, etl::endianness::value()> host_uchar_t;
782 typedef unaligned_type<short, etl::endianness::value()> host_short_t;
783 typedef unaligned_type<unsigned short, etl::endianness::value()> host_ushort_t;
784 typedef unaligned_type<int, etl::endianness::value()> host_int_t;
785 typedef unaligned_type<unsigned int, etl::endianness::value()> host_uint_t;
786 typedef unaligned_type<long, etl::endianness::value()> host_long_t;
787 typedef unaligned_type<unsigned long, etl::endianness::value()> host_ulong_t;
788 typedef unaligned_type<long long, etl::endianness::value()> host_long_long_t;
789 typedef unaligned_type<unsigned long long, etl::endianness::value()> host_ulong_long_t;
790#if ETL_USING_8BIT_TYPES
791 typedef unaligned_type<int8_t, etl::endianness::value()> host_int8_t;
792 typedef unaligned_type<uint8_t, etl::endianness::value()> host_uint8_t;
793#endif
794 typedef unaligned_type<int16_t, etl::endianness::value()> host_int16_t;
795 typedef unaligned_type<uint16_t, etl::endianness::value()> host_uint16_t;
796 typedef unaligned_type<int32_t, etl::endianness::value()> host_int32_t;
797 typedef unaligned_type<uint32_t, etl::endianness::value()> host_uint32_t;
798#if ETL_USING_64BIT_TYPES
799 typedef unaligned_type<int64_t, etl::endianness::value()> host_int64_t;
800 typedef unaligned_type<uint64_t, etl::endianness::value()> host_uint64_t;
801#endif
802 typedef unaligned_type<float, etl::endianness::value()> host_float_t;
803 typedef unaligned_type<double, etl::endianness::value()> host_double_t;
804 typedef unaligned_type<long double, etl::endianness::value()> host_long_double_t;
805#endif
806
807 // Little Endian
808 typedef unaligned_type<char, etl::endian::little> le_char_t;
809 typedef unaligned_type<signed char, etl::endian::little> le_schar_t;
810 typedef unaligned_type<unsigned char, etl::endian::little> le_uchar_t;
811 typedef unaligned_type<short, etl::endian::little> le_short_t;
812 typedef unaligned_type<unsigned short, etl::endian::little> le_ushort_t;
813 typedef unaligned_type<int, etl::endian::little> le_int_t;
814 typedef unaligned_type<unsigned int, etl::endian::little> le_uint_t;
815 typedef unaligned_type<long, etl::endian::little> le_long_t;
816 typedef unaligned_type<unsigned long, etl::endian::little> le_ulong_t;
817 typedef unaligned_type<long long, etl::endian::little> le_long_long_t;
818 typedef unaligned_type<unsigned long long, etl::endian::little> le_ulong_long_t;
819#if ETL_USING_8BIT_TYPES
820 typedef unaligned_type<int8_t, etl::endian::little> le_int8_t;
821 typedef unaligned_type<uint8_t, etl::endian::little> le_uint8_t;
822#endif
823 typedef unaligned_type<int16_t, etl::endian::little> le_int16_t;
824 typedef unaligned_type<uint16_t, etl::endian::little> le_uint16_t;
825 typedef unaligned_type<int32_t, etl::endian::little> le_int32_t;
826 typedef unaligned_type<uint32_t, etl::endian::little> le_uint32_t;
827#if ETL_USING_64BIT_TYPES
828 typedef unaligned_type<int64_t, etl::endian::little> le_int64_t;
829 typedef unaligned_type<uint64_t, etl::endian::little> le_uint64_t;
830#endif
831 typedef unaligned_type<float, etl::endian::little> le_float_t;
832 typedef unaligned_type<double, etl::endian::little> le_double_t;
833 typedef unaligned_type<long double, etl::endian::little> le_long_double_t;
834
835 // Big Endian
836 typedef unaligned_type<char, etl::endian::big> be_char_t;
837 typedef unaligned_type<signed char, etl::endian::big> be_schar_t;
838 typedef unaligned_type<unsigned char, etl::endian::big> be_uchar_t;
839 typedef unaligned_type<short, etl::endian::big> be_short_t;
840 typedef unaligned_type<unsigned short, etl::endian::big> be_ushort_t;
841 typedef unaligned_type<int, etl::endian::big> be_int_t;
842 typedef unaligned_type<unsigned int, etl::endian::big> be_uint_t;
843 typedef unaligned_type<long, etl::endian::big> be_long_t;
844 typedef unaligned_type<unsigned long, etl::endian::big> be_ulong_t;
845 typedef unaligned_type<long long, etl::endian::big> be_long_long_t;
846 typedef unaligned_type<unsigned long long, etl::endian::big> be_ulong_long_t;
847#if ETL_USING_8BIT_TYPES
848 typedef unaligned_type<int8_t, etl::endian::big> be_int8_t;
849 typedef unaligned_type<uint8_t, etl::endian::big> be_uint8_t;
850#endif
851 typedef unaligned_type<int16_t, etl::endian::big> be_int16_t;
852 typedef unaligned_type<uint16_t, etl::endian::big> be_uint16_t;
853 typedef unaligned_type<int32_t, etl::endian::big> be_int32_t;
854 typedef unaligned_type<uint32_t, etl::endian::big> be_uint32_t;
855#if ETL_USING_64BIT_TYPES
856 typedef unaligned_type<int64_t, etl::endian::big> be_int64_t;
857 typedef unaligned_type<uint64_t, etl::endian::big> be_uint64_t;
858#endif
859 typedef unaligned_type<float, etl::endian::big> be_float_t;
860 typedef unaligned_type<double, etl::endian::big> be_double_t;
861 typedef unaligned_type<long double, etl::endian::big> be_long_double_t;
862
863 // Network Order
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
876 typedef be_int8_t net_int8_t;
877 typedef be_uint8_t net_uint8_t;
878#endif
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;
886#endif
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;
890
891#if ETL_USING_CPP11
892 template <typename T, int Endian>
893 using unaligned_type_t = typename etl::unaligned_type<T, Endian>::type;
894#endif
895
896#if ETL_USING_CPP17
897 template <typename T, int Endian>
898 constexpr size_t unaligned_type_v = etl::unaligned_type<T, Endian>::Size;
899#endif
900
901#if ETL_HAS_CONSTEXPR_ENDIANNESS
902 // Host order
903 typedef unaligned_type_ext<char, etl::endianness::value()> host_char_ext_t;
904 typedef unaligned_type_ext<signed char, etl::endianness::value()> host_schar_ext_t;
905 typedef unaligned_type_ext<unsigned char, etl::endianness::value()> host_uchar_ext_t;
906 typedef unaligned_type_ext<short, etl::endianness::value()> host_short_ext_t;
907 typedef unaligned_type_ext<unsigned short, etl::endianness::value()> host_ushort_ext_t;
908 typedef unaligned_type_ext<int, etl::endianness::value()> host_int_ext_t;
909 typedef unaligned_type_ext<unsigned int, etl::endianness::value()> host_uint_ext_t;
910 typedef unaligned_type_ext<long, etl::endianness::value()> host_long_ext_t;
911 typedef unaligned_type_ext<unsigned long, etl::endianness::value()> host_ulong_ext_t;
912 typedef unaligned_type_ext<long long, etl::endianness::value()> host_long_long_ext_t;
913 typedef unaligned_type_ext<unsigned long long, etl::endianness::value()> host_ulong_long_ext_t;
914#if ETL_USING_8BIT_TYPES
915 typedef unaligned_type_ext<int8_t, etl::endianness::value()> host_int8_ext_t;
916 typedef unaligned_type_ext<uint8_t, etl::endianness::value()> host_uint8_ext_t;
917#endif
918 typedef unaligned_type_ext<int16_t, etl::endianness::value()> host_int16_ext_t;
919 typedef unaligned_type_ext<uint16_t, etl::endianness::value()> host_uint16_ext_t;
920 typedef unaligned_type_ext<int32_t, etl::endianness::value()> host_int32_ext_t;
921 typedef unaligned_type_ext<uint32_t, etl::endianness::value()> host_uint32_ext_t;
922#if ETL_USING_64BIT_TYPES
923 typedef unaligned_type_ext<int64_t, etl::endianness::value()> host_int64_ext_t;
924 typedef unaligned_type_ext<uint64_t, etl::endianness::value()> host_uint64_ext_t;
925#endif
926 typedef unaligned_type_ext<float, etl::endianness::value()> host_float_ext_t;
927 typedef unaligned_type_ext<double, etl::endianness::value()> host_double_ext_t;
928 typedef unaligned_type_ext<long double, etl::endianness::value()> host_long_double_ext_t;
929#endif
930
931 // Little Endian
932 typedef unaligned_type_ext<char, etl::endian::little> le_char_ext_t;
933 typedef unaligned_type_ext<signed char, etl::endian::little> le_schar_ext_t;
934 typedef unaligned_type_ext<unsigned char, etl::endian::little> le_uchar_ext_t;
935 typedef unaligned_type_ext<short, etl::endian::little> le_short_ext_t;
936 typedef unaligned_type_ext<unsigned short, etl::endian::little> le_ushort_ext_t;
937 typedef unaligned_type_ext<int, etl::endian::little> le_int_ext_t;
938 typedef unaligned_type_ext<unsigned int, etl::endian::little> le_uint_ext_t;
939 typedef unaligned_type_ext<long, etl::endian::little> le_long_ext_t;
940 typedef unaligned_type_ext<unsigned long, etl::endian::little> le_ulong_ext_t;
941 typedef unaligned_type_ext<long long, etl::endian::little> le_long_long_ext_t;
942 typedef unaligned_type_ext<unsigned long long, etl::endian::little> le_ulong_long_ext_t;
943 #if ETL_USING_8BIT_TYPES
944 typedef unaligned_type_ext<int8_t, etl::endian::little> le_int8_ext_t;
945 typedef unaligned_type_ext<uint8_t, etl::endian::little> le_uint8_ext_t;
946 #endif
947 typedef unaligned_type_ext<int16_t, etl::endian::little> le_int16_ext_t;
948 typedef unaligned_type_ext<uint16_t, etl::endian::little> le_uint16_ext_t;
949 typedef unaligned_type_ext<int32_t, etl::endian::little> le_int32_ext_t;
950 typedef unaligned_type_ext<uint32_t, etl::endian::little> le_uint32_ext_t;
951 #if ETL_USING_64BIT_TYPES
952 typedef unaligned_type_ext<int64_t, etl::endian::little> le_int64_ext_t;
953 typedef unaligned_type_ext<uint64_t, etl::endian::little> le_uint64_ext_t;
954 #endif
955 typedef unaligned_type_ext<float, etl::endian::little> le_float_ext_t;
956 typedef unaligned_type_ext<double, etl::endian::little> le_double_ext_t;
957 typedef unaligned_type_ext<long double, etl::endian::little> le_long_double_ext_t;
958
959 // Big Endian
960 typedef unaligned_type_ext<char, etl::endian::big> be_char_ext_t;
961 typedef unaligned_type_ext<signed char, etl::endian::big> be_schar_ext_t;
962 typedef unaligned_type_ext<unsigned char, etl::endian::big> be_uchar_ext_t;
963 typedef unaligned_type_ext<short, etl::endian::big> be_short_ext_t;
964 typedef unaligned_type_ext<unsigned short, etl::endian::big> be_ushort_ext_t;
965 typedef unaligned_type_ext<int, etl::endian::big> be_int_ext_t;
966 typedef unaligned_type_ext<unsigned int, etl::endian::big> be_uint_ext_t;
967 typedef unaligned_type_ext<long, etl::endian::big> be_long_ext_t;
968 typedef unaligned_type_ext<unsigned long, etl::endian::big> be_ulong_ext_t;
969 typedef unaligned_type_ext<long long, etl::endian::big> be_long_long_ext_t;
970 typedef unaligned_type_ext<unsigned long long, etl::endian::big> be_ulong_long_ext_t;
971 #if ETL_USING_8BIT_TYPES
972 typedef unaligned_type_ext<int8_t, etl::endian::big> be_int8_ext_t;
973 typedef unaligned_type_ext<uint8_t, etl::endian::big> be_uint8_ext_t;
974 #endif
975 typedef unaligned_type_ext<int16_t, etl::endian::big> be_int16_ext_t;
976 typedef unaligned_type_ext<uint16_t, etl::endian::big> be_uint16_ext_t;
977 typedef unaligned_type_ext<int32_t, etl::endian::big> be_int32_ext_t;
978 typedef unaligned_type_ext<uint32_t, etl::endian::big> be_uint32_ext_t;
979 #if ETL_USING_64BIT_TYPES
980 typedef unaligned_type_ext<int64_t, etl::endian::big> be_int64_ext_t;
981 typedef unaligned_type_ext<uint64_t, etl::endian::big> be_uint64_ext_t;
982 #endif
983 typedef unaligned_type_ext<float, etl::endian::big> be_float_ext_t;
984 typedef unaligned_type_ext<double, etl::endian::big> be_double_ext_t;
985 typedef unaligned_type_ext<long double, etl::endian::big> be_long_double_ext_t;
986
987 // Network Order
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
1000 typedef be_int8_ext_t net_int8_ext_t;
1001 typedef be_uint8_ext_t net_uint8_ext_t;
1002#endif
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;
1010#endif
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;
1014
1015#if ETL_USING_CPP11
1016 template <typename T, int Endian>
1017 using unaligned_type_ext_t = typename etl::unaligned_type_ext<T, Endian>::type;
1018#endif
1019
1020#if ETL_USING_CPP17
1021 template <typename T, int Endian>
1022 constexpr size_t unaligned_type_ext_t_v = etl::unaligned_type_ext<T, Endian>::Size;
1023#endif
1024}
1025
1026
1027
1028#endif
Unaligned copy.
Definition unaligned_type.h:327
Definition iterator.h:228
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
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition exception.h:69
Definition exception.h:47
is_floating_point
Definition type_traits_generator.h:1094
bitset_ext
Definition absolute.h:39
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_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:451
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
ETL_PACKED_CLASS(unaligned_type_common)
Definition unaligned_type.h:88