aboutsummaryrefslogtreecommitdiff
path: root/frontend/generate_dungeon.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-29 20:01:27 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-29 20:01:27 +0100
commit9283e1eb66d6ff96b02f317e28cb6ff060953cdf (patch)
treec03d853ef620216f1c2299936004f56c6c3cee04 /frontend/generate_dungeon.cpp
parent7285f9f2c2622acff734e31314f92df9b25cae16 (diff)
WIP load XML
Diffstat (limited to 'frontend/generate_dungeon.cpp')
-rw-r--r--frontend/generate_dungeon.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/frontend/generate_dungeon.cpp b/frontend/generate_dungeon.cpp
new file mode 100644
index 0000000..c6ddcbf
--- /dev/null
+++ b/frontend/generate_dungeon.cpp
@@ -0,0 +1,55 @@
+#include <memory>
+#include <functional>
+#include <sqlite3.h>
+
+#include "backend/Dungeon.h"
+
+#include "generate_dungeon.h"
+#include "Exception.h"
+
+using namespace std;
+
+class DB {
+ typedef unique_ptr<sqlite3, function<void(sqlite3*)>> unique_sqlite3;
+ typedef unique_ptr<sqlite3_stmt, function<void(sqlite3_stmt*)>> unique_sqlite3_stmt;
+
+public:
+ DB(const string & path) {
+ sqlite3 * db = NULL;
+ int ret = sqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_READONLY, NULL);
+ this->db = {
+ db,
+ [] (sqlite3 * db) {
+ sqlite3_close_v2(db);
+ },
+ };
+ if (ret != SQLITE_OK)
+ throw Exception("sqlite3_open_v2");
+ }
+
+ unique_sqlite3_stmt prepare(const string & query) {
+ sqlite3_stmt * stmt = NULL;
+ int ret = sqlite3_prepare_v2(this->db.get(), query.c_str(), query.size(), &stmt, NULL);
+ unique_sqlite3_stmt uniq_stmt = {
+ stmt,
+ [] (sqlite3_stmt * stmt) {
+ sqlite3_finalize(stmt);
+ },
+ };
+ if (ret != SQLITE_OK)
+ throw Exception("sqlite3_prepare_v2");
+ return uniq_stmt;
+ }
+
+private:
+ unique_sqlite3 db = NULL;
+};
+
+unique_ptr<Dungeon> generate_dungeon() {
+ unique_ptr<Dungeon> dungeon = make_unique<Dungeon>();
+
+ DB db { "kerkersendraken.db" };
+
+ return dungeon;
+}
+