Skip to content

Commit 4f6e2f9

Browse files
committed
Merge branch 'develop'
2 parents 0a21a5f + 2747cab commit 4f6e2f9

File tree

11 files changed

+70
-19
lines changed

11 files changed

+70
-19
lines changed

parse/jsd_array.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace JSON
1313
{
1414
try
1515
{
16-
auto pt = object.tree.get_child(name);
16+
GET_CHILD(name, pt, {});
17+
1718
int pos = 0;
1819
for (auto const& i : pt)
1920
{

parse/jsd_container.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JSON
1111
{
1212
try
1313
{
14-
auto pt = object.tree.get_child(name);
14+
GET_CHILD(name, pt, {});
1515
for (auto const& i : pt)
1616
{
1717
T temp;

parse/jsd_core.h

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,51 @@
99

1010
namespace JSON
1111
{
12+
#define GET_VALUE(TYPE, NAME, TEMP, TAG_VALUE) \
13+
if (options.invalidPathHandler == InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR || \
14+
options.invalidPathHandler == InvalidPathHandlingBehaviour::TAG) \
15+
{ \
16+
value = {}; \
17+
auto opt = object.tree.get_optional <TYPE> (NAME); \
18+
if (!opt) { \
19+
if (options.invalidPathHandler == InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR) \
20+
return; \
21+
else { \
22+
value = TAG_VALUE; \
23+
return; \
24+
} \
25+
} \
26+
TEMP = opt.get(); \
27+
} \
28+
else \
29+
{ \
30+
TEMP = object.tree.get <TYPE> (NAME); \
31+
}
32+
// MAKRO END
33+
34+
#define GET_CHILD(NAME, RESULT, TAG_VALUE) \
35+
decltype(object.tree) RESULT;\
36+
if (options.invalidPathHandler == InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR || \
37+
options.invalidPathHandler == InvalidPathHandlingBehaviour::TAG) \
38+
{ \
39+
value = {}; \
40+
auto opt = object.tree.get_child_optional (NAME); \
41+
if (!opt) { \
42+
if (options.invalidPathHandler == InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR) \
43+
return; \
44+
else { \
45+
value = TAG_VALUE; \
46+
return; \
47+
} \
48+
} \
49+
RESULT = opt.get(); \
50+
} \
51+
else \
52+
{ \
53+
RESULT = object.tree.get_child (NAME); \
54+
}
55+
// MAKRO END
56+
1257
#define DEFAULT_PROPERTY_ERROR_HANDLER(DEFAULT_VALUE, TAG_VALUE) \
1358
switch (options.invalidPropertyHandler) { \
1459
case (InvalidPropertyHandlingBehaviour::DEFAULT): \
@@ -23,7 +68,7 @@ namespace JSON
2368
throw exc; \
2469
default: \
2570
return; \
26-
} \
71+
}
2772
// MAKRO END
2873

2974
#define DEFAULT_PATH_ERROR_HANDLER(DEFAULT_VALUE, TAG_VALUE) \
@@ -40,7 +85,7 @@ namespace JSON
4085
throw exc; \
4186
default: \
4287
return; \
43-
} \
88+
}
4489
// MAKRO END
4590
}
4691

parse/jsd_fundamental.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace JSON
1010
{
1111
try
1212
{
13-
std::string s = object.tree.get<std::string>(name);
13+
std::string s;
14+
GET_VALUE(std::string, name, s, char());
15+
1416
if (!s.empty())
1517
value = s[0];
16-
else
17-
value = char();
1818
}
1919
catch (boost::property_tree::ptree_bad_data& exc)
2020
{
@@ -30,11 +30,11 @@ namespace JSON
3030
{
3131
try
3232
{
33-
std::string s = object.tree.get<std::string>(name);
33+
std::string s;
34+
GET_VALUE(std::string, name, s, wchar_t());
35+
3436
if (!s.empty())
3537
value = s[0];
36-
else
37-
value = wchar_t();
3838
}
3939
catch (boost::property_tree::ptree_bad_data& exc)
4040
{

parse/jsd_fundamental.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace JSON
1414
{
1515
try
1616
{
17-
value = object.tree.get<T>(name);
17+
GET_VALUE(T, name, value, T());
1818
}
1919
catch (boost::property_tree::ptree_bad_data& exc)
2020
{

parse/jsd_map.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JSON
1111
{
1212
try
1313
{
14-
auto pt = object.tree.get_child(name);
14+
GET_CHILD(name, pt, (std::map<std::string, ValueT>()));
1515
for (auto const& i : pt)
1616
{
1717
ValueT temp;

parse/jsd_options.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ namespace JSON
2929
InvalidPathHandlingBehaviour invalidPathHandler = InvalidPathHandlingBehaviour::TAG);
3030
};
3131

32-
#define DEFAULT_PARSER_OPTIONS ParsingOptions{}
32+
const auto DefaultParserOptions = ParsingOptions{};
33+
const auto IngoreErrorsParserOptions = ParsingOptions{InvalidPropertyHandlingBehaviour::IGNORE_ALL_ERROR, InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR};
34+
const auto IgnoreMissingParserOptions = ParsingOptions{InvalidPropertyHandlingBehaviour::THROW, InvalidPathHandlingBehaviour::IGNORE_ALL_ERROR};
35+
const auto TagMissingParserOptions = ParsingOptions{InvalidPropertyHandlingBehaviour::THROW, InvalidPathHandlingBehaviour::TAG};
36+
37+
#define DEFAULT_PARSER_OPTIONS DefaultParserOptions
3338
}
3439

3540
#endif

parse/jsd_pair.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace JSON
1111
{
1212
try
1313
{
14-
value.first = object.tree.get<T>(name+".first");
15-
value.second = object.tree.get<U>(name+".second");
14+
GET_VALUE(T, name+".first", value.first, std::make_pair(T(), U()));
15+
GET_VALUE(T, name+".second", value.second, std::make_pair(T(), U()));
1616
}
1717
catch (boost::property_tree::ptree_bad_data& exc)
1818
{

parse/jsd_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace JSON
1414
{
1515
try
1616
{
17-
auto pt = object.tree.get_child(name);
17+
GET_CHILD(name, pt, std::set<T>{});
1818
for (auto const& i : pt)
1919
{
2020
T temp;

parse/jsd_string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void parse(std::string& value, std::string const& name,
77
{
88
try
99
{
10-
value = object.tree.get<std::string>(name);
10+
GET_VALUE(std::string, name, value, "<undefined>");
1111
}
1212
catch (boost::property_tree::ptree_bad_data& exc)
1313
{

0 commit comments

Comments
 (0)