|  | overview |  | wiki |  | api reference |  | download

- Main Page
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Functions Variables Typedefs Enumerations Enumerator
Public Member Functions
gameplay::Stream Class Reference

`#include <Stream.h>`

List of all members.

## 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

## Detailed Description

Defines a stream for reading and writing a sequence of bytes.

Use FileSystem::open() to create a stream.

## Constructor & Destructor Documentation

virtual gameplay::Stream::~Stream | ( |  | ) | `[inline, virtual]`

Destructor. The stream should be closed when it is destroyed.

## Member Function Documentation

virtual bool gameplay::Stream::canRead | ( |  | ) | `[pure virtual]`

Returns true if this stream can perform read operations.

Returns:
  True if the stream can read, false otherwise.

virtual bool gameplay::Stream::canSeek | ( |  | ) | `[pure virtual]`

Returns true if this stream can seek.

Returns:
  True if the stream can seek, false otherwise.

virtual bool gameplay::Stream::canWrite | ( |  | ) | `[pure virtual]`

Returns true if this stream can perform write operations.

Returns:
  True if the stream can write, false otherwise.

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.

Returns:
  True if end of stream reached, false otherwise.

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.

Returns:
  The length of the stream in bytes.

virtual long int gameplay::Stream::position | ( |  | ) | `[pure virtual]`

Returns the position of the file pointer. Zero is the start of the stream.

Returns:
  The file indicator offset in bytes.

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");

Parameters:

  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.

Returns:
  The number of elements read.

See also:
  canRead()

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.

Parameters:

  str | The array of chars to copy the string to.
  num | The maximum number of characters to be copied.

Returns:
  On success, str is returned. On error, NULL is returned.

See also:
  canRead()

virtual bool gameplay::Stream::rewind | ( |  | ) | `[pure virtual]`

Moves the file pointer to the start of the file.

Use canSeek() to determine if this method is supported.

Returns:
  True if successful, false otherwise.

See also:
  canSeek()

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.

Parameters:

  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().
  - `SEEK_SET` relative to the beginning of the file.
  - `SEEK_CUR` relative to the current position of the file pointer.
  - `SEEK_END` relative to the end of file.

Returns:
  True if successful, false otherwise.

See also:
  canSeek()

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");

Parameters:

  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.

Returns:
  The number of elements written.

See also:
  canWrite()

All Classes Functions Variables Typedefs Enumerations Enumerator