Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | 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

Codec getType () const override
 Returns the Codec type. More...
 
std::vector< std::string > getFilenames () const override
 Returns the full path of the files used by the database. More...
 
std::vector< std::pair< const char *, std::string > > getExtraInfo () const override
 Returns a vector of tag pairs containing extra information about the database (type, description, autoload, etc..) More...
 
const bytegetGameData (uint64_t offset, uint32_t length) override
 Fetches the data of a game (excluding index info), encoded in native format. More...
 
errorT flush () override
 Writes all pending output to the files. More...
 
errorT dyn_open (fileModeT fMode, const char *, const Progress &, Index *idx, NameBase *nb) override
 Opens/Creates a database. More...
 
std::pair< errorT, uint64_t > dyn_addGameData (const byte *src, size_t length)
 Stores the data of a game into memory. More...
 
std::pair< errorT, idNumberTdyn_addName (nameT nt, const char *name)
 Given a name (string), retrieve the corresponding ID. More...
 
errorT dyn_addIndexEntry (const IndexEntry &ie)
 Add an IndexEntry to idx_. More...
 
errorT dyn_saveIndexEntry (const IndexEntry &ie, gamenumT replaced)
 Replace an IndexEntry. More...
 
- Public Member Functions inherited from CodecNative< CodecMemory >
errorT addGame (const IndexEntry *srcIe, const NameBase *srcNb, const byte *srcData, size_t dataLen) override
 Add a game to 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 saveIndexEntry (const IndexEntry &ie, gamenumT replaced) override
 Replaces a game's IndexEntry (which contains the header data of a game). More...
 
std::pair< errorT, idNumberTaddName (nameT nt, const char *name) override
 Adds a name (player, event, site or round) to the database. More...
 
- Public Member Functions inherited from ICodecDatabase
virtual ~ICodecDatabase ()
 

Additional Inherited Members

- Public Types inherited from ICodecDatabase
enum  Codec { MEMORY, SCID4, PGN }
 
- Static Public Member Functions inherited from ICodecDatabase
static std::pair< ICodecDatabase *, errorTopen (Codec codec, fileModeT fMode, const char *filename, const Progress &progress, Index *idx, NameBase *nb)
 Creates a new object and calls the virtual function dyn_open(). More...
 
- Protected Member Functions inherited from CodecNative< CodecMemory >
 CodecNative ()
 
- Protected Attributes inherited from CodecNative< CodecMemory >
Indexidx_
 
NameBasenb_
 
ByteBuffer bbuf_
 

Detailed Description

Manages memory databases that do not have associated files.

Every open database should have a native representation in memory: to satisfy this requirement non-native codecs should be derived from this class.

Definition at line 34 of file codec_memory.h.

Member Function Documentation

◆ dyn_addGameData()

std::pair<errorT, uint64_t> CodecMemory::dyn_addGameData ( const byte src,
size_t  length 
)
inline

Stores the data of a game into memory.

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.

Definition at line 90 of file codec_memory.h.

◆ dyn_addIndexEntry()

errorT CodecMemory::dyn_addIndexEntry ( const IndexEntry ie)
inline

Add an IndexEntry to idx_.

Parameters
iethe IndexEntry object to add.
Returns
OK if successful or an error code.

Definition at line 128 of file codec_memory.h.

◆ dyn_addName()

std::pair<errorT, idNumberT> CodecMemory::dyn_addName ( nameT  nt,
const char *  name 
)
inline

Given a name (string), retrieve the corresponding ID.

The name is added to nb_ if do not already exists in the NameBase.

Parameters
ntnameT type of the name to retrieve.
namethe name to retrieve.
Returns
  • on success, a std::pair containing OK and the ID.
  • on failure, a std::pair containing an error code and 0.

Definition at line 119 of file codec_memory.h.

◆ dyn_open()

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

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.

Definition at line 68 of file codec_memory.h.

◆ dyn_saveIndexEntry()

errorT CodecMemory::dyn_saveIndexEntry ( const IndexEntry ie,
gamenumT  replaced 
)
inline

Replace an IndexEntry.

Parameters
iethe IndexEntry with the new data.
replacedvalid gamenumT of the game to be replaced.
Returns
OK if successful or an error code.

Definition at line 142 of file codec_memory.h.

◆ flush()

errorT CodecMemory::flush ( )
inlineoverridevirtual

Writes all pending output to the files.

Returns
OK if successful or an error code.

Implements ICodecDatabase.

Reimplemented in CodecPgn.

Definition at line 66 of file codec_memory.h.

◆ getExtraInfo()

std::vector<std::pair<const char*, std::string> > CodecMemory::getExtraInfo ( ) const
inlineoverridevirtual

Returns a vector of tag pairs containing extra information about the database (type, description, autoload, etc..)

Implements ICodecDatabase.

Definition at line 53 of file codec_memory.h.

◆ getFilenames()

std::vector<std::string> CodecMemory::getFilenames ( ) const
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 CodecPgn.

Definition at line 48 of file codec_memory.h.

◆ getGameData()

const byte* CodecMemory::getGameData ( uint64_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.

Definition at line 59 of file codec_memory.h.

◆ getType()

Codec CodecMemory::getType ( ) const
inlineoverridevirtual

Returns the Codec type.

Implements ICodecDatabase.

Reimplemented in CodecPgn.

Definition at line 46 of file codec_memory.h.


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