3#include <initializer_list>
7#include <nlohmann/json.hpp>
67 template<
typename T> T
require(std::string
const& key)
const;
70 template<
typename T> T
optional(std::string
const& key, T fallback)
const;
81 std::string
require_enum(std::string
const& key, std::initializer_list<char const*> allowed)
const;
106 std::string
const& key,
107 long long min = std::numeric_limits<long long>::min(),
108 long long max = std::numeric_limits<long long>::max()
113 std::string
const& key,
114 double min = -std::numeric_limits<double>::infinity(),
115 double max = std::numeric_limits<double>::infinity()
124 void only_keys(std::initializer_list<char const*> allowed)
const;
158 void forbid_key(std::string
const& key, std::string
const& reason)
const;
162 void expect_enum(std::string
const& key, std::initializer_list<char const*> allowed)
const {
166 std::string
const& key,
167 long long min = std::numeric_limits<long long>::min(),
168 long long max = std::numeric_limits<long long>::max()
173 std::string
const& key,
174 double min = -std::numeric_limits<double>::infinity(),
175 double max = std::numeric_limits<double>::infinity()
183 nlohmann::json
const&
json()
const {
return j_; }
186 std::string
const&
path()
const {
return path_; }
189 nlohmann::json
const& j_;
192 std::string child_path(std::string
const& key)
const;
193 nlohmann::json
const& require_present(std::string
const& key)
const;
T optional(std::string const &key, T fallback) const
Extract an optional typed value, falling back to fallback.
nlohmann::json const & json() const
The raw underlying JSON (escape hatch for unusual cases).
Definition JsonReader.hpp:183
void require_keys(std::initializer_list< char const * > keys) const
Assert every key in keys is present on the wrapped object.
void only_keys(std::initializer_list< char const * > allowed) const
Assert the wrapped object contains only the given keys.
double require_number(std::string const &key, double min=-std::numeric_limits< double >::infinity(), double max=std::numeric_limits< double >::infinity()) const
Extract a required number (double), optionally constrained.
void require_string_array(std::string const &key, bool non_empty=false) const
Assert key is an array of strings, optionally non-empty.
JsonReader(nlohmann::json const &j, std::string path)
void expect_array(std::string const &key) const
Definition JsonReader.hpp:179
long long require_int(std::string const &key, long long min=std::numeric_limits< long long >::min(), long long max=std::numeric_limits< long long >::max()) const
Extract a required integer value, optionally constrained.
void expect_int(std::string const &key, long long min=std::numeric_limits< long long >::min(), long long max=std::numeric_limits< long long >::max()) const
Definition JsonReader.hpp:165
void require_object() const
Assert the wrapped value is a JSON object.
void expect_enum(std::string const &key, std::initializer_list< char const * > allowed) const
Definition JsonReader.hpp:162
void expect_number(std::string const &key, double min=-std::numeric_limits< double >::infinity(), double max=std::numeric_limits< double >::infinity()) const
Definition JsonReader.hpp:172
void forbid_key(std::string const &key, std::string const &reason) const
Throw if key is present and non-null on the wrapped object.
nlohmann::json const & require_array(std::string const &key) const
Return a const reference to a required array field.
bool contains(std::string const &key) const
Whether key is present on the wrapped object.
std::string const & path() const
The path prefix used in error messages.
Definition JsonReader.hpp:186
JsonReader at(std::string const &key) const
Descend into a required sub-object.
T require(std::string const &key) const
Extract a required typed value.
std::string require_enum(std::string const &key, std::initializer_list< char const * > allowed) const
Extract a required string constrained to allowed values.
Binarization strategies for multiclass-to-binary reduction.
Definition Benchmark.hpp:25