juk3n/fluffypublic Fork
⑂ e10b023
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

updated returning type defining in functions

juk3n committed 2024-07-03T17:53:47+02:00 Browse files
e10b023 parent: fb9ea54
modified app/include/database.hpp +3 -5
@@ -6,8 +6,6 @@
66 class Database
77 {
88 private:
9-
10-
119 std::string database_initialization_command =
1210 "CREATE TABLE games("
1311 "GAME_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
@@ -26,7 +24,7 @@ public:
2624 sqlite3_close(database);
2725 }
2826
29- void execute_sql_command(std::string command) {
27+ auto execute_sql_command(std::string command) -> void {
3028 int exit = 0;
3129 char *messageError;
3230 exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);
@@ -37,12 +35,12 @@ public:
3735 }
3836 }
3937
40- void initialize_database() {
38+ auto initialize_database() -> void {
4139 execute_sql_command(database_initialization_command);
4240 //printMessage("Database Initialized");
4341 }
4442
45- sqlite3* load_database(std::filesystem::path databasePath) {
43+ auto load_database(std::filesystem::path databasePath) -> sqlite3* {
4644 bool newCreation = not std::filesystem::exists(databasePath.string());
4745
4846 int exit = 0;
@@ -6,8 +6,6 @@
6 class Database6 class Database
7 {7 {
8 private:8 private:
9-
10-
11 std::string database_initialization_command =9 std::string database_initialization_command =
12 "CREATE TABLE games("10 "CREATE TABLE games("
13 "GAME_ID INTEGER PRIMARY KEY AUTOINCREMENT, "11 "GAME_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
@@ -26,7 +24,7 @@ public:
26 sqlite3_close(database);24 sqlite3_close(database);
27 }25 }
28 26
29- void execute_sql_command(std::string command) {27+ auto execute_sql_command(std::string command) -> void {
30 int exit = 0;28 int exit = 0;
31 char *messageError;29 char *messageError;
32 exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);30 exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);
@@ -37,12 +35,12 @@ public:
37 }35 }
38 }36 }
39 37
40- void initialize_database() {38+ auto initialize_database() -> void {
41 execute_sql_command(database_initialization_command);39 execute_sql_command(database_initialization_command);
42 //printMessage("Database Initialized");40 //printMessage("Database Initialized");
43 }41 }
44 42
45- sqlite3* load_database(std::filesystem::path databasePath) {43+ auto load_database(std::filesystem::path databasePath) -> sqlite3* {
46 bool newCreation = not std::filesystem::exists(databasePath.string());44 bool newCreation = not std::filesystem::exists(databasePath.string());
47 45
48 int exit = 0;46 int exit = 0;
modified app/include/game.hpp +3 -3
@@ -13,7 +13,7 @@ public:
1313 : id{id}, name{name}, path{path} {}
1414 ~Game() {}
1515
16- int getId() { return id; }
17- std::string getName() { return name; }
18- std::string getPath() { return path; }
16+ auto getId() -> int { return id; }
17+ auto getName() -> std::string { return name; }
18+ auto getPath() -> std::string { return path; }
1919 };
@@ -13,7 +13,7 @@ public:
13 : id{id}, name{name}, path{path} {}13 : id{id}, name{name}, path{path} {}
14 ~Game() {}14 ~Game() {}
15 15
16- int getId() { return id; }16+ auto getId() -> int { return id; }
17- std::string getName() { return name; }17+ auto getName() -> std::string { return name; }
18- std::string getPath() { return path; }18+ auto getPath() -> std::string { return path; }
19 };19 };
modified app/src/main.cpp +9 -11
@@ -25,28 +25,26 @@ std::vector<Game> games;
2525
2626 bool debugRun = false;
2727
28-void printMessage(std::string message) {
28+auto printMessage(std::string message) -> void {
2929 if (debugRun) {
3030 std::cout << message << std::endl;
3131 }
3232 }
3333
34-void addGame(Database& database, std::string name, std::string path) {
34+auto addGame(Database& database, std::string name, std::string path) -> void {
3535 std::string command =
3636 "INSERT INTO games (GAME_NAME, GAME_PATH) VALUES (";
3737 command += "'" + name + "', \"" + path + "\");";
3838 database.execute_sql_command(command);
3939 }
4040
41-void removeGame(Database& database, std::string name) {
41+auto removeGame(Database& database, std::string name) -> void{
4242 std::string command = "DELETE FROM games WHERE GAME_NAME=";
4343 command += "'" + name + "';";
4444 database.execute_sql_command(command);
4545 }
4646
47-
48-
49-void runGame(std::string gameName) {
47+auto runGame(std::string gameName) -> void {
5048 std::string pathToRun = "";
5149 for (auto &game : games) {
5250 if (gameName == game.getName()) {
@@ -56,7 +54,7 @@ void runGame(std::string gameName) {
5654 system(pathToRun.c_str());
5755 }
5856
59-void handleCommand(int argc, char const *argv[], Database& database) {
57+auto handleCommand(int argc, char const *argv[], Database& database) -> void{
6058 std::string command{};
6159 switch (argc) {
6260 case 2:
@@ -99,7 +97,7 @@ void handleCommand(int argc, char const *argv[], Database& database) {
9997 }
10098 }
10199
102-auto Style() -> ButtonOption {
100+auto style() -> ButtonOption {
103101 auto option = ButtonOption::Border();
104102 option.transform = [](const EntryState &s) {
105103 auto element = text(s.label);
@@ -123,12 +121,12 @@ auto runConsoleApp() -> void {
123121 auto gamesContainer{Container::Vertical({})};
124122 for (auto &game : games) {
125123 gamesContainer->Add(Button(
126- game.getName(), [&] { runGame(game.getName()); }, Style()));
124+ game.getName(), [&] { runGame(game.getName()); }, style()));
127125 }
128126
129127 auto menu_screen = ScreenInteractive::TerminalOutput();
130128
131- auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), Style());
129+ auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), style());
132130 gamesContainer->Add(quitButton);
133131
134132 int menuOptionSelected{0};
@@ -149,7 +147,7 @@ auto runConsoleApp() -> void {
149147
150148 }
151149
152-std::filesystem::path getExecutablePath() {
150+auto getExecutablePath() -> std::filesystem::path {
153151 char result[PATH_MAX];
154152 ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
155153 return std::filesystem::path(std::string(result, (count > 0) ? count : 0));
@@ -25,28 +25,26 @@ std::vector<Game> games;
25 25
26 bool debugRun = false;26 bool debugRun = false;
27 27
28-void printMessage(std::string message) {28+auto printMessage(std::string message) -> void {
29 if (debugRun) {29 if (debugRun) {
30 std::cout << message << std::endl;30 std::cout << message << std::endl;
31 }31 }
32 }32 }
33 33
34-void addGame(Database& database, std::string name, std::string path) {34+auto addGame(Database& database, std::string name, std::string path) -> void {
35 std::string command =35 std::string command =
36 "INSERT INTO games (GAME_NAME, GAME_PATH) VALUES (";36 "INSERT INTO games (GAME_NAME, GAME_PATH) VALUES (";
37 command += "'" + name + "', \"" + path + "\");";37 command += "'" + name + "', \"" + path + "\");";
38 database.execute_sql_command(command);38 database.execute_sql_command(command);
39 }39 }
40 40
41-void removeGame(Database& database, std::string name) {41+auto removeGame(Database& database, std::string name) -> void{
42 std::string command = "DELETE FROM games WHERE GAME_NAME=";42 std::string command = "DELETE FROM games WHERE GAME_NAME=";
43 command += "'" + name + "';";43 command += "'" + name + "';";
44 database.execute_sql_command(command);44 database.execute_sql_command(command);
45 }45 }
46 46
47-47+auto runGame(std::string gameName) -> void {
48-
49-void runGame(std::string gameName) {
50 std::string pathToRun = "";48 std::string pathToRun = "";
51 for (auto &game : games) {49 for (auto &game : games) {
52 if (gameName == game.getName()) {50 if (gameName == game.getName()) {
@@ -56,7 +54,7 @@ void runGame(std::string gameName) {
56 system(pathToRun.c_str());54 system(pathToRun.c_str());
57 }55 }
58 56
59-void handleCommand(int argc, char const *argv[], Database& database) {57+auto handleCommand(int argc, char const *argv[], Database& database) -> void{
60 std::string command{};58 std::string command{};
61 switch (argc) {59 switch (argc) {
62 case 2:60 case 2:
@@ -99,7 +97,7 @@ void handleCommand(int argc, char const *argv[], Database& database) {
99 }97 }
100 }98 }
101 99
102-auto Style() -> ButtonOption {100+auto style() -> ButtonOption {
103 auto option = ButtonOption::Border();101 auto option = ButtonOption::Border();
104 option.transform = [](const EntryState &s) {102 option.transform = [](const EntryState &s) {
105 auto element = text(s.label);103 auto element = text(s.label);
@@ -123,12 +121,12 @@ auto runConsoleApp() -> void {
123 auto gamesContainer{Container::Vertical({})};121 auto gamesContainer{Container::Vertical({})};
124 for (auto &game : games) {122 for (auto &game : games) {
125 gamesContainer->Add(Button(123 gamesContainer->Add(Button(
126- game.getName(), [&] { runGame(game.getName()); }, Style()));124+ game.getName(), [&] { runGame(game.getName()); }, style()));
127 }125 }
128 126
129 auto menu_screen = ScreenInteractive::TerminalOutput();127 auto menu_screen = ScreenInteractive::TerminalOutput();
130 128
131- auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), Style());129+ auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), style());
132 gamesContainer->Add(quitButton);130 gamesContainer->Add(quitButton);
133 131
134 int menuOptionSelected{0};132 int menuOptionSelected{0};
@@ -149,7 +147,7 @@ auto runConsoleApp() -> void {
149 147
150 }148 }
151 149
152-std::filesystem::path getExecutablePath() {150+auto getExecutablePath() -> std::filesystem::path {
153 char result[PATH_MAX];151 char result[PATH_MAX];
154 ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);152 ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
155 return std::filesystem::path(std::string(result, (count > 0) ? count : 0));153 return std::filesystem::path(std::string(result, (count > 0) ? count : 0));