Leosac
0.8.0
Open Source Access Control
|
Add a few useful extraction functions. More...
Functions | |
Auth::ValidityInfo | extract_validity_with_default (const nlohmann::json &obj, const std::string &base_key, const Auth::ValidityInfo &def) |
Extract fields representing a ValidityInfo object. More... | |
std::chrono::system_clock::time_point | extract_with_default (const nlohmann::json &obj, const std::string &key, const std::chrono::system_clock::time_point &tp) |
Extract an ISO 8601 datetime string from a json object. More... | |
template<typename T > | |
std::enable_if<!std::is_same< const char *, T >::value &&!std::is_same< std::chrono::system_clock::time_point, std::remove_reference_t< T > >::value &&!std::is_enum< T >::value, T >::type | extract_with_default (const nlohmann::json &obj, const std::string &key, T default_value) |
Extract the value of a key from a json object. More... | |
template<typename T > | |
std::enable_if< std::is_enum< T >::value, T >::type | extract_with_default (const nlohmann::json &obj, const std::string &key, T default_value) |
template<typename T > | |
std::enable_if< std::is_same< const char *, T >::value, std::string >::type | extract_with_default (const nlohmann::json &obj, const std::string &key, T default_value) |
Add a few useful extraction functions.
Some of theses are specific to Leosac.
Auth::ValidityInfo Leosac::JSONUtil::extract_validity_with_default | ( | const nlohmann::json & | obj, |
const std::string & | base_key, | ||
const Auth::ValidityInfo & | def | ||
) |
Extract fields representing a ValidityInfo object.
The JSON is expected to look like this:
${BASEKEY}-enabled
${BASEKEY}-start
${BASEKEY}-end
Definition at line 29 of file JSONUtils.cpp.
std::chrono::system_clock::time_point Leosac::JSONUtil::extract_with_default | ( | const nlohmann::json & | obj, |
const std::string & | key, | ||
const std::chrono::system_clock::time_point & | tp | ||
) |
Extract an ISO 8601 datetime string from a json object.
It returns its value as a C++ time_point object.
Definition at line 45 of file JSONUtils.cpp.
std::enable_if<!std::is_same<const char *, T>::value && !std::is_same<std::chrono::system_clock::time_point, std::remove_reference_t<T> >::value && !std::is_enum<T>::value, T>::type Leosac::JSONUtil::extract_with_default | ( | const nlohmann::json & | obj, |
const std::string & | key, | ||
T | default_value | ||
) |
Extract the value of a key from a json object.
If the key cannot be found, or if it is null, this function returns the default value instead.
Definition at line 110 of file JSONUtils.hpp.
std::enable_if<std::is_enum<T>::value, T>::type Leosac::JSONUtil::extract_with_default | ( | const nlohmann::json & | obj, |
const std::string & | key, | ||
T | default_value | ||
) |
Definition at line 127 of file JSONUtils.hpp.
std::enable_if<std::is_same<const char *, T>::value, std::string>::type Leosac::JSONUtil::extract_with_default | ( | const nlohmann::json & | obj, |
const std::string & | key, | ||
T | default_value | ||
) |
Definition at line 147 of file JSONUtils.hpp.