bit::Buffer Class Reference

Buffer storing and retrieving variable-width values (0-32 bits) in arbitrary bit positions. More...

#include <Buffer.hh>

List of all members.

Public Types

typedef std::vector< unsigned
char > 
DataVector
 The data vector used for internal buffer representation.

Public Member Functions

 Buffer (u64 size=0)
 Default constructor.
void swap (Buffer &buffer)
 Swap the contents of two buffers efficiently.
u64 size () const
 Return the size of the buffer in bytes.
void resize (u64 size)
 Resize the buffer.
u32 read_pos (u64 byte_pos, unsigned int bit_offset, unsigned int bits) const
 Read value from the buffer.
u32 read_elem (u64 elem, unsigned int bits_per_elem) const
 Read element at a given fixed-width element.
void write_pos (u64 byte_pos, unsigned int bit_offset, u32 value, unsigned int bits)
 Write value in the buffer.
void write_elem (u64 elem, unsigned int bits_per_elem, u32 value)
 Write value in the buffer in the place of given fixed-width element.
const unsigned char * data () const
 Const access the internal data buffer.
unsigned char * data ()
 Access the internal data buffer.

Private Attributes

DataVector m_data
 Buffer containing the actual bit data.


Detailed Description

Buffer storing and retrieving variable-width values (0-32 bits) in arbitrary bit positions.

The size of the buffer must be less than 2^64 bits.


Member Typedef Documentation

typedef std::vector<unsigned char> bit::Buffer::DataVector
 

The data vector used for internal buffer representation.


Constructor & Destructor Documentation

bit::Buffer::Buffer u64  size = 0  )  [inline]
 

Default constructor.

Parameters:
size = initial size of the buffer in bytes


Member Function Documentation

unsigned char* bit::Buffer::data  )  [inline]
 

Access the internal data buffer.

It is safe to write and read the first size() bytes of the pointer. Note, that resize() and swap may invalidate the pointer.

const unsigned char* bit::Buffer::data  )  const [inline]
 

Const access the internal data buffer.

It is safe to write and read the first size() bytes of the pointer. Note, that resize() and swap may invalidate the pointer.

u32 bit::Buffer::read_elem u64  elem,
unsigned int  bits_per_elem
const [inline]
 

Read element at a given fixed-width element.

Parameters:
elem = the index of the element to write
bits_per_elem = the number of bits per element (0-32 bits)
Exceptions:
bit::invalid_argument the bit argument is invalid
bit::out_of_range accessing outside the buffer

u32 bit::Buffer::read_pos u64  byte_pos,
unsigned int  bit_offset,
unsigned int  bits
const [inline]
 

Read value from the buffer.

Parameters:
byte_pos = byte position in the buffer for the read
bit_offset = bit offset for the read (0-31 bits)
bits = number of bits to read (0-32 bits)
Returns:
the value read from the buffer
Exceptions:
bit::invalid_argument on of the bit arguments are invalid
bit::out_of_range accessing outside the buffer

void bit::Buffer::resize u64  size  )  [inline]
 

Resize the buffer.

Growing the buffer does not invalidate buffer contents. If the buffer is grown, the new values are initialized to zero.

Parameters:
size = the new size of the buffer in bytes

u64 bit::Buffer::size  )  const [inline]
 

Return the size of the buffer in bytes.

void bit::Buffer::swap Buffer buffer  )  [inline]
 

Swap the contents of two buffers efficiently.

Invalidates pointers returned earlier by the data() method.

void bit::Buffer::write_elem u64  elem,
unsigned int  bits_per_elem,
u32  value
[inline]
 

Write value in the buffer in the place of given fixed-width element.

Parameters:
elem = the index of the element to write
bits_per_elem = the number of bits per element (0-32 bits)
value = the value to write
Exceptions:
bit::invalid_argument the bit argument is invalid
bit::out_of_range accessing outside the buffer

void bit::Buffer::write_pos u64  byte_pos,
unsigned int  bit_offset,
u32  value,
unsigned int  bits
[inline]
 

Write value in the buffer.

Parameters:
byte_pos = byte position in the buffer for the write
bit_offset = bit offset for the write (0-31 bits)
value = value to write (0-32 bits)
bits = number of bits to write (0-32 bits)
Exceptions:
bit::invalid_argument on of the bit arguments are invalid
bit::out_of_range accessing outside the buffer


Member Data Documentation

DataVector bit::Buffer::m_data [private]
 

Buffer containing the actual bit data.


The documentation for this class was generated from the following file:
Generated on Mon Jan 8 15:51:04 2007 for bit by  doxygen 1.4.6