diff options
author | HampusM <hampus@hampusmat.com> | 2022-01-10 17:37:42 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-01-10 17:37:42 +0100 |
commit | e2e15bbf141b17b74b611e32a66891ab6ee331bb (patch) | |
tree | 861c71ae9a108d570aaee434044ada2a6816b657 /src | |
parent | 8ceb79db1d0687bba005cef4a77bb889bf7ec3c3 (diff) |
refactor: remove usage of the fmt lib & clean up
Diffstat (limited to 'src')
-rw-r--r-- | src/mazerator.cpp | 70 |
1 files changed, 27 insertions, 43 deletions
diff --git a/src/mazerator.cpp b/src/mazerator.cpp index 0927b4c..f74f952 100644 --- a/src/mazerator.cpp +++ b/src/mazerator.cpp @@ -1,8 +1,6 @@ -#include "fmt/core.h" #include "getopt.h" #include "matrix.hpp" #include "maze.hpp" -#include "stack.hpp" #include "utils.hpp" #include "vector2.hpp" #include <iostream> @@ -12,7 +10,7 @@ void optarg_error(char arg, std::string error) { - std::cout << fmt::format("Error: Invalid option argument for -{}. {}", arg, error) + std::cout << "Error: Invalid option argument for -" << arg << ". " << error << std::endl; exit(EXIT_FAILURE); } @@ -20,14 +18,12 @@ void optarg_error(char arg, std::string error) void validate_start_coords(unsigned int start_x, unsigned int start_y, unsigned int width, unsigned int height) { - std::string error_format = - "The {} start coordinate cannot be higher than or equal to the maze's {}"; - if (start_x >= width) - throw fmt::format(error_format, "x", "width"); + throw "The x start coordinate cannot be higher than or equal to the maze's width"; if (start_y >= height) - throw fmt::format(error_format, "y", "height"); + throw "The y start coordinate cannot be higher than or equal to the maze's " + "height"; } /** @@ -52,19 +48,6 @@ void parse_uint_arg(unsigned int *num_dst, char arg, bool check_zero = false) } } -/** - * Parses a unsigned integer command-line argument. - * - * @param num_dst A shared pointer to a place to store the result value - * @param arg The command-line argument character - */ -void parse_uint_arg(std::shared_ptr<unsigned int> num_dst, char arg) -{ - num_dst = std::make_shared<unsigned int>(); - - parse_uint_arg(num_dst.get(), arg); -} - const struct option options[] = {{"width", required_argument, NULL, 'w'}, {"height", required_argument, NULL, 'h'}, {"wall", required_argument, NULL, 'W'}, @@ -98,10 +81,12 @@ int main(int argc, char *argv[]) parse_uint_arg(&maze_height, arg, true); break; case 'x': - parse_uint_arg(start_x, arg); + start_x = std::make_shared<unsigned int>(); + parse_uint_arg(start_x.get(), arg); break; case 'y': - parse_uint_arg(start_y, arg); + start_y = std::make_shared<unsigned int>(); + parse_uint_arg(start_y.get(), arg); break; case 'W': wall = optarg; @@ -114,27 +99,26 @@ int main(int argc, char *argv[]) break; case 0: std::cout - << fmt::format( - "Usage: {} [OPTION]...\n\n" - "Options:\n" - " -w, --width WIDTH The width of the maze (Default: 40)\n" - " -h, --height HEIGHT The height of the maze (Default: 20)\n" - " -x, --start-x X The x coordinate for the start " - "position " - "(Default: random)\n" - " -y, --start-y Y The y coordinate for the start " - "position " - "(Default: random)\n" - " -W, --wall WALL Single character used as maze walls " - "(Default: '█')\n" - " -s, --seed SEED The randomization seed used for maze " - "generation\n" - " --help Displays usage information", - argv[0]) + << "Usage: " << argv[0] + << " [OPTION]...\n\n" + "Options:\n" + " -w, --width WIDTH The width of the maze (Default: 40)\n" + " -h, --height HEIGHT The height of the maze (Default: 20)\n" + " -x, --start-x X The x coordinate for the start " + "position " + "(Default: random)\n" + " -y, --start-y Y The y coordinate for the start " + "position " + "(Default: random)\n" + " -W, --wall WALL Single character used as maze walls " + "(Default: '█')\n" + " -s, --seed SEED The randomization seed used for maze " + "generation\n" + " --help Displays usage information" << std::endl; - exit(0); + return EXIT_SUCCESS; case '?': - std::cout << fmt::format("\nTry '{} --help' for more information", argv[0]) + std::cout << "\nTry '" << argv[0] << " --help' for more information" << std::endl; return EXIT_FAILURE; } @@ -166,7 +150,7 @@ int main(int argc, char *argv[]) { validate_start_coords(*start_x, *start_y, maze_width, maze_height); } - catch (std::string error) + catch (const char *error) { std::cout << "Error: " << error << std::endl; return EXIT_FAILURE; |