| OGRE 1.11.1 Object-Oriented Graphics Rendering Engine

Public Types | Public Member Functions | List of all members
Ogre::MemoryDataStream Class Reference
Core » Resources

Common subclass of DataStream for handling data from chunks of memory. More...

`#include <OgreDataStream.h>`

Inheritance diagram for Ogre::MemoryDataStream:
[legend]

## Public Types
enum | AccessMode { READ = 1, WRITE = 2 }

## Public Member Functions
| MemoryDataStream (void *pMem, size_t size, bool freeOnClose=false, bool readOnly=false)
| Wrap an existing memory chunk in a stream. More...
| MemoryDataStream (const String &name, void *pMem, size_t size, bool freeOnClose=false, bool readOnly=false)
| Wrap an existing memory chunk in a named stream. More...
| MemoryDataStream (DataStream &sourceStream, bool freeOnClose=true, bool readOnly=false)
| Create a stream which pre-buffers the contents of another stream. More...
| MemoryDataStream (const DataStreamPtr &sourceStream, bool freeOnClose=true, bool readOnly=false)
| Create a stream which pre-buffers the contents of another stream. More...
| MemoryDataStream (const String &name, DataStream &sourceStream, bool freeOnClose=true, bool readOnly=false)
| Create a named stream which pre-buffers the contents of another stream. More...
| MemoryDataStream (const String &name, const DataStreamPtr &sourceStream, bool freeOnClose=true, bool readOnly=false)
| Create a named stream which pre-buffers the contents of another stream. More...
| MemoryDataStream (size_t size, bool freeOnClose=true, bool readOnly=false)
| Create a stream with a brand new empty memory chunk. More...
| MemoryDataStream (const String &name, size_t size, bool freeOnClose=true, bool readOnly=false)
| Create a named stream with a brand new empty memory chunk. More...
| ~MemoryDataStream ()
void | close (void)
| Close the stream; this makes further operations invalid. More...
bool | eof (void) const
| Returns true if the stream has reached the end. More...
uint16 | getAccessMode () const
| Gets the access mode of the stream. More...
virtual String | getAsString (void)
| Returns a String containing the entire stream. More...
uchar * | getCurrentPtr (void)
| Get a pointer to the current position in the memory block this stream holds. More...
virtual String | getLine (bool trimAfter=true)
| Returns a String containing the next line of data, optionally trimmed for whitespace. More...
const String & | getName (void)
| Returns the name of the stream, if it has one. More...
uchar * | getPtr (void)
| Get a pointer to the start of the memory block this stream holds. More...
virtual bool | isReadable () const
| Reports whether this stream is readable. More...
virtual bool | isWriteable () const
| Reports whether this stream is writeable. More...
template<typename T >
DataStream & | operator>> (T &val)
size_t | read (void *buf, size_t count)
| Read the requisite number of bytes from the stream, stopping at the end of the file. More...
size_t | readLine (char *buf, size_t maxCount, const String &delim="\)
| Get a single line from the stream. More...
void | seek (size_t pos)
| Repositions the read point to a specified byte. More...
void | setFreeOnClose (bool free)
| Sets whether or not to free the encapsulated memory on close. More...
size_t | size (void) const
| Returns the total size of the data to be read from the stream, or 0 if this is indeterminate for this stream. More...
void | skip (long count)
| Skip a defined number of bytes. More...
size_t | skipLine (const String &delim="\)
| Skip a single line from the stream. More...
size_t | tell (void) const
| Returns the current byte offset from beginning. More...
size_t | write (const void *buf, size_t count)
| Write the requisite number of bytes from the stream (only applicable to streams that are not read-only) More...

## Detailed Description

Common subclass of DataStream for handling data from chunks of memory.

## Member Enumeration Documentation

## ◆ AccessMode

enum Ogre::DataStream::AccessMode
| inherited

Enumerator
READ |
WRITE |

## Constructor & Destructor Documentation

## ◆ MemoryDataStream() [1/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | void * | pMem,
|  | size_t | size,
|  | bool | freeOnClose = `false`,
|  | bool | readOnly = `false`
| ) |  |

Wrap an existing memory chunk in a stream.

Parameters

  pMem | Pointer to the existing memory
  size | The size of the memory chunk in bytes
  freeOnClose | If true, the memory associated will be destroyed when the stream is closed. Note: it's important that if you set this option to true, that you allocated the memory using OGRE_ALLOC_T with a category of MEMCATEGORY_GENERAL to ensure the freeing of memory matches up.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ MemoryDataStream() [2/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | const String & | name,
|  | void * | pMem,
|  | size_t | size,
|  | bool | freeOnClose = `false`,
|  | bool | readOnly = `false`
| ) |  |

Wrap an existing memory chunk in a named stream.

Parameters

  name | The name to give the stream
  pMem | Pointer to the existing memory
  size | The size of the memory chunk in bytes
  freeOnClose | If true, the memory associated will be destroyed when the stream is destroyed. Note: it's important that if you set this option to true, that you allocated the memory using OGRE_ALLOC_T with a category of MEMCATEGORY_GENERAL ensure the freeing of memory matches up.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ MemoryDataStream() [3/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | DataStream & | sourceStream,
|  | bool | freeOnClose = `true`,
|  | bool | readOnly = `false`
| ) |  |

Create a stream which pre-buffers the contents of another stream.

Remarks
  This constructor can be used to intentionally read in the entire contents of another stream, copying them to the internal buffer and thus making them available in memory as a single unit.

Parameters

  sourceStream | Another DataStream which will provide the source of data
  freeOnClose | If true, the memory associated will be destroyed when the stream is destroyed.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ MemoryDataStream() [4/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | const DataStreamPtr & | sourceStream,
|  | bool | freeOnClose = `true`,
|  | bool | readOnly = `false`
| ) |  |

Create a stream which pre-buffers the contents of another stream.

Remarks
  This constructor can be used to intentionally read in the entire contents of another stream, copying them to the internal buffer and thus making them available in memory as a single unit.

Parameters

  sourceStream | Another DataStream which will provide the source of data
  freeOnClose | If true, the memory associated will be destroyed when the stream is destroyed.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ MemoryDataStream() [5/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | const String & | name,
|  | DataStream & | sourceStream,
|  | bool | freeOnClose = `true`,
|  | bool | readOnly = `false`
| ) |  |

Create a named stream which pre-buffers the contents of another stream.

Remarks
  This constructor can be used to intentionally read in the entire contents of another stream, copying them to the internal buffer and thus making them available in memory as a single unit.

Parameters

  name | The name to give the stream
  sourceStream | Another DataStream which will provide the source of data
  freeOnClose | If true, the memory associated will be destroyed when the stream is destroyed.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ MemoryDataStream() [6/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | const String & | name,
|  | const DataStreamPtr & | sourceStream,
|  | bool | freeOnClose = `true`,
|  | bool | readOnly = `false`
| ) |  |

Create a named stream which pre-buffers the contents of another stream.

Remarks
  This constructor can be used to intentionally read in the entire contents of another stream, copying them to the internal buffer and thus making them available in memory as a single unit.

Parameters

  name | The name to give the stream
  sourceStream | Another DataStream which will provide the source of data
  freeOnClose | If true, the memory associated will be destroyed when the stream is destroyed.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ MemoryDataStream() [7/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | size_t | size,
|  | bool | freeOnClose = `true`,
|  | bool | readOnly = `false`
| ) |  |

Create a stream with a brand new empty memory chunk.

Parameters

  size | The size of the memory chunk to create in bytes
  freeOnClose | If true, the memory associated will be destroyed when the stream is destroyed.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ MemoryDataStream() [8/8]

Ogre::MemoryDataStream::MemoryDataStream | ( | const String & | name,
|  | size_t | size,
|  | bool | freeOnClose = `true`,
|  | bool | readOnly = `false`
| ) |  |

Create a named stream with a brand new empty memory chunk.

Parameters

  name | The name to give the stream
  size | The size of the memory chunk to create in bytes
  freeOnClose | If true, the memory associated will be destroyed when the stream is destroyed.
  readOnly | Whether to make the stream on this memory read-only once created

## ◆ ~MemoryDataStream()

Ogre::MemoryDataStream::~MemoryDataStream | ( |  | ) |

## Member Function Documentation

## ◆ getPtr()

uchar* Ogre::MemoryDataStream::getPtr | ( | void |  | ) |
| inline

Get a pointer to the start of the memory block this stream holds.

## ◆ getCurrentPtr()

uchar* Ogre::MemoryDataStream::getCurrentPtr | ( | void |  | ) |
| inline

Get a pointer to the current position in the memory block this stream holds.

## ◆ read()

size_t Ogre::MemoryDataStream::read | ( | void * | buf,
|  | size_t | count
| ) |  |
| virtual

Read the requisite number of bytes from the stream, stopping at the end of the file.

Parameters

  buf | Reference to a buffer pointer
  count | Number of bytes to read

Returns
  The number of bytes read

Implements Ogre::DataStream.

## ◆ write()

size_t Ogre::MemoryDataStream::write | ( | const void * | buf,
|  | size_t | count
| ) |  |
| virtual

Write the requisite number of bytes from the stream (only applicable to streams that are not read-only)

Parameters

  buf | Pointer to a buffer containing the bytes to write
  count | Number of bytes to write

Returns
  The number of bytes written

Reimplemented from Ogre::DataStream.

## ◆ readLine()

size_t Ogre::MemoryDataStream::readLine | ( | char * | buf,
|  | size_t | maxCount
| ) |  |
| virtual

Get a single line from the stream.

Remarks
  The delimiter character is not included in the data returned, and it is skipped over so the next read will occur after it. The buffer contents will include a terminating character.

Note
  If you used this function, you must open the stream in binary mode, otherwise, it'll produce unexpected results.

Parameters

  buf | Reference to a buffer pointer
  maxCount | The maximum length of data to be read, excluding the terminating character
  delim | The delimiter to stop at

Returns
  The number of bytes read, excluding the terminating character

Reimplemented from Ogre::DataStream.

## ◆ skipLine()

size_t Ogre::MemoryDataStream::skipLine | ( |  | ) |
| virtual

Skip a single line from the stream.

Note
  If you used this function, you must open the stream in binary mode, otherwise, it'll produce unexpected results.

Parameters

  delim | The delimiter(s) to stop at

Returns
  The number of bytes skipped

Reimplemented from Ogre::DataStream.

## ◆ skip()

void Ogre::MemoryDataStream::skip | ( | long | count | ) |
| virtual

Skip a defined number of bytes.

This can also be a negative value, in which case the file pointer rewinds a defined number of bytes.

Implements Ogre::DataStream.

## ◆ seek()

void Ogre::MemoryDataStream::seek | ( | size_t | pos | ) |
| virtual

Repositions the read point to a specified byte.

Implements Ogre::DataStream.

## ◆ tell()

size_t Ogre::MemoryDataStream::tell | ( | void |  | ) | const
| virtual

Returns the current byte offset from beginning.

Implements Ogre::DataStream.

## ◆ eof()

bool Ogre::MemoryDataStream::eof | ( | void |  | ) | const
| virtual

Returns true if the stream has reached the end.

Implements Ogre::DataStream.

## ◆ close()

void Ogre::MemoryDataStream::close | ( | void |  | ) |
| virtual

Close the stream; this makes further operations invalid.

Implements Ogre::DataStream.

## ◆ setFreeOnClose()

void Ogre::MemoryDataStream::setFreeOnClose | ( | bool | free | ) |
| inline

Sets whether or not to free the encapsulated memory on close.

## ◆ getName()

const String& Ogre::DataStream::getName | ( | void |  | ) |
| inline inherited

Returns the name of the stream, if it has one.

## ◆ getAccessMode()

uint16 Ogre::DataStream::getAccessMode | ( |  | ) | const
| inline inherited

Gets the access mode of the stream.

## ◆ isReadable()

virtual bool Ogre::DataStream::isReadable | ( |  | ) | const
| inline virtual inherited

Reports whether this stream is readable.

## ◆ isWriteable()

virtual bool Ogre::DataStream::isWriteable | ( |  | ) | const
| inline virtual inherited

Reports whether this stream is writeable.

## ◆ operator>>()

template<typename T >

DataStream& Ogre::DataStream::operator>> | ( | T & | val | ) |
| inherited

## ◆ getLine()

virtual String Ogre::DataStream::getLine | ( | bool | trimAfter = `true` | ) |
| virtual inherited

Returns a String containing the next line of data, optionally trimmed for whitespace.

Remarks
  This is a convenience method for text streams only, allowing you to retrieve a String object containing the next line of data. The data is read up to the next newline character and the result trimmed if required.

Note
  If you used this function, you must open the stream in binary mode, otherwise, it'll produce unexpected results.

Parameters

  trimAfter | If true, the line is trimmed for whitespace (as in String.trim(true,true))

## ◆ getAsString()

virtual String Ogre::DataStream::getAsString | ( | void |  | ) |
| virtual inherited

Returns a String containing the entire stream.

Remarks
  This is a convenience method for text streams only, allowing you to retrieve a String object containing all the data in the stream.

## ◆ size()

size_t Ogre::DataStream::size | ( | void |  | ) | const
| inline inherited

Returns the total size of the data to be read from the stream, or 0 if this is indeterminate for this stream.

The documentation for this class was generated from the following file:

- OgreDataStream.h