Embedded Template Library 1.0
Loading...
Searching...
No Matches
bitset_new.h
Go to the documentation of this file.
1
2/******************************************************************************
3The MIT License(MIT)
4
5Embedded Template Library.
6https://github.com/ETLCPP/etl
7https://www.etlcpp.com
8
9Copyright(c) 2022 John Wellbelove
10
11Permission is hereby granted, free of charge, to any person obtaining a copy
12of this software and associated documentation files(the "Software"), to deal
13in the Software without restriction, including without limitation the rights
14to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
15copies of the Software, and to permit persons to whom the Software is
16furnished to do so, subject to the following conditions :
17
18The above copyright notice and this permission notice shall be included in all
19copies or substantial portions of the Software.
20
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
24AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27SOFTWARE.
28******************************************************************************/
29
30#ifndef ETL_BITSET_NEW_INCLUDED
31#define ETL_BITSET_NEW_INCLUDED
32
33#include "../platform.h"
34#include "../algorithm.h"
35#include "../iterator.h"
36#include "../integral_limits.h"
37#include "../algorithm.h"
38#include "../nullptr.h"
39#include "../log.h"
40#include "../exception.h"
41#include "../integral_limits.h"
42#include "../binary.h"
43#include "../char_traits.h"
44#include "../static_assert.h"
45#include "../error_handler.h"
46#include "../span.h"
47#include "../string.h"
48#include "../enum_type.h"
49#include "../largest.h"
50#include "../smallest.h"
51
52#include <string.h>
53#include <stddef.h>
54#include <stdint.h>
55
56#if ETL_USING_STL
57#include <algorithm>
58#endif
59
60#include "minmax_push.h"
61
62#if defined(ETL_COMPILER_KEIL)
63#pragma diag_suppress 1300
64#endif
65
66#if ETL_USING_CPP11
67 #define ETL_STR(x) x
68 #define ETL_STRL(x) L##x
69 #define ETL_STRu(x) u##x
70 #define ETL_STRU(x) U##x
71#else
72 #define ETL_STR(x) x
73 #define ETL_STRL(x) x
74 #define ETL_STRu(x) x
75 #define ETL_STRU(x) x
76#endif
77
78//*****************************************************************************
82//*****************************************************************************
83
84namespace etl
85{
86 //***************************************************************************
90 //***************************************************************************
92 {
93 enum enum_type
94 {
95 Undefined = 0,
96 Single = 1,
97 Multi = 2
98 };
99
100 ETL_DECLARE_ENUM_TYPE(bitset_storage_model, char)
101 ETL_ENUM_TYPE(Undefined, "Undefined")
102 ETL_ENUM_TYPE(Single, "Single")
103 ETL_ENUM_TYPE(Multi, "Multi")
104 ETL_END_ENUM_TYPE
105 };
106
107 //***************************************************************************
110 //***************************************************************************
111 class bitset_exception : public etl::exception
112 {
113 public:
114
115 bitset_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
117 {
118 }
119 };
120
121 //***************************************************************************
124 //***************************************************************************
126 {
127 public:
128
130 : bitset_exception(ETL_ERROR_TEXT("bitset:type_too_small", ETL_BITSET_FILE_ID"A"), file_name_, line_number_)
131 {
132 }
133 };
134
135 //***************************************************************************
138 //***************************************************************************
139 class bitset_overflow : public bitset_exception
140 {
141 public:
142
143 bitset_overflow(string_type file_name_, numeric_type line_number_)
144 : bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"C"), file_name_, line_number_)
145 {
146 }
147 };
148
149 //***************************************************************************
152 //***************************************************************************
154 {
155 public:
156
158 : bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"D"), file_name_, line_number_)
159 {
160 }
161 };
162
163 //***************************************************************************
164 namespace private_bitset
165 {
166 template <typename TElement>
168 {
169 public:
170
171 typedef TElement element_type;
172 typedef TElement* pointer;
173 typedef const TElement* const_pointer;
174 typedef size_t size_type;
175
176 static ETL_CONSTANT size_t npos = etl::integral_limits<size_t>::max;
177 static ETL_CONSTANT size_t Bits_Per_Element = etl::integral_limits<TElement>::bits;
178 static ETL_CONSTANT TElement All_Set_Element = etl::integral_limits<TElement>::max;
179 static ETL_CONSTANT TElement All_Clear_Element = element_type(0);
180 };
181
182 template <typename TElement>
183 ETL_CONSTANT size_t bitset_impl_common<TElement>::npos;
184
185 template <typename TElement>
187
188 template <typename TElement>
190
191 template <typename TElement>
193 }
194
195 //*************************************************************************
198 //*************************************************************************
199 template <typename TElement, char Bitset_Layout>
201
202 //*************************************************************************
205 //*************************************************************************
206 template <typename TElement>
207 class bitset_impl<TElement, etl::bitset_storage_model::Single> : public etl::private_bitset::bitset_impl_common<TElement>
208 {
209 public:
210
214
215 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
217 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
218
220
221 //*************************************************************************
223 //*************************************************************************
224 static
225 ETL_CONSTEXPR14
226 void set_all(pointer pbuffer,
227 size_t /*number_of_elements*/,
228 element_type top_mask) ETL_NOEXCEPT
229 {
230 *pbuffer = All_Set_Element & top_mask;
231 }
232
233 //*************************************************************************
235 //*************************************************************************
236 static
237 ETL_CONSTEXPR14
238 void set_position(pointer pbuffer,
239 size_t position,
240 bool value = true)
241 {
242 const element_type mask = element_type(element_type(1) << position);
243
244 if (value == true)
245 {
246 *pbuffer |= mask;
247 }
248 else
249 {
250 *pbuffer &= ~mask;
251 }
252 }
253
254 //*************************************************************************
256 //*************************************************************************
257 template <size_t Position>
258 static
259 ETL_CONSTEXPR14
260 void set_position(pointer pbuffer,
261 bool value = true)
262 {
264
265 if (value == true)
266 {
267 *pbuffer |= mask;
268 }
269 else
270 {
271 *pbuffer &= ~mask;
272 }
273 }
274
275 //*************************************************************************
277 //*************************************************************************
278 template <size_t Position, bool Value>
279 static
280 ETL_CONSTEXPR14
281 void set_position(pointer pbuffer)
282 {
284
285 if (Value == true)
286 {
287 *pbuffer |= mask;
288 }
289 else
290 {
291 *pbuffer &= ~mask;
292 }
293 }
294
295 //*************************************************************************
297 //*************************************************************************
298 static
299 ETL_CONSTEXPR14
300 void reset_all(pointer pbuffer,
301 size_t /*number_of_elements*/) ETL_NOEXCEPT
302 {
303 *pbuffer = All_Clear_Element;
304 }
305
306 //*************************************************************************
308 //*************************************************************************
309 static
310 ETL_CONSTEXPR14
311
312 void reset_position(pointer pbuffer,
313 size_t position)
314 {
315 const element_type mask = element_type(element_type(1) << position);
316 *pbuffer &= ~mask;
317 }
318
319 //*************************************************************************
321 //*************************************************************************
322 static
323 ETL_CONSTEXPR14
324 void from_string(pointer pbuffer,
325 size_t /*number_of_elements*/,
326 size_t active_bits,
327 const char* text) ETL_NOEXCEPT
328 {
329 reset_all(pbuffer, 1U);
330
331 if (text != ETL_NULLPTR)
332 {
333 size_t string_length = etl::strlen(text);
334
335 // Build from the string.
337
339
340 for (size_t i = 0U; i < string_length; ++i)
341 {
342 if (text[i] == ETL_STR('1'))
343 {
344 *pbuffer |= mask;
345 }
346
347 mask >>= 1U;
348 }
349 }
350 }
351
352 //*************************************************************************
354 //*************************************************************************
355 static
356 ETL_CONSTEXPR14
357 void from_string(pointer pbuffer,
358 size_t /*number_of_elements*/,
359 size_t active_bits,
360 const wchar_t* text) ETL_NOEXCEPT
361 {
362 reset_all(pbuffer, 1U);
363
364 if (text != ETL_NULLPTR)
365 {
366 size_t string_length = etl::strlen(text);
367
368 // Build from the string.
370
372
373 for (size_t i = 0U; i < string_length; ++i)
374 {
375 if (text[i] == ETL_STRL('1'))
376 {
377 *pbuffer |= mask;
378 }
379
380 mask >>= 1U;
381 }
382 }
383 }
384
385 //*************************************************************************
387 //*************************************************************************
388 static
389 ETL_CONSTEXPR14
390 void from_string(pointer pbuffer,
391 size_t /*number_of_elements*/,
392 size_t active_bits,
393 const char16_t* text) ETL_NOEXCEPT
394 {
395 reset_all(pbuffer, 1U);
396
397 if (text != ETL_NULLPTR)
398 {
399 size_t string_length = etl::strlen(text);
400
401 // Build from the string.
403
405
406 for (size_t i = 0U; i < string_length; ++i)
407 {
408 if (text[i] == ETL_STRu('1'))
409 {
410 *pbuffer |= mask;
411 }
412
413 mask >>= 1U;
414 }
415 }
416 }
417
418 //*************************************************************************
420 //*************************************************************************
421 static
422 ETL_CONSTEXPR14
423 void from_string(pointer pbuffer,
424 size_t /*number_of_elements*/,
425 size_t active_bits,
426 const char32_t* text) ETL_NOEXCEPT
427 {
428 reset_all(pbuffer, 1U);
429
430 if (text != ETL_NULLPTR)
431 {
432 size_t string_length = etl::strlen(text);
433
434 // Build from the string.
436
438
439 for (size_t i = 0U; i < string_length; ++i)
440 {
441 if (text[i] == ETL_STRU('1'))
442 {
443 *pbuffer |= mask;
444 }
445
446 mask >>= 1U;
447 }
448 }
449 }
450
451 //*************************************************************************
453 //*************************************************************************
454 template <typename T>
455 static
456 ETL_CONSTEXPR14
458 size_t /*number_of_elements*/) ETL_NOEXCEPT
459 {
460 return T(*pbuffer);
461 }
462
463 //*************************************************************************
465 //*************************************************************************
466 template <typename T>
467 static
468 ETL_CONSTEXPR14
470 size_t position,
471 size_t length = etl::integral_limits<T>::bits)
472 {
474
476 const unsigned_t Shift = position % Bits_Per_Element;
477
478 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
479
481 {
482 value = etl::sign_extend<T>(value, length);
483 }
484
485 return static_cast<T>(value);
486 }
487
488 //*************************************************************************
490 //*************************************************************************
491#if ETL_USING_CPP11
493#else
494 template <typename T, size_t Position, size_t Length>
495#endif
496 static
497 ETL_CONSTEXPR14
499 {
501
503 const unsigned_t Shift = Position % Bits_Per_Element;
504
505 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
506
508 {
509 value = etl::sign_extend<T>(value, Length);
510 }
511
512 return static_cast<T>(value);
513 }
514
515 //*************************************************************************
518 //*************************************************************************
519 static
520 ETL_CONSTEXPR14
521 bool test(const_pointer pbuffer,
522 size_t position)
523 {
524 const element_type mask = element_type(element_type(1) << position);
525 return (*pbuffer & mask) != 0U;
526 }
527
528 //*************************************************************************
530 //*************************************************************************
531 static
532 ETL_CONSTEXPR14
533 size_t count(const_pointer pbuffer,
534 size_t /*number_of_elements*/) ETL_NOEXCEPT
535 {
536 return etl::count_bits(*pbuffer);
537 }
538
539 //*************************************************************************
540 // Are all the bits sets?
541 //*************************************************************************
542 static
543 ETL_CONSTEXPR14
544 bool all(const_pointer pbuffer,
545 size_t /*number_of_elements*/,
546 element_type top_mask) ETL_NOEXCEPT
547 {
548 return (*pbuffer & top_mask) == top_mask;
549 }
550
551 //*************************************************************************
552 // Are all the mask bits sets?
553 //*************************************************************************
554 static
555 ETL_CONSTEXPR14
556 bool all(const_pointer pbuffer,
557 size_t /*number_of_elements*/,
558 element_type top_mask,
559 element_type mask) ETL_NOEXCEPT
560 {
561 return (*pbuffer & top_mask & mask) == mask;
562 }
563
564 //*************************************************************************
566 //*************************************************************************
567 static
568 ETL_CONSTEXPR14
569 bool none(const_pointer pbuffer,
570 size_t /*number_of_elements*/) ETL_NOEXCEPT
571 {
572 return *pbuffer == All_Clear_Element;
573 }
574
575 //*************************************************************************
577 //*************************************************************************
578 static
579 ETL_CONSTEXPR14
580 bool none(const_pointer pbuffer,
581 size_t /*number_of_elements*/,
582 element_type mask) ETL_NOEXCEPT
583 {
584 return (*pbuffer & mask) == All_Clear_Element;
585 }
586
587 //*************************************************************************
589 //*************************************************************************
590 static
591 ETL_CONSTEXPR14
592 bool any(const_pointer pbuffer,
593 size_t /*number_of_elements*/) ETL_NOEXCEPT
594 {
595 return *pbuffer != All_Clear_Element;
596 }
597
598 //*************************************************************************
600 //*************************************************************************
601 static
602 ETL_CONSTEXPR14
603 bool any(const_pointer pbuffer,
604 size_t /*number_of_elements*/,
605 element_type mask) ETL_NOEXCEPT
606 {
607 return (*pbuffer & mask) != All_Clear_Element;
608 }
609
610 //*************************************************************************
612 //*************************************************************************
613 static
614 ETL_CONSTEXPR14
615 void flip_all(pointer pbuffer,
616 size_t /*number_of_elements*/) ETL_NOEXCEPT
617 {
618 *pbuffer = ~*pbuffer;
619 }
620
621 //*************************************************************************
623 //*************************************************************************
624 static
625 ETL_CONSTEXPR14
626 void flip_bits(pointer pbuffer,
628 {
629 *pbuffer ^= mask;
630 }
631
632 //*************************************************************************
634 //*************************************************************************
635 static
636 ETL_CONSTEXPR14
637 void flip_position(pointer pbuffer,
638 size_t position)
639 {
640 const element_type mask = element_type(element_type(1) << position);
641 *pbuffer ^= mask;
642 }
643
644 //*************************************************************************
646 //*************************************************************************
647 template <typename TString>
648 static
649 ETL_CONSTEXPR14
651 size_t active_bits,
652 typename TString::value_type zero = typename TString::value_type('0'),
653 typename TString::value_type one = typename TString::value_type('1'))
654 {
655 TString result;
656
657 result.resize(active_bits, '\0');
658
659 // Check that the string type can contain the digits.
660 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
661
662 for (size_t i = active_bits; i > 0; --i)
663 {
664 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
665 }
666
667 return result;
668 }
669
670 //*************************************************************************
675 //*************************************************************************
676 static
677 ETL_CONSTEXPR14
678 size_t find_next(const_pointer pbuffer,
679 size_t /*number_of_elements*/,
680 size_t active_bits,
681 bool state,
682 size_t position) ETL_NOEXCEPT
683 {
684 if (position < active_bits)
685 {
686 // Where to start.
687 size_t bit = position;
688
689 element_type mask = 1U << position;
690
691 // Needs checking?
692 if ((state && (*pbuffer != All_Clear_Element)) || (!state && (*pbuffer != All_Set_Element)))
693 {
694 // For each bit in the element...
695 while (bit < active_bits)
696 {
697 // Equal to the required state?
698 if (((*pbuffer & mask) != 0) == state)
699 {
700 return bit;
701 }
702
703 // Move on to the next bit.
704 mask <<= 1;
705 ++bit;
706 }
707 }
708 }
709
710 return npos;
711 }
712
713 //*************************************************************************
716 //*************************************************************************
717 static
718 ETL_CONSTEXPR14
721 size_t /*number_of_elements*/) ETL_NOEXCEPT
722 {
724 }
725
726 //*************************************************************************
729 //*************************************************************************
730 static
731 ETL_CONSTEXPR14
734 size_t /*number_of_elements*/) ETL_NOEXCEPT
735 {
737 }
738
739 //*************************************************************************
742 //*************************************************************************
743 static
744 ETL_CONSTEXPR14
747 size_t /*number_of_elements*/) ETL_NOEXCEPT
748 {
750 }
751
752 //*************************************************************************
755 //*************************************************************************
756 static
757 ETL_CONSTEXPR14
760 size_t /*number_of_elements*/) ETL_NOEXCEPT
761 {
763 }
764
765 //*************************************************************************
768 //*************************************************************************
769 static
770 ETL_CONSTEXPR14
771 void operator_not(pointer pbuffer,
772 size_t /*number_of_elements*/) ETL_NOEXCEPT
773 {
774 *pbuffer = ~*pbuffer;
775 }
776
777 //*************************************************************************
779 //*************************************************************************
780 static
781 ETL_CONSTEXPR14
783 size_t /*number_of_elements*/,
784 size_t active_bits,
785 size_t shift) ETL_NOEXCEPT
786 {
787 if (shift >= active_bits)
788 {
789 reset_all(pbuffer, 1U);
790 }
791 else
792 {
793 *pbuffer <<= shift;
794 }
795 }
796
797 //*************************************************************************
799 //*************************************************************************
800 static
801 ETL_CONSTEXPR14
803 size_t /*number_of_elements*/,
804 size_t active_bits,
805 size_t shift) ETL_NOEXCEPT
806 {
807 if (shift >= active_bits)
808 {
809 reset_all(pbuffer, 1U);
810 }
811 else
812 {
813 *pbuffer >>= shift;
814 }
815 }
816
817 //*************************************************************************
819 //*************************************************************************
820 static
821 ETL_CONSTEXPR14
824 size_t /*number_of_elements*/) ETL_NOEXCEPT
825 {
826 return (*lhs_pbuffer == *rhs_pbuffer);
827 }
828
829 //*************************************************************************
831 //*************************************************************************
832 template <typename TElementType>
833 static
834 ETL_CONSTEXPR14
835 void initialise(pointer pbuffer,
836 size_t /*number_of_elements*/,
837 unsigned long long value) ETL_NOEXCEPT
838 {
839 *pbuffer = static_cast<TElementType>(value);
840 }
841
842 //*************************************************************************
844 //*************************************************************************
845 static
846 ETL_CONSTEXPR14
849 size_t /*number_of_elements*/) ETL_NOEXCEPT
850 {
853 *rhs_pbuffer = temp;
854 }
855 };
856
857 //*************************************************************************
860 //*************************************************************************
861 template <typename TElement>
862 class bitset_impl<TElement, etl::bitset_storage_model::Multi> : public etl::private_bitset::bitset_impl_common<TElement>
863 {
864 private:
865
867
868 public:
869
873
874 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
876 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
877
879
880 //*************************************************************************
882 //*************************************************************************
883 template <size_t Position, size_t Length, size_t Bits_Per_Element>
885 {
886 static ETL_CONSTANT bool value = ((Position + Length - 1) >> etl::log2<Bits_Per_Element>::value) == (Position >> etl::log2<Bits_Per_Element>::value);
887 };
888
889 //*************************************************************************
892 //*************************************************************************
893 static
894 ETL_CONSTEXPR14
895 bool test(const_pointer pbuffer,
896 size_t position) ETL_NOEXCEPT
897 {
898 size_t index = position >> etl::log2<Bits_Per_Element>::value;
899 element_type mask = element_type(1) << (position & (Bits_Per_Element - 1));
900
901 return (pbuffer[index] & mask) != 0;
902 }
903
904 //*************************************************************************
906 //*************************************************************************
907 static
908 ETL_CONSTEXPR14
909 size_t count(const_pointer pbuffer,
910 size_t number_of_elements) ETL_NOEXCEPT
911 {
912 size_t count = 0;
913
914 while (number_of_elements-- != 0)
915 {
916 count += etl::count_bits(*pbuffer++);
917 }
918
919 return count;
920 }
921
922 //*************************************************************************
923 // Are all the bits sets?
924 //*************************************************************************
925 static
926 ETL_CONSTEXPR14
927 bool all(const_pointer pbuffer,
928 size_t number_of_elements,
929 element_type top_mask) ETL_NOEXCEPT
930 {
931 // All but the last.
932 while (number_of_elements-- != 1U)
933 {
934 if (*pbuffer++ != All_Set_Element)
935 {
936 return false;
937 }
938 }
939
940 // The last.
941 if ((*pbuffer & top_mask) != top_mask)
942 {
943 return false;
944 }
945
946 return true;
947 }
948
949 //*************************************************************************
951 //*************************************************************************
952 static
953 ETL_CONSTEXPR14
954 bool none(const_pointer pbuffer,
955 size_t number_of_elements) ETL_NOEXCEPT
956 {
957 while (number_of_elements-- != 0)
958 {
959 if (*pbuffer++ != 0)
960 {
961 return false;
962 }
963 }
964
965 return true;
966 }
967
968 //*************************************************************************
970 //*************************************************************************
971 static
972 ETL_CONSTEXPR14
973 bool any(const_pointer pbuffer,
974 size_t number_of_elements) ETL_NOEXCEPT
975 {
976 bool any_set = false;
977
978 while (number_of_elements-- != 0)
979 {
980 if (*pbuffer++ != All_Clear_Element)
981 {
982 any_set = true;
983 break;
984 }
985 }
986
987 return any_set;
988 }
989
990 //*************************************************************************
992 //*************************************************************************
993 static
994 ETL_CONSTEXPR14
995 void set_all(pointer pbuffer,
996 size_t number_of_elements,
997 element_type top_mask) ETL_NOEXCEPT
998 {
999 while (number_of_elements-- != 1U)
1000 {
1001 *pbuffer++ = All_Set_Element;
1002 }
1003
1004 *pbuffer = (All_Set_Element & top_mask);
1005 }
1006
1007 //*************************************************************************
1009 //*************************************************************************
1010 static
1011 ETL_CONSTEXPR14
1012 void set_position(pointer pbuffer,
1013 size_t position,
1014 bool value = true) ETL_NOEXCEPT
1015 {
1016 size_t index = position >> etl::log2<Bits_Per_Element>::value;
1017 element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1018
1019 if (value == true)
1020 {
1021 pbuffer[index] |= bit;
1022 }
1023 else
1024 {
1025 pbuffer[index] &= ~bit;
1026 }
1027 }
1028
1029 //*************************************************************************
1031 //*************************************************************************
1032 template <size_t Position>
1033 static
1034 ETL_CONSTEXPR14
1035 void set_position(pointer pbuffer,
1036 bool value = true)
1037 {
1039 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
1040
1041 if (value == true)
1042 {
1043 pbuffer[index] |= bit;
1044 }
1045 else
1046 {
1047 pbuffer[index] &= ~bit;
1048 }
1049 }
1050
1051 //*************************************************************************
1053 //*************************************************************************
1054 template <size_t Position, bool Value>
1055 static
1056 ETL_CONSTEXPR14
1057 void set_position(pointer pbuffer)
1058 {
1060 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
1061
1062 if (Value == true)
1063 {
1064 pbuffer[index] |= bit;
1065 }
1066 else
1067 {
1068 pbuffer[index] &= ~bit;
1069 }
1070 }
1071
1072 //*************************************************************************
1074 //*************************************************************************
1075 static
1076 ETL_CONSTEXPR14
1077 void from_string(pointer pbuffer,
1078 size_t number_of_elements,
1079 size_t total_bits,
1080 const char* text) ETL_NOEXCEPT
1081 {
1082 if (text == ETL_NULLPTR)
1083 {
1084 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1085 }
1086 else
1087 {
1088 size_t string_length = etl::strlen(text);
1089 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1090
1091 // Only reset elements we need to.
1092 while (index != number_of_elements)
1093 {
1094 pbuffer[index++] = All_Clear_Element;
1095 }
1096
1097 // Build from the string.
1098 size_t i = etl::min(total_bits, string_length);
1099
1100 while (i > 0)
1101 {
1102 set_position(pbuffer, --i, *text++ == ETL_STR('1'));
1103 }
1104 }
1105 }
1106
1107 //*************************************************************************
1109 //*************************************************************************
1110 static
1111 ETL_CONSTEXPR14
1112 void from_string(pointer pbuffer,
1113 size_t number_of_elements,
1114 size_t total_bits,
1115 const wchar_t* text) ETL_NOEXCEPT
1116 {
1117 if (text == ETL_NULLPTR)
1118 {
1119 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1120 }
1121 else
1122 {
1123 size_t string_length = etl::strlen(text);
1124 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1125
1126 // Only reset elements we need to.
1127 while (index != number_of_elements)
1128 {
1129 pbuffer[index++] = All_Clear_Element;
1130 }
1131
1132 // Build from the string.
1133 size_t i = etl::min(total_bits, string_length);
1134
1135 while (i > 0)
1136 {
1137 set_position(pbuffer, --i, *text++ == ETL_STRL('1'));
1138 }
1139 }
1140 }
1141
1142 //*************************************************************************
1144 //*************************************************************************
1145 static
1146 ETL_CONSTEXPR14
1147 void from_string(pointer pbuffer,
1148 size_t number_of_elements,
1149 size_t total_bits,
1150 const char16_t* text) ETL_NOEXCEPT
1151 {
1152 if (text == ETL_NULLPTR)
1153 {
1154 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1155 }
1156 else
1157 {
1158 size_t string_length = etl::strlen(text);
1159 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1160
1161 // Only reset elements we need to.
1162 while (index != number_of_elements)
1163 {
1164 pbuffer[index++] = All_Clear_Element;
1165 }
1166
1167 // Build from the string.
1168 size_t i = etl::min(total_bits, string_length);
1169
1170 while (i > 0)
1171 {
1172 set_position(pbuffer, --i, *text++ == ETL_STRu('1'));
1173 }
1174 }
1175 }
1176
1177 //*************************************************************************
1179 //*************************************************************************
1180 static
1181 ETL_CONSTEXPR14
1182 void from_string(pointer pbuffer,
1183 size_t number_of_elements,
1184 size_t total_bits,
1185 const char32_t* text) ETL_NOEXCEPT
1186 {
1187 if (text == ETL_NULLPTR)
1188 {
1189 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1190 }
1191 else
1192 {
1193 size_t string_length = etl::strlen(text);
1194 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1195
1196 // Only reset elements we need to.
1197 while (index != number_of_elements)
1198 {
1199 pbuffer[index++] = All_Clear_Element;
1200 }
1201
1202 // Build from the string.
1203 size_t i = etl::min(total_bits, string_length);
1204
1205 while (i > 0)
1206 {
1207 set_position(pbuffer, --i, *text++ == ETL_STRU('1'));
1208 }
1209 }
1210 }
1211
1212 //*************************************************************************
1214 //*************************************************************************
1215 static
1216 ETL_CONSTEXPR14
1217 void reset_all(pointer pbuffer,
1218 size_t number_of_elements) ETL_NOEXCEPT
1219 {
1220 while (number_of_elements-- != 0U)
1221 {
1222 *pbuffer++ = All_Clear_Element;
1223 }
1224 }
1225
1226 //*************************************************************************
1228 //*************************************************************************
1229 static
1230 ETL_CONSTEXPR14
1232 size_t position) ETL_NOEXCEPT
1233 {
1234 const size_t index = position >> etl::log2<Bits_Per_Element>::value;;
1235 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1236
1237 pbuffer[index] &= ~bit;
1238 }
1239
1240 //*************************************************************************
1242 //*************************************************************************
1243 template <typename T>
1244 static
1245 ETL_CONSTEXPR14
1247 size_t number_of_elements) ETL_NOEXCEPT
1248 {
1249 T v = T(0);
1250
1251 const bool OK = (sizeof(T) * CHAR_BIT) >= (number_of_elements * Bits_Per_Element);
1252
1253 if (OK)
1254 {
1256
1257 for (size_t i = 0UL; i < number_of_elements; ++i)
1258 {
1259 v |= T(typename etl::make_unsigned<T>::type(pbuffer[i]) << shift);
1260 shift += uint_least8_t(Bits_Per_Element);
1261 }
1262 }
1263
1264 return v;
1265 }
1266
1267 //*************************************************************************
1269 //*************************************************************************
1270 template <typename T>
1271 static
1272 ETL_CONSTEXPR14
1274 int element_index,
1275 size_t active_bits_in_msb,
1276 size_t length) ETL_NOEXCEPT
1277 {
1278 typedef typename etl::make_unsigned<T>::type unsigned_t;
1279
1280 unsigned_t value(0);
1281
1282 // Extract the first element, if partially filled.
1283 if (active_bits_in_msb < Bits_Per_Element)
1284 {
1286 value = pbuffer[element_index] & mask;
1287 length -= active_bits_in_msb;
1288 if (length >= Bits_Per_Element)
1289 {
1290 value = value << Bits_Per_Element;
1291 }
1292 --element_index;
1293 }
1294
1295 // Loop through the fully filled elements
1296 while (length >= Bits_Per_Element)
1297 {
1298 value |= pbuffer[element_index];
1299 length -= Bits_Per_Element;
1300 if (length >= Bits_Per_Element)
1301 {
1302 value = value << Bits_Per_Element;
1303 }
1304 --element_index;
1305 }
1306
1307 // Extract the last element, if partially filled.
1308 if (length != 0)
1309 {
1310 value = value << length;
1312 value |= (pbuffer[element_index] >> (Bits_Per_Element - length)) & mask;
1313 }
1314
1315 return value;
1316 }
1317
1318 //*************************************************************************
1321 //*************************************************************************
1322 template <typename T>
1323 static
1324 ETL_CONSTEXPR14
1326 size_t position,
1327 size_t length) ETL_NOEXCEPT
1328 {
1329 typedef typename etl::make_unsigned<T>::type unsigned_t;
1330
1331 unsigned_t value(0);
1332
1333 const int Msb_Element_Index = (position + length - 1) >> etl::log2<Bits_Per_Element>::value;
1335
1336 // Is the value contained within one element?
1338 {
1340 const unsigned_t Shift = position % Bits_Per_Element;
1341
1342 value = static_cast<unsigned_t>(pbuffer[Msb_Element_Index] >> Shift) & Mask;
1343 }
1344 else
1345 {
1346 // Get the number of active bits in the msb element
1347 size_t active_bits_in_msb = (position + length) - (Msb_Element_Index * Bits_Per_Element);
1348
1349 // Start with index of the element containing the msb.
1351
1353 }
1354
1355 return value;
1356 }
1357
1358 //*************************************************************************
1361 //*************************************************************************
1362 template <typename T, size_t Position, size_t Length>
1363 static
1364 ETL_CONSTEXPR14
1367 {
1368 typedef typename etl::make_unsigned<T>::type unsigned_t;
1369
1372 const unsigned_t Shift = Position % Bits_Per_Element;
1373
1374 return static_cast<unsigned_t>(pbuffer[Element_Index] >> Shift) & Mask;
1375 }
1376
1377 //*************************************************************************
1380 //*************************************************************************
1381 template <typename T, size_t Position, size_t Length>
1382 static
1383 ETL_CONSTEXPR14
1386 {
1387 // Start with index of the element containing the msb.
1389
1390 // Get the number of active bits in the first element
1391 const size_t Active_Bits_In_Msb = ((Position + Length - 1) % Bits_Per_Element) + 1;
1392
1394 }
1395
1396 //*************************************************************************
1398 //*************************************************************************
1399 template <typename T>
1400 static
1401 ETL_CONSTEXPR14
1403 size_t position,
1404 size_t length = etl::integral_limits<T>::bits)
1405 {
1406 typedef typename etl::make_unsigned<T>::type unsigned_t;
1407
1408 unsigned_t value = extract_from_buffer<unsigned_t>(pbuffer, position, length);
1409
1411 {
1412 value = etl::sign_extend<T>(value, length);
1413 }
1414
1415 return static_cast<T>(value);
1416 }
1417
1418 //*************************************************************************
1420 //*************************************************************************
1421 template <typename T, size_t Position, size_t Length>
1422 static
1423 ETL_CONSTEXPR14
1425 {
1426 typedef typename etl::make_unsigned<T>::type unsigned_t;
1427
1429
1431 {
1432 value = etl::sign_extend<T>(value, Length);
1433 }
1434
1435 return static_cast<T>(value);
1436 }
1437
1438 //*************************************************************************
1440 //*************************************************************************
1441 static
1442 ETL_CONSTEXPR14
1443 void flip_all(pointer pbuffer,
1444 size_t number_of_elements) ETL_NOEXCEPT
1445 {
1446 operator_not(pbuffer, number_of_elements);
1447 }
1448
1449 //*************************************************************************
1451 //*************************************************************************
1452 static
1453 ETL_CONSTEXPR14
1454 void flip_position(pointer pbuffer,
1455 size_t position) ETL_NOEXCEPT
1456 {
1457 const size_t index = position >> etl::log2<Bits_Per_Element>::value;;
1458 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1459
1460 pbuffer[index] ^= bit;
1461 }
1462
1463 //*************************************************************************
1468 //*************************************************************************
1469 static
1470 ETL_CONSTEXPR14
1471 size_t find_next(const_pointer pbuffer,
1472 size_t number_of_elements,
1473 size_t total_bits,
1474 bool state,
1475 size_t position) ETL_NOEXCEPT
1476 {
1477 // Where to start.
1478 size_t index = position >> log2<Bits_Per_Element>::value;
1479 size_t bit = position & (Bits_Per_Element - 1);
1480
1481 element_type mask = 1 << bit;
1482
1483 // For each element in the bitset...
1484 while (index < number_of_elements)
1485 {
1486 element_type value = pbuffer[index];
1487
1488 // Needs checking?
1489 if ((state && (value != All_Clear_Element)) ||
1490 (!state && (value != All_Set_Element)))
1491 {
1492 // For each bit in the element...
1493 while ((bit < Bits_Per_Element) && (position < total_bits))
1494 {
1495 // Equal to the required state?
1496 if (((value & mask) != 0) == state)
1497 {
1498 return position;
1499 }
1500
1501 // Move on to the next bit.
1502 mask <<= 1;
1503 ++position;
1504 ++bit;
1505 }
1506 }
1507 else
1508 {
1509 position += (Bits_Per_Element - bit);
1510 }
1511
1512 // Start at the beginning for all other elements.
1513 bit = 0;
1514 mask = 1;
1515
1516 ++index;
1517 }
1518
1519 return npos;
1520 }
1521
1522 //*************************************************************************
1524 //*************************************************************************
1525 template <typename TString>
1526 static
1527 ETL_CONSTEXPR14
1529 size_t active_bits,
1530 typename TString::value_type zero,
1531 typename TString::value_type one)
1532 {
1533 TString result;
1534
1535 result.resize(active_bits, '\0');
1536
1537 // Check that the string type can contain the digits.
1538 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
1539
1540 for (size_t i = active_bits; i > 0; --i)
1541 {
1542 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
1543 }
1544
1545 return result;
1546 }
1547
1548 //*************************************************************************
1550 //*************************************************************************
1551 static
1552 ETL_CONSTEXPR14
1555 size_t number_of_elements) ETL_NOEXCEPT
1556 {
1557 while (number_of_elements-- != 0)
1558 {
1560 ++lhs_pbuffer;
1561 ++rhs_pbuffer;
1562 }
1563 }
1564
1565 //*************************************************************************
1567 //*************************************************************************
1568 static
1569 ETL_CONSTEXPR14
1572 size_t number_of_elements) ETL_NOEXCEPT
1573 {
1574 while (number_of_elements-- != 0)
1575 {
1577 ++lhs_pbuffer;
1578 ++rhs_pbuffer;
1579 }
1580 }
1581
1582 //*************************************************************************
1584 //*************************************************************************
1585 static
1586 ETL_CONSTEXPR14
1589 size_t number_of_elements) ETL_NOEXCEPT
1590 {
1591 while (number_of_elements-- != 0)
1592 {
1594 ++lhs_pbuffer;
1595 ++rhs_pbuffer;
1596 }
1597 }
1598
1599 //*************************************************************************
1601 //*************************************************************************
1602 static
1603 ETL_CONSTEXPR14
1606 size_t number_of_elements) ETL_NOEXCEPT
1607 {
1608 while (number_of_elements-- != 0)
1609 {
1611 ++lhs_pbuffer;
1612 ++rhs_pbuffer;
1613 }
1614 }
1615
1616 //*************************************************************************
1618 //*************************************************************************
1619 static
1620 ETL_CONSTEXPR14
1621 void operator_not(pointer pbuffer,
1622 size_t number_of_elements) ETL_NOEXCEPT
1623 {
1624 while (number_of_elements-- != 0)
1625 {
1626 *pbuffer = ~*pbuffer;
1627 ++pbuffer;
1628 }
1629 }
1630
1631 //*************************************************************************
1633 //*************************************************************************
1634 static
1635 ETL_CONSTEXPR14
1637 size_t number_of_elements,
1638 size_t active_bits,
1639 size_t shift) ETL_NOEXCEPT
1640 {
1641 if (shift >= active_bits)
1642 {
1643 reset_all(pbuffer, number_of_elements);
1644 }
1645 else
1646 {
1647 // The place where the elements are split when shifting.
1648 const size_t split_position = Bits_Per_Element - (shift % Bits_Per_Element);
1649
1650 // Where we are shifting from.
1651 int src_index = int(number_of_elements - (shift / Bits_Per_Element) - 1U);
1652
1653 // Where we are shifting to.
1654 int dst_index = int(number_of_elements - 1U);
1655
1656 // Shift control constants.
1657 const size_t lsb_shift = Bits_Per_Element - split_position;
1658 const size_t msb_shift = split_position;
1659
1663
1664 // First lsb.
1666 pbuffer[dst_index] = lsb;
1667 --src_index;
1668
1669 // Now do the shifting.
1670 while (src_index >= 0)
1671 {
1672 // Shift msb.
1674 pbuffer[dst_index] = pbuffer[dst_index] | msb;
1675 --dst_index;
1676
1677 // Shift lsb.
1678 lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1679 pbuffer[dst_index] = lsb;
1680 --src_index;
1681 }
1682
1683 // Clear the remaining bits.
1684 // First lsb.
1685 pbuffer[dst_index] &= lsb_shifted_mask;
1686
1687 // The other remaining bytes on the right.
1688 for (int i = 0; i < dst_index; ++i)
1689 {
1690 pbuffer[i] = 0;
1691 }
1692 }
1693 }
1694
1695 //*************************************************************************
1697 //*************************************************************************
1698 static
1699 ETL_CONSTEXPR14
1701 size_t number_of_elements,
1702 size_t active_bits,
1703 size_t shift) ETL_NOEXCEPT
1704 {
1705 if (shift >= active_bits)
1706 {
1707 reset_all(pbuffer, number_of_elements);
1708 }
1709 else
1710 {
1711 // The place where the elements are split when shifting.
1712 const size_t split_position = shift % Bits_Per_Element;
1713
1714 // Where we are shifting from.
1715 int src_index = int(shift / Bits_Per_Element);
1716
1717 // Where we are shifting to.
1718 int dst_index = 0;
1719
1720 // Shift control constants.
1721 const size_t lsb_shift = Bits_Per_Element - split_position;
1722 const size_t msb_shift = split_position;
1723
1727
1728 // Now do the shifting.
1729 while (src_index < int(number_of_elements - 1))
1730 {
1731 // Shift msb.
1733 ++src_index;
1734
1735 // Shift lsb.
1737
1738 // Combine them.
1739 pbuffer[dst_index] = lsb | msb;
1740 ++dst_index;
1741 }
1742
1743 // Final msb.
1745 pbuffer[dst_index] = msb;
1746
1747 // Clear the remaining bits.
1748 // First msb.
1749 pbuffer[dst_index] &= msb_shifted_mask;
1750 ++dst_index;
1751
1752 // The other remaining bytes.
1753 while (dst_index < int(number_of_elements))
1754 {
1755 pbuffer[dst_index] = 0;
1756 ++dst_index;
1757 }
1758 }
1759 }
1760
1761 //*************************************************************************
1763 //*************************************************************************
1764 static
1765 ETL_CONSTEXPR14
1768 size_t number_of_elements) ETL_NOEXCEPT
1769 {
1770 return etl::equal(lhs_pbuffer, lhs_pbuffer + number_of_elements, rhs_pbuffer);
1771 }
1772
1773 //*************************************************************************
1776 //*************************************************************************
1777 template <typename TElementType>
1778 static
1779 ETL_CONSTEXPR14
1782 size_t number_of_elements,
1783 unsigned long long value) ETL_NOEXCEPT
1784 {
1785 size_t i = 0UL;
1786
1787 // Set the non-zero elements.
1788 pbuffer[i++] = value;
1789
1790 // Clear the remaining elements.
1791 while (i != number_of_elements)
1792 {
1793 pbuffer[i++] = All_Clear_Element;
1794 }
1795 }
1796
1797 //*************************************************************************
1800 //*************************************************************************
1801 template <typename TElementType>
1802 static
1803 ETL_CONSTEXPR14
1806 size_t number_of_elements,
1807 unsigned long long value) ETL_NOEXCEPT
1808 {
1809 size_t i = 0UL;
1810
1811 // Set the non-zero elements.
1812 const unsigned long long Shift = etl::integral_limits<element_type>::bits;
1813
1814 while ((value != 0) && (i != number_of_elements))
1815 {
1816 pbuffer[i++] = value & All_Set_Element;
1817 value = value >> Shift;
1818 }
1819
1820 // Clear the remaining elements.
1821 while (i != number_of_elements)
1822 {
1823 pbuffer[i++] = All_Clear_Element;
1824 }
1825 }
1826
1827 //*************************************************************************
1829 //*************************************************************************
1830 static
1831 ETL_CONSTEXPR14
1834 size_t number_of_elements)
1835 {
1836 etl::swap_ranges(pbuffer1, pbuffer1 + number_of_elements, pbuffer2);
1837 }
1838 };
1839
1840 namespace private_bitset
1841 {
1842 //***************************************************************************
1843 template <size_t Active_Bits, typename TElement>
1845 {
1846 public:
1847
1848 typedef typename etl::private_bitset::bitset_impl_common<TElement>::element_type element_type;
1849
1850 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
1851 using etl::private_bitset::bitset_impl_common<TElement>::All_Set_Element;
1852 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
1853
1854 static ETL_CONSTANT size_t Number_Of_Elements = (Active_Bits % Bits_Per_Element == 0) ? Active_Bits / Bits_Per_Element : Active_Bits / Bits_Per_Element + 1;
1855 static ETL_CONSTANT size_t Size = Active_Bits;
1856 static ETL_CONSTANT size_t Allocated_Bits = Number_Of_Elements * Bits_Per_Element;
1857
1858#if ETL_USING_CPP11
1859 static ETL_CONSTANT etl::bitset_storage_model Storage_Model = (bitset_common<Active_Bits, TElement>::Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi;
1860#else
1861 static ETL_CONSTANT etl::bitset_storage_model Storage_Model;
1862#endif
1863
1866
1867 private:
1868
1869 static ETL_CONSTANT size_t Top_Mask_Shift = ((Bits_Per_Element - ((Number_Of_Elements * Bits_Per_Element) - Active_Bits)) % Bits_Per_Element);
1870
1871 public:
1872
1873 static ETL_CONSTANT TElement Top_Mask = element_type(Top_Mask_Shift == 0 ? All_Set_Element : ~(All_Set_Element << Top_Mask_Shift));
1874 };
1875
1876
1877 template <size_t Active_Bits, typename TElement>
1879
1880 template <size_t Active_Bits, typename TElement>
1882
1883#if ETL_USING_CPP11
1884 template <size_t Active_Bits, typename TElement>
1886#else
1887 template <size_t Active_Bits, typename TElement>
1889#endif
1890
1891 template <size_t Active_Bits, typename TElement>
1893
1894 template <size_t Active_Bits, typename TElement>
1896 }
1897
1898 //***************************************************************************
1900 //***************************************************************************
1901 template <size_t Active_Bits = 0U,
1902 typename TElement = unsigned char>
1903 class bitset;
1904
1905 //***************************************************************************
1907 //***************************************************************************
1908 template <>
1909 class bitset<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
1910 {
1911 public:
1912
1916
1917 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
1918 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
1919 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
1920 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
1921 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
1922 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
1923 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
1924 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
1925 };
1926
1927 //*************************************************************************
1929 //*************************************************************************
1930 template <size_t Active_Bits, typename TElement>
1931 class bitset : public etl::private_bitset::bitset_common<Active_Bits, TElement>
1932 {
1933 public:
1934
1935 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
1936
1940
1941
1942
1943 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
1944 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
1945 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
1946 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
1947 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
1948 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
1949 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
1950 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
1951
1952 //*************************************************************************
1954 //*************************************************************************
1956 {
1957 public:
1958
1959 friend class bitset;
1960
1961 //*******************************
1963 //*******************************
1964 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
1965 : p_bitset(other.p_bitset)
1966 , position(other.position)
1967 {
1968 }
1969
1970 //*******************************
1972 //*******************************
1973 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
1974 {
1975 return p_bitset->test(position);
1976 }
1977
1978 //*******************************
1980 //*******************************
1981 ETL_CONSTEXPR14 bit_reference& operator = (bool b) ETL_NOEXCEPT
1982 {
1983 p_bitset->set(position, b);
1984 return *this;
1985 }
1986
1987 //*******************************
1989 //*******************************
1990 ETL_CONSTEXPR14 bit_reference& operator = (const bit_reference& r) ETL_NOEXCEPT
1991 {
1992 p_bitset->set(position, bool(r));
1993 return *this;
1994 }
1995
1996 //*******************************
1998 //*******************************
1999 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
2000 {
2001 p_bitset->flip(position);
2002 return *this;
2003 }
2004
2005 //*******************************
2007 //*******************************
2008 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
2009 {
2010 return !p_bitset->test(position);
2011 }
2012
2013 private:
2014
2015 //*******************************
2017 //*******************************
2018 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
2019 : p_bitset(ETL_NULLPTR)
2020 , position(0)
2021 {
2022 }
2023
2024 //*******************************
2026 //*******************************
2027 ETL_CONSTEXPR14 bit_reference(bitset<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
2028 : p_bitset(&r_bitset)
2029 , position(position_)
2030 {
2031 }
2032
2033 bitset<Active_Bits, TElement>* p_bitset;
2034 size_t position;
2035 };
2036
2037 //*************************************************************************
2039 //*************************************************************************
2040 ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
2041 : buffer()
2042 {
2043 implementation::reset_all(buffer, Number_Of_Elements);
2044 }
2045
2046 //*************************************************************************
2048 //*************************************************************************
2049 ETL_CONSTEXPR14 bitset(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2050 : buffer()
2051 {
2052 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
2053 }
2054
2055 //*************************************************************************
2057 //*************************************************************************
2058 template <typename TValue>
2059 ETL_CONSTEXPR14 bitset(TValue value, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
2060 : buffer()
2061 {
2062 implementation::template initialise<element_type>(buffer, Number_Of_Elements, value);
2063 }
2064
2065 //*************************************************************************
2067 //*************************************************************************
2068 template <typename TPString>
2069 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0) ETL_NOEXCEPT
2070 : buffer()
2071 {
2072 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2073 }
2074
2075 //*************************************************************************
2077 //*************************************************************************
2078 template <typename TPString>
2079 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0) ETL_NOEXCEPT
2080 : buffer()
2081 {
2082 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2083 }
2084
2085 //*************************************************************************
2087 //*************************************************************************
2088 template <typename TPString>
2089 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char16_t*>::value>::type* = 0) ETL_NOEXCEPT
2090 : buffer()
2091 {
2092 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2093 }
2094
2095 //*************************************************************************
2097 //*************************************************************************
2098 template <typename TPString>
2099 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char32_t*>::value>::type* = 0) ETL_NOEXCEPT
2100 : buffer()
2101 {
2102 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2103 }
2104
2105 //*************************************************************************
2107 //*************************************************************************
2108 ETL_CONSTEXPR14 bitset& operator =(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2109 {
2110 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
2111
2112 return *this;
2113 }
2114
2115 //*************************************************************************
2117 //*************************************************************************
2118 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set() ETL_NOEXCEPT
2119 {
2120 implementation::set_all(buffer, Number_Of_Elements, Top_Mask);
2121
2122 return *this;
2123 }
2124
2125 //*************************************************************************
2127 //*************************************************************************
2128 ETL_CONSTEXPR14
2129 bitset<Active_Bits, TElement>& set(size_t position, bool value = true)
2130 {
2131 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2132
2133 implementation::set_position(buffer, position, value);
2134
2135 return *this;
2136 }
2137
2138 //*************************************************************************
2140 //*************************************************************************
2141 template <size_t Position>
2142 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set(bool value = true)
2143 {
2144 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2145
2147
2148 return *this;
2149 }
2150
2151 //*************************************************************************
2153 //*************************************************************************
2154 template <size_t Position, bool Value>
2156 {
2157 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2158
2160
2161 return *this;
2162 }
2163
2164 //*************************************************************************
2166 //*************************************************************************
2167 template <typename TPString>
2168 ETL_CONSTEXPR14
2170 set(TPString text) ETL_NOEXCEPT
2171 {
2172 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2173
2174 return *this;
2175 }
2176
2177 //*************************************************************************
2179 //*************************************************************************
2180 template <typename TPString>
2181 ETL_CONSTEXPR14
2183 set(TPString text) ETL_NOEXCEPT
2184 {
2185 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2186
2187 return *this;
2188 }
2189
2190 //*************************************************************************
2192 //*************************************************************************
2193 template <typename TPString>
2194 ETL_CONSTEXPR14
2196 set(TPString text) ETL_NOEXCEPT
2197 {
2198 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2199
2200 return *this;
2201 }
2202
2203 //*************************************************************************
2205 //*************************************************************************
2206 template <typename TPString>
2207 ETL_CONSTEXPR14
2209 set(TPString text) ETL_NOEXCEPT
2210 {
2211 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2212
2213 return *this;
2214 }
2215
2216 //*************************************************************************
2218 //*************************************************************************
2219 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
2220 {
2221 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2222
2223 return *this;
2224 }
2225
2226 //*************************************************************************
2228 //*************************************************************************
2229 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const wchar_t* text) ETL_NOEXCEPT
2230 {
2231 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2232
2233 return *this;
2234 }
2235
2236 //*************************************************************************
2238 //*************************************************************************
2239 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char16_t* text) ETL_NOEXCEPT
2240 {
2241 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2242
2243 return *this;
2244 }
2245
2246 //*************************************************************************
2248 //*************************************************************************
2249 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char32_t* text) ETL_NOEXCEPT
2250 {
2251 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2252
2253 return *this;
2254 }
2255
2256 //*************************************************************************
2258 //*************************************************************************
2259 template <typename T>
2260 ETL_CONSTEXPR14
2262 value() const ETL_NOEXCEPT
2263 {
2264 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2265 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
2266
2267 return implementation::template value<T>(buffer, Number_Of_Elements);
2268 }
2269
2270 //*************************************************************************
2273 //*************************************************************************
2274 template <typename T>
2275 ETL_CONSTEXPR14
2276 T extract(size_t position, size_t length = etl::integral_limits<T>::bits) const
2277 {
2278 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2279
2280 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
2281 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
2282
2283 return implementation::template extract<T>(buffer, position, length);
2284 }
2285
2286 //*************************************************************************
2289 //*************************************************************************
2290#if ETL_USING_CPP11
2292#else
2293 template <typename T, size_t Position, size_t Length>
2294#endif
2295 ETL_CONSTEXPR14
2296 T extract() const
2297 {
2298 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2299 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
2300 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
2301
2303 }
2304
2305 //*************************************************************************
2307 //*************************************************************************
2308 unsigned long to_ulong() const
2309 {
2311
2312 return implementation::template value<unsigned long>(buffer, Number_Of_Elements);
2313 }
2314
2315 //*************************************************************************
2317 //*************************************************************************
2318 unsigned long long to_ullong() const
2319 {
2321
2322 return implementation::template value<unsigned long long>(buffer, Number_Of_Elements);
2323 }
2324
2325 //*************************************************************************
2327 //*************************************************************************
2328 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset() ETL_NOEXCEPT
2329 {
2330 implementation::reset_all(buffer, Number_Of_Elements);
2331
2332 return *this;
2333 }
2334
2335 //*************************************************************************
2337 //*************************************************************************
2338 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset(size_t position)
2339 {
2340 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2341
2342 implementation::reset_position(buffer, position);
2343
2344 return *this;
2345 }
2346
2347 //*************************************************************************
2350 //*************************************************************************
2351 ETL_CONSTEXPR14 bool test(size_t position) const
2352 {
2353 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
2354
2355 return implementation::test(buffer, position);
2356 }
2357
2358 //*************************************************************************
2361 //*************************************************************************
2362 template <size_t Position>
2363 ETL_CONSTEXPR14 bool test() const
2364 {
2365 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2366
2367 return implementation::test(buffer, Position);
2368 }
2369
2370 //*************************************************************************
2372 //*************************************************************************
2373 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
2374 {
2375 return Active_Bits;
2376 }
2377
2378 //*************************************************************************
2380 //*************************************************************************
2381 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
2382 {
2383 return Number_Of_Elements;
2384 }
2385
2386 //*************************************************************************
2388 //*************************************************************************
2389 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
2390 {
2391 return All_Set_Element;
2392 }
2393
2394 //*************************************************************************
2396 //*************************************************************************
2397 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
2398 {
2399 return All_Clear_Element;
2400 }
2401
2402 //*************************************************************************
2404 //*************************************************************************
2405 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
2406 {
2407 return Bits_Per_Element;
2408 }
2409
2410 //*************************************************************************
2412 //*************************************************************************
2413 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
2414 {
2415 return Top_Mask;
2416 }
2417
2418 //*************************************************************************
2420 //*************************************************************************
2421 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
2422 {
2423 return Number_Of_Elements * Bits_Per_Element;
2424 }
2425
2426 //*************************************************************************
2430 //*************************************************************************
2431 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
2432 {
2433 return Storage_Model;
2434 }
2435
2436 //*************************************************************************
2438 //*************************************************************************
2439 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
2440 {
2441 return implementation::count(buffer, Number_Of_Elements);
2442 }
2443
2444 //*************************************************************************
2445 // Are all the bits sets?
2446 //*************************************************************************
2447 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
2448 {
2449 return implementation::all(buffer, Number_Of_Elements, Top_Mask);
2450 }
2451
2452 //*************************************************************************
2453 // Are all the mask bits sets?
2454 //*************************************************************************
2455 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
2456 {
2457 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2458
2459 return implementation::all(buffer, Number_Of_Elements, Top_Mask, mask);
2460 }
2461
2462 //*************************************************************************
2464 //*************************************************************************
2465 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
2466 {
2467 return implementation::none(buffer, Number_Of_Elements);
2468 }
2469
2470 //*************************************************************************
2472 //*************************************************************************
2473 ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
2474 {
2475 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2476
2477 return implementation::none(buffer, Number_Of_Elements, mask);
2478 }
2479
2480 //*************************************************************************
2482 //*************************************************************************
2483 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
2484 {
2485 return implementation::any(buffer, Number_Of_Elements);
2486 }
2487
2488 //*************************************************************************
2490 //*************************************************************************
2491 ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
2492 {
2493 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2494
2495 return implementation::any(buffer, Number_Of_Elements, mask);
2496 }
2497
2498 //*************************************************************************
2500 //*************************************************************************
2501 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip() ETL_NOEXCEPT
2502 {
2503 implementation::flip_all(buffer, Number_Of_Elements);
2504
2505 return *this;
2506 }
2507
2508 //*************************************************************************
2510 //*************************************************************************
2511 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip(size_t position)
2512 {
2513 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2514
2515 implementation::flip_position(buffer, position);
2516
2517 return *this;
2518 }
2519
2520 //*************************************************************************
2522 //*************************************************************************
2523 ETL_CONSTEXPR14 bool operator[] (size_t position) const ETL_NOEXCEPT
2524 {
2525 return implementation::test(buffer, position);
2526 }
2527
2528 //*************************************************************************
2530 //*************************************************************************
2531 ETL_CONSTEXPR14 bit_reference operator [] (size_t position) ETL_NOEXCEPT
2532 {
2533 return bit_reference(*this, position);
2534 }
2535
2536 //*************************************************************************
2538 //*************************************************************************
2539#if ETL_USING_CPP11
2540 template <typename TString = etl::string<Active_Bits>>
2541#else
2542 template <typename TString>
2543#endif
2544 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
2545 typename TString::value_type one = typename TString::value_type('1')) const
2546 {
2547 return implementation::template to_string<TString>(buffer, Active_Bits, zero, one);
2548 }
2549
2550 //*************************************************************************
2554 //*************************************************************************
2555 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
2556 {
2557 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, 0);
2558 }
2559
2560 //*************************************************************************
2565 //*************************************************************************
2566 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
2567 {
2568 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, position);
2569 }
2570
2571 //*************************************************************************
2573 //*************************************************************************
2575 {
2577
2578 implementation::operator_and(temp.buffer, other.buffer, Number_Of_Elements);
2579
2580 return temp;
2581 }
2582
2583 //*************************************************************************
2585 //*************************************************************************
2587 {
2588 implementation::operator_and(buffer, other.buffer, Number_Of_Elements);
2589
2590 return *this;
2591 }
2592
2593 //*************************************************************************
2595 //*************************************************************************
2597 {
2599
2600 implementation::operator_or(temp.buffer, other.buffer, Number_Of_Elements);
2601
2602 return temp;
2603 }
2604
2605 //*************************************************************************
2607 //*************************************************************************
2609 {
2610 implementation::operator_or(&buffer[0], &other.buffer[0], Number_Of_Elements);
2611
2612 return *this;
2613 }
2614
2615 //*************************************************************************
2617 //*************************************************************************
2619 {
2621
2622 implementation::operator_xor(temp.buffer, other.buffer, Number_Of_Elements);
2623
2624 return temp;
2625 }
2626
2627 //*************************************************************************
2629 //*************************************************************************
2631 {
2632 implementation::operator_xor(buffer, other.buffer, Number_Of_Elements);
2633
2634 return *this;
2635 }
2636
2637 //*************************************************************************
2639 //*************************************************************************
2640 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator ~() const ETL_NOEXCEPT
2641 {
2643
2644 implementation::flip_all(temp.buffer, Number_Of_Elements);
2645
2646 return temp;
2647 }
2648
2649 //*************************************************************************
2651 //*************************************************************************
2652 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator <<(size_t shift) const ETL_NOEXCEPT
2653 {
2655
2656 implementation::operator_shift_left(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2657
2658 return temp;
2659 }
2660
2661 //*************************************************************************
2663 //*************************************************************************
2664 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator <<=(size_t shift) ETL_NOEXCEPT
2665 {
2666 if (shift >= Active_Bits)
2667 {
2668 implementation::reset_all(buffer, Number_Of_Elements);
2669 }
2670 else
2671 {
2672 implementation::operator_shift_left(buffer, Number_Of_Elements, Active_Bits, shift);
2673 }
2674
2675 return *this;
2676 }
2677
2678 //*************************************************************************
2680 //*************************************************************************
2681 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator >>(size_t shift) const ETL_NOEXCEPT
2682 {
2684
2685 implementation::operator_shift_right(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2686
2687 return temp;
2688 }
2689
2690 //*************************************************************************
2692 //*************************************************************************
2693 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator >>=(size_t shift) ETL_NOEXCEPT
2694 {
2695 if (shift >= Active_Bits)
2696 {
2697 implementation::reset_all(buffer, Number_Of_Elements);
2698 }
2699 else
2700 {
2701 implementation::operator_shift_right(buffer, Number_Of_Elements, Active_Bits, shift);
2702 }
2703
2704 return *this;
2705 }
2706
2707 //*************************************************************************
2709 //*************************************************************************
2710 friend ETL_CONSTEXPR14 bool operator ==(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2711 {
2712 return implementation::operator_equality(lhs.buffer, rhs.buffer, lhs.Number_Of_Elements);
2713 }
2714
2715 //*************************************************************************
2717 //*************************************************************************
2718 friend ETL_CONSTEXPR14 bool operator !=(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2719 {
2720 return !(lhs == rhs);
2721 }
2722
2723 //*************************************************************************
2725 //*************************************************************************
2726 ETL_CONSTEXPR14 void swap(etl::bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2727 {
2728 implementation::swap(buffer, other.buffer, Number_Of_Elements);
2729 }
2730
2731 //*************************************************************************
2734 //*************************************************************************
2735 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
2736 {
2737 return span_type(buffer, Number_Of_Elements);
2738 }
2739
2740 //*************************************************************************
2743 //*************************************************************************
2744 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
2745 {
2746 return const_span_type(buffer, Number_Of_Elements);
2747 }
2748
2749 private:
2750
2751 // The implementation of the bitset functionality.
2752 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi> implementation;
2753
2754 // The storage for the bitset.
2755 element_type buffer[Number_Of_Elements];
2756 };
2757
2758 //***************************************************************************
2761 //***************************************************************************
2762 template <size_t Active_Bits, typename TElement>
2764 {
2766 temp &= rhs;
2767 return temp;
2768 }
2769
2770 //***************************************************************************
2773 //***************************************************************************
2774 template<size_t Active_Bits, typename TElement>
2776 {
2778 temp |= rhs;
2779 return temp;
2780 }
2781
2782 //***************************************************************************
2785 //***************************************************************************
2786 template<size_t Active_Bits, typename TElement>
2788 {
2790 temp ^= rhs;
2791 return temp;
2792 }
2793}
2794
2795//***************************************************************************
2798//***************************************************************************
2799template<size_t Active_Bits, typename TElement>
2800ETL_CONSTEXPR14 bool operator != (const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2801{
2802 return !(lhs == rhs);
2803}
2804
2805//*************************************************************************
2807//*************************************************************************
2808template <size_t Active_Bits, typename TElement>
2809ETL_CONSTEXPR14 void swap(etl::bitset<Active_Bits, TElement>& lhs, etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2810{
2811 lhs.swap(rhs);
2812}
2813
2814//***************************************************************************
2816//***************************************************************************
2817namespace etl
2818{
2819 //***************************************************************************
2820 template <size_t Active_Bits = 0U,
2821 typename TElement = unsigned char>
2822 class bitset_ext;
2823
2824 //***************************************************************************
2826 //***************************************************************************
2827 template <>
2828 class bitset_ext<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
2829 {
2830 public:
2831
2832 typedef size_t size_type;
2833
2837
2838 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
2839 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
2840 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
2841 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
2842 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
2843 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
2844 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
2845 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
2846 };
2847
2848 //*************************************************************************
2850 //*************************************************************************
2851 template <size_t Active_Bits, typename TElement>
2852 class bitset_ext : public etl::private_bitset::bitset_common<Active_Bits, TElement>
2853 {
2854 public:
2855
2856 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
2857
2858 typedef size_t size_type;
2859
2863
2864 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
2865 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
2866 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
2867 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
2868 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
2869 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
2870 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
2871 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
2872
2873 typedef etl::array<TElement, Number_Of_Elements> buffer_type;
2874
2875 //*************************************************************************
2877 //*************************************************************************
2879 {
2880 public:
2881
2882 friend class bitset_ext;
2883
2884 //*******************************
2886 //*******************************
2887 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
2888 : p_bitset(other.p_bitset)
2889 , position(other.position)
2890 {
2891 }
2892
2893 //*******************************
2895 //*******************************
2896 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
2897 {
2898 return p_bitset->test(position);
2899 }
2900
2901 //*******************************
2903 //*******************************
2904 ETL_CONSTEXPR14 bit_reference& operator = (bool b) ETL_NOEXCEPT
2905 {
2906 p_bitset->set(position, b);
2907 return *this;
2908 }
2909
2910 //*******************************
2912 //*******************************
2913 ETL_CONSTEXPR14 bit_reference& operator = (const bit_reference& r) ETL_NOEXCEPT
2914 {
2915 p_bitset->set(position, bool(r));
2916 return *this;
2917 }
2918
2919 //*******************************
2921 //*******************************
2922 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
2923 {
2924 p_bitset->flip(position);
2925 return *this;
2926 }
2927
2928 //*******************************
2930 //*******************************
2931 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
2932 {
2933 return !p_bitset->test(position);
2934 }
2935
2936 private:
2937
2938 //*******************************
2940 //*******************************
2941 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
2942 : p_bitset(ETL_NULLPTR)
2943 , position(0)
2944 {
2945 }
2946
2947 //*******************************
2949 //*******************************
2950 ETL_CONSTEXPR14 bit_reference(bitset_ext<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
2951 : p_bitset(&r_bitset)
2952 , position(position_)
2953 {
2954 }
2955
2956 bitset_ext<Active_Bits, TElement>* p_bitset;
2957 size_t position;
2958 };
2959
2960 //*************************************************************************
2962 //*************************************************************************
2963 ETL_CONSTEXPR14 explicit bitset_ext(element_type* pbuffer_)
2964 : pbuffer(pbuffer_)
2965 {
2966 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2967 implementation::reset_all(pbuffer, Number_Of_Elements);
2968 }
2969
2970 //*************************************************************************
2972 //*************************************************************************
2973 ETL_CONSTEXPR14 explicit bitset_ext(buffer_type& buffer)
2974 : pbuffer(buffer.data())
2975 {
2976 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2977 implementation::reset_all(pbuffer, Number_Of_Elements);
2978 }
2979
2980 //*************************************************************************
2982 //*************************************************************************
2983 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, element_type* pbuffer_)
2984 : pbuffer(pbuffer_)
2985 {
2986 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2987 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2988 }
2989
2990 //*************************************************************************
2992 //*************************************************************************
2993 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, buffer_type& buffer) ETL_NOEXCEPT
2994 : pbuffer(buffer.data())
2995 {
2996 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2997 }
2998
2999 //*************************************************************************
3001 //*************************************************************************
3002 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT ETL_DELETE;
3003
3004 //*************************************************************************
3006 //*************************************************************************
3007 ETL_CONSTEXPR14 bitset_ext(unsigned long long value, element_type* pbuffer_)
3008 : pbuffer(pbuffer_)
3009 {
3010 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3011 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value);
3012 }
3013
3014 //*************************************************************************
3016 //*************************************************************************
3017 template <typename TValue>
3018 ETL_CONSTEXPR14 bitset_ext(TValue value, buffer_type& buffer, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
3019 : pbuffer(buffer.data())
3020 {
3021 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value);
3022 }
3023
3024 //*************************************************************************
3026 //*************************************************************************
3027 template <typename TPString>
3028 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0)
3029 : pbuffer(pbuffer_)
3030 {
3031 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3032 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3033 }
3034
3035 //*************************************************************************
3037 //*************************************************************************
3038 template <typename TPString>
3039 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0) ETL_NOEXCEPT
3040 : pbuffer(buffer.data())
3041 {
3042 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3043 }
3044
3045 //*************************************************************************
3047 //*************************************************************************
3048 template <typename TPString>
3049 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0)
3050 : pbuffer(pbuffer_)
3051 {
3052 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3053 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3054 }
3055
3056 //*************************************************************************
3058 //*************************************************************************
3059 template <typename TPString>
3060 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0) ETL_NOEXCEPT
3061 : pbuffer(buffer.data())
3062 {
3063 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3064 }
3065
3066 //*************************************************************************
3068 //*************************************************************************
3069 template <typename TPString>
3070 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char16_t*>::value>::type* = 0)
3071 : pbuffer(pbuffer_)
3072 {
3073 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3074 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3075 }
3076
3077 //*************************************************************************
3079 //*************************************************************************
3080 template <typename TPString>
3081 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char16_t*>::value>::type* = 0) ETL_NOEXCEPT
3082 : pbuffer(buffer.data())
3083 {
3084 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3085 }
3086
3087 //*************************************************************************
3089 //*************************************************************************
3090 template <typename TPString>
3091 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char32_t*>::value>::type* = 0)
3092 : pbuffer(pbuffer_)
3093 {
3094 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3095 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3096 }
3097
3098 //*************************************************************************
3100 //*************************************************************************
3101 template <typename TPString>
3102 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char32_t*>::value>::type* = 0) ETL_NOEXCEPT
3103 : pbuffer(buffer.data())
3104 {
3105 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3106 }
3107
3108 //*************************************************************************
3110 //*************************************************************************
3111 ETL_CONSTEXPR14 bitset_ext& operator =(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3112 {
3113 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
3114
3115 return *this;
3116 }
3117
3118 //*************************************************************************
3120 //*************************************************************************
3121 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set() ETL_NOEXCEPT
3122 {
3123 implementation::set_all(pbuffer, Number_Of_Elements, Top_Mask);
3124
3125 return *this;
3126 }
3127
3128 //*************************************************************************
3130 //*************************************************************************
3131 ETL_CONSTEXPR14
3132 bitset_ext<Active_Bits, TElement>& set(size_t position, bool value = true)
3133 {
3134 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3135
3136 implementation::set_position(pbuffer, position, value);
3137
3138 return *this;
3139 }
3140
3141 //*************************************************************************
3143 //*************************************************************************
3144 template <size_t Position>
3145 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set(bool value = true)
3146 {
3147 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3148
3149 implementation::template set_position<Position>(pbuffer, value);
3150
3151 return *this;
3152 }
3153
3154 //*************************************************************************
3156 //*************************************************************************
3157 template <size_t Position, bool Value>
3158 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set()
3159 {
3160 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3161
3162 implementation::template set_position<Position, Value>(pbuffer);
3163
3164 return *this;
3165 }
3166
3167 //*************************************************************************
3169 //*************************************************************************
3170 template <typename TPString>
3171 ETL_CONSTEXPR14
3172 typename etl::enable_if<etl::is_same<TPString, const char*>::value, bitset_ext<Active_Bits, TElement>&>::type
3173 set(TPString text) ETL_NOEXCEPT
3174 {
3175 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3176
3177 return *this;
3178 }
3179
3180 //*************************************************************************
3182 //*************************************************************************
3183 template <typename TPString>
3184 ETL_CONSTEXPR14
3185 typename etl::enable_if<etl::is_same<TPString, const wchar_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
3186 set(TPString text) ETL_NOEXCEPT
3187 {
3188 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3189
3190 return *this;
3191 }
3192
3193 //*************************************************************************
3195 //*************************************************************************
3196 template <typename TPString>
3197 ETL_CONSTEXPR14
3198 typename etl::enable_if<etl::is_same<TPString, const char16_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
3199 set(TPString text) ETL_NOEXCEPT
3200 {
3201 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3202
3203 return *this;
3204 }
3205
3206 //*************************************************************************
3208 //*************************************************************************
3209 template <typename TPString>
3210 ETL_CONSTEXPR14
3211 typename etl::enable_if<etl::is_same<TPString, const char32_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
3212 set(TPString text) ETL_NOEXCEPT
3213 {
3214 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3215
3216 return *this;
3217 }
3218
3219 //*************************************************************************
3221 //*************************************************************************
3222 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
3223 {
3224 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3225
3226 return *this;
3227 }
3228
3229 //*************************************************************************
3231 //*************************************************************************
3232 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const wchar_t* text) ETL_NOEXCEPT
3233 {
3234 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3235
3236 return *this;
3237 }
3238
3239 //*************************************************************************
3241 //*************************************************************************
3242 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char16_t* text) ETL_NOEXCEPT
3243 {
3244 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3245
3246 return *this;
3247 }
3248
3249 //*************************************************************************
3251 //*************************************************************************
3252 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char32_t* text) ETL_NOEXCEPT
3253 {
3254 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3255
3256 return *this;
3257 }
3258
3259 //*************************************************************************
3261 //*************************************************************************
3262 template <typename T>
3263 ETL_CONSTEXPR14
3264 T value() const ETL_NOEXCEPT
3265 {
3266 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3267 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
3268
3269 return implementation::template value<T>(pbuffer, Number_Of_Elements);
3270 }
3271
3272 //*************************************************************************
3275 //*************************************************************************
3276 template <typename T>
3277 ETL_CONSTEXPR14
3278 T extract(size_t position, size_t length = etl::integral_limits<T>::bits)
3279 {
3280 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3281
3282 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
3283 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
3284
3285 return implementation::template extract<T>(pbuffer, position, length);
3286 }
3287
3288 //*************************************************************************
3291 //*************************************************************************
3292#if ETL_USING_CPP11
3293 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
3294#else
3295 template <typename T, size_t Position, size_t Length>
3296#endif
3297 ETL_CONSTEXPR14
3298 T extract() const
3299 {
3300 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3301 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
3302 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
3303
3304 return implementation::template extract<T, Position, Length>(pbuffer);
3305 }
3306
3307 //*************************************************************************
3309 //*************************************************************************
3310 unsigned long to_ulong() const
3311 {
3313
3314 return implementation::template value<unsigned long>(pbuffer, Number_Of_Elements);
3315 }
3316
3317 //*************************************************************************
3319 //*************************************************************************
3320 unsigned long long to_ullong() const
3321 {
3323
3324 return implementation::template value<unsigned long long>(pbuffer, Number_Of_Elements);
3325 }
3326
3327 //*************************************************************************
3329 //*************************************************************************
3330 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset() ETL_NOEXCEPT
3331 {
3332 implementation::reset_all(pbuffer, Number_Of_Elements);
3333
3334 return *this;
3335 }
3336
3337 //*************************************************************************
3339 //*************************************************************************
3340 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset(size_t position)
3341 {
3342 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3343
3344 implementation::reset_position(pbuffer, position);
3345
3346 return *this;
3347 }
3348
3349 //*************************************************************************
3352 //*************************************************************************
3353 ETL_CONSTEXPR14 bool test(size_t position) const
3354 {
3355 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
3356
3357 return implementation::test(pbuffer, position);
3358 }
3359
3360 //*************************************************************************
3363 //*************************************************************************
3364 template <size_t Position>
3365 ETL_CONSTEXPR14 bool test() const
3366 {
3367 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3368
3369 return implementation::test(pbuffer, Position);
3370 }
3371
3372 //*************************************************************************
3374 //*************************************************************************
3375 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
3376 {
3377 return Active_Bits;
3378 }
3379
3380 //*************************************************************************
3382 //*************************************************************************
3383 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
3384 {
3385 return Number_Of_Elements;
3386 }
3387
3388 //*************************************************************************
3390 //*************************************************************************
3391 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
3392 {
3393 return All_Set_Element;
3394 }
3395
3396 //*************************************************************************
3398 //*************************************************************************
3399 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
3400 {
3401 return All_Clear_Element;
3402 }
3403
3404 //*************************************************************************
3406 //*************************************************************************
3407 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
3408 {
3409 return Top_Mask;
3410 }
3411
3412 //*************************************************************************
3414 //*************************************************************************
3415 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
3416 {
3417 return Bits_Per_Element;
3418 }
3419
3420 //*************************************************************************
3422 //*************************************************************************
3423 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
3424 {
3425 return Number_Of_Elements * Bits_Per_Element;
3426 }
3427
3428 //*************************************************************************
3432 //*************************************************************************
3433 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
3434 {
3435 return Storage_Model;
3436 }
3437
3438 //*************************************************************************
3440 //*************************************************************************
3441 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
3442 {
3443 return implementation::count(pbuffer, Number_Of_Elements);
3444 }
3445
3446 //*************************************************************************
3447 // Are all the bits sets?
3448 //*************************************************************************
3449 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
3450 {
3451 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask);
3452 }
3453
3454 //*************************************************************************
3455 // Are all the mask bits sets?
3456 //*************************************************************************
3457 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
3458 {
3459 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3460
3461 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask, mask);
3462 }
3463
3464 //*************************************************************************
3466 //*************************************************************************
3467 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
3468 {
3469 return implementation::none(pbuffer, Number_Of_Elements);
3470 }
3471
3472 //*************************************************************************
3474 //*************************************************************************
3475 ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
3476 {
3477 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3478
3479 return implementation::none(pbuffer, Number_Of_Elements, mask);
3480 }
3481
3482 //*************************************************************************
3484 //*************************************************************************
3485 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
3486 {
3487 return implementation::any(pbuffer, Number_Of_Elements);
3488 }
3489
3490 //*************************************************************************
3492 //*************************************************************************
3493 ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
3494 {
3495 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3496
3497 return implementation::any(pbuffer, Number_Of_Elements, mask);
3498 }
3499
3500 //*************************************************************************
3502 //*************************************************************************
3503 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip() ETL_NOEXCEPT
3504 {
3505 implementation::flip_all(pbuffer, Number_Of_Elements);
3506
3507 return *this;
3508 }
3509
3510 //*************************************************************************
3512 //*************************************************************************
3513 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip(size_t position)
3514 {
3515 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3516
3517 implementation::flip_position(pbuffer, position);
3518
3519 return *this;
3520 }
3521
3522 //*************************************************************************
3524 //*************************************************************************
3525 ETL_CONSTEXPR14 bool operator[] (size_t position) const ETL_NOEXCEPT
3526 {
3527 return implementation::test(pbuffer, position);
3528 }
3529
3530 //*************************************************************************
3532 //*************************************************************************
3533 ETL_CONSTEXPR14 bit_reference operator [] (size_t position) ETL_NOEXCEPT
3534 {
3535 return bit_reference(*this, position);
3536 }
3537
3538 //*************************************************************************
3540 //*************************************************************************
3541#if ETL_USING_CPP11
3542 template <typename TString = etl::string<Active_Bits>>
3543#else
3544 template <typename TString>
3545#endif
3546 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
3547 typename TString::value_type one = typename TString::value_type('1')) const
3548 {
3549 return implementation::template to_string<TString>(pbuffer, Active_Bits, zero, one);
3550 }
3551
3552 //*************************************************************************
3556 //*************************************************************************
3557 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
3558 {
3559 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, 0);
3560 }
3561
3562 //*************************************************************************
3567 //*************************************************************************
3568 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
3569 {
3570 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, position);
3571 }
3572
3573 //*************************************************************************
3575 //*************************************************************************
3576 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator &=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3577 {
3578 implementation::operator_and(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3579
3580 return *this;
3581 }
3582
3583 //*************************************************************************
3585 //*************************************************************************
3586 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator |=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3587 {
3588 implementation::operator_or(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3589
3590 return *this;
3591 }
3592
3593 //*************************************************************************
3595 //*************************************************************************
3596 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator ^=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3597 {
3598 implementation::operator_xor(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3599
3600 return *this;
3601 }
3602
3603 //*************************************************************************
3605 //*************************************************************************
3606 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator <<=(size_t shift) ETL_NOEXCEPT
3607 {
3608 implementation::operator_shift_left(pbuffer, Number_Of_Elements, Active_Bits, shift);
3609
3610 return *this;
3611 }
3612
3613 //*************************************************************************
3615 //*************************************************************************
3616 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator >>=(size_t shift) ETL_NOEXCEPT
3617 {
3618 implementation::operator_shift_right(pbuffer, Number_Of_Elements, Active_Bits, shift);
3619
3620 return *this;
3621 }
3622
3623 //*************************************************************************
3625 //*************************************************************************
3626 friend ETL_CONSTEXPR14 bool operator ==(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3627 {
3628 return implementation::operator_equality(lhs.pbuffer, rhs.pbuffer, lhs.Number_Of_Elements);
3629 }
3630
3631 //*************************************************************************
3633 //*************************************************************************
3634 friend ETL_CONSTEXPR14 bool operator !=(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3635 {
3636 return !(lhs == rhs);
3637 }
3638
3639 //*************************************************************************
3641 //*************************************************************************
3642 ETL_CONSTEXPR14 void swap(etl::bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3643 {
3644 implementation::swap(pbuffer, other.pbuffer, Number_Of_Elements);
3645 }
3646
3647 //*************************************************************************
3650 //*************************************************************************
3651 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
3652 {
3653 return span_type(pbuffer, Number_Of_Elements);
3654 }
3655
3656 //*************************************************************************
3659 //*************************************************************************
3660 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
3661 {
3662 return const_span_type(pbuffer, Number_Of_Elements);
3663 }
3664
3665 private:
3666
3667 // The implementation of the bitset functionality.
3668 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi> implementation;
3669
3670 // Pointer to the storage for the bitset.
3671 element_type* pbuffer;
3672 };
3673}
3674
3675//***************************************************************************
3678//***************************************************************************
3679template<size_t Active_Bits, typename TElement>
3681{
3682 return !(lhs == rhs);
3683}
3684
3685//*************************************************************************
3687//*************************************************************************
3688template <size_t Active_Bits, typename TElement>
3690{
3691 lhs.swap(rhs);
3692}
3693
3694namespace etl
3695{
3696 namespace private_bitset
3697 {
3698 //*************************************************************************
3701 //*************************************************************************
3702 template <typename TLhsSpan, typename TRhsSpan>
3703 bool compare_bitset_spans(const TLhsSpan& lhs_span, const TRhsSpan& rhs_span)
3704 {
3705 typedef typename TLhsSpan::value_type lhs_element_t;
3706 typedef typename TRhsSpan::value_type rhs_element_t;
3707
3708 const int steps = static_cast<int>(sizeof(lhs_element_t) / sizeof(rhs_element_t));
3709
3710 typename TLhsSpan::iterator lhs_itr = lhs_span.begin();
3711 typename TRhsSpan::iterator rhs_itr = rhs_span.begin();
3712
3713 while (lhs_itr != lhs_span.end())
3714 {
3715 const lhs_element_t& lhs_value = *lhs_itr;
3716
3717 // Build the rhs element in terms of the lhs element type.
3718 lhs_element_t rhs_value = 0;
3719
3720 const int shift_step = etl::integral_limits<rhs_element_t>::bits;
3721 int shift = 0;
3722
3723 for (int i = 0; i < steps; ++i)
3724 {
3725 rhs_value |= (static_cast<lhs_element_t>(*rhs_itr) << shift);
3726 ++rhs_itr;
3727 shift += shift_step;
3728 }
3729
3730 if (lhs_value != rhs_value)
3731 {
3732 return false;
3733 }
3734
3735 ++lhs_itr;
3736 }
3737
3738 return true;
3739 }
3740 }
3741}
3742
3743//***************************************************************************
3748//***************************************************************************
3749template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3750ETL_CONSTEXPR14
3753{
3754 // Get a span of each type.
3755 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3756 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3757
3758 // Put the bitset with the largest element type as the first argument.
3759 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3760 {
3761 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3762 }
3763 else
3764 {
3765 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3766 }
3767}
3768
3769//***************************************************************************
3774//***************************************************************************
3775template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3776ETL_CONSTEXPR14
3779{
3780 return !(lhs == rhs);
3781}
3782
3783//***************************************************************************
3788//***************************************************************************
3789template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3790ETL_CONSTEXPR14
3793{
3794 // Get a span of each type.
3797
3798 // Put the bitset with the largest element type as the first argument.
3799 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3800 {
3801 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3802 }
3803 else
3804 {
3805 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3806 }
3807}
3808
3809//***************************************************************************
3814//***************************************************************************
3815template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3816ETL_CONSTEXPR14
3819{
3820 return !(lhs == rhs);
3821}
3822
3823//***************************************************************************
3827//***************************************************************************
3828template<size_t Active_Bits, typename TElement>
3829ETL_CONSTEXPR14
3831{
3832 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3833 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3834
3835 typename etl::bitset<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3836 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3837
3838 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3839
3840 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3841}
3842
3843//***************************************************************************
3847//***************************************************************************
3848template<size_t Active_Bits, typename TElement>
3849ETL_CONSTEXPR14
3851{
3852 return !(lhs == rhs);
3853}
3854
3855//***************************************************************************
3859//***************************************************************************
3860template<size_t Active_Bits, typename TElement>
3861ETL_CONSTEXPR14
3863{
3864 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3865 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3866
3867 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3868 typename etl::bitset<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3869
3870 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3871
3872 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3873}
3874
3875//***************************************************************************
3879//***************************************************************************
3880template<size_t Active_Bits, typename TElement>
3881ETL_CONSTEXPR14
3883{
3884 return !(lhs == rhs);
3885}
3886
3887//***************************************************************************
3891//***************************************************************************
3892template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3893ETL_CONSTEXPR14
3896{
3897 // Get a span of each type.
3898 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3900
3901 // Put the bitset with the largest element type as the first argument.
3902 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3903 {
3904 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3905 }
3906 else
3907 {
3908 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3909 }
3910}
3911
3912//***************************************************************************
3916//***************************************************************************
3917template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3918ETL_CONSTEXPR14
3921{
3922 return !(lhs == rhs);
3923}
3924
3925//***************************************************************************
3929//***************************************************************************
3930template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3931ETL_CONSTEXPR14
3934{
3935 // Get a span of each type.
3937 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3938
3939 // Put the bitset with the largest element type as the first argument.
3940 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3941 {
3942 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3943 }
3944 else
3945 {
3946 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3947 }
3948}
3949
3950//***************************************************************************
3954//***************************************************************************
3955template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3956ETL_CONSTEXPR14
3959{
3960 return !(lhs == rhs);
3961}
3962
3963#include "minmax_pop.h"
3964
3965#endif
The reference type returned.
Definition bitset_new.h:1956
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:1964
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1981
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:1999
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:2008
The reference type returned.
Definition bitset_new.h:2879
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2904
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:2922
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:2931
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:2887
Definition binary.h:2216
Definition binary.h:2249
Definition bitset_new.h:1845
Definition bitset_new.h:168
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:968
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value &&etl::is_unsigned< T >::value &&(etl::integral_limits< T >::bits==16U), uint_least8_t >::type count_bits(T value)
Definition binary.h:922
Definition binary.h:353
static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator_equality
Definition bitset_new.h:1766
static ETL_CONSTEXPR14 etl::make_unsigned< T >::type extract_from_multiple_elements(const element_type *pbuffer, int element_index, size_t active_bits_in_msb, size_t length) ETL_NOEXCEPT
Extract an value from multiple elements.
Definition bitset_new.h:1273
ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:2473
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:1424
bitset< MaxN > & operator&=(const bitset< MaxN > &other)
operator &=
Definition bitset_legacy.h:1391
ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
Definition bitset_new.h:2566
static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t number_of_elements, size_t total_bits, bool state, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:1471
ETL_CONSTEXPR14 T extract(size_t position, size_t length=etl::integral_limits< T >::bits) const
Definition bitset_new.h:2276
static ETL_CONSTEXPR14 void set_all(pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
Set all bits.
Definition bitset_new.h:995
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:2129
static ETL_CONSTEXPR14 etl::enable_if< value_is_in_one_element< Position, Length, Bits_Per_Element >::value, typenameetl::make_unsigned< T >::type >::type extract_from_buffer(const_pointer pbuffer)
Definition bitset_new.h:1366
static ETL_CONSTEXPR14 etl::make_unsigned< T >::type extract_from_buffer(const_pointer pbuffer, size_t position, size_t length) ETL_NOEXCEPT
Definition bitset_new.h:1325
ETL_CONSTEXPR14 bitset(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:2049
static ETL_CONSTEXPR14 void swap(pointer lhs_pbuffer, pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
swap
Definition bitset_new.h:847
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar16_t * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a char16 string.
Definition bitset_new.h:2196
friend bool operator==(const bitset< MaxN > &lhs, const bitset< MaxN > &rhs)
operator ==
Definition bitset_legacy.h:1472
static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position)
Reset the bit at the position.
Definition bitset_new.h:312
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t) ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:615
static ETL_CONSTEXPR14 etl::enable_if<!value_is_in_one_element< Position, Length, Bits_Per_Element >::value, typenameetl::make_unsigned< T >::type >::type extract_from_buffer(const_pointer pbuffer)
Definition bitset_new.h:1385
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t, element_type mask) ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:603
static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
The value of a set element.
Definition bitset_new.h:2389
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:238
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:2249
bitset< MaxN > & flip()
Flip all of the bits.
Definition bitset_legacy.h:1336
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:1077
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:498
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:2239
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:1443
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set() ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:2118
static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t, size_t active_bits, bool state, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:678
static ETL_CONSTEXPR14 void initialise(pointer pbuffer, size_t, unsigned long long value) ETL_NOEXCEPT
Initialise from an unsigned long long.
Definition bitset_new.h:835
static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits, typename TString::value_type zero, typename TString::value_type one)
Returns a string representing the bitset.
Definition bitset_new.h:1528
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:2501
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:2219
ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
Definition bitset_new.h:2744
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:1112
ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:2465
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const char16_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2089
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position)
Flip the bit at the position.
Definition bitset_new.h:637
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:1147
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator&(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator &
Definition bitset_new.h:2574
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value=true)
Set the bit at the position.
Definition bitset_new.h:1035
static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator assignment
Definition bitset_new.h:1553
static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t, element_type mask) ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:580
ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
Definition bitset_new.h:2555
static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
Set the bit at the position.
Definition bitset_new.h:1057
ETL_CONSTEXPR14 bitset(TValue value, typename etl::enable_if< is_integral< TValue >::value >::type *=0) ETL_NOEXCEPT
Construct from a value.
Definition bitset_new.h:2059
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:2229
static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator and
Definition bitset_new.h:1570
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip(size_t position)
Flip the bit at the position.
Definition bitset_new.h:2511
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:1307
static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
The number of storage elements in the bitset.
Definition bitset_new.h:2381
static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:909
static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:745
ETL_CONSTEXPR14 void swap(etl::bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
swap
Definition bitset_new.h:2726
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length=etl::integral_limits< T >::bits)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:1402
ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero=typename TString::value_type('0'), typename TString::value_type one=typename TString::value_type('1')) const
Returns a string representing the bitset.
Definition bitset_new.h:2544
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:357
static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
The total number of bits of storage, including unused.
Definition bitset_new.h:2421
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_left
Definition bitset_new.h:1636
static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
The mask for the msb element.
Definition bitset_new.h:2413
static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator or
Definition bitset_new.h:1587
static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_right
Definition bitset_new.h:802
ETL_CONSTEXPR14 bool test(size_t position) const
Definition bitset_new.h:2351
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value, T >::type value() const ETL_NOEXCEPT
Get as an integral value.
Definition bitset_new.h:2262
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:592
ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:2491
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const char32_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2099
static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
The value of a clear element.
Definition bitset_new.h:2397
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset() ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:2328
static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:1217
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:324
bitset< MaxN > & operator<<=(size_t shift)
operator <<=
Definition bitset_legacy.h:1442
bitset< MaxN > operator<<(size_t shift) const
operator <<
Definition bitset_legacy.h:1430
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_left
Definition bitset_new.h:782
static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:758
static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Get as a value.
Definition bitset_new.h:1246
static ETL_CONSTEXPR14 void flip_bits(pointer pbuffer, element_type mask=etl::integral_limits< element_type >::max) ETL_NOEXCEPT
Flip some of the bits.
Definition bitset_new.h:626
static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:954
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Flip the bit at the position.
Definition bitset_new.h:1454
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator|(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator |
Definition bitset_new.h:2596
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value=true) ETL_NOEXCEPT
Set the bit at the position.
Definition bitset_new.h:1012
static ETL_CONSTEXPR14 void swap(pointer pbuffer1, pointer pbuffer2, size_t number_of_elements)
Swap bitset buffers.
Definition bitset_new.h:1832
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator not
Definition bitset_new.h:1621
bitset< MaxN > & operator|=(const bitset< MaxN > &other)
operator |=
Definition bitset_legacy.h:1400
static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
The number of bits in an element.
Definition bitset_new.h:2405
ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:2439
static ETL_CONSTEXPR14 etl::enable_if< etl::integral_limits< TElementType >::bits==etl::integral_limits< unsignedlonglong >::bits, void >::type initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
Definition bitset_new.h:1781
bitset< MaxN > operator~() const
operator ~
Definition bitset_legacy.h:1418
static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Get as an integral value.
Definition bitset_new.h:457
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(bool value=true)
Set the bit at the position.
Definition bitset_new.h:2142
friend ETL_CONSTEXPR14 bool operator!=(const bitset< Active_Bits, TElement > &lhs, const bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator !=
Definition bitset_new.h:2718
ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
Read [] operator.
Definition bitset_new.h:2523
static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t) ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:300
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const wchar_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2079
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:2170
bitset< MaxN > operator>>(size_t shift) const
operator >>
Definition bitset_legacy.h:1451
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:973
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position)
Definition bitset_new.h:521
static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Reset the bit at the position.
Definition bitset_new.h:1231
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator^(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator ^
Definition bitset_new.h:2618
static ETL_CONSTEXPR14 void set_all(pointer pbuffer, size_t, element_type top_mask) ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:226
static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:569
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:1182
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset(size_t position)
Reset the bit at the position.
Definition bitset_new.h:2338
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constwchar_t * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:2183
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
The number of bits in the bitset.
Definition bitset_new.h:2373
bitset< MaxN > & operator=(const bitset< MaxN > &other)
operator =
Definition bitset_legacy.h:1378
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const char * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2069
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:423
static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_right
Definition bitset_new.h:1700
bitset< MaxN > & operator^=(const bitset< MaxN > &other)
operator ^=
Definition bitset_legacy.h:1409
static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:732
static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
Set the bit at the position.
Definition bitset_new.h:281
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set()
Set the bit at the position.
Definition bitset_new.h:2155
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length=etl::integral_limits< T >::bits)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:469
unsigned long long to_ullong() const
Get as an unsigned long long.
Definition bitset_new.h:2318
ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:2483
static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
operator_equality
Definition bitset_new.h:822
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:2363
ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
Definition bitset_new.h:2735
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:390
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value=true)
Set the bit at the position.
Definition bitset_new.h:260
unsigned long to_ulong() const
Get as an unsigned long.
Definition bitset_new.h:2308
static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator xor
Definition bitset_new.h:1604
static ETL_CONSTEXPR14 etl::enable_if< etl::integral_limits< TElementType >::bits!=etl::integral_limits< unsignedlonglong >::bits, void >::type initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
Definition bitset_new.h:1805
static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:533
static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:719
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:895
ETL_CONSTEXPR14 T extract() const
Definition bitset_new.h:2296
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:771
bitset< MaxN > & set()
Set all of the bits.
Definition bitset_legacy.h:1207
static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits, typename TString::value_type zero=typename TString::value_type('0'), typename TString::value_type one=typename TString::value_type('1'))
Returns a string representing the bitset.
Definition bitset_new.h:650
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar32_t * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a char32 string.
Definition bitset_new.h:2209
ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
Default constructor.
Definition bitset_new.h:2040
bitset< MaxN > & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:1463
static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
Definition bitset_new.h:2431
Bitset forward declaration.
Definition bitset_legacy.h:1130
Definition bitset_legacy.h:85
Definition bitset_new.h:200
Definition bitset_new.h:154
Definition bitset_legacy.h:127
Definition bitset_new.h:126
ETL_CONSTEXPR14 bool operator!=(const etl::bitset< Active_Bits, TElement > &lhs, const etl::bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
Definition bitset_new.h:2800
ETL_CONSTEXPR14 etl::enable_if<!etl::is_same< TLhsElement, TRhsElement >::value, bool >::type operator==(const etl::bitset< Active_Bits, TLhsElement > &lhs, const etl::bitset< Active_Bits, TRhsElement > &rhs) ETL_NOEXCEPT
Definition bitset_new.h:3752
Definition bitset_new.h:92
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
Definition integral_limits.h:516
Definition log.h:99
enable_if
Definition type_traits_generator.h:1186
is_integral
Definition type_traits_generator.h:996
is_same
Definition type_traits_generator.h:1036
is_unsigned
Definition type_traits_generator.h:1016
make_unsigned
Definition type_traits_generator.h:1176
bitset_ext
Definition absolute.h:38
etl::byte operator|(etl::byte lhs, etl::byte rhs)
Or.
Definition byte.h:265
etl::byte operator&(etl::byte lhs, etl::byte rhs)
And.
Definition byte.h:273
ETL_CONSTEXPR14 size_t strlen(const T *t)
Alternative strlen for all character types.
Definition char_traits.h:285
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition array.h:630
etl::byte operator^(etl::byte lhs, etl::byte rhs)
Exclusive Or.
Definition byte.h:281
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
pair holds two objects of arbitrary type
Definition utility.h:164
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:176
const TIString & to_string(const bool value, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append=false)
For booleans.
Definition to_string_helper.h:501