File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,9 @@ AssemblyItem Assembly::createAssemblyItemFromJSON(Json::Value const& _json)
109
109
std::string name = getOrDefault<std::string>(_json, " name" , " " );
110
110
solAssert (!name.empty ());
111
111
112
- int begin = getOrDefault <int >(_json, " begin" , - 1 );
113
- int end = getOrDefault <int >(_json, " end" , - 1 );
114
- int srcIndex = getOrDefault <int >(_json, " source" , - 1 );
112
+ int begin = get <int >(_json, " begin" );
113
+ int end = get <int >(_json, " end" );
114
+ int srcIndex = get <int >(_json, " source" );
115
115
size_t modifierDepth = static_cast <size_t >(getOrDefault<int >(_json, " modifierDepth" , 0 ));
116
116
std::string value = getOrDefault<std::string>(_json, " value" , " " );
117
117
std::string jumpType = getOrDefault<std::string>(_json, " jumpType" , " " );
Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ struct helper;
81
81
{ \
82
82
return _input[_name].CHECK_TYPE (); \
83
83
} \
84
+ static TYPE get (Json::Value const & _input, std::string const & _name) \
85
+ { \
86
+ return _input[_name].CONVERT_TYPE (); \
87
+ } \
84
88
static TYPE getOrDefault (Json::Value const & _input, std::string const & _name, TYPE _default = {}) \
85
89
{ \
86
90
TYPE result = _default; \
@@ -114,6 +118,12 @@ bool ofTypeIfExists(Json::Value const& _input, std::string const& _name)
114
118
return true ;
115
119
}
116
120
121
+ template <typename T>
122
+ T get (Json::Value const & _input, std::string const & _name)
123
+ {
124
+ return detail::helper<T>::get (_input, _name);
125
+ }
126
+
117
127
template <typename T>
118
128
T getOrDefault (Json::Value const & _input, std::string const & _name, T _default = {})
119
129
{
Original file line number Diff line number Diff line change @@ -286,6 +286,29 @@ BOOST_AUTO_TEST_CASE(json_getOrDefault)
286
286
BOOST_CHECK (getOrDefault<std::string>(json, " no_string" , " ERROR" ) == " ERROR" );
287
287
}
288
288
289
+ BOOST_AUTO_TEST_CASE (json_get)
290
+ {
291
+ Json::Value json;
292
+
293
+ json[" float" ] = 3 .1f ;
294
+ json[" double" ] = 3.1 ;
295
+ json[" int" ] = 2 ;
296
+ json[" int64" ] = Json::Int64{0x4000000000000000 };
297
+ json[" uint64" ] = Json::UInt64{0x5000000000000000 };
298
+ json[" string" ] = " Hello World!" ;
299
+
300
+ BOOST_CHECK (get<float >(json, " float" ) == 3 .1f );
301
+ BOOST_CHECK (get<double >(json, " double" ) == 3.1 );
302
+ BOOST_CHECK (get<int >(json, " int" ) == 2 );
303
+ BOOST_CHECK (get<Json::Int>(json, " int" ) == 2 );
304
+ BOOST_CHECK (get<Json::UInt>(json, " int" ) == 2 );
305
+ BOOST_CHECK (get<Json::Int64>(json, " int" ) == 2 );
306
+ BOOST_CHECK (get<Json::Int64>(json, " int64" ) == 0x4000000000000000 );
307
+ BOOST_CHECK (get<Json::UInt64>(json, " int64" ) == 0x4000000000000000 );
308
+ BOOST_CHECK (get<Json::UInt64>(json, " uint64" ) == 0x5000000000000000 );
309
+ BOOST_CHECK (get<std::string>(json, " string" ) == " Hello World!" );
310
+ }
311
+
289
312
BOOST_AUTO_TEST_SUITE_END ()
290
313
291
314
}
You can’t perform that action at this time.
0 commit comments