closed #91
This commit is contained in:
parent
48c4f4d05d
commit
540c58964d
2 changed files with 155 additions and 34 deletions
99
src/json.hpp
99
src/json.hpp
|
@ -1860,37 +1860,73 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (object)
|
/// get a pointer to the value (object)
|
||||||
const object_t* get_impl_ptr(object_t*) const noexcept
|
object_t* get_impl_ptr(object_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_object() ? m_value.object : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (object)
|
||||||
|
const object_t* get_impl_ptr(const object_t*) 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)
|
||||||
const array_t* get_impl_ptr(array_t*) const noexcept
|
array_t* get_impl_ptr(array_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_array() ? m_value.array : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (array)
|
||||||
|
const array_t* get_impl_ptr(const array_t*) 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)
|
||||||
const string_t* get_impl_ptr(string_t*) const noexcept
|
string_t* get_impl_ptr(string_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_string() ? m_value.string : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (string)
|
||||||
|
const string_t* get_impl_ptr(const string_t*) 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)
|
||||||
const boolean_t* get_impl_ptr(boolean_t*) const noexcept
|
boolean_t* get_impl_ptr(boolean_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_boolean() ? &m_value.boolean : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (boolean)
|
||||||
|
const boolean_t* get_impl_ptr(const boolean_t*) 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)
|
||||||
const number_integer_t* get_impl_ptr(number_integer_t*) const noexcept
|
number_integer_t* get_impl_ptr(number_integer_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_number_integer() ? &m_value.number_integer : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (integer number)
|
||||||
|
const number_integer_t* get_impl_ptr(const number_integer_t*) 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 (floating-point number)
|
/// get a pointer to the value (floating-point number)
|
||||||
const number_float_t* get_impl_ptr(number_float_t*) const noexcept
|
number_float_t* get_impl_ptr(number_float_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (floating-point number)
|
||||||
|
const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_float() ? &m_value.number_float : nullptr;
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1969,7 +2005,21 @@ class basic_json
|
||||||
std::enable_if<
|
std::enable_if<
|
||||||
std::is_pointer<PointerType>::value
|
std::is_pointer<PointerType>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
PointerType get() const noexcept
|
PointerType get() noexcept
|
||||||
|
{
|
||||||
|
// delegate the call to get_ptr
|
||||||
|
return get_ptr<PointerType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief get a pointer value (explicit)
|
||||||
|
@copydoc get()
|
||||||
|
*/
|
||||||
|
template<typename PointerType, typename
|
||||||
|
std::enable_if<
|
||||||
|
std::is_pointer<PointerType>::value
|
||||||
|
, int>::type = 0>
|
||||||
|
const PointerType get() const noexcept
|
||||||
{
|
{
|
||||||
// delegate the call to get_ptr
|
// delegate the call to get_ptr
|
||||||
return get_ptr<PointerType>();
|
return get_ptr<PointerType>();
|
||||||
|
@ -2002,15 +2052,25 @@ class basic_json
|
||||||
std::enable_if<
|
std::enable_if<
|
||||||
std::is_pointer<PointerType>::value
|
std::is_pointer<PointerType>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
PointerType get_ptr() const noexcept
|
PointerType get_ptr() noexcept
|
||||||
{
|
{
|
||||||
// get_impl_ptr will only work with non-const and non-volatile pointer
|
// delegate the call to get_impl_ptr<>()
|
||||||
// types. Therefore, we case away all cv properties to be able to
|
return get_impl_ptr(static_cast<PointerType>(nullptr));
|
||||||
// select the correct function. The cv properties will then be added
|
}
|
||||||
// again by the const const cast to PointerType.
|
|
||||||
return const_cast<PointerType>(get_impl_ptr(
|
/*!
|
||||||
static_cast<typename std::add_pointer<typename std::remove_cv<typename std::remove_pointer<PointerType>::type>::type>::type>
|
@brief get a pointer value (implicit)
|
||||||
(nullptr)));
|
@copydoc get_ptr()
|
||||||
|
*/
|
||||||
|
template<typename PointerType, typename
|
||||||
|
std::enable_if<
|
||||||
|
std::is_pointer<PointerType>::value
|
||||||
|
and std::is_const<PointerType>::value
|
||||||
|
, int>::type = 0>
|
||||||
|
const PointerType get_ptr() const noexcept
|
||||||
|
{
|
||||||
|
// delegate the call to get_impl_ptr<>() const
|
||||||
|
return get_impl_ptr(static_cast<const PointerType>(nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -6326,15 +6386,16 @@ basic_json_parser_59:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// constructor for strings
|
/// constructor for strings
|
||||||
parser(const string_t& s, parser_callback_t cb = nullptr) : callback(cb), m_lexer(s)
|
parser(const string_t& s, parser_callback_t cb = nullptr)
|
||||||
|
: callback(cb), m_lexer(s)
|
||||||
{
|
{
|
||||||
// read first token
|
// read first token
|
||||||
get_token();
|
get_token();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// a parser reading from an input stream
|
/// a parser reading from an input stream
|
||||||
parser(std::istream& _is, parser_callback_t cb = nullptr) : callback(cb),
|
parser(std::istream& _is, parser_callback_t cb = nullptr)
|
||||||
m_lexer(&_is)
|
: callback(cb), m_lexer(&_is)
|
||||||
{
|
{
|
||||||
// read first token
|
// read first token
|
||||||
get_token();
|
get_token();
|
||||||
|
@ -6601,7 +6662,7 @@ basic_json_parser_59:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// levels of recursion
|
/// current level of recursion
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
/// callback function
|
/// callback function
|
||||||
parser_callback_t callback;
|
parser_callback_t callback;
|
||||||
|
|
|
@ -1860,37 +1860,73 @@ class basic_json
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get a pointer to the value (object)
|
/// get a pointer to the value (object)
|
||||||
const object_t* get_impl_ptr(object_t*) const noexcept
|
object_t* get_impl_ptr(object_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_object() ? m_value.object : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (object)
|
||||||
|
const object_t* get_impl_ptr(const object_t*) 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)
|
||||||
const array_t* get_impl_ptr(array_t*) const noexcept
|
array_t* get_impl_ptr(array_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_array() ? m_value.array : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (array)
|
||||||
|
const array_t* get_impl_ptr(const array_t*) 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)
|
||||||
const string_t* get_impl_ptr(string_t*) const noexcept
|
string_t* get_impl_ptr(string_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_string() ? m_value.string : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (string)
|
||||||
|
const string_t* get_impl_ptr(const string_t*) 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)
|
||||||
const boolean_t* get_impl_ptr(boolean_t*) const noexcept
|
boolean_t* get_impl_ptr(boolean_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_boolean() ? &m_value.boolean : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (boolean)
|
||||||
|
const boolean_t* get_impl_ptr(const boolean_t*) 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)
|
||||||
const number_integer_t* get_impl_ptr(number_integer_t*) const noexcept
|
number_integer_t* get_impl_ptr(number_integer_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_number_integer() ? &m_value.number_integer : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (integer number)
|
||||||
|
const number_integer_t* get_impl_ptr(const number_integer_t*) 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 (floating-point number)
|
/// get a pointer to the value (floating-point number)
|
||||||
const number_float_t* get_impl_ptr(number_float_t*) const noexcept
|
number_float_t* get_impl_ptr(number_float_t*) noexcept
|
||||||
|
{
|
||||||
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get a pointer to the value (floating-point number)
|
||||||
|
const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
|
||||||
{
|
{
|
||||||
return is_number_float() ? &m_value.number_float : nullptr;
|
return is_number_float() ? &m_value.number_float : nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1969,7 +2005,21 @@ class basic_json
|
||||||
std::enable_if<
|
std::enable_if<
|
||||||
std::is_pointer<PointerType>::value
|
std::is_pointer<PointerType>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
PointerType get() const noexcept
|
PointerType get() noexcept
|
||||||
|
{
|
||||||
|
// delegate the call to get_ptr
|
||||||
|
return get_ptr<PointerType>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief get a pointer value (explicit)
|
||||||
|
@copydoc get()
|
||||||
|
*/
|
||||||
|
template<typename PointerType, typename
|
||||||
|
std::enable_if<
|
||||||
|
std::is_pointer<PointerType>::value
|
||||||
|
, int>::type = 0>
|
||||||
|
const PointerType get() const noexcept
|
||||||
{
|
{
|
||||||
// delegate the call to get_ptr
|
// delegate the call to get_ptr
|
||||||
return get_ptr<PointerType>();
|
return get_ptr<PointerType>();
|
||||||
|
@ -2002,15 +2052,25 @@ class basic_json
|
||||||
std::enable_if<
|
std::enable_if<
|
||||||
std::is_pointer<PointerType>::value
|
std::is_pointer<PointerType>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
PointerType get_ptr() const noexcept
|
PointerType get_ptr() noexcept
|
||||||
{
|
{
|
||||||
// get_impl_ptr will only work with non-const and non-volatile pointer
|
// delegate the call to get_impl_ptr<>()
|
||||||
// types. Therefore, we case away all cv properties to be able to
|
return get_impl_ptr(static_cast<PointerType>(nullptr));
|
||||||
// select the correct function. The cv properties will then be added
|
}
|
||||||
// again by the const const cast to PointerType.
|
|
||||||
return const_cast<PointerType>(get_impl_ptr(
|
/*!
|
||||||
static_cast<typename std::add_pointer<typename std::remove_cv<typename std::remove_pointer<PointerType>::type>::type>::type>
|
@brief get a pointer value (implicit)
|
||||||
(nullptr)));
|
@copydoc get_ptr()
|
||||||
|
*/
|
||||||
|
template<typename PointerType, typename
|
||||||
|
std::enable_if<
|
||||||
|
std::is_pointer<PointerType>::value
|
||||||
|
and std::is_const<PointerType>::value
|
||||||
|
, int>::type = 0>
|
||||||
|
const PointerType get_ptr() const noexcept
|
||||||
|
{
|
||||||
|
// delegate the call to get_impl_ptr<>() const
|
||||||
|
return get_impl_ptr(static_cast<const PointerType>(nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in a new issue