Embedded Template Library  1.0
bitset

Classes

class  etl::bitset_exception
 
class  etl::bitset_nullptr
 
class  etl::bitset_type_too_small
 
class  etl::ibitset
 
class  etl::bitset< MAXN >
 

Functions

template<const size_t MAXN>
bitset< MAXN > etl::operator& (const bitset< MAXN > &lhs, const bitset< MAXN > &rhs)
 
template<const size_t MAXN>
bitset< MAXN > etl::operator| (const bitset< MAXN > &lhs, const bitset< MAXN > &rhs)
 
template<const size_t MAXN>
bitset< MAXN > etl::operator^ (const bitset< MAXN > &lhs, const bitset< MAXN > &rhs)
 
template<const size_t MAXN>
bool etl::operator!= (const bitset< MAXN > &lhs, const bitset< MAXN > &rhs)
 

Detailed Description

Similar to std::bitset but without requiring std::string.


Class Documentation

◆ etl::bitset_exception

class etl::bitset_exception

Exception base for bitset

Public Member Functions

 bitset_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
 
- Public Member Functions inherited from etl::exception
 exception (string_type reason_, string_type file_, numeric_type line_)
 Constructor.
 
string_type what () const
 
string_type file_name () const
 
numeric_type line_number () const
 

Additional Inherited Members

- Public Types inherited from etl::exception
typedef const char * string_type
 
typedef int numeric_type
 

◆ etl::bitset_nullptr

class etl::bitset_nullptr

Bitset null pointer exception.

Public Member Functions

 bitset_nullptr (string_type file_name_, numeric_type line_number_)
 
- Public Member Functions inherited from etl::bitset_exception
 bitset_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
 
- Public Member Functions inherited from etl::exception
 exception (string_type reason_, string_type file_, numeric_type line_)
 Constructor.
 
string_type what () const
 
string_type file_name () const
 
numeric_type line_number () const
 

Additional Inherited Members

- Public Types inherited from etl::exception
typedef const char * string_type
 
typedef int numeric_type
 

◆ etl::bitset_type_too_small

class etl::bitset_type_too_small

Bitset type_too_small exception.

Public Member Functions

 bitset_type_too_small (string_type file_name_, numeric_type line_number_)
 
- Public Member Functions inherited from etl::bitset_exception
 bitset_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
 
- Public Member Functions inherited from etl::exception
 exception (string_type reason_, string_type file_, numeric_type line_)
 Constructor.
 
string_type what () const
 
string_type file_name () const
 
numeric_type line_number () const
 

Additional Inherited Members

- Public Types inherited from etl::exception
typedef const char * string_type
 
typedef int numeric_type
 

◆ etl::ibitset

class etl::ibitset

The base class for etl::bitset

Public Types

enum  { npos = etl::integral_limits<size_t>::max }
 
typedef etl::span< element_t > span_type
 
typedef etl::span< const element_t > const_span_type
 

Public Member Functions

size_t size () const
 The size of the bitset.
 
size_t count () const
 Count the number of bits set.
 
bool test (size_t position) const
 
ibitsetset ()
 Set the bit at the position.
 
ibitsetset (size_t position, bool value=true)
 Set the bit at the position.
 
ibitsetset (const char *text)
 Set from a string.
 
ibitsetfrom_string (const char *text)
 Set from a string.
 
ibitsetfrom_string (const wchar_t *text)
 Set from a wide string.
 
ibitsetfrom_string (const char16_t *text)
 Set from a u16 string.
 
ibitsetfrom_string (const char32_t *text)
 Set from a u32 string.
 
template<typename T >
etl::enable_if< etl::is_integral< T >::value, T >::type value () const
 Put to a value.
 
ibitsetreset ()
 Resets the bitset.
 
ibitsetreset (size_t position)
 Reset the bit at the position.
 
ibitsetflip ()
 Flip all of the bits.
 
ibitsetflip (size_t position)
 Flip the bit at the position.
 
bool all () const
 
bool any () const
 Are any of the bits set?
 
bool none () const
 Are none of the bits set?
 
size_t find_first (bool state) const
 
size_t find_next (bool state, size_t position) const
 
bool operator[] (size_t position) const
 Read [] operator.
 
bit_reference operator[] (size_t position)
 Write [] operator.
 
ibitsetoperator&= (const ibitset &other)
 operator &=
 
ibitsetoperator|= (const ibitset &other)
 operator |=
 
ibitsetoperator^= (const ibitset &other)
 operator ^=
 
ibitsetoperator<<= (size_t shift)
 operator <<=
 
ibitsetoperator>>= (size_t shift)
 operator >>=
 
ibitsetoperator= (const ibitset &other)
 operator =
 
void swap (ibitset &other)
 swap
 
span_type span ()
 
const_span_type span () const
 

Static Public Attributes

static const element_t ALL_SET = etl::integral_limits<element_t>::max
 
static const element_t ALL_CLEAR = 0
 
static const size_t BITS_PER_ELEMENT = etl::integral_limits<element_t>::bits
 

Protected Types

typedef uint_least8_t element_t
 

Protected Member Functions

ibitsetinitialise (unsigned long long value)
 Initialise from an unsigned long long.
 
void invert ()
 Invert.
 
bit_reference get_bit_reference (size_t position)
 Gets a reference to the specified bit.
 
 ibitset (size_t nbits_, size_t size_, element_t *pdata_)
 Constructor.
 
 ~ibitset ()
 Destructor.
 

Static Protected Member Functions

static bool is_equal (const ibitset &lhs, const ibitset &rhs)
 Compare bitsets.
 

Protected Attributes

element_t TOP_MASK
 

Member Function Documentation

◆ find_first()

size_t etl::ibitset::find_first ( bool  state) const
inline

Finds the first bit in the specified state.

Parameters
stateThe state to search for.
Returns
The position of the bit or SIZE if none were found.

◆ find_next()

size_t etl::ibitset::find_next ( bool  state,
size_t  position 
) const
inline

Finds the next bit in the specified state.

Parameters
stateThe state to search for.
positionThe position to start from.
Returns
The position of the bit or SIZE if none were found.

◆ span() [1/2]

span_type etl::ibitset::span ( )
inline

span Returns a span of the underlying data.

◆ span() [2/2]

const_span_type etl::ibitset::span ( ) const
inline

span Returns a const span of the underlying data.

◆ test()

bool etl::ibitset::test ( size_t  position) const
inline

Tests a bit at a position. Positions greater than the number of configured bits will return false.

◆ etl::bitset

class etl::bitset

template<const size_t MAXN>
class etl::bitset< MAXN >

The class emulates an array of bool elements, but optimized for space allocation. Will accommodate any number of bits. Does not use std::string.

Template Parameters
MAXNThe number of bits.

Public Member Functions

 bitset ()
 Default constructor.
 
 bitset (const bitset< MAXN > &other)
 Copy constructor.
 
 bitset (unsigned long long value)
 Construct from a value.
 
 bitset (const char *text)
 Construct from a string.
 
bitset< MAXN > & set ()
 Set all of the bits.
 
bitset< MAXN > & set (size_t position, bool value=true)
 Set the bit at the position.
 
bitset< MAXN > & set (const char *text)
 Set from a string.
 
bitset< MAXN > & from_string (const char *text)
 Set from a string.
 
bitset< MAXN > & from_string (const wchar_t *text)
 Set from a wide string.
 
bitset< MAXN > & from_string (const char16_t *text)
 Set from a u16 string.
 
bitset< MAXN > & from_string (const char32_t *text)
 Set from a u32 string.
 
template<typename T >
etl::enable_if< etl::is_integral< T >::value, T >::type value () const
 Put to a value.
 
bitset< MAXN > & reset ()
 Reset all of the bits.
 
bitset< MAXN > & reset (size_t position)
 Reset the bit at the position.
 
bitset< MAXN > & flip ()
 Flip all of the bits.
 
bitset< MAXN > & flip (size_t position)
 Flip the bit at the position.
 
bitset< MAXN > & operator= (const bitset< MAXN > &other)
 operator =
 
bitset< MAXN > & operator&= (const bitset< MAXN > &other)
 operator &=
 
bitset< MAXN > & operator|= (const bitset< MAXN > &other)
 operator |=
 
bitset< MAXN > & operator^= (const bitset< MAXN > &other)
 operator ^=
 
bitset< MAXN > operator~ () const
 operator ~
 
bitset< MAXN > operator<< (size_t shift) const
 operator <<
 
bitset< MAXN > & operator<<= (size_t shift)
 operator <<=
 
bitset< MAXN > operator>> (size_t shift) const
 operator >>
 
bitset< MAXN > & operator>>= (size_t shift)
 operator >>=
 
- Public Member Functions inherited from etl::ibitset
size_t size () const
 The size of the bitset.
 
size_t count () const
 Count the number of bits set.
 
bool test (size_t position) const
 
ibitsetset ()
 Set the bit at the position.
 
ibitsetset (size_t position, bool value=true)
 Set the bit at the position.
 
ibitsetset (const char *text)
 Set from a string.
 
ibitsetfrom_string (const char *text)
 Set from a string.
 
ibitsetfrom_string (const wchar_t *text)
 Set from a wide string.
 
ibitsetfrom_string (const char16_t *text)
 Set from a u16 string.
 
ibitsetfrom_string (const char32_t *text)
 Set from a u32 string.
 
template<typename T >
etl::enable_if< etl::is_integral< T >::value, T >::type value () const
 Put to a value.
 
ibitsetreset ()
 Resets the bitset.
 
ibitsetreset (size_t position)
 Reset the bit at the position.
 
ibitsetflip ()
 Flip all of the bits.
 
ibitsetflip (size_t position)
 Flip the bit at the position.
 
bool all () const
 
bool any () const
 Are any of the bits set?
 
bool none () const
 Are none of the bits set?
 
size_t find_first (bool state) const
 
size_t find_next (bool state, size_t position) const
 
bool operator[] (size_t position) const
 Read [] operator.
 
bit_reference operator[] (size_t position)
 Write [] operator.
 
ibitsetoperator&= (const ibitset &other)
 operator &=
 
ibitsetoperator|= (const ibitset &other)
 operator |=
 
ibitsetoperator^= (const ibitset &other)
 operator ^=
 
ibitsetoperator<<= (size_t shift)
 operator <<=
 
ibitsetoperator>>= (size_t shift)
 operator >>=
 
ibitsetoperator= (const ibitset &other)
 operator =
 
void swap (ibitset &other)
 swap
 
span_type span ()
 
const_span_type span () const
 

Static Public Attributes

static const size_t ALLOCATED_BITS = ARRAY_SIZE * BITS_PER_ELEMENT
 
- Static Public Attributes inherited from etl::ibitset
static const element_t ALL_SET = etl::integral_limits<element_t>::max
 
static const element_t ALL_CLEAR = 0
 
static const size_t BITS_PER_ELEMENT = etl::integral_limits<element_t>::bits
 

Friends

bool operator== (const bitset< MAXN > &lhs, const bitset< MAXN > &rhs)
 operator ==
 

Additional Inherited Members

- Public Types inherited from etl::ibitset
enum  { npos = etl::integral_limits<size_t>::max }
 
typedef etl::span< element_t > span_type
 
typedef etl::span< const element_t > const_span_type
 
- Protected Types inherited from etl::ibitset
typedef uint_least8_t element_t
 
- Protected Member Functions inherited from etl::ibitset
ibitsetinitialise (unsigned long long value)
 Initialise from an unsigned long long.
 
void invert ()
 Invert.
 
bit_reference get_bit_reference (size_t position)
 Gets a reference to the specified bit.
 
 ibitset (size_t nbits_, size_t size_, element_t *pdata_)
 Constructor.
 
 ~ibitset ()
 Destructor.
 
- Static Protected Member Functions inherited from etl::ibitset
static bool is_equal (const ibitset &lhs, const ibitset &rhs)
 Compare bitsets.
 
- Protected Attributes inherited from etl::ibitset
element_t TOP_MASK
 

Function Documentation

◆ operator!=()

template<const size_t MAXN>
bool etl::operator!= ( const bitset< MAXN > &  lhs,
const bitset< MAXN > &  rhs 
)

operator !=

◆ operator&()

template<const size_t MAXN>
bitset<MAXN> etl::operator& ( const bitset< MAXN > &  lhs,
const bitset< MAXN > &  rhs 
)

operator &

◆ operator^()

template<const size_t MAXN>
bitset<MAXN> etl::operator^ ( const bitset< MAXN > &  lhs,
const bitset< MAXN > &  rhs 
)

operator ^

◆ operator|()

template<const size_t MAXN>
bitset<MAXN> etl::operator| ( const bitset< MAXN > &  lhs,
const bitset< MAXN > &  rhs 
)

operator |