Skip to content

Commit 0bcb594

Browse files
committed
Fixed wrong behaviour for normal non polymorphic classes.
1 parent d91623e commit 0bcb594

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

parse/jsd_smart_ptr.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace JSON
99
{
1010
namespace internal
1111
{
12-
template <typename T, bool ClassType, bool Enabler>
12+
template <typename T, bool ClassType, bool Poly>
1313
struct smart_pointer_parser
1414
{
1515
};
1616

1717
template <typename T>
18-
struct smart_pointer_parser <T, true, true>
18+
struct smart_pointer_parser <T, true, false>
1919
{
2020
static void get(T& value, std::string const& name, PropertyTree const& object, ParsingOptions const& options)
2121
{
@@ -25,7 +25,7 @@ namespace JSON
2525
};
2626

2727
template <typename T>
28-
struct smart_pointer_parser <T, false, true>
28+
struct smart_pointer_parser <T, false, false>
2929
{
3030
static void get(T& value, std::string const& name, PropertyTree const& object, ParsingOptions const& options)
3131
{
@@ -36,7 +36,7 @@ namespace JSON
3636
};
3737

3838
template <typename T>
39-
struct smart_pointer_parser <T, true, false>
39+
struct smart_pointer_parser <T, true, true>
4040
{
4141
static void get(T& value, std::string const& name, PropertyTree const& object, ParsingOptions const& options)
4242
{
@@ -73,7 +73,7 @@ namespace JSON
7373
};
7474

7575
template <typename T>
76-
struct smart_pointer_parser <T, false, false>
76+
struct smart_pointer_parser <T, false, true>
7777
{
7878
static void get(T& value, std::string const& name, PropertyTree const& object, ParsingOptions const& options)
7979
{
@@ -88,14 +88,13 @@ namespace JSON
8888
{
8989

9090
using element_type = typename std::decay<decltype(value)>::type::element_type;
91-
using polydecl_type = polydecls <element_type>;
9291

9392
internal::smart_pointer_parser <T,
9493
std::is_class <element_type>::value,
95-
std::is_same <typename polydecl_type::type, no_poly>::value>::get(value,
96-
name,
97-
object,
98-
options);
94+
is_polydecl <element_type>::value>::get(value,
95+
name,
96+
object,
97+
options);
9998
}
10099
}
101100
}

stringify/jss_smart_ptr.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace JSON
1414
{
1515
static void exec(std::ostream& stream, const std::string& name, T const& value, StringificationOptions const& options)
1616
{
17+
if (options.in_object && !options.ignore_name)
18+
WRITE_NAME(stream);
1719
value->stringify(stream, options);
1820
}
1921
};
@@ -24,6 +26,8 @@ namespace JSON
2426
static void exec(std::ostream& stream, const std::string& name, T const& value, StringificationOptions const& options)
2527
{
2628
//value->stringify(stream, options);
29+
if (options.in_object && !options.ignore_name)
30+
WRITE_NAME(stream);
2731
polydecls <typename T::element_type>::smart_pointer_set(value, stream, options);
2832
}
2933
};
@@ -40,15 +44,12 @@ namespace JSON
4044
template <typename T>
4145
std::ostream& stringify_smart_ptr(std::ostream& stream, const std::string& name, T const& value, StringificationOptions const& options = {})
4246
{
43-
if (options.in_object && !options.ignore_name)
44-
WRITE_NAME(stream);
45-
4647
using element_type = typename std::decay<decltype(value)>::type::element_type;
4748

4849
internal::smart_pointer_stringifier <
4950
typename std::decay<decltype(value)>::type,
5051
std::is_class <element_type>::value,
51-
!std::is_same <element_type, no_poly>::value
52+
is_polydecl <element_type>::value
5253
>::exec(stream, name, value, options);
5354
return stream;
5455
}

utility/polymorphy.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ namespace JSON
2525
struct polydecls
2626
{
2727
using type = no_poly;
28+
};
2829

29-
static std::string identify_type(T const*)
30-
{
31-
return "SimpleJson_internal_error";
32-
}
30+
template <typename T>
31+
struct is_polydecl
32+
{
33+
static constexpr bool const value = !std::is_same <typename polydecls <T>::type, no_poly>::value;
3334
};
3435

3536
template <typename BaseT, typename PackT>

0 commit comments

Comments
 (0)