Skip to content

Commit e037614

Browse files
committed
Fixed several bugs, enabled boost::optional support for stringification.
1 parent 9c79dfa commit e037614

23 files changed

+107
-153
lines changed

parse/jsd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
#include "jsd_atomic.h"
1212
#include "jsd_fusion_adapted_struct.h"
1313
#include "jsd_object.h"
14+
#include "jsd_optional.h"
1415

1516
#endif

stringify/jss.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
#include "jss_forward_list.h"
1414
#include "jss_iterator.h"
1515
#include "jss_array.h"
16-
#include "jss_struct.h"
1716
#include "jss_tuple.h"
1817
#include "jss_object.h"
19-
#include "jss_initializer_list.h"
2018
#include "jss_convenience.h"
2119
#include "jss_queue.h"
2220
#include "jss_stack.h"
@@ -29,6 +27,7 @@
2927
#include "jss_atomic.h"
3028
#include "jss_smart_ptr.h"
3129
#include "jss_check.h"
30+
#include "jss_optional.h"
3231

3332
#include "jss_undefine.h"
3433

stringify/jss_array.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define JSS_ARRAY_H_INCLUDED
33

44
#include "jss_core.h"
5-
#include "jss_struct.h"
65
#include "jss_iterator.h"
6+
#include "jss_optional.h"
77
#include <array>
88

99
namespace JSON
@@ -14,14 +14,16 @@ namespace JSON
1414
{
1515
options.ignore_name = true;
1616
WRITE_ARRAY_START(stream);
17-
if (!values.empty())
17+
bool first = true;
18+
for (auto const& i : values)
1819
{
19-
for (auto i = values.begin(); i != values.end() - 1; ++i)
20+
if (Internal::is_optional_set(i))
2021
{
21-
stringify(stream, {}, *i, options);
22-
stream << options.delimiter;
22+
if (!first)
23+
stream << options.delimiter;
24+
stringify(stream, {}, i, options);
25+
first = false;
2326
}
24-
stream << values.back();
2527
}
2628
WRITE_ARRAY_END(stream);
2729
return stream;

stringify/jss_bidirectional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace JSON
1313
std::ostream& stringify (std::ostream& stream, std::string const& name, ContainerT <T> values, StringificationOptions const& options = DEFAULT_OPTIONS,
1414
typename std::enable_if<has_bidirectional_iterator<T, ContainerT>::value>::type* = nullptr)
1515
{
16-
Internal::stringify_i(stream, name, values, [](ContainerT <T> const& c){ auto end = c.end(); end--; return end; });
16+
Internal::stringify_i(stream, name, values, options);
1717
return stream;
1818
}
1919
}

stringify/jss_container.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@
44
#include "jss_core.h"
55
#include "jss_object.h"
66
#include "jss_check.h"
7+
#include "jss_optional.h"
78
#include <functional>
89

910
namespace JSON { namespace Internal
1011
{
1112
template <typename T, template <typename, class = std::allocator <T> > class ContainerT,
1213
typename FuncT = std::function <typename ContainerT<T>::const_iterator(ContainerT<T> const&)>,
1314
class = typename std::enable_if<Internal::can_stringify<typename ContainerT<T>::value_type>::value>::type >
14-
inline std::ostream& stringify_i(std::ostream& stream, std::string const& name, ContainerT <T> const& values, FuncT end_iter, StringificationOptions const& options = DEFAULT_OPTIONS)
15+
inline std::ostream& stringify_i(std::ostream& stream, std::string const& name, ContainerT <T> const& values, StringificationOptions const& options = DEFAULT_OPTIONS)
1516
{
1617
using namespace Internal;
1718

1819
WRITE_ARRAY_START(stream);
19-
if (!values.empty())
20+
auto noNameOption = options;
21+
noNameOption.ignore_name = true;
22+
23+
bool first = true;
24+
for (auto const& i : values)
2025
{
21-
auto end = end_iter(values);
22-
APPLY_IO_MANIPULATERS(stream);
23-
auto noNameOption = options;
24-
noNameOption.ignore_name = true;
25-
auto i = values.begin();
26-
for (; i != end; ++i)
26+
if (Internal::is_optional_set(i))
2727
{
28-
stringify(stream, {}, *i, noNameOption);
29-
stream << options.delimiter;
28+
if (!first)
29+
stream << options.delimiter;
30+
stringify(stream, {}, i, noNameOption);
31+
first = false;
3032
}
31-
stringify(stream, {}, *i, noNameOption);
3233
}
3334
WRITE_ARRAY_END(stream);
3435
return stream;

stringify/jss_core.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace JSON
2525
constexpr auto TemplateRecursionMaximum = 8;
2626

2727
#define CLASS_STRINGIFY_FUNCTION_NAME stringify
28-
#define APPLY_IO_MANIPULATERS(STREAM) options.io_options.apply(STREAM)
2928

3029
#define WRITE_NAME(STREAM) \
3130
if (!options.ignore_name && options.in_object) \

stringify/jss_forward.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace JSON
1313
std::ostream& stringify(std::ostream& stream, std::string const& name, ContainerT <T> const& values, StringificationOptions const& options = DEFAULT_OPTIONS,
1414
typename std::enable_if<has_forward_iterator<T, ContainerT>::value>::type* = nullptr)
1515
{
16-
Internal::stringify_i(stream, name, values, [](ContainerT <T> const& c){ auto b = c.cbegin(); std::advance(b, std::distance(b, c.cend()) - 1); return b; }, options);
16+
Internal::stringify_i(stream, name, values, options);
1717
return stream;
1818
}
1919
}

stringify/jss_forward_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef JSS_FORWARD_LIST_H_INCLUDED
22
#define JSS_FORWARD_LIST_H_INCLUDED
33

4-
#include "jss_forward.h"
54
#include <forward_list>
5+
#include "jss_forward.h"
66

77
#endif // JSS_FORWARD_LIST_H_INCLUDED

stringify/jss_fundamental.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ namespace JSON
44
{
55
std::ostream& stringify(std::ostream& stream, std::string const& name, char value, StringificationOptions const& options)
66
{
7-
APPLY_IO_MANIPULATERS(stream);
87
WRITE_NAME(stream);
98
stream << "\"" << value << "\"";
109
return stream;
1110
}
1211

1312
std::ostream& stringify(std::ostream& stream, std::string const& name, wchar_t value, StringificationOptions const& options)
1413
{
15-
APPLY_IO_MANIPULATERS(stream);
1614
WRITE_NAME(stream);
1715
stream << "\"" << value << "\"";
1816
return stream;

stringify/jss_fundamental.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace JSON
1313
|| std::is_enum<T>::value >::type >
1414
std::ostream& stringify(std::ostream& stream, std::string const& name, T value, StringificationOptions const& options = DEFAULT_OPTIONS)
1515
{
16-
APPLY_IO_MANIPULATERS(stream);
1716
WRITE_NAME(stream);
1817
stream << value;
1918
return stream;

0 commit comments

Comments
 (0)