cds  2.3.2
cds::algo::split_bitstring< BitString, BitStringSize, UInt > Class Template Reference

Cuts a bit sequence from fixed-size bit-string. More...

#include <cds/algo/split_bitstring.h>

Public Types

typedef BitString bitstring
 Bit-string type.
 
typedef UInt uint_type
 Result type of cut() function.
 

Public Member Functions

 split_bitstring (bitstring const &h)
 Initializises the splitter with reference to h and zero start bit offset.
 
 split_bitstring (bitstring const &h, size_t nBitOffset)
 Initializises the splitter with reference to h and start bit offset nBitOffset.
 
 operator bool () const
 Returns true if end-of-string is not reached yet.
 
bool eos () const
 Returns true if end-of-stream encountered.
 
uint_type cut (unsigned count)
 Cuts next count bits from bit-string. More...
 
uint_type safe_cut (unsigned count)
 Cuts up to count from the bit-string. More...
 
void reset () noexcept
 Resets the splitter.
 
bitstring const * source () const
 Returns pointer to source bitstring.
 
size_t bit_offset () const
 Returns current bit offset from beginning of bit-string.
 
size_t rest_count () const
 Returns how many bits remain.
 

Static Public Member Functions

static constexpr bool is_correct (unsigned)
 Returns true for any argument.
 

Static Public Attributes

static constexpr size_t const c_bitstring_size = BitStringSize ? BitStringSize : sizeof( BitString )
 size of BitString in bytes
 

Detailed Description

template<typename BitString, size_t BitStringSize = sizeof( BitString ), typename UInt = unsigned>
class cds::algo::split_bitstring< BitString, BitStringSize, UInt >

Cuts a bit sequence from fixed-size bit-string.

The splitter can be used as an iterator over bit-string. Each call of cut() or safe_cut() cuts the bit count specified and keeps the position inside bit-string for the next call.

The splitter stores a const reference to bit-string, not a copy. The maximum count of bits that can be cut in a single call is sizeof(UInt) * 8

The splitter keeps byte order.

Template parameters:

  • BitString - a fixed-sized type that interprets as bit string
  • BitStringSize - the size of BitString in bytes, default is sizeof( BitString ). You can specify 0 for default.
  • UInt - an unsigned integer, return type for cut(), default is unsigned

There are specialized splitters:

Member Function Documentation

◆ cut()

template<typename BitString , size_t BitStringSize = sizeof( BitString ), typename UInt = unsigned>
uint_type cds::algo::split_bitstring< BitString, BitStringSize, UInt >::cut ( unsigned  count)
inline

Cuts next count bits from bit-string.

For performance reason, the function does not manage out-of-bound condition. To control that use safe_cut().

◆ safe_cut()

template<typename BitString , size_t BitStringSize = sizeof( BitString ), typename UInt = unsigned>
uint_type cds::algo::split_bitstring< BitString, BitStringSize, UInt >::safe_cut ( unsigned  count)
inline

Cuts up to count from the bit-string.

Safe analog of cut() but if count is more than the rest of bit-string, only the rest is returned. When eos() condition is met the function returns 0.


The documentation for this class was generated from the following file:

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:13 by Doxygen 1.8.13