Yate
Public Member Functions | List of all members
BitVector Class Reference

A slice vector holding bits. More...

#include <yatemath.h>

Inheritance diagram for BitVector:
SliceVector< Obj > MathVectorBase GenObject

Public Member Functions

 BitVector ()
 
 BitVector (const BitVector &other)
 
 BitVector (unsigned int len, unsigned int maxLen=0)
 
 BitVector (const BitVector &other, unsigned int offs, unsigned int len=0)
 
 BitVector (const char *str, unsigned int maxLen=0)
 
bool valid () const
 
bool get (FloatVector &dest) const
 
bool set (const FloatVector &input)
 
void xorMsb (uint32_t value, unsigned int offs=0, uint8_t len=32)
 
void xorMsb16 (uint16_t value, unsigned int offs=0, uint8_t len=16)
 
uint64_t pack (unsigned int offs=0, int len=-1) const
 
void unpack (uint64_t value, unsigned int offs=0, uint8_t len=64)
 
void unpackMsb (uint32_t value, unsigned int offs=0, uint8_t len=32)
 
void unpackMsb16 (uint16_t value, unsigned int offs=0, uint8_t len=16)
 
bool pack (ByteVector &dest) const
 
bool unpack (const ByteVector &src)
 
StringappendTo (String &buf, unsigned int offs=0, int len=-1) const
 
String toString (unsigned int offs, int len=-1) const
 
bool setSlice (const BitVector &other, unsigned int offs=0, unsigned int len=0)
 
BitVector head (unsigned int len) const
 
bool head (BitVector &dest, unsigned int len) const
 
BitVector tail (unsigned int len) const
 
bool tail (BitVector &dest, unsigned int len) const
 
BitVector slice (unsigned int offs, unsigned int len) const
 
bool slice (BitVector &dest, unsigned int offs, unsigned int len=0) const
 
- Public Member Functions inherited from SliceVector< Obj >
 SliceVector ()
 
 SliceVector (const SliceVector &other)
 
 SliceVector (unsigned int len, const Obj *buf=0, unsigned int maxLen=0)
 
 SliceVector (const SliceVector &v1, const SliceVector &v2)
 
 SliceVector (const SliceVector &v1, const SliceVector &v2, const SliceVector &v3)
 
 SliceVector (const SliceVector &other, unsigned int offs, unsigned int len=0)
 
virtual ~SliceVector ()
 
Obj * data (unsigned int offs, unsigned int len)
 
const Obj * data (unsigned int offs, unsigned int len) const
 
Obj * data (unsigned int offs=0)
 
const Obj * data (unsigned int offs=0) const
 
Obj * data (unsigned int offs, unsigned int len, Obj *&eod)
 
const Obj * data (unsigned int offs, unsigned int len, const Obj *&eod) const
 
unsigned int length () const
 
unsigned int maxLen () const
 
unsigned int size () const
 
unsigned int available (unsigned int offs, int len=-1) const
 
unsigned int availableClamp (unsigned int clamp, unsigned int offs=0, int len=-1) const
 
virtual unsigned int vectorSize () const
 
bool resize (unsigned int len)
 
void resizeMax ()
 
void steal (SliceVector &other)
 
void resetStorage (unsigned int len, unsigned int maxLen=0)
 
bool setSlice (const SliceVector &other, unsigned int offs=0, unsigned int len=0)
 
SliceVector head (unsigned int len) const
 
bool head (SliceVector &dest, unsigned int len) const
 
SliceVector tail (unsigned int len) const
 
bool tail (SliceVector &dest, unsigned int len) const
 
SliceVector slice (unsigned int offs, unsigned int len) const
 
bool slice (SliceVector &dest, unsigned int offs, unsigned int len=0) const
 
bool copy (const SliceVector &src, unsigned int len, unsigned int offs=0, unsigned int srcOffs=0)
 
void bzero (unsigned int offs, unsigned int len)
 
void bzero ()
 
void fill (const Obj &value)
 
void apply (void(*func)(Obj &))
 
Obj sum () const
 
Obj sumApply (Obj(*func)(const Obj &)) const
 
float sumApplyF (float(*func)(const Obj &)) const
 
bool sum (const SliceVector &other)
 
void sum (const Obj &value)
 
bool sub (const SliceVector &other)
 
void sub (const Obj &value)
 
bool mul (const SliceVector &other)
 
void mul (const Obj &value)
 
void mul (float value)
 
Obj & operator[] (unsigned int index)
 
const Obj & operator[] (unsigned int index) const
 
Obj & operator[] (signed int index)
 
const Obj & operator[] (signed int index) const
 
bool operator== (const SliceVector &other) const
 
bool operator!= (const SliceVector &other) const
 
SliceVectoroperator= (const SliceVector &other)
 
SliceVectoroperator+= (const SliceVector &other)
 
SliceVectoroperator+= (const Obj &value)
 
SliceVectoroperator-= (const SliceVector &other)
 
SliceVectoroperator-= (const Obj &value)
 
SliceVectoroperator*= (const SliceVector &other)
 
SliceVectoroperator*= (const Obj &value)
 
SliceVectoroperator*= (float value)
 
bool equals (const SliceVector &other) const
 
Stringdump (String &buf, String &(*func)(String &s, const Obj &o, const char *sep, const char *fmt), const char *sep=",", const char *fmt=0) const
 
Stringdump (String &buf, unsigned int lineLen, String &(*func)(String &s, const Obj &o, const char *sep, const char *fmt), unsigned int offset=0, const char *linePrefix=0, const char *suffix="\r\n", const char *sep=",", const char *fmt=0) const
 
Stringhexify (String &buf, char sep=0) const
 
StringdumpHex (String &buf, unsigned int lineLen, unsigned int offset=0, const char *linePrefix=0, const char *suffix="\r\n") const
 
int unHexify (const char *str, unsigned int len, int sep=255)
 
int unHexify (const String &str, int sep=255)
 
- Public Member Functions inherited from MathVectorBase
virtual ~MathVectorBase ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual bool alive () const
 
virtual void destruct ()
 
virtual const StringtoString () const
 
virtual const StringtraceId () const
 
virtual void * getObject (const String &name) const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Additional Inherited Members

- Static Public Member Functions inherited from SliceVector< Obj >
static unsigned int objSize ()
 
static unsigned int size (unsigned int len)
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 
- Protected Member Functions inherited from SliceVector< Obj >
Obj * end (Obj *start, unsigned int len)
 
const Obj * end (const Obj *start, unsigned int len) const
 
bool setData (Obj *data=0, unsigned int len=0, unsigned int maxLen=0)
 
bool initStorage (unsigned int len, const Obj *data=0, unsigned int maxLen=0)
 
bool initSlice (bool del, const SliceVector &other, unsigned int offs=0, unsigned int len=0)
 
- Protected Attributes inherited from SliceVector< Obj >
RefStoragem_storage
 
Obj * m_data
 
unsigned int m_length
 
unsigned int m_maxLen
 

Detailed Description

A slice vector holding bits.

This vector holds bit values using 1 byte. It implements methods operating on bits. NOTE: The array indexing operator allows setting invalid values (not 1 or 0). The pack/unpack methods are safe (they will handle non 0 values as bit 1). The comparison operators may fail for vectors containing values other than 0 or 1.

Constructor & Destructor Documentation

BitVector ( )
inline

Constructor

Referenced by BitVector::slice(), and BitVector::tail().

BitVector ( const BitVector other)
inline

Copy constructor. Builds a slice of another vector

Parameters
otherOriginal vector
BitVector ( unsigned int  len,
unsigned int  maxLen = 0 
)
inlineexplicit

Constructor. Build the vector storage

Parameters
lenLength of data
maxLenOptional vector maximum length (it will be adjusted to be at least len)
BitVector ( const BitVector other,
unsigned int  offs,
unsigned int  len = 0 
)
inlineexplicit

Constructor. Builds a slice of another vector

Parameters
otherOriginal vector
offsOffset in the original vector
lenThe number of elements (0 to use all available from offset)
BitVector ( const char *  str,
unsigned int  maxLen = 0 
)
explicit

Constructor. Build from string bits

Parameters
strString bits ('1' -> 1, else -> 0)
maxLenOptional vector maximum length

Member Function Documentation

String& appendTo ( String buf,
unsigned int  offs = 0,
int  len = -1 
) const

Append bits to string

Parameters
bufDestination string
offsOptional starting index
lenThe number of elements to be added (negative to add all)
Returns
Destination string address

Referenced by TelEngine::operator<<(), and BitVector::toString().

bool get ( FloatVector dest) const

Set float bit values from this vector (0 -> 0.0F, non 0 -> 1.0F). The destination vector will be resized to this vector's length

Parameters
destThe destination vector
Returns
True on success, false if destination resize failed
BitVector head ( unsigned int  len) const
inline

Retrieve vector head

Parameters
lenThe number of elements to retrieve
Returns
A vector containing the first elements of this vector

References BitVector::slice().

bool head ( BitVector dest,
unsigned int  len 
) const
inline

Retrieve vector head

Parameters
destDestination vector
lenThe number of elements to retrieve
Returns
True on success, false on failure (not enough data in our vector)

References BitVector::slice().

uint64_t pack ( unsigned int  offs = 0,
int  len = -1 
) const

Pack up to 64 bits, LSB-first (i.e. first bit goes to LSB in destination)

Parameters
offsThe start offset
lenThe number of elements to be packed (-1 to pack all available). No more than 64 bits will be packed
Returns
The packed 64-bit value
bool pack ( ByteVector dest) const

Pack bits into a ByteVector (LSB source to MSB in destination). MSB of first byte in destination will have the same value of the first bit in this vector. Remaining elements in destination are left untouched

Parameters
destDestination vector
Returns
True on success, false on failure (not enough space in destination vector)
bool set ( const FloatVector input)

Initializes this vector from float values (0.0F -> 0, non 0 -> 1). The vector will be resized to input length

Parameters
inputThe input vector
Returns
True on success, false if resize failed
bool setSlice ( const BitVector other,
unsigned int  offs = 0,
unsigned int  len = 0 
)
inline

Set a slice containing another vector

Parameters
otherOriginal vector
offsOffset in the original vector
lenThe number of elements (0 to use all available from offset)
Returns
True on success, false on failure
BitVector slice ( unsigned int  offs,
unsigned int  len 
) const
inline

Retrieve a vector slice

Parameters
offsOffset in our vector
lenThe number of elements to retrieve
Returns
A vector containing the requested slice (empty if offset/length are invalid)

References BitVector::BitVector().

Referenced by BitVector::head().

bool slice ( BitVector dest,
unsigned int  offs,
unsigned int  len = 0 
) const
inline

Set a slice of this vector to another one. The destination vector will be changed

Parameters
destDestination vector
offsOffset in our vector
lenThe number of elements (0 to use all available from offset)
Returns
True on success, false on failure (not enough data in our vector)
BitVector tail ( unsigned int  len) const
inline

Retrieve vector tail (last elements)

Parameters
lenThe number of elements to retrieve
Returns
A vector containing the last elements of this vector

References BitVector::BitVector(), and SliceVector< Obj >::length().

bool tail ( BitVector dest,
unsigned int  len 
) const
inline

Retrieve vector tail (last elements)

Parameters
lenThe number of elements to retrieve
destDestination vector
Returns
True on success, false on failure (not enough data in our vector)

References SliceVector< Obj >::length().

String toString ( unsigned int  offs,
int  len = -1 
) const
inline

Build a String from vector bits and return it

Parameters
offsOptional starting index
lenThe number of elements to be added (negative to add all)
Returns
A newly created String containing vector bits

References BitVector::appendTo().

void unpack ( uint64_t  value,
unsigned int  offs = 0,
uint8_t  len = 64 
)

Unpack up to 64 bits into this vector, LSB first

Parameters
valueValue to unpack
offsOptional start offset
lenThe number of bits to unpack
bool unpack ( const ByteVector src)

Unpack a ByteVector into this BitVector. MSB of the first element in source goes to first bit in this vector. Remaining bits are left untouched

Parameters
srcSource byte vector
Returns
True on success, false if there is not enough space to unpack
void unpackMsb ( uint32_t  value,
unsigned int  offs = 0,
uint8_t  len = 32 
)

Unpack up to 32 bits into this vector (MSB to LSB). MSB from value is the first unpacked bit

Parameters
valueThe value to be unpacked
offsOptional start offset
lenThe number of bits to unpack

Referenced by BitVector::unpackMsb16().

void unpackMsb16 ( uint16_t  value,
unsigned int  offs = 0,
uint8_t  len = 16 
)
inline

Unpack up to 16 bits into this vector (MSB to LSB). MSB from value is the first unpacked bit

Parameters
valueThe value to be unpacked
offsOptional start offset
lenThe number of bits to unpack

References BitVector::unpackMsb().

bool valid ( ) const

Check if this vector contains valid values (0 or 1)

Returns
True on success, false if the vector contains values other than 0 or 1
void xorMsb ( uint32_t  value,
unsigned int  offs = 0,
uint8_t  len = 32 
)

Apply XOR on vector elements using a given value's bits, MSB first. Given v31,v30,...,v0 the value's bits in MSB order the result will be data()[offs] ^= v31, data()[offs+1] ^= v30 ...

Parameters
valueValue to use
offsStart position in this BitVector
lenThe number of bits to use

Referenced by BitVector::xorMsb16().

void xorMsb16 ( uint16_t  value,
unsigned int  offs = 0,
uint8_t  len = 16 
)
inline

Apply XOR on vector elements using a given value's bits, MSB first. Given v15,v14,...,v0 the value's bits in MSB order the result will be data()[offs] ^= v15, data()[offs+1] ^= v14 ...

Parameters
valueValue to use
offsStart position in this BitVector
lenThe number of bits to use

References BitVector::xorMsb().


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