47 template<
typename BasicJsonType>
48 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t
b)
noexcept
50 j.m_value.destroy(j.m_type);
60 template<
typename BasicJsonType>
61 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
63 j.m_value.destroy(j.m_type);
69 template<
typename BasicJsonType>
70 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
72 j.m_value.destroy(j.m_type);
74 j.m_value = std::move(s);
78 template <
typename BasicJsonType,
typename CompatibleStringType,
81 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
83 j.m_value.destroy(j.m_type);
85 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
93 template<
typename BasicJsonType>
94 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t&
b)
96 j.m_value.destroy(j.m_type);
98 j.m_value =
typename BasicJsonType::binary_t(
b);
102 template<
typename BasicJsonType>
103 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&&
b)
105 j.m_value.destroy(j.m_type);
107 j.m_value =
typename BasicJsonType::binary_t(std::move(
b));
108 j.assert_invariant();
115 template<
typename BasicJsonType>
116 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
118 j.m_value.destroy(j.m_type);
121 j.assert_invariant();
128 template<
typename BasicJsonType>
129 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
131 j.m_value.destroy(j.m_type);
134 j.assert_invariant();
141 template<
typename BasicJsonType>
142 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
144 j.m_value.destroy(j.m_type);
147 j.assert_invariant();
154 template<
typename BasicJsonType>
155 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
157 j.m_value.destroy(j.m_type);
161 j.assert_invariant();
164 template<
typename BasicJsonType>
165 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
167 j.m_value.destroy(j.m_type);
169 j.m_value = std::move(arr);
171 j.assert_invariant();
174 template <
typename BasicJsonType,
typename CompatibleArrayType,
177 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
182 j.m_value.destroy(j.m_type);
184 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
186 j.assert_invariant();
189 template<
typename BasicJsonType>
190 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
192 j.m_value.destroy(j.m_type);
195 j.m_value.array->reserve(arr.size());
196 for (
const bool x : arr)
198 j.m_value.array->push_back(x);
199 j.set_parent(j.m_value.array->back());
201 j.assert_invariant();
204 template<
typename BasicJsonType,
typename T,
206 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
208 j.m_value.destroy(j.m_type);
211 j.m_value.array->resize(arr.size());
214 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
217 j.assert_invariant();
224 template<
typename BasicJsonType>
225 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
227 j.m_value.destroy(j.m_type);
231 j.assert_invariant();
234 template<
typename BasicJsonType>
235 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
237 j.m_value.destroy(j.m_type);
239 j.m_value = std::move(obj);
241 j.assert_invariant();
244 template <
typename BasicJsonType,
typename CompatibleObjectType,
246 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
251 j.m_value.destroy(j.m_type);
253 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
255 j.assert_invariant();
263template<
typename BasicJsonType,
typename T,
270template <
typename BasicJsonType,
typename BoolRef,
272 ((std::is_same<std::vector<bool>::reference, BoolRef>::value
273 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>::value)
274 || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
276 typename BasicJsonType::boolean_t >::value))
277 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
278inline void to_json(BasicJsonType& j,
const BoolRef&
b)
noexcept
283template<
typename BasicJsonType,
typename CompatibleString,
285inline void to_json(BasicJsonType& j,
const CompatibleString& s)
290template<
typename BasicJsonType>
291inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
296template<
typename BasicJsonType,
typename FloatType,
298inline void to_json(BasicJsonType& j, FloatType val)
noexcept
303template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
305inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
310template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
312inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
317#if !JSON_DISABLE_ENUM_SERIALIZATION
318template<
typename BasicJsonType,
typename EnumType,
320inline void to_json(BasicJsonType& j, EnumType
e)
noexcept
327template<
typename BasicJsonType>
328inline void to_json(BasicJsonType& j,
const std::vector<bool>&
e)
333template <
typename BasicJsonType,
typename CompatibleArrayType,
334 enable_if_t < is_compatible_array_type<BasicJsonType,
335 CompatibleArrayType>::value&&
336 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
338 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
339 !is_basic_json<CompatibleArrayType>::value,
341inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
346template<
typename BasicJsonType>
347inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
352template<
typename BasicJsonType,
typename T,
354inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
359template<
typename BasicJsonType>
360inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
365template <
typename BasicJsonType,
typename CompatibleObjectType,
367inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
372template<
typename BasicJsonType>
373inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
379 typename BasicJsonType,
typename T, std::size_t N,
380 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
381 const T(&)[N]>::value,
383inline void to_json(BasicJsonType& j,
const T(&arr)[N])
388template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
389inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
391 j = { p.first, p.second };
395template<
typename BasicJsonType,
typename T,
399 j = { {
b.key(),
b.value()} };
402template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
405 j = { std::get<Idx>(t)... };
408template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
409inline void to_json(BasicJsonType& j,
const T& t)
414#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
415template<
typename BasicJsonType>
416inline void to_json(BasicJsonType& j,
const std_fs::path& p)
424 template<
typename BasicJsonType,
typename T>
425 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(
to_json(j, std::forward<T>(val))))
426 ->
decltype(
to_json(j, std::forward<T>(val)), void())
428 return to_json(j, std::forward<T>(val));
433#ifndef JSON_HAS_CPP_17
442#ifndef JSON_HAS_CPP_17
#define WPI_JSON_NAMESPACE_END
Definition: abi_macros.h:59
#define WPI_JSON_NAMESPACE_BEGIN
Definition: abi_macros.h:53
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:256
#define JSON_INLINE_VARIABLE
Definition: macro_scope.h:139
detail namespace with internal helper functions
Definition: xchar.h:20
void to_json_tuple_impl(BasicJsonType &j, const Tuple &t, index_sequence< Idx... >)
Definition: to_json.h:403
auto copy(const Range &range, OutputIt out) -> OutputIt
Definition: ranges.h:26
void to_json(BasicJsonType &j, const T &b)
Definition: to_json.h:397
typename std::enable_if< B, T >::type enable_if_t
Definition: cpp_future.h:38
make_integer_sequence< size_t, N > make_index_sequence
Definition: ranges.h:201
value_t
the JSON type enumeration
Definition: value_t.h:54
@ number_integer
number value (signed integer)
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
void to_json(BasicJsonType &j, T b) noexcept
Definition: to_json.h:265
type
Definition: core.h:556
typename std::remove_cv< typename std::remove_reference< T >::type >::type uncvref_t
Definition: cpp_future.h:24
static constexpr const charge::coulomb_t e(1.6021766208e-19)
elementary charge.
array(T, Ts...) -> array< T, 1+sizeof...(Ts)>
static void construct(BasicJsonType &j, const std::vector< bool > &arr)
Definition: to_json.h:190
static void construct(BasicJsonType &j, typename BasicJsonType::array_t &&arr)
Definition: to_json.h:165
static void construct(BasicJsonType &j, const typename BasicJsonType::array_t &arr)
Definition: to_json.h:155
static void construct(BasicJsonType &j, const CompatibleArrayType &arr)
Definition: to_json.h:177
static void construct(BasicJsonType &j, const std::valarray< T > &arr)
Definition: to_json.h:206
static void construct(BasicJsonType &j, const typename BasicJsonType::binary_t &b)
Definition: to_json.h:94
static void construct(BasicJsonType &j, typename BasicJsonType::binary_t &&b)
Definition: to_json.h:103
static void construct(BasicJsonType &j, typename BasicJsonType::boolean_t b) noexcept
Definition: to_json.h:48
static void construct(BasicJsonType &j, typename BasicJsonType::number_float_t val) noexcept
Definition: to_json.h:116
static void construct(BasicJsonType &j, typename BasicJsonType::number_integer_t val) noexcept
Definition: to_json.h:142
static void construct(BasicJsonType &j, typename BasicJsonType::number_unsigned_t val) noexcept
Definition: to_json.h:129
static void construct(BasicJsonType &j, const typename BasicJsonType::object_t &obj)
Definition: to_json.h:225
static void construct(BasicJsonType &j, const CompatibleObjectType &obj)
Definition: to_json.h:246
static void construct(BasicJsonType &j, typename BasicJsonType::object_t &&obj)
Definition: to_json.h:235
static void construct(BasicJsonType &j, typename BasicJsonType::string_t &&s)
Definition: to_json.h:70
static void construct(BasicJsonType &j, const CompatibleStringType &str)
Definition: to_json.h:81
static void construct(BasicJsonType &j, const typename BasicJsonType::string_t &s)
Definition: to_json.h:61
static constexpr auto value
Definition: type_traits.h:350
Definition: cpp_future.h:155
Definition: to_json.h:423
auto operator()(BasicJsonType &j, T &&val) const noexcept(noexcept(to_json(j, std::forward< T >(val)))) -> decltype(to_json(j, std::forward< T >(val)), void())
Definition: to_json.h:425