MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / _parser_probability_result

Function _parser_probability_result

Extensions/PilotOSMachine/QPilotMachine.cpp:255–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253}
254
255static ErrorCode _parser_probability_result(JsonParser& json_parser, std::map<std::string, double>& result)
256{
257 ErrorCode err_code = ErrorCode::NO_ERROR_FOUND;
258 if (json_parser.has_member("errCode"))
259 {
260 err_code = (ErrorCode)json_parser.get_uint32("errCode");
261 }
262
263 if (json_parser.has_member_string("taskResult"))
264 {
265 const auto _result_str = json_parser.get_string("taskResult");
266 JsonParser _json_parser_result;
267 if (!_json_parser_result.load_json(_result_str.c_str()))
268 {
269 return ErrorCode::JSON_FIELD_ERROR;
270 }
271
272 std::vector<std::string> key_vec;
273 if (_json_parser_result.has_member(MSG_DICT_KEY))
274 {
275 _json_parser_result.get_array(MSG_DICT_KEY, key_vec);
276 }
277 else if (_json_parser_result.has_member("Key"))
278 {
279 _json_parser_result.get_array("Key", key_vec);
280 }
281
282 std::vector<double> val_vec;
283 if (_json_parser_result.has_member(MSG_DICT_VALUE))
284 {
285 _json_parser_result.get_array(MSG_DICT_VALUE, val_vec);
286 }
287 else if (_json_parser_result.has_member("Value"))
288 {
289 _json_parser_result.get_array("Value", val_vec);
290 }
291
292 for (size_t i = 0; i < key_vec.size(); ++i)
293 {
294 result.insert(std::make_pair(key_vec[i], val_vec[i]));
295 }
296 }
297 else if (json_parser.has_member_array("taskResult"))
298 {
299 auto& doc = json_parser.get_json_obj();
300
301 for (auto& iter : doc["taskResult"].GetArray())
302 {
303 if (iter.IsString())
304 {
305 std::string _result_str = iter.GetString();
306 JsonParser _json_parser_result;
307 if (!_json_parser_result.load_json(_result_str.c_str()))
308 {
309 return ErrorCode::JSON_FIELD_ERROR;
310 }
311
312 std::vector<std::string> key_vec;

Callers

nothing calls this directly

Calls 12

get_uint32Method · 0.80
has_member_stringMethod · 0.80
get_stringMethod · 0.80
load_jsonMethod · 0.80
get_arrayMethod · 0.80
has_member_arrayMethod · 0.80
GetArrayMethod · 0.80
GetStringMethod · 0.80
get_uint64Method · 0.80
has_memberMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected