class MemoryByteStream: public ByteStream

ByteStream interface managing a memory buffer.

Inheritance:


Public Methods

[more] MemoryByteStream()
Constructs an empty MemoryByteStream.
[more] MemoryByteStream(const void *buffer, size_t size)
Constructs a MemoryByteStream by copying initial data.
[more] MemoryByteStream(const char *buffer)
Constructs a MemoryByteStream by copying an initial string.
[more]int size()
Returns the total number of bytes contained in the buffer.
[more]char& operator[] (int n)
Returns a reference to the byte at offset n.

Protected Fields

[more]int bsize
Number of bytes in internal buffer.
[more]int nblocks
Number of 4096 bytes blocks.
[more]char** blocks
Pointers (possibly null) to 4096 bytes blocks.

Protected Methods

[more]size_t readat(void *buffer, size_t sz, int pos)
Reads data from a random position.


Inherited from ByteStream:

Public

Virtual Functions.

[more]virtual ~ByteStream()
Virtual destructor.
[more]virtual size_t read(void *buffer, size_t size)
Reads data from a ByteStream.
[more]virtual size_t write(const void *buffer, size_t size)
Writes data to a ByteStream.
[more]virtual long tell(void)
Returns the offset of the current position in the ByteStream.
[more]virtual int is_seekable(void) const
Tests whether function seek can seek backwards.
[more]virtual void seek(long offset, int whence = SEEK_SET)
Sets the current position for reading or writing the ByteStream.
[more]virtual void flush()
Flushes all buffers in the ByteStream.

Utility Functions.

[more]size_t readall(void *buffer, size_t size)
Reads data and blocks until everything has been read.
[more]size_t writall(const void *buffer, size_t size)
Writes data and blocks until everything has been written.
[more]size_t copy(ByteStream &bsfrom, size_t size=0)
Copy data from another ByteStream.
[more]void write8(unsigned int card8)
Writes a one-byte integer to a ByteStream.
[more]void write16(unsigned int card16)
Writes a two-bytes integer to a ByteStream.
[more]void write32(unsigned int card32)
Writes a four-bytes integer to a ByteStream.
[more]unsigned int read8()
Reads a one-byte integer from a ByteStream.
[more]unsigned int read16()
Reads a two-bytes integer from a ByteStream.
[more]unsigned int read32()
Reads a four-bytes integer from a ByteStream.


Documentation

ByteStream interface managing a memory buffer. Class MemoryByteStream manages a dynamically resizeable buffer from which data can be read or written. The buffer itself is organized as an array of blocks of 4096 bytes.
o MemoryByteStream()
Constructs an empty MemoryByteStream. The buffer is initially empty. You must first use function write to store data into the buffer, use function seek to rewind the current position, and function read to read the data back.

o MemoryByteStream(const void *buffer, size_t size)
Constructs a MemoryByteStream by copying initial data. The MemoryByteStream buffer is initialized with size bytes copied from the memory area pointed to by buffer.

o MemoryByteStream(const char *buffer)
Constructs a MemoryByteStream by copying an initial string. The MemoryByteStream buffer is initialized with the null terminated string buffer.

oint size()
Returns the total number of bytes contained in the buffer. Valid offsets for function seek range from 0 to the value returned by this function.

ochar& operator[] (int n)
Returns a reference to the byte at offset n. This reference can be used to read (as in mbs[n]) or modify (as in mbs[n]=c) the contents of the buffer.

osize_t readat(void *buffer, size_t sz, int pos)
Reads data from a random position. This function reads at most sz bytes at position pos into buffer and returns the actual number of bytes read. The current position is unchanged.

oint bsize
Number of bytes in internal buffer.

oint nblocks
Number of 4096 bytes blocks.

ochar** blocks
Pointers (possibly null) to 4096 bytes blocks.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java