Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
ac4d4a0f
Commit
ac4d4a0f
authored
Dec 17, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed compilation error and fixed shadow warnings
parent
07033f67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
490 additions
and
310 deletions
+490
-310
json.hpp
src/json.hpp
+245
-155
json.hpp.re2c
src/json.hpp.re2c
+245
-155
No files found.
src/json.hpp
View file @
ac4d4a0f
...
@@ -841,7 +841,7 @@ class basic_json
...
@@ -841,7 +841,7 @@ class basic_json
object | `{}`
object | `{}`
array | `[]`
array | `[]`
@param[in] value the type of the value to create
@param[in] value
_type
the type of the value to create
@complexity Constant.
@complexity Constant.
...
@@ -863,8 +863,8 @@ class basic_json
...
@@ -863,8 +863,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
const
value_t
value
)
basic_json
(
const
value_t
value
_type
)
:
m_type
(
value
),
m_value
(
valu
e
)
:
m_type
(
value
_type
),
m_value
(
value_typ
e
)
{}
{}
/*!
/*!
...
@@ -916,9 +916,9 @@ class basic_json
...
@@ -916,9 +916,9 @@ class basic_json
Create an object JSON value with a given content.
Create an object JSON value with a given content.
@param[in] val
ue
a value for the object
@param[in] val a value for the object
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for object value fails
@throw std::bad_alloc if allocation for object value fails
...
@@ -930,8 +930,8 @@ class basic_json
...
@@ -930,8 +930,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
const
object_t
&
val
ue
)
basic_json
(
const
object_t
&
val
)
:
m_type
(
value_t
::
object
),
m_value
(
val
ue
)
:
m_type
(
value_t
::
object
),
m_value
(
val
)
{}
{}
/*!
/*!
...
@@ -944,9 +944,9 @@ class basic_json
...
@@ -944,9 +944,9 @@ class basic_json
@tparam CompatibleObjectType an object type whose `key_type` and
@tparam CompatibleObjectType an object type whose `key_type` and
`value_type` is compatible to @ref object_t
`value_type` is compatible to @ref object_t
@param[in] val
ue
a value for the object
@param[in] val a value for the object
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for object value fails
@throw std::bad_alloc if allocation for object value fails
...
@@ -962,12 +962,12 @@ class basic_json
...
@@ -962,12 +962,12 @@ class basic_json
std
::
is_constructible
<
typename
object_t
::
key_type
,
typename
CompatibleObjectType
::
key_type
>::
value
and
std
::
is_constructible
<
typename
object_t
::
key_type
,
typename
CompatibleObjectType
::
key_type
>::
value
and
std
::
is_constructible
<
basic_json
,
typename
CompatibleObjectType
::
mapped_type
>::
value
,
int
>::
type
std
::
is_constructible
<
basic_json
,
typename
CompatibleObjectType
::
mapped_type
>::
value
,
int
>::
type
=
0
>
=
0
>
basic_json
(
const
CompatibleObjectType
&
val
ue
)
basic_json
(
const
CompatibleObjectType
&
val
)
:
m_type
(
value_t
::
object
)
:
m_type
(
value_t
::
object
)
{
{
using
std
::
begin
;
using
std
::
begin
;
using
std
::
end
;
using
std
::
end
;
m_value
.
object
=
create
<
object_t
>
(
begin
(
val
ue
),
end
(
value
));
m_value
.
object
=
create
<
object_t
>
(
begin
(
val
),
end
(
val
));
}
}
/*!
/*!
...
@@ -975,9 +975,9 @@ class basic_json
...
@@ -975,9 +975,9 @@ class basic_json
Create an array JSON value with a given content.
Create an array JSON value with a given content.
@param[in] val
ue
a value for the array
@param[in] val a value for the array
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for array value fails
@throw std::bad_alloc if allocation for array value fails
...
@@ -989,8 +989,8 @@ class basic_json
...
@@ -989,8 +989,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
const
array_t
&
val
ue
)
basic_json
(
const
array_t
&
val
)
:
m_type
(
value_t
::
array
),
m_value
(
val
ue
)
:
m_type
(
value_t
::
array
),
m_value
(
val
)
{}
{}
/*!
/*!
...
@@ -1003,9 +1003,9 @@ class basic_json
...
@@ -1003,9 +1003,9 @@ class basic_json
@tparam CompatibleArrayType an object type whose `value_type` is compatible
@tparam CompatibleArrayType an object type whose `value_type` is compatible
to @ref array_t
to @ref array_t
@param[in] val
ue
a value for the array
@param[in] val a value for the array
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for array value fails
@throw std::bad_alloc if allocation for array value fails
...
@@ -1026,12 +1026,12 @@ class basic_json
...
@@ -1026,12 +1026,12 @@ class basic_json
not
std
::
is_same
<
CompatibleArrayType
,
typename
array_t
::
const_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
array_t
::
const_iterator
>::
value
and
std
::
is_constructible
<
basic_json
,
typename
CompatibleArrayType
::
value_type
>::
value
,
int
>::
type
std
::
is_constructible
<
basic_json
,
typename
CompatibleArrayType
::
value_type
>::
value
,
int
>::
type
=
0
>
=
0
>
basic_json
(
const
CompatibleArrayType
&
val
ue
)
basic_json
(
const
CompatibleArrayType
&
val
)
:
m_type
(
value_t
::
array
)
:
m_type
(
value_t
::
array
)
{
{
using
std
::
begin
;
using
std
::
begin
;
using
std
::
end
;
using
std
::
end
;
m_value
.
array
=
create
<
array_t
>
(
begin
(
val
ue
),
end
(
value
));
m_value
.
array
=
create
<
array_t
>
(
begin
(
val
),
end
(
val
));
}
}
/*!
/*!
...
@@ -1039,9 +1039,9 @@ class basic_json
...
@@ -1039,9 +1039,9 @@ class basic_json
Create an string JSON value with a given content.
Create an string JSON value with a given content.
@param[in] val
ue
a value for the string
@param[in] val a value for the string
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for string value fails
@throw std::bad_alloc if allocation for string value fails
...
@@ -1055,8 +1055,8 @@ class basic_json
...
@@ -1055,8 +1055,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
const
string_t
&
val
ue
)
basic_json
(
const
string_t
&
val
)
:
m_type
(
value_t
::
string
),
m_value
(
val
ue
)
:
m_type
(
value_t
::
string
),
m_value
(
val
)
{}
{}
/*!
/*!
...
@@ -1064,9 +1064,9 @@ class basic_json
...
@@ -1064,9 +1064,9 @@ class basic_json
Create a string JSON value with a given content.
Create a string JSON value with a given content.
@param[in] val
ue
a literal value for the string
@param[in] val a literal value for the string
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for string value fails
@throw std::bad_alloc if allocation for string value fails
...
@@ -1079,8 +1079,8 @@ class basic_json
...
@@ -1079,8 +1079,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
const
typename
string_t
::
value_type
*
val
ue
)
basic_json
(
const
typename
string_t
::
value_type
*
val
)
:
basic_json
(
string_t
(
val
ue
))
:
basic_json
(
string_t
(
val
))
{}
{}
/*!
/*!
...
@@ -1088,12 +1088,12 @@ class basic_json
...
@@ -1088,12 +1088,12 @@ class basic_json
Create a string JSON value with a given content.
Create a string JSON value with a given content.
@param[in] val
ue
a value for the string
@param[in] val a value for the string
@tparam CompatibleStringType an string type which is compatible to @ref
@tparam CompatibleStringType an string type which is compatible to @ref
string_t
string_t
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for string value fails
@throw std::bad_alloc if allocation for string value fails
...
@@ -1110,8 +1110,8 @@ class basic_json
...
@@ -1110,8 +1110,8 @@ class basic_json
std
::
enable_if
<
std
::
enable_if
<
std
::
is_constructible
<
string_t
,
CompatibleStringType
>::
value
,
int
>::
type
std
::
is_constructible
<
string_t
,
CompatibleStringType
>::
value
,
int
>::
type
=
0
>
=
0
>
basic_json
(
const
CompatibleStringType
&
val
ue
)
basic_json
(
const
CompatibleStringType
&
val
)
:
basic_json
(
string_t
(
val
ue
))
:
basic_json
(
string_t
(
val
))
{}
{}
/*!
/*!
...
@@ -1119,7 +1119,7 @@ class basic_json
...
@@ -1119,7 +1119,7 @@ class basic_json
Creates a JSON boolean type from a given value.
Creates a JSON boolean type from a given value.
@param[in] val
ue
a boolean value to store
@param[in] val a boolean value to store
@complexity Constant.
@complexity Constant.
...
@@ -1128,8 +1128,8 @@ class basic_json
...
@@ -1128,8 +1128,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
boolean_t
val
ue
)
basic_json
(
boolean_t
val
)
:
m_type
(
value_t
::
boolean
),
m_value
(
val
ue
)
:
m_type
(
value_t
::
boolean
),
m_value
(
val
)
{}
{}
/*!
/*!
...
@@ -1140,7 +1140,7 @@ class basic_json
...
@@ -1140,7 +1140,7 @@ class basic_json
@tparam T helper type to compare number_integer_t and int (not visible in)
@tparam T helper type to compare number_integer_t and int (not visible in)
the interface.
the interface.
@param[in] val
ue
an integer to create a JSON number from
@param[in] val an integer to create a JSON number from
@note This constructor would have the same signature as @ref
@note This constructor would have the same signature as @ref
basic_json(const int value), so we need to switch this one off in case
basic_json(const int value), so we need to switch this one off in case
...
@@ -1162,8 +1162,8 @@ class basic_json
...
@@ -1162,8 +1162,8 @@ class basic_json
not
(
std
::
is_same
<
T
,
int
>::
value
)
not
(
std
::
is_same
<
T
,
int
>::
value
)
and
std
::
is_same
<
T
,
number_integer_t
>::
value
and
std
::
is_same
<
T
,
number_integer_t
>::
value
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
basic_json
(
const
number_integer_t
val
ue
)
basic_json
(
const
number_integer_t
val
)
:
m_type
(
value_t
::
number_integer
),
m_value
(
val
ue
)
:
m_type
(
value_t
::
number_integer
),
m_value
(
val
)
{}
{}
/*!
/*!
...
@@ -1171,7 +1171,7 @@ class basic_json
...
@@ -1171,7 +1171,7 @@ class basic_json
Create an integer number JSON value with a given content.
Create an integer number JSON value with a given content.
@param[in] val
ue
an integer to create a JSON number from
@param[in] val an integer to create a JSON number from
@note This constructor allows to pass enums directly to a constructor. As
@note This constructor allows to pass enums directly to a constructor. As
C++ has no way of specifying the type of an anonymous enum explicitly, we
C++ has no way of specifying the type of an anonymous enum explicitly, we
...
@@ -1191,9 +1191,9 @@ class basic_json
...
@@ -1191,9 +1191,9 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
const
int
val
ue
)
basic_json
(
const
int
val
)
:
m_type
(
value_t
::
number_integer
),
:
m_type
(
value_t
::
number_integer
),
m_value
(
static_cast
<
number_integer_t
>
(
val
ue
))
m_value
(
static_cast
<
number_integer_t
>
(
val
))
{}
{}
/*!
/*!
...
@@ -1207,7 +1207,7 @@ class basic_json
...
@@ -1207,7 +1207,7 @@ class basic_json
@tparam CompatibleNumberIntegerType an integer type which is compatible to
@tparam CompatibleNumberIntegerType an integer type which is compatible to
@ref number_integer_t.
@ref number_integer_t.
@param[in] val
ue
an integer to create a JSON number from
@param[in] val an integer to create a JSON number from
@complexity Constant.
@complexity Constant.
...
@@ -1226,9 +1226,9 @@ class basic_json
...
@@ -1226,9 +1226,9 @@ class basic_json
std
::
is_constructible
<
number_integer_t
,
CompatibleNumberIntegerType
>::
value
and
std
::
is_constructible
<
number_integer_t
,
CompatibleNumberIntegerType
>::
value
and
std
::
numeric_limits
<
CompatibleNumberIntegerType
>::
is_integer
,
CompatibleNumberIntegerType
>::
type
std
::
numeric_limits
<
CompatibleNumberIntegerType
>::
is_integer
,
CompatibleNumberIntegerType
>::
type
=
0
>
=
0
>
basic_json
(
const
CompatibleNumberIntegerType
val
ue
)
noexcept
basic_json
(
const
CompatibleNumberIntegerType
val
)
noexcept
:
m_type
(
value_t
::
number_integer
),
:
m_type
(
value_t
::
number_integer
),
m_value
(
static_cast
<
number_integer_t
>
(
val
ue
))
m_value
(
static_cast
<
number_integer_t
>
(
val
))
{}
{}
/*!
/*!
...
@@ -1236,13 +1236,13 @@ class basic_json
...
@@ -1236,13 +1236,13 @@ class basic_json
Create a floating-point number JSON value with a given content.
Create a floating-point number JSON value with a given content.
@param[in] val
ue
a floating-point value to create a JSON number from
@param[in] val a floating-point value to create a JSON number from
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
disallows NaN values:
disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such
> Numeric values that cannot be represented in the grammar below (such
> as Infinity and NaN) are not permitted.
> as Infinity and NaN) are not permitted.
In case the parameter @a val
ue
is not a number, a JSON null value is
In case the parameter @a val is not a number, a JSON null value is
created instead.
created instead.
@complexity Constant.
@complexity Constant.
...
@@ -1255,11 +1255,11 @@ class basic_json
...
@@ -1255,11 +1255,11 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
const
number_float_t
val
ue
)
basic_json
(
const
number_float_t
val
)
:
m_type
(
value_t
::
number_float
),
m_value
(
val
ue
)
:
m_type
(
value_t
::
number_float
),
m_value
(
val
)
{
{
// replace infinity and NAN by null
// replace infinity and NAN by null
if
(
not
std
::
isfinite
(
val
ue
))
if
(
not
std
::
isfinite
(
val
))
{
{
m_type
=
value_t
::
null
;
m_type
=
value_t
::
null
;
m_value
=
json_value
();
m_value
=
json_value
();
...
@@ -1276,13 +1276,13 @@ class basic_json
...
@@ -1276,13 +1276,13 @@ class basic_json
@tparam CompatibleNumberFloatType a floating-point type which is compatible
@tparam CompatibleNumberFloatType a floating-point type which is compatible
to @ref number_float_t.
to @ref number_float_t.
@param[in] val
ue
a floating-point to create a JSON number from
@param[in] val a floating-point to create a JSON number from
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
disallows NaN values:
disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such
> Numeric values that cannot be represented in the grammar below (such
> as Infinity and NaN) are not permitted.
> as Infinity and NaN) are not permitted.
In case the parameter @a val
ue
is not a number, a JSON null value is
In case the parameter @a val is not a number, a JSON null value is
created instead.
created instead.
@complexity Constant.
@complexity Constant.
...
@@ -1301,8 +1301,8 @@ class basic_json
...
@@ -1301,8 +1301,8 @@ class basic_json
std
::
is_constructible
<
number_float_t
,
CompatibleNumberFloatType
>::
value
and
std
::
is_constructible
<
number_float_t
,
CompatibleNumberFloatType
>::
value
and
std
::
is_floating_point
<
CompatibleNumberFloatType
>::
value
>::
type
std
::
is_floating_point
<
CompatibleNumberFloatType
>::
value
>::
type
>
>
basic_json
(
const
CompatibleNumberFloatType
val
ue
)
noexcept
basic_json
(
const
CompatibleNumberFloatType
val
)
noexcept
:
basic_json
(
number_float_t
(
val
ue
))
:
basic_json
(
number_float_t
(
val
))
{}
{}
/*!
/*!
...
@@ -1378,7 +1378,7 @@ class basic_json
...
@@ -1378,7 +1378,7 @@ class basic_json
value_t
manual_type
=
value_t
::
array
)
value_t
manual_type
=
value_t
::
array
)
{
{
// the initializer list could describe an object
// the initializer list could describe an object
bool
is_object
=
true
;
bool
is_
an_
object
=
true
;
// check if each element is an array with two elements whose first
// check if each element is an array with two elements whose first
// element is a string
// element is a string
...
@@ -1389,7 +1389,7 @@ class basic_json
...
@@ -1389,7 +1389,7 @@ class basic_json
{
{
// we found an element that makes it impossible to use the
// we found an element that makes it impossible to use the
// initializer list as object
// initializer list as object
is_object
=
false
;
is_
an_
object
=
false
;
break
;
break
;
}
}
}
}
...
@@ -1400,17 +1400,17 @@ class basic_json
...
@@ -1400,17 +1400,17 @@ class basic_json
// if array is wanted, do not create an object though possible
// if array is wanted, do not create an object though possible
if
(
manual_type
==
value_t
::
array
)
if
(
manual_type
==
value_t
::
array
)
{
{
is_object
=
false
;
is_
an_
object
=
false
;
}
}
// if object is wanted but impossible, throw an exception
// if object is wanted but impossible, throw an exception
if
(
manual_type
==
value_t
::
object
and
not
is_object
)
if
(
manual_type
==
value_t
::
object
and
not
is_
an_
object
)
{
{
throw
std
::
domain_error
(
"cannot create object from initializer list"
);
throw
std
::
domain_error
(
"cannot create object from initializer list"
);
}
}
}
}
if
(
is_object
)
if
(
is_
an_
object
)
{
{
// the initializer list is a list of pairs -> create object
// the initializer list is a list of pairs -> create object
m_type
=
value_t
::
object
;
m_type
=
value_t
::
object
;
...
@@ -1512,14 +1512,14 @@ class basic_json
...
@@ -1512,14 +1512,14 @@ class basic_json
/*!
/*!
@brief construct an array with count copies of given value
@brief construct an array with count copies of given value
Constructs a JSON array value by creating @a c
ou
nt copies of a passed
Constructs a JSON array value by creating @a cnt copies of a passed
value. In case @a c
ou
nt is `0`, an empty array is created. As postcondition,
value. In case @a cnt is `0`, an empty array is created. As postcondition,
`std::distance(begin(),end()) == c
ou
nt` holds.
`std::distance(begin(),end()) == cnt` holds.
@param[in] c
ount the number of JSON copies of @a value
to create
@param[in] c
nt the number of JSON copies of @a val
to create
@param[in] val
ue
the JSON value to copy
@param[in] val the JSON value to copy
@complexity Linear in @a c
ou
nt.
@complexity Linear in @a cnt.
@liveexample{The following code shows examples for the @ref
@liveexample{The following code shows examples for the @ref
basic_json(size_type\, const basic_json&)
basic_json(size_type\, const basic_json&)
...
@@ -1527,10 +1527,10 @@ class basic_json
...
@@ -1527,10 +1527,10 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json
(
size_type
c
ount
,
const
basic_json
&
value
)
basic_json
(
size_type
c
nt
,
const
basic_json
&
val
)
:
m_type
(
value_t
::
array
)
:
m_type
(
value_t
::
array
)
{
{
m_value
.
array
=
create
<
array_t
>
(
c
ount
,
value
);
m_value
.
array
=
create
<
array_t
>
(
c
nt
,
val
);
}
}
/*!
/*!
...
@@ -2161,17 +2161,27 @@ class basic_json
...
@@ -2161,17 +2161,27 @@ class basic_json
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
T
get_impl
(
T
*
)
const
T
get_impl
(
T
*
)
const
{
{
return
is_object
()
if
(
is_object
())
?
T
(
m_value
.
object
->
begin
(),
m_value
.
object
->
end
())
{
:
throw
std
::
domain_error
(
"type must be object, but is "
+
type_name
());
return
T
(
m_value
.
object
->
begin
(),
m_value
.
object
->
end
());
}
else
{
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
*
)
const
{
{
return
is_object
()
if
(
is_object
())
?
*
(
m_value
.
object
)
{
:
throw
std
::
domain_error
(
"type must be object, but is "
+
type_name
());
return
*
(
m_value
.
object
);
}
else
{
throw
std
::
domain_error
(
"type must be object, but is "
+
type_name
());
}
}
}
/// get an array (explicit)
/// get an array (explicit)
...
@@ -2234,17 +2244,27 @@ class basic_json
...
@@ -2234,17 +2244,27 @@ class basic_json
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
T
get_impl
(
T
*
)
const
T
get_impl
(
T
*
)
const
{
{
return
is_array
()
if
(
is_array
())
?
T
(
m_value
.
array
->
begin
(),
m_value
.
array
->
end
())
{
:
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
());
return
T
(
m_value
.
array
->
begin
(),
m_value
.
array
->
end
());
}
else
{
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
*
)
const
{
{
return
is_array
()
if
(
is_array
())
?
*
(
m_value
.
array
)
{
:
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
());
return
*
(
m_value
.
array
);
}
else
{
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
());
}
}
}
/// get a string (explicit)
/// get a string (explicit)
...
@@ -2254,9 +2274,14 @@ class basic_json
...
@@ -2254,9 +2274,14 @@ class basic_json
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
T
get_impl
(
T
*
)
const
T
get_impl
(
T
*
)
const
{
{
return
is_string
()
if
(
is_string
())
?
*
m_value
.
string
{
:
throw
std
::
domain_error
(
"type must be string, but is "
+
type_name
());
return
*
m_value
.
string
;
}
else
{
throw
std
::
domain_error
(
"type must be string, but is "
+
type_name
());
}
}
}
/// get a number (explicit)
/// get a number (explicit)
...
@@ -2288,9 +2313,14 @@ class basic_json
...
@@ -2288,9 +2313,14 @@ class basic_json
/// get a boolean (explicit)
/// get a boolean (explicit)
boolean_t
get_impl
(
boolean_t
*
)
const
boolean_t
get_impl
(
boolean_t
*
)
const
{
{
return
is_boolean
()
if
(
is_boolean
())
?
m_value
.
boolean
{
:
throw
std
::
domain_error
(
"type must be boolean, but is "
+
type_name
());
return
m_value
.
boolean
;
}
else
{
throw
std
::
domain_error
(
"type must be boolean, but is "
+
type_name
());
}
}
}
/// get a pointer to the value (object)
/// get a pointer to the value (object)
...
@@ -2582,9 +2612,14 @@ class basic_json
...
@@ -2582,9 +2612,14 @@ class basic_json
reference
at
(
size_type
idx
)
reference
at
(
size_type
idx
)
{
{
// at only works for arrays
// at only works for arrays
return
is_array
()
if
(
is_array
())
?
m_value
.
array
->
at
(
idx
)
{
:
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
return
m_value
.
array
->
at
(
idx
);
}
else
{
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -2611,9 +2646,14 @@ class basic_json
...
@@ -2611,9 +2646,14 @@ class basic_json
const_reference
at
(
size_type
idx
)
const
const_reference
at
(
size_type
idx
)
const
{
{
// at only works for arrays
// at only works for arrays
return
is_array
()
if
(
is_array
())
?
m_value
.
array
->
at
(
idx
)
{
:
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
return
m_value
.
array
->
at
(
idx
);
}
else
{
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -2644,9 +2684,14 @@ class basic_json
...
@@ -2644,9 +2684,14 @@ class basic_json
reference
at
(
const
typename
object_t
::
key_type
&
key
)
reference
at
(
const
typename
object_t
::
key_type
&
key
)
{
{
// at only works for objects
// at only works for objects
return
is_object
()
if
(
is_object
())
?
m_value
.
object
->
at
(
key
)
{
:
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
return
m_value
.
object
->
at
(
key
);
}
else
{
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -2677,9 +2722,14 @@ class basic_json
...
@@ -2677,9 +2722,14 @@ class basic_json
const_reference
at
(
const
typename
object_t
::
key_type
&
key
)
const
const_reference
at
(
const
typename
object_t
::
key_type
&
key
)
const
{
{
// at only works for objects
// at only works for objects
return
is_object
()
if
(
is_object
())
?
m_value
.
object
->
at
(
key
)
{
:
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
return
m_value
.
object
->
at
(
key
);
}
else
{
throw
std
::
domain_error
(
"cannot use at() with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -2752,9 +2802,14 @@ class basic_json
...
@@ -2752,9 +2802,14 @@ class basic_json
const_reference
operator
[](
size_type
idx
)
const
const_reference
operator
[](
size_type
idx
)
const
{
{
// at only works for arrays
// at only works for arrays
return
is_array
()
if
(
is_array
())
?
m_value
.
array
->
operator
[](
idx
)
{
:
throw
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
());
return
m_value
.
array
->
operator
[](
idx
);
}
else
{
throw
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -2793,9 +2848,14 @@ class basic_json
...
@@ -2793,9 +2848,14 @@ class basic_json
}
}
// [] only works for objects
// [] only works for objects
return
is_object
()
if
(
is_object
())
?
m_value
.
object
->
operator
[](
key
)
{
:
throw
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
());
return
m_value
.
object
->
operator
[](
key
);
}
else
{
throw
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -2837,9 +2897,14 @@ class basic_json
...
@@ -2837,9 +2897,14 @@ class basic_json
}
}
// at only works for objects
// at only works for objects
return
is_object
()
if
(
is_object
())
?
m_value
.
object
->
operator
[](
key
)
{
:
throw
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
());
return
m_value
.
object
->
operator
[](
key
);
}
else
{
throw
std
::
domain_error
(
"cannot use operator[] with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -3227,9 +3292,14 @@ class basic_json
...
@@ -3227,9 +3292,14 @@ class basic_json
size_type
erase
(
const
typename
object_t
::
key_type
&
key
)
size_type
erase
(
const
typename
object_t
::
key_type
&
key
)
{
{
// this erase only works for objects
// this erase only works for objects
return
is_object
()
if
(
is_object
())
?
m_value
.
object
->
erase
(
key
)
{
:
throw
std
::
domain_error
(
"cannot use erase() with "
+
type_name
());
return
m_value
.
object
->
erase
(
key
);
}
else
{
throw
std
::
domain_error
(
"cannot use erase() with "
+
type_name
());
}
}
}
/*!
/*!
...
@@ -3839,11 +3909,11 @@ class basic_json
...
@@ -3839,11 +3909,11 @@ class basic_json
/*!
/*!
@brief add an object to an array
@brief add an object to an array
Appends the given element @a val
ue
to the end of the JSON value. If the
Appends the given element @a val to the end of the JSON value. If the
function is called on a JSON null value, an empty array is created before
function is called on a JSON null value, an empty array is created before
appending @a val
ue
.
appending @a val.
@param val
ue
the value to add to the JSON array
@param val the value to add to the JSON array
@throw std::domain_error when called on a type other than JSON array or null
@throw std::domain_error when called on a type other than JSON array or null
...
@@ -3855,7 +3925,7 @@ class basic_json
...
@@ -3855,7 +3925,7 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
void
push_back
(
basic_json
&&
val
ue
)
void
push_back
(
basic_json
&&
val
)
{
{
// push_back only works for null objects or arrays
// push_back only works for null objects or arrays
if
(
not
(
is_null
()
or
is_array
()))
if
(
not
(
is_null
()
or
is_array
()))
...
@@ -3871,18 +3941,18 @@ class basic_json
...
@@ -3871,18 +3941,18 @@ class basic_json
}
}
// add element to array (move semantics)
// add element to array (move semantics)
m_value
.
array
->
push_back
(
std
::
move
(
val
ue
));
m_value
.
array
->
push_back
(
std
::
move
(
val
));
// invalidate object
// invalidate object
val
ue
.
m_type
=
value_t
::
null
;
val
.
m_type
=
value_t
::
null
;
}
}
/*!
/*!
@brief add an object to an array
@brief add an object to an array
@copydoc push_back(basic_json&&)
@copydoc push_back(basic_json&&)
*/
*/
reference
operator
+=
(
basic_json
&&
val
ue
)
reference
operator
+=
(
basic_json
&&
val
)
{
{
push_back
(
std
::
move
(
val
ue
));
push_back
(
std
::
move
(
val
));
return
*
this
;
return
*
this
;
}
}
...
@@ -3890,7 +3960,7 @@ class basic_json
...
@@ -3890,7 +3960,7 @@ class basic_json
@brief add an object to an array
@brief add an object to an array
@copydoc push_back(basic_json&&)
@copydoc push_back(basic_json&&)
*/
*/
void
push_back
(
const
basic_json
&
val
ue
)
void
push_back
(
const
basic_json
&
val
)
{
{
// push_back only works for null objects or arrays
// push_back only works for null objects or arrays
if
(
not
(
is_null
()
or
is_array
()))
if
(
not
(
is_null
()
or
is_array
()))
...
@@ -3906,27 +3976,27 @@ class basic_json
...
@@ -3906,27 +3976,27 @@ class basic_json
}
}
// add element to array
// add element to array
m_value
.
array
->
push_back
(
val
ue
);
m_value
.
array
->
push_back
(
val
);
}
}
/*!
/*!
@brief add an object to an array
@brief add an object to an array
@copydoc push_back(basic_json&&)
@copydoc push_back(basic_json&&)
*/
*/
reference
operator
+=
(
const
basic_json
&
val
ue
)
reference
operator
+=
(
const
basic_json
&
val
)
{
{
push_back
(
val
ue
);
push_back
(
val
);
return
*
this
;
return
*
this
;
}
}
/*!
/*!
@brief add an object to an object
@brief add an object to an object
Inserts the given element @a val
ue
to the JSON object. If the function is
Inserts the given element @a val to the JSON object. If the function is
called on a JSON null value, an empty object is created before inserting @a
called on a JSON null value, an empty object is created before inserting @a
val
ue
.
val.
@param[in] val
ue
the value to add to the JSON object
@param[in] val the value to add to the JSON object
@throw std::domain_error when called on a type other than JSON object or
@throw std::domain_error when called on a type other than JSON object or
null
null
...
@@ -3939,7 +4009,7 @@ class basic_json
...
@@ -3939,7 +4009,7 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
void
push_back
(
const
typename
object_t
::
value_type
&
val
ue
)
void
push_back
(
const
typename
object_t
::
value_type
&
val
)
{
{
// push_back only works for null objects or objects
// push_back only works for null objects or objects
if
(
not
(
is_null
()
or
is_object
()))
if
(
not
(
is_null
()
or
is_object
()))
...
@@ -3955,28 +4025,28 @@ class basic_json
...
@@ -3955,28 +4025,28 @@ class basic_json
}
}
// add element to array
// add element to array
m_value
.
object
->
insert
(
val
ue
);
m_value
.
object
->
insert
(
val
);
}
}
/*!
/*!
@brief add an object to an object
@brief add an object to an object
@copydoc push_back(const typename object_t::value_type&)
@copydoc push_back(const typename object_t::value_type&)
*/
*/
reference
operator
+=
(
const
typename
object_t
::
value_type
&
val
ue
)
reference
operator
+=
(
const
typename
object_t
::
value_type
&
val
)
{
{
push_back
(
val
ue
);
push_back
(
val
);
return
operator
[](
val
ue
.
first
);
return
operator
[](
val
.
first
);
}
}
/*!
/*!
@brief inserts element
@brief inserts element
Inserts element @a val
ue
before iterator @a pos.
Inserts element @a val before iterator @a pos.
@param[in] pos iterator before which the content will be inserted; may be
@param[in] pos iterator before which the content will be inserted; may be
the end() iterator
the end() iterator
@param[in] val
ue
element to insert
@param[in] val element to insert
@return iterator pointing to the inserted @a val
ue
.
@return iterator pointing to the inserted @a val.
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if @a pos is not an iterator of *this
@throw std::domain_error if @a pos is not an iterator of *this
...
@@ -3988,7 +4058,7 @@ class basic_json
...
@@ -3988,7 +4058,7 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
iterator
insert
(
const_iterator
pos
,
const
basic_json
&
val
ue
)
iterator
insert
(
const_iterator
pos
,
const
basic_json
&
val
)
{
{
// insert only works for arrays
// insert only works for arrays
if
(
is_array
())
if
(
is_array
())
...
@@ -4001,7 +4071,7 @@ class basic_json
...
@@ -4001,7 +4071,7 @@ class basic_json
// insert to array and return iterator
// insert to array and return iterator
iterator
result
(
this
);
iterator
result
(
this
);
result
.
m_it
.
array_iterator
=
m_value
.
array
->
insert
(
pos
.
m_it
.
array_iterator
,
val
ue
);
result
.
m_it
.
array_iterator
=
m_value
.
array
->
insert
(
pos
.
m_it
.
array_iterator
,
val
);
return
result
;
return
result
;
}
}
else
else
...
@@ -4014,34 +4084,34 @@ class basic_json
...
@@ -4014,34 +4084,34 @@ class basic_json
@brief inserts element
@brief inserts element
@copydoc insert(const_iterator, const basic_json&)
@copydoc insert(const_iterator, const basic_json&)
*/
*/
iterator
insert
(
const_iterator
pos
,
basic_json
&&
val
ue
)
iterator
insert
(
const_iterator
pos
,
basic_json
&&
val
)
{
{
return
insert
(
pos
,
val
ue
);
return
insert
(
pos
,
val
);
}
}
/*!
/*!
@brief inserts elements
@brief inserts elements
Inserts @a c
ount copies of @a value
before iterator @a pos.
Inserts @a c
nt copies of @a val
before iterator @a pos.
@param[in] pos iterator before which the content will be inserted; may be
@param[in] pos iterator before which the content will be inserted; may be
the end() iterator
the end() iterator
@param[in] c
ount number of copies of @a value
to insert
@param[in] c
nt number of copies of @a val
to insert
@param[in] val
ue
element to insert
@param[in] val element to insert
@return iterator pointing to the first element inserted, or @a pos if
@return iterator pointing to the first element inserted, or @a pos if
`c
ou
nt==0`
`cnt==0`
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if @a pos is not an iterator of *this
@throw std::domain_error if @a pos is not an iterator of *this
@complexity Linear in @a c
ou
nt plus linear in the distance between @a pos
@complexity Linear in @a cnt plus linear in the distance between @a pos
and end of the container.
and end of the container.
@liveexample{The example shows how insert is used.,insert__count}
@liveexample{The example shows how insert is used.,insert__count}
@since version 1.0
@since version 1.0
*/
*/
iterator
insert
(
const_iterator
pos
,
size_type
c
ount
,
const
basic_json
&
value
)
iterator
insert
(
const_iterator
pos
,
size_type
c
nt
,
const
basic_json
&
val
)
{
{
// insert only works for arrays
// insert only works for arrays
if
(
is_array
())
if
(
is_array
())
...
@@ -4054,7 +4124,7 @@ class basic_json
...
@@ -4054,7 +4124,7 @@ class basic_json
// insert to array and return iterator
// insert to array and return iterator
iterator
result
(
this
);
iterator
result
(
this
);
result
.
m_it
.
array_iterator
=
m_value
.
array
->
insert
(
pos
.
m_it
.
array_iterator
,
c
ount
,
value
);
result
.
m_it
.
array_iterator
=
m_value
.
array
->
insert
(
pos
.
m_it
.
array_iterator
,
c
nt
,
val
);
return
result
;
return
result
;
}
}
else
else
...
@@ -5398,9 +5468,14 @@ class basic_json
...
@@ -5398,9 +5468,14 @@ class basic_json
default
:
default
:
{
{
return
m_it
.
primitive_iterator
.
is_begin
()
if
(
m_it
.
primitive_iterator
.
is_begin
())
?
*
m_object
{
:
throw
std
::
out_of_range
(
"cannot get value"
);
return
*
m_object
;
}
else
{
throw
std
::
out_of_range
(
"cannot get value"
);
}
}
}
}
}
}
}
...
@@ -5422,9 +5497,14 @@ class basic_json
...
@@ -5422,9 +5497,14 @@ class basic_json
default
:
default
:
{
{
return
m_it
.
primitive_iterator
.
is_begin
()
if
(
m_it
.
primitive_iterator
.
is_begin
())
?
m_object
{
:
throw
std
::
out_of_range
(
"cannot get value"
);
return
m_object
;
}
else
{
throw
std
::
out_of_range
(
"cannot get value"
);
}
}
}
}
}
}
}
...
@@ -5671,9 +5751,14 @@ class basic_json
...
@@ -5671,9 +5751,14 @@ class basic_json
default
:
default
:
{
{
return
(
m_it
.
primitive_iterator
==
-
n
)
if
(
m_it
.
primitive_iterator
==
-
n
)
?
*
m_object
{
:
throw
std
::
out_of_range
(
"cannot get value"
);
return
*
m_object
;
}
else
{
throw
std
::
out_of_range
(
"cannot get value"
);
}
}
}
}
}
}
}
...
@@ -5681,9 +5766,14 @@ class basic_json
...
@@ -5681,9 +5766,14 @@ class basic_json
/// return the key of an object iterator
/// return the key of an object iterator
typename
object_t
::
key_type
key
()
const
typename
object_t
::
key_type
key
()
const
{
{
return
m_object
->
is_object
()
if
(
m_object
->
is_object
())
?
m_it
.
object_iterator
->
first
{
:
throw
std
::
domain_error
(
"cannot use key() for non-object iterators"
);
return
m_it
.
object_iterator
->
first
;
}
else
{
throw
std
::
domain_error
(
"cannot use key() for non-object iterators"
);
}
}
}
/// return the value of an iterator
/// return the value of an iterator
...
@@ -6207,10 +6297,10 @@ class basic_json
...
@@ -6207,10 +6297,10 @@ class basic_json
return
":"
;
return
":"
;
case
token_type
:
:
value_separator
:
case
token_type
:
:
value_separator
:
return
","
;
return
","
;
case
token_type
:
:
end_of_input
:
return
"<end of input>"
;
case
token_type
:
:
parse_error
:
case
token_type
:
:
parse_error
:
return
"<parse error>"
;
return
"<parse error>"
;
case
token_type
:
:
end_of_input
:
return
"<end of input>"
;
}
}
}
}
...
...
src/json.hpp.re2c
View file @
ac4d4a0f
...
@@ -841,7 +841,7 @@ class basic_json
...
@@ -841,7 +841,7 @@ class basic_json
object | `{}`
object | `{}`
array | `[]`
array | `[]`
@param[in] value the type of the value to create
@param[in] value
_type
the type of the value to create
@complexity Constant.
@complexity Constant.
...
@@ -863,8 +863,8 @@ class basic_json
...
@@ -863,8 +863,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(const value_t value)
basic_json(const value_t value
_type
)
: m_type(value
), m_value(valu
e)
: m_type(value
_type), m_value(value_typ
e)
{}
{}
/*!
/*!
...
@@ -916,9 +916,9 @@ class basic_json
...
@@ -916,9 +916,9 @@ class basic_json
Create an object JSON value with a given content.
Create an object JSON value with a given content.
@param[in] val
ue
a value for the object
@param[in] val a value for the object
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for object value fails
@throw std::bad_alloc if allocation for object value fails
...
@@ -930,8 +930,8 @@ class basic_json
...
@@ -930,8 +930,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(const object_t& val
ue
)
basic_json(const object_t& val)
: m_type(value_t::object), m_value(val
ue
)
: m_type(value_t::object), m_value(val)
{}
{}
/*!
/*!
...
@@ -944,9 +944,9 @@ class basic_json
...
@@ -944,9 +944,9 @@ class basic_json
@tparam CompatibleObjectType an object type whose `key_type` and
@tparam CompatibleObjectType an object type whose `key_type` and
`value_type` is compatible to @ref object_t
`value_type` is compatible to @ref object_t
@param[in] val
ue
a value for the object
@param[in] val a value for the object
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for object value fails
@throw std::bad_alloc if allocation for object value fails
...
@@ -962,12 +962,12 @@ class basic_json
...
@@ -962,12 +962,12 @@ class basic_json
std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
= 0>
= 0>
basic_json(const CompatibleObjectType& val
ue
)
basic_json(const CompatibleObjectType& val)
: m_type(value_t::object)
: m_type(value_t::object)
{
{
using std::begin;
using std::begin;
using std::end;
using std::end;
m_value.object = create<object_t>(begin(val
ue), end(value
));
m_value.object = create<object_t>(begin(val
), end(val
));
}
}
/*!
/*!
...
@@ -975,9 +975,9 @@ class basic_json
...
@@ -975,9 +975,9 @@ class basic_json
Create an array JSON value with a given content.
Create an array JSON value with a given content.
@param[in] val
ue
a value for the array
@param[in] val a value for the array
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for array value fails
@throw std::bad_alloc if allocation for array value fails
...
@@ -989,8 +989,8 @@ class basic_json
...
@@ -989,8 +989,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(const array_t& val
ue
)
basic_json(const array_t& val)
: m_type(value_t::array), m_value(val
ue
)
: m_type(value_t::array), m_value(val)
{}
{}
/*!
/*!
...
@@ -1003,9 +1003,9 @@ class basic_json
...
@@ -1003,9 +1003,9 @@ class basic_json
@tparam CompatibleArrayType an object type whose `value_type` is compatible
@tparam CompatibleArrayType an object type whose `value_type` is compatible
to @ref array_t
to @ref array_t
@param[in] val
ue
a value for the array
@param[in] val a value for the array
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for array value fails
@throw std::bad_alloc if allocation for array value fails
...
@@ -1026,12 +1026,12 @@ class basic_json
...
@@ -1026,12 +1026,12 @@ class basic_json
not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
= 0>
= 0>
basic_json(const CompatibleArrayType& val
ue
)
basic_json(const CompatibleArrayType& val)
: m_type(value_t::array)
: m_type(value_t::array)
{
{
using std::begin;
using std::begin;
using std::end;
using std::end;
m_value.array = create<array_t>(begin(val
ue), end(value
));
m_value.array = create<array_t>(begin(val
), end(val
));
}
}
/*!
/*!
...
@@ -1039,9 +1039,9 @@ class basic_json
...
@@ -1039,9 +1039,9 @@ class basic_json
Create an string JSON value with a given content.
Create an string JSON value with a given content.
@param[in] val
ue
a value for the string
@param[in] val a value for the string
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for string value fails
@throw std::bad_alloc if allocation for string value fails
...
@@ -1055,8 +1055,8 @@ class basic_json
...
@@ -1055,8 +1055,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(const string_t& val
ue
)
basic_json(const string_t& val)
: m_type(value_t::string), m_value(val
ue
)
: m_type(value_t::string), m_value(val)
{}
{}
/*!
/*!
...
@@ -1064,9 +1064,9 @@ class basic_json
...
@@ -1064,9 +1064,9 @@ class basic_json
Create a string JSON value with a given content.
Create a string JSON value with a given content.
@param[in] val
ue
a literal value for the string
@param[in] val a literal value for the string
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for string value fails
@throw std::bad_alloc if allocation for string value fails
...
@@ -1079,8 +1079,8 @@ class basic_json
...
@@ -1079,8 +1079,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(const typename string_t::value_type* val
ue
)
basic_json(const typename string_t::value_type* val)
: basic_json(string_t(val
ue
))
: basic_json(string_t(val))
{}
{}
/*!
/*!
...
@@ -1088,12 +1088,12 @@ class basic_json
...
@@ -1088,12 +1088,12 @@ class basic_json
Create a string JSON value with a given content.
Create a string JSON value with a given content.
@param[in] val
ue
a value for the string
@param[in] val a value for the string
@tparam CompatibleStringType an string type which is compatible to @ref
@tparam CompatibleStringType an string type which is compatible to @ref
string_t
string_t
@complexity Linear in the size of the passed @a val
ue
.
@complexity Linear in the size of the passed @a val.
@throw std::bad_alloc if allocation for string value fails
@throw std::bad_alloc if allocation for string value fails
...
@@ -1110,8 +1110,8 @@ class basic_json
...
@@ -1110,8 +1110,8 @@ class basic_json
std::enable_if<
std::enable_if<
std::is_constructible<string_t, CompatibleStringType>::value, int>::type
std::is_constructible<string_t, CompatibleStringType>::value, int>::type
= 0>
= 0>
basic_json(const CompatibleStringType& val
ue
)
basic_json(const CompatibleStringType& val)
: basic_json(string_t(val
ue
))
: basic_json(string_t(val))
{}
{}
/*!
/*!
...
@@ -1119,7 +1119,7 @@ class basic_json
...
@@ -1119,7 +1119,7 @@ class basic_json
Creates a JSON boolean type from a given value.
Creates a JSON boolean type from a given value.
@param[in] val
ue
a boolean value to store
@param[in] val a boolean value to store
@complexity Constant.
@complexity Constant.
...
@@ -1128,8 +1128,8 @@ class basic_json
...
@@ -1128,8 +1128,8 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(boolean_t val
ue
)
basic_json(boolean_t val)
: m_type(value_t::boolean), m_value(val
ue
)
: m_type(value_t::boolean), m_value(val)
{}
{}
/*!
/*!
...
@@ -1140,7 +1140,7 @@ class basic_json
...
@@ -1140,7 +1140,7 @@ class basic_json
@tparam T helper type to compare number_integer_t and int (not visible in)
@tparam T helper type to compare number_integer_t and int (not visible in)
the interface.
the interface.
@param[in] val
ue
an integer to create a JSON number from
@param[in] val an integer to create a JSON number from
@note This constructor would have the same signature as @ref
@note This constructor would have the same signature as @ref
basic_json(const int value), so we need to switch this one off in case
basic_json(const int value), so we need to switch this one off in case
...
@@ -1162,8 +1162,8 @@ class basic_json
...
@@ -1162,8 +1162,8 @@ class basic_json
not (std::is_same<T, int>::value)
not (std::is_same<T, int>::value)
and std::is_same<T, number_integer_t>::value
and std::is_same<T, number_integer_t>::value
, int>::type = 0>
, int>::type = 0>
basic_json(const number_integer_t val
ue
)
basic_json(const number_integer_t val)
: m_type(value_t::number_integer), m_value(val
ue
)
: m_type(value_t::number_integer), m_value(val)
{}
{}
/*!
/*!
...
@@ -1171,7 +1171,7 @@ class basic_json
...
@@ -1171,7 +1171,7 @@ class basic_json
Create an integer number JSON value with a given content.
Create an integer number JSON value with a given content.
@param[in] val
ue
an integer to create a JSON number from
@param[in] val an integer to create a JSON number from
@note This constructor allows to pass enums directly to a constructor. As
@note This constructor allows to pass enums directly to a constructor. As
C++ has no way of specifying the type of an anonymous enum explicitly, we
C++ has no way of specifying the type of an anonymous enum explicitly, we
...
@@ -1191,9 +1191,9 @@ class basic_json
...
@@ -1191,9 +1191,9 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(const int val
ue
)
basic_json(const int val)
: m_type(value_t::number_integer),
: m_type(value_t::number_integer),
m_value(static_cast<number_integer_t>(val
ue
))
m_value(static_cast<number_integer_t>(val))
{}
{}
/*!
/*!
...
@@ -1207,7 +1207,7 @@ class basic_json
...
@@ -1207,7 +1207,7 @@ class basic_json
@tparam CompatibleNumberIntegerType an integer type which is compatible to
@tparam CompatibleNumberIntegerType an integer type which is compatible to
@ref number_integer_t.
@ref number_integer_t.
@param[in] val
ue
an integer to create a JSON number from
@param[in] val an integer to create a JSON number from
@complexity Constant.
@complexity Constant.
...
@@ -1226,9 +1226,9 @@ class basic_json
...
@@ -1226,9 +1226,9 @@ class basic_json
std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
std::numeric_limits<CompatibleNumberIntegerType>::is_integer, CompatibleNumberIntegerType>::type
std::numeric_limits<CompatibleNumberIntegerType>::is_integer, CompatibleNumberIntegerType>::type
= 0>
= 0>
basic_json(const CompatibleNumberIntegerType val
ue
) noexcept
basic_json(const CompatibleNumberIntegerType val) noexcept
: m_type(value_t::number_integer),
: m_type(value_t::number_integer),
m_value(static_cast<number_integer_t>(val
ue
))
m_value(static_cast<number_integer_t>(val))
{}
{}
/*!
/*!
...
@@ -1236,13 +1236,13 @@ class basic_json
...
@@ -1236,13 +1236,13 @@ class basic_json
Create a floating-point number JSON value with a given content.
Create a floating-point number JSON value with a given content.
@param[in] val
ue
a floating-point value to create a JSON number from
@param[in] val a floating-point value to create a JSON number from
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
disallows NaN values:
disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such
> Numeric values that cannot be represented in the grammar below (such
> as Infinity and NaN) are not permitted.
> as Infinity and NaN) are not permitted.
In case the parameter @a val
ue
is not a number, a JSON null value is
In case the parameter @a val is not a number, a JSON null value is
created instead.
created instead.
@complexity Constant.
@complexity Constant.
...
@@ -1255,11 +1255,11 @@ class basic_json
...
@@ -1255,11 +1255,11 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(const number_float_t val
ue
)
basic_json(const number_float_t val)
: m_type(value_t::number_float), m_value(val
ue
)
: m_type(value_t::number_float), m_value(val)
{
{
// replace infinity and NAN by null
// replace infinity and NAN by null
if (not std::isfinite(val
ue
))
if (not std::isfinite(val))
{
{
m_type = value_t::null;
m_type = value_t::null;
m_value = json_value();
m_value = json_value();
...
@@ -1276,13 +1276,13 @@ class basic_json
...
@@ -1276,13 +1276,13 @@ class basic_json
@tparam CompatibleNumberFloatType a floating-point type which is compatible
@tparam CompatibleNumberFloatType a floating-point type which is compatible
to @ref number_float_t.
to @ref number_float_t.
@param[in] val
ue
a floating-point to create a JSON number from
@param[in] val a floating-point to create a JSON number from
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
disallows NaN values:
disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such
> Numeric values that cannot be represented in the grammar below (such
> as Infinity and NaN) are not permitted.
> as Infinity and NaN) are not permitted.
In case the parameter @a val
ue
is not a number, a JSON null value is
In case the parameter @a val is not a number, a JSON null value is
created instead.
created instead.
@complexity Constant.
@complexity Constant.
...
@@ -1301,8 +1301,8 @@ class basic_json
...
@@ -1301,8 +1301,8 @@ class basic_json
std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
std::is_floating_point<CompatibleNumberFloatType>::value>::type
std::is_floating_point<CompatibleNumberFloatType>::value>::type
>
>
basic_json(const CompatibleNumberFloatType val
ue
) noexcept
basic_json(const CompatibleNumberFloatType val) noexcept
: basic_json(number_float_t(val
ue
))
: basic_json(number_float_t(val))
{}
{}
/*!
/*!
...
@@ -1378,7 +1378,7 @@ class basic_json
...
@@ -1378,7 +1378,7 @@ class basic_json
value_t manual_type = value_t::array)
value_t manual_type = value_t::array)
{
{
// the initializer list could describe an object
// the initializer list could describe an object
bool is_object = true;
bool is_
an_
object = true;
// check if each element is an array with two elements whose first
// check if each element is an array with two elements whose first
// element is a string
// element is a string
...
@@ -1389,7 +1389,7 @@ class basic_json
...
@@ -1389,7 +1389,7 @@ class basic_json
{
{
// we found an element that makes it impossible to use the
// we found an element that makes it impossible to use the
// initializer list as object
// initializer list as object
is_object = false;
is_
an_
object = false;
break;
break;
}
}
}
}
...
@@ -1400,17 +1400,17 @@ class basic_json
...
@@ -1400,17 +1400,17 @@ class basic_json
// if array is wanted, do not create an object though possible
// if array is wanted, do not create an object though possible
if (manual_type == value_t::array)
if (manual_type == value_t::array)
{
{
is_object = false;
is_
an_
object = false;
}
}
// if object is wanted but impossible, throw an exception
// if object is wanted but impossible, throw an exception
if (manual_type == value_t::object and not is_object)
if (manual_type == value_t::object and not is_
an_
object)
{
{
throw std::domain_error("cannot create object from initializer list");
throw std::domain_error("cannot create object from initializer list");
}
}
}
}
if (is_object)
if (is_
an_
object)
{
{
// the initializer list is a list of pairs -> create object
// the initializer list is a list of pairs -> create object
m_type = value_t::object;
m_type = value_t::object;
...
@@ -1512,14 +1512,14 @@ class basic_json
...
@@ -1512,14 +1512,14 @@ class basic_json
/*!
/*!
@brief construct an array with count copies of given value
@brief construct an array with count copies of given value
Constructs a JSON array value by creating @a c
ou
nt copies of a passed
Constructs a JSON array value by creating @a cnt copies of a passed
value. In case @a c
ou
nt is `0`, an empty array is created. As postcondition,
value. In case @a cnt is `0`, an empty array is created. As postcondition,
`std::distance(begin(),end()) == c
ou
nt` holds.
`std::distance(begin(),end()) == cnt` holds.
@param[in] c
ount the number of JSON copies of @a value
to create
@param[in] c
nt the number of JSON copies of @a val
to create
@param[in] val
ue
the JSON value to copy
@param[in] val the JSON value to copy
@complexity Linear in @a c
ou
nt.
@complexity Linear in @a cnt.
@liveexample{The following code shows examples for the @ref
@liveexample{The following code shows examples for the @ref
basic_json(size_type\, const basic_json&)
basic_json(size_type\, const basic_json&)
...
@@ -1527,10 +1527,10 @@ class basic_json
...
@@ -1527,10 +1527,10 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
basic_json(size_type c
ount, const basic_json& value
)
basic_json(size_type c
nt, const basic_json& val
)
: m_type(value_t::array)
: m_type(value_t::array)
{
{
m_value.array = create<array_t>(c
ount, value
);
m_value.array = create<array_t>(c
nt, val
);
}
}
/*!
/*!
...
@@ -2161,17 +2161,27 @@ class basic_json
...
@@ -2161,17 +2161,27 @@ class basic_json
, int>::type = 0>
, int>::type = 0>
T get_impl(T*) const
T get_impl(T*) const
{
{
return is_object()
if (is_object())
? T(m_value.object->begin(), m_value.object->end())
{
: throw std::domain_error("type must be object, but is " + type_name());
return T(m_value.object->begin(), m_value.object->end());
}
else
{
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*) const
{
{
return is_object()
if (is_object())
? *(m_value.object)
{
: throw std::domain_error("type must be object, but is " + type_name());
return *(m_value.object);
}
else
{
throw std::domain_error("type must be object, but is " + type_name());
}
}
}
/// get an array (explicit)
/// get an array (explicit)
...
@@ -2234,17 +2244,27 @@ class basic_json
...
@@ -2234,17 +2244,27 @@ class basic_json
, int>::type = 0>
, int>::type = 0>
T get_impl(T*) const
T get_impl(T*) const
{
{
return is_array()
if (is_array())
? T(m_value.array->begin(), m_value.array->end())
{
: throw std::domain_error("type must be array, but is " + type_name());
return T(m_value.array->begin(), m_value.array->end());
}
else
{
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*) const
{
{
return is_array()
if (is_array())
? *(m_value.array)
{
: throw std::domain_error("type must be array, but is " + type_name());
return *(m_value.array);
}
else
{
throw std::domain_error("type must be array, but is " + type_name());
}
}
}
/// get a string (explicit)
/// get a string (explicit)
...
@@ -2254,9 +2274,14 @@ class basic_json
...
@@ -2254,9 +2274,14 @@ class basic_json
, int>::type = 0>
, int>::type = 0>
T get_impl(T*) const
T get_impl(T*) const
{
{
return is_string()
if (is_string())
? *m_value.string
{
: throw std::domain_error("type must be string, but is " + type_name());
return *m_value.string;
}
else
{
throw std::domain_error("type must be string, but is " + type_name());
}
}
}
/// get a number (explicit)
/// get a number (explicit)
...
@@ -2288,9 +2313,14 @@ class basic_json
...
@@ -2288,9 +2313,14 @@ class basic_json
/// get a boolean (explicit)
/// get a boolean (explicit)
boolean_t get_impl(boolean_t*) const
boolean_t get_impl(boolean_t*) const
{
{
return is_boolean()
if (is_boolean())
? m_value.boolean
{
: throw std::domain_error("type must be boolean, but is " + type_name());
return m_value.boolean;
}
else
{
throw std::domain_error("type must be boolean, but is " + type_name());
}
}
}
/// get a pointer to the value (object)
/// get a pointer to the value (object)
...
@@ -2582,9 +2612,14 @@ class basic_json
...
@@ -2582,9 +2612,14 @@ class basic_json
reference at(size_type idx)
reference at(size_type idx)
{
{
// at only works for arrays
// at only works for arrays
return is_array()
if (is_array())
? m_value.array->at(idx)
{
: throw std::domain_error("cannot use at() with " + type_name());
return m_value.array->at(idx);
}
else
{
throw std::domain_error("cannot use at() with " + type_name());
}
}
}
/*!
/*!
...
@@ -2611,9 +2646,14 @@ class basic_json
...
@@ -2611,9 +2646,14 @@ class basic_json
const_reference at(size_type idx) const
const_reference at(size_type idx) const
{
{
// at only works for arrays
// at only works for arrays
return is_array()
if (is_array())
? m_value.array->at(idx)
{
: throw std::domain_error("cannot use at() with " + type_name());
return m_value.array->at(idx);
}
else
{
throw std::domain_error("cannot use at() with " + type_name());
}
}
}
/*!
/*!
...
@@ -2644,9 +2684,14 @@ class basic_json
...
@@ -2644,9 +2684,14 @@ class basic_json
reference at(const typename object_t::key_type& key)
reference at(const typename object_t::key_type& key)
{
{
// at only works for objects
// at only works for objects
return is_object()
if (is_object())
? m_value.object->at(key)
{
: throw std::domain_error("cannot use at() with " + type_name());
return m_value.object->at(key);
}
else
{
throw std::domain_error("cannot use at() with " + type_name());
}
}
}
/*!
/*!
...
@@ -2677,9 +2722,14 @@ class basic_json
...
@@ -2677,9 +2722,14 @@ class basic_json
const_reference at(const typename object_t::key_type& key) const
const_reference at(const typename object_t::key_type& key) const
{
{
// at only works for objects
// at only works for objects
return is_object()
if (is_object())
? m_value.object->at(key)
{
: throw std::domain_error("cannot use at() with " + type_name());
return m_value.object->at(key);
}
else
{
throw std::domain_error("cannot use at() with " + type_name());
}
}
}
/*!
/*!
...
@@ -2752,9 +2802,14 @@ class basic_json
...
@@ -2752,9 +2802,14 @@ class basic_json
const_reference operator[](size_type idx) const
const_reference operator[](size_type idx) const
{
{
// at only works for arrays
// at only works for arrays
return is_array()
if (is_array())
? m_value.array->operator[](idx)
{
: throw std::domain_error("cannot use operator[] with " + type_name());
return m_value.array->operator[](idx);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
}
}
/*!
/*!
...
@@ -2793,9 +2848,14 @@ class basic_json
...
@@ -2793,9 +2848,14 @@ class basic_json
}
}
// [] only works for objects
// [] only works for objects
return is_object()
if (is_object())
? m_value.object->operator[](key)
{
: throw std::domain_error("cannot use operator[] with " + type_name());
return m_value.object->operator[](key);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
}
}
/*!
/*!
...
@@ -2837,9 +2897,14 @@ class basic_json
...
@@ -2837,9 +2897,14 @@ class basic_json
}
}
// at only works for objects
// at only works for objects
return is_object()
if (is_object())
? m_value.object->operator[](key)
{
: throw std::domain_error("cannot use operator[] with " + type_name());
return m_value.object->operator[](key);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
}
}
/*!
/*!
...
@@ -3227,9 +3292,14 @@ class basic_json
...
@@ -3227,9 +3292,14 @@ class basic_json
size_type erase(const typename object_t::key_type& key)
size_type erase(const typename object_t::key_type& key)
{
{
// this erase only works for objects
// this erase only works for objects
return is_object()
if (is_object())
? m_value.object->erase(key)
{
: throw std::domain_error("cannot use erase() with " + type_name());
return m_value.object->erase(key);
}
else
{
throw std::domain_error("cannot use erase() with " + type_name());
}
}
}
/*!
/*!
...
@@ -3839,11 +3909,11 @@ class basic_json
...
@@ -3839,11 +3909,11 @@ class basic_json
/*!
/*!
@brief add an object to an array
@brief add an object to an array
Appends the given element @a val
ue
to the end of the JSON value. If the
Appends the given element @a val to the end of the JSON value. If the
function is called on a JSON null value, an empty array is created before
function is called on a JSON null value, an empty array is created before
appending @a val
ue
.
appending @a val.
@param val
ue
the value to add to the JSON array
@param val the value to add to the JSON array
@throw std::domain_error when called on a type other than JSON array or null
@throw std::domain_error when called on a type other than JSON array or null
...
@@ -3855,7 +3925,7 @@ class basic_json
...
@@ -3855,7 +3925,7 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
void push_back(basic_json&& val
ue
)
void push_back(basic_json&& val)
{
{
// push_back only works for null objects or arrays
// push_back only works for null objects or arrays
if (not(is_null() or is_array()))
if (not(is_null() or is_array()))
...
@@ -3871,18 +3941,18 @@ class basic_json
...
@@ -3871,18 +3941,18 @@ class basic_json
}
}
// add element to array (move semantics)
// add element to array (move semantics)
m_value.array->push_back(std::move(val
ue
));
m_value.array->push_back(std::move(val));
// invalidate object
// invalidate object
val
ue
.m_type = value_t::null;
val.m_type = value_t::null;
}
}
/*!
/*!
@brief add an object to an array
@brief add an object to an array
@copydoc push_back(basic_json&&)
@copydoc push_back(basic_json&&)
*/
*/
reference operator+=(basic_json&& val
ue
)
reference operator+=(basic_json&& val)
{
{
push_back(std::move(val
ue
));
push_back(std::move(val));
return *this;
return *this;
}
}
...
@@ -3890,7 +3960,7 @@ class basic_json
...
@@ -3890,7 +3960,7 @@ class basic_json
@brief add an object to an array
@brief add an object to an array
@copydoc push_back(basic_json&&)
@copydoc push_back(basic_json&&)
*/
*/
void push_back(const basic_json& val
ue
)
void push_back(const basic_json& val)
{
{
// push_back only works for null objects or arrays
// push_back only works for null objects or arrays
if (not(is_null() or is_array()))
if (not(is_null() or is_array()))
...
@@ -3906,27 +3976,27 @@ class basic_json
...
@@ -3906,27 +3976,27 @@ class basic_json
}
}
// add element to array
// add element to array
m_value.array->push_back(val
ue
);
m_value.array->push_back(val);
}
}
/*!
/*!
@brief add an object to an array
@brief add an object to an array
@copydoc push_back(basic_json&&)
@copydoc push_back(basic_json&&)
*/
*/
reference operator+=(const basic_json& val
ue
)
reference operator+=(const basic_json& val)
{
{
push_back(val
ue
);
push_back(val);
return *this;
return *this;
}
}
/*!
/*!
@brief add an object to an object
@brief add an object to an object
Inserts the given element @a val
ue
to the JSON object. If the function is
Inserts the given element @a val to the JSON object. If the function is
called on a JSON null value, an empty object is created before inserting @a
called on a JSON null value, an empty object is created before inserting @a
val
ue
.
val.
@param[in] val
ue
the value to add to the JSON object
@param[in] val the value to add to the JSON object
@throw std::domain_error when called on a type other than JSON object or
@throw std::domain_error when called on a type other than JSON object or
null
null
...
@@ -3939,7 +4009,7 @@ class basic_json
...
@@ -3939,7 +4009,7 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
void push_back(const typename object_t::value_type& val
ue
)
void push_back(const typename object_t::value_type& val)
{
{
// push_back only works for null objects or objects
// push_back only works for null objects or objects
if (not(is_null() or is_object()))
if (not(is_null() or is_object()))
...
@@ -3955,28 +4025,28 @@ class basic_json
...
@@ -3955,28 +4025,28 @@ class basic_json
}
}
// add element to array
// add element to array
m_value.object->insert(val
ue
);
m_value.object->insert(val);
}
}
/*!
/*!
@brief add an object to an object
@brief add an object to an object
@copydoc push_back(const typename object_t::value_type&)
@copydoc push_back(const typename object_t::value_type&)
*/
*/
reference operator+=(const typename object_t::value_type& val
ue
)
reference operator+=(const typename object_t::value_type& val)
{
{
push_back(val
ue
);
push_back(val);
return operator[](val
ue
.first);
return operator[](val.first);
}
}
/*!
/*!
@brief inserts element
@brief inserts element
Inserts element @a val
ue
before iterator @a pos.
Inserts element @a val before iterator @a pos.
@param[in] pos iterator before which the content will be inserted; may be
@param[in] pos iterator before which the content will be inserted; may be
the end() iterator
the end() iterator
@param[in] val
ue
element to insert
@param[in] val element to insert
@return iterator pointing to the inserted @a val
ue
.
@return iterator pointing to the inserted @a val.
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if @a pos is not an iterator of *this
@throw std::domain_error if @a pos is not an iterator of *this
...
@@ -3988,7 +4058,7 @@ class basic_json
...
@@ -3988,7 +4058,7 @@ class basic_json
@since version 1.0
@since version 1.0
*/
*/
iterator insert(const_iterator pos, const basic_json& val
ue
)
iterator insert(const_iterator pos, const basic_json& val)
{
{
// insert only works for arrays
// insert only works for arrays
if (is_array())
if (is_array())
...
@@ -4001,7 +4071,7 @@ class basic_json
...
@@ -4001,7 +4071,7 @@ class basic_json
// insert to array and return iterator
// insert to array and return iterator
iterator result(this);
iterator result(this);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val
ue
);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
return result;
return result;
}
}
else
else
...
@@ -4014,34 +4084,34 @@ class basic_json
...
@@ -4014,34 +4084,34 @@ class basic_json
@brief inserts element
@brief inserts element
@copydoc insert(const_iterator, const basic_json&)
@copydoc insert(const_iterator, const basic_json&)
*/
*/
iterator insert(const_iterator pos, basic_json&& val
ue
)
iterator insert(const_iterator pos, basic_json&& val)
{
{
return insert(pos, val
ue
);
return insert(pos, val);
}
}
/*!
/*!
@brief inserts elements
@brief inserts elements
Inserts @a c
ount copies of @a value
before iterator @a pos.
Inserts @a c
nt copies of @a val
before iterator @a pos.
@param[in] pos iterator before which the content will be inserted; may be
@param[in] pos iterator before which the content will be inserted; may be
the end() iterator
the end() iterator
@param[in] c
ount number of copies of @a value
to insert
@param[in] c
nt number of copies of @a val
to insert
@param[in] val
ue
element to insert
@param[in] val element to insert
@return iterator pointing to the first element inserted, or @a pos if
@return iterator pointing to the first element inserted, or @a pos if
`c
ou
nt==0`
`cnt==0`
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if called on JSON values other than arrays
@throw std::domain_error if @a pos is not an iterator of *this
@throw std::domain_error if @a pos is not an iterator of *this
@complexity Linear in @a c
ou
nt plus linear in the distance between @a pos
@complexity Linear in @a cnt plus linear in the distance between @a pos
and end of the container.
and end of the container.
@liveexample{The example shows how insert is used.,insert__count}
@liveexample{The example shows how insert is used.,insert__count}
@since version 1.0
@since version 1.0
*/
*/
iterator insert(const_iterator pos, size_type c
ount, const basic_json& value
)
iterator insert(const_iterator pos, size_type c
nt, const basic_json& val
)
{
{
// insert only works for arrays
// insert only works for arrays
if (is_array())
if (is_array())
...
@@ -4054,7 +4124,7 @@ class basic_json
...
@@ -4054,7 +4124,7 @@ class basic_json
// insert to array and return iterator
// insert to array and return iterator
iterator result(this);
iterator result(this);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, c
ount, value
);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, c
nt, val
);
return result;
return result;
}
}
else
else
...
@@ -5398,9 +5468,14 @@ class basic_json
...
@@ -5398,9 +5468,14 @@ class basic_json
default:
default:
{
{
return m_it.primitive_iterator.is_begin()
if (m_it.primitive_iterator.is_begin())
? *m_object
{
: throw std::out_of_range("cannot get value");
return *m_object;
}
else
{
throw std::out_of_range("cannot get value");
}
}
}
}
}
}
}
...
@@ -5422,9 +5497,14 @@ class basic_json
...
@@ -5422,9 +5497,14 @@ class basic_json
default:
default:
{
{
return m_it.primitive_iterator.is_begin()
if (m_it.primitive_iterator.is_begin())
? m_object
{
: throw std::out_of_range("cannot get value");
return m_object;
}
else
{
throw std::out_of_range("cannot get value");
}
}
}
}
}
}
}
...
@@ -5671,9 +5751,14 @@ class basic_json
...
@@ -5671,9 +5751,14 @@ class basic_json
default:
default:
{
{
return (m_it.primitive_iterator == -n)
if (m_it.primitive_iterator == -n)
? *m_object
{
: throw std::out_of_range("cannot get value");
return *m_object;
}
else
{
throw std::out_of_range("cannot get value");
}
}
}
}
}
}
}
...
@@ -5681,9 +5766,14 @@ class basic_json
...
@@ -5681,9 +5766,14 @@ class basic_json
/// return the key of an object iterator
/// return the key of an object iterator
typename object_t::key_type key() const
typename object_t::key_type key() const
{
{
return m_object->is_object()
if (m_object->is_object())
? m_it.object_iterator->first
{
: throw std::domain_error("cannot use key() for non-object iterators");
return m_it.object_iterator->first;
}
else
{
throw std::domain_error("cannot use key() for non-object iterators");
}
}
}
/// return the value of an iterator
/// return the value of an iterator
...
@@ -6207,10 +6297,10 @@ class basic_json
...
@@ -6207,10 +6297,10 @@ class basic_json
return ":";
return ":";
case token_type::value_separator:
case token_type::value_separator:
return ",";
return ",";
case token_type::end_of_input:
return "<end of input>";
case token_type::parse_error:
case token_type::parse_error:
return "<parse error>";
return "<parse error>";
case token_type::end_of_input:
return "<end of input>";
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment