#include <iomemory.h>
Helper class for Url of type maxon::URLSCHEME_MEMORY. It turns memory blocks into InputStreams or OutputStreams. This way a memory block can be handled like a real file. The following example shows how to write into a memory file.
Public Types | |
using | FreeBufferCallback = Delegate< void(const Char *&buffer)> |
Public Member Functions | |
MAXON_METHOD Result< void > | PrepareReadBuffer (const Block< const Char > &buffer, const FreeBufferCallback &freeBufferCallback) |
MAXON_METHOD Result< void > | Reset (Int size) |
MAXON_METHOD const Char & | operator[] (Int idx) |
MAXON_METHOD Int | GetSize () const |
MAXON_METHOD Bool | IsWritable () const |
MAXON_METHOD Result< Url > | GetUrl () const |
MAXON_METHOD Result< void > | ReadBytes (Int position, const Block< Byte > &data) const |
MAXON_METHOD Result< Int > | ReadBytesEOS (Int position, const Block< Byte > &data) const |
MAXON_METHOD Result< void > | WriteBytes (Int position, const Block< const Byte > &data) |
MAXON_METHOD Result< InputStreamRef > | OpenInputStream (OPENSTREAMFLAGS flags) const |
MAXON_METHOD Result< OutputStreamRef > | OpenOutputStream (OPENSTREAMFLAGS flags) |
MAXON_METHOD Result< InOutputStreamRef > | OpenInOutputStream (OPENSTREAMFLAGS flags) |
Static Public Member Functions | |
static MAXON_METHOD IoMemoryInterface * | Alloc (MAXON_SOURCE_LOCATION_DECLARATION) |
static MAXON_METHOD IoMemoryInterface * | Alloc (MAXON_SOURCE_LOCATION_DECLARATION, const IoMemoryInterface &src) |
Private Member Functions | |
MAXON_INTERFACE_NONVIRTUAL (IoMemoryInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.iomemory", MAXON_IMPLEMENTATION_MODULE("net.maxon.kernel")) | |
using FreeBufferCallback = Delegate<void(const Char*& buffer)> |
Argument type of PrepareReadBuffer().
|
private |
|
static |
Allocators for common use.
[in] | allocLocation | Source location. |
|
static |
MAXON_METHOD Result<void> PrepareReadBuffer | ( | const Block< const Char > & | buffer, |
const FreeBufferCallback & | freeBufferCallback | ||
) |
Prepares a given memory block for reading. The ownership of the memory can be transfered to the object. The memory will be freed by calling DeleteMem().
[in] | buffer | Block with the available data to read from. |
[in] | freeBufferCallback | If a callback/lambda is given the memory should be owned by the object and will be freed by calling the callback. Within the callback the memory should be freed and the pointer must be set to nullptr! If "nullptr" the memory needs to be freed by yourself and needs to be kept until this class is not used anymore. |
MAXON_METHOD Result<void> Reset | ( | Int | size | ) |
Resets the class and preallocate a given size of bytes. In read mode the memory can e.g. be filled with WriteBytes. Write mode only needs size 0 as the data grows dynamically.
[in] | size | Requested size of bytes in the buffer. This memory can be accessed via operator[] or ReadBytes/WriteBytes. |
MAXON_METHOD const Char& operator[] | ( | Int | idx | ) |
Accesses operator to the buffer.
[in] | idx | Index of the data to read. |
MAXON_METHOD Int GetSize | ( | ) | const |
Gets the current buffer size.
MAXON_METHOD Bool IsWritable | ( | ) | const |
Returns whether the object is writable (true) or not (false)
MAXON_METHOD Result<Url> GetUrl | ( | ) | const |
Creates an Url for this IoMemoryRef class. This name can be used to call InputStreamRef and OutputStreamRef functions with memory files. The Url can be passed to any function that accepts Urls for reading/writing files. E.g. reading/writing images from a memory block etc. InOutputStreamRef is not supported.
MAXON_METHOD Result<void> ReadBytes | ( | Int | position, |
const Block< Byte > & | data | ||
) | const |
Copies the classes buffer from position to destData with the given length.
[in] | position | Start copying memory from this offset. The position is the offset in the classes buffer, not the destination buffer. |
[in] | data | Destination buffer. |
Copies the classes buffer from position to destData with the given length.
[in] | position | Start copying memory from this offset. The position is the offset in the classes buffer, not the destination buffer. |
[in] | data | Destination buffer. |
MAXON_METHOD Result<void> WriteBytes | ( | Int | position, |
const Block< const Byte > & | data | ||
) |
Writes the given sourceData at position in the classes buffer with the given length.
[in] | position | Start copying memory to this offset. The position is the offset in the classes buffer, not the source data buffer. |
[in] | data | Source data buffer. |
MAXON_METHOD Result<InputStreamRef> OpenInputStream | ( | OPENSTREAMFLAGS | flags | ) | const |
MAXON_METHOD Result<OutputStreamRef> OpenOutputStream | ( | OPENSTREAMFLAGS | flags | ) |
MAXON_METHOD Result<InOutputStreamRef> OpenInOutputStream | ( | OPENSTREAMFLAGS | flags | ) |