Fennel: ByteWindow< IndexT > Class Template Reference (original) (raw)

ByteWindow represents a window into a large array of bytes. More...

#include <[ByteBuffer.h](ByteBuffer%5F8h-source.html)>

List of all members.

Public Member Functions
void init (SharedByteBuffer pBuffer)
Initialize a buffer, valid from index 0.
void reset ()
Reinitializes buffer to empty condition.
uint getCapacity () const
Returns the capacity of the buffer.
IndexT getStart () const
Returns the index of the first entry stored in the buffer.
IndexT getEnd () const
Returns the index of the end of data (the first entry with no data).
IndexT getLimit ()
Returns the write limit of the buffer (the first invalid index).
PBuffer getMem (IndexT index, uint &size)
Returns contiguous memory at position.
void advance (IndexT pos)
Advances the start of the buffer, releasing part of the buffer to store more values.
void advanceEnd (IndexT pos)
Advances the end pointer, initializing new entries to zero.
UnsignedByte getByte (IndexT index) const
Returns the value of the byte at the specified index.
void mergeByte (IndexT index, UnsignedByte val)
Merge a byte into the buffer.
void mergeMem (IndexT index, PConstBuffer byteSeg, uint len)
Merge a series of bytes into the buffer.
Private Member Functions
uint getOffset (IndexT index) const
Retrieves the offset of index in buffer.
uint getUnwrappedMemSize (IndexT index)
Returns size of buffer starting at index, which is not wrapped by the circular buffer.
Private Attributes
SharedByteBuffer pBuffer
Internal buffer.
uint windowSize
Maximum size of window.
uint startOffset
Offset of current start index.
IndexT start
Current start index; buffer has no data for index < start.
IndexT end
Index not yet written; buffer has no data for index >= end.

Detailed Description

template

class ByteWindow< IndexT >

ByteWindow represents a window into a large array of bytes.

It's like an array whose start and end are not fixed. At any time, the buffer is valid for entries between start and end. However, the start may be advanced, as data is read. The end may be advanced as more data is written. The amount of data is limited by the buffer's capacity, and data cannot be written past the limit.

The contents of a ByteWindow can be considered to be initialized to zero. A ByteWindow neither allocates nor frees any memory. It is templatized to support different kinds of indexes.

Definition at line 166 of file ByteBuffer.h.


Member Function Documentation

template

uint ByteWindow< IndexT >::getOffset ( IndexT index ) const [inline, private]

template

uint ByteWindow< IndexT >::getUnwrappedMemSize ( IndexT index ) [inline, private]

template

| void ByteWindow< IndexT >::reset | ( | | ) | [inline] | | -------------------------------------------------------- | - | | - | ---------- |

template

| uint ByteWindow< IndexT >::getCapacity | ( | | ) | const [inline] | | --------------------------------------------------------------------------------------------------------------------------- | - | | - | ---------------- |

template

| IndexT ByteWindow< IndexT >::getStart | ( | | ) | const [inline] | | ------------------------------------------------------------- | - | | - | ---------------- |

template

| IndexT ByteWindow< IndexT >::getEnd | ( | | ) | const [inline] | | ----------------------------------------------------------- | - | | - | ---------------- |

template

| IndexT ByteWindow< IndexT >::getLimit | ( | | ) | [inline] | | ------------------------------------------------------------- | - | | - | ---------- |

template

void ByteWindow< IndexT >::advance ( IndexT pos ) [inline]

template

void ByteWindow< IndexT >::advanceEnd ( IndexT pos ) [inline]

Merge a series of bytes into the buffer.

Definition at line 339 of file ByteBuffer.h.

References ByteWindow< IndexT >::advanceEnd(), ByteWindow< IndexT >::end, ByteWindow< IndexT >::getLimit(), ByteWindow< IndexT >::getOffset(), ByteWindow< IndexT >::getUnwrappedMemSize(), min(), ByteWindow< IndexT >::pBuffer, ByteWindow< IndexT >::start, and ByteWindow< IndexT >::windowSize.

00340 { 00341 assert(index >= start); 00342 assert(len < windowSize); 00343 assert(index + len <= getLimit()); 00344 assert(len > 0); 00345 00346
00347 IndexT writeEnd = index + len; 00348 if (writeEnd > end) { 00349 advanceEnd(writeEnd); 00350 } 00351 00352 uint chunkSize = std::min(len, getUnwrappedMemSize(index)); 00353 pBuffer->mergeMem(getOffset(index), byteSeg, chunkSize); 00354 if (len > chunkSize) { 00355 pBuffer->mergeMem(0, byteSeg + chunkSize, len - chunkSize); 00356 } 00357 }


Member Data Documentation


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


Generated on Mon Jun 22 04:00:27 2009 for Fennel by doxygen 1.5.1