From 81fdc3f73a5d89e613c8e19f385c2144b35f6204 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 12:19:20 +0100 Subject: Add Spanish Paitence to cmd parse and refactor --- src/main/command_line_helper.cpp | 20 ++++++++++++-------- src/main/command_line_helper.h | 4 +++- src/main/main.cpp | 1 - 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/main/command_line_helper.cpp b/src/main/command_line_helper.cpp index fdf6c9c..22678af 100644 --- a/src/main/command_line_helper.cpp +++ b/src/main/command_line_helper.cpp @@ -14,6 +14,9 @@ using namespace std; namespace po = boost::program_options; +vector command_line_helper::valid_sol_types = + {"black-hole", "simple-black-hole", "spanish-patience"}; + command_line_helper::command_line_helper() : main_options("options"), random_deal(-1) { @@ -78,12 +81,12 @@ bool command_line_helper::assess_errors() { bool valid_sol_type = assess_sol_type(); if (!valid_sol_type) return false; - if (random_deal >= 0 && !input_files.empty()) { + if (random_deal != -1 && !input_files.empty()) { print_rand_plus_input_err(); return false; } - if (input_files.empty() && random_deal >= 0) { + if (input_files.empty() && random_deal == -1) { print_no_input_error(); return false; } @@ -91,21 +94,22 @@ bool command_line_helper::assess_errors() { } bool command_line_helper::assess_sol_type() { - if (solitaire_type == "black-hole") { - return true; - } else if (solitaire_type == "simple-black-hole") { + if (find(valid_sol_types.begin(), valid_sol_types.end(), solitaire_type) != + valid_sol_types.end()) { return true; } else { cerr << "Error: Solitaire type is not valid: " << solitaire_type - << "\nValid solitaire types are: 'black-hole' and " - "'simple-black-hole'"; + << "\nValid solitaire types are: "; + copy(begin(valid_sol_types), end(valid_sol_types), + ostream_iterator(cerr, ", ")); + cerr << "\n"; print_help(); return false; } } void command_line_helper::print_help() { - cout << "Usage: solvitaire [options] input-file1 input-file2 ...\n" + cerr << "Usage: solvitaire [options] input-file1 input-file2 ...\n" << main_options << "\n"; } diff --git a/src/main/command_line_helper.h b/src/main/command_line_helper.h index 5694830..47eef4c 100644 --- a/src/main/command_line_helper.h +++ b/src/main/command_line_helper.h @@ -16,13 +16,15 @@ public: int get_random_deal(); bool get_help(); private: + static std::vector valid_sol_types; + bool assess_errors(); bool assess_sol_type(); void print_help(); void print_no_input_error(); void print_no_sol_type_error(); void print_rand_plus_input_err(); - + boost::program_options::options_description cmdline_options; boost::program_options::options_description main_options; boost::program_options::positional_options_description p; diff --git a/src/main/main.cpp b/src/main/main.cpp index cc1df9f..245b737 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -4,7 +4,6 @@ #include #include "command_line_helper.h" -#include "card.h" #include "deal_parser.h" #include "game_state.h" #include "solver.h" -- cgit v1.2.1