aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output/input/json-parsing/json_helper.cpp
diff options
context:
space:
mode:
authorthecharlesblake2018-01-03 13:05:31 +0000
committerthecharlesblake2018-01-03 13:05:31 +0000
commit7f4712b292632becfc83bc0e887271b25fefd21a (patch)
tree0dd0201057886c7fda86a53b447cce5d04948d25 /src/main/input-output/input/json-parsing/json_helper.cpp
parentTidy up card class (diff)
downloadmetasol-7f4712b292632becfc83bc0e887271b25fefd21a.tar.gz
metasol-7f4712b292632becfc83bc0e887271b25fefd21a.zip

Refactor io dir structure

Diffstat (limited to 'src/main/input-output/input/json-parsing/json_helper.cpp')
-rw-r--r--src/main/input-output/input/json-parsing/json_helper.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/input-output/input/json-parsing/json_helper.cpp b/src/main/input-output/input/json-parsing/json_helper.cpp
new file mode 100644
index 0000000..89f4564
--- /dev/null
+++ b/src/main/input-output/input/json-parsing/json_helper.cpp
@@ -0,0 +1,35 @@
+//
+// Created by thecharlesblake on 11/13/17.
+//
+
+#include <fstream>
+#include <sstream>
+
+#include "json_helper.h"
+
+using namespace std;
+using namespace rapidjson;
+
+Document json_helper::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()) {
+ throw runtime_error("could not read file " + filename);
+ } else {
+ Document d;
+
+ d.Parse(buf.str().c_str());
+ if (d.HasParseError()) {
+ throw runtime_error(filename + " not valid json");
+ } else {
+ return d;
+ }
+ }
+}
+
+void json_helper::json_parse_err(const string& msg) {
+ throw runtime_error("Error in JSON doc: " + msg);
+}