Scid  4.7.0
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 () const =0
 Returns the Codec type. More...
 
virtual std::vector< std::string > getFilenames () const =0
 Returns the full path of the files used by the database. More...
 
virtual std::vector< std::pair< const char *, std::string > > getExtraInfo () const =0
 Returns a vector of tag pairs containing extra information about the database (type, description, autoload, etc..) More...
 
virtual const bytegetGameData (uint64_t offset, uint32_t length)=0
 Fetches the data of a game (excluding index info), encoded in native format. More...
 
virtual errorT addGame (const IndexEntry *srcIe, const NameBase *srcNb, const byte *srcData, size_t dataLen)=0
 Add a game to the database. More...
 
virtual errorT addGame (Game *game)=0
 Add a game to the database. More...
 
virtual errorT saveGame (Game *game, gamenumT replaced)=0
 Replaces a game in the database. More...
 
virtual errorT saveIndexEntry (const IndexEntry &ie, gamenumT replaced)=0
 Replaces a game's IndexEntry (which contains the header data of a game). More...
 
virtual std::pair< errorT, idNumberTaddName (nameT nt, const char *name)=0
 Adds a name (player, event, site or round) to the database. More...
 
virtual errorT flush ()=0
 Writes all pending output to the files. More...
 

Static Public Member Functions

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

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

◆ Codec

Enumerator
MEMORY 
SCID4 
PGN 

Definition at line 47 of file codec.h.

Constructor & Destructor Documentation

◆ ~ICodecDatabase()

virtual ICodecDatabase::~ICodecDatabase ( )
inlinevirtual

Definition at line 45 of file codec.h.

Member Function Documentation

◆ addGame() [1/2]

virtual errorT ICodecDatabase::addGame ( const IndexEntry srcIe,
const NameBase srcNb,
const byte srcData,
size_t  dataLen 
)
pure virtual

Add a game to the database.

Parameters
srcIevalid pointer to the header data.
srcNbvalid pointer to the NameBase containing srcIe's names.
srcDatavalid pointer to a buffer containing the game data (encoded in native format).
dataLenlength of the game data (in bytes).
Returns
OK if successful or an error code.

Implemented in CodecNative< Derived >, CodecNative< CodecMemory >, and CodecNative< CodecSCID4 >.

◆ addGame() [2/2]

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 CodecNative< Derived >, CodecNative< CodecMemory >, and CodecNative< CodecSCID4 >.

◆ addName()

virtual std::pair<errorT, idNumberT> ICodecDatabase::addName ( nameT  nt,
const char *  name 
)
pure virtual

Adds a name (player, event, site or round) to the database.

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

Implemented in CodecNative< Derived >, CodecNative< CodecMemory >, and CodecNative< CodecSCID4 >.

◆ flush()

virtual errorT ICodecDatabase::flush ( )
pure virtual

Writes all pending output to the files.

Returns
OK if successful or an error code.

Implemented in CodecSCID4, CodecMemory, and CodecPgn.

◆ getExtraInfo()

virtual std::vector<std::pair<const char*, std::string> > ICodecDatabase::getExtraInfo ( ) const
pure virtual

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

Implemented in CodecSCID4, and CodecMemory.

◆ getFilenames()

virtual std::vector<std::string> ICodecDatabase::getFilenames ( ) const
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 CodecSCID4, CodecMemory, and CodecPgn.

◆ getGameData()

virtual const byte* ICodecDatabase::getGameData ( uint64_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 CodecSCID4, and CodecMemory.

◆ getType()

virtual Codec ICodecDatabase::getType ( ) const
pure virtual

Returns the Codec type.

Implemented in CodecSCID4, CodecMemory, and CodecPgn.

◆ open()

std::pair< ICodecDatabase *, errorT > ICodecDatabase::open ( Codec  codec,
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.
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 OK.
  • on error: nullptr and the error code.

Definition at line 30 of file scidbase.cpp.

◆ saveGame()

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 CodecNative< Derived >, CodecNative< CodecMemory >, and CodecNative< CodecSCID4 >.

◆ saveIndexEntry()

virtual errorT ICodecDatabase::saveIndexEntry ( const IndexEntry ie,
gamenumT  replaced 
)
pure virtual

Replaces a game's IndexEntry (which contains the header data of a game).

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

Implemented in CodecNative< Derived >, CodecNative< CodecMemory >, and CodecNative< CodecSCID4 >.


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