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

Base class for non-native databases. More...

#include <codec_proxy.h>

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

Public Member Functions

errorT open (const char *filename, fileModeT fMode)
 Opens/creates a database encoded in a non-native format. More...
 
errorT parseNext (Game &)
 Reads the next game. More...
 
std::pair< size_t, size_t > parseProgress ()
 Returns info about the parsing progress. More...
 
const char * parseErrors ()
 Returns the list of errors produced by parseNext() calls. More...
 
errorT gameAdd (Game *)
 Adds a game into the database. More...
 
errorT gameSave (Game *, gamenumT)
 Replaces a game in the database. More...
 
- Public Member Functions inherited from CodecMemory
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...
 
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 ()
 

Static Public Member Functions

template<typename TProgress , typename TSource , typename TDestFn >
static errorT parseGames (const TProgress &progress, TSource &src, TDestFn destFn)
 
- 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...
 

Additional Inherited Members

- Public Types inherited from ICodecDatabase
enum  Codec { MEMORY, SCID4, PGN }
 
- Protected Member Functions inherited from CodecNative< CodecMemory >
 CodecNative ()
 
- Protected Attributes inherited from CodecNative< CodecMemory >
Indexidx_
 
NameBasenb_
 
ByteBuffer bbuf_
 

Detailed Description

template<typename Derived>
class CodecProxy< Derived >

Base class for non-native databases.

Every class derived from ICodecDatabase must keep an Index object and the corresponding NameBase object fully updated in memory. This implies that the virtual function dyn_open() must load in memory the header's data of all the games; however a dependency between the codecs and the Index class is not desirable. This class provides an interface that encapsulates the codecs, requiring only the ability to exchange Game objects.

Definition at line 48 of file codec_proxy.h.

Member Function Documentation

◆ gameAdd()

template<typename Derived>
errorT CodecProxy< Derived >::gameAdd ( Game )
inline

Adds a game into the database.

Parameters
Game*valid pointer to a Game object with the new data.
Returns
OK in case of success, an errorT code otherwise.

Definition at line 90 of file codec_proxy.h.

◆ gameSave()

template<typename Derived>
errorT CodecProxy< Derived >::gameSave ( Game ,
gamenumT   
)
inline

Replaces a game in the database.

Parameters
Game*valid pointer to a Game object with the new data.
gamenumTvalid gamenumT of the game to be replaced.
Returns
OK in case of success, an errorT code otherwise.

Definition at line 98 of file codec_proxy.h.

◆ open()

template<typename Derived>
errorT CodecProxy< Derived >::open ( const char *  filename,
fileModeT  fMode 
)

Opens/creates a database encoded in a non-native format.

Parameters
filenamefull path of the database to be opened.
fModevalid file access mode.
Returns
OK in case of success, an errorT code otherwise.

◆ parseErrors()

template<typename Derived>
const char* CodecProxy< Derived >::parseErrors ( )
inline

Returns the list of errors produced by parseNext() calls.

Definition at line 83 of file codec_proxy.h.

◆ parseGames()

template<typename Derived>
template<typename TProgress , typename TSource , typename TDestFn >
static errorT CodecProxy< Derived >::parseGames ( const TProgress &  progress,
TSource &  src,
TDestFn  destFn 
)
inlinestatic

Definition at line 172 of file codec_proxy.h.

◆ parseNext()

template<typename Derived>
errorT CodecProxy< Derived >::parseNext ( Game )
inline

Reads the next game.

A derived class implements this function to sequentially read the games contained into the database.

Parameters
Game&the Game object where the data will be stored.
Returns
  • ERROR_NotFound if there are no more games to be read.
  • OK otherwise.

Definition at line 69 of file codec_proxy.h.

◆ parseProgress()

template<typename Derived>
std::pair<size_t, size_t> CodecProxy< Derived >::parseProgress ( )
inline

Returns info about the parsing progress.

Returns
a pair<size_t, size_t> where first element is the quantity of data parsed and second one is the total amount of data of the database.

Definition at line 76 of file codec_proxy.h.


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