From 5864e5abc43b201c3801fa39a2fcaf9e3a9e8914 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 27 Feb 2022 12:54:10 +0100 Subject: refactor: use dependency injection --- src/game_of_life.cpp | 97 +++++++++------------------------------------------- 1 file changed, 16 insertions(+), 81 deletions(-) (limited to 'src/game_of_life.cpp') diff --git a/src/game_of_life.cpp b/src/game_of_life.cpp index 3cd662b..9f7b019 100644 --- a/src/game_of_life.cpp +++ b/src/game_of_life.cpp @@ -1,94 +1,29 @@ -#include "conversion.hpp" -#include "randomization.hpp" +#include "bootstrap.hpp" +#include "interfaces/argument_parser.hpp" +#include "interfaces/randomization.hpp" #include -#include -#include -#include #include -namespace -{ -void optarg_error(char arg, const std::string_view &error) -{ - std::cout << "Error: Invalid option argument for -" << arg << ". " << error - << std::endl; - exit(EXIT_FAILURE); -} - -/** - * Returns the current optarg as a string view. - */ -std::string_view get_str_optarg() -{ - return std::string_view(optarg); -} - -/** - * Returns the current optarg as a unsigned integer. - * - * @param arg The current command-line argument character - * @param check_zero Whether or not to make sure that the result is not zero - */ -unsigned int get_uint_optarg(char arg, bool check_zero = false) -{ - auto conversion_result = str_to_uint(get_str_optarg()); - - if (!conversion_result.success || (check_zero && conversion_result.result == 0)) - { - optarg_error(arg, conversion_result.fail_reason); - } - - return conversion_result.result; -} -} // namespace - -constexpr std::array options = { - option({"seed", required_argument, nullptr, 's'}), - option({"help", no_argument, nullptr, 0}), option({nullptr, 0, nullptr, 0})}; +const std::vector