Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
844bfd39
Commit
844bfd39
authored
Jun 22, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more documentation
parent
27b0a4d1
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
238 additions
and
48 deletions
+238
-48
doc/Makefile
doc/Makefile
+1
-1
doc/css/mylayout.css
doc/css/mylayout.css
+10
-3
doc/examples/basic_json__CompatibleIntegerNumberType.cpp
doc/examples/basic_json__CompatibleIntegerNumberType.cpp
+27
-0
doc/examples/basic_json__CompatibleIntegerNumberType.output
doc/examples/basic_json__CompatibleIntegerNumberType.output
+5
-0
doc/examples/basic_json__number_float_t.cpp
doc/examples/basic_json__number_float_t.cpp
+21
-0
doc/examples/basic_json__number_float_t.output
doc/examples/basic_json__number_float_t.output
+3
-0
doc/examples/basic_json__number_integer_t.cpp
doc/examples/basic_json__number_integer_t.cpp
+14
-0
doc/examples/basic_json__number_integer_t.output
doc/examples/basic_json__number_integer_t.output
+1
-0
src/json.hpp
src/json.hpp
+78
-22
src/json.hpp.re2c
src/json.hpp.re2c
+78
-22
No files found.
doc/Makefile
View file @
844bfd39
...
@@ -41,7 +41,7 @@ doxygen: create_output
...
@@ -41,7 +41,7 @@ doxygen: create_output
gsed
-i
's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g'
html/
*
.html
gsed
-i
's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g'
html/
*
.html
gsed
-i
's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g'
html/
*
.html
gsed
-i
's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g'
html/
*
.html
upload
:
doxygen
upload
:
doxygen
check_output
cd
html
;
../git-update-ghpages nlohmann/json
cd
html
;
../git-update-ghpages nlohmann/json
rm
-fr
html
rm
-fr
html
open http://nlohmann.github.io/json/
open http://nlohmann.github.io/json/
...
...
doc/css/mylayout.css
View file @
844bfd39
.memtemplate
{
/* hide lengthy template information */
.memtemplate
,
.memTemplParams
{
display
:
none
;
display
:
none
;
}
}
.memTemplParams
{
/* allow compiler information to wrap */
display
:
none
;
/* https://css-tricks.com/snippets/css/make-pre-text-wrap/ */
pre
.fragment
{
white-space
:
pre-wrap
;
/* css-3 */
white-space
:
-moz-pre-wrap
;
/* Mozilla, since 1999 */
white-space
:
-pre-wrap
;
/* Opera 4-6 */
white-space
:
-o-pre-wrap
;
/* Opera 7 */
word-wrap
:
break-word
;
/* Internet Explorer 5.5+ */
}
}
doc/examples/basic_json__CompatibleIntegerNumberType.cpp
0 → 100644
View file @
844bfd39
#include <json.hpp>
using
namespace
nlohmann
;
int
main
()
{
// create values of different integer types
short
n42
=
42
;
int
n23
=
23
;
long
n1024
=
1024
;
int_least32_t
n17
=
17
;
uint8_t
n8
=
8
;
// create JSON numbers
json
j42
(
n42
);
json
j23
(
n23
);
json
j1024
(
n1024
);
json
j17
(
n17
);
json
j8
(
n8
);
// serialize the JSON numbers
std
::
cout
<<
j42
<<
'\n'
;
std
::
cout
<<
j23
<<
'\n'
;
std
::
cout
<<
j1024
<<
'\n'
;
std
::
cout
<<
j17
<<
'\n'
;
std
::
cout
<<
j8
<<
'\n'
;
}
doc/examples/basic_json__CompatibleIntegerNumberType.output
0 → 100644
View file @
844bfd39
42
23
1024
17
8
doc/examples/basic_json__number_float_t.cpp
0 → 100644
View file @
844bfd39
#include <json.hpp>
using
namespace
nlohmann
;
int
main
()
{
// create values of different floating-point types
json
::
number_float_t
v_ok
=
3.141592653589793
;
json
::
number_float_t
v_nan
=
NAN
;
json
::
number_float_t
v_infinity
=
INFINITY
;
// create JSON numbers
json
j_ok
(
v_ok
);
json
j_nan
(
v_nan
);
json
j_infinity
(
v_infinity
);
// serialize the JSON numbers
std
::
cout
<<
j_ok
<<
'\n'
;
std
::
cout
<<
j_nan
<<
'\n'
;
std
::
cout
<<
j_infinity
<<
'\n'
;
}
doc/examples/basic_json__number_float_t.output
0 → 100644
View file @
844bfd39
3.14159265358979
null
null
doc/examples/basic_json__number_integer_t.cpp
0 → 100644
View file @
844bfd39
#include <json.hpp>
using
namespace
nlohmann
;
int
main
()
{
// create a JSON number from number_integer_t
json
::
number_integer_t
value
=
42
;
json
j
(
value
);
// serialize the JSON numbers
std
::
cout
<<
j
<<
'\n'
;
}
doc/examples/basic_json__number_integer_t.output
0 → 100644
View file @
844bfd39
42
src/json.hpp
View file @
844bfd39
...
@@ -600,7 +600,7 @@ class basic_json
...
@@ -600,7 +600,7 @@ class basic_json
/*!
/*!
@brief create a string (explicit)
@brief create a string (explicit)
Create a
n
string JSON value with a given content.
Create a string JSON value with a given content.
@param[in] value a literal value for the string
@param[in] value a literal value for the string
...
@@ -636,13 +636,22 @@ class basic_json
...
@@ -636,13 +636,22 @@ class basic_json
/*!
/*!
@brief create an integer number (explicit)
@brief create an integer number (explicit)
@tparam T helper type to compare number_integer_t and int
Create an interger number JSON value with a given content.
@tparam T helper type to compare number_integer_t and int (not visible in)
the interface.
@param[in] value an integer to create a JSON number from
@param[in] value an integer to create a JSON number from
This constructor takes care about explicitly passed values of type
@note This constructor would have the same signature as @ref
number_integer_t. However, this constructor would have the same signature
basic_json(const int value), so we need to switch this one off in case
as the existing one for const int values, so we need to switch this one off
number_integer_t is the same as int. This is done via the helper type @a T.
in case number_integer_t is the same as int.
@complexity Constant.
@todo Add example.
@sa basic_json(const int)
*/
*/
template
<
typename
T
,
template
<
typename
T
,
typename
std
::
enable_if
<
typename
std
::
enable_if
<
...
@@ -654,33 +663,80 @@ class basic_json
...
@@ -654,33 +663,80 @@ class basic_json
{}
{}
/*!
/*!
@brief create an int number to support enum type (implicit)
@brief create an integer number from an enum type (explicit)
Create an interger number JSON value with a given content.
@param[in] value an integer to create a JSON number from
@param[in] value an integer to create a JSON number from
This constructor allows to pass enums directly to a constructor. As C++ has
@note This constructor allows to pass enums directly to a constructor. As
no way of specifying the type of an anonymous enum explicitly, we can only
C++ has no way of specifying the type of an anonymous enum explicitly, we
rely on the fact that such values implicitly convert to int. As int may
can only rely on the fact that such values implicitly convert to int. As
already be the same type of number_integer_t, we may need to switch off
int may already be the same type of number_integer_t, we may need to switch
that constructor, which is done above.
off the constructor @ref basic_json(const number_integer_t).
@complexity Constant.
@liveexample{The example below shows the construction of a JSON integer
number value.,basic_json__number_integer_t}
@sa basic_json(const number_integer_t)
*/
*/
basic_json
(
const
int
value
)
basic_json
(
const
int
value
)
:
m_type
(
value_t
::
number_integer
),
:
m_type
(
value_t
::
number_integer
),
m_value
(
static_cast
<
number_integer_t
>
(
value
))
m_value
(
static_cast
<
number_integer_t
>
(
value
))
{}
{}
/// create an integer number (implicit)
/*!
template
<
typename
T
,
typename
@brief create an integer number (implicit)
Create an inteher numnbr JSON value with a given content. This constructor
allows any type that can be used to construct values of type @ref
number_integer_t. Examples may include the types `int`, `int32_t`, or
`short`.
@tparam CompatibleNumberIntegerType an integer type which is compatible to
@ref number_integer_t.
@param[in] value an integer to create a JSON number from
@complexity Constant.
@liveexample{The example below shows the construction of several JSON
integer number values from compatible
types.,basic_json__CompatibleIntegerNumberType}
@sa basic_json(const number_integer_t)
*/
template
<
typename
CompatibleNumberIntegerType
,
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_constructible
<
number_integer_t
,
T
>
::
value
and
std
::
is_constructible
<
number_integer_t
,
CompatibleNumberIntegerType
>
::
value
and
std
::
numeric_limits
<
T
>::
is_integer
,
T
>::
type
std
::
numeric_limits
<
CompatibleNumberIntegerType
>::
is_integer
,
CompatibleNumberIntegerType
>::
type
=
0
>
=
0
>
basic_json
(
const
T
value
)
noexcept
basic_json
(
const
CompatibleNumberIntegerType
value
)
noexcept
:
m_type
(
value_t
::
number_integer
),
:
m_type
(
value_t
::
number_integer
),
m_value
(
static_cast
<
number_integer_t
>
(
value
))
m_value
(
static_cast
<
number_integer_t
>
(
value
))
{}
{}
/// create a floating-point number (explicit)
/*!
@brief create a floating-point number (explicit)
Create a floating-point number JSON value with a given content.
@param[in] value a floating-point value to create a JSON number from
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such
> as Infinity and NaN) are not permitted.
In case the parameter @a value is not a number, a JSON null value is
created instead.
@complexity Linear.
@liveexample{The following example creates several floating-point
values.,basic_json__number_float_t}
*/
basic_json
(
const
number_float_t
value
)
basic_json
(
const
number_float_t
value
)
:
m_type
(
value_t
::
number_float
),
m_value
(
value
)
:
m_type
(
value_t
::
number_float
),
m_value
(
value
)
{
{
...
@@ -693,12 +749,12 @@ class basic_json
...
@@ -693,12 +749,12 @@ class basic_json
}
}
/// create a floating-point number (implicit)
/// create a floating-point number (implicit)
template
<
typename
T
,
typename
=
typename
template
<
typename
CompatibleNumberFloatType
,
typename
=
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_constructible
<
number_float_t
,
T
>
::
value
and
std
::
is_constructible
<
number_float_t
,
CompatibleNumberFloatType
>
::
value
and
std
::
is_floating_point
<
T
>::
value
>::
type
std
::
is_floating_point
<
CompatibleNumberFloatType
>::
value
>::
type
>
>
basic_json
(
const
T
value
)
noexcept
basic_json
(
const
CompatibleNumberFloatType
value
)
noexcept
:
basic_json
(
number_float_t
(
value
))
:
basic_json
(
number_float_t
(
value
))
{}
{}
...
...
src/json.hpp.re2c
View file @
844bfd39
...
@@ -600,7 +600,7 @@ class basic_json
...
@@ -600,7 +600,7 @@ class basic_json
/*!
/*!
@brief create a string (explicit)
@brief create a string (explicit)
Create a
n
string JSON value with a given content.
Create a string JSON value with a given content.
@param[in] value a literal value for the string
@param[in] value a literal value for the string
...
@@ -636,13 +636,22 @@ class basic_json
...
@@ -636,13 +636,22 @@ class basic_json
/*!
/*!
@brief create an integer number (explicit)
@brief create an integer number (explicit)
@tparam T helper type to compare number_integer_t and int
Create an interger number JSON value with a given content.
@tparam T helper type to compare number_integer_t and int (not visible in)
the interface.
@param[in] value an integer to create a JSON number from
@param[in] value an integer to create a JSON number from
This constructor takes care about explicitly passed values of type
@note This constructor would have the same signature as @ref
number_integer_t. However, this constructor would have the same signature
basic_json(const int value), so we need to switch this one off in case
as the existing one for const int values, so we need to switch this one off
number_integer_t is the same as int. This is done via the helper type @a T.
in case number_integer_t is the same as int.
@complexity Constant.
@todo Add example.
@sa basic_json(const int)
*/
*/
template<typename T,
template<typename T,
typename std::enable_if<
typename std::enable_if<
...
@@ -654,33 +663,80 @@ class basic_json
...
@@ -654,33 +663,80 @@ class basic_json
{}
{}
/*!
/*!
@brief create an int number to support enum type (implicit)
@brief create an integer number from an enum type (explicit)
Create an interger number JSON value with a given content.
@param[in] value an integer to create a JSON number from
@param[in] value an integer to create a JSON number from
This constructor allows to pass enums directly to a constructor. As C++ has
@note This constructor allows to pass enums directly to a constructor. As
no way of specifying the type of an anonymous enum explicitly, we can only
C++ has no way of specifying the type of an anonymous enum explicitly, we
rely on the fact that such values implicitly convert to int. As int may
can only rely on the fact that such values implicitly convert to int. As
already be the same type of number_integer_t, we may need to switch off
int may already be the same type of number_integer_t, we may need to switch
that constructor, which is done above.
off the constructor @ref basic_json(const number_integer_t).
@complexity Constant.
@liveexample{The example below shows the construction of a JSON integer
number value.,basic_json__number_integer_t}
@sa basic_json(const number_integer_t)
*/
*/
basic_json(const int value)
basic_json(const int value)
: m_type(value_t::number_integer),
: m_type(value_t::number_integer),
m_value(static_cast<number_integer_t>(value))
m_value(static_cast<number_integer_t>(value))
{}
{}
/// create an integer number (implicit)
/*!
template<typename T, typename
@brief create an integer number (implicit)
Create an inteher numnbr JSON value with a given content. This constructor
allows any type that can be used to construct values of type @ref
number_integer_t. Examples may include the types `int`, `int32_t`, or
`short`.
@tparam CompatibleNumberIntegerType an integer type which is compatible to
@ref number_integer_t.
@param[in] value an integer to create a JSON number from
@complexity Constant.
@liveexample{The example below shows the construction of several JSON
integer number values from compatible
types.,basic_json__CompatibleIntegerNumberType}
@sa basic_json(const number_integer_t)
*/
template<typename CompatibleNumberIntegerType, typename
std::enable_if<
std::enable_if<
std::is_constructible<number_integer_t,
T
>::value and
std::is_constructible<number_integer_t,
CompatibleNumberIntegerType
>::value and
std::numeric_limits<
T>::is_integer, T
>::type
std::numeric_limits<
CompatibleNumberIntegerType>::is_integer, CompatibleNumberIntegerType
>::type
= 0>
= 0>
basic_json(const
T
value) noexcept
basic_json(const
CompatibleNumberIntegerType
value) noexcept
: m_type(value_t::number_integer),
: m_type(value_t::number_integer),
m_value(static_cast<number_integer_t>(value))
m_value(static_cast<number_integer_t>(value))
{}
{}
/// create a floating-point number (explicit)
/*!
@brief create a floating-point number (explicit)
Create a floating-point number JSON value with a given content.
@param[in] value a floating-point value to create a JSON number from
@note RFC 7159 <http://www.rfc-editor.org/rfc/rfc7159.txt>, section 6
disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such
> as Infinity and NaN) are not permitted.
In case the parameter @a value is not a number, a JSON null value is
created instead.
@complexity Linear.
@liveexample{The following example creates several floating-point
values.,basic_json__number_float_t}
*/
basic_json(const number_float_t value)
basic_json(const number_float_t value)
: m_type(value_t::number_float), m_value(value)
: m_type(value_t::number_float), m_value(value)
{
{
...
@@ -693,12 +749,12 @@ class basic_json
...
@@ -693,12 +749,12 @@ class basic_json
}
}
/// create a floating-point number (implicit)
/// create a floating-point number (implicit)
template<typename
T
, typename = typename
template<typename
CompatibleNumberFloatType
, typename = typename
std::enable_if<
std::enable_if<
std::is_constructible<number_float_t,
T
>::value and
std::is_constructible<number_float_t,
CompatibleNumberFloatType
>::value and
std::is_floating_point<
T
>::value>::type
std::is_floating_point<
CompatibleNumberFloatType
>::value>::type
>
>
basic_json(const
T
value) noexcept
basic_json(const
CompatibleNumberFloatType
value) noexcept
: basic_json(number_float_t(value))
: basic_json(number_float_t(value))
{}
{}
...
...
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