Node:binistream, Next:, Previous:binio, Up:Base classes



binistream

binistream provides an input-only binary stream.

Header file: binio.h

Public methods:

binistream()
The constructor.
~binistream()
The destructor.
Int readInt(unsigned int size)
Reads an integer of size size (in bytes) from the stream and returns it. The return value is undefined if an error occured. The maximum number of bytes that can be read at once equals the size (in bytes) of the largest integer type, supported by the system.
Float readFloat(FType ft)
Reads a floating-point number from the stream and returns it. Takes the floating-point format to read as the argument ft. Refer to the list of public types of the binio class for information about what floating-point formats are supported. The return value is undefined if an error occured. The value from the stream is always rendered to the biggest floating-point type, supported by the system.

If your architecture is incompatible with the floating-point number that has just been read, readFloat() tries to convert it. This is sometimes not possible or not as accurate as the original value and an error will be issued in these cases. Refer to the list of public types of the binio class for information about what errors could be issued.

unsigned long readString(char *str, unsigned long maxlen, char delim)
std::string readString(char delim = '\0')
Reads a character string from the stream. Both pre-allocated standard C ASCIIZ strings and STL string objects are supported.

The ASCIIZ version takes a pointer to the pre-allocated string buffer as the str argument. maxlen specifies the maximum number of characters to be read from the stream (not including the trailing \0 that is always appended to the string buffer). The optional argument delim is a delimiter character. If this character is encountered in the stream, no more characters will be read. The delimiter character itself is discarded. It will not appear in the final string. If the delim argument is omitted, always up to maxlen characters are read.

The string object version just takes one optional argument, the delimiter character, explained above. Characters are always read until the delimiter character or the end of the stream is encountered. If delim is omitted, it defaults to \0. It returns a string object, containing the final string.

Int peekInt(unsigned int size)
Like readInt(), but doesn't modify the stream position, so any later access to the stream will appear as if peekInt() has never been called.
Float peekFloat(FType ft)
Like readFloat(), but doesn't modify the stream position, so any later access to the stream will appear as if peekFloat() has never been called.
bool ateof()
Returns true if the current stream position is at the last byte of the stream. false is returned otherwise.
void ignore(unsigned long amount = 1)
Reads and then immediately discards the specified amount of bytes from the stream. If the optional argument amount is omitted, it defaults to 1, ignoring exactly 1 byte from the stream.

Protected methods:

virtual Byte getByte()
Abstract virtual method to extract exactly one byte (8 bits) from the stream and advance stream pointer accordingly. The byte is returned. Implemented by the stream layer.