Open Search
    IoMemoryInterface Class Reference

    #include <iomemory.h>

    Detailed Description

    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.

    IoMemoryRef mfh = IoMemoryRef::Create() iferr_return;
    Url writemem = mfh.GetUrl() iferr_return;
    OutputStreamRef outmem = writemem.OpenOutputStream() iferr_return;
    outmem.Write("ABCDE", 5);
    outmem.Write("FGHIJ", 5);
    outmem.Close();
    for (Int i = 0; i < mfh.GetSize(); i++)
    {
    }
    Py_ssize_t i
    Definition: abstract.h:645
    MAXON_METHOD Result< OutputStreamRef > OpenOutputStream(OPENSTREAMFLAGS flags)
    MAXON_METHOD Int GetSize() const
    MAXON_METHOD Result< Url > GetUrl() const
    for(i=0;i< length;i++)
    Definition: unicodeobject.h:61
    maxon::Int Int
    Definition: ge_sys_math.h:64
    static auto Create(ARGS &&... args)
    Definition: apibase.h:2829
    #define OutputWithFlags(flags, formatString,...)
    Definition: debugdiagnostics.h:150
    @ DIAGNOSTIC
    Diagnostic output, shows up if this group of output is activated. This is also the default.
    @ NOLINEBREAK
    If set, no line break is added.
    #define iferr_return
    Definition: resultbase.h:1524
    IoMemoryRef mem = IoMemoryRef::Create() iferr_return;
    [](const Char*& buffer)
    {
    const char ** buffer
    Definition: abstract.h:327
    MAXON_METHOD Result< void > PrepareReadBuffer(const Block< const Char > &buffer, const FreeBufferCallback &freeBufferCallback)
    Py_ssize_t size
    Definition: bytesobject.h:86
    #define NewMem(T, cnt)
    Definition: defaultallocator.h:195
    maxon::Char Char
    Definition: ge_sys_math.h:56
    Block< T > ToBlock(T(&array)[N])
    Definition: block.h:950
    void DeleteMem(T *&p)
    Definition: defaultallocator.h:257

    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 Charoperator[] (Int idx)
     
    MAXON_METHOD Int GetSize () const
     
    MAXON_METHOD Bool IsWritable () const
     
    MAXON_METHOD Result< UrlGetUrl () const
     
    MAXON_METHOD Result< void > ReadBytes (Int position, const Block< Byte > &data) const
     
    MAXON_METHOD Result< IntReadBytesEOS (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 IoMemoryInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
     
    static MAXON_METHOD IoMemoryInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, const IoMemoryInterface &src)
     

    Private Member Functions

     MAXON_INTERFACE_NONVIRTUAL (IoMemoryInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.iomemory")
     

    Member Typedef Documentation

    ◆ FreeBufferCallback

    using FreeBufferCallback = Delegate<void(const Char*& buffer)>

    Argument type of PrepareReadBuffer().

    Member Function Documentation

    ◆ MAXON_INTERFACE_NONVIRTUAL()

    MAXON_INTERFACE_NONVIRTUAL ( IoMemoryInterface  ,
    MAXON_REFERENCE_NORMAL  ,
    "net.maxon.interface.iomemory"   
    )
    private

    ◆ Alloc() [1/2]

    Allocators for common use.

    Parameters
    [in]allocLocationSource location.

    ◆ Alloc() [2/2]

    ◆ PrepareReadBuffer()

    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().

    Parameters
    [in]bufferBlock with the available data to read from.
    [in]freeBufferCallbackIf 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.
    Returns
    OK on success.

    ◆ Reset()

    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.

    Parameters
    [in]sizeRequested size of bytes in the buffer. This memory can be accessed via operator[] or ReadBytes/WriteBytes.
    Returns
    OK on success.

    ◆ operator[]()

    MAXON_METHOD const Char& operator[] ( Int  idx)

    Accesses operator to the buffer.

    Parameters
    [in]idxIndex of the data to read.
    Returns
    Value of the position in the buffer.

    ◆ GetSize()

    MAXON_METHOD Int GetSize ( ) const

    Gets the current buffer size.

    Returns
    Size of the internal buffer.

    ◆ IsWritable()

    MAXON_METHOD Bool IsWritable ( ) const

    Returns whether the object is writable (true) or not (false)

    Returns
    The current mode.

    ◆ GetUrl()

    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.

    Returns
    Url for further operations.

    ◆ ReadBytes()

    MAXON_METHOD Result<void> ReadBytes ( Int  position,
    const Block< Byte > &  data 
    ) const

    Copies the classes buffer from position to destData with the given length.

    Parameters
    [in]positionStart copying memory from this offset. The position is the offset in the classes buffer, not the destination buffer.
    [in]dataDestination buffer.
    Returns
    OK on success.

    ◆ ReadBytesEOS()

    MAXON_METHOD Result<Int> ReadBytesEOS ( Int  position,
    const Block< Byte > &  data 
    ) const

    Copies the classes buffer from position to destData with the given length.

    Parameters
    [in]positionStart copying memory from this offset. The position is the offset in the classes buffer, not the destination buffer.
    [in]dataDestination buffer.
    Returns
    Number of bytes copied.

    ◆ WriteBytes()

    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.

    Parameters
    [in]positionStart copying memory to this offset. The position is the offset in the classes buffer, not the source data buffer.
    [in]dataSource data buffer.
    Returns
    OK on success.

    ◆ OpenInputStream()

    MAXON_METHOD Result<InputStreamRef> OpenInputStream ( OPENSTREAMFLAGS  flags) const

    ◆ OpenOutputStream()

    MAXON_METHOD Result<OutputStreamRef> OpenOutputStream ( OPENSTREAMFLAGS  flags)

    ◆ OpenInOutputStream()

    MAXON_METHOD Result<InOutputStreamRef> OpenInOutputStream ( OPENSTREAMFLAGS  flags)