Skip to content

Commit 442058f

Browse files
committed
interface cleanup
1 parent afba1d3 commit 442058f

10 files changed

+62
-100
lines changed

doc/examples/basic_json.cpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

doc/examples/basic_json.link

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/examples/basic_json.output

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/examples/basic_json__istream.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ int main()
2727
ss << text;
2828

2929
// create JSON from stream
30-
json j_complete(ss);
30+
json j_complete(ss); // deprecated!
31+
// shall be replaced by: json j_complete = json::parse(ss);
3132
std::cout << std::setw(4) << j_complete << "\n\n";
3233

3334

@@ -51,5 +52,6 @@ int main()
5152

5253
// create JSON from stream (with callback)
5354
json j_filtered(ss, cb);
55+
// shall be replaced by: json j_filtered = json::parse(ss, cb);
5456
std::cout << std::setw(4) << j_filtered << '\n';
5557
}

doc/examples/basic_json__istream.link

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a target="_blank" href="http://melpon.org/wandbox/permlink/VzSqLszbnoWE92dD"><b>online</b></a>
1+
<a target="_blank" href="http://melpon.org/wandbox/permlink/R6dzpKXlxrttShf7"><b>online</b></a>

doc/examples/basic_json__nullptr_t.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ using json = nlohmann::json;
44

55
int main()
66
{
7-
// create a JSON null value
8-
json j(nullptr);
7+
// implicitly create a JSON null value
8+
json j1;
9+
10+
// explicitly create a JSON null value
11+
json j2(nullptr);
912

1013
// serialize the JSON null value
11-
std::cout << j << '\n';
14+
std::cout << j1 << '\n' << j2 << '\n';
1215
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a target="_blank" href="http://melpon.org/wandbox/permlink/PMMpoM0ujdJDsuta"><b>online</b></a>
1+
<a target="_blank" href="http://melpon.org/wandbox/permlink/9Tvfs2dJBW8m8ihA"><b>online</b></a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
null
2+
null

src/json.hpp

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ SOFTWARE.
7373
#pragma GCC diagnostic ignored "-Wfloat-equal"
7474
#endif
7575

76+
// allow for portable deprecation warnings
77+
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
78+
#define JSON_DEPRECATED __attribute__((deprecated))
79+
#elif defined(_MSC_VER)
80+
#define JSON_DEPRECATED __declspec(deprecated)
81+
#else
82+
#define JSON_DEPRECATED
83+
#endif
84+
7685
/*!
7786
@brief namespace for Niels Lohmann
7887
@see https://github.com/nlohmann
@@ -1057,40 +1066,10 @@ class basic_json
10571066
}
10581067

10591068
/*!
1060-
@brief create a null object (implicitly)
1061-
1062-
Create a `null` JSON value. This is the implicit version of the `null`
1063-
value constructor as it takes no parameters.
1064-
1065-
@note The class invariant is satisfied, because it poses no requirements
1066-
for null values.
1067-
1068-
@complexity Constant.
1069-
1070-
@exceptionsafety No-throw guarantee: this constructor never throws
1071-
exceptions.
1072-
1073-
@requirement This function helps `basic_json` satisfying the
1074-
[Container](http://en.cppreference.com/w/cpp/concept/Container)
1075-
requirements:
1076-
- The complexity is constant.
1077-
- As postcondition, it holds: `basic_json().empty() == true`.
1078-
1079-
@liveexample{The following code shows the constructor for a `null` JSON
1080-
value.,basic_json}
1081-
1082-
@sa @ref basic_json(std::nullptr_t) -- create a `null` value
1083-
1084-
@since version 1.0.0
1085-
*/
1086-
basic_json() = default;
1087-
1088-
/*!
1089-
@brief create a null object (explicitly)
1069+
@brief create a null object
10901070
1091-
Create a `null` JSON value. This is the explicitly version of the `null`
1092-
value constructor as it takes a null pointer as parameter. It allows to
1093-
create `null` values by explicitly assigning a `nullptr` to a JSON value.
1071+
Create a `null` JSON value. It either takes a null pointer as parameter
1072+
(explicitly creating `null`) or no parameter (implicitly creating `null`).
10941073
The passed null pointer itself is not read -- it is only used to choose
10951074
the right constructor.
10961075
@@ -1099,15 +1078,12 @@ class basic_json
10991078
@exceptionsafety No-throw guarantee: this constructor never throws
11001079
exceptions.
11011080
1102-
@liveexample{The following code shows the constructor with null pointer
1103-
parameter.,basic_json__nullptr_t}
1104-
1105-
@sa @ref basic_json() -- default constructor (implicitly creating a `null`
1106-
value)
1081+
@liveexample{The following code shows the constructor with and without a
1082+
null pointer parameter.,basic_json__nullptr_t}
11071083
11081084
@since version 1.0.0
11091085
*/
1110-
basic_json(std::nullptr_t) noexcept
1086+
basic_json(std::nullptr_t = nullptr) noexcept
11111087
: basic_json(value_t::null)
11121088
{
11131089
assert_invariant();
@@ -1971,12 +1947,21 @@ class basic_json
19711947
19721948
@note A UTF-8 byte order mark is silently ignored.
19731949
1950+
@deprecated This constructor is deprecated and will be removed in version
1951+
3.0.0 to unify the interface of the library. Deserialization will be
1952+
done by stream operators or by calling one of the `parse` functions,
1953+
e.g. @ref parse(std::istream&, const parser_callback_t). That is, calls
1954+
like `json j(i);` for an input stream @a i need to be replaced by
1955+
`json j = json::parse(i);`. See the example below.
1956+
19741957
@liveexample{The example below demonstrates constructing a JSON value from
19751958
a `std::stringstream` with and without callback
19761959
function.,basic_json__istream}
19771960
1978-
@since version 2.0.0
1961+
@since version 2.0.0, deprecated in version 2.0.3, to be removed in
1962+
version 3.0.0
19791963
*/
1964+
JSON_DEPRECATED
19801965
explicit basic_json(std::istream& i, const parser_callback_t cb = nullptr)
19811966
{
19821967
*this = parser(i, cb).parse();

src/json.hpp.re2c

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ SOFTWARE.
7373
#pragma GCC diagnostic ignored "-Wfloat-equal"
7474
#endif
7575

76+
// allow for portable deprecation warnings
77+
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
78+
#define JSON_DEPRECATED __attribute__((deprecated))
79+
#elif defined(_MSC_VER)
80+
#define JSON_DEPRECATED __declspec(deprecated)
81+
#else
82+
#define JSON_DEPRECATED
83+
#endif
84+
7685
/*!
7786
@brief namespace for Niels Lohmann
7887
@see https://github.com/nlohmann
@@ -1057,40 +1066,10 @@ class basic_json
10571066
}
10581067

10591068
/*!
1060-
@brief create a null object (implicitly)
1061-
1062-
Create a `null` JSON value. This is the implicit version of the `null`
1063-
value constructor as it takes no parameters.
1064-
1065-
@note The class invariant is satisfied, because it poses no requirements
1066-
for null values.
1067-
1068-
@complexity Constant.
1069-
1070-
@exceptionsafety No-throw guarantee: this constructor never throws
1071-
exceptions.
1072-
1073-
@requirement This function helps `basic_json` satisfying the
1074-
[Container](http://en.cppreference.com/w/cpp/concept/Container)
1075-
requirements:
1076-
- The complexity is constant.
1077-
- As postcondition, it holds: `basic_json().empty() == true`.
1078-
1079-
@liveexample{The following code shows the constructor for a `null` JSON
1080-
value.,basic_json}
1081-
1082-
@sa @ref basic_json(std::nullptr_t) -- create a `null` value
1083-
1084-
@since version 1.0.0
1085-
*/
1086-
basic_json() = default;
1087-
1088-
/*!
1089-
@brief create a null object (explicitly)
1069+
@brief create a null object
10901070

1091-
Create a `null` JSON value. This is the explicitly version of the `null`
1092-
value constructor as it takes a null pointer as parameter. It allows to
1093-
create `null` values by explicitly assigning a `nullptr` to a JSON value.
1071+
Create a `null` JSON value. It either takes a null pointer as parameter
1072+
(explicitly creating `null`) or no parameter (implicitly creating `null`).
10941073
The passed null pointer itself is not read -- it is only used to choose
10951074
the right constructor.
10961075

@@ -1099,15 +1078,12 @@ class basic_json
10991078
@exceptionsafety No-throw guarantee: this constructor never throws
11001079
exceptions.
11011080

1102-
@liveexample{The following code shows the constructor with null pointer
1103-
parameter.,basic_json__nullptr_t}
1104-
1105-
@sa @ref basic_json() -- default constructor (implicitly creating a `null`
1106-
value)
1081+
@liveexample{The following code shows the constructor with and without a
1082+
null pointer parameter.,basic_json__nullptr_t}
11071083

11081084
@since version 1.0.0
11091085
*/
1110-
basic_json(std::nullptr_t) noexcept
1086+
basic_json(std::nullptr_t = nullptr) noexcept
11111087
: basic_json(value_t::null)
11121088
{
11131089
assert_invariant();
@@ -1971,12 +1947,21 @@ class basic_json
19711947

19721948
@note A UTF-8 byte order mark is silently ignored.
19731949

1950+
@deprecated This constructor is deprecated and will be removed in version
1951+
3.0.0 to unify the interface of the library. Deserialization will be
1952+
done by stream operators or by calling one of the `parse` functions,
1953+
e.g. @ref parse(std::istream&, const parser_callback_t). That is, calls
1954+
like `json j(i);` for an input stream @a i need to be replaced by
1955+
`json j = json::parse(i);`. See the example below.
1956+
19741957
@liveexample{The example below demonstrates constructing a JSON value from
19751958
a `std::stringstream` with and without callback
19761959
function.,basic_json__istream}
19771960

1978-
@since version 2.0.0
1961+
@since version 2.0.0, deprecated in version 2.0.3, to be removed in
1962+
version 3.0.0
19791963
*/
1964+
JSON_DEPRECATED
19801965
explicit basic_json(std::istream& i, const parser_callback_t cb = nullptr)
19811966
{
19821967
*this = parser(i, cb).parse();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy