G3D::BinaryInput Class Reference#include <BinaryInput.h>
List of all members.
|
Public Member Functions |
| | BinaryInput (const std::string &filename, G3DEndian fileEndian, bool compressed=false) |
| | BinaryInput (const uint8 *data, int dataLen, G3DEndian dataEndian, bool compressed=false, bool copyMemory=true) |
| virtual | ~BinaryInput () |
| std::string | getFilename () const |
| const uint8 * | getCArray () const |
| const uint8 | operator[] (int n) |
| int | getLength () const |
| int | size () const |
| int | getPosition () const |
| void | setPosition (int p) |
| void | reset () |
| int8 | readInt8 () |
| bool | readBool8 () |
| uint8 | readUInt8 () |
| uint16 | readUInt16 () |
| int16 | readInt16 () |
| uint32 | readUInt32 () |
| int32 | readInt32 () |
| uint64 | readUInt64 () |
| int64 | readInt64 () |
| float32 | readFloat32 () |
| float64 | readFloat64 () |
| void | readBytes (int n, void *bytes) |
| void | readBytes (void *bytes, int n) |
| std::string | readString (int n) |
| std::string | readString () |
| std::string | readStringEven () |
| std::string | readString32 () |
| Vector4 | readVector4 () |
| Vector3 | readVector3 () |
| Vector2 | readVector2 () |
| Color4 | readColor4 () |
| Color3 | readColor3 () |
| void | skip (int n) |
| bool | hasMore () const |
| void | beginBits () |
| uint32 | readBits (int numBits) |
| void | endBits () |
| | DECLARE_READER (Bool8, bool) DECLARE_READER(UInt8 |
| uint8 | DECLARE_READER (Int8, int8) DECLARE_READER(UInt16 |
| uint8 uint16 | DECLARE_READER (Int16, int16) DECLARE_READER(UInt32 |
| uint8 uint16 uint32 | DECLARE_READER (Int32, int32) DECLARE_READER(UInt64 |
| uint8 uint16 uint32 uint64 | DECLARE_READER (Int64, int64) DECLARE_READER(Float32 |
Static Public Attributes |
| static const bool | NO_COPY |
Detailed Description
Sequential or random access byte-order independent binary file access. Files compressed with zlib and beginning with an unsigned 32-bit int size are transparently decompressed when the compressed = true flag is specified to the constructor.
For every readX method there are also versions that operate on a whole Array, std::vector, or C-array. e.g. readFloat32(Array<float32>& array, n) These methods resize the array or std::vector to the appropriate size before reading. For a C-array, they require the pointer to reference a memory block at least large enough to hold n elements.
Most classes define serialize/deserialize methods that use BinaryInput, BinaryOutput, TextInput, and TextOutput. There are text serializer functions for primitive types (e.g. int, std::string, float, double) but not binary serializers-- you must call the BinaryInput::readInt32 or other appropriate function. This is because it would be very hard to debug the error sequence: serialize(1.0, bo); ... float f; deserialize(f, bi); in which a double is serialized and then deserialized as a float.
Constructor & Destructor Documentation
| G3D::BinaryInput::BinaryInput |
( |
const std::string & |
filename, |
|
|
G3DEndian |
fileEndian, |
|
|
bool |
compressed = false |
|
) |
|
|
|
|
If the file cannot be opened, a zero length buffer is presented. |
| G3D::BinaryInput::BinaryInput |
( |
const uint8 * |
data, |
|
|
int |
dataLen, |
|
|
G3DEndian |
dataEndian, |
|
|
bool |
compressed = false, |
|
|
bool |
copyMemory = true |
|
) |
|
|
|
|
Creates input stream from an in memory source. Unless you specify copyMemory = false, the data is copied from the pointer, so you may deallocate it as soon as the object is constructed. It is an error to specify copyMemory = false and compressed = true.
To decompress part of a file, you can follow the following paradigm:
BinaryInput master(...);
read from master to point where compressed data exists.
BinaryInput subset(master.getCArray() + master.getPosition(),
master.length() - master.getPosition(),
true, true);
Now read from subset (it is ok for master to go out of scope)
|
| virtual G3D::BinaryInput::~BinaryInput |
( |
|
) |
[virtual] |
|
Member Function Documentation
| void G3D::BinaryInput::beginBits |
( |
|
) |
|
|
|
|
Prepares for bit reading via readBits. Only readBits can be called between beginBits and endBits without corrupting the data stream. |
| uint8 G3D::BinaryInput::DECLARE_READER |
( |
Int8 |
, |
|
|
int8 |
|
|
) |
|
|
| G3D::BinaryInput::DECLARE_READER |
( |
Bool8 |
, |
|
|
bool |
|
|
) |
|
|
| void G3D::BinaryInput::endBits |
( |
|
) |
|
|
| const uint8* G3D::BinaryInput::getCArray |
( |
|
) |
const [inline] |
|
|
|
Returns a pointer to the internal memory buffer. May throw an exception for huge files. |
| std::string G3D::BinaryInput::getFilename |
( |
|
) |
const [inline] |
|
| int G3D::BinaryInput::getLength |
( |
|
) |
const [inline] |
|
|
|
Returns the length of the file in bytes. |
| int G3D::BinaryInput::getPosition |
( |
|
) |
const [inline] |
|
|
|
Returns the current byte position in the file, where 0 is the beginning and getLength() - 1 is the end. |
| bool G3D::BinaryInput::hasMore |
( |
|
) |
const [inline] |
|
|
|
Returns true if the position is not at the end of the file |
| const uint8 G3D::BinaryInput::operator[] |
( |
int |
n |
) |
[inline] |
|
|
|
Performs bounds checks in debug mode. [] are relative to the start of the file, not the current position. Seeks to the new position before reading (and leaves that as the current position) |
| uint32 G3D::BinaryInput::readBits |
( |
int |
numBits |
) |
|
|
|
|
Can only be called between beginBits and endBits |
| bool G3D::BinaryInput::readBool8 |
( |
|
) |
[inline] |
|
| void G3D::BinaryInput::readBytes |
( |
void * |
bytes, |
|
|
int |
n |
|
) |
[inline] |
|
|
|
Returns the data in bytes. |
| void G3D::BinaryInput::readBytes |
( |
int |
n, |
|
|
void * |
bytes |
|
) |
|
|
| Color3 G3D::BinaryInput::readColor3 |
( |
|
) |
|
|
| Color4 G3D::BinaryInput::readColor4 |
( |
|
) |
|
|
| float32 G3D::BinaryInput::readFloat32 |
( |
|
) |
[inline] |
|
| float64 G3D::BinaryInput::readFloat64 |
( |
|
) |
[inline] |
|
| int16 G3D::BinaryInput::readInt16 |
( |
|
) |
[inline] |
|
| int32 G3D::BinaryInput::readInt32 |
( |
|
) |
[inline] |
|
| int64 G3D::BinaryInput::readInt64 |
( |
|
) |
[inline] |
|
| int8 G3D::BinaryInput::readInt8 |
( |
|
) |
[inline] |
|
| std::string G3D::BinaryInput::readString |
( |
|
) |
|
|
|
|
Reads until NULL or the end of the file is encountered. |
| std::string G3D::BinaryInput::readString |
( |
int |
n |
) |
|
|
|
|
Reads an n character string. The string is not required to end in NULL in the file but will always be a proper std::string when returned. |
| std::string G3D::BinaryInput::readString32 |
( |
|
) |
|
|
| std::string G3D::BinaryInput::readStringEven |
( |
|
) |
|
|
|
|
Reads until NULL or the end of the file is encountered. If the string has odd length (including NULL), reads another byte. |
| uint16 G3D::BinaryInput::readUInt16 |
( |
|
) |
[inline] |
|
| uint32 G3D::BinaryInput::readUInt32 |
( |
|
) |
[inline] |
|
| uint64 G3D::BinaryInput::readUInt64 |
( |
|
) |
|
|
| uint8 G3D::BinaryInput::readUInt8 |
( |
|
) |
[inline] |
|
| Vector2 G3D::BinaryInput::readVector2 |
( |
|
) |
|
|
| Vector3 G3D::BinaryInput::readVector3 |
( |
|
) |
|
|
| Vector4 G3D::BinaryInput::readVector4 |
( |
|
) |
|
|
| void G3D::BinaryInput::reset |
( |
|
) |
[inline] |
|
|
|
Goes back to the beginning of the file. |
| void G3D::BinaryInput::setPosition |
( |
int |
p |
) |
[inline] |
|
|
|
Sets the position. Cannot set past length. May throw a char* when seeking backwards more than 10 MB on a huge file. |
| int G3D::BinaryInput::size |
( |
|
) |
const [inline] |
|
| void G3D::BinaryInput::skip |
( |
int |
n |
) |
[inline] |
|
Member Data Documentation
|
|
false, constant to use with the copyMemory option |
The documentation for this class was generated from the following file:
Generated on Mon Jul 17 11:50:45 2006 for G3D by
1.4.5
Hosted by
|