We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3a5b0ac commit 9c79dfaCopy full SHA for 9c79dfa
parse/jsd_optional.h
@@ -0,0 +1,28 @@
1
+#ifndef JSD_OPTIONAL_H_INCLUDED
2
+#define JSD_OPTIONAL_H_INCLUDED
3
+
4
+#include <boost/optional.hpp>
5
6
+namespace JSON
7
+{
8
+ template <typename T>
9
+ void parse(boost::optional <T>& value, std::string const& name,
10
+ PropertyTree const& object, ParsingOptions const& options = DEFAULT_PARSER_OPTIONS)
11
+ {
12
+ try
13
14
+ auto opt = object.tree.get_optional <T> (name);
15
+ if (!opt)
16
+ return; // its ok, it was optional
17
+ else
18
+ value = opt.get();
19
+ }
20
+ catch (boost::property_tree::ptree_bad_data& exc)
21
22
+ DEFAULT_PROPERTY_ERROR_HANDLER(T(), T());
23
24
+ // cannot throw ptree_bad_path
25
26
+}
27
28
+#endif // JSD_OPTIONAL_H_INCLUDED
0 commit comments