Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

sheep::BinaryStream Class Reference

#include <binarystream.h>

List of all members.

Public Types

enum  StreamMode { InputStream, OutputStream }
enum  Endianness { NativeEndian, LittleEndian, BigEndian }
enum  SeekOrigin { SeekFromBeginning, SeekFromCurrent, SeekFromEnd }

Public Member Functions

 BinaryStream ()
 BinaryStream (const std::string &filename, StreamMode mode, Endianness endianness=NativeEndian)
 ~BinaryStream ()
void Open (const std::string &filename, StreamMode mode, Endianness endianness=NativeEndian)
void Close () throw (WriteException)
bool IsOpen () const
void SetBufferSize (int size)
void SetEndianness (Endianness endianness)
void Seek (long offset, SeekOrigin origin) throw (SeekException)
long Tell () const throw (SeekException)
void Write (const void *data, size_t size) throw (WriteException)
void Read (void *data, size_t size) throw (ReadException)
template<typename T> void Write (T t) throw (WriteException)
template<typename T> void Read (T *t) throw (ReadException)

Private Member Functions

Endianness get_host_endianness () const
void initialize ()
void flush_output_buffer () throw (WriteException)
size_t fill_input_buffer () throw (ReadException)
void invalidate_input_buffer ()
template<typename T> void swap_bytes (T *t) const
 Byte swapping function.


Private Attributes

FILE * m_file
 The file to which is binded the stream.

StreamMode m_mode
 Stream mode (input or output).

bool m_swap
 True if bytes must be swapped (if host and target endianness differ).

char * m_buffer_base
 Base address of the buffer.

char * m_buffer_end
 In InputStream mode: one byte past the end of the data. In OutputStream mode: one byte past the end of the buffer.

char * m_buffer_ptr
 Current location in the buffer (points to the next byte to read/write).

int m_buffer_size
 Total size of the buffer.


Member Enumeration Documentation

enum sheep::BinaryStream::Endianness
 

Enumeration values:
NativeEndian 
LittleEndian 
BigEndian 

Definition at line 48 of file binarystream.h.

enum sheep::BinaryStream::SeekOrigin
 

Enumeration values:
SeekFromBeginning 
SeekFromCurrent 
SeekFromEnd 

Definition at line 81 of file binarystream.h.

enum sheep::BinaryStream::StreamMode
 

Enumeration values:
InputStream 
OutputStream 

Definition at line 43 of file binarystream.h.


Constructor & Destructor Documentation

BinaryStream::BinaryStream  ) 
 

Definition at line 33 of file binarystream.cpp.

References initialize().

BinaryStream::BinaryStream const std::string &  filename,
StreamMode  mode,
Endianness  endianness = NativeEndian
 

Definition at line 37 of file binarystream.cpp.

References initialize(), and Open().

BinaryStream::~BinaryStream  ) 
 

Definition at line 45 of file binarystream.cpp.

References Close().


Member Function Documentation

void BinaryStream::Close  )  throw (WriteException)
 

Definition at line 65 of file binarystream.cpp.

Referenced by sheep::TRILoader::close_geometry_file(), and ~BinaryStream().

size_t BinaryStream::fill_input_buffer  )  throw (ReadException) [private]
 

Definition at line 245 of file binarystream.cpp.

void BinaryStream::flush_output_buffer  )  throw (WriteException) [private]
 

Definition at line 228 of file binarystream.cpp.

BinaryStream::Endianness BinaryStream::get_host_endianness  )  const [private]
 

Definition at line 212 of file binarystream.cpp.

References BigEndian, and LittleEndian.

Referenced by SetEndianness().

void BinaryStream::initialize  )  [private]
 

Definition at line 219 of file binarystream.cpp.

References InputStream, m_buffer_base, m_buffer_end, m_buffer_ptr, m_buffer_size, m_mode, and m_swap.

Referenced by BinaryStream().

void BinaryStream::invalidate_input_buffer  )  [private]
 

Definition at line 262 of file binarystream.cpp.

References m_buffer_base, and m_buffer_end.

bool BinaryStream::IsOpen  )  const
 

Definition at line 78 of file binarystream.cpp.

Referenced by toxic::PhotonMap::CreateFromFile(), sheep::TRILoader::open_geometry_file(), and toxic::PhotonMap::WriteToFile().

void BinaryStream::Open const std::string &  filename,
StreamMode  mode,
Endianness  endianness = NativeEndian
 

Definition at line 49 of file binarystream.cpp.

References DEFAULT_BUFFER_SIZE, InputStream, m_mode, SetBufferSize(), and SetEndianness().

Referenced by BinaryStream(), and sheep::TRILoader::open_geometry_file().

template<typename T>
void BinaryStream::Read T *  t  )  throw (ReadException) [inline]
 

Definition at line 168 of file binarystream.h.

void BinaryStream::Read void *  data,
size_t  size
throw (ReadException)
 

Reads a sequence of contiguous bytes from the stream. No byte reordering is performed.

Definition at line 172 of file binarystream.cpp.

References sheep::min().

Referenced by toxic::PhotonMap::CreateFromFile(), and sheep::TRILoader::read_geometry_file().

void BinaryStream::Seek long  offset,
SeekOrigin  origin
throw (SeekException)
 

Definition at line 103 of file binarystream.cpp.

Referenced by sheep::TRILoader::Load().

void BinaryStream::SetBufferSize int  size  ) 
 

Sets the I/O buffer size. 'size' is expressed in bytes. The smallest value for 'size' is 1. This method must be called before using the stream.

Definition at line 82 of file binarystream.cpp.

References InputStream, m_buffer_base, m_buffer_end, m_buffer_ptr, m_buffer_size, and m_mode.

Referenced by toxic::PhotonMap::CreateFromFile(), Open(), and toxic::PhotonMap::WriteToFile().

void BinaryStream::SetEndianness Endianness  endianness  ) 
 

Definition at line 97 of file binarystream.cpp.

References get_host_endianness(), m_swap, and NativeEndian.

Referenced by Open(), and sheep::TRILoader::read_geometry_file().

template<typename T>
void BinaryStream::swap_bytes T *  t  )  const [inline, private]
 

Byte swapping function.

Definition at line 178 of file binarystream.h.

long BinaryStream::Tell  )  const throw (SeekException)
 

Definition at line 126 of file binarystream.cpp.

Referenced by sheep::TRILoader::Load(), and sheep::TRILoader::read_geometry_file().

template<typename T>
void BinaryStream::Write t  )  throw (WriteException) [inline]
 

Definition at line 160 of file binarystream.h.

void BinaryStream::Write const void *  data,
size_t  size
throw (WriteException)
 

Writes a sequence of contiguous bytes to the stream. No byte reordering is performed.

Definition at line 137 of file binarystream.cpp.

References sheep::min().

Referenced by toxic::PhotonMap::WriteToFile().


Member Data Documentation

char* sheep::BinaryStream::m_buffer_base [private]
 

Base address of the buffer.

Definition at line 115 of file binarystream.h.

Referenced by initialize(), invalidate_input_buffer(), and SetBufferSize().

char* sheep::BinaryStream::m_buffer_end [private]
 

In InputStream mode: one byte past the end of the data. In OutputStream mode: one byte past the end of the buffer.

Definition at line 116 of file binarystream.h.

Referenced by initialize(), invalidate_input_buffer(), and SetBufferSize().

char* sheep::BinaryStream::m_buffer_ptr [private]
 

Current location in the buffer (points to the next byte to read/write).

Definition at line 117 of file binarystream.h.

Referenced by initialize(), and SetBufferSize().

int sheep::BinaryStream::m_buffer_size [private]
 

Total size of the buffer.

Definition at line 118 of file binarystream.h.

Referenced by initialize(), and SetBufferSize().

FILE* sheep::BinaryStream::m_file [private]
 

The file to which is binded the stream.

Definition at line 112 of file binarystream.h.

StreamMode sheep::BinaryStream::m_mode [private]
 

Stream mode (input or output).

Definition at line 113 of file binarystream.h.

Referenced by initialize(), Open(), and SetBufferSize().

bool sheep::BinaryStream::m_swap [private]
 

True if bytes must be swapped (if host and target endianness differ).

Definition at line 114 of file binarystream.h.

Referenced by initialize(), and SetEndianness().


The documentation for this class was generated from the following files:
Generated on Tue May 11 01:31:55 2004 for toxic by doxygen 1.3.6