Commit c8b9165f authored by Dominik Charousset's avatar Dominik Charousset

Use load_file instead of reading file manually

parent 23cb4188
...@@ -48,22 +48,17 @@ int caf_main(caf::actor_system& sys) { ...@@ -48,22 +48,17 @@ int caf_main(caf::actor_system& sys) {
// Get file path from config (positional argument). // Get file path from config (positional argument).
auto& cfg = sys.config(); auto& cfg = sys.config();
if (cfg.remainder.size() != 1) { if (cfg.remainder.size() != 1) {
std::cerr << "*** expected one positional argument: path to a JSON file\n"; std::cerr
<< "*** expected one positional argument: path to a JSON file\n"
<< "\n\nNote: expected a JSON list of user objects. For example:\n"
<< example_input << '\n';
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto& file_path = cfg.remainder[0]; auto& file_path = cfg.remainder[0];
// Read file into a string. // Read JSON-formatted file.
std::ifstream input{file_path};
if (!input) {
std::cerr << "*** unable to open input file '" << file_path << "'\n";
return EXIT_FAILURE;
}
std::string json{std::istreambuf_iterator<char>{input},
std::istreambuf_iterator<char>{}};
// Parse the JSON-formatted text.
caf::json_reader reader; caf::json_reader reader;
if (!reader.load(json)) { if (!reader.load_file(file_path)) {
std::cerr << "*** failed to parse JSON input: " std::cerr << "*** failed to parse JSON file: "
<< to_string(reader.get_error()) << '\n'; << to_string(reader.get_error()) << '\n';
return EXIT_FAILURE; return EXIT_FAILURE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment