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

#include <bit/buffer.h>

Inheritance diagram for bit::Buffer:

Inheritance graph
[legend]
List of all members.

Detailed Description

This class manages a packed bit (or octet) buffer.

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 bit segments from the buffer.

Todo:
create an overloaded = operator that copies memory if the buffer is the owner
Author:
Rick L. Vinyard, Jr.


Public Types

typedef BitPointer< Bufferpointer
typedef BitPointer< Bufferpointer
typedef BitPointer< Bufferpointer

Public Member Functions

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)
size_t size_max ()
 Gets the maximum size this buffer is allowed to grow.
void set_size_max (size_t sizemax)
 Sets the maximum size that this buffer is allowed to grow.
virtual void set_data (const void *newdata, size_t newsize, DataMode mode=COPY) throw (std::bad_alloc)
virtual bool resize (size_t s) throw (std::bad_alloc)
sigc::signal< void > signal_changed ()
 Signals a change to the data within the 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::pointer 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::pointer 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)
size_t size_max ()
 Gets the maximum size this buffer is allowed to grow.
void set_size_max (size_t sizemax)
 Sets the maximum size that this buffer is allowed to grow.
virtual void set_data (const void *newdata, size_t newsize, DataMode mode=COPY) throw (std::bad_alloc)
virtual bool resize (size_t s) throw (std::bad_alloc)
sigc::signal< void > signal_changed ()
 Signals a change to the data within the 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::pointer 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::pointer 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)
size_t size_max ()
 Gets the maximum size this buffer is allowed to grow.
void set_size_max (size_t sizemax)
 Sets the maximum size that this buffer is allowed to grow.
virtual void set_data (const void *newdata, size_t newsize, DataMode mode=COPY) throw (std::bad_alloc)
virtual bool resize (size_t s) throw (std::bad_alloc)
sigc::signal< void > signal_changed ()
 Signals a change to the data within the buffer.

Static Public Member Functions

static pointer create (size_t initial_size=0, size_t sizemax=0)
static pointer create (void *data, size_t size, size_t sizemax=0, DataMode mode=COPY)
static pointer create (size_t initial_size=0, size_t sizemax=0)
static pointer create (void *data, size_t size, size_t sizemax=0, DataMode mode=COPY)
static pointer create (size_t initial_size=0, size_t sizemax=0)
static pointer create (void *data, size_t size, size_t sizemax=0, DataMode mode=COPY)

Protected Member Functions

 Buffer (size_t initial_size=0, size_t sizemax=0)
 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)
 Construct a buffer that is a copy of external data.
bool clear_bits (size_t offset, size_t bits, bool suppress)
 Utility method to clear bits and suppress calling the on_changed* methods.
virtual void on_data_changed ()
 Buffer (size_t initial_size=0, size_t sizemax=0)
 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)
 Construct a buffer that is a copy of external data.
bool clear_bits (size_t offset, size_t bits, bool suppress)
 Utility method to clear bits and suppress calling the on_changed* methods.
virtual void on_data_changed ()
 Buffer (size_t initial_size=0, size_t sizemax=0)
 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)
 Construct a buffer that is a copy of external data.
bool clear_bits (size_t offset, size_t bits, bool suppress)
 Utility method to clear bits and suppress calling the on_changed* methods.
virtual void on_data_changed ()

Protected Attributes

size_t m_size_max


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
buf_offset_bits The offset from the beginning of the buffer in bits to begin extraction from
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

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 ^

void bit::Buffer::set_size_max ( size_t  sizemax  ) 

Sets the maximum size that this buffer is allowed to grow.

Note: if sizemax is set to a value less than the current buffer size the buffer will be truncated immediately.

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
buf_offset_bits The offset from the beginning of the buffer in bits to begin extraction from
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

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 ^

void bit::Buffer::set_size_max ( size_t  sizemax  ) 

Sets the maximum size that this buffer is allowed to grow.

Note: if sizemax is set to a value less than the current buffer size the buffer will be truncated immediately.

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
buf_offset_bits The offset from the beginning of the buffer in bits to begin extraction from
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

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 ^

void bit::Buffer::set_size_max ( size_t  sizemax  ) 

Sets the maximum size that this buffer is allowed to grow.

Note: if sizemax is set to a value less than the current buffer size the buffer will be truncated immediately.


The documentation for this class was generated from the following files:
Generated on Tue Mar 13 20:00:02 2007 by  doxygen 1.5.1