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
50841590
Commit
50841590
authored
Jul 16, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added changes from #105: MSVC fixes
- additionally, switch off optimization flags to maybe allow build to complete on AppVeyor
parent
e007f02c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
47 deletions
+64
-47
CMakeLists.txt
CMakeLists.txt
+1
-1
json.hpp
src/json.hpp
+28
-21
json.hpp.re2c
src/json.hpp.re2c
+28
-21
unit.cpp
test/unit.cpp
+7
-4
No files found.
CMakeLists.txt
View file @
50841590
...
@@ -8,7 +8,7 @@ add_executable(json_unit
...
@@ -8,7 +8,7 @@ add_executable(json_unit
if
(
MSVC
)
if
(
MSVC
)
set
(
CMAKE_CXX_FLAGS
set
(
CMAKE_CXX_FLAGS
"/EHsc"
"/EHsc
/Od
"
)
)
add_definitions
(
-D_SCL_SECURE_NO_WARNINGS
)
add_definitions
(
-D_SCL_SECURE_NO_WARNINGS
)
else
(
MSVC
)
else
(
MSVC
)
...
...
src/json.hpp
View file @
50841590
...
@@ -137,7 +137,7 @@ class basic_json
...
@@ -137,7 +137,7 @@ class basic_json
{
{
private
:
private
:
/// workaround type for MSVC
/// workaround type for MSVC
using
__basic_json
=
using
basic_json_t
=
basic_json
<
ObjectType
,
ArrayType
,
StringType
,
BooleanType
,
NumberIntegerType
,
NumberFloatType
,
AllocatorType
>
;
basic_json
<
ObjectType
,
ArrayType
,
StringType
,
BooleanType
,
NumberIntegerType
,
NumberFloatType
,
AllocatorType
>
;
public
:
public
:
...
@@ -890,10 +890,10 @@ class basic_json
...
@@ -890,10 +890,10 @@ class basic_json
*/
*/
template
<
class
CompatibleArrayType
,
typename
template
<
class
CompatibleArrayType
,
typename
std
::
enable_if
<
std
::
enable_if
<
not
std
::
is_same
<
CompatibleArrayType
,
typename
__basic_json
::
iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
basic_json_t
::
iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
__basic_json
::
const_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
basic_json_t
::
const_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
__basic_json
::
reverse_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
basic_json_t
::
reverse_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
__basic_json
::
const_reverse_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
basic_json_t
::
const_reverse_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
array_t
::
iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
array_t
::
iterator
>::
value
and
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
...
@@ -1401,8 +1401,8 @@ class basic_json
...
@@ -1401,8 +1401,8 @@ class basic_json
*/
*/
template
<
class
InputIT
,
typename
template
<
class
InputIT
,
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_same
<
InputIT
,
typename
__basic_json
::
iterator
>::
value
or
std
::
is_same
<
InputIT
,
typename
basic_json_t
::
iterator
>::
value
or
std
::
is_same
<
InputIT
,
typename
__basic_json
::
const_iterator
>::
value
std
::
is_same
<
InputIT
,
typename
basic_json_t
::
const_iterator
>::
value
,
int
>::
type
,
int
>::
type
=
0
>
=
0
>
basic_json
(
InputIT
first
,
InputIT
last
)
:
m_type
(
first
.
m_object
->
m_type
)
basic_json
(
InputIT
first
,
InputIT
last
)
:
m_type
(
first
.
m_object
->
m_type
)
...
@@ -1503,7 +1503,7 @@ class basic_json
...
@@ -1503,7 +1503,7 @@ class basic_json
@throw std::bad_alloc if allocation for object, array, or string fails.
@throw std::bad_alloc if allocation for object, array, or string fails.
@liveexample{The following code shows an example for the copy
@liveexample{The following code shows an example for the copy
constructor.,basic_json
__basic_json
}
constructor.,basic_json
basic_json_t
}
@ingroup container
@ingroup container
*/
*/
...
@@ -1958,7 +1958,7 @@ class basic_json
...
@@ -1958,7 +1958,7 @@ class basic_json
template
<
class
T
,
typename
template
<
class
T
,
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_convertible
<
typename
object_t
::
key_type
,
typename
T
::
key_type
>::
value
and
std
::
is_convertible
<
typename
object_t
::
key_type
,
typename
T
::
key_type
>::
value
and
std
::
is_convertible
<
__basic_json
,
typename
T
::
mapped_type
>::
value
std
::
is_convertible
<
basic_json_t
,
typename
T
::
mapped_type
>::
value
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
T
get_impl
(
T
*
)
const
T
get_impl
(
T
*
)
const
{
{
...
@@ -1994,8 +1994,8 @@ class basic_json
...
@@ -1994,8 +1994,8 @@ class basic_json
/// get an array (explicit)
/// get an array (explicit)
template
<
class
T
,
typename
template
<
class
T
,
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_convertible
<
__basic_json
,
typename
T
::
value_type
>::
value
and
std
::
is_convertible
<
basic_json_t
,
typename
T
::
value_type
>::
value
and
not
std
::
is_same
<
__basic_json
,
typename
T
::
value_type
>::
value
and
not
std
::
is_same
<
basic_json_t
,
typename
T
::
value_type
>::
value
and
not
std
::
is_arithmetic
<
T
>::
value
and
not
std
::
is_arithmetic
<
T
>::
value
and
not
std
::
is_convertible
<
std
::
string
,
T
>::
value
and
not
std
::
is_convertible
<
std
::
string
,
T
>::
value
and
not
has_mapped_type
<
T
>::
value
not
has_mapped_type
<
T
>::
value
...
@@ -2024,8 +2024,8 @@ class basic_json
...
@@ -2024,8 +2024,8 @@ class basic_json
/// get an array (explicit)
/// get an array (explicit)
template
<
class
T
,
typename
template
<
class
T
,
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_convertible
<
__basic_json
,
T
>::
value
and
std
::
is_convertible
<
basic_json_t
,
T
>::
value
and
not
std
::
is_same
<
__basic_json
,
T
>::
value
not
std
::
is_same
<
basic_json_t
,
T
>::
value
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
std
::
vector
<
T
>
get_impl
(
std
::
vector
<
T
>*
)
const
std
::
vector
<
T
>
get_impl
(
std
::
vector
<
T
>*
)
const
{
{
...
@@ -2838,8 +2838,8 @@ class basic_json
...
@@ -2838,8 +2838,8 @@ class basic_json
*/
*/
template
<
class
InteratorType
,
typename
template
<
class
InteratorType
,
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_same
<
InteratorType
,
typename
__basic_json
::
iterator
>::
value
or
std
::
is_same
<
InteratorType
,
typename
basic_json_t
::
iterator
>::
value
or
std
::
is_same
<
InteratorType
,
typename
__basic_json
::
const_iterator
>::
value
std
::
is_same
<
InteratorType
,
typename
basic_json_t
::
const_iterator
>::
value
,
int
>::
type
,
int
>::
type
=
0
>
=
0
>
InteratorType
erase
(
InteratorType
pos
)
InteratorType
erase
(
InteratorType
pos
)
...
@@ -2931,8 +2931,8 @@ class basic_json
...
@@ -2931,8 +2931,8 @@ class basic_json
*/
*/
template
<
class
InteratorType
,
typename
template
<
class
InteratorType
,
typename
std
::
enable_if
<
std
::
enable_if
<
std
::
is_same
<
InteratorType
,
typename
basic_json
::
iterator
>::
value
or
std
::
is_same
<
InteratorType
,
typename
basic_json
_t
::
iterator
>::
value
or
std
::
is_same
<
InteratorType
,
typename
basic_json
::
const_iterator
>::
value
std
::
is_same
<
InteratorType
,
typename
basic_json
_t
::
const_iterator
>::
value
,
int
>::
type
,
int
>::
type
=
0
>
=
0
>
InteratorType
erase
(
InteratorType
first
,
InteratorType
last
)
InteratorType
erase
(
InteratorType
first
,
InteratorType
last
)
...
@@ -4285,8 +4285,9 @@ class basic_json
...
@@ -4285,8 +4285,9 @@ class basic_json
}
}
// We only reach this line if we cannot compare values. In that case,
// We only reach this line if we cannot compare values. In that case,
// we compare types.
// we compare types. Note we have to call the operator explicitly,
return
lhs_type
<
rhs_type
;
// because MSVC has problems otherwise.
return
operator
<
(
lhs_type
,
rhs_type
);
}
}
/*!
/*!
...
@@ -4851,8 +4852,14 @@ class basic_json
...
@@ -4851,8 +4852,14 @@ class basic_json
difference_type
m_it
=
std
::
numeric_limits
<
std
::
ptrdiff_t
>::
min
();
difference_type
m_it
=
std
::
numeric_limits
<
std
::
ptrdiff_t
>::
min
();
};
};
/// an iterator value
/*!
union
internal_iterator
@brief an iterator value
@note This structure could easily be a union, but MSVC currently does not
allow unions members with complex constructors, see
https://github.com/nlohmann/json/pull/105.
*/
struct
internal_iterator
{
{
/// iterator for JSON objects
/// iterator for JSON objects
typename
object_t
::
iterator
object_iterator
;
typename
object_t
::
iterator
object_iterator
;
...
...
src/json.hpp.re2c
View file @
50841590
...
@@ -137,7 +137,7 @@ class basic_json
...
@@ -137,7 +137,7 @@ class basic_json
{
{
private:
private:
/// workaround type for MSVC
/// workaround type for MSVC
using
__basic_json
=
using
basic_json_t
=
basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>;
basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>;
public:
public:
...
@@ -890,10 +890,10 @@ class basic_json
...
@@ -890,10 +890,10 @@ class basic_json
*/
*/
template <class CompatibleArrayType, typename
template <class CompatibleArrayType, typename
std::enable_if<
std::enable_if<
not std::is_same<CompatibleArrayType, typename
__basic_json
::iterator>::value and
not std::is_same<CompatibleArrayType, typename
basic_json_t
::iterator>::value and
not std::is_same<CompatibleArrayType, typename
__basic_json
::const_iterator>::value and
not std::is_same<CompatibleArrayType, typename
basic_json_t
::const_iterator>::value and
not std::is_same<CompatibleArrayType, typename
__basic_json
::reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename
basic_json_t
::reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename
__basic_json
::const_reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename
basic_json_t
::const_reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
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
...
@@ -1401,8 +1401,8 @@ class basic_json
...
@@ -1401,8 +1401,8 @@ class basic_json
*/
*/
template <class InputIT, typename
template <class InputIT, typename
std::enable_if<
std::enable_if<
std::is_same<InputIT, typename
__basic_json
::iterator>::value or
std::is_same<InputIT, typename
basic_json_t
::iterator>::value or
std::is_same<InputIT, typename
__basic_json
::const_iterator>::value
std::is_same<InputIT, typename
basic_json_t
::const_iterator>::value
, int>::type
, int>::type
= 0>
= 0>
basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
...
@@ -1503,7 +1503,7 @@ class basic_json
...
@@ -1503,7 +1503,7 @@ class basic_json
@throw std::bad_alloc if allocation for object, array, or string fails.
@throw std::bad_alloc if allocation for object, array, or string fails.
@liveexample{The following code shows an example for the copy
@liveexample{The following code shows an example for the copy
constructor.,basic_json
__basic_json
}
constructor.,basic_json
basic_json_t
}
@ingroup container
@ingroup container
*/
*/
...
@@ -1958,7 +1958,7 @@ class basic_json
...
@@ -1958,7 +1958,7 @@ class basic_json
template <class T, typename
template <class T, typename
std::enable_if<
std::enable_if<
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
std::is_convertible<
__basic_json
, typename T::mapped_type>::value
std::is_convertible<
basic_json_t
, typename T::mapped_type>::value
, int>::type = 0>
, int>::type = 0>
T get_impl(T*) const
T get_impl(T*) const
{
{
...
@@ -1994,8 +1994,8 @@ class basic_json
...
@@ -1994,8 +1994,8 @@ class basic_json
/// get an array (explicit)
/// get an array (explicit)
template <class T, typename
template <class T, typename
std::enable_if<
std::enable_if<
std::is_convertible<
__basic_json
, typename T::value_type>::value and
std::is_convertible<
basic_json_t
, typename T::value_type>::value and
not std::is_same<
__basic_json
, typename T::value_type>::value and
not std::is_same<
basic_json_t
, typename T::value_type>::value and
not std::is_arithmetic<T>::value and
not std::is_arithmetic<T>::value and
not std::is_convertible<std::string, T>::value and
not std::is_convertible<std::string, T>::value and
not has_mapped_type<T>::value
not has_mapped_type<T>::value
...
@@ -2024,8 +2024,8 @@ class basic_json
...
@@ -2024,8 +2024,8 @@ class basic_json
/// get an array (explicit)
/// get an array (explicit)
template <class T, typename
template <class T, typename
std::enable_if<
std::enable_if<
std::is_convertible<
__basic_json
, T>::value and
std::is_convertible<
basic_json_t
, T>::value and
not std::is_same<
__basic_json
, T>::value
not std::is_same<
basic_json_t
, T>::value
, int>::type = 0>
, int>::type = 0>
std::vector<T> get_impl(std::vector<T>*) const
std::vector<T> get_impl(std::vector<T>*) const
{
{
...
@@ -2838,8 +2838,8 @@ class basic_json
...
@@ -2838,8 +2838,8 @@ class basic_json
*/
*/
template <class InteratorType, typename
template <class InteratorType, typename
std::enable_if<
std::enable_if<
std::is_same<InteratorType, typename
__basic_json
::iterator>::value or
std::is_same<InteratorType, typename
basic_json_t
::iterator>::value or
std::is_same<InteratorType, typename
__basic_json
::const_iterator>::value
std::is_same<InteratorType, typename
basic_json_t
::const_iterator>::value
, int>::type
, int>::type
= 0>
= 0>
InteratorType erase(InteratorType pos)
InteratorType erase(InteratorType pos)
...
@@ -2931,8 +2931,8 @@ class basic_json
...
@@ -2931,8 +2931,8 @@ class basic_json
*/
*/
template <class InteratorType, typename
template <class InteratorType, typename
std::enable_if<
std::enable_if<
std::is_same<InteratorType, typename basic_json::iterator>::value or
std::is_same<InteratorType, typename basic_json
_t
::iterator>::value or
std::is_same<InteratorType, typename basic_json::const_iterator>::value
std::is_same<InteratorType, typename basic_json
_t
::const_iterator>::value
, int>::type
, int>::type
= 0>
= 0>
InteratorType erase(InteratorType first, InteratorType last)
InteratorType erase(InteratorType first, InteratorType last)
...
@@ -4285,8 +4285,9 @@ class basic_json
...
@@ -4285,8 +4285,9 @@ class basic_json
}
}
// We only reach this line if we cannot compare values. In that case,
// We only reach this line if we cannot compare values. In that case,
// we compare types.
// we compare types. Note we have to call the operator explicitly,
return lhs_type < rhs_type;
// because MSVC has problems otherwise.
return operator<(lhs_type, rhs_type);
}
}
/*!
/*!
...
@@ -4851,8 +4852,14 @@ class basic_json
...
@@ -4851,8 +4852,14 @@ class basic_json
difference_type m_it = std::numeric_limits<std::ptrdiff_t>::min();
difference_type m_it = std::numeric_limits<std::ptrdiff_t>::min();
};
};
/// an iterator value
/*!
union internal_iterator
@brief an iterator value
@note This structure could easily be a union, but MSVC currently does not
allow unions members with complex constructors, see
https://github.com/nlohmann/json/pull/105.
*/
struct internal_iterator
{
{
/// iterator for JSON objects
/// iterator for JSON objects
typename object_t::iterator object_iterator;
typename object_t::iterator object_iterator;
...
...
test/unit.cpp
View file @
50841590
...
@@ -6939,7 +6939,7 @@ TEST_CASE("lexicographical comparison operators")
...
@@ -6939,7 +6939,7 @@ TEST_CASE("lexicographical comparison operators")
CAPTURE
(
i
);
CAPTURE
(
i
);
CAPTURE
(
j
);
CAPTURE
(
j
);
// check precomputed values
// check precomputed values
CHECK
(
(
j_types
[
i
]
<
j_types
[
j
])
==
expected
[
i
][
j
]
);
CHECK
(
operator
<
(
j_types
[
i
],
j_types
[
j
])
==
expected
[
i
][
j
]
);
}
}
}
}
}
}
...
@@ -8163,9 +8163,11 @@ TEST_CASE("parser class")
...
@@ -8163,9 +8163,11 @@ TEST_CASE("parser class")
SECTION
(
"escaped"
)
SECTION
(
"escaped"
)
{
{
// quotation mark "\""
// quotation mark "\""
CHECK
(
json
::
parser
(
"
\"\\\"\"
"
).
parse
()
==
R"("\"")"
_json
);
auto
r1
=
R"("\"")"
_json
;
CHECK
(
json
::
parser
(
"
\"\\\"\"
"
).
parse
()
==
r1
);
// reverse solidus "\\"
// reverse solidus "\\"
CHECK
(
json
::
parser
(
"
\"\\\\\"
"
).
parse
()
==
R"("\\")"
_json
);
auto
r2
=
R"("\\")"
_json
;
CHECK
(
json
::
parser
(
"
\"\\\\\"
"
).
parse
()
==
r2
);
// solidus
// solidus
CHECK
(
json
::
parser
(
"
\"\\
/
\"
"
).
parse
()
==
R"("/")"
_json
);
CHECK
(
json
::
parser
(
"
\"\\
/
\"
"
).
parse
()
==
R"("/")"
_json
);
// backspace
// backspace
...
@@ -9738,7 +9740,8 @@ TEST_CASE("regression tests")
...
@@ -9738,7 +9740,8 @@ TEST_CASE("regression tests")
{
{
auto
s
=
"[
\"\\\"
foo
\\\"\"
]"
;
auto
s
=
"[
\"\\\"
foo
\\\"\"
]"
;
json
j
=
json
::
parse
(
s
);
json
j
=
json
::
parse
(
s
);
CHECK
(
j
==
R"(["\"foo\""])"
_json
);
auto
expected
=
R"(["\"foo\""])"
_json
;
CHECK
(
j
==
expected
);
}
}
}
}
...
...
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