diff options
author | HampusM <hampus@hampusmat.com> | 2022-02-25 18:16:40 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:53 +0200 |
commit | e233dc28491c33e8a7dc0a11576d3b8ce91cce2c (patch) | |
tree | 40551d581baf43690eda5e0c3a7d083998136031 /src/game_of_life.cpp | |
parent | d36ec4670770022c0ec8337f6df4de292ca941db (diff) |
refactor: delete exception usages & game options
Diffstat (limited to 'src/game_of_life.cpp')
-rw-r--r-- | src/game_of_life.cpp | 30 |
1 files changed, 8 insertions, 22 deletions
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 <getopt.h> @@ -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<std::string_view>(argv, argv + argc); - GameOptions game_options; + std::shared_ptr<RandomNumberGenerator> random_gen = nullptr; char arg = 0; while ((arg = static_cast<char>( @@ -73,7 +63,7 @@ int main(int argc, char *argv[]) { auto seed = get_uint_optarg(arg, true); - game_options.random_gen = std::make_shared<RandomNumberGenerator>(seed); + random_gen = std::make_shared<RandomNumberGenerator>(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<RandomNumberGenerator>(); + random_gen = std::make_shared<RandomNumberGenerator>(); } - - // auto game = Game(game_options); - - // game.run(); } |