seven bits

bit::Buffer Class Reference
["Data Buffers"]

#include <bit/buffer.h>

Inheritance diagram for bit::Buffer:

bit::Data bit::RecordBuffer

List of all members.


Detailed Description

This class adds an interface for managing a packed bit (or octet) buffer.

to the base Data class which is octet oriented. Although this class manages bit oriented buffers, it attempts to optimize for octet (byte) based buffers.

The methods pack(), unpack() and clear() provide a means of extracting and setting bit segments in the underlying buffer.

Author:
Rick L. Vinyard, Jr.

Public Member Functions

 Buffer (size_t initial_size=0, size_t sizemax=0) throw (std::bad_alloc)
 Construct a buffer of a given size that is allowed to dynamically grown as pack/unpack requests are made.
 Buffer (void *data, size_t size, size_t sizemax=0, DataMode mode=COPY) throw (std::bad_alloc)
 Constructor initializes buffer with a copy of specific data.
 Buffer (const Data &other)
 Constructor initializes buffer to use the specified underlying data chunk.
 Buffer (const Buffer &other)
 Copy constructor.
 ~Buffer ()
bool unpack (void *mem, size_t mem_octets, Location mem_loc, size_t buf_offset_bits, size_t extract_bits)
 Transfer data from the buffer area into the low order bits of a memory location.
Data unpack (size_t buf_offset_bits, size_t extract_bits, Location mem_loc=END)
template<typename T>
bool unpack (T &val, Location mem_loc, size_t buf_offset_bits, size_t extract_bits)
bool pack (const void *mem, size_t mem_octets, Location mem_loc, size_t buf_offset, size_t buf_tgtsize, size_t n)
 Transfer data from the low order bits of a memory location into the low order bits of a segment of the buffer area.
bool pack (Data d, size_t buf_offset, size_t buf_tgtsize, size_t n, Location mem_loc=END)
template<typename T>
bool pack (const T &val, Location mem_loc, size_t offset, size_t destsize, size_t n)
bool clear_bits (size_t offset, size_t bits)

Constructor & Destructor Documentation

bit::Buffer::Buffer ( size_t  initial_size = 0,
size_t  sizemax = 0 
) throw (std::bad_alloc)

Construct a buffer of a given size that is allowed to dynamically grown as pack/unpack requests are made.

bit::Buffer::Buffer ( void *  data,
size_t  size,
size_t  sizemax = 0,
DataMode  mode = COPY 
) throw (std::bad_alloc)

Constructor initializes buffer with a copy of specific data.

bit::Buffer::Buffer ( const Data other  ) 

Constructor initializes buffer to use the specified underlying data chunk.

bit::Buffer::Buffer ( const Buffer other  ) 

Copy constructor.

bit::Buffer::~Buffer (  ) 


Member Function Documentation

bool bit::Buffer::unpack ( void *  mem,
size_t  mem_octets,
Location  mem_loc,
size_t  buf_offset_bits,
size_t  extract_bits 
)

Transfer data from the buffer area into the low order bits of a memory location.

Parameters:
mem The memory location to transfer buffer data into
mem_octets The size of the memory location in octets
mem_loc The memory location relative position (END or START)
buf_offset_bits The offset from the beginning of the buffer in bits to begin extraction from
extract_bits The size of the data to extract in bits
Returns:
true if transfer accomplished, false otherwise
Bit Buffer ================================================== |000000000011111111112222222222333333333344444444| |012345678901234567890123456789012345678901234567| ================================================== ^ buf_offset_bits = 14 ^ extract_bits = 20 ^

Memory Buffer ================================================== |000000000011111111112222222222333333333344444444| |012345678901234567890123456789012345678901234567| ================================================== ^ mem = start of memory address ^ mem_octets = 6 ^ ^ Resulting data ^ when mem_loc = END ^ Resulting data ^ when mem_loc = START

References bit::Data::data(), bit::last_octet_lower_bits(), bit::left_shift(), bit::masks, bit::octet_ceiling(), bit::Data::resize(), bit::Data::size(), and bit::START.

Referenced by bit::FieldBuffer::unpack(), unpack(), and bit::FieldBuffer::unpack_uint64().

Data bit::Buffer::unpack ( size_t  buf_offset_bits,
size_t  extract_bits,
Location  mem_loc = END 
)

template<typename T>
bool bit::Buffer::unpack ( T &  val,
Location  mem_loc,
size_t  buf_offset_bits,
size_t  extract_bits 
) [inline]

References unpack().

bool bit::Buffer::pack ( const void *  mem,
size_t  mem_octets,
Location  mem_loc,
size_t  buf_offset,
size_t  buf_tgtsize,
size_t  n 
)

Transfer data from the low order bits of a memory location into the low order bits of a segment of the buffer area.

Parameters:
mem The memory location to transfer from
mem_octets The size of the memory location in octets
buf_offset The offset from the start of the data buffer in bits
buf_tgtsize The size of the target area in the buffer in bits
n The size of the data to extract in bits
Returns:
true if transfer accomplished, false otherwise. If
Parameters:
offset +
destsize are greater than the size of the buffer and the buffer cannot be expanded to accommodate the request zero is returned.
Memory Buffer ================================================== |000000000011111111112222222222333333333344444444| |012345678901234567890123456789012345678901234567| ================================================== ^ mem = start of memory address ^ mem_octets = 6 ^ ^ n = 10 ^ when mem_loc = END ^ cpy out^ when mem_loc = END ^ n = 10 ^ when mem_loc = START ^ cpy out^ when mem_loc = START

Bit Buffer ================================================== |000000000011111111112222222222333333333344444444| |012345678901234567890123456789012345678901234567| ================================================== ^ buf_offset_bits = 14 ^ buf_tgtsize = 20 ^ ^ n = 10 ^ ^ cpy in ^

References clear_bits(), bit::Data::data(), bit::last_octet_lower_bits(), bit::last_octet_upper_bits(), bit::masks, bit::octet_ceiling(), bit::Data::resize(), bit::right_shift(), bit::Data::size(), and bit::START.

Referenced by bit::FieldBuffer::pack(), pack(), and bit::FieldBuffer::pack_uint64().

bool bit::Buffer::pack ( Data  d,
size_t  buf_offset,
size_t  buf_tgtsize,
size_t  n,
Location  mem_loc = END 
)

template<typename T>
bool bit::Buffer::pack ( const T &  val,
Location  mem_loc,
size_t  offset,
size_t  destsize,
size_t  n 
) [inline]

References pack().

bool bit::Buffer::clear_bits ( size_t  offset,
size_t  bits 
)


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

Generated on Mon Nov 3 10:50:01 2008 for bit by doxygen 1.5.6