From b8f4cae869eace06df73ac7c1c390cc42cfe499b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 26 Dec 2017 17:29:24 +0000 Subject: Add basic tableau deal parsing --- src/main/util/util.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/main/util/util.cpp') diff --git a/src/main/util/util.cpp b/src/main/util/util.cpp index 46038aa..7e7de8d 100644 --- a/src/main/util/util.cpp +++ b/src/main/util/util.cpp @@ -8,16 +8,28 @@ #include "util.h" using namespace std; -using namespace boost; +using namespace rapidjson; -const optional util::read_file(const string& filename) { - ifstream ifstr(filename); - stringstream buf; +Document util::get_file_json(const string& filename) { + // Reads the file into a string + std::ifstream ifstr(filename); + std::stringstream buf; buf << ifstr.rdbuf(); if (ifstr.fail()) { - return none; + throw runtime_error("could not read file " + filename); } else { - return buf.str(); + Document d; + + d.Parse(buf.str().c_str()); + if (d.HasParseError()) { + throw runtime_error(filename + " not valid json"); + } else { + return d; + } } } + +void util::json_parse_err(const string& msg) { + throw runtime_error("Error in JSON doc: " + msg); +} -- cgit v1.2.1