diff options
| author | thecharlesblake | 2017-12-26 17:29:24 +0000 |
|---|---|---|
| committer | thecharlesblake | 2017-12-26 17:29:24 +0000 |
| commit | b8f4cae869eace06df73ac7c1c390cc42cfe499b (patch) | |
| tree | 0440d8c082388f3fb04f7c977b16eeb4ddf024ef /src/main/util | |
| parent | Refactor game state to prep for deal parse (diff) | |
| download | metasol-b8f4cae869eace06df73ac7c1c390cc42cfe499b.tar.gz metasol-b8f4cae869eace06df73ac7c1c390cc42cfe499b.zip | |
Add basic tableau deal parsing
Diffstat (limited to 'src/main/util')
| -rw-r--r-- | src/main/util/util.cpp | 24 | ||||
| -rw-r--r-- | src/main/util/util.h | 5 |
2 files changed, 21 insertions, 8 deletions
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<string> 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); +} diff --git a/src/main/util/util.h b/src/main/util/util.h index 1721daa..de2a94d 100644 --- a/src/main/util/util.h +++ b/src/main/util/util.h @@ -7,11 +7,12 @@ #include <string> -#include <boost/optional.hpp> +#include <rapidjson/schema.h> class util { public: - static const boost::optional<std::string> read_file(const std::string&); + static rapidjson::Document get_file_json(const std::string&); + static void json_parse_err(const std::string& msg); }; |
