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
175 static ETL_CONSTANT size_t npos = etl::integral_limits<size_t>::max;
176 static ETL_CONSTANT size_t Bits_Per_Element = etl::integral_limits<TElement>::bits;
177 static ETL_CONSTANT TElement All_Set_Element = etl::integral_limits<TElement>::max;
178 static ETL_CONSTANT TElement All_Clear_Element = element_type(0);
179 };
180
181 template <typename TElement>
182 ETL_CONSTANT size_t bitset_impl_common<TElement>::npos;
183
184 template <typename TElement>
186
187 template <typename TElement>
189
190 template <typename TElement>
192 }
193
194 //*************************************************************************
197 //*************************************************************************
198 template <typename TElement, char Bitset_Layout>
200
201 //*************************************************************************
204 //*************************************************************************
205 template <typename TElement>
206 class bitset_impl<TElement, etl::bitset_storage_model::Single> : public etl::private_bitset::bitset_impl_common<TElement>
207 {
208 public:
209
213
214 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
216 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
217
219
220 //*************************************************************************
222 //*************************************************************************
223 static
224 ETL_CONSTEXPR14
225 void set_all(pointer pbuffer,
226 size_t /*number_of_elements*/,
227 element_type top_mask) ETL_NOEXCEPT
228 {
229 *pbuffer = All_Set_Element & top_mask;
230 }
231
232 //*************************************************************************
234 //*************************************************************************
235 static
236 ETL_CONSTEXPR14
237 void set_position(pointer pbuffer,
238 size_t position,
239 bool value = true)
240 {
241 const element_type mask = element_type(element_type(1) << position);
242
243 if (value == true)
244 {
245 *pbuffer |= mask;
246 }
247 else
248 {
249 *pbuffer &= ~mask;
250 }
251 }
252
253 //*************************************************************************
255 //*************************************************************************
256 template <size_t Position>
257 static
258 ETL_CONSTEXPR14
259 void set_position(pointer pbuffer,
260 bool value = true)
261 {
263
264 if (value == true)
265 {
266 *pbuffer |= mask;
267 }
268 else
269 {
270 *pbuffer &= ~mask;
271 }
272 }
273
274 //*************************************************************************
276 //*************************************************************************
277 template <size_t Position, bool Value>
278 static
279 ETL_CONSTEXPR14
280 void set_position(pointer pbuffer)
281 {
283
284 if (Value == true)
285 {
286 *pbuffer |= mask;
287 }
288 else
289 {
290 *pbuffer &= ~mask;
291 }
292 }
293
294 //*************************************************************************
296 //*************************************************************************
297 static
298 ETL_CONSTEXPR14
299 void reset_all(pointer pbuffer,
300 size_t /*number_of_elements*/) ETL_NOEXCEPT
301 {
302 *pbuffer = All_Clear_Element;
303 }
304
305 //*************************************************************************
307 //*************************************************************************
308 static
309 ETL_CONSTEXPR14
310
311 void reset_position(pointer pbuffer,
312 size_t position)
313 {
314 const element_type mask = element_type(element_type(1) << position);
315 *pbuffer &= ~mask;
316 }
317
318 //*************************************************************************
320 //*************************************************************************
321 static
322 ETL_CONSTEXPR14
323 void from_string(pointer pbuffer,
324 size_t /*number_of_elements*/,
325 size_t active_bits,
326 const char* text) ETL_NOEXCEPT
327 {
328 reset_all(pbuffer, 1U);
329
330 if (text != ETL_NULLPTR)
331 {
332 size_t string_length = etl::strlen(text);
333
334 // Build from the string.
336
338
339 for (size_t i = 0U; i < string_length; ++i)
340 {
341 if (text[i] == ETL_STR('1'))
342 {
343 *pbuffer |= mask;
344 }
345
346 mask >>= 1U;
347 }
348 }
349 }
350
351 //*************************************************************************
353 //*************************************************************************
354 static
355 ETL_CONSTEXPR14
356 void from_string(pointer pbuffer,
357 size_t /*number_of_elements*/,
358 size_t active_bits,
359 const wchar_t* text) ETL_NOEXCEPT
360 {
361 reset_all(pbuffer, 1U);
362
363 if (text != ETL_NULLPTR)
364 {
365 size_t string_length = etl::strlen(text);
366
367 // Build from the string.
369
371
372 for (size_t i = 0U; i < string_length; ++i)
373 {
374 if (text[i] == ETL_STRL('1'))
375 {
376 *pbuffer |= mask;
377 }
378
379 mask >>= 1U;
380 }
381 }
382 }
383
384 //*************************************************************************
386 //*************************************************************************
387 static
388 ETL_CONSTEXPR14
389 void from_string(pointer pbuffer,
390 size_t /*number_of_elements*/,
391 size_t active_bits,
392 const char16_t* text) ETL_NOEXCEPT
393 {
394 reset_all(pbuffer, 1U);
395
396 if (text != ETL_NULLPTR)
397 {
398 size_t string_length = etl::strlen(text);
399
400 // Build from the string.
402
404
405 for (size_t i = 0U; i < string_length; ++i)
406 {
407 if (text[i] == ETL_STRu('1'))
408 {
409 *pbuffer |= mask;
410 }
411
412 mask >>= 1U;
413 }
414 }
415 }
416
417 //*************************************************************************
419 //*************************************************************************
420 static
421 ETL_CONSTEXPR14
422 void from_string(pointer pbuffer,
423 size_t /*number_of_elements*/,
424 size_t active_bits,
425 const char32_t* text) ETL_NOEXCEPT
426 {
427 reset_all(pbuffer, 1U);
428
429 if (text != ETL_NULLPTR)
430 {
431 size_t string_length = etl::strlen(text);
432
433 // Build from the string.
435
437
438 for (size_t i = 0U; i < string_length; ++i)
439 {
440 if (text[i] == ETL_STRU('1'))
441 {
442 *pbuffer |= mask;
443 }
444
445 mask >>= 1U;
446 }
447 }
448 }
449
450 //*************************************************************************
452 //*************************************************************************
453 template <typename T>
454 static
455 ETL_CONSTEXPR14
457 size_t /*number_of_elements*/) ETL_NOEXCEPT
458 {
459 return T(*pbuffer);
460 }
461
462 //*************************************************************************
464 //*************************************************************************
465 template <typename T>
466 static
467 ETL_CONSTEXPR14
469 size_t position,
470 size_t length = etl::integral_limits<T>::bits)
471 {
473
475 const unsigned_t Shift = position % Bits_Per_Element;
476
477 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
478
480 {
481 value = etl::sign_extend<T>(value, length);
482 }
483
484 return static_cast<T>(value);
485 }
486
487 //*************************************************************************
489 //*************************************************************************
490#if ETL_USING_CPP11
492#else
493 template <typename T, size_t Position, size_t Length>
494#endif
495 static
496 ETL_CONSTEXPR14
498 {
500
502 const unsigned_t Shift = Position % Bits_Per_Element;
503
504 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
505
507 {
508 value = etl::sign_extend<T>(value, Length);
509 }
510
511 return static_cast<T>(value);
512 }
513
514 //*************************************************************************
517 //*************************************************************************
518 static
519 ETL_CONSTEXPR14
520 bool test(const_pointer pbuffer,
521 size_t position)
522 {
523 const element_type mask = element_type(element_type(1) << position);
524 return (*pbuffer & mask) != 0U;
525 }
526
527 //*************************************************************************
529 //*************************************************************************
530 static
531 ETL_CONSTEXPR14
532 size_t count(const_pointer pbuffer,
533 size_t /*number_of_elements*/) ETL_NOEXCEPT
534 {
535 return etl::count_bits(*pbuffer);
536 }
537
538 //*************************************************************************
539 // Are all the bits sets?
540 //*************************************************************************
541 static
542 ETL_CONSTEXPR14
543 bool all(const_pointer pbuffer,
544 size_t /*number_of_elements*/,
545 element_type top_mask) ETL_NOEXCEPT
546 {
547 return (*pbuffer & top_mask) == top_mask;
548 }
549
550 //*************************************************************************
551 // Are all the mask bits sets?
552 //*************************************************************************
553 static
554 ETL_CONSTEXPR14
555 bool all(const_pointer pbuffer,
556 size_t /*number_of_elements*/,
557 element_type top_mask,
558 element_type mask) ETL_NOEXCEPT
559 {
560 return (*pbuffer & top_mask & mask) == mask;
561 }
562
563 //*************************************************************************
565 //*************************************************************************
566 static
567 ETL_CONSTEXPR14
568 bool none(const_pointer pbuffer,
569 size_t /*number_of_elements*/) ETL_NOEXCEPT
570 {
571 return *pbuffer == All_Clear_Element;
572 }
573
574 //*************************************************************************
576 //*************************************************************************
577 static
578 ETL_CONSTEXPR14
579 bool none(const_pointer pbuffer,
580 size_t /*number_of_elements*/,
581 element_type mask) ETL_NOEXCEPT
582 {
583 return (*pbuffer & mask) == All_Clear_Element;
584 }
585
586 //*************************************************************************
588 //*************************************************************************
589 static
590 ETL_CONSTEXPR14
591 bool any(const_pointer pbuffer,
592 size_t /*number_of_elements*/) ETL_NOEXCEPT
593 {
594 return *pbuffer != All_Clear_Element;
595 }
596
597 //*************************************************************************
599 //*************************************************************************
600 static
601 ETL_CONSTEXPR14
602 bool any(const_pointer pbuffer,
603 size_t /*number_of_elements*/,
604 element_type mask) ETL_NOEXCEPT
605 {
606 return (*pbuffer & mask) != All_Clear_Element;
607 }
608
609 //*************************************************************************
611 //*************************************************************************
612 static
613 ETL_CONSTEXPR14
614 void flip_all(pointer pbuffer,
615 size_t /*number_of_elements*/) ETL_NOEXCEPT
616 {
617 *pbuffer = ~*pbuffer;
618 }
619
620 //*************************************************************************
622 //*************************************************************************
623 static
624 ETL_CONSTEXPR14
625 void flip_bits(pointer pbuffer,
627 {
628 *pbuffer ^= mask;
629 }
630
631 //*************************************************************************
633 //*************************************************************************
634 static
635 ETL_CONSTEXPR14
636 void flip_position(pointer pbuffer,
637 size_t position)
638 {
639 const element_type mask = element_type(element_type(1) << position);
640 *pbuffer ^= mask;
641 }
642
643 //*************************************************************************
645 //*************************************************************************
646 template <typename TString>
647 static
648 ETL_CONSTEXPR14
650 size_t active_bits,
651 typename TString::value_type zero = typename TString::value_type('0'),
652 typename TString::value_type one = typename TString::value_type('1'))
653 {
654 TString result;
655
656 result.resize(active_bits, '\0');
657
658 // Check that the string type can contain the digits.
659 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
660
661 for (size_t i = active_bits; i > 0; --i)
662 {
663 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
664 }
665
666 return result;
667 }
668
669 //*************************************************************************
674 //*************************************************************************
675 static
676 ETL_CONSTEXPR14
677 size_t find_next(const_pointer pbuffer,
678 size_t /*number_of_elements*/,
679 size_t active_bits,
680 bool state,
681 size_t position) ETL_NOEXCEPT
682 {
683 if (position < active_bits)
684 {
685 // Where to start.
686 size_t bit = position;
687
688 element_type mask = 1U << position;
689
690 // Needs checking?
691 if ((state && (*pbuffer != All_Clear_Element)) || (!state && (*pbuffer != All_Set_Element)))
692 {
693 // For each bit in the element...
694 while (bit < active_bits)
695 {
696 // Equal to the required state?
697 if (((*pbuffer & mask) != 0) == state)
698 {
699 return bit;
700 }
701
702 // Move on to the next bit.
703 mask <<= 1;
704 ++bit;
705 }
706 }
707 }
708
709 return npos;
710 }
711
712 //*************************************************************************
715 //*************************************************************************
716 static
717 ETL_CONSTEXPR14
720 size_t /*number_of_elements*/) ETL_NOEXCEPT
721 {
723 }
724
725 //*************************************************************************
728 //*************************************************************************
729 static
730 ETL_CONSTEXPR14
733 size_t /*number_of_elements*/) ETL_NOEXCEPT
734 {
736 }
737
738 //*************************************************************************
741 //*************************************************************************
742 static
743 ETL_CONSTEXPR14
746 size_t /*number_of_elements*/) ETL_NOEXCEPT
747 {
749 }
750
751 //*************************************************************************
754 //*************************************************************************
755 static
756 ETL_CONSTEXPR14
759 size_t /*number_of_elements*/) ETL_NOEXCEPT
760 {
762 }
763
764 //*************************************************************************
767 //*************************************************************************
768 static
769 ETL_CONSTEXPR14
770 void operator_not(pointer pbuffer,
771 size_t /*number_of_elements*/) ETL_NOEXCEPT
772 {
773 *pbuffer = ~*pbuffer;
774 }
775
776 //*************************************************************************
778 //*************************************************************************
779 static
780 ETL_CONSTEXPR14
782 size_t /*number_of_elements*/,
783 size_t active_bits,
784 size_t shift) ETL_NOEXCEPT
785 {
786 if (shift >= active_bits)
787 {
788 reset_all(pbuffer, 1U);
789 }
790 else
791 {
792 *pbuffer <<= shift;
793 }
794 }
795
796 //*************************************************************************
798 //*************************************************************************
799 static
800 ETL_CONSTEXPR14
802 size_t /*number_of_elements*/,
803 size_t active_bits,
804 size_t shift) ETL_NOEXCEPT
805 {
806 if (shift >= active_bits)
807 {
808 reset_all(pbuffer, 1U);
809 }
810 else
811 {
812 *pbuffer >>= shift;
813 }
814 }
815
816 //*************************************************************************
818 //*************************************************************************
819 static
820 ETL_CONSTEXPR14
823 size_t /*number_of_elements*/) ETL_NOEXCEPT
824 {
825 return (*lhs_pbuffer == *rhs_pbuffer);
826 }
827
828 //*************************************************************************
830 //*************************************************************************
831 template <typename TElementType>
832 static
833 ETL_CONSTEXPR14
834 void initialise(pointer pbuffer,
835 size_t /*number_of_elements*/,
836 unsigned long long value) ETL_NOEXCEPT
837 {
838 *pbuffer = static_cast<TElementType>(value);
839 }
840
841 //*************************************************************************
843 //*************************************************************************
844 static
845 ETL_CONSTEXPR14
848 size_t /*number_of_elements*/) ETL_NOEXCEPT
849 {
852 *rhs_pbuffer = temp;
853 }
854 };
855
856 //*************************************************************************
859 //*************************************************************************
860 template <typename TElement>
861 class bitset_impl<TElement, etl::bitset_storage_model::Multi> : public etl::private_bitset::bitset_impl_common<TElement>
862 {
863 private:
864
866
867 public:
868
872
873 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
875 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
876
878
879 //*************************************************************************
881 //*************************************************************************
882 template <size_t Position, size_t Length, size_t Bits_Per_Element>
884 {
885 static ETL_CONSTANT bool value = ((Position + Length - 1) >> etl::log2<Bits_Per_Element>::value) == (Position >> etl::log2<Bits_Per_Element>::value);
886 };
887
888 //*************************************************************************
891 //*************************************************************************
892 static
893 ETL_CONSTEXPR14
894 bool test(const_pointer pbuffer,
895 size_t position) ETL_NOEXCEPT
896 {
897 size_t index = position >> etl::log2<Bits_Per_Element>::value;
898 element_type mask = element_type(1) << (position & (Bits_Per_Element - 1));
899
900 return (pbuffer[index] & mask) != 0;
901 }
902
903 //*************************************************************************
905 //*************************************************************************
906 static
907 ETL_CONSTEXPR14
908 size_t count(const_pointer pbuffer,
909 size_t number_of_elements) ETL_NOEXCEPT
910 {
911 size_t count = 0;
912
913 while (number_of_elements-- != 0)
914 {
915 count += etl::count_bits(*pbuffer++);
916 }
917
918 return count;
919 }
920
921 //*************************************************************************
922 // Are all the bits sets?
923 //*************************************************************************
924 static
925 ETL_CONSTEXPR14
926 bool all(const_pointer pbuffer,
927 size_t number_of_elements,
928 element_type top_mask) ETL_NOEXCEPT
929 {
930 // All but the last.
931 while (number_of_elements-- != 1U)
932 {
933 if (*pbuffer++ != All_Set_Element)
934 {
935 return false;
936 }
937 }
938
939 // The last.
940 if ((*pbuffer & top_mask) != top_mask)
941 {
942 return false;
943 }
944
945 return true;
946 }
947
948 //*************************************************************************
950 //*************************************************************************
951 static
952 ETL_CONSTEXPR14
953 bool none(const_pointer pbuffer,
954 size_t number_of_elements) ETL_NOEXCEPT
955 {
956 while (number_of_elements-- != 0)
957 {
958 if (*pbuffer++ != 0)
959 {
960 return false;
961 }
962 }
963
964 return true;
965 }
966
967 //*************************************************************************
969 //*************************************************************************
970 static
971 ETL_CONSTEXPR14
972 bool any(const_pointer pbuffer,
973 size_t number_of_elements) ETL_NOEXCEPT
974 {
975 bool any_set = false;
976
977 while (number_of_elements-- != 0)
978 {
979 if (*pbuffer++ != All_Clear_Element)
980 {
981 any_set = true;
982 break;
983 }
984 }
985
986 return any_set;
987 }
988
989 //*************************************************************************
991 //*************************************************************************
992 static
993 ETL_CONSTEXPR14
994 void set_all(pointer pbuffer,
995 size_t number_of_elements,
996 element_type top_mask) ETL_NOEXCEPT
997 {
998 while (number_of_elements-- != 1U)
999 {
1000 *pbuffer++ = All_Set_Element;
1001 }
1002
1003 *pbuffer = (All_Set_Element & top_mask);
1004 }
1005
1006 //*************************************************************************
1008 //*************************************************************************
1009 static
1010 ETL_CONSTEXPR14
1011 void set_position(pointer pbuffer,
1012 size_t position,
1013 bool value = true) ETL_NOEXCEPT
1014 {
1015 size_t index = position >> etl::log2<Bits_Per_Element>::value;
1016 element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1017
1018 if (value == true)
1019 {
1020 pbuffer[index] |= bit;
1021 }
1022 else
1023 {
1024 pbuffer[index] &= ~bit;
1025 }
1026 }
1027
1028 //*************************************************************************
1030 //*************************************************************************
1031 template <size_t Position>
1032 static
1033 ETL_CONSTEXPR14
1034 void set_position(pointer pbuffer,
1035 bool value = true)
1036 {
1038 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
1039
1040 if (value == true)
1041 {
1042 pbuffer[index] |= bit;
1043 }
1044 else
1045 {
1046 pbuffer[index] &= ~bit;
1047 }
1048 }
1049
1050 //*************************************************************************
1052 //*************************************************************************
1053 template <size_t Position, bool Value>
1054 static
1055 ETL_CONSTEXPR14
1056 void set_position(pointer pbuffer)
1057 {
1059 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
1060
1061 if (Value == true)
1062 {
1063 pbuffer[index] |= bit;
1064 }
1065 else
1066 {
1067 pbuffer[index] &= ~bit;
1068 }
1069 }
1070
1071 //*************************************************************************
1073 //*************************************************************************
1074 static
1075 ETL_CONSTEXPR14
1076 void from_string(pointer pbuffer,
1077 size_t number_of_elements,
1078 size_t total_bits,
1079 const char* text) ETL_NOEXCEPT
1080 {
1081 if (text == ETL_NULLPTR)
1082 {
1083 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1084 }
1085 else
1086 {
1087 size_t string_length = etl::strlen(text);
1088 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1089
1090 // Only reset elements we need to.
1091 while (index != number_of_elements)
1092 {
1093 pbuffer[index++] = All_Clear_Element;
1094 }
1095
1096 // Build from the string.
1097 size_t i = etl::min(total_bits, string_length);
1098
1099 while (i > 0)
1100 {
1101 set_position(pbuffer, --i, *text++ == ETL_STR('1'));
1102 }
1103 }
1104 }
1105
1106 //*************************************************************************
1108 //*************************************************************************
1109 static
1110 ETL_CONSTEXPR14
1111 void from_string(pointer pbuffer,
1112 size_t number_of_elements,
1113 size_t total_bits,
1114 const wchar_t* text) ETL_NOEXCEPT
1115 {
1116 if (text == ETL_NULLPTR)
1117 {
1118 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1119 }
1120 else
1121 {
1122 size_t string_length = etl::strlen(text);
1123 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1124
1125 // Only reset elements we need to.
1126 while (index != number_of_elements)
1127 {
1128 pbuffer[index++] = All_Clear_Element;
1129 }
1130
1131 // Build from the string.
1132 size_t i = etl::min(total_bits, string_length);
1133
1134 while (i > 0)
1135 {
1136 set_position(pbuffer, --i, *text++ == ETL_STRL('1'));
1137 }
1138 }
1139 }
1140
1141 //*************************************************************************
1143 //*************************************************************************
1144 static
1145 ETL_CONSTEXPR14
1146 void from_string(pointer pbuffer,
1147 size_t number_of_elements,
1148 size_t total_bits,
1149 const char16_t* text) ETL_NOEXCEPT
1150 {
1151 if (text == ETL_NULLPTR)
1152 {
1153 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1154 }
1155 else
1156 {
1157 size_t string_length = etl::strlen(text);
1158 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1159
1160 // Only reset elements we need to.
1161 while (index != number_of_elements)
1162 {
1163 pbuffer[index++] = All_Clear_Element;
1164 }
1165
1166 // Build from the string.
1167 size_t i = etl::min(total_bits, string_length);
1168
1169 while (i > 0)
1170 {
1171 set_position(pbuffer, --i, *text++ == ETL_STRu('1'));
1172 }
1173 }
1174 }
1175
1176 //*************************************************************************
1178 //*************************************************************************
1179 static
1180 ETL_CONSTEXPR14
1181 void from_string(pointer pbuffer,
1182 size_t number_of_elements,
1183 size_t total_bits,
1184 const char32_t* text) ETL_NOEXCEPT
1185 {
1186 if (text == ETL_NULLPTR)
1187 {
1188 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1189 }
1190 else
1191 {
1192 size_t string_length = etl::strlen(text);
1193 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1194
1195 // Only reset elements we need to.
1196 while (index != number_of_elements)
1197 {
1198 pbuffer[index++] = All_Clear_Element;
1199 }
1200
1201 // Build from the string.
1202 size_t i = etl::min(total_bits, string_length);
1203
1204 while (i > 0)
1205 {
1206 set_position(pbuffer, --i, *text++ == ETL_STRU('1'));
1207 }
1208 }
1209 }
1210
1211 //*************************************************************************
1213 //*************************************************************************
1214 static
1215 ETL_CONSTEXPR14
1216 void reset_all(pointer pbuffer,
1217 size_t number_of_elements) ETL_NOEXCEPT
1218 {
1219 while (number_of_elements-- != 0U)
1220 {
1221 *pbuffer++ = All_Clear_Element;
1222 }
1223 }
1224
1225 //*************************************************************************
1227 //*************************************************************************
1228 static
1229 ETL_CONSTEXPR14
1231 size_t position) ETL_NOEXCEPT
1232 {
1233 const size_t index = position >> etl::log2<Bits_Per_Element>::value;;
1234 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1235
1236 pbuffer[index] &= ~bit;
1237 }
1238
1239 //*************************************************************************
1241 //*************************************************************************
1242 template <typename T>
1243 static
1244 ETL_CONSTEXPR14
1246 size_t number_of_elements) ETL_NOEXCEPT
1247 {
1248 T v = T(0);
1249
1250 const bool OK = (sizeof(T) * CHAR_BIT) >= (number_of_elements * Bits_Per_Element);
1251
1252 if (OK)
1253 {
1255
1256 for (size_t i = 0UL; i < number_of_elements; ++i)
1257 {
1258 v |= T(typename etl::make_unsigned<T>::type(pbuffer[i]) << shift);
1259 shift += uint_least8_t(Bits_Per_Element);
1260 }
1261 }
1262
1263 return v;
1264 }
1265
1266 //*************************************************************************
1268 //*************************************************************************
1269 template <typename T>
1270 static
1271 ETL_CONSTEXPR14
1273 int element_index,
1274 size_t active_bits_in_msb,
1275 size_t length) ETL_NOEXCEPT
1276 {
1277 typedef typename etl::make_unsigned<T>::type unsigned_t;
1278
1279 unsigned_t value(0);
1280
1281 // Extract the first element, if partially filled.
1282 if (active_bits_in_msb < Bits_Per_Element)
1283 {
1285 value = pbuffer[element_index] & mask;
1286 length -= active_bits_in_msb;
1287 if (length >= Bits_Per_Element)
1288 {
1289 value = value << Bits_Per_Element;
1290 }
1291 --element_index;
1292 }
1293
1294 // Loop through the fully filled elements
1295 while (length >= Bits_Per_Element)
1296 {
1297 value |= pbuffer[element_index];
1298 length -= Bits_Per_Element;
1299 if (length >= Bits_Per_Element)
1300 {
1301 value = value << Bits_Per_Element;
1302 }
1303 --element_index;
1304 }
1305
1306 // Extract the last element, if partially filled.
1307 if (length != 0)
1308 {
1309 value = value << length;
1311 value |= (pbuffer[element_index] >> (Bits_Per_Element - length)) & mask;
1312 }
1313
1314 return value;
1315 }
1316
1317 //*************************************************************************
1320 //*************************************************************************
1321 template <typename T>
1322 static
1323 ETL_CONSTEXPR14
1325 size_t position,
1326 size_t length) ETL_NOEXCEPT
1327 {
1328 typedef typename etl::make_unsigned<T>::type unsigned_t;
1329
1330 unsigned_t value(0);
1331
1332 const int Msb_Element_Index = (position + length - 1) >> etl::log2<Bits_Per_Element>::value;
1334
1335 // Is the value contained within one element?
1337 {
1339 const unsigned_t Shift = position % Bits_Per_Element;
1340
1341 value = static_cast<unsigned_t>(pbuffer[Msb_Element_Index] >> Shift) & Mask;
1342 }
1343 else
1344 {
1345 // Get the number of active bits in the msb element
1346 size_t active_bits_in_msb = (position + length) - (Msb_Element_Index * Bits_Per_Element);
1347
1348 // Start with index of the element containing the msb.
1350
1352 }
1353
1354 return value;
1355 }
1356
1357 //*************************************************************************
1360 //*************************************************************************
1361 template <typename T, size_t Position, size_t Length>
1362 static
1363 ETL_CONSTEXPR14
1366 {
1367 typedef typename etl::make_unsigned<T>::type unsigned_t;
1368
1371 const unsigned_t Shift = Position % Bits_Per_Element;
1372
1373 return static_cast<unsigned_t>(pbuffer[Element_Index] >> Shift) & Mask;
1374 }
1375
1376 //*************************************************************************
1379 //*************************************************************************
1380 template <typename T, size_t Position, size_t Length>
1381 static
1382 ETL_CONSTEXPR14
1385 {
1386 // Start with index of the element containing the msb.
1388
1389 // Get the number of active bits in the first element
1390 const size_t Active_Bits_In_Msb = ((Position + Length - 1) % Bits_Per_Element) + 1;
1391
1393 }
1394
1395 //*************************************************************************
1397 //*************************************************************************
1398 template <typename T>
1399 static
1400 ETL_CONSTEXPR14
1402 size_t position,
1403 size_t length = etl::integral_limits<T>::bits)
1404 {
1405 typedef typename etl::make_unsigned<T>::type unsigned_t;
1406
1407 unsigned_t value = extract_from_buffer<unsigned_t>(pbuffer, position, length);
1408
1410 {
1411 value = etl::sign_extend<T>(value, length);
1412 }
1413
1414 return static_cast<T>(value);
1415 }
1416
1417 //*************************************************************************
1419 //*************************************************************************
1420 template <typename T, size_t Position, size_t Length>
1421 static
1422 ETL_CONSTEXPR14
1424 {
1425 typedef typename etl::make_unsigned<T>::type unsigned_t;
1426
1428
1430 {
1431 value = etl::sign_extend<T>(value, Length);
1432 }
1433
1434 return static_cast<T>(value);
1435 }
1436
1437 //*************************************************************************
1439 //*************************************************************************
1440 static
1441 ETL_CONSTEXPR14
1442 void flip_all(pointer pbuffer,
1443 size_t number_of_elements) ETL_NOEXCEPT
1444 {
1445 operator_not(pbuffer, number_of_elements);
1446 }
1447
1448 //*************************************************************************
1450 //*************************************************************************
1451 static
1452 ETL_CONSTEXPR14
1453 void flip_position(pointer pbuffer,
1454 size_t position) ETL_NOEXCEPT
1455 {
1456 const size_t index = position >> etl::log2<Bits_Per_Element>::value;;
1457 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1458
1459 pbuffer[index] ^= bit;
1460 }
1461
1462 //*************************************************************************
1467 //*************************************************************************
1468 static
1469 ETL_CONSTEXPR14
1470 size_t find_next(const_pointer pbuffer,
1471 size_t number_of_elements,
1472 size_t total_bits,
1473 bool state,
1474 size_t position) ETL_NOEXCEPT
1475 {
1476 // Where to start.
1477 size_t index = position >> log2<Bits_Per_Element>::value;
1478 size_t bit = position & (Bits_Per_Element - 1);
1479
1480 element_type mask = 1 << bit;
1481
1482 // For each element in the bitset...
1483 while (index < number_of_elements)
1484 {
1485 element_type value = pbuffer[index];
1486
1487 // Needs checking?
1488 if ((state && (value != All_Clear_Element)) ||
1489 (!state && (value != All_Set_Element)))
1490 {
1491 // For each bit in the element...
1492 while ((bit < Bits_Per_Element) && (position < total_bits))
1493 {
1494 // Equal to the required state?
1495 if (((value & mask) != 0) == state)
1496 {
1497 return position;
1498 }
1499
1500 // Move on to the next bit.
1501 mask <<= 1;
1502 ++position;
1503 ++bit;
1504 }
1505 }
1506 else
1507 {
1508 position += (Bits_Per_Element - bit);
1509 }
1510
1511 // Start at the beginning for all other elements.
1512 bit = 0;
1513 mask = 1;
1514
1515 ++index;
1516 }
1517
1518 return npos;
1519 }
1520
1521 //*************************************************************************
1523 //*************************************************************************
1524 template <typename TString>
1525 static
1526 ETL_CONSTEXPR14
1528 size_t active_bits,
1529 typename TString::value_type zero,
1530 typename TString::value_type one)
1531 {
1532 TString result;
1533
1534 result.resize(active_bits, '\0');
1535
1536 // Check that the string type can contain the digits.
1537 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
1538
1539 for (size_t i = active_bits; i > 0; --i)
1540 {
1541 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
1542 }
1543
1544 return result;
1545 }
1546
1547 //*************************************************************************
1549 //*************************************************************************
1550 static
1551 ETL_CONSTEXPR14
1554 size_t number_of_elements) ETL_NOEXCEPT
1555 {
1556 while (number_of_elements-- != 0)
1557 {
1559 ++lhs_pbuffer;
1560 ++rhs_pbuffer;
1561 }
1562 }
1563
1564 //*************************************************************************
1566 //*************************************************************************
1567 static
1568 ETL_CONSTEXPR14
1571 size_t number_of_elements) ETL_NOEXCEPT
1572 {
1573 while (number_of_elements-- != 0)
1574 {
1576 ++lhs_pbuffer;
1577 ++rhs_pbuffer;
1578 }
1579 }
1580
1581 //*************************************************************************
1583 //*************************************************************************
1584 static
1585 ETL_CONSTEXPR14
1588 size_t number_of_elements) ETL_NOEXCEPT
1589 {
1590 while (number_of_elements-- != 0)
1591 {
1593 ++lhs_pbuffer;
1594 ++rhs_pbuffer;
1595 }
1596 }
1597
1598 //*************************************************************************
1600 //*************************************************************************
1601 static
1602 ETL_CONSTEXPR14
1605 size_t number_of_elements) ETL_NOEXCEPT
1606 {
1607 while (number_of_elements-- != 0)
1608 {
1610 ++lhs_pbuffer;
1611 ++rhs_pbuffer;
1612 }
1613 }
1614
1615 //*************************************************************************
1617 //*************************************************************************
1618 static
1619 ETL_CONSTEXPR14
1620 void operator_not(pointer pbuffer,
1621 size_t number_of_elements) ETL_NOEXCEPT
1622 {
1623 while (number_of_elements-- != 0)
1624 {
1625 *pbuffer = ~*pbuffer;
1626 ++pbuffer;
1627 }
1628 }
1629
1630 //*************************************************************************
1632 //*************************************************************************
1633 static
1634 ETL_CONSTEXPR14
1636 size_t number_of_elements,
1637 size_t active_bits,
1638 size_t shift) ETL_NOEXCEPT
1639 {
1640 if (shift >= active_bits)
1641 {
1642 reset_all(pbuffer, number_of_elements);
1643 }
1644 else
1645 {
1646 // The place where the elements are split when shifting.
1647 const size_t split_position = Bits_Per_Element - (shift % Bits_Per_Element);
1648
1649 // Where we are shifting from.
1650 int src_index = int(number_of_elements - (shift / Bits_Per_Element) - 1U);
1651
1652 // Where we are shifting to.
1653 int dst_index = int(number_of_elements - 1U);
1654
1655 // Shift control constants.
1656 const size_t lsb_shift = Bits_Per_Element - split_position;
1657 const size_t msb_shift = split_position;
1658
1662
1663 // First lsb.
1665 pbuffer[dst_index] = lsb;
1666 --src_index;
1667
1668 // Now do the shifting.
1669 while (src_index >= 0)
1670 {
1671 // Shift msb.
1673 pbuffer[dst_index] = pbuffer[dst_index] | msb;
1674 --dst_index;
1675
1676 // Shift lsb.
1677 lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1678 pbuffer[dst_index] = lsb;
1679 --src_index;
1680 }
1681
1682 // Clear the remaining bits.
1683 // First lsb.
1684 pbuffer[dst_index] &= lsb_shifted_mask;
1685
1686 // The other remaining bytes on the right.
1687 for (int i = 0; i < dst_index; ++i)
1688 {
1689 pbuffer[i] = 0;
1690 }
1691 }
1692 }
1693
1694 //*************************************************************************
1696 //*************************************************************************
1697 static
1698 ETL_CONSTEXPR14
1700 size_t number_of_elements,
1701 size_t active_bits,
1702 size_t shift) ETL_NOEXCEPT
1703 {
1704 if (shift >= active_bits)
1705 {
1706 reset_all(pbuffer, number_of_elements);
1707 }
1708 else
1709 {
1710 // The place where the elements are split when shifting.
1711 const size_t split_position = shift % Bits_Per_Element;
1712
1713 // Where we are shifting from.
1714 int src_index = int(shift / Bits_Per_Element);
1715
1716 // Where we are shifting to.
1717 int dst_index = 0;
1718
1719 // Shift control constants.
1720 const size_t lsb_shift = Bits_Per_Element - split_position;
1721 const size_t msb_shift = split_position;
1722
1726
1727 // Now do the shifting.
1728 while (src_index < int(number_of_elements - 1))
1729 {
1730 // Shift msb.
1732 ++src_index;
1733
1734 // Shift lsb.
1736
1737 // Combine them.
1738 pbuffer[dst_index] = lsb | msb;
1739 ++dst_index;
1740 }
1741
1742 // Final msb.
1744 pbuffer[dst_index] = msb;
1745
1746 // Clear the remaining bits.
1747 // First msb.
1748 pbuffer[dst_index] &= msb_shifted_mask;
1749 ++dst_index;
1750
1751 // The other remaining bytes.
1752 while (dst_index < int(number_of_elements))
1753 {
1754 pbuffer[dst_index] = 0;
1755 ++dst_index;
1756 }
1757 }
1758 }
1759
1760 //*************************************************************************
1762 //*************************************************************************
1763 static
1764 ETL_CONSTEXPR14
1767 size_t number_of_elements) ETL_NOEXCEPT
1768 {
1769 return etl::equal(lhs_pbuffer, lhs_pbuffer + number_of_elements, rhs_pbuffer);
1770 }
1771
1772 //*************************************************************************
1775 //*************************************************************************
1776 template <typename TElementType>
1777 static
1778 ETL_CONSTEXPR14
1781 size_t number_of_elements,
1782 unsigned long long value) ETL_NOEXCEPT
1783 {
1784 size_t i = 0UL;
1785
1786 // Set the non-zero elements.
1787 pbuffer[i++] = value;
1788
1789 // Clear the remaining elements.
1790 while (i != number_of_elements)
1791 {
1792 pbuffer[i++] = All_Clear_Element;
1793 }
1794 }
1795
1796 //*************************************************************************
1799 //*************************************************************************
1800 template <typename TElementType>
1801 static
1802 ETL_CONSTEXPR14
1805 size_t number_of_elements,
1806 unsigned long long value) ETL_NOEXCEPT
1807 {
1808 size_t i = 0UL;
1809
1810 // Set the non-zero elements.
1811 const unsigned long long Shift = etl::integral_limits<element_type>::bits;
1812
1813 while ((value != 0) && (i != number_of_elements))
1814 {
1815 pbuffer[i++] = value & All_Set_Element;
1816 value = value >> Shift;
1817 }
1818
1819 // Clear the remaining elements.
1820 while (i != number_of_elements)
1821 {
1822 pbuffer[i++] = All_Clear_Element;
1823 }
1824 }
1825
1826 //*************************************************************************
1828 //*************************************************************************
1829 static
1830 ETL_CONSTEXPR14
1833 size_t number_of_elements)
1834 {
1835 etl::swap_ranges(pbuffer1, pbuffer1 + number_of_elements, pbuffer2);
1836 }
1837 };
1838
1839 namespace private_bitset
1840 {
1841 //***************************************************************************
1842 template <size_t Active_Bits, typename TElement>
1844 {
1845 public:
1846
1847 typedef typename etl::private_bitset::bitset_impl_common<TElement>::element_type element_type;
1848
1849 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
1850 using etl::private_bitset::bitset_impl_common<TElement>::All_Set_Element;
1851 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
1852
1853 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;
1854 static ETL_CONSTANT size_t Size = Active_Bits;
1855 static ETL_CONSTANT size_t Allocated_Bits = Number_Of_Elements * Bits_Per_Element;
1856
1857#if ETL_USING_CPP11
1858 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;
1859#else
1860 static ETL_CONSTANT etl::bitset_storage_model Storage_Model;
1861#endif
1862
1865
1866 private:
1867
1868 static ETL_CONSTANT size_t Top_Mask_Shift = ((Bits_Per_Element - ((Number_Of_Elements * Bits_Per_Element) - Active_Bits)) % Bits_Per_Element);
1869
1870 public:
1871
1872 static ETL_CONSTANT TElement Top_Mask = element_type(Top_Mask_Shift == 0 ? All_Set_Element : ~(All_Set_Element << Top_Mask_Shift));
1873 };
1874
1875
1876 template <size_t Active_Bits, typename TElement>
1878
1879 template <size_t Active_Bits, typename TElement>
1881
1882#if ETL_USING_CPP11
1883 template <size_t Active_Bits, typename TElement>
1885#else
1886 template <size_t Active_Bits, typename TElement>
1888#endif
1889
1890 template <size_t Active_Bits, typename TElement>
1892
1893 template <size_t Active_Bits, typename TElement>
1895 }
1896
1897 //***************************************************************************
1899 //***************************************************************************
1900 template <size_t Active_Bits = 0U,
1901 typename TElement = unsigned char>
1902 class bitset;
1903
1904 //***************************************************************************
1906 //***************************************************************************
1907 template <>
1908 class bitset<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
1909 {
1910 public:
1911
1915
1916 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
1917 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
1918 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
1919 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
1920 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
1921 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
1922 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
1923 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
1924 };
1925
1926 //*************************************************************************
1928 //*************************************************************************
1929 template <size_t Active_Bits, typename TElement>
1930 class bitset : public etl::private_bitset::bitset_common<Active_Bits, TElement>
1931 {
1932 public:
1933
1934 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
1935
1939
1940 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
1941 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
1942 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
1943 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
1944 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
1945 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
1946 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
1947 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
1948
1949 //*************************************************************************
1951 //*************************************************************************
1953 {
1954 public:
1955
1956 friend class bitset;
1957
1958 //*******************************
1960 //*******************************
1961 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
1962 : p_bitset(other.p_bitset)
1963 , position(other.position)
1964 {
1965 }
1966
1967 //*******************************
1969 //*******************************
1970 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
1971 {
1972 return p_bitset->test(position);
1973 }
1974
1975 //*******************************
1977 //*******************************
1978 ETL_CONSTEXPR14 bit_reference& operator = (bool b) ETL_NOEXCEPT
1979 {
1980 p_bitset->set(position, b);
1981 return *this;
1982 }
1983
1984 //*******************************
1986 //*******************************
1987 ETL_CONSTEXPR14 bit_reference& operator = (const bit_reference& r) ETL_NOEXCEPT
1988 {
1989 p_bitset->set(position, bool(r));
1990 return *this;
1991 }
1992
1993 //*******************************
1995 //*******************************
1996 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
1997 {
1998 p_bitset->flip(position);
1999 return *this;
2000 }
2001
2002 //*******************************
2004 //*******************************
2005 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
2006 {
2007 return !p_bitset->test(position);
2008 }
2009
2010 private:
2011
2012 //*******************************
2014 //*******************************
2015 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
2016 : p_bitset(ETL_NULLPTR)
2017 , position(0)
2018 {
2019 }
2020
2021 //*******************************
2023 //*******************************
2024 ETL_CONSTEXPR14 bit_reference(bitset<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
2025 : p_bitset(&r_bitset)
2026 , position(position_)
2027 {
2028 }
2029
2030 bitset<Active_Bits, TElement>* p_bitset;
2031 size_t position;
2032 };
2033
2034 //*************************************************************************
2036 //*************************************************************************
2037 ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
2038 : buffer()
2039 {
2040 implementation::reset_all(buffer, Number_Of_Elements);
2041 }
2042
2043 //*************************************************************************
2045 //*************************************************************************
2046 ETL_CONSTEXPR14 bitset(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2047 : buffer()
2048 {
2049 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
2050 }
2051
2052 //*************************************************************************
2054 //*************************************************************************
2055 template <typename TValue>
2056 ETL_CONSTEXPR14 bitset(TValue value, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
2057 : buffer()
2058 {
2059 implementation::template initialise<element_type>(buffer, Number_Of_Elements, value);
2060 }
2061
2062 //*************************************************************************
2064 //*************************************************************************
2065 template <typename TPString>
2066 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0) ETL_NOEXCEPT
2067 : buffer()
2068 {
2069 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2070 }
2071
2072 //*************************************************************************
2074 //*************************************************************************
2075 template <typename TPString>
2076 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0) ETL_NOEXCEPT
2077 : buffer()
2078 {
2079 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2080 }
2081
2082 //*************************************************************************
2084 //*************************************************************************
2085 template <typename TPString>
2086 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char16_t*>::value>::type* = 0) ETL_NOEXCEPT
2087 : buffer()
2088 {
2089 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2090 }
2091
2092 //*************************************************************************
2094 //*************************************************************************
2095 template <typename TPString>
2096 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char32_t*>::value>::type* = 0) ETL_NOEXCEPT
2097 : buffer()
2098 {
2099 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2100 }
2101
2102 //*************************************************************************
2104 //*************************************************************************
2105 ETL_CONSTEXPR14 bitset& operator =(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2106 {
2107 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
2108
2109 return *this;
2110 }
2111
2112 //*************************************************************************
2114 //*************************************************************************
2115 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set() ETL_NOEXCEPT
2116 {
2117 implementation::set_all(buffer, Number_Of_Elements, Top_Mask);
2118
2119 return *this;
2120 }
2121
2122 //*************************************************************************
2124 //*************************************************************************
2125 ETL_CONSTEXPR14
2126 bitset<Active_Bits, TElement>& set(size_t position, bool value = true)
2127 {
2128 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2129
2130 implementation::set_position(buffer, position, value);
2131
2132 return *this;
2133 }
2134
2135 //*************************************************************************
2137 //*************************************************************************
2138 template <size_t Position>
2139 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set(bool value = true)
2140 {
2141 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2142
2144
2145 return *this;
2146 }
2147
2148 //*************************************************************************
2150 //*************************************************************************
2151 template <size_t Position, bool Value>
2153 {
2154 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2155
2157
2158 return *this;
2159 }
2160
2161 //*************************************************************************
2163 //*************************************************************************
2164 template <typename TPString>
2165 ETL_CONSTEXPR14
2167 set(TPString text) ETL_NOEXCEPT
2168 {
2169 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2170
2171 return *this;
2172 }
2173
2174 //*************************************************************************
2176 //*************************************************************************
2177 template <typename TPString>
2178 ETL_CONSTEXPR14
2180 set(TPString text) ETL_NOEXCEPT
2181 {
2182 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2183
2184 return *this;
2185 }
2186
2187 //*************************************************************************
2189 //*************************************************************************
2190 template <typename TPString>
2191 ETL_CONSTEXPR14
2193 set(TPString text) ETL_NOEXCEPT
2194 {
2195 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2196
2197 return *this;
2198 }
2199
2200 //*************************************************************************
2202 //*************************************************************************
2203 template <typename TPString>
2204 ETL_CONSTEXPR14
2206 set(TPString text) ETL_NOEXCEPT
2207 {
2208 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2209
2210 return *this;
2211 }
2212
2213 //*************************************************************************
2215 //*************************************************************************
2216 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
2217 {
2218 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2219
2220 return *this;
2221 }
2222
2223 //*************************************************************************
2225 //*************************************************************************
2226 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const wchar_t* text) ETL_NOEXCEPT
2227 {
2228 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2229
2230 return *this;
2231 }
2232
2233 //*************************************************************************
2235 //*************************************************************************
2236 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char16_t* text) ETL_NOEXCEPT
2237 {
2238 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2239
2240 return *this;
2241 }
2242
2243 //*************************************************************************
2245 //*************************************************************************
2246 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char32_t* text) ETL_NOEXCEPT
2247 {
2248 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2249
2250 return *this;
2251 }
2252
2253 //*************************************************************************
2255 //*************************************************************************
2256 template <typename T>
2257 ETL_CONSTEXPR14
2259 value() const ETL_NOEXCEPT
2260 {
2261 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2262 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
2263
2264 return implementation::template value<T>(buffer, Number_Of_Elements);
2265 }
2266
2267 //*************************************************************************
2270 //*************************************************************************
2271 template <typename T>
2272 ETL_CONSTEXPR14
2273 T extract(size_t position, size_t length = etl::integral_limits<T>::bits) const
2274 {
2275 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2276
2277 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
2278 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
2279
2280 return implementation::template extract<T>(buffer, position, length);
2281 }
2282
2283 //*************************************************************************
2286 //*************************************************************************
2287#if ETL_USING_CPP11
2289#else
2290 template <typename T, size_t Position, size_t Length>
2291#endif
2292 ETL_CONSTEXPR14
2293 T extract() const
2294 {
2295 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2296 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
2297 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
2298
2300 }
2301
2302 //*************************************************************************
2304 //*************************************************************************
2305 unsigned long to_ulong() const
2306 {
2308
2309 return implementation::template value<unsigned long>(buffer, Number_Of_Elements);
2310 }
2311
2312 //*************************************************************************
2314 //*************************************************************************
2315 unsigned long long to_ullong() const
2316 {
2318
2319 return implementation::template value<unsigned long long>(buffer, Number_Of_Elements);
2320 }
2321
2322 //*************************************************************************
2324 //*************************************************************************
2325 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset() ETL_NOEXCEPT
2326 {
2327 implementation::reset_all(buffer, Number_Of_Elements);
2328
2329 return *this;
2330 }
2331
2332 //*************************************************************************
2334 //*************************************************************************
2335 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset(size_t position)
2336 {
2337 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2338
2339 implementation::reset_position(buffer, position);
2340
2341 return *this;
2342 }
2343
2344 //*************************************************************************
2347 //*************************************************************************
2348 ETL_CONSTEXPR14 bool test(size_t position) const
2349 {
2350 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
2351
2352 return implementation::test(buffer, position);
2353 }
2354
2355 //*************************************************************************
2358 //*************************************************************************
2359 template <size_t Position>
2360 ETL_CONSTEXPR14 bool test() const
2361 {
2362 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2363
2364 return implementation::test(buffer, Position);
2365 }
2366
2367 //*************************************************************************
2369 //*************************************************************************
2370 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
2371 {
2372 return Active_Bits;
2373 }
2374
2375 //*************************************************************************
2377 //*************************************************************************
2378 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
2379 {
2380 return Number_Of_Elements;
2381 }
2382
2383 //*************************************************************************
2385 //*************************************************************************
2386 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
2387 {
2388 return All_Set_Element;
2389 }
2390
2391 //*************************************************************************
2393 //*************************************************************************
2394 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
2395 {
2396 return All_Clear_Element;
2397 }
2398
2399 //*************************************************************************
2401 //*************************************************************************
2402 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
2403 {
2404 return Bits_Per_Element;
2405 }
2406
2407 //*************************************************************************
2409 //*************************************************************************
2410 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
2411 {
2412 return Top_Mask;
2413 }
2414
2415 //*************************************************************************
2417 //*************************************************************************
2418 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
2419 {
2420 return Number_Of_Elements * Bits_Per_Element;
2421 }
2422
2423 //*************************************************************************
2427 //*************************************************************************
2428 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
2429 {
2430 return Storage_Model;
2431 }
2432
2433 //*************************************************************************
2435 //*************************************************************************
2436 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
2437 {
2438 return implementation::count(buffer, Number_Of_Elements);
2439 }
2440
2441 //*************************************************************************
2442 // Are all the bits sets?
2443 //*************************************************************************
2444 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
2445 {
2446 return implementation::all(buffer, Number_Of_Elements, Top_Mask);
2447 }
2448
2449 //*************************************************************************
2450 // Are all the mask bits sets?
2451 //*************************************************************************
2452 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
2453 {
2454 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2455
2456 return implementation::all(buffer, Number_Of_Elements, Top_Mask, mask);
2457 }
2458
2459 //*************************************************************************
2461 //*************************************************************************
2462 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
2463 {
2464 return implementation::none(buffer, Number_Of_Elements);
2465 }
2466
2467 //*************************************************************************
2469 //*************************************************************************
2470 ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
2471 {
2472 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2473
2474 return implementation::none(buffer, Number_Of_Elements, mask);
2475 }
2476
2477 //*************************************************************************
2479 //*************************************************************************
2480 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
2481 {
2482 return implementation::any(buffer, Number_Of_Elements);
2483 }
2484
2485 //*************************************************************************
2487 //*************************************************************************
2488 ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
2489 {
2490 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2491
2492 return implementation::any(buffer, Number_Of_Elements, mask);
2493 }
2494
2495 //*************************************************************************
2497 //*************************************************************************
2498 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip() ETL_NOEXCEPT
2499 {
2500 implementation::flip_all(buffer, Number_Of_Elements);
2501
2502 return *this;
2503 }
2504
2505 //*************************************************************************
2507 //*************************************************************************
2508 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip(size_t position)
2509 {
2510 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2511
2512 implementation::flip_position(buffer, position);
2513
2514 return *this;
2515 }
2516
2517 //*************************************************************************
2519 //*************************************************************************
2520 ETL_CONSTEXPR14 bool operator[] (size_t position) const ETL_NOEXCEPT
2521 {
2522 return implementation::test(buffer, position);
2523 }
2524
2525 //*************************************************************************
2527 //*************************************************************************
2528 ETL_CONSTEXPR14 bit_reference operator [] (size_t position) ETL_NOEXCEPT
2529 {
2530 return bit_reference(*this, position);
2531 }
2532
2533 //*************************************************************************
2535 //*************************************************************************
2536#if ETL_USING_CPP11
2537 template <typename TString = etl::string<Active_Bits>>
2538#else
2539 template <typename TString>
2540#endif
2541 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
2542 typename TString::value_type one = typename TString::value_type('1')) const
2543 {
2544 return implementation::template to_string<TString>(buffer, Active_Bits, zero, one);
2545 }
2546
2547 //*************************************************************************
2551 //*************************************************************************
2552 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
2553 {
2554 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, 0);
2555 }
2556
2557 //*************************************************************************
2562 //*************************************************************************
2563 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
2564 {
2565 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, position);
2566 }
2567
2568 //*************************************************************************
2570 //*************************************************************************
2572 {
2574
2575 implementation::operator_and(temp.buffer, other.buffer, Number_Of_Elements);
2576
2577 return temp;
2578 }
2579
2580 //*************************************************************************
2582 //*************************************************************************
2584 {
2585 implementation::operator_and(buffer, other.buffer, Number_Of_Elements);
2586
2587 return *this;
2588 }
2589
2590 //*************************************************************************
2592 //*************************************************************************
2594 {
2596
2597 implementation::operator_or(temp.buffer, other.buffer, Number_Of_Elements);
2598
2599 return temp;
2600 }
2601
2602 //*************************************************************************
2604 //*************************************************************************
2606 {
2607 implementation::operator_or(&buffer[0], &other.buffer[0], Number_Of_Elements);
2608
2609 return *this;
2610 }
2611
2612 //*************************************************************************
2614 //*************************************************************************
2616 {
2618
2619 implementation::operator_xor(temp.buffer, other.buffer, Number_Of_Elements);
2620
2621 return temp;
2622 }
2623
2624 //*************************************************************************
2626 //*************************************************************************
2628 {
2629 implementation::operator_xor(buffer, other.buffer, Number_Of_Elements);
2630
2631 return *this;
2632 }
2633
2634 //*************************************************************************
2636 //*************************************************************************
2637 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator ~() const ETL_NOEXCEPT
2638 {
2640
2641 implementation::flip_all(temp.buffer, Number_Of_Elements);
2642
2643 return temp;
2644 }
2645
2646 //*************************************************************************
2648 //*************************************************************************
2649 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator <<(size_t shift) const ETL_NOEXCEPT
2650 {
2652
2653 implementation::operator_shift_left(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2654
2655 return temp;
2656 }
2657
2658 //*************************************************************************
2660 //*************************************************************************
2661 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator <<=(size_t shift) ETL_NOEXCEPT
2662 {
2663 if (shift >= Active_Bits)
2664 {
2665 implementation::reset_all(buffer, Number_Of_Elements);
2666 }
2667 else
2668 {
2669 implementation::operator_shift_left(buffer, Number_Of_Elements, Active_Bits, shift);
2670 }
2671
2672 return *this;
2673 }
2674
2675 //*************************************************************************
2677 //*************************************************************************
2678 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator >>(size_t shift) const ETL_NOEXCEPT
2679 {
2681
2682 implementation::operator_shift_right(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2683
2684 return temp;
2685 }
2686
2687 //*************************************************************************
2689 //*************************************************************************
2690 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator >>=(size_t shift) ETL_NOEXCEPT
2691 {
2692 if (shift >= Active_Bits)
2693 {
2694 implementation::reset_all(buffer, Number_Of_Elements);
2695 }
2696 else
2697 {
2698 implementation::operator_shift_right(buffer, Number_Of_Elements, Active_Bits, shift);
2699 }
2700
2701 return *this;
2702 }
2703
2704 //*************************************************************************
2706 //*************************************************************************
2707 friend ETL_CONSTEXPR14 bool operator ==(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2708 {
2709 return implementation::operator_equality(lhs.buffer, rhs.buffer, lhs.Number_Of_Elements);
2710 }
2711
2712 //*************************************************************************
2714 //*************************************************************************
2715 friend ETL_CONSTEXPR14 bool operator !=(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2716 {
2717 return !(lhs == rhs);
2718 }
2719
2720 //*************************************************************************
2722 //*************************************************************************
2723 ETL_CONSTEXPR14 void swap(etl::bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2724 {
2725 implementation::swap(buffer, other.buffer, Number_Of_Elements);
2726 }
2727
2728 //*************************************************************************
2731 //*************************************************************************
2732 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
2733 {
2734 return span_type(buffer, Number_Of_Elements);
2735 }
2736
2737 //*************************************************************************
2740 //*************************************************************************
2741 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
2742 {
2743 return const_span_type(buffer, Number_Of_Elements);
2744 }
2745
2746 private:
2747
2748 // The implementation of the bitset functionality.
2749 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi> implementation;
2750
2751 // The storage for the bitset.
2752 element_type buffer[Number_Of_Elements];
2753 };
2754
2755 //***************************************************************************
2758 //***************************************************************************
2759 template <size_t Active_Bits, typename TElement>
2761 {
2763 temp &= rhs;
2764 return temp;
2765 }
2766
2767 //***************************************************************************
2770 //***************************************************************************
2771 template<size_t Active_Bits, typename TElement>
2773 {
2775 temp |= rhs;
2776 return temp;
2777 }
2778
2779 //***************************************************************************
2782 //***************************************************************************
2783 template<size_t Active_Bits, typename TElement>
2785 {
2787 temp ^= rhs;
2788 return temp;
2789 }
2790}
2791
2792//***************************************************************************
2795//***************************************************************************
2796template<size_t Active_Bits, typename TElement>
2797ETL_CONSTEXPR14 bool operator != (const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2798{
2799 return !(lhs == rhs);
2800}
2801
2802//*************************************************************************
2804//*************************************************************************
2805template <size_t Active_Bits, typename TElement>
2806ETL_CONSTEXPR14 void swap(etl::bitset<Active_Bits, TElement>& lhs, etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2807{
2808 lhs.swap(rhs);
2809}
2810
2811//***************************************************************************
2813//***************************************************************************
2814namespace etl
2815{
2816 //***************************************************************************
2817 template <size_t Active_Bits = 0U,
2818 typename TElement = unsigned char>
2819 class bitset_ext;
2820
2821 //***************************************************************************
2823 //***************************************************************************
2824 template <>
2825 class bitset_ext<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
2826 {
2827 public:
2828
2832
2833 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
2834 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
2835 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
2836 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
2837 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
2838 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
2839 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
2840 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
2841 };
2842
2843 //*************************************************************************
2845 //*************************************************************************
2846 template <size_t Active_Bits, typename TElement>
2847 class bitset_ext : public etl::private_bitset::bitset_common<Active_Bits, TElement>
2848 {
2849 public:
2850
2851 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
2852
2856
2857 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
2858 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
2859 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
2860 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
2861 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
2862 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
2863 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
2864 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
2865
2866 typedef etl::array<TElement, Number_Of_Elements> buffer_type;
2867
2868 //*************************************************************************
2870 //*************************************************************************
2872 {
2873 public:
2874
2875 friend class bitset_ext;
2876
2877 //*******************************
2879 //*******************************
2880 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
2881 : p_bitset(other.p_bitset)
2882 , position(other.position)
2883 {
2884 }
2885
2886 //*******************************
2888 //*******************************
2889 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
2890 {
2891 return p_bitset->test(position);
2892 }
2893
2894 //*******************************
2896 //*******************************
2897 ETL_CONSTEXPR14 bit_reference& operator = (bool b) ETL_NOEXCEPT
2898 {
2899 p_bitset->set(position, b);
2900 return *this;
2901 }
2902
2903 //*******************************
2905 //*******************************
2906 ETL_CONSTEXPR14 bit_reference& operator = (const bit_reference& r) ETL_NOEXCEPT
2907 {
2908 p_bitset->set(position, bool(r));
2909 return *this;
2910 }
2911
2912 //*******************************
2914 //*******************************
2915 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
2916 {
2917 p_bitset->flip(position);
2918 return *this;
2919 }
2920
2921 //*******************************
2923 //*******************************
2924 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
2925 {
2926 return !p_bitset->test(position);
2927 }
2928
2929 private:
2930
2931 //*******************************
2933 //*******************************
2934 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
2935 : p_bitset(ETL_NULLPTR)
2936 , position(0)
2937 {
2938 }
2939
2940 //*******************************
2942 //*******************************
2943 ETL_CONSTEXPR14 bit_reference(bitset_ext<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
2944 : p_bitset(&r_bitset)
2945 , position(position_)
2946 {
2947 }
2948
2949 bitset_ext<Active_Bits, TElement>* p_bitset;
2950 size_t position;
2951 };
2952
2953 //*************************************************************************
2955 //*************************************************************************
2956 ETL_CONSTEXPR14 explicit bitset_ext(element_type* pbuffer_)
2957 : pbuffer(pbuffer_)
2958 {
2959 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2960 implementation::reset_all(pbuffer, Number_Of_Elements);
2961 }
2962
2963 //*************************************************************************
2965 //*************************************************************************
2966 ETL_CONSTEXPR14 explicit bitset_ext(buffer_type& buffer)
2967 : pbuffer(buffer.data())
2968 {
2969 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2970 implementation::reset_all(pbuffer, Number_Of_Elements);
2971 }
2972
2973 //*************************************************************************
2975 //*************************************************************************
2976 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, element_type* pbuffer_)
2977 : pbuffer(pbuffer_)
2978 {
2979 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2980 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2981 }
2982
2983 //*************************************************************************
2985 //*************************************************************************
2986 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, buffer_type& buffer) ETL_NOEXCEPT
2987 : pbuffer(buffer.data())
2988 {
2989 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2990 }
2991
2992 //*************************************************************************
2994 //*************************************************************************
2995 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT ETL_DELETE;
2996
2997 //*************************************************************************
2999 //*************************************************************************
3000 ETL_CONSTEXPR14 bitset_ext(unsigned long long value, element_type* pbuffer_)
3001 : pbuffer(pbuffer_)
3002 {
3003 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3004 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value);
3005 }
3006
3007 //*************************************************************************
3009 //*************************************************************************
3010 template <typename TValue>
3011 ETL_CONSTEXPR14 bitset_ext(TValue value, buffer_type& buffer, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
3012 : pbuffer(buffer.data())
3013 {
3014 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value);
3015 }
3016
3017 //*************************************************************************
3019 //*************************************************************************
3020 template <typename TPString>
3021 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0)
3022 : pbuffer(pbuffer_)
3023 {
3024 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3025 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3026 }
3027
3028 //*************************************************************************
3030 //*************************************************************************
3031 template <typename TPString>
3032 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0) ETL_NOEXCEPT
3033 : pbuffer(buffer.data())
3034 {
3035 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3036 }
3037
3038 //*************************************************************************
3040 //*************************************************************************
3041 template <typename TPString>
3042 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0)
3043 : pbuffer(pbuffer_)
3044 {
3045 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3046 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3047 }
3048
3049 //*************************************************************************
3051 //*************************************************************************
3052 template <typename TPString>
3053 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0) ETL_NOEXCEPT
3054 : pbuffer(buffer.data())
3055 {
3056 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3057 }
3058
3059 //*************************************************************************
3061 //*************************************************************************
3062 template <typename TPString>
3063 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char16_t*>::value>::type* = 0)
3064 : pbuffer(pbuffer_)
3065 {
3066 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3067 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3068 }
3069
3070 //*************************************************************************
3072 //*************************************************************************
3073 template <typename TPString>
3074 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char16_t*>::value>::type* = 0) ETL_NOEXCEPT
3075 : pbuffer(buffer.data())
3076 {
3077 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3078 }
3079
3080 //*************************************************************************
3082 //*************************************************************************
3083 template <typename TPString>
3084 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char32_t*>::value>::type* = 0)
3085 : pbuffer(pbuffer_)
3086 {
3087 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
3088 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3089 }
3090
3091 //*************************************************************************
3093 //*************************************************************************
3094 template <typename TPString>
3095 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char32_t*>::value>::type* = 0) ETL_NOEXCEPT
3096 : pbuffer(buffer.data())
3097 {
3098 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3099 }
3100
3101 //*************************************************************************
3103 //*************************************************************************
3104 ETL_CONSTEXPR14 bitset_ext& operator =(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3105 {
3106 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
3107
3108 return *this;
3109 }
3110
3111 //*************************************************************************
3113 //*************************************************************************
3114 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set() ETL_NOEXCEPT
3115 {
3116 implementation::set_all(pbuffer, Number_Of_Elements, Top_Mask);
3117
3118 return *this;
3119 }
3120
3121 //*************************************************************************
3123 //*************************************************************************
3124 ETL_CONSTEXPR14
3125 bitset_ext<Active_Bits, TElement>& set(size_t position, bool value = true)
3126 {
3127 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3128
3129 implementation::set_position(pbuffer, position, value);
3130
3131 return *this;
3132 }
3133
3134 //*************************************************************************
3136 //*************************************************************************
3137 template <size_t Position>
3138 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set(bool value = true)
3139 {
3140 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3141
3142 implementation::template set_position<Position>(pbuffer, value);
3143
3144 return *this;
3145 }
3146
3147 //*************************************************************************
3149 //*************************************************************************
3150 template <size_t Position, bool Value>
3151 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set()
3152 {
3153 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3154
3155 implementation::template set_position<Position, Value>(pbuffer);
3156
3157 return *this;
3158 }
3159
3160 //*************************************************************************
3162 //*************************************************************************
3163 template <typename TPString>
3164 ETL_CONSTEXPR14
3165 typename etl::enable_if<etl::is_same<TPString, const char*>::value, bitset_ext<Active_Bits, TElement>&>::type
3166 set(TPString text) ETL_NOEXCEPT
3167 {
3168 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3169
3170 return *this;
3171 }
3172
3173 //*************************************************************************
3175 //*************************************************************************
3176 template <typename TPString>
3177 ETL_CONSTEXPR14
3178 typename etl::enable_if<etl::is_same<TPString, const wchar_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
3179 set(TPString text) ETL_NOEXCEPT
3180 {
3181 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3182
3183 return *this;
3184 }
3185
3186 //*************************************************************************
3188 //*************************************************************************
3189 template <typename TPString>
3190 ETL_CONSTEXPR14
3191 typename etl::enable_if<etl::is_same<TPString, const char16_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
3192 set(TPString text) ETL_NOEXCEPT
3193 {
3194 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3195
3196 return *this;
3197 }
3198
3199 //*************************************************************************
3201 //*************************************************************************
3202 template <typename TPString>
3203 ETL_CONSTEXPR14
3204 typename etl::enable_if<etl::is_same<TPString, const char32_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
3205 set(TPString text) ETL_NOEXCEPT
3206 {
3207 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3208
3209 return *this;
3210 }
3211
3212 //*************************************************************************
3214 //*************************************************************************
3215 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
3216 {
3217 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3218
3219 return *this;
3220 }
3221
3222 //*************************************************************************
3224 //*************************************************************************
3225 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const wchar_t* text) ETL_NOEXCEPT
3226 {
3227 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3228
3229 return *this;
3230 }
3231
3232 //*************************************************************************
3234 //*************************************************************************
3235 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char16_t* text) ETL_NOEXCEPT
3236 {
3237 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3238
3239 return *this;
3240 }
3241
3242 //*************************************************************************
3244 //*************************************************************************
3245 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char32_t* text) ETL_NOEXCEPT
3246 {
3247 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3248
3249 return *this;
3250 }
3251
3252 //*************************************************************************
3254 //*************************************************************************
3255 template <typename T>
3256 ETL_CONSTEXPR14
3257 T value() const ETL_NOEXCEPT
3258 {
3259 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3260 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
3261
3262 return implementation::template value<T>(pbuffer, Number_Of_Elements);
3263 }
3264
3265 //*************************************************************************
3268 //*************************************************************************
3269 template <typename T>
3270 ETL_CONSTEXPR14
3271 T extract(size_t position, size_t length = etl::integral_limits<T>::bits)
3272 {
3273 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3274
3275 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
3276 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
3277
3278 return implementation::template extract<T>(pbuffer, position, length);
3279 }
3280
3281 //*************************************************************************
3284 //*************************************************************************
3285#if ETL_USING_CPP11
3286 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
3287#else
3288 template <typename T, size_t Position, size_t Length>
3289#endif
3290 ETL_CONSTEXPR14
3291 T extract() const
3292 {
3293 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3294 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
3295 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
3296
3297 return implementation::template extract<T, Position, Length>(pbuffer);
3298 }
3299
3300 //*************************************************************************
3302 //*************************************************************************
3303 unsigned long to_ulong() const
3304 {
3306
3307 return implementation::template value<unsigned long>(pbuffer, Number_Of_Elements);
3308 }
3309
3310 //*************************************************************************
3312 //*************************************************************************
3313 unsigned long long to_ullong() const
3314 {
3316
3317 return implementation::template value<unsigned long long>(pbuffer, Number_Of_Elements);
3318 }
3319
3320 //*************************************************************************
3322 //*************************************************************************
3323 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset() ETL_NOEXCEPT
3324 {
3325 implementation::reset_all(pbuffer, Number_Of_Elements);
3326
3327 return *this;
3328 }
3329
3330 //*************************************************************************
3332 //*************************************************************************
3333 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset(size_t position)
3334 {
3335 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3336
3337 implementation::reset_position(pbuffer, position);
3338
3339 return *this;
3340 }
3341
3342 //*************************************************************************
3345 //*************************************************************************
3346 ETL_CONSTEXPR14 bool test(size_t position) const
3347 {
3348 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
3349
3350 return implementation::test(pbuffer, position);
3351 }
3352
3353 //*************************************************************************
3356 //*************************************************************************
3357 template <size_t Position>
3358 ETL_CONSTEXPR14 bool test() const
3359 {
3360 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3361
3362 return implementation::test(pbuffer, Position);
3363 }
3364
3365 //*************************************************************************
3367 //*************************************************************************
3368 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
3369 {
3370 return Active_Bits;
3371 }
3372
3373 //*************************************************************************
3375 //*************************************************************************
3376 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
3377 {
3378 return Number_Of_Elements;
3379 }
3380
3381 //*************************************************************************
3383 //*************************************************************************
3384 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
3385 {
3386 return All_Set_Element;
3387 }
3388
3389 //*************************************************************************
3391 //*************************************************************************
3392 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
3393 {
3394 return All_Clear_Element;
3395 }
3396
3397 //*************************************************************************
3399 //*************************************************************************
3400 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
3401 {
3402 return Top_Mask;
3403 }
3404
3405 //*************************************************************************
3407 //*************************************************************************
3408 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
3409 {
3410 return Bits_Per_Element;
3411 }
3412
3413 //*************************************************************************
3415 //*************************************************************************
3416 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
3417 {
3418 return Number_Of_Elements * Bits_Per_Element;
3419 }
3420
3421 //*************************************************************************
3425 //*************************************************************************
3426 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
3427 {
3428 return Storage_Model;
3429 }
3430
3431 //*************************************************************************
3433 //*************************************************************************
3434 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
3435 {
3436 return implementation::count(pbuffer, Number_Of_Elements);
3437 }
3438
3439 //*************************************************************************
3440 // Are all the bits sets?
3441 //*************************************************************************
3442 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
3443 {
3444 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask);
3445 }
3446
3447 //*************************************************************************
3448 // Are all the mask bits sets?
3449 //*************************************************************************
3450 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
3451 {
3452 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3453
3454 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask, mask);
3455 }
3456
3457 //*************************************************************************
3459 //*************************************************************************
3460 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
3461 {
3462 return implementation::none(pbuffer, Number_Of_Elements);
3463 }
3464
3465 //*************************************************************************
3467 //*************************************************************************
3468 ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
3469 {
3470 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3471
3472 return implementation::none(pbuffer, Number_Of_Elements, mask);
3473 }
3474
3475 //*************************************************************************
3477 //*************************************************************************
3478 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
3479 {
3480 return implementation::any(pbuffer, Number_Of_Elements);
3481 }
3482
3483 //*************************************************************************
3485 //*************************************************************************
3486 ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
3487 {
3488 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3489
3490 return implementation::any(pbuffer, Number_Of_Elements, mask);
3491 }
3492
3493 //*************************************************************************
3495 //*************************************************************************
3496 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip() ETL_NOEXCEPT
3497 {
3498 implementation::flip_all(pbuffer, Number_Of_Elements);
3499
3500 return *this;
3501 }
3502
3503 //*************************************************************************
3505 //*************************************************************************
3506 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip(size_t position)
3507 {
3508 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3509
3510 implementation::flip_position(pbuffer, position);
3511
3512 return *this;
3513 }
3514
3515 //*************************************************************************
3517 //*************************************************************************
3518 ETL_CONSTEXPR14 bool operator[] (size_t position) const ETL_NOEXCEPT
3519 {
3520 return implementation::test(pbuffer, position);
3521 }
3522
3523 //*************************************************************************
3525 //*************************************************************************
3526 ETL_CONSTEXPR14 bit_reference operator [] (size_t position) ETL_NOEXCEPT
3527 {
3528 return bit_reference(*this, position);
3529 }
3530
3531 //*************************************************************************
3533 //*************************************************************************
3534#if ETL_USING_CPP11
3535 template <typename TString = etl::string<Active_Bits>>
3536#else
3537 template <typename TString>
3538#endif
3539 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
3540 typename TString::value_type one = typename TString::value_type('1')) const
3541 {
3542 return implementation::template to_string<TString>(pbuffer, Active_Bits, zero, one);
3543 }
3544
3545 //*************************************************************************
3549 //*************************************************************************
3550 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
3551 {
3552 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, 0);
3553 }
3554
3555 //*************************************************************************
3560 //*************************************************************************
3561 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
3562 {
3563 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, position);
3564 }
3565
3566 //*************************************************************************
3568 //*************************************************************************
3569 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator &=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3570 {
3571 implementation::operator_and(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3572
3573 return *this;
3574 }
3575
3576 //*************************************************************************
3578 //*************************************************************************
3579 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator |=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3580 {
3581 implementation::operator_or(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3582
3583 return *this;
3584 }
3585
3586 //*************************************************************************
3588 //*************************************************************************
3589 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator ^=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3590 {
3591 implementation::operator_xor(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3592
3593 return *this;
3594 }
3595
3596 //*************************************************************************
3598 //*************************************************************************
3599 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator <<=(size_t shift) ETL_NOEXCEPT
3600 {
3601 implementation::operator_shift_left(pbuffer, Number_Of_Elements, Active_Bits, shift);
3602
3603 return *this;
3604 }
3605
3606 //*************************************************************************
3608 //*************************************************************************
3609 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator >>=(size_t shift) ETL_NOEXCEPT
3610 {
3611 implementation::operator_shift_right(pbuffer, Number_Of_Elements, Active_Bits, shift);
3612
3613 return *this;
3614 }
3615
3616 //*************************************************************************
3618 //*************************************************************************
3619 friend ETL_CONSTEXPR14 bool operator ==(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3620 {
3621 return implementation::operator_equality(lhs.pbuffer, rhs.pbuffer, lhs.Number_Of_Elements);
3622 }
3623
3624 //*************************************************************************
3626 //*************************************************************************
3627 friend ETL_CONSTEXPR14 bool operator !=(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3628 {
3629 return !(lhs == rhs);
3630 }
3631
3632 //*************************************************************************
3634 //*************************************************************************
3635 ETL_CONSTEXPR14 void swap(etl::bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3636 {
3637 implementation::swap(pbuffer, other.pbuffer, Number_Of_Elements);
3638 }
3639
3640 //*************************************************************************
3643 //*************************************************************************
3644 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
3645 {
3646 return span_type(pbuffer, Number_Of_Elements);
3647 }
3648
3649 //*************************************************************************
3652 //*************************************************************************
3653 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
3654 {
3655 return const_span_type(pbuffer, Number_Of_Elements);
3656 }
3657
3658 private:
3659
3660 // The implementation of the bitset functionality.
3661 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi> implementation;
3662
3663 // Pointer to the storage for the bitset.
3664 element_type* pbuffer;
3665 };
3666}
3667
3668//***************************************************************************
3671//***************************************************************************
3672template<size_t Active_Bits, typename TElement>
3674{
3675 return !(lhs == rhs);
3676}
3677
3678//*************************************************************************
3680//*************************************************************************
3681template <size_t Active_Bits, typename TElement>
3683{
3684 lhs.swap(rhs);
3685}
3686
3687namespace etl
3688{
3689 namespace private_bitset
3690 {
3691 //*************************************************************************
3694 //*************************************************************************
3695 template <typename TLhsSpan, typename TRhsSpan>
3696 bool compare_bitset_spans(const TLhsSpan& lhs_span, const TRhsSpan& rhs_span)
3697 {
3698 typedef typename TLhsSpan::value_type lhs_element_t;
3699 typedef typename TRhsSpan::value_type rhs_element_t;
3700
3701 const int steps = static_cast<int>(sizeof(lhs_element_t) / sizeof(rhs_element_t));
3702
3703 typename TLhsSpan::iterator lhs_itr = lhs_span.begin();
3704 typename TRhsSpan::iterator rhs_itr = rhs_span.begin();
3705
3706 while (lhs_itr != lhs_span.end())
3707 {
3708 const lhs_element_t& lhs_value = *lhs_itr;
3709
3710 // Build the rhs element in terms of the lhs element type.
3711 lhs_element_t rhs_value = 0;
3712
3713 const int shift_step = etl::integral_limits<rhs_element_t>::bits;
3714 int shift = 0;
3715
3716 for (int i = 0; i < steps; ++i)
3717 {
3718 rhs_value |= (static_cast<lhs_element_t>(*rhs_itr) << shift);
3719 ++rhs_itr;
3720 shift += shift_step;
3721 }
3722
3723 if (lhs_value != rhs_value)
3724 {
3725 return false;
3726 }
3727
3728 ++lhs_itr;
3729 }
3730
3731 return true;
3732 }
3733 }
3734}
3735
3736//***************************************************************************
3741//***************************************************************************
3742template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3743ETL_CONSTEXPR14
3746{
3747 // Get a span of each type.
3748 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3749 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3750
3751 // Put the bitset with the largest element type as the first argument.
3752 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3753 {
3754 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3755 }
3756 else
3757 {
3758 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3759 }
3760}
3761
3762//***************************************************************************
3767//***************************************************************************
3768template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3769ETL_CONSTEXPR14
3772{
3773 return !(lhs == rhs);
3774}
3775
3776//***************************************************************************
3781//***************************************************************************
3782template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3783ETL_CONSTEXPR14
3786{
3787 // Get a span of each type.
3790
3791 // Put the bitset with the largest element type as the first argument.
3792 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3793 {
3794 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3795 }
3796 else
3797 {
3798 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3799 }
3800}
3801
3802//***************************************************************************
3807//***************************************************************************
3808template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3809ETL_CONSTEXPR14
3812{
3813 return !(lhs == rhs);
3814}
3815
3816//***************************************************************************
3820//***************************************************************************
3821template<size_t Active_Bits, typename TElement>
3822ETL_CONSTEXPR14
3824{
3825 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3826 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3827
3828 typename etl::bitset<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3829 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3830
3831 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3832
3833 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3834}
3835
3836//***************************************************************************
3840//***************************************************************************
3841template<size_t Active_Bits, typename TElement>
3842ETL_CONSTEXPR14
3844{
3845 return !(lhs == rhs);
3846}
3847
3848//***************************************************************************
3852//***************************************************************************
3853template<size_t Active_Bits, typename TElement>
3854ETL_CONSTEXPR14
3856{
3857 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3858 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3859
3860 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3861 typename etl::bitset<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3862
3863 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3864
3865 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3866}
3867
3868//***************************************************************************
3872//***************************************************************************
3873template<size_t Active_Bits, typename TElement>
3874ETL_CONSTEXPR14
3876{
3877 return !(lhs == rhs);
3878}
3879
3880//***************************************************************************
3884//***************************************************************************
3885template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3886ETL_CONSTEXPR14
3889{
3890 // Get a span of each type.
3891 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3893
3894 // Put the bitset with the largest element type as the first argument.
3895 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3896 {
3897 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3898 }
3899 else
3900 {
3901 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3902 }
3903}
3904
3905//***************************************************************************
3909//***************************************************************************
3910template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3911ETL_CONSTEXPR14
3914{
3915 return !(lhs == rhs);
3916}
3917
3918//***************************************************************************
3922//***************************************************************************
3923template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3924ETL_CONSTEXPR14
3927{
3928 // Get a span of each type.
3930 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3931
3932 // Put the bitset with the largest element type as the first argument.
3933 if ETL_IF_CONSTEXPR(sizeof(TLhsElement) > sizeof(TRhsElement))
3934 {
3935 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3936 }
3937 else
3938 {
3939 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3940 }
3941}
3942
3943//***************************************************************************
3947//***************************************************************************
3948template<size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3949ETL_CONSTEXPR14
3952{
3953 return !(lhs == rhs);
3954}
3955
3956#include "minmax_pop.h"
3957
3958#endif
The reference type returned.
Definition bitset_new.h:1953
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:1961
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1978
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:1996
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:2005
The reference type returned.
Definition bitset_new.h:2872
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2897
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:2915
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:2924
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:2880
Definition binary.h:2216
Definition binary.h:2249
Definition bitset_new.h:1844
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:966
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:1765
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:1272
ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:2470
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:1423
bitset< MaxN > & operator&=(const bitset< MaxN > &other)
operator &=
Definition bitset_legacy.h:1389
ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
Definition bitset_new.h:2563
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:1470
ETL_CONSTEXPR14 T extract(size_t position, size_t length=etl::integral_limits< T >::bits) const
Definition bitset_new.h:2273
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:994
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:2126
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:1365
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:1324
ETL_CONSTEXPR14 bitset(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:2046
static ETL_CONSTEXPR14 void swap(pointer lhs_pbuffer, pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
swap
Definition bitset_new.h:846
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:2193
friend bool operator==(const bitset< MaxN > &lhs, const bitset< MaxN > &rhs)
operator ==
Definition bitset_legacy.h:1470
static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position)
Reset the bit at the position.
Definition bitset_new.h:311
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t) ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:614
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:1384
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:602
static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
The value of a set element.
Definition bitset_new.h:2386
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:237
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:2246
bitset< MaxN > & flip()
Flip all of the bits.
Definition bitset_legacy.h:1334
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:1076
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:497
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:2236
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:1442
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set() ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:2115
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:677
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:834
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:1527
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:2498
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:2216
ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
Definition bitset_new.h:2741
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:1111
ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:2462
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:2086
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position)
Flip the bit at the position.
Definition bitset_new.h:636
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:1146
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator&(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator &
Definition bitset_new.h:2571
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value=true)
Set the bit at the position.
Definition bitset_new.h:1034
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:1552
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:579
ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
Definition bitset_new.h:2552
static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
Set the bit at the position.
Definition bitset_new.h:1056
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:2056
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:2226
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:1569
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip(size_t position)
Flip the bit at the position.
Definition bitset_new.h:2508
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:1305
static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
The number of storage elements in the bitset.
Definition bitset_new.h:2378
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:908
static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:744
ETL_CONSTEXPR14 void swap(etl::bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
swap
Definition bitset_new.h:2723
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:1401
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:2541
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:356
static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
The total number of bits of storage, including unused.
Definition bitset_new.h:2418
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:1635
static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
The mask for the msb element.
Definition bitset_new.h:2410
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:1586
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:801
ETL_CONSTEXPR14 bool test(size_t position) const
Definition bitset_new.h:2348
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:2259
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:591
ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:2488
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:2096
static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
The value of a clear element.
Definition bitset_new.h:2394
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset() ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:2325
static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:1216
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:323
bitset< MaxN > & operator<<=(size_t shift)
operator <<=
Definition bitset_legacy.h:1440
bitset< MaxN > operator<<(size_t shift) const
operator <<
Definition bitset_legacy.h:1428
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:781
static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:757
static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Get as a value.
Definition bitset_new.h:1245
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:625
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:953
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Flip the bit at the position.
Definition bitset_new.h:1453
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator|(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator |
Definition bitset_new.h:2593
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:1011
static ETL_CONSTEXPR14 void swap(pointer pbuffer1, pointer pbuffer2, size_t number_of_elements)
Swap bitset buffers.
Definition bitset_new.h:1831
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator not
Definition bitset_new.h:1620
bitset< MaxN > & operator|=(const bitset< MaxN > &other)
operator |=
Definition bitset_legacy.h:1398
static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
The number of bits in an element.
Definition bitset_new.h:2402
ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:2436
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:1780
bitset< MaxN > operator~() const
operator ~
Definition bitset_legacy.h:1416
static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Get as an integral value.
Definition bitset_new.h:456
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(bool value=true)
Set the bit at the position.
Definition bitset_new.h:2139
friend ETL_CONSTEXPR14 bool operator!=(const bitset< Active_Bits, TElement > &lhs, const bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator !=
Definition bitset_new.h:2715
ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
Read [] operator.
Definition bitset_new.h:2520
static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t) ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:299
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:2076
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:2167
bitset< MaxN > operator>>(size_t shift) const
operator >>
Definition bitset_legacy.h:1449
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:972
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position)
Definition bitset_new.h:520
static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Reset the bit at the position.
Definition bitset_new.h:1230
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator^(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator ^
Definition bitset_new.h:2615
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:225
static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:568
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:1181
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset(size_t position)
Reset the bit at the position.
Definition bitset_new.h:2335
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:2180
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
The number of bits in the bitset.
Definition bitset_new.h:2370
bitset< MaxN > & operator=(const bitset< MaxN > &other)
operator =
Definition bitset_legacy.h:1376
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:2066
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:422
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:1699
bitset< MaxN > & operator^=(const bitset< MaxN > &other)
operator ^=
Definition bitset_legacy.h:1407
static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:731
static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
Set the bit at the position.
Definition bitset_new.h:280
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set()
Set the bit at the position.
Definition bitset_new.h:2152
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:468
unsigned long long to_ullong() const
Get as an unsigned long long.
Definition bitset_new.h:2315
ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:2480
static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
operator_equality
Definition bitset_new.h:821
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:2360
ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
Definition bitset_new.h:2732
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:389
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value=true)
Set the bit at the position.
Definition bitset_new.h:259
unsigned long to_ulong() const
Get as an unsigned long.
Definition bitset_new.h:2305
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:1603
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:1804
static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:532
static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:718
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:894
ETL_CONSTEXPR14 T extract() const
Definition bitset_new.h:2293
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:770
bitset< MaxN > & set()
Set all of the bits.
Definition bitset_legacy.h:1205
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:649
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:2206
ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
Default constructor.
Definition bitset_new.h:2037
bitset< MaxN > & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:1461
static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
Definition bitset_new.h:2428
Bitset forward declaration.
Definition bitset_legacy.h:1128
Definition bitset_legacy.h:85
Definition bitset_new.h:199
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:2797
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:3745
Definition bitset_new.h:92
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition exception.h:47
Definition integral_limits.h:516
Definition log.h:99
enable_if
Definition type_traits_generator.h:1191
is_integral
Definition type_traits_generator.h:1001
is_same
Definition type_traits_generator.h:1041
is_unsigned
Definition type_traits_generator.h:1021
make_unsigned
Definition type_traits_generator.h:1181
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