IoMemoryInterface Class Reference IO

#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.

IoMemoryRef mfh = IoMemoryRef::Create() iferr_return ; Url writemem = mfh. GetUrl (); OutputStreamRef outmem = writemem. OpenOutputStream () iferr_return ; outmem.Write("ABCDE", 5); outmem.Write("FGHIJ", 5); outmem.Close();
for ( Int i = 0; i < mfh. GetSize (); i++) { OutputWithFlags ( OUTPUT::DIAGNOSTIC | OUTPUT::NOLINEBREAK , "@{c}" , mfh[i]); } IoMemoryRef mem = IoMemoryRef::Create() iferr_return ; Char * buffer = NewMem ( Char , size) iferr_return ; mem. PrepareReadBuffer ( ToBlock (buffer, size), [](const Char *& buffer) { DeleteMem (buffer); }) iferr_return ;

Public Types

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

公共成员函数

MAXON_METHOD Result < void >  PrepareReadBuffer (const Block < const Char > &buffer, const FreeBufferCallback &freeBufferCallback)
MAXON_METHOD Result < void >  重置 ( Int size)
const MAXON_METHOD 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 MAXON_METHOD IoMemoryInterface Alloc ( MAXON_SOURCE_LOCATION_DECLARATION )
static MAXON_METHOD IoMemoryInterface Alloc ( MAXON_SOURCE_LOCATION_DECLARATION , const IoMemoryInterface & src )

私有成员函数

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

成员函数文档编制

◆  MAXON_INTERFACE_NONVIRTUAL()

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

◆  Alloc() [1/2]

static MAXON_METHOD IoMemoryInterface * Alloc ( MAXON_SOURCE_LOCATION_DECLARATION   )
static

Allocators for common use.

参数
[in] allocLocation Source location.

◆  Alloc() [2/2]

static MAXON_METHOD IoMemoryInterface * Alloc ( MAXON_SOURCE_LOCATION_DECLARATION   ,
const IoMemoryInterface src  
)
static

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

参数
[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.
返回
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.

参数
[in] size Requested size of bytes in the buffer. This memory can be accessed via operator[] or ReadBytes/WriteBytes.
返回
OK on success.

◆  operator[]()

const MAXON_METHOD Char & operator[] ( Int   idx )

Accesses operator to the buffer.

参数
[in] idx Index of the data to read.
返回
Value of the position in the buffer.

◆  GetSize()

MAXON_METHOD Int GetSize ( ) const

Gets the current buffer size.

返回
Size of the internal buffer.

◆  IsWritable()

MAXON_METHOD Bool IsWritable ( ) const

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

返回
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.

返回
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.

参数
[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.
返回
Number of bytes copied.

◆  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.

参数
[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.
返回
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.

参数
[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.
返回
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 )
maxon::IoMemoryInterface::OpenOutputStream
MAXON_METHOD Result< OutputStreamRef > OpenOutputStream(OPENSTREAMFLAGS flags)
Int
maxon::Int Int
定义: ge_sys_math.h:62
OutputWithFlags
#define OutputWithFlags(flags, formatString,...)
定义: debugdiagnostics.h:180
maxon::ToBlock
Block< T > ToBlock(T(&array)[N])
定义: block.h:873
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::IoMemoryInterface::GetUrl
MAXON_METHOD Result< Url > GetUrl() const
maxon::OUTPUT::NOLINEBREAK
@ NOLINEBREAK
if set, no line break is added
maxon::IoMemoryInterface::GetSize
MAXON_METHOD Int GetSize() const
maxon::DeleteMem
void DeleteMem(T *&p)
定义: defaultallocator.h:258
maxon::IoMemoryInterface::PrepareReadBuffer
MAXON_METHOD Result< void > PrepareReadBuffer(const Block< const Char > &buffer, const FreeBufferCallback &freeBufferCallback)
NewMem
#define NewMem(T, cnt)
定义: defaultallocator.h:196
maxon::OUTPUT::DIAGNOSTIC
@ DIAGNOSTIC
diagnostic output, shows up if this group of output is activated. This is also the default
Char
maxon::Char Char
定义: ge_sys_math.h:54