updated returning type defining in functions
e10b023 parent: fb9ea54 modified
app/include/database.hpp +3 -5 | @@ -6,8 +6,6 @@ | ||
| 6 | 6 | class Database |
| 7 | 7 | { |
| 8 | 8 | private: |
| 9 | - | |
| 10 | - | |
| 11 | 9 | std::string database_initialization_command = |
| 12 | 10 | "CREATE TABLE games(" |
| 13 | 11 | "GAME_ID INTEGER PRIMARY KEY AUTOINCREMENT, " |
| @@ -26,7 +24,7 @@ public: | ||
| 26 | 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 | 28 | int exit = 0; |
| 31 | 29 | char *messageError; |
| 32 | 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 | 39 | execute_sql_command(database_initialization_command); |
| 42 | 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 | 44 | bool newCreation = not std::filesystem::exists(databasePath.string()); |
| 47 | 45 | |
| 48 | 46 | int exit = 0; |
| @@ -6,8 +6,6 @@ | |||
| 6 | class Database | 6 | 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: | ||
| 13 | 13 | : id{id}, name{name}, path{path} {} |
| 14 | 14 | ~Game() {} |
| 15 | 15 | |
| 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; } | |
| 19 | 19 | }; |
| @@ -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; | ||
| 25 | 25 | |
| 26 | 26 | bool debugRun = false; |
| 27 | 27 | |
| 28 | -void printMessage(std::string message) { | |
| 28 | +auto printMessage(std::string message) -> void { | |
| 29 | 29 | if (debugRun) { |
| 30 | 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 | 35 | std::string command = |
| 36 | 36 | "INSERT INTO games (GAME_NAME, GAME_PATH) VALUES ("; |
| 37 | 37 | command += "'" + name + "', \"" + path + "\");"; |
| 38 | 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 | 42 | std::string command = "DELETE FROM games WHERE GAME_NAME="; |
| 43 | 43 | command += "'" + name + "';"; |
| 44 | 44 | database.execute_sql_command(command); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - | |
| 48 | - | |
| 49 | -void runGame(std::string gameName) { | |
| 47 | +auto runGame(std::string gameName) -> void { | |
| 50 | 48 | std::string pathToRun = ""; |
| 51 | 49 | for (auto &game : games) { |
| 52 | 50 | if (gameName == game.getName()) { |
| @@ -56,7 +54,7 @@ void runGame(std::string gameName) { | ||
| 56 | 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 | 58 | std::string command{}; |
| 61 | 59 | switch (argc) { |
| 62 | 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 | 101 | auto option = ButtonOption::Border(); |
| 104 | 102 | option.transform = [](const EntryState &s) { |
| 105 | 103 | auto element = text(s.label); |
| @@ -123,12 +121,12 @@ auto runConsoleApp() -> void { | ||
| 123 | 121 | auto gamesContainer{Container::Vertical({})}; |
| 124 | 122 | for (auto &game : games) { |
| 125 | 123 | gamesContainer->Add(Button( |
| 126 | - game.getName(), [&] { runGame(game.getName()); }, Style())); | |
| 124 | + game.getName(), [&] { runGame(game.getName()); }, style())); | |
| 127 | 125 | } |
| 128 | 126 | |
| 129 | 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 | 130 | gamesContainer->Add(quitButton); |
| 133 | 131 | |
| 134 | 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 | 151 | char result[PATH_MAX]; |
| 154 | 152 | ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); |
| 155 | 153 | 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)); |