Main Page | Class Hierarchy | Class List | Directories | Class Members

BitStream Class Reference

A BitStream is an abstraction for a memory buffer. More...

#include <mnt_bit_stream.h>

List of all members.

Public Member Functions

 BitStream (int size)
 Allocate a new BitStream of size bytes, and return a pointer to the BitStream.
 BitStream (char *name)
 Allocate and return a new BitStream whose contents are a memory map of the file fname.
 ~BitStream ()
 Deallocate the BitStream.
void resize (int newsize)
 Reallocate the BitStream to size number of bytes.
int bytes_left (int offset)
 Return the number of bytes of data in this BitStream, from the given offset postion off to the end.
void share (BitStream *dest)
 Share the buffer of this BitStream with another BitStream dest.

Public Attributes

unsigned char * buffer_
unsigned char * endDataPtr_
unsigned char * endBufPtr_
unsigned char isVirtual_
unsigned char isMMap_
int size_


Detailed Description

A BitStream is an abstraction for a memory buffer.


Constructor & Destructor Documentation

BitStream::BitStream int  size  ) 
 

Allocate a new BitStream of size bytes, and return a pointer to the BitStream.

If size=0, only the header, not the buffer, is allocated. This form is useful in conjunction with share().

Parameters:
size the size of the buffer to allocate.

BitStream::BitStream char *  fname  ) 
 

Allocate and return a new BitStream whose contents are a memory map of the file fname.

This BitStream can be used for reading only.

Parameters:
fname Filename of the file to mapped into memory.

BitStream::~BitStream  ) 
 

Deallocate the BitStream.

If the BitStream is not a ``virtual'' BitStream (i.e., not pointing to someone else's buffer), then the memory are deallocated. If the BitStream is created through memory map, the memory is unmapped.


Member Function Documentation

int BitStream::bytes_left int  off  ) 
 

Return the number of bytes of data in this BitStream, from the given offset postion off to the end.

For example, if this BitStream has 80 bytes of valid date, bytes_left(60) will return 20.

void BitStream::resize int  size  ) 
 

Reallocate the BitStream to size number of bytes.

If the BitStream size is increased, the contents of the buffer are unchanged. If it is decreased, the data will be truncated. This should not be used on memory mapped buffer.

Parameters:
size The new size of the BitStream.

void BitStream::share BitStream dest  ) 
 

Share the buffer of this BitStream with another BitStream dest.

That is, dest's buffer will be set to the buffer of this BitStream. Warning: dest's buffer is not free'd, so memory leaks can occur if not used carefully.

A common way to use this function is in conjunction with "dest = new BitStream(0)"

Parameters:
dest The BitStream we want to share this buffer with.


Member Data Documentation

unsigned char* BitStream::buffer_
 

pointer to first byte of memory buffer

unsigned char* BitStream::endBufPtr_
 

pointer to the next byte after the last byte in buffer

unsigned char* BitStream::endDataPtr_
 

pointer to the byte after last valid data byte in buffer

unsigned char BitStream::isMMap_
 

1 iff this is a memory mapped stream

unsigned char BitStream::isVirtual_
 

1 iff this is a virtual BitStream

int BitStream::size_
 

size of buffer in bytes


The documentation for this class was generated from the following files:
Generated on Wed Sep 14 12:37:12 2005 for mnt by  doxygen 1.4.4