#include <Stream.h>
Public Member Functions | |
virtual | ~Stream () |
virtual bool | canRead ()=0 |
virtual bool | canWrite ()=0 |
virtual bool | canSeek ()=0 |
virtual void | close ()=0 |
virtual size_t | read (void *ptr, size_t size, size_t count)=0 |
virtual char * | readLine (char *str, int num)=0 |
virtual size_t | write (const void *ptr, size_t size, size_t count)=0 |
virtual bool | eof ()=0 |
virtual size_t | length ()=0 |
virtual long int | position ()=0 |
virtual bool | seek (long int offset, int origin)=0 |
virtual bool | rewind ()=0 |
Defines a stream for reading and writing a sequence of bytes.
Use FileSystem::open() to create a stream.
virtual gameplay::Stream::~Stream | ( | ) | [inline, virtual] |
Destructor. The stream should be closed when it is destroyed.
virtual bool gameplay::Stream::canRead | ( | ) | [pure virtual] |
Returns true if this stream can perform read operations.
virtual bool gameplay::Stream::canSeek | ( | ) | [pure virtual] |
Returns true if this stream can seek.
virtual bool gameplay::Stream::canWrite | ( | ) | [pure virtual] |
Returns true if this stream can perform write operations.
virtual void gameplay::Stream::close | ( | ) | [pure virtual] |
Closes this stream.
virtual bool gameplay::Stream::eof | ( | ) | [pure virtual] |
Returns true if the end of the stream has been reached.
virtual size_t gameplay::Stream::length | ( | ) | [pure virtual] |
Returns the length of the stream in bytes.
Zero is returned if the length of the stream is unknown and/or it cannot be seeked.
Example: The length of a network stream is unknown and cannot be seeked.
virtual long int gameplay::Stream::position | ( | ) | [pure virtual] |
Returns the position of the file pointer. Zero is the start of the stream.
virtual size_t gameplay::Stream::read | ( | void * | ptr, |
size_t | size, | ||
size_t | count | ||
) | [pure virtual] |
Reads an array of count
elements, each of size size
.
int numbers[3]; if (stream->read(numbers, sizeof(int), 3) != 3) print("Error reading from file");
ptr | The pointer to the memory to copy into. The available size should be at least (size * count ) bytes. |
size | The size of each element to be read, in bytes. |
count | The number of elements to read. |
virtual char* gameplay::Stream::readLine | ( | char * | str, |
int | num | ||
) | [pure virtual] |
Reads a line from the stream.
A new line is denoted by by either "\n", "\r" or "\r\n". The line break character is included in the string. The terminating null character is added to the end of the string.
str | The array of chars to copy the string to. |
num | The maximum number of characters to be copied. |
virtual bool gameplay::Stream::rewind | ( | ) | [pure virtual] |
virtual bool gameplay::Stream::seek | ( | long int | offset, |
int | origin | ||
) | [pure virtual] |
Sets the position of the file pointer.
Use canSeek() to determine if this method is supported.
offset | The number of bytes to offset from origin. |
origin | The position used as a reference for offset. The supported values are the same as fseek().
|
virtual size_t gameplay::Stream::write | ( | const void * | ptr, |
size_t | size, | ||
size_t | count | ||
) | [pure virtual] |
Writes an array of count
elements, each of size size
.
int numbers[] = {1, 2, 3}; if (stream->write(numbers, sizeof(int), 3) != 3) print("Error writing to file");
ptr | The pointer to the array of elements to be written. |
size | The size of each element to be written, in bytes. |
count | The number of elements to write. |