Contents Functions Classes Topics User Forum CVS

G3D::BinaryOutput Class Reference

#include <BinaryOutput.h>

List of all members.

Public Member Functions

 BinaryOutput ()
 BinaryOutput (const std::string &filename, G3DEndian fileEndian)
 ~BinaryOutput ()
void compress ()
const uint8getCArray () const
void setEndian (G3DEndian fileEndian)
std::string getFilename () const
void commit (bool flush=true)
void commit (uint8 *)
void reset ()
int length () const
int getLength () const
int size () const
void setLength (int n)
int position () const
int getPosition () const
void setPosition (int p)
void writeBytes (const void *b, int count)
void writeInt8 (int8 i)
void writeBool8 (bool b)
void writeUInt8 (uint8 i)
void writeUInt16 (uint16 u)
void writeInt16 (int16 i)
void writeUInt32 (uint32 u)
void writeInt32 (int32 i)
void writeUInt64 (uint64 u)
void writeInt64 (int64 i)
void writeFloat32 (float32 f)
void writeFloat64 (float64 f)
void writeString (const std::string &s)
void writeString (const char *s)
void writeStringEven (const std::string &s)
void writeStringEven (const char *s)
void writeString32 (const char *s)
void writeString32 (const std::string &s)
void writeVector4 (const Vector4 &v)
void writeVector3 (const Vector3 &v)
void writeVector2 (const Vector2 &v)
void writeColor4 (const Color4 &v)
void writeColor3 (const Color3 &v)
void skip (int n)
void beginBits ()
void writeBits (uint32 bitString, int numBits)
void endBits ()
 DECLARE_WRITER (Bool8, bool) DECLARE_WRITER(UInt8
uint8 DECLARE_WRITER (Int8, int8) DECLARE_WRITER(UInt16
uint8 uint16 DECLARE_WRITER (Int16, int16) DECLARE_WRITER(UInt32
uint8 uint16 uint32 DECLARE_WRITER (Int32, int32) DECLARE_WRITER(UInt64
uint8 uint16 uint32 uint64 DECLARE_WRITER (Int64, int64) DECLARE_WRITER(Float32


Detailed Description

Sequential or random access byte-order independent binary file access.

The compress() call can be used to compress with zlib.

Any method call can trigger an out of memory error (thrown as char*) when writing to "<memory>" instead of a file.

Compressed writing and seeking backwards is not supported for huge files (i.e., BinaryOutput may have to dump the contents to disk if they exceed available RAM).


Constructor & Destructor Documentation

G3D::BinaryOutput::BinaryOutput  ) 
 

You must call setEndian() if you use this (memory) constructor.

G3D::BinaryOutput::BinaryOutput const std::string &  filename,
G3DEndian  fileEndian
 

Doesn't actually open the file; commit() does that. Use "<memory>" as the filename if you're going to commit to memory.

G3D::BinaryOutput::~BinaryOutput  ) 
 


Member Function Documentation

void G3D::BinaryOutput::beginBits  ) 
 

Call before a series of BinaryOutput::writeBits calls. Only writeBits can be called between beginBits and endBits without corrupting the stream.

void G3D::BinaryOutput::commit uint8  ) 
 

Write the bytes to memory (which must be of at least size() bytes).

void G3D::BinaryOutput::commit bool  flush = true  ) 
 

Write the bytes to disk. It is ok to call this multiple times; it will just overwrite the previous file.

Parent directories are created as needed if they do not exist.

Not called from the destructor; you must call it yourself.

Parameters:
flush If true (default) the file is ready for reading when the method returns, otherwise the method returns immediately and writes the file in the background.

void G3D::BinaryOutput::compress  ) 
 

Compresses the data in the buffer in place, preceeding it with a little-endian uint32 indicating the uncompressed size.

Call immediately before commit().

Cannot be used for huge files (ones where the data was already written to disk)-- will throw char*.

uint8 uint16 uint32 uint64 G3D::BinaryOutput::DECLARE_WRITER Int64  ,
int64 
 

uint8 uint16 uint32 G3D::BinaryOutput::DECLARE_WRITER Int32  ,
int32 
 

uint8 uint16 G3D::BinaryOutput::DECLARE_WRITER Int16  ,
int16 
 

uint8 G3D::BinaryOutput::DECLARE_WRITER Int8  ,
int8 
 

G3D::BinaryOutput::DECLARE_WRITER Bool8  ,
bool 
 

void G3D::BinaryOutput::endBits  ) 
 

Call after a series of BinaryOutput::writeBits calls. This will finish out with zeros the last byte into which bits were written.

const uint8* G3D::BinaryOutput::getCArray  )  const [inline]
 

Returns a pointer to the internal memory buffer.

std::string G3D::BinaryOutput::getFilename  )  const [inline]
 

int G3D::BinaryOutput::getLength  )  const [inline]
 

Returns the length of the file in bytes.

Deprecated:
use BinaryOutput.size

int G3D::BinaryOutput::getPosition  )  const [inline]
 

Deprecated:

int G3D::BinaryOutput::length  )  const [inline]
 

int G3D::BinaryOutput::position  )  const [inline]
 

Returns the current byte position in the file, where 0 is the beginning and getLength() - 1 is the end.

void G3D::BinaryOutput::reset  ) 
 

A memory BinaryOutput may be reset so that it can be written to again without allocating new memory. The underlying array will not be deallocated, but the reset structure will act like a newly intialized one.

void G3D::BinaryOutput::setEndian G3DEndian  fileEndian  ) 
 

void G3D::BinaryOutput::setLength int  n  )  [inline]
 

Sets the length of the file to n, padding with 0's past the current end. Does not change the position of the next byte to be written unless n < size().

Throws char* when resetting a huge file to be shorter than its current length.

void G3D::BinaryOutput::setPosition int  p  )  [inline]
 

Sets the position. Can set past length, in which case the file is padded with zeros up to one byte before the next to be written.

May throw a char* exception when seeking backwards on a huge file.

int G3D::BinaryOutput::size  )  const [inline]
 

void G3D::BinaryOutput::skip int  n  )  [inline]
 

Skips ahead n bytes.

void G3D::BinaryOutput::writeBits uint32  bitString,
int  numBits
 

Write numBits from bitString to the output stream. Bits are numbered from low to high.

Can only be called between beginBits and endBits. Bits written are semantically little-endian, regardless of the actual endian-ness of the system. That is, writeBits(0xABCD, 16) writes 0xCD to the first byte and 0xAB to the second byte. However, if used with BinaryInput::readBits, the ordering is transparent to the caller.

void G3D::BinaryOutput::writeBool8 bool  b  )  [inline]
 

void G3D::BinaryOutput::writeBytes const void *  b,
int  count
[inline]
 

void G3D::BinaryOutput::writeColor3 const Color3 v  ) 
 

void G3D::BinaryOutput::writeColor4 const Color4 v  ) 
 

void G3D::BinaryOutput::writeFloat32 float32  f  )  [inline]
 

void G3D::BinaryOutput::writeFloat64 float64  f  )  [inline]
 

void G3D::BinaryOutput::writeInt16 int16  i  )  [inline]
 

void G3D::BinaryOutput::writeInt32 int32  i  )  [inline]
 

void G3D::BinaryOutput::writeInt64 int64  i  )  [inline]
 

void G3D::BinaryOutput::writeInt8 int8  i  )  [inline]
 

Writes a signed 8-bit integer to the current position.

void G3D::BinaryOutput::writeString const char *  s  ) 
 

void G3D::BinaryOutput::writeString const std::string &  s  )  [inline]
 

Write a string with NULL termination.

void G3D::BinaryOutput::writeString32 const std::string &  s  )  [inline]
 

Write a string with a 32-bit length field in front of it.

void G3D::BinaryOutput::writeString32 const char *  s  ) 
 

void G3D::BinaryOutput::writeStringEven const char *  s  ) 
 

void G3D::BinaryOutput::writeStringEven const std::string &  s  )  [inline]
 

Write a string, ensuring that the total length including NULL is even.

void G3D::BinaryOutput::writeUInt16 uint16  u  ) 
 

void G3D::BinaryOutput::writeUInt32 uint32  u  ) 
 

void G3D::BinaryOutput::writeUInt64 uint64  u  ) 
 

void G3D::BinaryOutput::writeUInt8 uint8  i  )  [inline]
 

void G3D::BinaryOutput::writeVector2 const Vector2 v  ) 
 

void G3D::BinaryOutput::writeVector3 const Vector3 v  ) 
 

void G3D::BinaryOutput::writeVector4 const Vector4 v  ) 
 


The documentation for this class was generated from the following file:
Generated on Mon Jul 17 11:50:45 2006 for G3D by doxygen 1.4.5
Hosted by SourceForge.net Logo