Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CodecNative< Derived > Class Template Reference

This class stores the pointers to the Index and NameBase objects used by a native codec. More...

#include <codec_native.h>

Inheritance diagram for CodecNative< Derived >:
Inheritance graph
[legend]
Collaboration diagram for CodecNative< Derived >:
Collaboration graph
[legend]

Public Member Functions

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 ()
 
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 flush ()=0
 Writes all pending output to the files. More...
 

Protected Member Functions

 CodecNative ()
 

Protected Attributes

Indexidx_
 
NameBasenb_
 
ByteBuffer bbuf_
 

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

Detailed Description

template<typename Derived>
class CodecNative< Derived >

This class stores the pointers to the Index and NameBase objects used by a native codec.

It also implements the addGame() and saveGame() functions of the ICodecDatabase interface, splitting them into 2 function calls to a derived class (CRTP technique):

Definition at line 43 of file codec_native.h.

Constructor & Destructor Documentation

◆ CodecNative()

template<typename Derived>
CodecNative< Derived >::CodecNative ( )
inlineprotected

Definition at line 50 of file codec_native.h.

Member Function Documentation

◆ addGame() [1/2]

template<typename Derived>
errorT CodecNative< Derived >::addGame ( const IndexEntry srcIe,
const NameBase srcNb,
const byte srcData,
size_t  dataLen 
)
inlineoverridevirtual

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.

Implements ICodecDatabase.

Definition at line 53 of file codec_native.h.

◆ addGame() [2/2]

template<typename Derived>
errorT CodecNative< Derived >::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 69 of file codec_native.h.

◆ addName()

template<typename Derived>
std::pair<errorT, idNumberT> CodecNative< Derived >::addName ( nameT  nt,
const char *  name 
)
inlineoverridevirtual

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.

Implements ICodecDatabase.

Definition at line 92 of file codec_native.h.

◆ saveGame()

template<typename Derived>
errorT CodecNative< Derived >::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 77 of file codec_native.h.

◆ saveIndexEntry()

template<typename Derived>
errorT CodecNative< Derived >::saveIndexEntry ( const IndexEntry ie,
gamenumT  replaced 
)
inlineoverridevirtual

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.

Implements ICodecDatabase.

Definition at line 88 of file codec_native.h.

Member Data Documentation

◆ bbuf_

template<typename Derived>
ByteBuffer CodecNative< Derived >::bbuf_
protected

Definition at line 47 of file codec_native.h.

◆ idx_

template<typename Derived>
Index* CodecNative< Derived >::idx_
protected

Definition at line 45 of file codec_native.h.

◆ nb_

template<typename Derived>
NameBase* CodecNative< Derived >::nb_
protected

Definition at line 46 of file codec_native.h.


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