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
152 typedef element_type element_t;
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 etl::fill_n(pdata, Number_Of_Elements - 1U, ALL_SET);
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'));
432 if (text == ETL_NULLPTR)
449 if (text == ETL_NULLPTR)
466 if (text == ETL_NULLPTR)
483 if (text == ETL_NULLPTR)
498 template <
typename T>
504 const bool OK = (
sizeof(
T) *
CHAR_BIT) >= (Number_Of_Elements * Bits_Per_Element);
512 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
543 etl::fill_n(pdata, Number_Of_Elements, ALL_CLEAR);
553 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
557 if (position < Active_Bits)
559 if (Number_Of_Elements == 0)
563 else if (Number_Of_Elements == 1)
566 bit = element_type(1) << position;
571 bit = element_type(1) << (position & (Bits_Per_Element - 1));
574 pdata[index] &=
~bit;
590 clear_unused_bits_in_msb();
600 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(
bitset_overflow), *
this);
604 if (Number_Of_Elements == 0)
608 else if (Number_Of_Elements == 1)
611 bit = element_type(1) << position;
616 bit = element_type(1) << (position & (Bits_Per_Element - 1));
629 if (Number_Of_Elements == 0
UL)
635 for (
size_t i = 0UL; i < (Number_Of_Elements - 1U); ++i)
637 if (pdata[i] != ALL_SET)
644 if (pdata[Number_Of_Elements - 1U] != (ALL_SET & Top_Mask))
665 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
698 if (Number_Of_Elements == 0)
700 return ibitset::npos;
702 else if (Number_Of_Elements == 1)
710 bit = position & (Bits_Per_Element - 1);
716 while (index < Number_Of_Elements)
718 element_type
value = pdata[index];
721 if ((state && (
value != ALL_CLEAR)) ||
722 (!state && (
value != ALL_SET)))
725 while ((
bit < Bits_Per_Element) && (position < Active_Bits))
741 position += (Bits_Per_Element -
bit);
751 return ibitset::npos;
759 return test(position);
775 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
788 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
801 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
814 if (
shift >= Active_Bits)
818 else if (Number_Of_Elements != 0
UL)
821 if (Number_Of_Elements == 1UL)
825 else if (
shift == Bits_Per_Element)
827 etl::copy_backward(pdata, pdata + Number_Of_Elements - 1U, pdata + Number_Of_Elements);
881 clear_unused_bits_in_msb();
892 if (
shift >= Active_Bits)
896 else if (Number_Of_Elements != 0
UL)
899 if (Number_Of_Elements == 1UL)
904 else if (
shift == Bits_Per_Element)
906 etl::copy(pdata + 1, pdata + Number_Of_Elements, pdata);
907 pdata[Number_Of_Elements - 1U] = 0;
929 while (
src_index <
int(Number_Of_Elements - 1))
970 etl::copy_n(
other.pdata, Number_Of_Elements, pdata);
981 etl::swap_ranges(pdata, pdata + Number_Of_Elements,
other.pdata);
991 return span_type(pdata, pdata + Number_Of_Elements);
998 const_span_type span()
const
1000 return const_span_type(pdata, pdata + Number_Of_Elements);
1018 pdata[0] = element_type(
value);
1024 while ((
value != 0) && (
i < Number_Of_Elements))
1026 pdata[
i++] =
value & ALL_SET;
1031 clear_unused_bits_in_msb();
1041 for (
size_t i = 0
UL;
i < Number_Of_Elements; ++
i)
1043 pdata[
i] = ~pdata[
i];
1046 clear_unused_bits_in_msb();
1062 , Number_Of_Elements(
size_)
1065 const size_t allocated_bits = Number_Of_Elements * Bits_Per_Element;
1066 const size_t top_mask_shift = ((Bits_Per_Element - (allocated_bits - Active_Bits)) % Bits_Per_Element);
1075 return etl::equal(
lhs.pdata,
lhs.pdata +
lhs.Number_Of_Elements,
rhs.pdata);
1078 element_type Top_Mask;
1085 void clear_unused_bits_in_msb()
1087 pdata[Number_Of_Elements - 1U] &= Top_Mask;
1091 ibitset(
const ibitset&);
1093 const size_t Active_Bits;
1094 const size_t Number_Of_Elements;
1095 element_type* pdata;
1100#if defined(ETL_POLYMORPHIC_BITSET) || defined(ETL_POLYMORPHIC_CONTAINERS)
1113 ETL_CONSTANT ibitset::element_type ibitset::ALL_SET;
1115 ETL_CONSTANT ibitset::element_type ibitset::ALL_CLEAR;
1117 ETL_CONSTANT
size_t ibitset::Bits_Per_Element;
1126 template <
size_t MaxN>
1130 static ETL_CONSTANT
size_t Array_Size = (
MaxN % Bits_Per_Element == 0) ?
MaxN / Bits_Per_Element :
MaxN / Bits_Per_Element + 1;
1134 static ETL_CONSTANT
size_t ALLOCATED_BITS = Array_Size * Bits_Per_Element;
1135 static ETL_CONSTANT
size_t Allocated_Bits = ALLOCATED_BITS;
1154 etl::copy_n(
other.data, Array_Size, data);
1303 template <
typename T>
1308 ETL_STATIC_ASSERT((
sizeof(
T) *
CHAR_BIT) >= (Array_Size * Bits_Per_Element),
"Type too small");
1310 return ibitset::value<T>();
1353 template <
typename TString = etl::
string<MaxN>>
1355 template <
typename TString>
1357 TString to_string(
typename TString::value_type
zero =
typename TString::value_type(
'0'),
typename TString::value_type
one =
typename TString::value_type(
'1'))
const
1361 result.resize(
MaxN,
'\0');
1365 for (
size_t i =
MaxN;
i > 0; --
i)
1380 etl::copy_n(
other.data, Array_Size, data);
1477 element_type data[Array_Size > 0
U ? Array_Size : 1U];
1480 template <
size_t MaxN>
1481 ETL_CONSTANT
size_t bitset<MaxN>::ALLOCATED_BITS;
1483 template <
size_t MaxN>
1484 ETL_CONSTANT
size_t bitset<MaxN>::Allocated_Bits;
1490 template <
size_t MaxN>
1502 template<
size_t MaxN>
1514 template<
size_t MaxN>
1526 template<
size_t MaxN>
1536template <
size_t MaxN>
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:63
ETL_CONSTEXPR14 void transform_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TUnaryFunction function)
Definition algorithm.h:2638
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:500
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:1214
ibitset & reset()
Resets the bitset.
Definition bitset_legacy.h:541
bitset< MaxN > & operator&=(const bitset< MaxN > &other)
operator &=
Definition bitset_legacy.h:1389
bitset(const char16_t *text)
Construct from a string.
Definition bitset_legacy.h:1187
size_t find_first(bool state) const
Definition bitset_legacy.h:681
size_t find_next(bool state, size_t position) const
Definition bitset_legacy.h:692
ibitset & initialise(unsigned long long value)
Initialise from an unsigned long long.
Definition bitset_legacy.h:1009
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:655
~ibitset()
Destructor.
Definition bitset_legacy.h:1107
friend bool operator==(const bitset< MaxN > &lhs, const bitset< MaxN > &rhs)
operator ==
Definition bitset_legacy.h:1470
bitset< MaxN > & flip()
Flip all of the bits.
Definition bitset_legacy.h:1334
bit_reference get_bit_reference(size_t position)
Gets a reference to the specified bit.
Definition bitset_legacy.h:1052
ibitset & operator|=(const ibitset &other)
operator |=
Definition bitset_legacy.h:786
bitset(const bitset< MaxN > &other)
Copy constructor.
Definition bitset_legacy.h:1151
ibitset(size_t nbits_, size_t size_, element_type *pdata_)
Constructor.
Definition bitset_legacy.h:1060
bitset< MaxN > & set(const char32_t *text)
Set from a string.
Definition bitset_legacy.h:1253
bitset< MaxN > & set(const wchar_t *text)
Set from a string.
Definition bitset_legacy.h:1233
bitset(const char *text)
Construct from a string.
Definition bitset_legacy.h:1169
void swap(ibitset &other)
swap
Definition bitset_legacy.h:979
ibitset & operator=(const ibitset &other)
operator =
Definition bitset_legacy.h:966
bitset< MaxN > & reset()
Reset all of the bits.
Definition bitset_legacy.h:1316
bitset(const wchar_t *text)
Construct from a string.
Definition bitset_legacy.h:1178
ibitset & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:890
ibitset & operator^=(const ibitset &other)
operator ^=
Definition bitset_legacy.h:799
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:1305
bitset(unsigned long long value)
Construct from a value.
Definition bitset_legacy.h:1160
bitset< MaxN > & reset(size_t position)
Reset the bit at the position.
Definition bitset_legacy.h:1325
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:1357
ibitset & set(const char32_t *text)
Set from a u32string.
Definition bitset_legacy.h:481
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:583
bitset(const char32_t *text)
Construct from a string.
Definition bitset_legacy.h:1196
ibitset & operator&=(const ibitset &other)
operator &=
Definition bitset_legacy.h:773
bitset< MaxN > & from_string(const wchar_t *text)
Set from a wide string.
Definition bitset_legacy.h:1273
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
unsigned long to_ulong() const
Put to a unsigned long.
Definition bitset_legacy.h:525
bool operator[](size_t position) const
Read [] operator.
Definition bitset_legacy.h:757
unsigned long long to_ullong() const
Put to a unsigned long long.
Definition bitset_legacy.h:533
bitset< MaxN > & operator|=(const bitset< MaxN > &other)
operator |=
Definition bitset_legacy.h:1398
void invert()
Invert.
Definition bitset_legacy.h:1039
bitset()
Default constructor.
Definition bitset_legacy.h:1142
bitset< MaxN > operator~() const
operator ~
Definition bitset_legacy.h:1416
bitset< MaxN > operator>>(size_t shift) const
operator >>
Definition bitset_legacy.h:1449
bitset< MaxN > & from_string(const char16_t *text)
Set from a u16 string.
Definition bitset_legacy.h:1283
ibitset & reset(size_t position)
Reset the bit at the position.
Definition bitset_legacy.h:551
bitset< MaxN > & set(const char *text)
Set from a string.
Definition bitset_legacy.h:1223
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:1376
ibitset & set(const char16_t *text)
Set from a u16string.
Definition bitset_legacy.h:464
ibitset & set(const wchar_t *text)
Set from a wstring.
Definition bitset_legacy.h:447
ibitset & operator<<=(size_t shift)
operator <<=
Definition bitset_legacy.h:812
bitset< MaxN > & operator^=(const bitset< MaxN > &other)
operator ^=
Definition bitset_legacy.h:1407
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:2360
bool none() const
Are none of the bits set?
Definition bitset_legacy.h:663
bitset< MaxN > & from_string(const char32_t *text)
Set from a u32 string.
Definition bitset_legacy.h:1293
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:1243
ibitset & flip(size_t position)
Flip the bit at the position.
Definition bitset_legacy.h:598
bitset< MaxN > & flip(size_t position)
Flip the bit at the position.
Definition bitset_legacy.h:1343
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:1205
bitset< MaxN > & operator>>=(size_t shift)
operator >>=
Definition bitset_legacy.h:1461
static bool is_equal(const ibitset &lhs, const ibitset &rhs)
Compare bitsets.
Definition bitset_legacy.h:1073
bitset< MaxN > & from_string(const char *text)
Set from a string.
Definition bitset_legacy.h:1263
Bitset forward declaration.
Definition bitset_legacy.h:1128
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:1001
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
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