xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::json::decoder Namespace Reference

JSON decoder. More...

Classes

struct  AllowLegacyMicrosecondsTag
 Type used to specify that a time duration should allow a number of microseconds as well as a duration string. More...
 
class  Array
 An accessor used for reading the elements of a JSON array. More...
 
class  Document
 A JSON document. More...
 
class  Exception
 Mixin class for exceptions that occurred in a JSON document. More...
 
class  Location
 A class that can be used to log messages related to a specific line in a specific JSON document. More...
 
class  Name
 The name of a member of a JSON object. More...
 
class  NullValueError
 An Exception that is thrown when attempting to access a null value. More...
 
class  Object
 An accessor used for reading the members of a JSON object. More...
 
class  String
 An accessor used for reading a JSON string progressively. More...
 
class  SyntaxError
 An Exception that is thrown when a JSON stream is not valid. More...
 
class  TypeMismatchError
 An Exception that is thrown when a value has the wrong type. More...
 
class  Value
 A single value in a JSON document. More...
 

Typedefs

using Number = std::variant< std::intmax_t, std::uintmax_t, double >
 A generic number for decoding arbitrary numeric types from JSON documents.
 

Functions

template<typename StdException >
auto throwWithLocation (const Location &location, StdException &&exception)
 Throws an exception related to a location in a JSON document.
 
template<typename StdException >
auto throwWithLocation (std::reference_wrapper< const Document > document, StdException &&exception)
 Throws an exception related to the current line in a JSON document.
 
template<typename StdException >
auto throwWithLocation (std::reference_wrapper< const Document > document, std::uint_least32_t lineNumber, StdException &&exception)
 Throws an exception related to an arbitrary line in a JSON document.
 
template<typename StdException >
auto throwWithLocation (std::reference_wrapper< const Value > value, StdException &&exception)
 Throws an exception related to a JSON value.
 
template<typename StdException >
auto throwWithLocation (std::reference_wrapper< const Name > name, StdException &&exception)
 Throws an exception related to the name of a JSON object member.
 
template<typename StdException >
auto throwWithLocation (std::reference_wrapper< const Object > object, StdException &&exception)
 Throws an exception related to the an entire JSON object.
 
template<typename StdException >
auto throwWithLocation (std::reference_wrapper< const Array > array, StdException &&exception)
 Throws an exception related to the an entire JSON array.
 
template<typename StdException >
auto throwNestedWithLocation (const Location &location, StdException &&exception)
 Throws a nested exception related to a location in a JSON document.
 
template<typename StdException >
auto throwNestedWithLocation (std::reference_wrapper< const Document > document, StdException &&exception)
 Throws a nested exception related to the current line in a JSON document.
 
template<typename StdException >
auto throwNestedWithLocation (std::reference_wrapper< const Document > document, std::uint_least32_t lineNumber, StdException &&exception)
 Throws a nested exception related to an arbitrary line in a JSON document.
 
template<typename StdException >
auto throwNestedWithLocation (std::reference_wrapper< const Value > value, StdException &&exception)
 Throws a nested exception related to a JSON value.
 
template<typename StdException >
auto throwNestedWithLocation (std::reference_wrapper< const Name > name, StdException &&exception)
 Throws an exception related to the name of a JSON object member.
 
template<typename StdException >
auto throwNestedWithLocation (std::reference_wrapper< const Object > object, StdException &&exception)
 Throws an exception related to the an entire JSON object.
 
template<typename StdException >
auto throwNestedWithLocation (std::reference_wrapper< const Array > array, StdException &&exception)
 Throws an exception related to the an entire JSON array.
 

Variables

constexpr AllowLegacyMicrosecondsTag kAllowLegacyMicroseconds
 A marker used to specify that a time duration should allow a number of microseconds as well as a duration string.
 

Detailed Description

JSON decoder.

This namespace contains tools for parsing JSON formatted text data.

Typedef Documentation

◆ Number

A generic number for decoding arbitrary numeric types from JSON documents.

Include file
#include <xentara/utils/json/decoder/Types.hpp>

Function Documentation

◆ throwNestedWithLocation() [1/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwNestedWithLocation ( const Location location,
StdException &&  exception 
)

Throws a nested exception related to a location in a JSON document.

This function behaves just like throwWithLocation(), but throws the appropriate exception using std::throw_with_nested().

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
locationThe location
exceptionThe exception to throw

◆ throwNestedWithLocation() [2/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwNestedWithLocation ( std::reference_wrapper< const Array array,
StdException &&  exception 
)

Throws an exception related to the an entire JSON array.

This function behaves just like throwWithLocation(), but throws the appropriate exception using std::throw_with_nested().

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
arrayThe array
exceptionThe exception to throw

◆ throwNestedWithLocation() [3/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwNestedWithLocation ( std::reference_wrapper< const Document document,
std::uint_least32_t  lineNumber,
StdException &&  exception 
)

Throws a nested exception related to an arbitrary line in a JSON document.

This function behaves just like throwWithLocation(), but throws the appropriate exception using std::throw_with_nested().

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
documentThe document the error occurred in
lineNumberThe line number
exceptionThe exception to throw

◆ throwNestedWithLocation() [4/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwNestedWithLocation ( std::reference_wrapper< const Document document,
StdException &&  exception 
)

Throws a nested exception related to the current line in a JSON document.

This function behaves just like throwWithLocation(), but throws the appropriate exception using std::throw_with_nested().

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
documentThe document the error occurred in
exceptionThe exception to throw

◆ throwNestedWithLocation() [5/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwNestedWithLocation ( std::reference_wrapper< const Name name,
StdException &&  exception 
)

Throws an exception related to the name of a JSON object member.

This function behaves just like throwWithLocation(), but throws the appropriate exception using std::throw_with_nested().

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
nameThe name
exceptionThe exception to throw

◆ throwNestedWithLocation() [6/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwNestedWithLocation ( std::reference_wrapper< const Object object,
StdException &&  exception 
)

Throws an exception related to the an entire JSON object.

This function behaves just like throwWithLocation(), but throws the appropriate exception using std::throw_with_nested().

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
objectThe object
exceptionThe exception to throw

◆ throwNestedWithLocation() [7/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwNestedWithLocation ( std::reference_wrapper< const Value value,
StdException &&  exception 
)

Throws a nested exception related to a JSON value.

This function behaves just like throwWithLocation(), but throws the appropriate exception using std::throw_with_nested().

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
valueThe value
exceptionThe exception to throw

◆ throwWithLocation() [1/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwWithLocation ( const Location location,
StdException &&  exception 
)

Throws an exception related to a location in a JSON document.

If location contains a valid location, this function throws an exception of an internal type derived publicly both Exception and std::decay_t<StdException>. The what() string of the thrown exception is prefixed with the given location.

If location does not contain a valid location, exception is thrown as-is, without location information.

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
locationThe location
exceptionThe exception to throw

◆ throwWithLocation() [2/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwWithLocation ( std::reference_wrapper< const Array array,
StdException &&  exception 
)

Throws an exception related to the an entire JSON array.

This function throws an exception of an internal type derived publicly from both Exception and std::decay_t<StdException>. The what() string of the thrown exception is prefixed with the location of the begining of the given array.

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
arrayThe array
exceptionThe exception to throw

◆ throwWithLocation() [3/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwWithLocation ( std::reference_wrapper< const Document document,
std::uint_least32_t  lineNumber,
StdException &&  exception 
)

Throws an exception related to an arbitrary line in a JSON document.

If lineNumber is greater than 0, this function throws an exception of an internal type derived publicly from both Exception and std::decay_t<StdException>. The what() string of the thrown exception is prefixed with the given line number in the given document.

If lineNumber is 0, exception is thrown as-is, without location information.

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
documentThe document the error occurred in
lineNumberThe line number
exceptionThe exception to throw

◆ throwWithLocation() [4/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwWithLocation ( std::reference_wrapper< const Document document,
StdException &&  exception 
)

Throws an exception related to the current line in a JSON document.

This function throws an exception of an internal type derived publicly from both Exception and std::decay_t<StdException>. The what() string of the thrown exception is prefixed with the current line number in the given document.

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
documentThe document the error occurred in
exceptionThe exception to throw

◆ throwWithLocation() [5/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwWithLocation ( std::reference_wrapper< const Name name,
StdException &&  exception 
)

Throws an exception related to the name of a JSON object member.

If name is not default constructed, this function throws an exception of an internal type derived publicly from both Exception and std::decay_t<StdException>. The what() string of the thrown exception is prefixed with the location of the given name.

If name is default constructed, exception is thrown as-is, without location information.

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
nameThe name
exceptionThe exception to throw

◆ throwWithLocation() [6/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwWithLocation ( std::reference_wrapper< const Object object,
StdException &&  exception 
)

Throws an exception related to the an entire JSON object.

This function throws an exception of an internal type derived publicly from both Exception and std::decay_t<StdException>. The what() string of the thrown exception is prefixed with the location of the begining of the given object.

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
objectThe object
exceptionThe exception to throw

◆ throwWithLocation() [7/7]

template<typename StdException >
auto xentara::utils::json::decoder::throwWithLocation ( std::reference_wrapper< const Value value,
StdException &&  exception 
)

Throws an exception related to a JSON value.

If value is not default constructed, this function throws an exception of an internal type derived publicly from both Exception and std::decay_t<StdException>. The what() string of the thrown exception is prefixed with the location of the given value.

If value is default constructed, exception is thrown as-is, without location information.

Include file
#include <xentara/utils/json/decoder/Errors.hpp>
Parameters
valueThe value
exceptionThe exception to throw

Variable Documentation

◆ kAllowLegacyMicroseconds

constexpr AllowLegacyMicrosecondsTag xentara::utils::json::decoder::kAllowLegacyMicroseconds
constexpr

A marker used to specify that a time duration should allow a number of microseconds as well as a duration string.

This marker is used to select overloads of conversion functions that allow specifying a duration in a JSON file as a number instead of a string. This is used for backwards compatibility with older JSON formats that required duration to be specified as a numer of microseconds rather than a string.

See also
Value::toTimeDuration()