added include/game.hpp +18 -0
| new file mode 100644 |
| @@ -0,0 +1,18 @@ |
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <string> |
| 4 | + |
| 5 | +class Game |
| 6 | +{ |
| 7 | +private: |
| 8 | + int id; |
| 9 | + std::string name; |
| 10 | + std::string path; |
| 11 | +public: |
| 12 | + Game(int id, std::string name, std::string path) : id{id}, name{name}, path{path} { } |
| 13 | + ~Game() { } |
| 14 | + |
| 15 | + int getId() { return id; } |
| 16 | + std::string getName() { return name; } |
| 17 | + std::string getPath() { return path; } |
| 18 | +}; |
| new file mode 100644 |
| @@ -0,0 +1,18 @@ |
| | 1 | +#pragma once |
| | 2 | + |
| | 3 | +#include <string> |
| | 4 | + |
| | 5 | +class Game |
| | 6 | +{ |
| | 7 | +private: |
| | 8 | + int id; |
| | 9 | + std::string name; |
| | 10 | + std::string path; |
| | 11 | +public: |
| | 12 | + Game(int id, std::string name, std::string path) : id{id}, name{name}, path{path} { } |
| | 13 | + ~Game() { } |
| | 14 | + |
| | 15 | + int getId() { return id; } |
| | 16 | + std::string getName() { return name; } |
| | 17 | + std::string getPath() { return path; } |
| | 18 | +}; |
modified src/main.cpp +10 -1
| @@ -12,6 +12,7 @@ |
| 12 | 12 | #include <sqlite3.h> |
| 13 | 13 | #include <map> |
| 14 | 14 | |
| 15 | +#include <game.hpp> |
| 15 | 16 | |
| 16 | 17 | using namespace ftxui; |
| 17 | 18 | |
| @@ -43,8 +44,16 @@ void execute_sql_command(sqlite3* database, std::string command) { |
| 43 | 44 | } |
| 44 | 45 | } |
| 45 | 46 | |
| 47 | +int calculateFirstGameIdAvailable() { |
| 48 | + int availableId{}; |
| 49 | + |
| 50 | + availableId = games.size() + 1; |
| 51 | + |
| 52 | + return availableId; |
| 53 | +} |
| 54 | + |
| 46 | 55 | void addGame(sqlite3* database, std::string name, std::string path) { |
| 47 | | - int id = games.size() + 1; // calculateId(); |
| 56 | + int id = calculateFirstGameIdAvailable(); |
| 48 | 57 | addGameToDatabase(database, id, name, path); |
| 49 | 58 | } |
| 50 | 59 | |
| @@ -12,6 +12,7 @@ |
| 12 | #include <sqlite3.h> | 12 | #include <sqlite3.h> |
| 13 | #include <map> | 13 | #include <map> |
| 14 | | 14 | |
| | 15 | +#include <game.hpp> |
| 15 | | 16 | |
| 16 | using namespace ftxui; | 17 | using namespace ftxui; |
| 17 | | 18 | |
| @@ -43,8 +44,16 @@ void execute_sql_command(sqlite3* database, std::string command) { |
| 43 | } | 44 | } |
| 44 | } | 45 | } |
| 45 | | 46 | |
| | 47 | +int calculateFirstGameIdAvailable() { |
| | 48 | + int availableId{}; |
| | 49 | + |
| | 50 | + availableId = games.size() + 1; |
| | 51 | + |
| | 52 | + return availableId; |
| | 53 | +} |
| | 54 | + |
| 46 | void addGame(sqlite3* database, std::string name, std::string path) { | 55 | void addGame(sqlite3* database, std::string name, std::string path) { |
| 47 | - int id = games.size() + 1; // calculateId(); | 56 | + int id = calculateFirstGameIdAvailable(); |
| 48 | addGameToDatabase(database, id, name, path); | 57 | addGameToDatabase(database, id, name, path); |
| 49 | } | 58 | } |
| 50 | | 59 | |