Stream Class
This class cannot be instantiated. It is a base class for:
Stream class allows you to write data into a stream, that is into files (stored on the disk), blobs (stored in system memory) and sockets (to be sent over the network), as well as read data from a stream.
Stream Class
Members
int isAvailable()
Returns the status of the stream.Return value
Returns 1 if stream data is available; otherwise, 0.void setByteOrder(int order)
Sets the endianess of the stream.Arguments
- int order - A value indicating the endianess of the stream: 0 value is for LSB (least significant), 1 is for MSB (most significant).
int getByteOrder()
Returns the value indicating the endianess of the stream.Return value
A value indicating the endianess of the stream: 0 value is for LSB (least significant), 1 is for MSB (most significant).int isError()
Checks whether the stream has a read/write error.Return value
1 if the stream is opened; otherwise, 0.int isOpened()
Checks whether the stream is opened.Return value
1 if there is a read/write error; otherwise, 0.Variable gets()
Reads the stream data from the current position.Return value
Stream data starting from the current position.Stream getStream()
Returns a smart pointer to the stream.Return value
Stream instance.int getType()
Return the type of the stream.Return value
A value indicating the type of the stream.Variable puts(string str)
Writes a non-binary string of characters to the stream.Arguments
- string str - String to write.
Return value
1 if a string of characters is written successfully; otherwise, 0.int read(void * ptr, int size)
Reads unsigned char data in a binary format from the stream into a vector.Arguments
- void * ptr - Vector, into which data will be read.
- int size - Size of data to read.
Return value
1 if data is read successfully; otherwise, 0.dmat4 readDMat4()
Reads dmat4 (a matrix of double values, 8*12 bytes) in a binary format from the stream.Return value
Received matrix.double readDouble()
Reads a double in a binary format (8 bytes) from the stream.Return value
Received double.dvec2 readDVec2()
Reads a 2 component double vector from the stream in accordance with the little-endian order.Return value
Vector value.dvec3 readDVec3()
Reads a dvec3 in a binary format (8*3 bytes) from the stream.Return value
Received dvec3.dvec4 readDVec4()
Reads a dvec4 in a binary format (8*4 bytes) from the stream.Return value
Received dvec4.float readFloat()
Reads a float in a binary format (4 bytes) from the stream.Return value
Received floatint readInt()
Reads an integer in a binary format (4 bytes) from the stream.Return value
Received integer.int readInt2()
Reads a compact signed integer in a binary format from the stream.Return value
Received number.ivec2 readIVec2()
Reads a 2 component integer vector from the stream in accordance with the little-endian order.Return value
Vector value.ivec3 readIVec3()
Reads an ivec3 in a binary format (4*3 bytes) from the stream.Return value
Received ivec3.ivec4 readIVec4()
Reads an ivec4 in a binary format (4*4 bytes) from the stream.Return value
Received ivec4.Variable readLine()
Reads a line of non-binary characters from the stream: starting from the current position until the end of line is reached ("\n"). The maximum length of the line is 4096 bytes.Return value
Received line.long readLong()
Reads a long integer in a binary format (8 bytes) from the stream.Return value
Received long integer.mat4 readMat4()
Reads a mat4 (a matrix in a binary format, 4*16 bytes) from the stream.Return value
Received matrix.mat4 readMat44()
Reads the first 12 elements of 4x4 matrix from the current stream. The last 4 elements of the matrix are discarded.Return value
4x4 matrix with 12 read elements (the last four elements are equal to 0 0 0 1).quat readQuat()
Reads a quaternion in a binary format (4*4 bytes) from the stream.Return value
Received quaternion.short readShort()
Reads a short integer in a binary format (2 bytes) from the stream.Return value
Received short integer.int readStream(Stream dest, int size)
Reads the number of bytes from the current stream and writes data directly into the specified stream.Arguments
- Stream dest - Stream to write data into.
- int size - Size of data to be read from the current stream.
Return value
1 if both streams are opened and data is successfully written; otherwise, 0.Variable readString()
Reads a compact string in a binary format from the stream. Each binary string should be preceded by its length (the string length + the string itself). The string length is written as the compact signed integer.Return value
Received string.Variable readToken()
Reads a token from the stream. A token is a single word delimited by white space or a string in quotes, for example, "word" or "many words". A token is read starting from the current position up to the white space or line feed ("\n"), or if the first character is a double quote mark (") up to the second double quote mark (returned token will not contain any quotes). The maximum length of the string is 4096 bytes.Return value
Received token.int readUChar()
Reads an unsigned character in a binary format from the stream.Return value
Unsigned character in a binary format.unsigned int readUInt()
Reads a unsigned integer from the stream in accordance with the little-endian order.Return value
Data value.unsigned int readUInt2()
Reads a compact unsigned integer from the stream.Return value
Data value.int readUShort()
Reads an unsigned short integer from the stream.Return value
Received unsigned short integer.vec2 readVec2()
Reads a 2 component vector from the stream in accordance with the little-endian order.Return value
Vector value.vec3 readVec3()
Reads a vec3 in a binary format (4*3 bytes) from the stream.Return value
Received vec3.vec4 readVec4()
Reads a vec4 in a binary format (4*4 bytes) from the stream.Return value
Received vec4.int write(const void * ptr, int size)
Writes contents of a vector into the stream as unsigned char data in a binary format.Arguments
- const void * ptr - Buffer, from which data will be written.
- int size - Size of data to write.
Return value
1 if data is sent successfully; otherwise, 0.int writeChar(int value)
Writes an ASCII character in a binary format (1 byte) to the stream.Arguments
- int value - ASCII code of a character to write.
Return value
1 if a character is written successfully; otherwise 0.int writeDMat4(dmat4 value)
Writes a dmat4 (a matrix of double values, 8*12 bytes) to the stream.Arguments
- dmat4 value - A matrix to write.
Return value
1 if a matrix is written successfully; otherwise, 0.int writeDouble(double value)
Writes a double (8 bytes) in a binary format to the stream.Arguments
- double value - A double value to write.
Return value
1 if data is written successfully; otherwise, 0.int writeDVec2(dvec2 value)
Writes a 2 component double vector to the stream in accordance with the little-endian order.Arguments
- dvec2 value - Vector value.
Return value
1 if the operation was successful; otherwise, 0.int writeDVec3(dvec3 value)
Writes a dvec3 in a binary format (8*3 bytes) to the stream.Arguments
- dvec3 value - A dvec3 value to write.
Return value
1 if a vector is written successfully; otherwise, 0.int writeDVec4(dvec4 value)
Writes a dvec4 in a binary format (8*4 bytes) to the stream.Arguments
- dvec4 value - A dvec4 value to write.
Return value
1 if a vector is written successfully; otherwise, 0.int writeFloat(float value)
Writes a float (4 bytes) in a binary format to the stream.Arguments
- float value - A float value to write.
Return value
1 if data is written successfully; otherwise, 0.int writeInt(int value)
Writes an integer (4 bytes) in a binary format to the stream.Arguments
- int value - An integer value to write.
Return value
1 if data is written successfully; otherwise, 0.int writeInt2(int value)
Writes a compact signed integer in a binary format to the stream.Arguments
- int value - A compact signed integer to write.
Return value
1 if the compact integer is written successfully; otherwise, 0.int writeIVec2(ivec2 value)
Writes a 2 component integer vector to the stream in accordance with the little-endian order.Arguments
- ivec2 value - Vector value.
Return value
1 if the operation was successful; otherwise, 0.int writeIVec3(ivec3 value)
Writes a ivec3 in a binary format (4*3 bytes) to the stream.Arguments
- ivec3 value - An ivec3 value to write.
Return value
1 if a vector is written successfully; otherwise, 0.int writeIVec4(ivec4 value)
Writes an ivec4 in a binary format (4*4 bytes) to the stream.Arguments
- ivec4 value - An ivec4 to write.
Return value
1 if a vector is written successfully; otherwise, 0.int writeLong(long value)
Writes a long integer (8 bytes) in a binary format to the stream.Arguments
- long value - A long value to write.
Return value
1 if data is written successfully; otherwise, 0.int writeMat4(mat4 value)
Writes a mat4 (a matrix of float values, 4*16 bytes) to the stream.Arguments
- mat4 value - A matrix to write.
Return value
1 if a matrix is written successfully; otherwise, 0.int writeMat44(mat4 value)
Writes the first 12 elements of 4x4 matrix in a binary format into the current stream. The last 4 elements of the matrix are discarded.Arguments
- mat4 value - A 4x4 matrix.
Return value
1 if data is written successfully; otherwise, 0.int writeQuat(quat value)
Writes a quaternion in a binary format (4*4 bytes) to the stream.Arguments
- quat value - A quaternion to write.
Return value
1 if a quaternion is written successfully; otherwise, 0.int writeShort(short value)
Writes a short integer in a binary format (2 bytes) to the stream.Arguments
- short value - A short integer value to write.
Return value
1 if data is written successfully; otherwise, 0.int writeStream(Stream src, int size)
Reads the number of bytes from the given stream and writes data directly into the current one.Arguments
- Stream src - Stream to read data from.
- int size - Size of data to be read from the stream.
Return value
1 if both streams are opened and data is successfully written; otherwise, 0.Variable writeString(string str)
Writes a string in a binary format to the stream. Each binary string should be preceded by its length (4 bytes defining the length of string + the string itself).Arguments
- string str - String to write.
Return value
1 if the string is written successfully; otherwise, 0.Variable writeString2(string str)
Writes a compact string in a binary format to the stream. Each binary string should be preceded by its length (the string length + the string itself). The string length is written as the compact signed integer.Arguments
- string str - String to write.
Return value
1 if the string is written successfully; otherwise, 0.writeUChar(int value)
Writes an unsigned character to the stream.Arguments
- int value - Unsigned character to write.
Return value
1 if the unsigned character is written successfully; otherwise, 0.int writeUInt(unsigned int value)
Writes a unsigned integer to the stream in accordance with the little-endian order.Arguments
- unsigned int value - Data value.
Return value
1 if the operation was successful; otherwise, 0.int writeUInt2(unsigned int value)
Writes a compact unsigned integer to the stream.Arguments
- unsigned int value - Data value.
int writeUShort(int value)
Writes a unsigned short integer to the stream.Arguments
- int value - Unsigned short integer to write.
Return value
1 if the unsigned short integer is written successfully; otherwise, 0.int writeVec2(vec2 value)
Writes a 2 component vector to the stream in accordance with the little-endian order.Arguments
- vec2 value - Vector value.
Return value
1 if the operation was successful; otherwise, 0.int writeVec3(vec3 value)
Writes a vec3 in a binary format (4*3 bytes) to the stream.Arguments
- vec3 value - A vec3 to write.
Return value
1 if a vector is written successfully; otherwise, 0.int writeVec4(vec4 value)
Writes a vec4 in a binary format (4*4 bytes) to the stream.Arguments
- vec4 value - A vec4 to write.
Return value
1 if a vector is written successfully; otherwise, 0.int STREAM_BLOB
Description
A stream for blobs.int STREAM_FILE
Description
A stream for files.int STREAM_NUM_TYPES
Description
A number of stream types.int STREAM_SOCKET
Description
A stream for sockets.int STREAM_USER
Description
A user stream inherited from StreamBase.Last update: 2018-08-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)