Skip to content

Commit 7fdb3e4

Browse files
committed
Formatting changes, bugfix for std::array and a merge operation with default values was added.
1 parent 181d76f commit 7fdb3e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+549
-121
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ BOOST_FUSION_ADAPT_STRUCT
133133
(std::vector <std::string>, someContainer)
134134
)
135135

136-
JSON_INJECT_STRINGIFY(ConfigContent)
137-
JSON_INJECT_PARSE(ConfigContent)
136+
SJSON_INJECT_STRINGIFY(ConfigContent)
137+
SJSON_INJECT_PARSE(ConfigContent)
138138
```
139139
140140
## Example 2

parse/jsd_array.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace JSON
1212
{
1313
try
1414
{
15-
GET_CHILD(name, pt, {});
15+
SJSON_GET_CHILD(name, pt, {});
1616

1717
int pos = 0;
1818
for (auto const& i : pt)
@@ -23,15 +23,17 @@ namespace JSON
2323
value[pos++] = temp;
2424
else if (options.invalidPropertyHandler != InvalidPropertyHandlingBehaviour::IGNORE_ALL_ERROR)
2525
throw std::out_of_range("there is more data to be read, but the array is full");
26-
}
26+
}
27+
for (; pos < static_cast <decltype(pos)>(N); ++pos)
28+
value[pos] = 0;
2729
}
2830
catch (boost::property_tree::ptree_bad_data& exc)
2931
{
30-
DEFAULT_PROPERTY_ERROR_HANDLER({}, {});
32+
SJSON_DEFAULT_PROPERTY_ERROR_HANDLER({}, {});
3133
}
3234
catch (boost::property_tree::ptree_bad_path& exc)
3335
{
34-
DEFAULT_PATH_ERROR_HANDLER({}, {});
36+
SJSON_DEFAULT_PATH_ERROR_HANDLER({}, {});
3537
}
3638
}
3739
}

parse/jsd_container.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace JSON
1010
{
1111
try
1212
{
13-
GET_CHILD(name, pt, {});
13+
SJSON_GET_CHILD(name, pt, {});
1414

1515
/*
1616
decltype(object.tree) pt;
@@ -46,11 +46,11 @@ namespace JSON
4646
}
4747
catch (boost::property_tree::ptree_bad_data& exc)
4848
{
49-
DEFAULT_PROPERTY_ERROR_HANDLER({},{});
49+
SJSON_DEFAULT_PROPERTY_ERROR_HANDLER({},{});
5050
}
5151
catch (boost::property_tree::ptree_bad_path& exc)
5252
{
53-
DEFAULT_PATH_ERROR_HANDLER({},{});
53+
SJSON_DEFAULT_PATH_ERROR_HANDLER({},{});
5454
}
5555
}
5656
}

parse/jsd_core.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace JSON
6060
};
6161
*/
6262

63-
#define GET_VALUE(TYPE, NAME, TEMP, TAG_VALUE) \
63+
#define SJSON_GET_VALUE(TYPE, NAME, TEMP, TAG_VALUE) \
6464
if (options.invalidPathHandler == InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR || \
6565
options.invalidPathHandler == InvalidPathHandlingBehaviour::TAG) \
6666
{ \
@@ -82,7 +82,7 @@ namespace JSON
8282
}
8383
// MAKRO END
8484

85-
#define GET_CHILD(NAME, RESULT, TAG_VALUE) \
85+
#define SJSON_GET_CHILD(NAME, RESULT, TAG_VALUE) \
8686
decltype(object.tree) RESULT;\
8787
if (options.invalidPathHandler == InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR || \
8888
options.invalidPathHandler == InvalidPathHandlingBehaviour::TAG) \
@@ -105,7 +105,7 @@ namespace JSON
105105
}
106106
// MAKRO END
107107

108-
#define DEFAULT_PROPERTY_ERROR_HANDLER(DEFAULT_VALUE, TAG_VALUE) \
108+
#define SJSON_DEFAULT_PROPERTY_ERROR_HANDLER(DEFAULT_VALUE, TAG_VALUE) \
109109
switch (options.invalidPropertyHandler) { \
110110
case (InvalidPropertyHandlingBehaviour::DEFAULT): \
111111
/* value = {}; */\
@@ -120,7 +120,7 @@ namespace JSON
120120
}
121121
// MAKRO END
122122

123-
#define DEFAULT_PATH_ERROR_HANDLER(DEFAULT_VALUE, TAG_VALUE) \
123+
#define SJSON_DEFAULT_PATH_ERROR_HANDLER(DEFAULT_VALUE, TAG_VALUE) \
124124
switch (options.invalidPathHandler) { \
125125
case (InvalidPathHandlingBehaviour::DEFAULT): \
126126
/* value = {}; */\

parse/jsd_enum.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ namespace JSON
1616
{
1717
using integer_type = typename type_of_size <sizeof(T) * 8>::type;
1818
integer_type temp;
19-
GET_VALUE(integer_type, name, temp, T());
19+
SJSON_GET_VALUE(integer_type, name, temp, T());
2020
value = static_cast <T>(temp);
2121
}
2222
catch (boost::property_tree::ptree_bad_data& exc)
2323
{
24-
DEFAULT_PROPERTY_ERROR_HANDLER(T(), T());
24+
SJSON_DEFAULT_PROPERTY_ERROR_HANDLER(T(), T());
2525
}
2626
catch (boost::property_tree::ptree_bad_path& exc)
2727
{
28-
DEFAULT_PATH_ERROR_HANDLER(T(), T());
28+
SJSON_DEFAULT_PATH_ERROR_HANDLER(T(), T());
2929
}
3030
}
3131
}

parse/jsd_fundamental.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ namespace JSON
1111
try
1212
{
1313
std::string s;
14-
GET_VALUE(std::string, name, s, char());
14+
SJSON_GET_VALUE(std::string, name, s, char());
1515

1616
if (!s.empty())
1717
value = s[0];
1818
}
1919
catch (boost::property_tree::ptree_bad_data& exc)
2020
{
21-
DEFAULT_PROPERTY_ERROR_HANDLER(char(), char());
21+
SJSON_DEFAULT_PROPERTY_ERROR_HANDLER(char(), char());
2222
}
2323
catch (boost::property_tree::ptree_bad_path& exc)
2424
{
25-
DEFAULT_PATH_ERROR_HANDLER(char(), char());
25+
SJSON_DEFAULT_PATH_ERROR_HANDLER(char(), char());
2626
}
2727
}
2828
void parse(wchar_t& value, std::string const& name,
@@ -31,18 +31,18 @@ namespace JSON
3131
try
3232
{
3333
std::string s;
34-
GET_VALUE(std::string, name, s, wchar_t());
34+
SJSON_GET_VALUE(std::string, name, s, wchar_t());
3535

3636
if (!s.empty())
3737
value = s[0];
3838
}
3939
catch (boost::property_tree::ptree_bad_data& exc)
4040
{
41-
DEFAULT_PROPERTY_ERROR_HANDLER(wchar_t(), wchar_t());
41+
SJSON_DEFAULT_PROPERTY_ERROR_HANDLER(wchar_t(), wchar_t());
4242
}
4343
catch (boost::property_tree::ptree_bad_path& exc)
4444
{
45-
DEFAULT_PATH_ERROR_HANDLER(wchar_t(), wchar_t());
45+
SJSON_DEFAULT_PATH_ERROR_HANDLER(wchar_t(), wchar_t());
4646
}
4747
}
4848
}

parse/jsd_fundamental.hpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@
55

66
namespace JSON
77
{
8-
template <typename T,
9-
class = typename std::enable_if< (std::is_arithmetic<T>::value && !std::is_same<T, char>::value && !std::is_same<T, wchar_t>::value)
10-
&& !std::is_enum<T>::value >::type
11-
>
12-
void parse(T& value, std::string const& name,
13-
PropertyTree const& object, ParsingOptions const& options = {})
8+
template <
9+
typename T,
10+
class = typename std::enable_if<(
11+
std::is_arithmetic<T>::value &&
12+
!std::is_same<T, char>::value &&
13+
!std::is_same<T, wchar_t>::value) &&
14+
!std::is_enum<T>::value
15+
>::type
16+
>
17+
void parse(
18+
T& value,
19+
std::string const& name,
20+
PropertyTree const& object,
21+
ParsingOptions const& options = {}
22+
)
1423
{
1524
try
1625
{
17-
GET_VALUE(T, name, value, T());
26+
SJSON_GET_VALUE(T, name, value, T());
1827
}
1928
catch (boost::property_tree::ptree_bad_data& exc)
2029
{
21-
DEFAULT_PROPERTY_ERROR_HANDLER(T(), T());
30+
SJSON_DEFAULT_PROPERTY_ERROR_HANDLER(T(), T());
2231
}
2332
catch (boost::property_tree::ptree_bad_path& exc)
2433
{
25-
DEFAULT_PATH_ERROR_HANDLER(T(), T());
34+
SJSON_DEFAULT_PATH_ERROR_HANDLER(T(), T());
2635
}
2736
}
2837

parse/jsd_fusion_adapted_struct.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace JSON
7676
};
7777
}
7878

79-
#define JSON_INJECT_PARSE(ClassName) \
79+
#define SJSON_INJECT_PARSE(ClassName) \
8080
namespace JSON \
8181
{ \
8282
void parse( \

parse/jsd_generic_parser.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@
77
namespace JSON
88
{
99
using namespace boost::property_tree;
10-
10+
//#####################################################################################################################
1111
PropertyTree::PropertyTree(boost::property_tree::ptree tree)
1212
: tree(tree)
1313
{
1414

1515
}
16-
// ======================================================================================================
16+
//---------------------------------------------------------------------------------------------------------------------
17+
void PropertyTree::to_stream(std::ostream& stream)
18+
{
19+
write_json(stream, tree);
20+
}
21+
//#####################################################################################################################
1722
PropertyTree parse_json(std::istream& stream)
1823
{
1924
ptree pt;
2025
read_json(stream, pt);
2126
return PropertyTree(pt);
2227
}
28+
//---------------------------------------------------------------------------------------------------------------------
2329
PropertyTree parse_json(std::string const& str)
2430
{
2531
std::stringstream sstr(str);
@@ -28,7 +34,7 @@ namespace JSON
2834
read_json(sstr, pt);
2935
return PropertyTree(pt);
3036
}
31-
37+
//---------------------------------------------------------------------------------------------------------------------
3238
boost::optional<PropertyTree> parse_auto(std::istream& stream)
3339
{
3440
ptree pt;
@@ -62,7 +68,7 @@ namespace JSON
6268

6369
return boost::make_optional( PropertyTree(pt) );
6470
}
65-
71+
//---------------------------------------------------------------------------------------------------------------------
6672
boost::optional<PropertyTree> parse_xml(std::istream& stream)
6773
{
6874
ptree pt;
@@ -75,4 +81,5 @@ namespace JSON
7581
return boost::optional<PropertyTree>();
7682
}
7783
}
84+
//#####################################################################################################################
7885
}

parse/jsd_generic_parser.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ namespace JSON
1515
{
1616
boost::property_tree::ptree tree;
1717

18-
PropertyTree(boost::property_tree::ptree tree = {});
18+
PropertyTree(boost::property_tree::ptree tree = {});
19+
void to_stream(std::ostream& stream);
1920
};
2021

2122
PropertyTree parse_json(std::istream& stream);

0 commit comments

Comments
 (0)