WPILibC++ 2023.4.3
json.h File Reference
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <limits>
#include <memory>
#include <span>
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "wpi/StringMap.h"

Go to the source code of this file.

Classes

struct  wpi::detail::is_json< typename >
 
struct  wpi::detail::is_json< json >
 
struct  wpi::detail::priority_tag< N >
 
struct  wpi::detail::priority_tag< 0 >
 
struct  wpi::detail::is_complete_type< T, typename >
 
struct  wpi::detail::is_complete_type< T, decltype(void(sizeof(T)))>
 
struct  wpi::detail::is_compatible_object_type_impl< B, RealType, CompatibleObjectType >
 
struct  wpi::detail::is_compatible_object_type_impl< true, RealType, CompatibleObjectType >
 
struct  wpi::detail::is_compatible_object_type< BasicJsonType, CompatibleObjectType >
 
struct  wpi::detail::is_json_nested_type< BasicJsonType, T >
 
struct  wpi::detail::is_compatible_array_type< BasicJsonType, CompatibleArrayType >
 
struct  wpi::detail::is_compatible_integer_type_impl< bool, typename, typename >
 
struct  wpi::detail::is_compatible_integer_type_impl< true, RealIntegerType, CompatibleNumberIntegerType >
 
struct  wpi::detail::is_compatible_integer_type< RealIntegerType, CompatibleNumberIntegerType >
 
struct  wpi::detail::has_from_json< BasicJsonType, T >
 
struct  wpi::detail::has_non_default_from_json< BasicJsonType, T >
 
struct  wpi::detail::has_to_json< BasicJsonType, T >
 
struct  wpi::detail::is_compatible_complete_type< BasicJsonType, CompatibleCompleteType >
 
struct  wpi::detail::is_compatible_type< BasicJsonType, CompatibleType >
 
struct  wpi::detail::static_const< T >
 
class  wpi::detail::exception
 general exception of the json class More...
 
class  wpi::detail::parse_error
 exception indicating a parse error More...
 
class  wpi::detail::invalid_iterator
 exception indicating errors with iterators More...
 
class  wpi::detail::type_error
 exception indicating executing a member function with a wrong type More...
 
class  wpi::detail::out_of_range
 exception indicating access out of the defined range More...
 
class  wpi::detail::other_error
 exception indicating other library errors More...
 
struct  wpi::detail::from_json_fn
 
struct  wpi::detail::external_constructor< value_t::boolean >
 
struct  wpi::detail::external_constructor< value_t::string >
 
struct  wpi::detail::external_constructor< value_t::number_float >
 
struct  wpi::detail::external_constructor< value_t::number_unsigned >
 
struct  wpi::detail::external_constructor< value_t::number_integer >
 
struct  wpi::detail::external_constructor< value_t::array >
 
struct  wpi::detail::external_constructor< value_t::object >
 
struct  wpi::detail::to_json_fn
 
class  wpi::detail::primitive_iterator_t
 
struct  wpi::detail::internal_iterator< BasicJsonType >
 an iterator value More...
 
class  wpi::detail::iter_impl< BasicJsonType >
 a template for a bidirectional iterator for the json class More...
 
class  wpi::detail::iteration_proxy< IteratorType >
 proxy class for the items() function More...
 
class  wpi::detail::json_reverse_iterator< Base >
 a template for a reverse iterator class More...
 
class  wpi::detail::json_ref< BasicJsonType >
 
class  wpi::json_pointer
 
struct  wpi::adl_serializer< typename, typename >
 default JSONSerializer template argument More...
 
class  wpi::json
 a class to store JSON values More...
 
struct  std::hash< wpi::json >
 hash value for JSON objects More...
 
struct  std::less< ::wpi::detail::value_t >
 specialization for std::less<value_t> More...
 

Namespaces

namespace  wpi
 /file This file defines the SmallVector class.
 
namespace  wpi::detail
 detail namespace with internal helper functions
 
namespace  std
 

Macros

#define NLOHMANN_JSON_VERSION_MAJOR   3
 
#define NLOHMANN_JSON_VERSION_MINOR   1
 
#define NLOHMANN_JSON_VERSION_PATCH   2
 
#define JSON_THROW(exception)   std::abort()
 
#define JSON_TRY   if(true)
 
#define JSON_CATCH(exception)   if(false)
 
#define JSON_LIKELY(x)   x
 
#define JSON_UNLIKELY(x)   x
 
#define NLOHMANN_JSON_HAS_HELPER(type)
 Helper to determine whether there's a key_type for T. More...
 

Typedefs

template<bool B, typename T = void>
using wpi::detail::enable_if_t = typename std::enable_if< B, T >::type
 
template<typename T >
using wpi::detail::uncvref_t = typename std::remove_cv< typename std::remove_reference< T >::type >::type
 

Enumerations

enum class  wpi::detail::value_t : std::uint8_t {
  wpi::detail::null , wpi::detail::object , wpi::detail::array , wpi::detail::string ,
  wpi::detail::boolean , wpi::detail::number_integer , wpi::detail::number_unsigned , wpi::detail::number_float ,
  wpi::detail::discarded
}
 the JSON type enumeration More...
 

Functions

 wpi::detail::NLOHMANN_JSON_HAS_HELPER (mapped_type)
 
 wpi::detail::NLOHMANN_JSON_HAS_HELPER (key_type)
 
 wpi::detail::NLOHMANN_JSON_HAS_HELPER (value_type)
 
 wpi::detail::NLOHMANN_JSON_HAS_HELPER (iterator)
 
bool wpi::detail::operator< (const value_t lhs, const value_t rhs) noexcept
 comparison operator for JSON types More...
 
template<typename BasicJsonType , typename ArithmeticType , enable_if_t< std::is_arithmetic< ArithmeticType >::value and not std::is_same< ArithmeticType, bool >::value, int > = 0>
void wpi::detail::get_arithmetic_value (const BasicJsonType &j, ArithmeticType &val)
 
template<typename BasicJsonType >
void wpi::detail::from_json (const BasicJsonType &j, bool &b)
 
template<typename BasicJsonType >
void wpi::detail::from_json (const BasicJsonType &j, std::string &s)
 
template<typename BasicJsonType >
void wpi::detail::from_json (const BasicJsonType &j, double &val)
 
template<typename BasicJsonType >
void wpi::detail::from_json (const BasicJsonType &j, uint64_t &val)
 
template<typename BasicJsonType >
void wpi::detail::from_json (const BasicJsonType &j, int64_t &val)
 
template<typename BasicJsonType , typename EnumType , enable_if_t< std::is_enum< EnumType >::value, int > = 0>
void wpi::detail::from_json (const BasicJsonType &j, EnumType &e)
 
template<typename BasicJsonType >
void wpi::detail::from_json (const BasicJsonType &j, typename BasicJsonType::array_t &arr)
 
template<typename BasicJsonType , typename CompatibleArrayType >
void wpi::detail::from_json_array_impl (const BasicJsonType &j, CompatibleArrayType &arr, priority_tag< 0 >)
 
template<typename BasicJsonType , typename CompatibleArrayType >
auto wpi::detail::from_json_array_impl (const BasicJsonType &j, CompatibleArrayType &arr, priority_tag< 1 >) -> decltype(arr.reserve(std::declval< typename CompatibleArrayType::size_type >()), void())
 
template<typename BasicJsonType , typename T , std::size_t N>
void wpi::detail::from_json_array_impl (const BasicJsonType &j, std::array< T, N > &arr, priority_tag< 2 >)
 
template<typename BasicJsonType , typename CompatibleArrayType , enable_if_t< is_compatible_array_type< BasicJsonType, CompatibleArrayType >::value and not std::is_same< typename BasicJsonType::array_t, CompatibleArrayType >::value and std::is_constructible< BasicJsonType, typename CompatibleArrayType::value_type >::value, int > = 0>
void wpi::detail::from_json (const BasicJsonType &j, CompatibleArrayType &arr)
 
template<typename BasicJsonType >
void wpi::detail::from_json (const BasicJsonType &j, typename BasicJsonType::object_t &obj)
 
template<typename BasicJsonType , typename CompatibleObjectType , enable_if_t< is_compatible_object_type< BasicJsonType, CompatibleObjectType >::value and not std::is_same< typename BasicJsonType::object_t, CompatibleObjectType >::value, int > = 0>
void wpi::detail::from_json (const BasicJsonType &j, CompatibleObjectType &obj)
 
template<typename BasicJsonType , typename ArithmeticType , enable_if_t< std::is_arithmetic< ArithmeticType >::value and not std::is_same< ArithmeticType, uint64_t >::value and not std::is_same< ArithmeticType, int64_t >::value and not std::is_same< ArithmeticType, double >::value and not std::is_same< ArithmeticType, bool >::value, int > = 0>
void wpi::detail::from_json (const BasicJsonType &j, ArithmeticType &val)
 
template<typename BasicJsonType , typename A1 , typename A2 >
void wpi::detail::from_json (const BasicJsonType &j, std::pair< A1, A2 > &p)
 
template<typename BasicJsonType , typename Tuple , std::size_t... Idx>
void wpi::detail::from_json_tuple_impl (const BasicJsonType &j, Tuple &t, std::index_sequence< Idx... >)
 
template<typename BasicJsonType , typename... Args>
void wpi::detail::from_json (const BasicJsonType &j, std::tuple< Args... > &t)
 
template<typename BasicJsonType , typename T , enable_if_t< std::is_same< T, bool >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, T b) noexcept
 
template<typename BasicJsonType , typename CompatibleString , enable_if_t< std::is_constructible< std::string_view, CompatibleString >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, const CompatibleString &s)
 
template<typename BasicJsonType , typename T , enable_if_t< std::is_same< std::string, T >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, T &&s)
 
template<typename BasicJsonType , typename FloatType , enable_if_t< std::is_floating_point< FloatType >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, FloatType val) noexcept
 
template<typename BasicJsonType , typename CompatibleNumberUnsignedType , enable_if_t< is_compatible_integer_type< uint64_t, CompatibleNumberUnsignedType >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, CompatibleNumberUnsignedType val) noexcept
 
template<typename BasicJsonType , typename CompatibleNumberIntegerType , enable_if_t< is_compatible_integer_type< int64_t, CompatibleNumberIntegerType >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, CompatibleNumberIntegerType val) noexcept
 
template<typename BasicJsonType , typename EnumType , enable_if_t< std::is_enum< EnumType >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, EnumType e) noexcept
 
template<typename BasicJsonType >
void wpi::detail::to_json (BasicJsonType &j, const std::vector< bool > &e)
 
template<typename BasicJsonType , typename CompatibleArrayType , enable_if_t< is_compatible_array_type< BasicJsonType, CompatibleArrayType >::value or std::is_same< typename BasicJsonType::array_t, CompatibleArrayType >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, const CompatibleArrayType &arr)
 
template<typename BasicJsonType >
void wpi::detail::to_json (BasicJsonType &j, typename BasicJsonType::array_t &&arr)
 
template<typename BasicJsonType , typename CompatibleObjectType , enable_if_t< is_compatible_object_type< BasicJsonType, CompatibleObjectType >::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, const CompatibleObjectType &obj)
 
template<typename BasicJsonType >
void wpi::detail::to_json (BasicJsonType &j, typename BasicJsonType::object_t &&obj)
 
template<typename BasicJsonType , typename T , std::size_t N, enable_if_t< not std::is_constructible< std::string_view, T(&)[N]>::value, int > = 0>
void wpi::detail::to_json (BasicJsonType &j, T(&arr)[N])
 
template<typename BasicJsonType , typename... Args>
void wpi::detail::to_json (BasicJsonType &j, const std::pair< Args... > &p)
 
template<typename BasicJsonType , typename Tuple , std::size_t... Idx>
void wpi::detail::to_json_tuple_impl (BasicJsonType &j, const Tuple &t, std::index_sequence< Idx... >)
 
template<typename BasicJsonType , typename... Args>
void wpi::detail::to_json (BasicJsonType &j, const std::tuple< Args... > &t)
 
template<>
void std::swap< wpi::json > (wpi::json &j1, wpi::json &j2) noexcept(is_nothrow_move_constructible< wpi::json >::value and is_nothrow_move_assignable< wpi::json >::value)
 exchanges the values of two JSON objects More...
 
wpi::json operator""_json (const char *s, std::size_t n)
 user-defined string literal for JSON values More...
 
wpi::json::json_pointer operator""_json_pointer (const char *s, std::size_t n)
 user-defined string literal for JSON pointer More...
 

Macro Definition Documentation

◆ JSON_CATCH

#define JSON_CATCH (   exception)    if(false)

◆ JSON_LIKELY

#define JSON_LIKELY (   x)    x

◆ JSON_THROW

#define JSON_THROW (   exception)    std::abort()

◆ JSON_TRY

#define JSON_TRY   if(true)

◆ JSON_UNLIKELY

#define JSON_UNLIKELY (   x)    x

◆ NLOHMANN_JSON_HAS_HELPER

#define NLOHMANN_JSON_HAS_HELPER (   type)
Value:
template<typename T> struct has_##type { \
private: \
template<typename U, typename = typename U::type> \
static int detect(U &&); \
static void detect(...); \
public: \
static constexpr bool value = \
std::is_integral<decltype(detect(std::declval<T>()))>::value; \
}
Definition: core.h:1240
type
Definition: core.h:575

Helper to determine whether there's a key_type for T.

This helper is used to tell associative containers apart from other containers such as sequence containers. For instance, std::map passes the test as it contains a mapped_type, whereas std::vector fails the test.

See also
http://stackoverflow.com/a/7728728/266378
Since
version 1.0.0, overworked in version 2.0.6

◆ NLOHMANN_JSON_VERSION_MAJOR

#define NLOHMANN_JSON_VERSION_MAJOR   3

◆ NLOHMANN_JSON_VERSION_MINOR

#define NLOHMANN_JSON_VERSION_MINOR   1

◆ NLOHMANN_JSON_VERSION_PATCH

#define NLOHMANN_JSON_VERSION_PATCH   2

Function Documentation

◆ operator""_json()

wpi::json operator""_json ( const char *  s,
std::size_t  n 
)
inline

user-defined string literal for JSON values

This operator implements a user-defined string literal for JSON objects. It can be used by adding "_json" to a string literal and returns a JSON object if no parse error occurred.

Parameters
[in]sa string representation of a JSON object
[in]nthe length of string s
Returns
a JSON object
Since
version 1.0.0

◆ operator""_json_pointer()

wpi::json::json_pointer operator""_json_pointer ( const char *  s,
std::size_t  n 
)
inline

user-defined string literal for JSON pointer

This operator implements a user-defined string literal for JSON Pointers. It can be used by adding "_json_pointer" to a string literal and returns a JSON pointer object if no parse error occurred.

Parameters
[in]sa string representation of a JSON Pointer
[in]nthe length of string s
Returns
a JSON pointer object
Since
version 2.0.0