add set status for funsies
This commit is contained in:
@@ -37,7 +37,7 @@ inline void json_nullable(const ::nlohmann::json &j, const char *key, T &val) {
|
||||
if (!at.is_null())
|
||||
val = at.get<T::value_type>();
|
||||
else
|
||||
val = std::nullopt;
|
||||
val = ::std::nullopt;
|
||||
} else {
|
||||
const auto &at = j.at(key);
|
||||
if (!at.is_null())
|
||||
@@ -53,9 +53,9 @@ inline void json_optional_nullable(const ::nlohmann::json &j, const char *key, T
|
||||
if (!at.is_null())
|
||||
val = at.get<T::value_type>();
|
||||
else
|
||||
val = std::nullopt;
|
||||
val = ::std::nullopt;
|
||||
} else {
|
||||
val = std::nullopt;
|
||||
val = ::std::nullopt;
|
||||
}
|
||||
} else {
|
||||
if (j.contains(key)) {
|
||||
@@ -74,7 +74,7 @@ inline void json_update_optional_nullable(const ::nlohmann::json &j, const char
|
||||
if (!at.is_null())
|
||||
val = at.get<T::value_type>();
|
||||
else
|
||||
val = std::nullopt;
|
||||
val = ::std::nullopt;
|
||||
}
|
||||
} else {
|
||||
if (j.contains(key)) {
|
||||
@@ -109,32 +109,45 @@ inline void json_update_optional_nullable_default(const ::nlohmann::json &j, con
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
// get a json value that is guaranteed to be present and non-null
|
||||
#define JS_D(k, t) \
|
||||
do { \
|
||||
detail::json_direct(j, k, t); \
|
||||
} while (0)
|
||||
|
||||
// get a json value that may not be present
|
||||
#define JS_O(k, t) \
|
||||
do { \
|
||||
detail::json_optional(j, k, t); \
|
||||
} while (0)
|
||||
|
||||
// get a json value that may be null
|
||||
#define JS_N(k, t) \
|
||||
do { \
|
||||
detail::json_nullable(j, k, t); \
|
||||
} while (0)
|
||||
|
||||
// get a json value that may not be present or may be null
|
||||
#define JS_ON(k, t) \
|
||||
do { \
|
||||
detail::json_optional_nullable(j, k, t); \
|
||||
} while (0)
|
||||
|
||||
// set from a json value only if it is present. null will assign default-constructed value
|
||||
#define JS_RD(k, t) \
|
||||
do { \
|
||||
detail::json_update_optional_nullable(j, k, t); \
|
||||
} while (0)
|
||||
|
||||
// set from a json value only if it is present. null will assign the given default
|
||||
#define JS_RV(k, t, d) \
|
||||
do { \
|
||||
detail::json_update_optional_nullable_default(j, k, t, d); \
|
||||
} while (0)
|
||||
|
||||
// set a json value from a std::optional only if it has a value
|
||||
#define JS_IF(k, v) \
|
||||
do { \
|
||||
if (v.has_value()) \
|
||||
j[k] = *v; \
|
||||
} while (0)
|
||||
|
Reference in New Issue
Block a user