2022-02-24 11:50:16 +01:00
|
|
|
#pragma once
|
|
|
|
#include "game_tab/Game.hpp"
|
2022-02-25 11:13:35 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2022-02-24 11:50:16 +01:00
|
|
|
|
2023-05-13 10:43:21 +02:00
|
|
|
/**
|
|
|
|
* @brief Represent the interface that each database type (such as PGNGameBase) must follow
|
|
|
|
* to be accessible in OChess.
|
|
|
|
*/
|
2022-02-24 11:50:16 +01:00
|
|
|
class GameBase {
|
|
|
|
|
|
|
|
public:
|
2022-02-28 20:16:57 +01:00
|
|
|
virtual std::shared_ptr<Game> GetGame(std::uint32_t id) = 0;
|
2022-12-26 13:39:33 +01:00
|
|
|
virtual void Save(std::vector<std::uint32_t> to_delete,
|
2022-12-27 15:58:16 +01:00
|
|
|
std::vector<std::string> databases_to_import,
|
2022-12-26 13:39:33 +01:00
|
|
|
std::vector<std::shared_ptr<Game>> games_to_import) = 0;
|
2022-02-28 20:16:57 +01:00
|
|
|
virtual std::shared_ptr<Game> GetCurrentGame() = 0;
|
2022-02-24 15:22:56 +01:00
|
|
|
virtual bool NextGame() = 0;
|
|
|
|
virtual std::string GetTag(std::string tag) = 0;
|
|
|
|
virtual void Reset() = 0;
|
2022-12-26 12:51:48 +01:00
|
|
|
virtual std::string GetFormat() = 0;
|
|
|
|
virtual std::string GetFilePath() = 0;
|
2022-02-26 12:30:07 +01:00
|
|
|
/**
|
|
|
|
* @brief Save the given base into current base format (export)
|
|
|
|
*
|
|
|
|
* @param base
|
|
|
|
*/
|
2022-02-28 20:30:57 +01:00
|
|
|
virtual void Export(std::shared_ptr<GameBase> base) = 0;
|
2022-12-26 19:20:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief An additionnal static method is expected with the following signature:
|
|
|
|
* static void CreateDatabaseFile(std::string path);
|
|
|
|
*/
|
2022-12-27 11:42:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Open a data
|
|
|
|
*
|
|
|
|
* @param dbpath
|
|
|
|
* @return std::shared_ptr<GameBase>
|
|
|
|
*/
|
2022-12-28 07:21:30 +01:00
|
|
|
std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfNotExist=true);
|
|
|
|
/**
|
|
|
|
* @brief Single game open
|
|
|
|
*
|
|
|
|
* @param dbpath
|
|
|
|
* @param id
|
|
|
|
* @return std::shared_ptr<Game>
|
|
|
|
*/
|
2022-12-30 15:09:24 +01:00
|
|
|
std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id);
|
|
|
|
void SaveGame(const std::string &dbpath, std::shared_ptr<Game> g);
|