CMS 3D CMS Logo

lat::ReadWriteBuffer Class Reference

Buffer for reads and writes to a seekable backing store. More...

#include <Iguana/Utilities/classlib/iotools/ReadWriteBuffer.h>

List of all members.

Public Types

enum  { DEFAULT_SIZE = 4096 }

Public Member Functions

unsigned char * buffer (void) const
void bump (IOSize n)
IOSize capacity (void) const
unsigned char * current (void) const
unsigned char * dirty (void) const
unsigned char * end (void) const
void filled (IOSize n)
void get (void *data, IOSize n)
IOSize left (void) const
unsigned char * limit (void) const
ptrdiff_t offset (void) const
ReadWriteBufferoperator= (const ReadWriteBuffer &x)
unsigned char * pback (void) const
void put (const void *data, IOSize n)
 ReadWriteBuffer (const ReadWriteBuffer &x)
 ReadWriteBuffer (IOSize busize=DEFAULT_SIZE)
unsigned char * reference (void) const
void reset (void)
void skip (IOSize n)
void taken (IOSize n)
void unget (const void *data, IOSize n)
 ~ReadWriteBuffer (void)

Private Attributes

unsigned char * m_buffer
unsigned char * m_current
unsigned char * m_dirty
unsigned char * m_end
unsigned char * m_limit
unsigned char * m_pback
unsigned char * m_reference


Detailed Description

Buffer for reads and writes to a seekable backing store.

This class makes it easier to buffer input and output to seekable stores such as Storage objects. The object maintains a reference location and a single combined buffer for both reads and writes. The buffer can be thought of as a cache window of data surrounding the reference location, the file position of the underlying store. The "real" file position is the current buffer position, which is usually at an offset from the store's file position: negative after buffered reads, positive after buffered writes.

Clients should use get() for buffered reads from the store. If left() returns zero to indicate the buffer is exhausted, clients should copy at most capacity() bytes from the external source into end(). They should then call filled() to tell the buffer how much was added, the method updates the other pointers and moves the reference location to the end of the newly added data. This matches normal reads: the store file pointer remains at the end of what has just been read. The "real" file pointer is the one maintained by the buffer at the beginning of the data. It is possible to add more data even if left() does not return zero provided capacity() returns non-zero and is not dirty().

Clients should use put() for buffered writes to the store. If capacity() returns zero to indicate the buffer is full, clients should write the section dirty() .. current () to the store. offset() indicates the distance from the reference location at which the write should occur, current() - dirty() is the number of bytes to write. Once the data has been written, the client should call taken() to move the pointers and the reference location to the end of the just written data. This matches normal writes; the store file pointer remains at the end of what was just written.

Writing to the buffer causes it to discard data already buffered for reads with filled(). More specifically, left() will return zero after a put() as long as there is dirty data in the buffer; all of it must be extracted with taken() before read can proceed. Thus, if left() returns zero, clients should notice the buffer is dirty() and synchronise with the external store before trying to read more input. This behaviour implies that some already data may be lost if the underlying input is unseekable (stream-like). Use separate read and write buffers for streaming.

The buffer also maintains a push-back area. Bytes already read from the buffer can be "unread", or new data can be pushed back to be accessed on the next get(). Arbitrary amounts of data can be pushed back. That data is however considered "virtual" as it may not correspond to the data in the backing store. Thus a put() discards all pushed-back data, and then writes at the last "real" position (remembered by pback()).

Definition at line 68 of file ReadWriteBuffer.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
DEFAULT_SIZE 

Definition at line 71 of file ReadWriteBuffer.h.

00071 { DEFAULT_SIZE = 4096 };  //< Default buffer size


Constructor & Destructor Documentation

lat::ReadWriteBuffer::ReadWriteBuffer ( IOSize  busize = DEFAULT_SIZE  ) 

lat::ReadWriteBuffer::ReadWriteBuffer ( const ReadWriteBuffer x  ) 

lat::ReadWriteBuffer::~ReadWriteBuffer ( void   ) 


Member Function Documentation

unsigned char* lat::ReadWriteBuffer::buffer ( void   )  const

void lat::ReadWriteBuffer::bump ( IOSize  n  ) 

IOSize lat::ReadWriteBuffer::capacity ( void   )  const

unsigned char* lat::ReadWriteBuffer::current ( void   )  const

unsigned char* lat::ReadWriteBuffer::dirty ( void   )  const

unsigned char* lat::ReadWriteBuffer::end ( void   )  const

void lat::ReadWriteBuffer::filled ( IOSize  n  ) 

void lat::ReadWriteBuffer::get ( void data,
IOSize  n 
)

IOSize lat::ReadWriteBuffer::left ( void   )  const

unsigned char* lat::ReadWriteBuffer::limit ( void   )  const

ptrdiff_t lat::ReadWriteBuffer::offset ( void   )  const

ReadWriteBuffer& lat::ReadWriteBuffer::operator= ( const ReadWriteBuffer x  ) 

unsigned char* lat::ReadWriteBuffer::pback ( void   )  const

void lat::ReadWriteBuffer::put ( const void data,
IOSize  n 
)

unsigned char* lat::ReadWriteBuffer::reference ( void   )  const

void lat::ReadWriteBuffer::reset ( void   ) 

void lat::ReadWriteBuffer::skip ( IOSize  n  ) 

void lat::ReadWriteBuffer::taken ( IOSize  n  ) 

void lat::ReadWriteBuffer::unget ( const void data,
IOSize  n 
)


Member Data Documentation

unsigned char* lat::ReadWriteBuffer::m_buffer [private]

Definition at line 103 of file ReadWriteBuffer.h.

unsigned char* lat::ReadWriteBuffer::m_current [private]

Definition at line 104 of file ReadWriteBuffer.h.

unsigned char* lat::ReadWriteBuffer::m_dirty [private]

Definition at line 109 of file ReadWriteBuffer.h.

unsigned char* lat::ReadWriteBuffer::m_end [private]

Definition at line 105 of file ReadWriteBuffer.h.

unsigned char* lat::ReadWriteBuffer::m_limit [private]

Definition at line 106 of file ReadWriteBuffer.h.

unsigned char* lat::ReadWriteBuffer::m_pback [private]

Definition at line 108 of file ReadWriteBuffer.h.

unsigned char* lat::ReadWriteBuffer::m_reference [private]

Definition at line 107 of file ReadWriteBuffer.h.


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:48:34 2009 for CMSSW by  doxygen 1.5.4