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
89f60683
Unverified
Commit
89f60683
authored
Mar 12, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feature/exceptions_3.0.0
parents
0f6b8aa7
dfa4e83c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
8 deletions
+116
-8
.travis.yml
.travis.yml
+3
-3
README.md
README.md
+1
-1
src/json.hpp
src/json.hpp
+40
-1
src/json.hpp.re2c
src/json.hpp.re2c
+40
-1
test/src/unit-modifiers.cpp
test/src/unit-modifiers.cpp
+3
-2
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+16
-0
test/src/unit-udt.cpp
test/src/unit-udt.cpp
+13
-0
No files found.
.travis.yml
View file @
89f60683
...
...
@@ -78,13 +78,13 @@ matrix:
env
:
-
COMPILER=g++-4.9
-
SPECIAL=no_exceptions
-
TEST_PATTERN=-e \"*\"
addons
:
apt
:
sources
:
[
'
ubuntu-toolchain-r-test'
]
packages
:
[
g++-4.9
,
cppcheck
]
before_script
:
-
CPPFLAGS="-DJSON_NOEXCEPTION" make
after_success
:
-
make clean
-
CPPFLAGS="-DJSON_NOEXCEPTION" make check TEST_PATTERN="-e \"*\""
# Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/)
...
...
README.md
View file @
89f60683
...
...
@@ -828,7 +828,7 @@ I deeply appreciate the help of the following people.
-
[
rswanson-ihi
](
https://github.com/rswanson-ihi
)
noted a typo in the README.
-
[
Mihai Stan
](
https://github.com/stanmihai4
)
fixed a bug in the comparison with
`nullptr`
s.
-
[
Tushar Maheshwari
](
https://github.com/tusharpm
)
added
[
cotire
](
https://github.com/sakra/cotire
)
support to speed up the compilation.
-
[
TedLyngmo
](
https://github.com/TedLyngmo
)
noted a typo in the README.
-
[
TedLyngmo
](
https://github.com/TedLyngmo
)
noted a typo in the README
and fixed some
`-Weffc++`
warnings
.
Thanks a lot for helping out! Please
[
let me know
](
mailto:mail@nlohmann.me
)
if I forgot someone.
...
...
src/json.hpp
View file @
89f60683
...
...
@@ -81,7 +81,7 @@ SOFTWARE.
#endif
// allow to disable exceptions
#if
not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS
)
#if
(defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION
)
#define JSON_THROW(exception) throw exception
#define JSON_TRY try
#define JSON_CATCH(exception) catch(exception)
...
...
@@ -529,6 +529,19 @@ struct external_constructor<value_t::array>
j
.
m_value
.
array
=
j
.
template
create
<
typename
BasicJsonType
::
array_t
>(
begin
(
arr
),
end
(
arr
));
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
std
::
vector
<
bool
>&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
value_t
::
array
;
j
.
m_value
.
array
->
reserve
(
arr
.
size
());
for
(
bool
x
:
arr
)
{
j
.
m_value
.
array
->
push_back
(
x
);
}
j
.
assert_invariant
();
}
};
template
<
>
...
...
@@ -767,6 +780,12 @@ void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
e
);
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
vector
<
bool
>&
e
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
e
);
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
...
...
@@ -6392,6 +6411,10 @@ class basic_json
*/
class
serializer
{
private:
serializer
(
const
serializer
&
)
=
delete
;
serializer
&
operator
=
(
const
serializer
&
)
=
delete
;
public:
/*!
@param[in] s output stream to serialize to
...
...
@@ -13427,6 +13450,22 @@ struct hash<nlohmann::json>
return
h
(
j
.
dump
());
}
};
/// specialization for std::less<value_t>
template
<
>
struct
less
<::
nlohmann
::
detail
::
value_t
>
{
/*!
@brief compare two value_t enum values
@since version 3.0.0
*/
bool
operator
()(
nlohmann
::
detail
::
value_t
lhs
,
nlohmann
::
detail
::
value_t
rhs
)
const
noexcept
{
return
nlohmann
::
detail
::
operator
<
(
lhs
,
rhs
);
}
};
}
// namespace std
/*!
...
...
src/json.hpp.re2c
View file @
89f60683
...
...
@@ -81,7 +81,7 @@ SOFTWARE.
#endif
// allow to disable exceptions
#if
not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS
)
#if
(defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION
)
#define JSON_THROW(exception) throw exception
#define JSON_TRY try
#define JSON_CATCH(exception) catch(exception)
...
...
@@ -529,6 +529,19 @@ struct external_constructor<value_t::array>
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.assert_invariant();
}
template<typename BasicJsonType>
static void construct(BasicJsonType& j, const std::vector<bool>& arr)
{
j.m_type = value_t::array;
j.m_value = value_t::array;
j.m_value.array->reserve(arr.size());
for (bool x : arr)
{
j.m_value.array->push_back(x);
}
j.assert_invariant();
}
};
template<>
...
...
@@ -767,6 +780,12 @@ void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept
external_constructor<value_t::number_integer>::construct(j, e);
}
template<typename BasicJsonType>
void to_json(BasicJsonType& j, const std::vector<bool>& e)
{
external_constructor<value_t::array>::construct(j, e);
}
template <
typename BasicJsonType, typename CompatibleArrayType,
enable_if_t <
...
...
@@ -6392,6 +6411,10 @@ class basic_json
*/
class serializer
{
private:
serializer(const serializer&) = delete;
serializer& operator=(const serializer&) = delete;
public:
/*!
@param[in] s output stream to serialize to
...
...
@@ -12460,6 +12483,22 @@ struct hash<nlohmann::json>
return h(j.dump());
}
};
/// specialization for std::less<value_t>
template <>
struct less<::nlohmann::detail::value_t>
{
/*!
@brief compare two value_t enum values
@since version 3.0.0
*/
bool operator()(nlohmann::detail::value_t lhs,
nlohmann::detail::value_t rhs) const noexcept
{
return nlohmann::detail::operator<(lhs, rhs);
}
};
} // namespace std
/*!
...
...
test/src/unit-modifiers.cpp
View file @
89f60683
...
...
@@ -585,10 +585,11 @@ TEST_CASE("modifiers")
SECTION
(
"insert nothing (count = 0)"
)
{
auto
pos
=
j_array
.
end
();
auto
it
=
j_array
.
insert
(
j_array
.
end
(),
0
,
5
);
CHECK
(
j_array
.
size
()
==
4
);
CHECK
(
it
==
pos
);
// the returned iterator points to the first inserted element;
// there were 4 elements, so it should point to the 5th
CHECK
(
it
==
j_array
.
begin
()
+
4
);
CHECK
(
j_array
==
json
({
1
,
2
,
3
,
4
}));
}
}
...
...
test/src/unit-regression.cpp
View file @
89f60683
...
...
@@ -833,4 +833,20 @@ TEST_CASE("regression tests")
std
::
string
s2
=
j2
.
dump
();
CHECK
(
s1
==
s2
);
}
SECTION
(
"issue #486 - json::value_t can't be a map's key type in VC++ 2015"
)
{
// the code below must compile with MSVC
std
::
map
<
json
::
value_t
,
std
::
string
>
jsonTypes
;
jsonTypes
[
json
::
value_t
::
array
]
=
"array"
;
}
SECTION
(
"issue #494 - conversion from vector<bool> to json fails to build"
)
{
std
::
vector
<
bool
>
boolVector
=
{
false
,
true
,
false
,
false
};
json
j
;
j
[
"bool_vector"
]
=
boolVector
;
CHECK
(
j
[
"bool_vector"
].
dump
()
==
"[false,true,false,false]"
);
}
}
test/src/unit-udt.cpp
View file @
89f60683
...
...
@@ -49,16 +49,19 @@ enum class country
struct
age
{
int
m_val
;
age
(
int
rhs
=
0
)
:
m_val
(
rhs
)
{}
};
struct
name
{
std
::
string
m_val
;
name
(
const
std
::
string
rhs
=
""
)
:
m_val
(
rhs
)
{}
};
struct
address
{
std
::
string
m_val
;
address
(
const
std
::
string
rhs
=
""
)
:
m_val
(
rhs
)
{}
};
struct
person
...
...
@@ -66,18 +69,24 @@ struct person
age
m_age
;
name
m_name
;
country
m_country
;
person
()
:
m_age
(),
m_name
(),
m_country
()
{}
person
(
const
age
&
a
,
const
name
&
n
,
const
country
&
c
)
:
m_age
(
a
),
m_name
(
n
),
m_country
(
c
)
{}
};
struct
contact
{
person
m_person
;
address
m_address
;
contact
()
:
m_person
(),
m_address
()
{}
contact
(
const
person
&
p
,
const
address
&
a
)
:
m_person
(
p
),
m_address
(
a
)
{}
};
struct
contact_book
{
name
m_book_name
;
std
::
vector
<
contact
>
m_contacts
;
contact_book
()
:
m_book_name
(),
m_contacts
()
{}
contact_book
(
const
name
&
n
,
const
std
::
vector
<
contact
>&
c
)
:
m_book_name
(
n
),
m_contacts
(
c
)
{}
};
}
...
...
@@ -319,6 +328,8 @@ namespace udt
struct
legacy_type
{
std
::
string
number
;
legacy_type
()
:
number
()
{}
legacy_type
(
const
std
::
string
&
n
)
:
number
(
n
)
{}
};
}
...
...
@@ -593,6 +604,8 @@ struct small_pod
struct
non_pod
{
std
::
string
s
;
non_pod
()
:
s
()
{}
non_pod
(
const
std
::
string
&
S
)
:
s
(
S
)
{}
};
template
<
typename
BasicJsonType
>
...
...
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