|
CeresEngine 0.2.0
A game development framework
|
A data stream that reads or writes data into a memory buffer. More...
#include <CeresEngine/Foundation/IO/Stream.hpp>
Public Member Functions | |
| MemoryDataStream () | |
| Allocates a new empty memory data stream. | |
| MemoryDataStream (size_t size) | |
| Allocates a new chunk of memory and wraps it in a stream. | |
| MemoryDataStream (Byte *memory, size_t size, bool freeOnClose=false) | |
| Wrap an existing memory chunk in a stream. | |
| MemoryDataStream (const ByteMemoryView &buffer, bool freeOnClose=false) | |
| Wrap an existing memory chunk in a stream. | |
| MemoryDataStream (DataStream &stream) | |
| Copies all contents of the existing data stream into a memory stream. | |
| MemoryDataStream (const MemoryDataStream &) | |
| MemoryDataStream (MemoryDataStream &&) noexcept | |
| ~MemoryDataStream () final | |
| MemoryView< const Byte > | getData () const |
| Gets a view to the underlying memory data. | |
| MemoryView< Byte > | getData () |
| Gets a view to the underlying memory data. | |
| bool | isGrowable () const |
| Determines if write or seek calls can grow the underlying memory buffer. | |
| bool | isSeekable (const Seek mode=Seek::Start) const noexcept final |
| Checks if the stream is seekable. | |
| void | seek (std::streamsize position, Seek mode=Seek::Start) final |
| Changes the position of the data stream. | |
| bool | isTellable () const noexcept final |
| Checks if the stream knows it's current absolute position. | |
| size_t | tell () final |
| Gets the absolute stream position, in bytes. | |
| bool | isSizeKnown () const noexcept final |
| Checks if the stream knows the size of the data. | |
| size_t | size () final |
| Gets the number of bytes available on the stream. | |
| bool | isReadable () const noexcept final |
| Checks if the stream is readable. | |
| size_t | read (void *data, size_t n) final |
Reads data from the data stream to a buffer of raw memory data with length n. | |
| bool | isWritable () const noexcept final |
| Checks if the stream is writable. | |
| size_t | write (const void *data, size_t n) final |
Writes data to the data stream from a buffer of raw memory data with length n. | |
Public Member Functions inherited from CeresEngine::IInputStream | |
| template<typename T > | |
| size_t | read (const MemoryView< T > &memoryView) |
| Reads data from the strea into a memory view. | |
| template<typename T > | |
| size_t | read (const StridedMemoryView< T > &memoryView) |
| Reads data from the stream into a strided memory view. | |
| Optional< String > | readString () |
Reads data from the buffer as a C++ String. | |
| template<typename T > requires std::is_trivially_copyable_v<T> | |
| Optional< T > | read () |
| Reads a trivially copyable obhect from the stream. | |
| virtual bool | invalidate () |
| In the stream is buffered, invalidates any buffered read data from the stream. | |
Public Member Functions inherited from CeresEngine::IStream | |
| IStream ()=default | |
| IStream (const IStream &) noexcept=delete | |
| IStream & | operator= (const IStream &) noexcept=delete |
| IStream (IStream &&) noexcept=default | |
| IStream & | operator= (IStream &&) noexcept=default |
| virtual | ~IStream () noexcept=default |
| void | skip (const size_t n) |
Skips n bytes from the data stream. | |
Public Member Functions inherited from CeresEngine::IOutputStream | |
| template<typename T > | |
| size_t | write (const MemoryView< const T > &memoryView) |
| Writes data from a memory view to the stream. | |
| template<typename T > | |
| size_t | write (const StridedMemoryView< const T > &memoryView) |
| Writes data from a strided memory view to the stream. | |
| size_t | writeString (const StringView string) |
| Writes a string to the data stream. | |
| template<typename T > requires std::is_trivially_copyable_v<T> | |
| bool | write (T value) |
| Writes a trivially copyable object to the stream. | |
| virtual bool | flush () |
| In the stream is buffered, invalidates any buffered write data from to stream. | |
Private Member Functions | |
| bool | growIfNeeded (std::size_t desiredSize) |
| Grows the memory stream if needed. | |
Private Attributes | |
| ByteMemoryView | mBuffer |
| std::size_t | mSize = 0 |
| std::size_t | mPosition = 0 |
| bool | mOwnsBuffer = true |
Additional Inherited Members | |
Public Types inherited from CeresEngine::IStream | |
| enum class | Seek { Start = SEEK_SET , Current = SEEK_CUR , End = SEEK_END } |
| An enumeration that describes how a data stream should be seeked. More... | |
A data stream that reads or writes data into a memory buffer.
|
explicit |
Allocates a new empty memory data stream.
|
explicit |
Allocates a new chunk of memory and wraps it in a stream.
| size | Size of the memory chunk in bytes. |
| CeresEngine::MemoryDataStream::MemoryDataStream | ( | Byte * | memory, |
| size_t | size, | ||
| bool | freeOnClose = false |
||
| ) |
Wrap an existing memory chunk in a stream.
| memory | Memory to wrap the data stream around. |
| size | Size of the memory chunk in bytes. |
| freeOnClose | Should the memory buffer be freed when the data stream goes out of scope. |
| CeresEngine::MemoryDataStream::MemoryDataStream | ( | const ByteMemoryView & | buffer, |
| bool | freeOnClose = false |
||
| ) |
Wrap an existing memory chunk in a stream.
| buffer | Memory to wrap the data stream around. |
| freeOnClose | Should the memory buffer be freed when the data stream goes out of scope. |
|
explicit |
Copies all contents of the existing data stream into a memory stream.
| CeresEngine::MemoryDataStream::MemoryDataStream | ( | const MemoryDataStream & | ) |
|
noexcept |
|
final |
|
inline |
Gets a view to the underlying memory data.
|
inline |
Gets a view to the underlying memory data.
|
private |
Grows the memory stream if needed.
|
inline |
Determines if write or seek calls can grow the underlying memory buffer.
|
inlinefinalvirtualnoexcept |
Checks if the stream is readable.
If this method returns true, read() is safe to be called on this stream.
Reimplemented from CeresEngine::IInputStream.
|
inlinefinalvirtualnoexcept |
Checks if the stream is seekable.
If this method returns true, seek() is safe to be called on this stream.
Reimplemented from CeresEngine::IStream.
|
inlinefinalvirtualnoexcept |
Checks if the stream knows the size of the data.
If this method returns true, size() is safe to be called on this stream.
Reimplemented from CeresEngine::IStream.
|
inlinefinalvirtualnoexcept |
Checks if the stream knows it's current absolute position.
If this method returns true, tell() is safe to be called on this stream.
Reimplemented from CeresEngine::IStream.
|
inlinefinalvirtualnoexcept |
Checks if the stream is writable.
If this method returns true, write() is safe to be called on this stream.
Reimplemented from CeresEngine::IOutputStream.
Reads data from the data stream to a buffer of raw memory data with length n.
isReadable() returns true.| data | The memory location to which read data should be placed. |
| n | The maximum number of bytes to be read from the data stream. |
n. If 0, indicates that the stream has ended. Reimplemented from CeresEngine::IInputStream.
|
finalvirtual |
Changes the position of the data stream.
isSeekable() returns true.| position | The position to set the data stream to. |
| mode | The mode to change the data stream position. |
Reimplemented from CeresEngine::IStream.
|
inlinefinalvirtual |
Gets the number of bytes available on the stream.
isSizeKnown() returns true. Reimplemented from CeresEngine::IStream.
|
inlinefinalvirtual |
Gets the absolute stream position, in bytes.
isTellable() returns true. Reimplemented from CeresEngine::IStream.
Writes data to the data stream from a buffer of raw memory data with length n.
isWritable() returns true.| data | The memory location to which written data should be copied from. |
| n | The maximum number of bytes to be write to the data stream. |
n, in that case the write operation must be repeated to ensure that all data was written. If 0, indicates that the stream has ended. Reimplemented from CeresEngine::IOutputStream.
|
private |
|
private |
|
private |