Leosac  0.8.0
Open Source Access Control
Leosac::JSONUtil Namespace Reference

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)
 

Detailed Description

Add a few useful extraction functions.

Some of theses are specific to Leosac.

Function Documentation

◆ extract_validity_with_default()

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.

◆ extract_with_default() [1/4]

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.

◆ extract_with_default() [2/4]

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 Leosac::JSONUtil::extract_with_default ( const nlohmann::json obj,
const std::string &  key,
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.

◆ extract_with_default() [3/4]

template<typename T >
std::enable_if<std::is_enum<T>::value, T>::type Leosac::JSONUtil::extract_with_default ( const nlohmann::json obj,
const std::string &  key,
default_value 
)

Definition at line 127 of file JSONUtils.hpp.

◆ extract_with_default() [4/4]

template<typename T >
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,
default_value 
)

Definition at line 147 of file JSONUtils.hpp.