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
154 typedef element_type element_t;
157 static ETL_CONSTANT element_type ALL_CLEAR = 0;
185 return p_bitset->
test(position);
192 : p_bitset(
other.p_bitset)
193 , position(
other.position)
202 p_bitset->
set(position,
b);
211 p_bitset->
set(position,
bool(
r));
220 p_bitset->
flip(position);
229 return !p_bitset->
test(position);
238 : p_bitset(ETL_NULLPTR)
271 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
283 bool test(
size_t position)
const
285 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow),
false);
289 if (position >= Active_Bits)
293 if (Number_Of_Elements == 0)
297 else if (Number_Of_Elements == 1)
300 mask = element_type(1) << position;
305 mask = element_type(1) << (position & (Bits_Per_Element - 1));
308 return (pdata[index] &
mask) != 0;
316 etl::fill_n(pdata, Number_Of_Elements - 1U, ALL_SET);
317 pdata[Number_Of_Elements - 1U] = Top_Mask;
327 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
331 if (position < Active_Bits)
333 if (Number_Of_Elements == 0)
337 else if (Number_Of_Elements == 1)
340 bit = element_type(1) << position;
345 bit = element_type(1) << (position & (Bits_Per_Element - 1));
354 pdata[index] &=
~bit;
372 set(--
i, *text++ == ETL_STRL(
'1'));
389 set(--
i, *text++ == ETL_STRL(
'1'));
406 set(--
i, *text++ == ETL_STRu(
'1'));
423 set(--
i, *text++ == ETL_STRU(
'1'));
434 if (text == ETL_NULLPTR)
451 if (text == ETL_NULLPTR)
468 if (text == ETL_NULLPTR)
485 if (text == ETL_NULLPTR)
500 template <
typename T>
506 const bool OK = (
sizeof(
T) *
CHAR_BIT) >= (Number_Of_Elements * Bits_Per_Element);
514 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
545 etl::fill_n(pdata, Number_Of_Elements, ALL_CLEAR);
555 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
559 if (position < Active_Bits)
561 if (Number_Of_Elements == 0)
565 else if (Number_Of_Elements == 1)
568 bit = element_type(1) << position;
573 bit = element_type(1) << (position & (Bits_Per_Element - 1));
576 pdata[index] &=
~bit;
592 clear_unused_bits_in_msb();
602 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
606 if (Number_Of_Elements == 0)
610 else if (Number_Of_Elements == 1)
613 bit = element_type(1) << position;
618 bit = element_type(1) << (position & (Bits_Per_Element - 1));
631 if (Number_Of_Elements == 0
UL)
637 for (
size_t i = 0UL; i < (Number_Of_Elements - 1U); ++i)
639 if (pdata[i] != ALL_SET)
646 if (pdata[Number_Of_Elements - 1U] != (ALL_SET & Top_Mask))
667 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
700 if (Number_Of_Elements == 0)
702 return ibitset::npos;
704 else if (Number_Of_Elements == 1)
712 bit = position & (Bits_Per_Element - 1);
718 while (index < Number_Of_Elements)
720 element_type
value = pdata[index];
723 if ((state && (
value != ALL_CLEAR)) ||
724 (!state && (
value != ALL_SET)))
727 while ((
bit < Bits_Per_Element) && (position < Active_Bits))
743 position += (Bits_Per_Element -
bit);
753 return ibitset::npos;
761 return test(position);
777 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
790 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
803 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
816 if (
shift >= Active_Bits)
820 else if (Number_Of_Elements != 0
UL)
823 if (Number_Of_Elements == 1UL)
827 else if (
shift == Bits_Per_Element)
829 etl::copy_backward(pdata, pdata + Number_Of_Elements - 1U, pdata + Number_Of_Elements);
883 clear_unused_bits_in_msb();
894 if (
shift >= Active_Bits)
898 else if (Number_Of_Elements != 0
UL)
901 if (Number_Of_Elements == 1UL)
906 else if (
shift == Bits_Per_Element)
908 etl::copy(pdata + 1, pdata + Number_Of_Elements, pdata);
909 pdata[Number_Of_Elements - 1U] = 0;
931 while (
src_index <
int(Number_Of_Elements - 1))
972 etl::copy_n(
other.pdata, Number_Of_Elements, pdata);
983 etl::swap_ranges(pdata, pdata + Number_Of_Elements,
other.pdata);
993 return span_type(pdata, pdata + Number_Of_Elements);
1000 const_span_type span()
const
1002 return const_span_type(pdata, pdata + Number_Of_Elements);
1020 pdata[0] = element_type(
value);
1026 while ((
value != 0) && (
i < Number_Of_Elements))
1028 pdata[
i++] =
value & ALL_SET;
1033 clear_unused_bits_in_msb();
1043 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
1045 pdata[
i] = ~pdata[
i];
1048 clear_unused_bits_in_msb();
1064 , Number_Of_Elements(
size_)
1067 const size_t allocated_bits = Number_Of_Elements * Bits_Per_Element;
1068 const size_t top_mask_shift = ((Bits_Per_Element - (allocated_bits - Active_Bits)) % Bits_Per_Element);
1077 return etl::equal(
lhs.pdata,
lhs.pdata +
lhs.Number_Of_Elements,
rhs.pdata);
1080 element_type Top_Mask;
1087 void clear_unused_bits_in_msb()
1089 pdata[Number_Of_Elements - 1U] &= Top_Mask;
1093 ibitset(
const ibitset&);
1095 const size_t Active_Bits;
1096 const size_t Number_Of_Elements;
1097 element_type* pdata;
1102#if defined(ETL_POLYMORPHIC_BITSET) || defined(ETL_POLYMORPHIC_CONTAINERS)
1115 ETL_CONSTANT ibitset::element_type ibitset::ALL_SET;
1117 ETL_CONSTANT ibitset::element_type ibitset::ALL_CLEAR;
1119 ETL_CONSTANT
size_t ibitset::Bits_Per_Element;
1128 template <
size_t MaxN>
1132 static ETL_CONSTANT
size_t Array_Size = (
MaxN % Bits_Per_Element == 0) ?
MaxN / Bits_Per_Element :
MaxN / Bits_Per_Element + 1;
1136 static ETL_CONSTANT
size_t ALLOCATED_BITS = Array_Size * Bits_Per_Element;
1137 static ETL_CONSTANT
size_t Allocated_Bits = ALLOCATED_BITS;
1156 etl::copy_n(
other.data, Array_Size, data);
1305 template <
typename T>
1310 ETL_STATIC_ASSERT((
sizeof(
T) *
CHAR_BIT) >= (Array_Size * Bits_Per_Element),
"Type too small");
1312 return ibitset::value<T>();
1355 template <
typename TString = etl::
string<MaxN>>
1357 template <
typename TString>
1359 TString to_string(
typename TString::value_type
zero =
typename TString::value_type(
'0'),
typename TString::value_type
one =
typename TString::value_type(
'1'))
const
1363 result.resize(
MaxN,
'\0');
1367 for (
size_t i =
MaxN;
i > 0; --
i)
1382 etl::copy_n(
other.data, Array_Size, data);
1479 element_type data[Array_Size > 0
U ? Array_Size : 1U];
1482 template <
size_t MaxN>
1483 ETL_CONSTANT
size_t bitset<MaxN>::ALLOCATED_BITS;
1485 template <
size_t MaxN>
1486 ETL_CONSTANT
size_t bitset<MaxN>::Allocated_Bits;
1492 template <
size_t MaxN>
1504 template<
size_t MaxN>
1516 template<
size_t MaxN>
1528 template<
size_t MaxN>
1538template <
size_t MaxN>
The reference type returned.
Definition bitset_legacy.h:175
bool operator~() const
Return the logical inverse of the bit.
Definition bitset_legacy.h:227
bit_reference(const bit_reference &other)
Copy constructor.
Definition bitset_legacy.h:191
bit_reference & operator=(bool b)
Assignment operator.
Definition bitset_legacy.h:200
bit_reference & flip()
Flip the bit.
Definition bitset_legacy.h:218
Span - Fixed Extent.
Definition span.h:63
ETL_CONSTEXPR14 void transform_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TUnaryFunction function)
Definition algorithm.h:2650
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
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:502
ibitset & set()
Set all bits.
Definition bitset_legacy.h:314
bitset< MaxN > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_legacy.h:1216
ibitset & reset()
Resets the bitset.
Definition bitset_legacy.h:543
bitset< MaxN > & operator&=(const bitset< MaxN > &other)
operator &=
Definition bitset_legacy.h:1391
bitset(const char16_t *text)
Construct from a string.
Definition bitset_legacy.h:1189
size_t find_first(bool state) const
Definition bitset_legacy.h:683
size_t find_next(bool state, size_t position) const
Definition bitset_legacy.h:694
ibitset & initialise(unsigned long long value)
Initialise from an unsigned long long.
Definition bitset_legacy.h:1011
ibitset & from_string(const char16_t *text)
Set from a u16 string.
Definition bitset_legacy.h:398
bool any() const
Are any of the bits set?
Definition bitset_legacy.h:657
~ibitset()
Destructor.
Definition bitset_legacy.h:1109
friend bool operator==(const bitset< MaxN > &lhs, const bitset< MaxN > &rhs)
operator ==
Definition bitset_legacy.h:1472
bitset< MaxN > & flip()
Flip all of the bits.
Definition bitset_legacy.h:1336
bit_reference get_bit_reference(size_t position)
Gets a reference to the specified bit.
Definition bitset_legacy.h:1054
ibitset & operator|=(const ibitset &other)
operator |=
Definition bitset_legacy.h:788
bitset(const bitset< MaxN > &other)
Copy constructor.
Definition bitset_legacy.h:1153
ibitset(size_t nbits_, size_t size_, element_type *pdata_)
Constructor.
Definition bitset_legacy.h:1062
bitset< MaxN > & set(const char32_t *text)
Set from a string.
Definition bitset_legacy.h:1255
bitset< MaxN > & set(const wchar_t *text)
Set from a string.
Definition bitset_legacy.h:1235
bitset(const char *text)
Construct from a string.
Definition bitset_legacy.h:1171
void swap(ibitset &other)
swap
Definition bitset_legacy.h:981
ibitset & operator=(const ibitset &other)
operator =
Definition bitset_legacy.h:968
bitset< MaxN > & reset()
Reset all of the bits.
Definition bitset_legacy.h:1318
bitset(const wchar_t *text)
Construct from a string.
Definition bitset_legacy.h:1180
ibitset & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:892
ibitset & operator^=(const ibitset &other)
operator ^=
Definition bitset_legacy.h:801
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:1307
bitset(unsigned long long value)
Construct from a value.
Definition bitset_legacy.h:1162
bitset< MaxN > & reset(size_t position)
Reset the bit at the position.
Definition bitset_legacy.h:1327
size_t count() const
Count the number of bits set.
Definition bitset_legacy.h:267
ibitset & from_string(const wchar_t *text)
Set from a wide string.
Definition bitset_legacy.h:381
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:1359
ibitset & set(const char32_t *text)
Set from a u32string.
Definition bitset_legacy.h:483
ibitset & from_string(const char32_t *text)
Set from a u32 string.
Definition bitset_legacy.h:415
ibitset & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_legacy.h:325
ibitset & flip()
Flip all of the bits.
Definition bitset_legacy.h:585
bitset(const char32_t *text)
Construct from a string.
Definition bitset_legacy.h:1198
ibitset & operator&=(const ibitset &other)
operator &=
Definition bitset_legacy.h:775
bitset< MaxN > & from_string(const wchar_t *text)
Set from a wide string.
Definition bitset_legacy.h:1275
bitset< MaxN > & operator<<=(size_t shift)
operator <<=
Definition bitset_legacy.h:1442
bitset< MaxN > operator<<(size_t shift) const
operator <<
Definition bitset_legacy.h:1430
unsigned long to_ulong() const
Put to a unsigned long.
Definition bitset_legacy.h:527
bool operator[](size_t position) const
Read [] operator.
Definition bitset_legacy.h:759
unsigned long long to_ullong() const
Put to a unsigned long long.
Definition bitset_legacy.h:535
bitset< MaxN > & operator|=(const bitset< MaxN > &other)
operator |=
Definition bitset_legacy.h:1400
void invert()
Invert.
Definition bitset_legacy.h:1041
bitset()
Default constructor.
Definition bitset_legacy.h:1144
bitset< MaxN > operator~() const
operator ~
Definition bitset_legacy.h:1418
bitset< MaxN > operator>>(size_t shift) const
operator >>
Definition bitset_legacy.h:1451
bitset< MaxN > & from_string(const char16_t *text)
Set from a u16 string.
Definition bitset_legacy.h:1285
ibitset & reset(size_t position)
Reset the bit at the position.
Definition bitset_legacy.h:553
bitset< MaxN > & set(const char *text)
Set from a string.
Definition bitset_legacy.h:1225
ibitset & from_string(const char *text)
Set from a string.
Definition bitset_legacy.h:364
bitset< MaxN > & operator=(const bitset< MaxN > &other)
operator =
Definition bitset_legacy.h:1378
ibitset & set(const char16_t *text)
Set from a u16string.
Definition bitset_legacy.h:466
ibitset & set(const wchar_t *text)
Set from a wstring.
Definition bitset_legacy.h:449
ibitset & operator<<=(size_t shift)
operator <<=
Definition bitset_legacy.h:814
bitset< MaxN > & operator^=(const bitset< MaxN > &other)
operator ^=
Definition bitset_legacy.h:1409
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:2363
bool none() const
Are none of the bits set?
Definition bitset_legacy.h:665
bitset< MaxN > & from_string(const char32_t *text)
Set from a u32 string.
Definition bitset_legacy.h:1295
bool test(size_t position) const
Definition bitset_legacy.h:283
size_t size() const
The number of bits in the bitset.
Definition bitset_legacy.h:259
bitset< MaxN > & set(const char16_t *text)
Set from a string.
Definition bitset_legacy.h:1245
ibitset & flip(size_t position)
Flip the bit at the position.
Definition bitset_legacy.h:600
bitset< MaxN > & flip(size_t position)
Flip the bit at the position.
Definition bitset_legacy.h:1345
ibitset & set(const char *text)
Set from a string.
Definition bitset_legacy.h:432
bitset< MaxN > & set()
Set all of the bits.
Definition bitset_legacy.h:1207
bitset< MaxN > & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:1463
static bool is_equal(const ibitset &lhs, const ibitset &rhs)
Compare bitsets.
Definition bitset_legacy.h:1075
bitset< MaxN > & from_string(const char *text)
Set from a string.
Definition bitset_legacy.h:1265
Bitset forward declaration.
Definition bitset_legacy.h:1130
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:516
is_integral
Definition type_traits_generator.h:996
make_unsigned
Definition type_traits_generator.h:1176
bitset_ext
Definition absolute.h:38
etl::byte operator|(etl::byte lhs, etl::byte rhs)
Or.
Definition byte.h:265
etl::byte operator&(etl::byte lhs, etl::byte rhs)
And.
Definition byte.h:273
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
ETL_CONSTEXPR14 size_t strlen(const T *t)
Alternative strlen for all character types.
Definition char_traits.h:285
etl::byte operator^(etl::byte lhs, etl::byte rhs)
Exclusive Or.
Definition byte.h:281
pair holds two objects of arbitrary type
Definition utility.h:164