#ifndef HELPERS_H_ #define HELPERS_H_ #include #include #include #include "json.hpp" // Reads configuration json from supplied filename // cfg - output json // filename - filepath from which to read json // log - ostream to log human readable errors to - can be nullptr // Returns - true if read and parse is successful bool read_config_json(nlohmann::json& cfg, const std::string& filename, std::ostream* log); // Reads configuration json from supplied istream // cfg - output json // in - istream from which to read json // log - ostream to log human readable errors to - can be nullptr // Returns - true if read and parse is successful bool read_config_json(nlohmann::json& cfg, std::istream& in, std::ostream* log); // JSON Extraction Helpers // out value is modified only if an extraction happened // Returns - whether an extraction happened bool json_extract(const nlohmann::json& j, const std::string& key, std::string& out); bool json_extract(const nlohmann::json& j, const std::string& key, int& out); bool json_extract(const nlohmann::json& j, const std::string& key, bool& out); bool json_extract(const nlohmann::json& j, const std::string& key, uint16_t& out); #endif // HELPERS_H_