💄 ran clang-tidy
This commit is contained in:
parent
9755cc75b1
commit
245a69d554
4 changed files with 174 additions and 266 deletions
170
src/json.hpp
170
src/json.hpp
|
@ -128,7 +128,7 @@ struct has_mapped_type
|
||||||
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief a class to store JSON values
|
@brief a class to store JSON values
|
||||||
|
@ -767,7 +767,7 @@ class basic_json
|
||||||
};
|
};
|
||||||
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
|
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
|
||||||
alloc.construct(object.get(), std::forward<Args>(args)...);
|
alloc.construct(object.get(), std::forward<Args>(args)...);
|
||||||
assert(object.get() != nullptr);
|
assert(object != nullptr);
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2583,30 +2583,26 @@ class basic_json
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
|
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
|
||||||
std::is_convertible<basic_json_t, typename T::mapped_type>::value, int>::type = 0>
|
std::is_convertible<basic_json_t, typename T::mapped_type>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_object())
|
if (is_object())
|
||||||
{
|
{
|
||||||
return T(m_value.object->begin(), m_value.object->end());
|
return T(m_value.object->begin(), m_value.object->end());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be object, but is " + type_name());
|
throw std::domain_error("type must be object, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an object (explicit)
|
/// get an object (explicit)
|
||||||
object_t get_impl(object_t*) const
|
object_t get_impl(object_t* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_object())
|
if (is_object())
|
||||||
{
|
{
|
||||||
return *(m_value.object);
|
return *(m_value.object);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be object, but is " + type_name());
|
throw std::domain_error("type must be object, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
|
@ -2615,7 +2611,7 @@ class basic_json
|
||||||
not std::is_arithmetic<T>::value and
|
not std::is_arithmetic<T>::value and
|
||||||
not std::is_convertible<std::string, T>::value and
|
not std::is_convertible<std::string, T>::value and
|
||||||
not has_mapped_type<T>::value, int>::type = 0>
|
not has_mapped_type<T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
|
@ -2627,17 +2623,15 @@ class basic_json
|
||||||
});
|
});
|
||||||
return to_vector;
|
return to_vector;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
std::is_convertible<basic_json_t, T>::value and
|
std::is_convertible<basic_json_t, T>::value and
|
||||||
not std::is_same<basic_json_t, T>::value, int>::type = 0>
|
not std::is_same<basic_json_t, T>::value, int>::type = 0>
|
||||||
std::vector<T> get_impl(std::vector<T>*) const
|
std::vector<T> get_impl(std::vector<T>* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
|
@ -2650,60 +2644,52 @@ class basic_json
|
||||||
});
|
});
|
||||||
return to_vector;
|
return to_vector;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
std::is_same<basic_json, typename T::value_type>::value and
|
std::is_same<basic_json, typename T::value_type>::value and
|
||||||
not has_mapped_type<T>::value, int>::type = 0>
|
not has_mapped_type<T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
return T(m_value.array->begin(), m_value.array->end());
|
return T(m_value.array->begin(), m_value.array->end());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
array_t get_impl(array_t*) const
|
array_t get_impl(array_t* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
return *(m_value.array);
|
return *(m_value.array);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get a string (explicit)
|
/// get a string (explicit)
|
||||||
template<typename T, typename std::enable_if<
|
template<typename T, typename std::enable_if<
|
||||||
std::is_convertible<string_t, T>::value, int>::type = 0>
|
std::is_convertible<string_t, T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_string())
|
if (is_string())
|
||||||
{
|
{
|
||||||
return *m_value.string;
|
return *m_value.string;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be string, but is " + type_name());
|
throw std::domain_error("type must be string, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get a number (explicit)
|
/// get a number (explicit)
|
||||||
template<typename T, typename std::enable_if<
|
template<typename T, typename std::enable_if<
|
||||||
std::is_arithmetic<T>::value, int>::type = 0>
|
std::is_arithmetic<T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
|
@ -2730,7 +2716,7 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a boolean (explicit)
|
/// get a boolean (explicit)
|
||||||
constexpr boolean_t get_impl(boolean_t*) const
|
constexpr boolean_t get_impl(boolean_t* /*unused*/) const
|
||||||
{
|
{
|
||||||
return is_boolean()
|
return is_boolean()
|
||||||
? m_value.boolean
|
? m_value.boolean
|
||||||
|
@ -2738,85 +2724,85 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (object)
|
/// get a pointer to the value (object)
|
||||||
object_t* get_impl_ptr(object_t*) noexcept
|
object_t* get_impl_ptr(object_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_object() ? m_value.object : nullptr;
|
return is_object() ? m_value.object : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (object)
|
/// get a pointer to the value (object)
|
||||||
constexpr const object_t* get_impl_ptr(const object_t*) const noexcept
|
constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_object() ? m_value.object : nullptr;
|
return is_object() ? m_value.object : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (array)
|
/// get a pointer to the value (array)
|
||||||
array_t* get_impl_ptr(array_t*) noexcept
|
array_t* get_impl_ptr(array_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_array() ? m_value.array : nullptr;
|
return is_array() ? m_value.array : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (array)
|
/// get a pointer to the value (array)
|
||||||
constexpr const array_t* get_impl_ptr(const array_t*) const noexcept
|
constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_array() ? m_value.array : nullptr;
|
return is_array() ? m_value.array : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (string)
|
/// get a pointer to the value (string)
|
||||||
string_t* get_impl_ptr(string_t*) noexcept
|
string_t* get_impl_ptr(string_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_string() ? m_value.string : nullptr;
|
return is_string() ? m_value.string : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (string)
|
/// get a pointer to the value (string)
|
||||||
constexpr const string_t* get_impl_ptr(const string_t*) const noexcept
|
constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_string() ? m_value.string : nullptr;
|
return is_string() ? m_value.string : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (boolean)
|
/// get a pointer to the value (boolean)
|
||||||
boolean_t* get_impl_ptr(boolean_t*) noexcept
|
boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_boolean() ? &m_value.boolean : nullptr;
|
return is_boolean() ? &m_value.boolean : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (boolean)
|
/// get a pointer to the value (boolean)
|
||||||
constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
|
constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_boolean() ? &m_value.boolean : nullptr;
|
return is_boolean() ? &m_value.boolean : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (integer number)
|
/// get a pointer to the value (integer number)
|
||||||
number_integer_t* get_impl_ptr(number_integer_t*) noexcept
|
number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_number_integer() ? &m_value.number_integer : nullptr;
|
return is_number_integer() ? &m_value.number_integer : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (integer number)
|
/// get a pointer to the value (integer number)
|
||||||
constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
|
constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_integer() ? &m_value.number_integer : nullptr;
|
return is_number_integer() ? &m_value.number_integer : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (unsigned number)
|
/// get a pointer to the value (unsigned number)
|
||||||
number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
|
number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (unsigned number)
|
/// get a pointer to the value (unsigned number)
|
||||||
constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
|
constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (floating-point number)
|
/// get a pointer to the value (floating-point number)
|
||||||
number_float_t* get_impl_ptr(number_float_t*) noexcept
|
number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_number_float() ? &m_value.number_float : nullptr;
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (floating-point number)
|
/// get a pointer to the value (floating-point number)
|
||||||
constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
|
constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_float() ? &m_value.number_float : nullptr;
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
}
|
}
|
||||||
|
@ -2845,12 +2831,10 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *ptr;
|
return *ptr;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
|
throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
|
||||||
obj.type_name());
|
obj.type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -3349,11 +3333,9 @@ class basic_json
|
||||||
|
|
||||||
return m_value.array->operator[](idx);
|
return m_value.array->operator[](idx);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified array element
|
@brief access specified array element
|
||||||
|
@ -3381,11 +3363,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.array->operator[](idx);
|
return m_value.array->operator[](idx);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified object element
|
@brief access specified object element
|
||||||
|
@ -3429,11 +3409,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.object->operator[](key);
|
return m_value.object->operator[](key);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief read-only access specified object element
|
@brief read-only access specified object element
|
||||||
|
@ -3473,11 +3451,9 @@ class basic_json
|
||||||
assert(m_value.object->find(key) != m_value.object->end());
|
assert(m_value.object->find(key) != m_value.object->end());
|
||||||
return m_value.object->find(key)->second;
|
return m_value.object->find(key)->second;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified object element
|
@brief access specified object element
|
||||||
|
@ -3590,11 +3566,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.object->operator[](key);
|
return m_value.object->operator[](key);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief read-only access specified object element
|
@brief read-only access specified object element
|
||||||
|
@ -3635,11 +3609,9 @@ class basic_json
|
||||||
assert(m_value.object->find(key) != m_value.object->end());
|
assert(m_value.object->find(key) != m_value.object->end());
|
||||||
return m_value.object->find(key)->second;
|
return m_value.object->find(key)->second;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified object element with default value
|
@brief access specified object element with default value
|
||||||
|
@ -3702,11 +3674,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return default_value;
|
return default_value;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw std::domain_error("cannot use value() with " + type_name());
|
throw std::domain_error("cannot use value() with " + type_name());
|
||||||
|
@ -4131,11 +4101,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.object->erase(key);
|
return m_value.object->erase(key);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use erase() with " + type_name());
|
throw std::domain_error("cannot use erase() with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief remove element from a JSON array given an index
|
@brief remove element from a JSON array given an index
|
||||||
|
@ -5186,11 +5154,9 @@ class basic_json
|
||||||
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
|
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use insert() with " + type_name());
|
throw std::domain_error("cannot use insert() with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief inserts element
|
@brief inserts element
|
||||||
|
@ -5241,11 +5207,9 @@ class basic_json
|
||||||
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
|
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use insert() with " + type_name());
|
throw std::domain_error("cannot use insert() with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief inserts elements
|
@brief inserts elements
|
||||||
|
@ -6122,7 +6086,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
// assertion to check that the iterator range is indeed contiguous,
|
// assertion to check that the iterator range is indeed contiguous,
|
||||||
// see http://stackoverflow.com/a/35008842/266378 for more discussion
|
// see http://stackoverflow.com/a/35008842/266378 for more discussion
|
||||||
assert(std::accumulate(first, last, std::make_pair<bool, int>(true, 0),
|
assert(std::accumulate(first, last, std::pair<bool, int>(true, 0),
|
||||||
[&first](std::pair<bool, int> res, decltype(*first) val)
|
[&first](std::pair<bool, int> res, decltype(*first) val)
|
||||||
{
|
{
|
||||||
res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
|
res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
|
||||||
|
@ -6327,7 +6291,7 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
T result;
|
T result;
|
||||||
uint8_t* ptr = reinterpret_cast<uint8_t*>(&result);
|
auto* ptr = reinterpret_cast<uint8_t*>(&result);
|
||||||
for (size_t i = 0; i < sizeof(T); ++i)
|
for (size_t i = 0; i < sizeof(T); ++i)
|
||||||
{
|
{
|
||||||
*ptr++ = vec[current_index + sizeof(T) - i];
|
*ptr++ = vec[current_index + sizeof(T) - i];
|
||||||
|
@ -6473,7 +6437,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
// float 64
|
// float 64
|
||||||
v.push_back(0xcb);
|
v.push_back(0xcb);
|
||||||
const uint8_t* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
const auto* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
||||||
for (size_t i = 0; i < 8; ++i)
|
for (size_t i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
v.push_back(helper[7 - i]);
|
v.push_back(helper[7 - i]);
|
||||||
|
@ -6716,7 +6680,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
// Double-Precision Float
|
// Double-Precision Float
|
||||||
v.push_back(0xfb);
|
v.push_back(0xfb);
|
||||||
const uint8_t* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
const auto* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
||||||
for (size_t i = 0; i < 8; ++i)
|
for (size_t i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
v.push_back(helper[7 - i]);
|
v.push_back(helper[7 - i]);
|
||||||
|
@ -6916,7 +6880,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
return v[current_idx];
|
return v[current_idx];
|
||||||
}
|
}
|
||||||
else if (v[current_idx] <= 0x8f) // fixmap
|
if (v[current_idx] <= 0x8f) // fixmap
|
||||||
{
|
{
|
||||||
basic_json result = value_t::object;
|
basic_json result = value_t::object;
|
||||||
const size_t len = v[current_idx] & 0x0f;
|
const size_t len = v[current_idx] & 0x0f;
|
||||||
|
@ -7577,7 +7541,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
val = mant == 0 ? INFINITY : NAN;
|
val = mant == 0 ? INFINITY : NAN;
|
||||||
}
|
}
|
||||||
return half & 0x8000 ? -val : val;
|
return (half & 0x8000) != 0 ? -val : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0xfa: // Single-Precision Float (four-byte IEEE 754)
|
case 0xfa: // Single-Precision Float (four-byte IEEE 754)
|
||||||
|
@ -7800,12 +7764,10 @@ class basic_json
|
||||||
// from c (1 byte) to \uxxxx (6 bytes)
|
// from c (1 byte) to \uxxxx (6 bytes)
|
||||||
return res + 5;
|
return res + 5;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8509,13 +8471,11 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *m_object;
|
return *m_object;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::out_of_range("cannot get value");
|
throw std::out_of_range("cannot get value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief dereference the iterator
|
@brief dereference the iterator
|
||||||
|
@ -8545,13 +8505,11 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_object;
|
return m_object;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::out_of_range("cannot get value");
|
throw std::out_of_range("cannot get value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief post-increment (it++)
|
@brief post-increment (it++)
|
||||||
|
@ -8861,13 +8819,11 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *m_object;
|
return *m_object;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::out_of_range("cannot get value");
|
throw std::out_of_range("cannot get value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief return the key of an object iterator
|
@brief return the key of an object iterator
|
||||||
|
@ -8881,11 +8837,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_it.object_iterator->first;
|
return m_it.object_iterator->first;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use key() for non-object iterators");
|
throw std::domain_error("cannot use key() for non-object iterators");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief return the value of an iterator
|
@brief return the value of an iterator
|
||||||
|
@ -10209,7 +10163,7 @@ basic_json_parser_66:
|
||||||
assert(m_marker == nullptr or m_marker <= m_limit);
|
assert(m_marker == nullptr or m_marker <= m_limit);
|
||||||
|
|
||||||
// number of processed characters (p)
|
// number of processed characters (p)
|
||||||
const size_t num_processed_chars = static_cast<size_t>(m_start - m_content);
|
const auto num_processed_chars = static_cast<size_t>(m_start - m_content);
|
||||||
// offset for m_marker wrt. to m_start
|
// offset for m_marker wrt. to m_start
|
||||||
const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start;
|
const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start;
|
||||||
// number of unprocessed characters (u)
|
// number of unprocessed characters (u)
|
||||||
|
@ -10601,7 +10555,7 @@ basic_json_parser_66:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// parse with strtod
|
// parse with strtod
|
||||||
result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), NULL);
|
result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), nullptr);
|
||||||
|
|
||||||
// replace infinity and NAN by null
|
// replace infinity and NAN by null
|
||||||
if (not std::isfinite(result.m_value.number_float))
|
if (not std::isfinite(result.m_value.number_float))
|
||||||
|
@ -11336,7 +11290,7 @@ basic_json_parser_66:
|
||||||
// - start: position after the previous slash
|
// - start: position after the previous slash
|
||||||
for (
|
for (
|
||||||
// search for the first slash after the first character
|
// search for the first slash after the first character
|
||||||
size_t slash = reference_string.find_first_of("/", 1),
|
size_t slash = reference_string.find_first_of('/', 1),
|
||||||
// set the beginning of the first reference token
|
// set the beginning of the first reference token
|
||||||
start = 1;
|
start = 1;
|
||||||
// we can stop if start == string::npos+1 = 0
|
// we can stop if start == string::npos+1 = 0
|
||||||
|
@ -11345,16 +11299,16 @@ basic_json_parser_66:
|
||||||
// (will eventually be 0 if slash == std::string::npos)
|
// (will eventually be 0 if slash == std::string::npos)
|
||||||
start = slash + 1,
|
start = slash + 1,
|
||||||
// find next slash
|
// find next slash
|
||||||
slash = reference_string.find_first_of("/", start))
|
slash = reference_string.find_first_of('/', start))
|
||||||
{
|
{
|
||||||
// use the text between the beginning of the reference token
|
// use the text between the beginning of the reference token
|
||||||
// (start) and the last slash (slash).
|
// (start) and the last slash (slash).
|
||||||
auto reference_token = reference_string.substr(start, slash - start);
|
auto reference_token = reference_string.substr(start, slash - start);
|
||||||
|
|
||||||
// check reference tokens are properly escaped
|
// check reference tokens are properly escaped
|
||||||
for (size_t pos = reference_token.find_first_of("~");
|
for (size_t pos = reference_token.find_first_of('~');
|
||||||
pos != std::string::npos;
|
pos != std::string::npos;
|
||||||
pos = reference_token.find_first_of("~", pos + 1))
|
pos = reference_token.find_first_of('~', pos + 1))
|
||||||
{
|
{
|
||||||
assert(reference_token[pos] == '~');
|
assert(reference_token[pos] == '~');
|
||||||
|
|
||||||
|
@ -12188,7 +12142,7 @@ uses the standard template types.
|
||||||
@since version 1.0.0
|
@since version 1.0.0
|
||||||
*/
|
*/
|
||||||
using json = basic_json<>;
|
using json = basic_json<>;
|
||||||
}
|
} // namespace nlohmann
|
||||||
|
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
|
@ -12229,7 +12183,7 @@ struct hash<nlohmann::json>
|
||||||
return h(j.dump());
|
return h(j.dump());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace std
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief user-defined string literal for JSON values
|
@brief user-defined string literal for JSON values
|
||||||
|
|
|
@ -128,7 +128,7 @@ struct has_mapped_type
|
||||||
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
std::is_integral<decltype(detect(std::declval<T>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief a class to store JSON values
|
@brief a class to store JSON values
|
||||||
|
@ -767,7 +767,7 @@ class basic_json
|
||||||
};
|
};
|
||||||
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
|
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
|
||||||
alloc.construct(object.get(), std::forward<Args>(args)...);
|
alloc.construct(object.get(), std::forward<Args>(args)...);
|
||||||
assert(object.get() != nullptr);
|
assert(object != nullptr);
|
||||||
return object.release();
|
return object.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2583,30 +2583,26 @@ class basic_json
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
|
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
|
||||||
std::is_convertible<basic_json_t, typename T::mapped_type>::value, int>::type = 0>
|
std::is_convertible<basic_json_t, typename T::mapped_type>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_object())
|
if (is_object())
|
||||||
{
|
{
|
||||||
return T(m_value.object->begin(), m_value.object->end());
|
return T(m_value.object->begin(), m_value.object->end());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be object, but is " + type_name());
|
throw std::domain_error("type must be object, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an object (explicit)
|
/// get an object (explicit)
|
||||||
object_t get_impl(object_t*) const
|
object_t get_impl(object_t* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_object())
|
if (is_object())
|
||||||
{
|
{
|
||||||
return *(m_value.object);
|
return *(m_value.object);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be object, but is " + type_name());
|
throw std::domain_error("type must be object, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
|
@ -2615,7 +2611,7 @@ class basic_json
|
||||||
not std::is_arithmetic<T>::value and
|
not std::is_arithmetic<T>::value and
|
||||||
not std::is_convertible<std::string, T>::value and
|
not std::is_convertible<std::string, T>::value and
|
||||||
not has_mapped_type<T>::value, int>::type = 0>
|
not has_mapped_type<T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
|
@ -2627,17 +2623,15 @@ class basic_json
|
||||||
});
|
});
|
||||||
return to_vector;
|
return to_vector;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
std::is_convertible<basic_json_t, T>::value and
|
std::is_convertible<basic_json_t, T>::value and
|
||||||
not std::is_same<basic_json_t, T>::value, int>::type = 0>
|
not std::is_same<basic_json_t, T>::value, int>::type = 0>
|
||||||
std::vector<T> get_impl(std::vector<T>*) const
|
std::vector<T> get_impl(std::vector<T>* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
|
@ -2650,60 +2644,52 @@ class basic_json
|
||||||
});
|
});
|
||||||
return to_vector;
|
return to_vector;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
template<class T, typename std::enable_if<
|
template<class T, typename std::enable_if<
|
||||||
std::is_same<basic_json, typename T::value_type>::value and
|
std::is_same<basic_json, typename T::value_type>::value and
|
||||||
not has_mapped_type<T>::value, int>::type = 0>
|
not has_mapped_type<T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
return T(m_value.array->begin(), m_value.array->end());
|
return T(m_value.array->begin(), m_value.array->end());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get an array (explicit)
|
/// get an array (explicit)
|
||||||
array_t get_impl(array_t*) const
|
array_t get_impl(array_t* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_array())
|
if (is_array())
|
||||||
{
|
{
|
||||||
return *(m_value.array);
|
return *(m_value.array);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be array, but is " + type_name());
|
throw std::domain_error("type must be array, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get a string (explicit)
|
/// get a string (explicit)
|
||||||
template<typename T, typename std::enable_if<
|
template<typename T, typename std::enable_if<
|
||||||
std::is_convertible<string_t, T>::value, int>::type = 0>
|
std::is_convertible<string_t, T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
if (is_string())
|
if (is_string())
|
||||||
{
|
{
|
||||||
return *m_value.string;
|
return *m_value.string;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("type must be string, but is " + type_name());
|
throw std::domain_error("type must be string, but is " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// get a number (explicit)
|
/// get a number (explicit)
|
||||||
template<typename T, typename std::enable_if<
|
template<typename T, typename std::enable_if<
|
||||||
std::is_arithmetic<T>::value, int>::type = 0>
|
std::is_arithmetic<T>::value, int>::type = 0>
|
||||||
T get_impl(T*) const
|
T get_impl(T* /*unused*/) const
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
|
@ -2730,7 +2716,7 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a boolean (explicit)
|
/// get a boolean (explicit)
|
||||||
constexpr boolean_t get_impl(boolean_t*) const
|
constexpr boolean_t get_impl(boolean_t* /*unused*/) const
|
||||||
{
|
{
|
||||||
return is_boolean()
|
return is_boolean()
|
||||||
? m_value.boolean
|
? m_value.boolean
|
||||||
|
@ -2738,85 +2724,85 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (object)
|
/// get a pointer to the value (object)
|
||||||
object_t* get_impl_ptr(object_t*) noexcept
|
object_t* get_impl_ptr(object_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_object() ? m_value.object : nullptr;
|
return is_object() ? m_value.object : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (object)
|
/// get a pointer to the value (object)
|
||||||
constexpr const object_t* get_impl_ptr(const object_t*) const noexcept
|
constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_object() ? m_value.object : nullptr;
|
return is_object() ? m_value.object : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (array)
|
/// get a pointer to the value (array)
|
||||||
array_t* get_impl_ptr(array_t*) noexcept
|
array_t* get_impl_ptr(array_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_array() ? m_value.array : nullptr;
|
return is_array() ? m_value.array : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (array)
|
/// get a pointer to the value (array)
|
||||||
constexpr const array_t* get_impl_ptr(const array_t*) const noexcept
|
constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_array() ? m_value.array : nullptr;
|
return is_array() ? m_value.array : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (string)
|
/// get a pointer to the value (string)
|
||||||
string_t* get_impl_ptr(string_t*) noexcept
|
string_t* get_impl_ptr(string_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_string() ? m_value.string : nullptr;
|
return is_string() ? m_value.string : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (string)
|
/// get a pointer to the value (string)
|
||||||
constexpr const string_t* get_impl_ptr(const string_t*) const noexcept
|
constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_string() ? m_value.string : nullptr;
|
return is_string() ? m_value.string : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (boolean)
|
/// get a pointer to the value (boolean)
|
||||||
boolean_t* get_impl_ptr(boolean_t*) noexcept
|
boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_boolean() ? &m_value.boolean : nullptr;
|
return is_boolean() ? &m_value.boolean : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (boolean)
|
/// get a pointer to the value (boolean)
|
||||||
constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
|
constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_boolean() ? &m_value.boolean : nullptr;
|
return is_boolean() ? &m_value.boolean : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (integer number)
|
/// get a pointer to the value (integer number)
|
||||||
number_integer_t* get_impl_ptr(number_integer_t*) noexcept
|
number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_number_integer() ? &m_value.number_integer : nullptr;
|
return is_number_integer() ? &m_value.number_integer : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (integer number)
|
/// get a pointer to the value (integer number)
|
||||||
constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
|
constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_integer() ? &m_value.number_integer : nullptr;
|
return is_number_integer() ? &m_value.number_integer : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (unsigned number)
|
/// get a pointer to the value (unsigned number)
|
||||||
number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
|
number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (unsigned number)
|
/// get a pointer to the value (unsigned number)
|
||||||
constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
|
constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (floating-point number)
|
/// get a pointer to the value (floating-point number)
|
||||||
number_float_t* get_impl_ptr(number_float_t*) noexcept
|
number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return is_number_float() ? &m_value.number_float : nullptr;
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (floating-point number)
|
/// get a pointer to the value (floating-point number)
|
||||||
constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
|
constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_float() ? &m_value.number_float : nullptr;
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
}
|
}
|
||||||
|
@ -2845,12 +2831,10 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *ptr;
|
return *ptr;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
|
throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
|
||||||
obj.type_name());
|
obj.type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -3349,11 +3333,9 @@ class basic_json
|
||||||
|
|
||||||
return m_value.array->operator[](idx);
|
return m_value.array->operator[](idx);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified array element
|
@brief access specified array element
|
||||||
|
@ -3381,11 +3363,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.array->operator[](idx);
|
return m_value.array->operator[](idx);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified object element
|
@brief access specified object element
|
||||||
|
@ -3429,11 +3409,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.object->operator[](key);
|
return m_value.object->operator[](key);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief read-only access specified object element
|
@brief read-only access specified object element
|
||||||
|
@ -3473,11 +3451,9 @@ class basic_json
|
||||||
assert(m_value.object->find(key) != m_value.object->end());
|
assert(m_value.object->find(key) != m_value.object->end());
|
||||||
return m_value.object->find(key)->second;
|
return m_value.object->find(key)->second;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified object element
|
@brief access specified object element
|
||||||
|
@ -3590,11 +3566,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.object->operator[](key);
|
return m_value.object->operator[](key);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief read-only access specified object element
|
@brief read-only access specified object element
|
||||||
|
@ -3635,11 +3609,9 @@ class basic_json
|
||||||
assert(m_value.object->find(key) != m_value.object->end());
|
assert(m_value.object->find(key) != m_value.object->end());
|
||||||
return m_value.object->find(key)->second;
|
return m_value.object->find(key)->second;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use operator[] with " + type_name());
|
throw std::domain_error("cannot use operator[] with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief access specified object element with default value
|
@brief access specified object element with default value
|
||||||
|
@ -3702,11 +3674,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return default_value;
|
return default_value;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw std::domain_error("cannot use value() with " + type_name());
|
throw std::domain_error("cannot use value() with " + type_name());
|
||||||
|
@ -4131,11 +4101,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_value.object->erase(key);
|
return m_value.object->erase(key);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use erase() with " + type_name());
|
throw std::domain_error("cannot use erase() with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief remove element from a JSON array given an index
|
@brief remove element from a JSON array given an index
|
||||||
|
@ -5186,11 +5154,9 @@ class basic_json
|
||||||
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
|
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use insert() with " + type_name());
|
throw std::domain_error("cannot use insert() with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief inserts element
|
@brief inserts element
|
||||||
|
@ -5241,11 +5207,9 @@ class basic_json
|
||||||
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
|
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use insert() with " + type_name());
|
throw std::domain_error("cannot use insert() with " + type_name());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief inserts elements
|
@brief inserts elements
|
||||||
|
@ -6122,7 +6086,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
// assertion to check that the iterator range is indeed contiguous,
|
// assertion to check that the iterator range is indeed contiguous,
|
||||||
// see http://stackoverflow.com/a/35008842/266378 for more discussion
|
// see http://stackoverflow.com/a/35008842/266378 for more discussion
|
||||||
assert(std::accumulate(first, last, std::make_pair<bool, int>(true, 0),
|
assert(std::accumulate(first, last, std::pair<bool, int>(true, 0),
|
||||||
[&first](std::pair<bool, int> res, decltype(*first) val)
|
[&first](std::pair<bool, int> res, decltype(*first) val)
|
||||||
{
|
{
|
||||||
res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
|
res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
|
||||||
|
@ -6327,7 +6291,7 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
T result;
|
T result;
|
||||||
uint8_t* ptr = reinterpret_cast<uint8_t*>(&result);
|
auto* ptr = reinterpret_cast<uint8_t*>(&result);
|
||||||
for (size_t i = 0; i < sizeof(T); ++i)
|
for (size_t i = 0; i < sizeof(T); ++i)
|
||||||
{
|
{
|
||||||
*ptr++ = vec[current_index + sizeof(T) - i];
|
*ptr++ = vec[current_index + sizeof(T) - i];
|
||||||
|
@ -6473,7 +6437,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
// float 64
|
// float 64
|
||||||
v.push_back(0xcb);
|
v.push_back(0xcb);
|
||||||
const uint8_t* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
const auto* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
||||||
for (size_t i = 0; i < 8; ++i)
|
for (size_t i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
v.push_back(helper[7 - i]);
|
v.push_back(helper[7 - i]);
|
||||||
|
@ -6716,7 +6680,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
// Double-Precision Float
|
// Double-Precision Float
|
||||||
v.push_back(0xfb);
|
v.push_back(0xfb);
|
||||||
const uint8_t* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
const auto* helper = reinterpret_cast<const uint8_t*>(&(j.m_value.number_float));
|
||||||
for (size_t i = 0; i < 8; ++i)
|
for (size_t i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
v.push_back(helper[7 - i]);
|
v.push_back(helper[7 - i]);
|
||||||
|
@ -6916,7 +6880,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
return v[current_idx];
|
return v[current_idx];
|
||||||
}
|
}
|
||||||
else if (v[current_idx] <= 0x8f) // fixmap
|
if (v[current_idx] <= 0x8f) // fixmap
|
||||||
{
|
{
|
||||||
basic_json result = value_t::object;
|
basic_json result = value_t::object;
|
||||||
const size_t len = v[current_idx] & 0x0f;
|
const size_t len = v[current_idx] & 0x0f;
|
||||||
|
@ -7577,7 +7541,7 @@ class basic_json
|
||||||
{
|
{
|
||||||
val = mant == 0 ? INFINITY : NAN;
|
val = mant == 0 ? INFINITY : NAN;
|
||||||
}
|
}
|
||||||
return half & 0x8000 ? -val : val;
|
return (half & 0x8000) != 0 ? -val : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0xfa: // Single-Precision Float (four-byte IEEE 754)
|
case 0xfa: // Single-Precision Float (four-byte IEEE 754)
|
||||||
|
@ -7800,12 +7764,10 @@ class basic_json
|
||||||
// from c (1 byte) to \uxxxx (6 bytes)
|
// from c (1 byte) to \uxxxx (6 bytes)
|
||||||
return res + 5;
|
return res + 5;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8509,13 +8471,11 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *m_object;
|
return *m_object;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::out_of_range("cannot get value");
|
throw std::out_of_range("cannot get value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief dereference the iterator
|
@brief dereference the iterator
|
||||||
|
@ -8545,13 +8505,11 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_object;
|
return m_object;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::out_of_range("cannot get value");
|
throw std::out_of_range("cannot get value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief post-increment (it++)
|
@brief post-increment (it++)
|
||||||
|
@ -8861,13 +8819,11 @@ class basic_json
|
||||||
{
|
{
|
||||||
return *m_object;
|
return *m_object;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::out_of_range("cannot get value");
|
throw std::out_of_range("cannot get value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief return the key of an object iterator
|
@brief return the key of an object iterator
|
||||||
|
@ -8881,11 +8837,9 @@ class basic_json
|
||||||
{
|
{
|
||||||
return m_it.object_iterator->first;
|
return m_it.object_iterator->first;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::domain_error("cannot use key() for non-object iterators");
|
throw std::domain_error("cannot use key() for non-object iterators");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief return the value of an iterator
|
@brief return the value of an iterator
|
||||||
|
@ -9359,7 +9313,7 @@ class basic_json
|
||||||
assert(m_marker == nullptr or m_marker <= m_limit);
|
assert(m_marker == nullptr or m_marker <= m_limit);
|
||||||
|
|
||||||
// number of processed characters (p)
|
// number of processed characters (p)
|
||||||
const size_t num_processed_chars = static_cast<size_t>(m_start - m_content);
|
const auto num_processed_chars = static_cast<size_t>(m_start - m_content);
|
||||||
// offset for m_marker wrt. to m_start
|
// offset for m_marker wrt. to m_start
|
||||||
const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start;
|
const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start;
|
||||||
// number of unprocessed characters (u)
|
// number of unprocessed characters (u)
|
||||||
|
@ -9751,7 +9705,7 @@ class basic_json
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// parse with strtod
|
// parse with strtod
|
||||||
result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), NULL);
|
result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), nullptr);
|
||||||
|
|
||||||
// replace infinity and NAN by null
|
// replace infinity and NAN by null
|
||||||
if (not std::isfinite(result.m_value.number_float))
|
if (not std::isfinite(result.m_value.number_float))
|
||||||
|
@ -10486,7 +10440,7 @@ class basic_json
|
||||||
// - start: position after the previous slash
|
// - start: position after the previous slash
|
||||||
for (
|
for (
|
||||||
// search for the first slash after the first character
|
// search for the first slash after the first character
|
||||||
size_t slash = reference_string.find_first_of("/", 1),
|
size_t slash = reference_string.find_first_of('/', 1),
|
||||||
// set the beginning of the first reference token
|
// set the beginning of the first reference token
|
||||||
start = 1;
|
start = 1;
|
||||||
// we can stop if start == string::npos+1 = 0
|
// we can stop if start == string::npos+1 = 0
|
||||||
|
@ -10495,16 +10449,16 @@ class basic_json
|
||||||
// (will eventually be 0 if slash == std::string::npos)
|
// (will eventually be 0 if slash == std::string::npos)
|
||||||
start = slash + 1,
|
start = slash + 1,
|
||||||
// find next slash
|
// find next slash
|
||||||
slash = reference_string.find_first_of("/", start))
|
slash = reference_string.find_first_of('/', start))
|
||||||
{
|
{
|
||||||
// use the text between the beginning of the reference token
|
// use the text between the beginning of the reference token
|
||||||
// (start) and the last slash (slash).
|
// (start) and the last slash (slash).
|
||||||
auto reference_token = reference_string.substr(start, slash - start);
|
auto reference_token = reference_string.substr(start, slash - start);
|
||||||
|
|
||||||
// check reference tokens are properly escaped
|
// check reference tokens are properly escaped
|
||||||
for (size_t pos = reference_token.find_first_of("~");
|
for (size_t pos = reference_token.find_first_of('~');
|
||||||
pos != std::string::npos;
|
pos != std::string::npos;
|
||||||
pos = reference_token.find_first_of("~", pos + 1))
|
pos = reference_token.find_first_of('~', pos + 1))
|
||||||
{
|
{
|
||||||
assert(reference_token[pos] == '~');
|
assert(reference_token[pos] == '~');
|
||||||
|
|
||||||
|
@ -11338,7 +11292,7 @@ uses the standard template types.
|
||||||
@since version 1.0.0
|
@since version 1.0.0
|
||||||
*/
|
*/
|
||||||
using json = basic_json<>;
|
using json = basic_json<>;
|
||||||
}
|
} // namespace nlohmann
|
||||||
|
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
|
@ -11379,7 +11333,7 @@ struct hash<nlohmann::json>
|
||||||
return h(j.dump());
|
return h(j.dump());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace std
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief user-defined string literal for JSON values
|
@brief user-defined string literal for JSON values
|
||||||
|
|
|
@ -80,7 +80,7 @@ struct my_allocator : std::allocator<T>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
::new(reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
::new (reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -912,7 +912,7 @@ TEST_CASE("constructors")
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} , 13 };
|
json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue