From e233dc28491c33e8a7dc0a11576d3b8ce91cce2c Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 25 Feb 2022 18:16:40 +0100 Subject: refactor: delete exception usages & game options --- src/game_of_life.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/game_of_life.cpp') diff --git a/src/game_of_life.cpp b/src/game_of_life.cpp index 32d393e..3cd662b 100644 --- a/src/game_of_life.cpp +++ b/src/game_of_life.cpp @@ -1,5 +1,4 @@ #include "conversion.hpp" -#include "game/options.hpp" #include "randomization.hpp" #include @@ -33,23 +32,14 @@ std::string_view get_str_optarg() */ unsigned int get_uint_optarg(char arg, bool check_zero = false) { - unsigned int num = 0; + auto conversion_result = str_to_uint(get_str_optarg()); - try + if (!conversion_result.success || (check_zero && conversion_result.result == 0)) { - num = str_to_uint(get_str_optarg()); - - if (check_zero && num == 0) - { - throw "It should not be 0"; - } - } - catch (const char *error) - { - optarg_error(arg, std::string_view(error)); + optarg_error(arg, conversion_result.fail_reason); } - return num; + return conversion_result.result; } } // namespace @@ -61,7 +51,7 @@ int main(int argc, char *argv[]) { auto args = std::vector(argv, argv + argc); - GameOptions game_options; + std::shared_ptr random_gen = nullptr; char arg = 0; while ((arg = static_cast( @@ -73,7 +63,7 @@ int main(int argc, char *argv[]) { auto seed = get_uint_optarg(arg, true); - game_options.random_gen = std::make_shared(seed); + random_gen = std::make_shared(seed); break; } case 0: @@ -97,12 +87,8 @@ int main(int argc, char *argv[]) } } - if (game_options.random_gen == nullptr) + if (random_gen == nullptr) { - game_options.random_gen = std::make_shared(); + random_gen = std::make_shared(); } - - // auto game = Game(game_options); - - // game.run(); } -- cgit v1.2.3-18-g5258