aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/base_tab/gamebase/GameBase.cpp13
-rw-r--r--src/base_tab/gamebase/GameBase.hpp10
2 files changed, 22 insertions, 1 deletions
diff --git a/src/base_tab/gamebase/GameBase.cpp b/src/base_tab/gamebase/GameBase.cpp
new file mode 100644
index 0000000..e8f9a59
--- /dev/null
+++ b/src/base_tab/gamebase/GameBase.cpp
@@ -0,0 +1,13 @@
+#include "GameBase.hpp"
+#include "PGNGameBase.hpp"
+
+std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfNotExist){
+ wxFileName file(dbpath);
+ wxString ext = file.GetExt().Lower();
+ if (ext == "pgn") {
+ if(createIfNotExist && !file.Exists())
+ PGNGameBase::CreateDatabaseFile(dbpath);
+ return std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
+ }
+ return nullptr;
+} \ No newline at end of file
diff --git a/src/base_tab/gamebase/GameBase.hpp b/src/base_tab/gamebase/GameBase.hpp
index c87078d..008b36e 100644
--- a/src/base_tab/gamebase/GameBase.hpp
+++ b/src/base_tab/gamebase/GameBase.hpp
@@ -27,4 +27,12 @@ public:
* @brief An additionnal static method is expected with the following signature:
* static void CreateDatabaseFile(std::string path);
*/
-}; \ No newline at end of file
+};
+
+/**
+ * @brief Open a data
+ *
+ * @param dbpath
+ * @return std::shared_ptr<GameBase>
+ */
+std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfNotExist=true); \ No newline at end of file