GemaCoreLib
The GeMA Core library
Public Member Functions | List of all members
GmMemoryDumpItem Class Referenceabstract

Interface for an object that can be dumped and undumped to either file or memory by GmMemoryDump. More...

#include <gmMemoryDump.h>

Inheritance diagram for GmMemoryDumpItem:
Inheritance graph
[legend]

Public Member Functions

virtual ~GmMemoryDumpItem ()
 Virtual destructor.
 
virtual QString itemName () const =0
 Returns the item name. Should be a string with at most GM_MEMORY_DUMP_ITEM_NAME_SIZE characters.
 
virtual int itemType () const =0
 Returns the item type.
 
virtual bool canCompress () const =0
 Should this item be compressed if the MemoryDump object is configured with compression?
 
virtual bool partialOp () const =0
 Does this item supports partial load / save operations?
 
virtual bool fixedSize () const =0
 Is this dump item a fixed size item that probably won't grow in the future? If so, extra space will NOT be reserved on file for growing even if growing is configured on the memory dump object.
 
virtual bool opStart (int op)
 Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation on this item will begin. More...
 
virtual bool opEnd (int op)
 Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation was completed succesfully (it won't be called if the operation failed). More...
 
virtual qint64 size () const =0
 Returns the current item size (in bytes)
 
virtual bool fillDataHeader (char *header)=0
 Function called together with getDataBuffer() to provide a "header information" with fixed size (equal to GM_MEMORY_DUMP_ITEM_DATA_SIZE) that is also saved for the dump item. This information is then made available when setDataBuffer() is called. More...
 
virtual void getDataBuffer (GmMemoryBufferList &bufferList, qint64 size=0, qint64 offset=0)=0
 Fills the provided bufferList object with the set of buffers that together define the dump item data. More...
 
virtual bool setDataBuffer (GmMemoryBufferList &bufferList, const char *header, qint64 size, qint64 offset=0)=0
 Fills the provided bufferList object with the set of buffers that should be used to update the dump item data. More...
 
virtual void bufferReleased (int op, bool ok)
 Function called once after a call to getDataBuffer() / setDataBuffer() to inform the item data that the returned buffer will not be used anymore by the memory dump object. More...
 

Detailed Description

Interface for an object that can be dumped and undumped to either file or memory by GmMemoryDump.

The provided interface is targeted for allowing the file operations to be done directly over the dump item memory and so minimizing buffer copies.

It also allows for partial operations reading/updating only part of the dump item memory.

To allow for the item memory to be spread over multiple buffers, the returned pointers should be collected on a GmMemoryBufferList object.

Member Function Documentation

◆ bufferReleased()

virtual void GmMemoryDumpItem::bufferReleased ( int  op,
bool  ok 
)
inlinevirtual

Function called once after a call to getDataBuffer() / setDataBuffer() to inform the item data that the returned buffer will not be used anymore by the memory dump object.

This function is always called after a buffer request, even on errors. On success, its call happends BEFORE the call to opEnd() (on errors, opEnd() is not called at all).

The ok parameter tells if the underlying buffer operation was well succeeded or not. If ok is false, the buffer contents for a setDataBuffer() operation is undefined. The op parameter is 0 if the finished operation was a get operation and 1 if it was a set operation.

Reimplemented in GmStateDumpLuaDataItem, GmStateDumpMapDataItem< K, V >, GmStateDumpMapDataItem< QString, QVariant >, GmStateDumpValueSetDataItem, and GmStateDumpFunctionMapDataItem.

◆ fillDataHeader()

virtual bool GmMemoryDumpItem::fillDataHeader ( char *  header)
pure virtual

Function called together with getDataBuffer() to provide a "header information" with fixed size (equal to GM_MEMORY_DUMP_ITEM_DATA_SIZE) that is also saved for the dump item. This information is then made available when setDataBuffer() is called.

This function should fill the buffer with data and return true if it makes use of this functionality. Otherwise it can just return false indicating that the header was not updated at all.

It will be called even if size() returns zero.

Implemented in GmStateDumpLuaDataItem, GmStateDumpMapDataItem< K, V >, GmStateDumpMapDataItem< QString, QVariant >, GmStateDumpSplitIntVecDataItem, GmStateDumpSDVectorDataItem< Vector >, GmStateDumpBufferDataItem, GmStateDumpArmaDataItem< T >, GmStateDumpArmaDataItem< GmMatrix >, GmStateDumpArmaDataItem< GmVector >, GmStateDumpValueSetDataItem, and GmStateDumpFunctionMapDataItem.

◆ getDataBuffer()

virtual void GmMemoryDumpItem::getDataBuffer ( GmMemoryBufferList bufferList,
qint64  size = 0,
qint64  offset = 0 
)
pure virtual

Fills the provided bufferList object with the set of buffers that together define the dump item data.

If size is NOT zero, the filled bufferList should present a partial view of that data with size bytes and starting at the given offset. Otherwise, the filled bufferList size should be equal to the size returned by size(). If partialOp() returns false, this function will always be called with size and offset equal to 0.

The pointers added to the bufferList MUST remain valid until a call to bufferReleased(). The function can assume that between a call to getDataBuffer() and its closing bufferReleased() there will be no other calls to getDataBuffer() or setDataBuffer().

If size() == 0, this function is allowed to return without adding any buffers to bufferList. Otherwise, it MUST fill it with at least one valid buffer.

Implemented in GmStateDumpLuaDataItem, GmStateDumpMapDataItem< K, V >, GmStateDumpMapDataItem< QString, QVariant >, GmStateDumpSplitIntVecDataItem, GmStateDumpSDVectorDataItem< Vector >, GmStateDumpBufferDataItem, GmStateDumpArmaDataItem< T >, GmStateDumpArmaDataItem< GmMatrix >, GmStateDumpArmaDataItem< GmVector >, GmStateDumpValueSetDataItem, and GmStateDumpFunctionMapDataItem.

◆ opEnd()

virtual bool GmMemoryDumpItem::opEnd ( int  op)
inlinevirtual

Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation was completed succesfully (it won't be called if the operation failed).

If this function returns false, the operation will be aborted. This allows for the dump item to do some extra content validation after a load operation.

Reimplemented in GmStateDumpMapDataItem< K, V >, GmStateDumpMapDataItem< QString, QVariant >, and GmStateDumpBufferDataItem.

◆ opStart()

virtual bool GmMemoryDumpItem::opStart ( int  op)
inlinevirtual

Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation on this item will begin.

If this function returns false, the operation will be aborted. It will be called before any calls to size(), fillDataHeader(), getDataBuffer(), setDataBuffer() or bufferReleased().

Reimplemented in GmStateDumpLuaDataItem, GmStateDumpMapDataItem< K, V >, GmStateDumpMapDataItem< QString, QVariant >, GmStateDumpSplitIntVecDataItem, and GmStateDumpBufferDataItem.

◆ setDataBuffer()

virtual bool GmMemoryDumpItem::setDataBuffer ( GmMemoryBufferList bufferList,
const char *  header,
qint64  size,
qint64  offset = 0 
)
pure virtual

Fills the provided bufferList object with the set of buffers that should be used to update the dump item data.

The header parameter provides the header information filled by fillDataHeader() when the item data was last saved. Its size is equal to GM_MEMORY_DUMP_ITEM_DATA_SIZE.

The size parameter informs the size of the data to be written. If the dump item can not cope with that size, the function should return false and leave the bufferList empty. The offset parameter is used for partial data updates to the area starting at the given offset. If partialOp() returns false, this function will always be called with offset equal to 0.

The pointers added to the bufferList MUST remain valid until a call to bufferReleased() , when its contents can then be used by the item data if needed. The function can assume that between a call to setDataBuffer() and its closing bufferReleased() there will be no other calls to setDataBuffer() or getDataBuffer().

This function will NOT be called with size == 0.

Implemented in GmStateDumpLuaDataItem, GmStateDumpMapDataItem< K, V >, GmStateDumpMapDataItem< QString, QVariant >, GmStateDumpSplitIntVecDataItem, GmStateDumpSDVectorDataItem< Vector >, GmStateDumpBufferDataItem, GmStateDumpArmaDataItem< T >, GmStateDumpArmaDataItem< GmMatrix >, GmStateDumpArmaDataItem< GmVector >, GmStateDumpValueSetDataItem, and GmStateDumpFunctionMapDataItem.


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