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{
66
67 //***************************************************************************
69 //***************************************************************************
71 {
72 public:
73
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
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 //*************************************************************************
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 {
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 {
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_>
270 {
271 public:
272
274
275 protected:
276
277 //*******************************
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 , public private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true>
453 {
454 public:
455
456 ETL_STATIC_ASSERT(etl::is_integral<T>::value || etl::is_floating_point<T>::value, "Unaligned type must be integral or floating point");
457
458 typedef T value_type;
459
460 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::storage_type storage_type;
461 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::pointer pointer;
462 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_pointer const_pointer;
463 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::iterator iterator;
464 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_iterator const_iterator;
465 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::reverse_iterator reverse_iterator;
466 typedef typename private_unaligned_type::unaligned_type_storage<sizeof(T)>::const_reverse_iterator const_reverse_iterator;
467
468 static ETL_CONSTANT int Endian = Endian_;
469 static ETL_CONSTANT size_t Size = sizeof(T);
470
471 //*************************************************************************
473 //*************************************************************************
474 unaligned_type()
475 {
476 }
477
478 //*************************************************************************
480 //*************************************************************************
481 unaligned_type(T value)
482 {
483 this->copy_value_to_store(value, this->storage);
484 }
485
486 //*************************************************************************
488 //*************************************************************************
489 unaligned_type(const void* address)
490 {
491 etl::copy_n(reinterpret_cast<const char*>(address), sizeof(T), this->storage);
492 }
493
494 //*************************************************************************
496 //*************************************************************************
497 unaligned_type(const void* address, size_t buffer_size)
498 {
499 ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::unaligned_type_buffer_size));
500
501 etl::copy_n(reinterpret_cast<const char*>(address), sizeof(T), this->storage);
502 }
503
504 //*************************************************************************
506 //*************************************************************************
507 unaligned_type(const unaligned_type<T, Endian>& other)
508 {
509 this->copy_store_to_store(other.data(), Endian, this->storage);
510 }
511
512 //*************************************************************************
514 //*************************************************************************
515 template <int Endian_Other>
516 unaligned_type(const unaligned_type<T, Endian_Other>& other)
517 {
518 this->copy_store_to_store(other.data(), Endian_Other, this->storage);
519 }
520
521 //*************************************************************************
523 //*************************************************************************
524 unaligned_type& operator =(T value)
525 {
526 this->copy_value_to_store(value, this->storage);
527
528 return *this;
529 }
530
531 //*************************************************************************
533 //*************************************************************************
534 unaligned_type& operator =(const unaligned_type<T, Endian_>& other)
535 {
536 this->copy_store_to_store(other.data(), Endian_, this->storage);
537
538 return *this;
539 }
540
541 //*************************************************************************
543 //*************************************************************************
544 template <int Endian_Other>
545 unaligned_type& operator =(const unaligned_type<T, Endian_Other>& other)
546 {
547 this->copy_store_to_store(other.data(), Endian_Other, this->storage);
548
549 return *this;
550 }
551
552 //*************************************************************************
554 //*************************************************************************
555 operator T() const
556 {
557 T value = T();
558
559 this->copy_store_to_value(this->storage, value);
560
561 return value;
562 }
563
564 //*************************************************************************
566 //*************************************************************************
567 T value() const
568 {
569 T value = T();
570
571 this->copy_store_to_value(this->storage, value);
572
573 return value;
574 }
575 }; ETL_END_PACKED
576
577 template <typename T, int Endian_>
578 ETL_CONSTANT int unaligned_type<T, Endian_>::Endian;
579
580 template <typename T, int Endian_>
581 ETL_CONSTANT size_t unaligned_type<T, Endian_>::Size;
582
583 //*************************************************************************
589 //*************************************************************************
590 template <typename T, int Endian_>
591 ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>
592 , public private_unaligned_type::unaligned_copy<sizeof(T), Endian_, etl::is_floating_point<T>::value ? false : true>
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 typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::storage_type storage_type;
604 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::pointer pointer;
605 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_pointer const_pointer;
606 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::iterator iterator;
607 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_iterator const_iterator;
608 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::reverse_iterator reverse_iterator;
609 typedef typename private_unaligned_type::unaligned_type_storage_ext<sizeof(T)>::const_reverse_iterator const_reverse_iterator;
610
611 static ETL_CONSTANT int Endian = Endian_;
612 static ETL_CONSTANT size_t Size = sizeof(T);
613
614 //*************************************************************************
616 //*************************************************************************
617 unaligned_type_ext(pointer storage_)
618 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
619 {
620 }
621
622 //*************************************************************************
624 //*************************************************************************
625 unaligned_type_ext(T value, pointer storage_)
626 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
627 {
628 this->copy_value_to_store(value, this->storage);
629 }
630
631 //*************************************************************************
633 //*************************************************************************
634 template <int Endian_Other>
635 unaligned_type_ext(const unaligned_type_ext<T, Endian_Other>& other, pointer storage_)
636 : private_unaligned_type::unaligned_type_storage_ext<Size>(storage_)
637 {
638 this->copy_store_to_store(other.data(), Endian_Other, this->storage);
639 }
640
641#if ETL_USING_CPP11
642 //*************************************************************************
644 //*************************************************************************
645 unaligned_type_ext(unaligned_type_ext<T, Endian>&& other)
646 : private_unaligned_type::unaligned_type_storage_ext<Size>(other.storage)
647 {
648 other.storage = ETL_NULLPTR;
649 }
650
651 //*************************************************************************
653 //*************************************************************************
654 template <int Endian_Other>
655 unaligned_type_ext(unaligned_type_ext<T, Endian_Other>&& other)
656 : private_unaligned_type::unaligned_type_storage_ext<Size>(other.storage)
657 {
658 // If we're constructing from a different endianess then we need to reverse the data order.
659 if (Endian != Endian_Other)
660 {
661 etl::reverse(this->begin(), this->end());
662 }
663
664 other.storage = ETL_NULLPTR;
665 }
666#endif
667
668 //*************************************************************************
670 //*************************************************************************
671 unaligned_type_ext& operator =(T value)
672 {
673 this->copy_value_to_store(value, this->storage);
674
675 return *this;
676 }
677
678 //*************************************************************************
680 //*************************************************************************
681 unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian>& other)
682 {
683 this->copy_store_to_store(other.data(), Endian, this->storage);
684
685 return *this;
686 }
687
688 //*************************************************************************
690 //*************************************************************************
691 template <int Endian_Other>
692 unaligned_type_ext& operator =(const unaligned_type_ext<T, Endian_Other>& other)
693 {
694 this->copy_store_to_store(other.data(), Endian_Other, this->storage);
695
696 return *this;
697 }
698
699#if ETL_USING_CPP11
700 //*************************************************************************
702 //*************************************************************************
703 unaligned_type_ext& operator =(unaligned_type_ext<T, Endian>&& other)
704 {
705 this->storage = other.storage;
706 other.storage = ETL_NULLPTR;
707
708 return *this;
709 }
710
711 //*************************************************************************
713 //*************************************************************************
714 template <int Endian_Other>
715 unaligned_type_ext& operator =(unaligned_type_ext<T, Endian_Other>&& other)
716 {
717 this->storage = other.storage;
718
719 // If we're assigning from a different endianess then we need to reverse the data order.
720 if (Endian != Endian_Other)
721 {
722 etl::reverse(this->begin(), this->end());
723 }
724
725 other.storage = ETL_NULLPTR;
726
727 return *this;
728 }
729#endif
730
731 //*************************************************************************
733 //*************************************************************************
734 operator T() const
735 {
736 T value = T();
737
738 this->copy_store_to_value(this->storage, value);
739
740 return value;
741 }
742
743 //*************************************************************************
745 //*************************************************************************
746 T value() const
747 {
748 T value = T();
749
750 this->copy_store_to_value(this->storage, value);
751
752 return value;
753 }
754
755 //*************************************************************************
757 //*************************************************************************
758 void set_storage(pointer storage_)
759 {
760 this->storage = storage_;
761 }
762
763 private:
764
765 unaligned_type_ext() ETL_DELETE;
766
767 }; ETL_END_PACKED
768
769 template <typename T, int Endian_>
770 ETL_CONSTANT int unaligned_type_ext<T, Endian_>::Endian;
771
772 template <typename T, int Endian_>
773 ETL_CONSTANT size_t unaligned_type_ext<T, Endian_>::Size;
774
775#if ETL_HAS_CONSTEXPR_ENDIANNESS
776 // Host order
777 typedef unaligned_type<char, etl::endianness::value()> host_char_t;
778 typedef unaligned_type<signed char, etl::endianness::value()> host_schar_t;
779 typedef unaligned_type<unsigned char, etl::endianness::value()> host_uchar_t;
780 typedef unaligned_type<short, etl::endianness::value()> host_short_t;
781 typedef unaligned_type<unsigned short, etl::endianness::value()> host_ushort_t;
782 typedef unaligned_type<int, etl::endianness::value()> host_int_t;
783 typedef unaligned_type<unsigned int, etl::endianness::value()> host_uint_t;
784 typedef unaligned_type<long, etl::endianness::value()> host_long_t;
785 typedef unaligned_type<unsigned long, etl::endianness::value()> host_ulong_t;
786 typedef unaligned_type<long long, etl::endianness::value()> host_long_long_t;
787 typedef unaligned_type<unsigned long long, etl::endianness::value()> host_ulong_long_t;
788#if ETL_USING_8BIT_TYPES
789 typedef unaligned_type<int8_t, etl::endianness::value()> host_int8_t;
790 typedef unaligned_type<uint8_t, etl::endianness::value()> host_uint8_t;
791#endif
792 typedef unaligned_type<int16_t, etl::endianness::value()> host_int16_t;
793 typedef unaligned_type<uint16_t, etl::endianness::value()> host_uint16_t;
794 typedef unaligned_type<int32_t, etl::endianness::value()> host_int32_t;
795 typedef unaligned_type<uint32_t, etl::endianness::value()> host_uint32_t;
796#if ETL_USING_64BIT_TYPES
797 typedef unaligned_type<int64_t, etl::endianness::value()> host_int64_t;
798 typedef unaligned_type<uint64_t, etl::endianness::value()> host_uint64_t;
799#endif
800 typedef unaligned_type<float, etl::endianness::value()> host_float_t;
801 typedef unaligned_type<double, etl::endianness::value()> host_double_t;
802 typedef unaligned_type<long double, etl::endianness::value()> host_long_double_t;
803#endif
804
805 // Little Endian
806 typedef unaligned_type<char, etl::endian::little> le_char_t;
807 typedef unaligned_type<signed char, etl::endian::little> le_schar_t;
808 typedef unaligned_type<unsigned char, etl::endian::little> le_uchar_t;
809 typedef unaligned_type<short, etl::endian::little> le_short_t;
810 typedef unaligned_type<unsigned short, etl::endian::little> le_ushort_t;
811 typedef unaligned_type<int, etl::endian::little> le_int_t;
812 typedef unaligned_type<unsigned int, etl::endian::little> le_uint_t;
813 typedef unaligned_type<long, etl::endian::little> le_long_t;
814 typedef unaligned_type<unsigned long, etl::endian::little> le_ulong_t;
815 typedef unaligned_type<long long, etl::endian::little> le_long_long_t;
816 typedef unaligned_type<unsigned long long, etl::endian::little> le_ulong_long_t;
817#if ETL_USING_8BIT_TYPES
818 typedef unaligned_type<int8_t, etl::endian::little> le_int8_t;
819 typedef unaligned_type<uint8_t, etl::endian::little> le_uint8_t;
820#endif
821 typedef unaligned_type<int16_t, etl::endian::little> le_int16_t;
822 typedef unaligned_type<uint16_t, etl::endian::little> le_uint16_t;
823 typedef unaligned_type<int32_t, etl::endian::little> le_int32_t;
824 typedef unaligned_type<uint32_t, etl::endian::little> le_uint32_t;
825#if ETL_USING_64BIT_TYPES
826 typedef unaligned_type<int64_t, etl::endian::little> le_int64_t;
827 typedef unaligned_type<uint64_t, etl::endian::little> le_uint64_t;
828#endif
829 typedef unaligned_type<float, etl::endian::little> le_float_t;
830 typedef unaligned_type<double, etl::endian::little> le_double_t;
831 typedef unaligned_type<long double, etl::endian::little> le_long_double_t;
832
833 // Big Endian
834 typedef unaligned_type<char, etl::endian::big> be_char_t;
835 typedef unaligned_type<signed char, etl::endian::big> be_schar_t;
836 typedef unaligned_type<unsigned char, etl::endian::big> be_uchar_t;
837 typedef unaligned_type<short, etl::endian::big> be_short_t;
838 typedef unaligned_type<unsigned short, etl::endian::big> be_ushort_t;
839 typedef unaligned_type<int, etl::endian::big> be_int_t;
840 typedef unaligned_type<unsigned int, etl::endian::big> be_uint_t;
841 typedef unaligned_type<long, etl::endian::big> be_long_t;
842 typedef unaligned_type<unsigned long, etl::endian::big> be_ulong_t;
843 typedef unaligned_type<long long, etl::endian::big> be_long_long_t;
844 typedef unaligned_type<unsigned long long, etl::endian::big> be_ulong_long_t;
845#if ETL_USING_8BIT_TYPES
846 typedef unaligned_type<int8_t, etl::endian::big> be_int8_t;
847 typedef unaligned_type<uint8_t, etl::endian::big> be_uint8_t;
848#endif
849 typedef unaligned_type<int16_t, etl::endian::big> be_int16_t;
850 typedef unaligned_type<uint16_t, etl::endian::big> be_uint16_t;
851 typedef unaligned_type<int32_t, etl::endian::big> be_int32_t;
852 typedef unaligned_type<uint32_t, etl::endian::big> be_uint32_t;
853#if ETL_USING_64BIT_TYPES
854 typedef unaligned_type<int64_t, etl::endian::big> be_int64_t;
855 typedef unaligned_type<uint64_t, etl::endian::big> be_uint64_t;
856#endif
857 typedef unaligned_type<float, etl::endian::big> be_float_t;
858 typedef unaligned_type<double, etl::endian::big> be_double_t;
859 typedef unaligned_type<long double, etl::endian::big> be_long_double_t;
860
861 // Network Order
862 typedef be_char_t net_char_t;
863 typedef be_schar_t net_schar_t;
864 typedef be_uchar_t net_uchar_t;
865 typedef be_short_t net_short_t;
866 typedef be_ushort_t net_ushort_t;
867 typedef be_int_t net_int_t;
868 typedef be_uint_t net_uint_t;
869 typedef be_long_t net_long_t;
870 typedef be_ulong_t net_ulong_t;
871 typedef be_long_long_t net_long_long_t;
872 typedef be_ulong_long_t net_ulong_long_t;
873#if ETL_USING_8BIT_TYPES
874 typedef be_int8_t net_int8_t;
875 typedef be_uint8_t net_uint8_t;
876#endif
877 typedef be_int16_t net_int16_t;
878 typedef be_uint16_t net_uint16_t;
879 typedef be_int32_t net_int32_t;
880 typedef be_uint32_t net_uint32_t;
881#if ETL_USING_64BIT_TYPES
882 typedef be_int64_t net_int64_t;
883 typedef be_uint64_t net_uint64_t;
884#endif
885 typedef be_float_t net_float_t;
886 typedef be_double_t net_double_t;
887 typedef be_long_double_t net_long_double_t;
888
889#if ETL_USING_CPP11
890 template <typename T, int Endian>
891 using unaligned_type_t = typename etl::unaligned_type<T, Endian>::type;
892#endif
893
894#if ETL_USING_CPP17
895 template <typename T, int Endian>
896 constexpr size_t unaligned_type_v = etl::unaligned_type<T, Endian>::Size;
897#endif
898
899#if ETL_HAS_CONSTEXPR_ENDIANNESS
900 // Host order
901 typedef unaligned_type_ext<char, etl::endianness::value()> host_char_ext_t;
902 typedef unaligned_type_ext<signed char, etl::endianness::value()> host_schar_ext_t;
903 typedef unaligned_type_ext<unsigned char, etl::endianness::value()> host_uchar_ext_t;
904 typedef unaligned_type_ext<short, etl::endianness::value()> host_short_ext_t;
905 typedef unaligned_type_ext<unsigned short, etl::endianness::value()> host_ushort_ext_t;
906 typedef unaligned_type_ext<int, etl::endianness::value()> host_int_ext_t;
907 typedef unaligned_type_ext<unsigned int, etl::endianness::value()> host_uint_ext_t;
908 typedef unaligned_type_ext<long, etl::endianness::value()> host_long_ext_t;
909 typedef unaligned_type_ext<unsigned long, etl::endianness::value()> host_ulong_ext_t;
910 typedef unaligned_type_ext<long long, etl::endianness::value()> host_long_long_ext_t;
911 typedef unaligned_type_ext<unsigned long long, etl::endianness::value()> host_ulong_long_ext_t;
912#if ETL_USING_8BIT_TYPES
913 typedef unaligned_type_ext<int8_t, etl::endianness::value()> host_int8_ext_t;
914 typedef unaligned_type_ext<uint8_t, etl::endianness::value()> host_uint8_ext_t;
915#endif
916 typedef unaligned_type_ext<int16_t, etl::endianness::value()> host_int16_ext_t;
917 typedef unaligned_type_ext<uint16_t, etl::endianness::value()> host_uint16_ext_t;
918 typedef unaligned_type_ext<int32_t, etl::endianness::value()> host_int32_ext_t;
919 typedef unaligned_type_ext<uint32_t, etl::endianness::value()> host_uint32_ext_t;
920#if ETL_USING_64BIT_TYPES
921 typedef unaligned_type_ext<int64_t, etl::endianness::value()> host_int64_ext_t;
922 typedef unaligned_type_ext<uint64_t, etl::endianness::value()> host_uint64_ext_t;
923#endif
924 typedef unaligned_type_ext<float, etl::endianness::value()> host_float_ext_t;
925 typedef unaligned_type_ext<double, etl::endianness::value()> host_double_ext_t;
926 typedef unaligned_type_ext<long double, etl::endianness::value()> host_long_double_ext_t;
927#endif
928
929 // Little Endian
930 typedef unaligned_type_ext<char, etl::endian::little> le_char_ext_t;
931 typedef unaligned_type_ext<signed char, etl::endian::little> le_schar_ext_t;
932 typedef unaligned_type_ext<unsigned char, etl::endian::little> le_uchar_ext_t;
933 typedef unaligned_type_ext<short, etl::endian::little> le_short_ext_t;
934 typedef unaligned_type_ext<unsigned short, etl::endian::little> le_ushort_ext_t;
935 typedef unaligned_type_ext<int, etl::endian::little> le_int_ext_t;
936 typedef unaligned_type_ext<unsigned int, etl::endian::little> le_uint_ext_t;
937 typedef unaligned_type_ext<long, etl::endian::little> le_long_ext_t;
938 typedef unaligned_type_ext<unsigned long, etl::endian::little> le_ulong_ext_t;
939 typedef unaligned_type_ext<long long, etl::endian::little> le_long_long_ext_t;
940 typedef unaligned_type_ext<unsigned long long, etl::endian::little> le_ulong_long_ext_t;
941 #if ETL_USING_8BIT_TYPES
942 typedef unaligned_type_ext<int8_t, etl::endian::little> le_int8_ext_t;
943 typedef unaligned_type_ext<uint8_t, etl::endian::little> le_uint8_ext_t;
944 #endif
945 typedef unaligned_type_ext<int16_t, etl::endian::little> le_int16_ext_t;
946 typedef unaligned_type_ext<uint16_t, etl::endian::little> le_uint16_ext_t;
947 typedef unaligned_type_ext<int32_t, etl::endian::little> le_int32_ext_t;
948 typedef unaligned_type_ext<uint32_t, etl::endian::little> le_uint32_ext_t;
949 #if ETL_USING_64BIT_TYPES
950 typedef unaligned_type_ext<int64_t, etl::endian::little> le_int64_ext_t;
951 typedef unaligned_type_ext<uint64_t, etl::endian::little> le_uint64_ext_t;
952 #endif
953 typedef unaligned_type_ext<float, etl::endian::little> le_float_ext_t;
954 typedef unaligned_type_ext<double, etl::endian::little> le_double_ext_t;
955 typedef unaligned_type_ext<long double, etl::endian::little> le_long_double_ext_t;
956
957 // Big Endian
958 typedef unaligned_type_ext<char, etl::endian::big> be_char_ext_t;
959 typedef unaligned_type_ext<signed char, etl::endian::big> be_schar_ext_t;
960 typedef unaligned_type_ext<unsigned char, etl::endian::big> be_uchar_ext_t;
961 typedef unaligned_type_ext<short, etl::endian::big> be_short_ext_t;
962 typedef unaligned_type_ext<unsigned short, etl::endian::big> be_ushort_ext_t;
963 typedef unaligned_type_ext<int, etl::endian::big> be_int_ext_t;
964 typedef unaligned_type_ext<unsigned int, etl::endian::big> be_uint_ext_t;
965 typedef unaligned_type_ext<long, etl::endian::big> be_long_ext_t;
966 typedef unaligned_type_ext<unsigned long, etl::endian::big> be_ulong_ext_t;
967 typedef unaligned_type_ext<long long, etl::endian::big> be_long_long_ext_t;
968 typedef unaligned_type_ext<unsigned long long, etl::endian::big> be_ulong_long_ext_t;
969 #if ETL_USING_8BIT_TYPES
970 typedef unaligned_type_ext<int8_t, etl::endian::big> be_int8_ext_t;
971 typedef unaligned_type_ext<uint8_t, etl::endian::big> be_uint8_ext_t;
972 #endif
973 typedef unaligned_type_ext<int16_t, etl::endian::big> be_int16_ext_t;
974 typedef unaligned_type_ext<uint16_t, etl::endian::big> be_uint16_ext_t;
975 typedef unaligned_type_ext<int32_t, etl::endian::big> be_int32_ext_t;
976 typedef unaligned_type_ext<uint32_t, etl::endian::big> be_uint32_ext_t;
977 #if ETL_USING_64BIT_TYPES
978 typedef unaligned_type_ext<int64_t, etl::endian::big> be_int64_ext_t;
979 typedef unaligned_type_ext<uint64_t, etl::endian::big> be_uint64_ext_t;
980 #endif
981 typedef unaligned_type_ext<float, etl::endian::big> be_float_ext_t;
982 typedef unaligned_type_ext<double, etl::endian::big> be_double_ext_t;
983 typedef unaligned_type_ext<long double, etl::endian::big> be_long_double_ext_t;
984
985 // Network Order
986 typedef be_char_ext_t net_char_ext_t;
987 typedef be_schar_ext_t net_schar_ext_t;
988 typedef be_uchar_ext_t net_uchar_ext_t;
989 typedef be_short_ext_t net_short_ext_t;
990 typedef be_ushort_ext_t net_ushort_ext_t;
991 typedef be_int_ext_t net_int_ext_t;
992 typedef be_uint_ext_t net_uint_ext_t;
993 typedef be_long_ext_t net_long_ext_t;
994 typedef be_ulong_ext_t net_ulong_ext_t;
995 typedef be_long_long_ext_t net_long_long_ext_t;
996 typedef be_ulong_long_ext_t net_ulong_long_ext_t;
997#if ETL_USING_8BIT_TYPES
998 typedef be_int8_ext_t net_int8_ext_t;
999 typedef be_uint8_ext_t net_uint8_ext_t;
1000#endif
1001 typedef be_int16_ext_t net_int16_ext_t;
1002 typedef be_uint16_ext_t net_uint16_ext_t;
1003 typedef be_int32_ext_t net_int32_ext_t;
1004 typedef be_uint32_ext_t net_uint32_ext_t;
1005#if ETL_USING_64BIT_TYPES
1006 typedef be_int64_ext_t net_int64_ext_t;
1007 typedef be_uint64_ext_t net_uint64_ext_t;
1008#endif
1009 typedef be_float_ext_t net_float_ext_t;
1010 typedef be_double_ext_t net_double_ext_t;
1011 typedef be_long_double_ext_t net_long_double_ext_t;
1012
1013#if ETL_USING_CPP11
1014 template <typename T, int Endian>
1015 using unaligned_type_ext_t = typename etl::unaligned_type_ext<T, Endian>::type;
1016#endif
1017
1018#if ETL_USING_CPP17
1019 template <typename T, int Endian>
1020 constexpr size_t unaligned_type_ext_t_v = etl::unaligned_type_ext<T, Endian>::Size;
1021#endif
1022}
1023
1024
1025
1026#endif
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:739
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
is_floating_point
Definition type_traits_generator.h:1026
is_integral
Definition type_traits_generator.h:996
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_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
pair holds two objects of arbitrary type
Definition utility.h:164
Definition unaligned_type.h:58