SFML 3.0.2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
sf::MemoryInputStream Class Reference
System module

Implementation of input stream based on a memory chunk. More...

`#include <SFML/System/MemoryInputStream.hpp>`

Inheritance diagram for sf::MemoryInputStream:

## Public Member Functions
| MemoryInputStream (const void *data, std::size_t sizeInBytes)
| Construct the stream from its data.
std::optional< std::size_t > | read (void *data, std::size_t size) override
| Read data from the stream.
std::optional< std::size_t > | seek (std::size_t position) override
| Change the current reading position.
std::optional< std::size_t > | tell () override
| Get the current reading position in the stream.
std::optional< std::size_t > | getSize () override
| Return the size of the stream.

## Detailed Description

Implementation of input stream based on a memory chunk.

This class is a specialization of InputStream that reads from data in memory.

It wraps a memory chunk in the common InputStream interface and therefore allows to use generic classes or functions that accept such a stream, with content already loaded in memory.

In addition to the virtual functions inherited from InputStream, MemoryInputStream adds a function to specify the pointer and size of the data in memory.

SFML resource classes can usually be loaded directly from memory, so this class shouldn't be useful to you unless you create your own algorithms that operate on an InputStream.

Usage example:

void process(InputStream& stream);
MemoryInputStream stream(thePtr, theSize);
process(stream);
sf::InputStream
Abstract class for custom file input streams.
Definition InputStream.hpp:46
sf::MemoryInputStream::MemoryInputStream
MemoryInputStream(const void *data, std::size_t sizeInBytes)
Construct the stream from its data.

See also
  InputStream, FileInputStream

Definition at line 46 of file MemoryInputStream.hpp.

## Constructor & Destructor Documentation

## ◆ MemoryInputStream()

sf::MemoryInputStream::MemoryInputStream | ( | const void * | data,
|  | std::size_t | sizeInBytes )

Construct the stream from its data.

Parameters

  data | Pointer to the data in memory
  sizeInBytes | Size of the data, in bytes

## Member Function Documentation

## ◆ getSize()

std::optional< std::size_t > sf::MemoryInputStream::getSize | ( |  | ) |
| override virtual

Return the size of the stream.

Returns
  The total number of bytes available in the stream, or std::nullopt on error

Implements sf::InputStream.

## ◆ read()

std::optional< std::size_t > sf::MemoryInputStream::read | ( | void * | data,
|  | std::size_t | size )
| nodiscard override virtual

Read data from the stream.

After reading, the stream's reading position must be advanced by the amount of bytes read.

Parameters

  data | Buffer where to copy the read data
  size | Desired number of bytes to read

Returns
  The number of bytes actually read, or std::nullopt on error

Implements sf::InputStream.

## ◆ seek()

std::optional< std::size_t > sf::MemoryInputStream::seek | ( | std::size_t | position | ) |
| nodiscard override virtual

Change the current reading position.

Parameters

  position | The position to seek to, from the beginning

Returns
  The position actually sought to, or std::nullopt on error

Implements sf::InputStream.

## ◆ tell()

std::optional< std::size_t > sf::MemoryInputStream::tell | ( |  | ) |
| nodiscard override virtual

Get the current reading position in the stream.

Returns
  The current position, or std::nullopt on error.

Implements sf::InputStream.

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

- MemoryInputStream.hpp