diff options
| author | thecharlesblake | 2018-01-03 12:39:06 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-01-03 12:39:06 +0000 |
| commit | fa40f6facc5c500cae8bf890e66a7bf5d490387e (patch) | |
| tree | 9b3202e433e5151a38f78084ee843b20edec4f89 /src/main | |
| parent | Major refactor, putting pile logic into game_state (diff) | |
| download | metasol-fa40f6facc5c500cae8bf890e66a7bf5d490387e.tar.gz metasol-fa40f6facc5c500cae8bf890e66a7bf5d490387e.zip | |
Rename util to json_helper
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/game/sol_rules.cpp | 32 | ||||
| -rw-r--r-- | src/main/input-output/deal_parser.cpp | 6 | ||||
| -rw-r--r-- | src/main/input-output/json_helper.cpp (renamed from src/main/util/util.cpp) | 6 | ||||
| -rw-r--r-- | src/main/input-output/json_helper.h (renamed from src/main/util/util.h) | 2 | ||||
| -rw-r--r-- | src/main/main.cpp | 4 |
5 files changed, 25 insertions, 25 deletions
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index a1567f7..28c2af7 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -9,7 +9,7 @@ #include "rapidjson/error/en.h" #include "sol_rules.h" -#include "../util/util.h" +#include "../input-output/json_helper.h" #include "../input-output/sol_preset_types.h" using namespace std; @@ -24,7 +24,7 @@ typedef sol_rules::build_policy pol; const sol_rules sol_rules::from_file(const string rules_file) { sol_rules sr = get_default(); - Document d = util::get_file_json(rules_file); + Document d = json_helper::get_file_json(rules_file); modify_sol_rules(sr, d); @@ -59,7 +59,7 @@ sol_rules sol_rules::get_default() { void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (!d.IsObject()) { - util::json_parse_err("JSON doc must be object"); + json_helper::json_parse_err("JSON doc must be object"); } if (d.HasMember("tableau piles")) { @@ -69,7 +69,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (d["tableau piles"]["count"].IsInt()) { sr.tableau_pile_count = static_cast<uint8_t>(d["tableau piles"]["count"].GetInt()); } else { - util::json_parse_err("[tableau piles][count] must be an integer"); + json_helper::json_parse_err("[tableau piles][count] must be an integer"); } } @@ -82,11 +82,11 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { } else if (bo_str == "descending") { sr.build_ord = build_order::DESCENDING; } else { - util::json_parse_err("[tableau piles][build order] is invalid"); + json_helper::json_parse_err("[tableau piles][build order] is invalid"); } } else { - util::json_parse_err("[tableau piles][build order] must be an string"); + json_helper::json_parse_err("[tableau piles][build order] must be an string"); } } @@ -103,11 +103,11 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { } else if (bp_str == "no-build") { sr.build_pol = build_policy::NO_BUILD; } else { - util::json_parse_err("[tableau piles][build policy] is invalid"); + json_helper::json_parse_err("[tableau piles][build policy] is invalid"); } } else { - util::json_parse_err("[tableau piles][build policy] must be an string"); + json_helper::json_parse_err("[tableau piles][build policy] must be an string"); } } @@ -120,16 +120,16 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { } else if (sp_str == "no-build") { sr.spaces_pol = spaces_policy::NO_BUILD; } else { - util::json_parse_err("[tableau piles][spaces policy] is invalid"); + json_helper::json_parse_err("[tableau piles][spaces policy] is invalid"); } } else { - util::json_parse_err("[tableau piles][spaces policy] must be an string"); + json_helper::json_parse_err("[tableau piles][spaces policy] must be an string"); } } } else { - util::json_parse_err("[tableau piles] must be an object"); + json_helper::json_parse_err("[tableau piles] must be an object"); } } @@ -137,7 +137,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (d["max rank"].IsInt()) { sr.max_rank = static_cast<card::rank_t>(d["max rank"].GetInt()); } else { - util::json_parse_err("[max rank] must be an integer"); + json_helper::json_parse_err("[max rank] must be an integer"); } } @@ -145,7 +145,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (d["hole"].IsBool()) { sr.hole = d["hole"].GetBool(); } else { - util::json_parse_err("[hole] must be a boolean"); + json_helper::json_parse_err("[hole] must be a boolean"); } } @@ -153,7 +153,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (d["foundations"].IsBool()) { sr.foundations = d["foundations"].GetBool(); } else { - util::json_parse_err("[foundations] must be a boolean"); + json_helper::json_parse_err("[foundations] must be a boolean"); } } @@ -161,7 +161,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (d["cells"].IsInt()) { sr.cells = static_cast<uint8_t>(d["cells"].GetInt()); } else { - util::json_parse_err("[cells] must be an integer"); + json_helper::json_parse_err("[cells] must be an integer"); } } @@ -169,7 +169,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (d["stock size"].IsInt()) { sr.stock_size = static_cast<uint8_t>(d["stock size"].GetInt()); } else { - util::json_parse_err("[stock size] must be an integer"); + json_helper::json_parse_err("[stock size] must be an integer"); } } } diff --git a/src/main/input-output/deal_parser.cpp b/src/main/input-output/deal_parser.cpp index c876e91..8637649 100644 --- a/src/main/input-output/deal_parser.cpp +++ b/src/main/input-output/deal_parser.cpp @@ -4,7 +4,7 @@ #include "deal_parser.h" #include "../game/game_state.h" -#include "../util/util.h" +#include "json_helper.h" using namespace std; using namespace rapidjson; @@ -35,7 +35,7 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document& assert(json_tab_piles.IsArray()); if (gs.tableau_piles.size() != gs.rules.tableau_pile_count) { - util::json_parse_err("Incorrect number of tableau piles"); + json_helper::json_parse_err("Incorrect number of tableau piles"); } for (auto p = std::make_pair(begin(json_tab_piles.GetArray()), begin(gs.tableau_piles)); @@ -67,7 +67,7 @@ void deal_parser::parse_cells(game_state &gs, const Document& doc) { if (json_cell_arr.Empty()) return; else if (gs.rules.cells != json_cell_arr.Size()) { - util::json_parse_err("Incorrect number of cells"); + json_helper::json_parse_err("Incorrect number of cells"); } for (auto p = std::make_pair(begin(json_cell_arr), begin(gs.cells)); diff --git a/src/main/util/util.cpp b/src/main/input-output/json_helper.cpp index 7e7de8d..89f4564 100644 --- a/src/main/util/util.cpp +++ b/src/main/input-output/json_helper.cpp @@ -5,12 +5,12 @@ #include <fstream> #include <sstream> -#include "util.h" +#include "json_helper.h" using namespace std; using namespace rapidjson; -Document util::get_file_json(const string& filename) { +Document json_helper::get_file_json(const string& filename) { // Reads the file into a string std::ifstream ifstr(filename); std::stringstream buf; @@ -30,6 +30,6 @@ Document util::get_file_json(const string& filename) { } } -void util::json_parse_err(const string& msg) { +void json_helper::json_parse_err(const string& msg) { throw runtime_error("Error in JSON doc: " + msg); } diff --git a/src/main/util/util.h b/src/main/input-output/json_helper.h index de2a94d..5ab24bc 100644 --- a/src/main/util/util.h +++ b/src/main/input-output/json_helper.h @@ -9,7 +9,7 @@ #include <rapidjson/schema.h> -class util { +class json_helper { public: static rapidjson::Document get_file_json(const std::string&); static void json_parse_err(const std::string& msg); diff --git a/src/main/main.cpp b/src/main/main.cpp index e07e566..342cdd0 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -5,7 +5,7 @@ #include "input-output/command_line_helper.h" #include "solver/solver.h" #include "input-output/log_helper.h" -#include "util/util.h" +#include "input-output/json_helper.h" using namespace rapidjson; @@ -72,7 +72,7 @@ void solve_input_files(const vector<string> input_files, const sol_rules& rules) for (const string& input_file : input_files) { try { // Reads in the input file to a json doc - const Document in_doc = util::get_file_json(input_file); + const Document in_doc = json_helper::get_file_json(input_file); // Attempts to create a game state object from the json game_state gs(rules, in_doc); |
