GClasses
GClasses::GBlobQueue Class Reference

Detailed Description

This is a special queue for handling blobs that come in and go out in varying sizes. It is particulary designed for streaming things that must travel or be parsed in packets that may differ in size from how they are sent or transmitted.

#include <GBlob.h>

Public Member Functions

 GBlobQueue ()
 
 ~GBlobQueue ()
 
const char * dequeue (size_t len)
 Returns a pointer to the specified number of bytes, and advances the queue by that amount. If less than the required amount is available, then it will buffer any remaining bytes and return NULL, and not advance the queue. (The idea is that you will enqueue some more bytes and then try again.) In most cases, this method will just return a pointer within the blob that was most recently enqueued, but it may return a pointer to its own buffer when breaks occur at unfortunate positions. (The internal buffer is guaranteed to grow no bigger than the largest value ever passed for len.) More...
 
void enqueue (const char *pBlob, size_t len)
 Adds some bytes to the queue. pBlob is assumed to remain valid until a call to dequeue returns NULL. More...
 
size_t readyBytes ()
 Returns the number of bytes that are ready to go. If you pass this same number to dequeue, it is guaranteed to return a non-NULL value, and subsequent calls to dequeue are guaranteed to return NULL until you call enqueue to put something back into the queue. More...
 

Protected Member Functions

void reallocBuffer (size_t newSize)
 

Protected Attributes

size_t m_bufferAllocation
 
size_t m_bufferBytes
 
size_t m_bytesRemaining
 
char * m_pBuffer
 
const char * m_pPos
 

Constructor & Destructor Documentation

GClasses::GBlobQueue::GBlobQueue ( )
GClasses::GBlobQueue::~GBlobQueue ( )

Member Function Documentation

const char* GClasses::GBlobQueue::dequeue ( size_t  len)

Returns a pointer to the specified number of bytes, and advances the queue by that amount. If less than the required amount is available, then it will buffer any remaining bytes and return NULL, and not advance the queue. (The idea is that you will enqueue some more bytes and then try again.) In most cases, this method will just return a pointer within the blob that was most recently enqueued, but it may return a pointer to its own buffer when breaks occur at unfortunate positions. (The internal buffer is guaranteed to grow no bigger than the largest value ever passed for len.)

void GClasses::GBlobQueue::enqueue ( const char *  pBlob,
size_t  len 
)

Adds some bytes to the queue. pBlob is assumed to remain valid until a call to dequeue returns NULL.

size_t GClasses::GBlobQueue::readyBytes ( )
inline

Returns the number of bytes that are ready to go. If you pass this same number to dequeue, it is guaranteed to return a non-NULL value, and subsequent calls to dequeue are guaranteed to return NULL until you call enqueue to put something back into the queue.

void GClasses::GBlobQueue::reallocBuffer ( size_t  newSize)
protected

Member Data Documentation

size_t GClasses::GBlobQueue::m_bufferAllocation
protected
size_t GClasses::GBlobQueue::m_bufferBytes
protected
size_t GClasses::GBlobQueue::m_bytesRemaining
protected
char* GClasses::GBlobQueue::m_pBuffer
protected
const char* GClasses::GBlobQueue::m_pPos
protected