Scid  4.6.5
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CodecMemory Class Reference

Manages memory databases that do not have associated files. More...

#include <codec_memory.h>

Inheritance diagram for CodecMemory:
Inheritance graph
[legend]
Collaboration diagram for CodecMemory:
Collaboration graph
[legend]

Public Member Functions

 CodecMemory ()
 
Codec getType () override
 Returns the Codec type. More...
 
std::vector< std::string > getFilenames () override
 Returns the full path of the files used by the database. More...
 
const bytegetGameData (uint32_t offset, uint32_t length) override
 Fetches the data of a game (excluding index info), encoded in native format. More...
 
errorT addGame (IndexEntry *ie, const byte *src, size_t length) override
 Add a game to the database. More...
 
errorT saveGame (IndexEntry *ie, const byte *src, size_t length, gamenumT replaced) override
 Replaces a game in the database. More...
 
errorT addGame (Game *game) override
 Add a game to the database. More...
 
errorT saveGame (Game *game, gamenumT replaced) override
 Replaces a game in the database. More...
 
errorT flush () override
 Writes all pending output to the files. More...
 
- Public Member Functions inherited from ICodecDatabase
virtual ~ICodecDatabase ()
 

Protected Member Functions

errorT dyn_open (fileModeT fMode, const char *, const Progress &, Index *idx, NameBase *nb) override
 Opens/Creates a database. More...
 
virtual std::pair< errorT, uint32_t > dyn_addGameData (const byte *src, size_t length)
 Stores the data of the game into the database. More...
 

Protected Attributes

Indexidx_
 
NameBasenb_
 

Additional Inherited Members

- Public Types inherited from ICodecDatabase
enum  Codec { MEMORY, SCID4, PGN }
 
- Static Public Member Functions inherited from ICodecDatabase
static ICodecDatabasemake (Codec codec, errorT *err, fileModeT fMode, const char *filename, const Progress &progress, Index *idx, NameBase *nb)
 Creates a new object and calls the virtual function dyn_open(). More...
 

Detailed Description

Manages memory databases that do not have associated files.

This class stores the data of the games into a std::vector; derived classes can override the virtual functions dyn_addGameData() and getGameData() in order to store the data into a different container or file.

Definition at line 47 of file codec_memory.h.

Constructor & Destructor Documentation

CodecMemory::CodecMemory ( )
inline

Definition at line 57 of file codec_memory.h.

Member Function Documentation

errorT CodecMemory::addGame ( IndexEntry srcIe,
const byte src,
size_t  length 
)
inlineoverridevirtual

Add a game to the database.

Parameters
srcIevalid pointer to the header data.
srcvalid pointer to a buffer containing the game data (encoded in native format).
lengthlength of the game data (in bytes).
Returns
OK if successful or an error code.

Implements ICodecDatabase.

Definition at line 75 of file codec_memory.h.

errorT CodecMemory::addGame ( Game game)
inlineoverridevirtual

Add a game to the database.

Parameters
gamevalid pointer to a Game object with the data of the game.
Returns
OK if successful or an error code.

Implements ICodecDatabase.

Definition at line 84 of file codec_memory.h.

virtual std::pair<errorT, uint32_t> CodecMemory::dyn_addGameData ( const byte src,
size_t  length 
)
inlineprotectedvirtual

Stores the data of the game into the database.

A derived class can override this function to store the data into a different container or file. In that case it must also override the virtual function getGameData().

Parameters
srcvalid pointer to a buffer that contains the game data (encoded in native format).
lengththe length of the buffer src (in bytes).
Returns
  • on success, a std::pair containing OK and the offset of the stored data (usable to retrieve the data with getGameData()).
  • on failure, a std::pair containing an error code and 0.

Reimplemented in CodecScid4.

Definition at line 127 of file codec_memory.h.

errorT CodecMemory::dyn_open ( fileModeT  fMode,
const char *  filename,
const Progress progress,
Index idx,
NameBase nb 
)
inlineoverrideprotectedvirtual

Opens/Creates a database.

This virtual function is called only once immediately after the class constructor.

Parameters
fModea valid file mode.
filenamethe full path of the database to open.
progressa Progress object used for GUI communications.
idxvalid pointer to the Index object for this database.
nbvalid pointer to the NameBase object for this database.
Returns
  • OK: the object is ready to be used.
  • ERROR_NameDataLoss: some names are corrupted and cannot be recovered, however the object can still be used.
  • Other error codes: the operation failed (the object must be destroyed).

Implements ICodecDatabase.

Reimplemented in CodecScid4.

Definition at line 105 of file codec_memory.h.

errorT CodecMemory::flush ( )
inlineoverridevirtual

Writes all pending output to the files.

Returns
OK if successful or an error code.

Implements ICodecDatabase.

Reimplemented in CodecScid4, and CodecPgn.

Definition at line 100 of file codec_memory.h.

std::vector<std::string> CodecMemory::getFilenames ( )
inlineoverridevirtual

Returns the full path of the files used by the database.

The order of the filenames must be consistent for objects of the same Codec type.

Implements ICodecDatabase.

Reimplemented in CodecScid4, and CodecPgn.

Definition at line 61 of file codec_memory.h.

const byte* CodecMemory::getGameData ( uint32_t  offset,
uint32_t  length 
)
inlineoverridevirtual

Fetches the data of a game (excluding index info), encoded in native format.

Parameters
offsetoffset of the requested game.
lengthlength of the game data (in bytes).
Returns
  • a pointer to the game data.
  • 0 (nullptr) on error.

Implements ICodecDatabase.

Reimplemented in CodecScid4.

Definition at line 65 of file codec_memory.h.

Codec CodecMemory::getType ( )
inlineoverridevirtual

Returns the Codec type.

Implements ICodecDatabase.

Reimplemented in CodecScid4, and CodecPgn.

Definition at line 59 of file codec_memory.h.

errorT CodecMemory::saveGame ( IndexEntry srcIe,
const byte src,
size_t  length,
gamenumT  replaced 
)
inlineoverridevirtual

Replaces a game in the database.

Parameters
srcIevalid pointer to the new header data.
srcvalid pointer to a buffer containing the new game data (encoded in native format).
lengthlength of the new game data (in bytes).
replacedvalid gamenumT of the game to be replaced.
Returns
OK if successful or an error code.

Implements ICodecDatabase.

Definition at line 79 of file codec_memory.h.

errorT CodecMemory::saveGame ( Game game,
gamenumT  replaced 
)
inlineoverridevirtual

Replaces a game in the database.

Parameters
gamevalid pointer to a Game object with the new data.
replacedvalid gamenumT of the game to be replaced
Returns
OK if successful or an error code.

Implements ICodecDatabase.

Definition at line 92 of file codec_memory.h.

Member Data Documentation

Index* CodecMemory::idx_
protected

Definition at line 49 of file codec_memory.h.

NameBase* CodecMemory::nb_
protected

Definition at line 50 of file codec_memory.h.


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