Scid  4.6.5
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ICodecDatabase Class Referenceabstract

This interface separates the logic of a database from its representation. More...

#include <codec.h>

Inheritance diagram for ICodecDatabase:
Inheritance graph
[legend]

Public Types

enum  Codec { MEMORY, SCID4, PGN }
 

Public Member Functions

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

Static Public Member Functions

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

This interface separates the logic of a database from its representation.

Ideally all the file I/O should be encapsulated in classes derived from this interface.

Definition at line 43 of file codec.h.

Member Enumeration Documentation

Enumerator
MEMORY 
SCID4 
PGN 

Definition at line 47 of file codec.h.

Constructor & Destructor Documentation

virtual ICodecDatabase::~ICodecDatabase ( )
inlinevirtual

Definition at line 45 of file codec.h.

Member Function Documentation

virtual errorT ICodecDatabase::addGame ( IndexEntry srcIe,
const byte src,
size_t  length 
)
pure virtual

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.

Implemented in CodecMemory.

virtual errorT ICodecDatabase::addGame ( Game game)
pure virtual

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.

Implemented in CodecMemory.

virtual errorT ICodecDatabase::flush ( )
pure virtual

Writes all pending output to the files.

Returns
OK if successful or an error code.

Implemented in CodecMemory, CodecScid4, and CodecPgn.

virtual std::vector<std::string> ICodecDatabase::getFilenames ( )
pure virtual

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.

Implemented in CodecMemory, CodecScid4, and CodecPgn.

virtual const byte* ICodecDatabase::getGameData ( uint32_t  offset,
uint32_t  length 
)
pure virtual

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.

Implemented in CodecMemory, and CodecScid4.

virtual Codec ICodecDatabase::getType ( )
pure virtual

Returns the Codec type.

Implemented in CodecMemory, CodecScid4, and CodecPgn.

ICodecDatabase * ICodecDatabase::make ( Codec  codec,
errorT err,
fileModeT  fMode,
const char *  filename,
const Progress progress,
Index idx,
NameBase nb 
)
static

Creates a new object and calls the virtual function dyn_open().

Parameters
codecthe type of the object to be created.
err[out]OK on success, an error code on failure.
fModea valid file mode.
filenamethe full path of the database to be opened.
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
  • on success: a valid pointer to the new object and set err to OK.
  • on error: 0 (nullptr) and sets err to the error code.

Definition at line 29 of file scidbase.cpp.

virtual errorT ICodecDatabase::saveGame ( IndexEntry srcIe,
const byte src,
size_t  length,
gamenumT  replaced 
)
pure virtual

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.

Implemented in CodecMemory.

virtual errorT ICodecDatabase::saveGame ( Game game,
gamenumT  replaced 
)
pure virtual

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.

Implemented in CodecMemory.


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