31#ifndef ETL_BITSET_LEGACY_INCLUDED
32#define ETL_BITSET_LEGACY_INCLUDED
34#include "../platform.h"
35#include "../algorithm.h"
36#include "../iterator.h"
37#include "../integral_limits.h"
38#include "../algorithm.h"
39#include "../nullptr.h"
41#include "../exception.h"
42#include "../integral_limits.h"
44#include "../char_traits.h"
45#include "../static_assert.h"
46#include "../error_handler.h"
56#if defined(ETL_COMPILER_KEIL)
57#pragma diag_suppress 1300
62 #define ETL_STRL(x) L##x
63 #define ETL_STRu(x) u##x
64 #define ETL_STRU(x) U##x
145#if !defined(ETL_BITSET_ELEMENT_TYPE)
146 #define ETL_BITSET_ELEMENT_TYPE uint_least8_t
151 typedef typename etl::make_unsigned<ETL_BITSET_ELEMENT_TYPE>::type element_type;
155 static ETL_CONSTANT element_type ALL_CLEAR = 0;
183 return p_bitset->
test(position);
190 : p_bitset(
other.p_bitset)
191 , position(
other.position)
200 p_bitset->
set(position,
b);
209 p_bitset->
set(position,
bool(
r));
218 p_bitset->
flip(position);
227 return !p_bitset->
test(position);
236 : p_bitset(ETL_NULLPTR)
269 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
281 bool test(
size_t position)
const
283 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow),
false);
287 if (position >= Active_Bits)
291 if (Number_Of_Elements == 0)
295 else if (Number_Of_Elements == 1)
298 mask = element_type(1) << position;
303 mask = element_type(1) << (position & (Bits_Per_Element - 1));
306 return (pdata[index] &
mask) != 0;
314 ::memset(pdata, 0xFF, Number_Of_Elements);
315 pdata[Number_Of_Elements - 1U] = Top_Mask;
325 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
329 if (position < Active_Bits)
331 if (Number_Of_Elements == 0)
335 else if (Number_Of_Elements == 1)
338 bit = element_type(1) << position;
343 bit = element_type(1) << (position & (Bits_Per_Element - 1));
352 pdata[index] &=
~bit;
370 set(--
i, *text++ == ETL_STRL(
'1'));
387 set(--
i, *text++ == ETL_STRL(
'1'));
404 set(--
i, *text++ == ETL_STRu(
'1'));
421 set(--
i, *text++ == ETL_STRU(
'1'));
470 template <
typename T>
476 const bool OK = (
sizeof(
T) *
CHAR_BIT) >= (Number_Of_Elements * Bits_Per_Element);
484 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
486 v |=
T(
typename etl::make_unsigned<T>::type(pdata[
i]) <<
shift);
515 ::memset(pdata, 0x00, Number_Of_Elements);
525 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
529 if (position < Active_Bits)
531 if (Number_Of_Elements == 0)
535 else if (Number_Of_Elements == 1)
538 bit = element_type(1) << position;
543 bit = element_type(1) << (position & (Bits_Per_Element - 1));
546 pdata[index] &=
~bit;
557 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
559 pdata[
i] = ~pdata[
i];
562 clear_unused_bits_in_msb();
572 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
576 if (Number_Of_Elements == 0)
580 else if (Number_Of_Elements == 1)
583 bit = element_type(1) << position;
588 bit = element_type(1) << (position & (Bits_Per_Element - 1));
601 if (Number_Of_Elements == 0
UL)
607 for (
size_t i = 0UL; i < (Number_Of_Elements - 1U); ++i)
609 if (pdata[i] != ALL_SET)
616 if (pdata[Number_Of_Elements - 1U] != (ALL_SET & Top_Mask))
637 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
670 if (Number_Of_Elements == 0)
672 return ibitset::npos;
674 else if (Number_Of_Elements == 1)
682 bit = position & (Bits_Per_Element - 1);
688 while (index < Number_Of_Elements)
690 element_type
value = pdata[index];
693 if ((state && (
value != ALL_CLEAR)) ||
694 (!state && (
value != ALL_SET)))
697 while ((
bit < Bits_Per_Element) && (position < Active_Bits))
713 position += (Bits_Per_Element -
bit);
723 return ibitset::npos;
731 return test(position);
747 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
760 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
773 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
786 if (
shift >= Active_Bits)
790 else if (Number_Of_Elements != 0
UL)
793 if (Number_Of_Elements == 1UL)
797 else if (
shift == Bits_Per_Element)
799 etl::copy_backward(pdata, pdata + Number_Of_Elements - 1U, pdata + Number_Of_Elements);
854 clear_unused_bits_in_msb();
865 if (
shift >= Active_Bits)
869 else if (Number_Of_Elements != 0
UL)
872 if (Number_Of_Elements == 1UL)
877 else if (
shift == Bits_Per_Element)
879 etl::copy(pdata + 1, pdata + Number_Of_Elements, pdata);
880 pdata[Number_Of_Elements - 1U] = 0;
902 while (
src_index <
int(Number_Of_Elements - 1))
926 while (
dst_index <
int(Number_Of_Elements))
944 etl::copy_n(
other.pdata, Number_Of_Elements, pdata);
955 etl::swap_ranges(pdata, pdata + Number_Of_Elements,
other.pdata);
965 return span_type(pdata, pdata + Number_Of_Elements);
972 const_span_type span()
const
974 return const_span_type(pdata, pdata + Number_Of_Elements);
992 pdata[0] = element_type(
value);
998 while ((
value != 0) && (
i < Number_Of_Elements))
1000 pdata[
i++] =
value & ALL_SET;
1005 clear_unused_bits_in_msb();
1015 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
1017 pdata[
i] = ~pdata[
i];
1020 clear_unused_bits_in_msb();
1036 , Number_Of_Elements(
size_)
1039 const size_t allocated_bits = Number_Of_Elements * Bits_Per_Element;
1049 return etl::equal(
lhs.pdata,
lhs.pdata +
lhs.Number_Of_Elements,
rhs.pdata);
1052 element_type Top_Mask;
1059 void clear_unused_bits_in_msb()
1061 pdata[Number_Of_Elements - 1U] &= Top_Mask;
1065 ibitset(
const ibitset&);
1067 const size_t Active_Bits;
1068 const size_t Number_Of_Elements;
1069 element_type* pdata;
1074#if defined(ETL_POLYMORPHIC_BITSET) || defined(ETL_POLYMORPHIC_CONTAINERS)
1087 ETL_CONSTANT ibitset::element_type ibitset::ALL_SET;
1089 ETL_CONSTANT ibitset::element_type ibitset::ALL_CLEAR;
1091 ETL_CONSTANT
size_t ibitset::Bits_Per_Element;
1100 template <
size_t MaxN>
1104 static ETL_CONSTANT
size_t Array_Size = (
MaxN % Bits_Per_Element == 0) ?
MaxN / Bits_Per_Element :
MaxN / Bits_Per_Element + 1;
1108 static ETL_CONSTANT
size_t ALLOCATED_BITS = Array_Size * Bits_Per_Element;
1109 static ETL_CONSTANT
size_t Allocated_Bits = ALLOCATED_BITS;
1128 etl::copy_n(
other.data, Array_Size, data);
1199 ETL_ASSERT_OR_RETURN_VALUE(text != 0, ETL_ERROR(
bitset_nullptr), *
this);
1210 ETL_ASSERT_OR_RETURN_VALUE(text != 0, ETL_ERROR(
bitset_nullptr), *
this);
1221 ETL_ASSERT_OR_RETURN_VALUE(text != 0, ETL_ERROR(
bitset_nullptr), *
this);
1232 ETL_ASSERT_OR_RETURN_VALUE(text != 0, ETL_ERROR(
bitset_nullptr), *
this);
1281 template <
typename T>
1286 ETL_STATIC_ASSERT((
sizeof(
T) *
CHAR_BIT) >= (Array_Size * Bits_Per_Element),
"Type too small");
1288 return ibitset::value<T>();
1331 template <
typename TString = etl::
string<MaxN>>
1333 template <
typename TString>
1335 TString to_string(
typename TString::value_type
zero =
typename TString::value_type(
'0'),
typename TString::value_type
one =
typename TString::value_type(
'1'))
const
1339 result.resize(
MaxN,
'\0');
1343 for (
size_t i =
MaxN;
i > 0; --
i)
1358 etl::copy_n(
other.data, Array_Size, data);
1455 element_type data[Array_Size > 0U ? Array_Size : 1U];
1458 template <
size_t MaxN>
1459 ETL_CONSTANT
size_t bitset<MaxN>::ALLOCATED_BITS;
1461 template <
size_t MaxN>
1462 ETL_CONSTANT
size_t bitset<MaxN>::Allocated_Bits;
1468 template <
size_t MaxN>
1480 template<
size_t MaxN>
1492 template<
size_t MaxN>
1504 template<
size_t MaxN>
1514template <
size_t MaxN>
void swap(etl::bitset< MaxN > &lhs, etl::bitset< MaxN > &rhs)
swap
Definition bitset_legacy.h:1515
The reference type returned.
Definition bitset_legacy.h:173
bool operator~() const
Return the logical inverse of the bit.
Definition bitset_legacy.h:225
bit_reference(const bit_reference &other)
Copy constructor.
Definition bitset_legacy.h:189
bit_reference & operator=(bool b)
Assignment operator.
Definition bitset_legacy.h:198
bit_reference & flip()
Flip the bit.
Definition bitset_legacy.h:216
Span - Fixed Extent.
Definition span.h:62
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:956
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:472
ibitset & set()
Set all bits.
Definition bitset_legacy.h:312
bitset< MaxN > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_legacy.h:1188
ibitset & reset()
Resets the bitset.
Definition bitset_legacy.h:513
bitset< MaxN > & operator&=(const bitset< MaxN > &other)
operator &=
Definition bitset_legacy.h:1367
bitset(const char16_t *text)
Construct from a string.
Definition bitset_legacy.h:1161
size_t find_first(bool state) const
Definition bitset_legacy.h:653
size_t find_next(bool state, size_t position) const
Definition bitset_legacy.h:664
ibitset & initialise(unsigned long long value)
Initialise from an unsigned long long.
Definition bitset_legacy.h:983
ibitset & from_string(const char16_t *text)
Set from a u16 string.
Definition bitset_legacy.h:396
bool any() const
Are any of the bits set?
Definition bitset_legacy.h:627
~ibitset()
Destructor.
Definition bitset_legacy.h:1081
friend bool operator==(const bitset< MaxN > &lhs, const bitset< MaxN > &rhs)
operator ==
Definition bitset_legacy.h:1448
bitset< MaxN > & flip()
Flip all of the bits.
Definition bitset_legacy.h:1312
bit_reference get_bit_reference(size_t position)
Gets a reference to the specified bit.
Definition bitset_legacy.h:1026
ibitset & operator|=(const ibitset &other)
operator |=
Definition bitset_legacy.h:758
bitset(const bitset< MaxN > &other)
Copy constructor.
Definition bitset_legacy.h:1125
ibitset(size_t nbits_, size_t size_, element_type *pdata_)
Constructor.
Definition bitset_legacy.h:1034
bitset< MaxN > & set(const char32_t *text)
Set from a string.
Definition bitset_legacy.h:1230
bitset< MaxN > & set(const wchar_t *text)
Set from a string.
Definition bitset_legacy.h:1208
bitset(const char *text)
Construct from a string.
Definition bitset_legacy.h:1143
void swap(ibitset &other)
swap
Definition bitset_legacy.h:953
ibitset & operator=(const ibitset &other)
operator =
Definition bitset_legacy.h:940
bitset< MaxN > & reset()
Reset all of the bits.
Definition bitset_legacy.h:1294
bitset(const wchar_t *text)
Construct from a string.
Definition bitset_legacy.h:1152
ibitset & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:863
ibitset & operator^=(const ibitset &other)
operator ^=
Definition bitset_legacy.h:771
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:1283
bitset(unsigned long long value)
Construct from a value.
Definition bitset_legacy.h:1134
bitset< MaxN > & reset(size_t position)
Reset the bit at the position.
Definition bitset_legacy.h:1303
size_t count() const
Count the number of bits set.
Definition bitset_legacy.h:265
ibitset & from_string(const wchar_t *text)
Set from a wide string.
Definition bitset_legacy.h:379
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_legacy.h:1335
ibitset & set(const char32_t *text)
Set from a u32string.
Definition bitset_legacy.h:460
ibitset & from_string(const char32_t *text)
Set from a u32 string.
Definition bitset_legacy.h:413
ibitset & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_legacy.h:323
ibitset & flip()
Flip all of the bits.
Definition bitset_legacy.h:555
bitset(const char32_t *text)
Construct from a string.
Definition bitset_legacy.h:1170
ibitset & operator&=(const ibitset &other)
operator &=
Definition bitset_legacy.h:745
bitset< MaxN > & from_string(const wchar_t *text)
Set from a wide string.
Definition bitset_legacy.h:1251
bitset< MaxN > & operator<<=(size_t shift)
operator <<=
Definition bitset_legacy.h:1418
bitset< MaxN > operator<<(size_t shift) const
operator <<
Definition bitset_legacy.h:1406
unsigned long to_ulong() const
Put to a unsigned long.
Definition bitset_legacy.h:497
bool operator[](size_t position) const
Read [] operator.
Definition bitset_legacy.h:729
unsigned long long to_ullong() const
Put to a unsigned long long.
Definition bitset_legacy.h:505
bitset< MaxN > & operator|=(const bitset< MaxN > &other)
operator |=
Definition bitset_legacy.h:1376
void invert()
Invert.
Definition bitset_legacy.h:1013
bitset()
Default constructor.
Definition bitset_legacy.h:1116
bitset< MaxN > operator~() const
operator ~
Definition bitset_legacy.h:1394
bitset< MaxN > operator>>(size_t shift) const
operator >>
Definition bitset_legacy.h:1427
bitset< MaxN > & from_string(const char16_t *text)
Set from a u16 string.
Definition bitset_legacy.h:1261
ibitset & reset(size_t position)
Reset the bit at the position.
Definition bitset_legacy.h:523
bitset< MaxN > & set(const char *text)
Set from a string.
Definition bitset_legacy.h:1197
ibitset & from_string(const char *text)
Set from a string.
Definition bitset_legacy.h:362
bitset< MaxN > & operator=(const bitset< MaxN > &other)
operator =
Definition bitset_legacy.h:1354
ibitset & set(const char16_t *text)
Set from a u16string.
Definition bitset_legacy.h:450
ibitset & set(const wchar_t *text)
Set from a wstring.
Definition bitset_legacy.h:440
ibitset & operator<<=(size_t shift)
operator <<=
Definition bitset_legacy.h:784
bitset< MaxN > & operator^=(const bitset< MaxN > &other)
operator ^=
Definition bitset_legacy.h:1385
bool none() const
Are none of the bits set?
Definition bitset_legacy.h:635
bitset< MaxN > & from_string(const char32_t *text)
Set from a u32 string.
Definition bitset_legacy.h:1271
bool test(size_t position) const
Definition bitset_legacy.h:281
size_t size() const
The number of bits in the bitset.
Definition bitset_legacy.h:257
bitset< MaxN > & set(const char16_t *text)
Set from a string.
Definition bitset_legacy.h:1219
ibitset & flip(size_t position)
Flip the bit at the position.
Definition bitset_legacy.h:570
bitset< MaxN > & flip(size_t position)
Flip the bit at the position.
Definition bitset_legacy.h:1321
ibitset & set(const char *text)
Set from a string.
Definition bitset_legacy.h:430
bitset< MaxN > & set()
Set all of the bits.
Definition bitset_legacy.h:1179
bitset< MaxN > & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:1439
static bool is_equal(const ibitset &lhs, const ibitset &rhs)
Compare bitsets.
Definition bitset_legacy.h:1047
bitset< MaxN > & from_string(const char *text)
Set from a string.
Definition bitset_legacy.h:1241
Definition bitset_legacy.h:1102
Definition bitset_legacy.h:85
Definition bitset_legacy.h:99
Definition bitset_legacy.h:127
Definition bitset_legacy.h:113
Definition bitset_legacy.h:141
Definition exception.h:47
Definition integral_limits.h:468
is_integral
Definition type_traits_generator.h:1001
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
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:645
etl::byte operator^(etl::byte lhs, etl::byte rhs)
Exclusive Or.
Definition byte.h:281
ETL_CONSTEXPR size_t strlen(const T *t)
Alternative strlen for all character types.
Definition char_traits.h:267
pair holds two objects of arbitrary type
Definition utility.h:164