void handle_reply ( std::string json ) { std::vector<std::string> classes; std::stringstream ss ( json ); try { boost::property_tree::ptree tree; boost::property_tree::read_json( ss, tree ); // JSON reply is: { results: [], trace: [], error: '' } for ( auto child : tree.get_child( "results" ) ) classes.push_back ( child.second.get_value<std::string>() ); // Check for Errors returned by the api.rapp.cloud for ( auto child : tree.get_child( "error" ) ) { const std::string value = child.second.get_value<std::string>(); if ( !value.empty() ) std::cerr << "ontologySubClassesOf JSON error: " << value << std::endl; } } catch( boost::property_tree::json_parser::json_parser_error & je ) { std::cerr << "ontologySubClassesOf::handle_reply Error parsing: " << je.filename() << " on line: " << je.line() << std::endl; std::cerr << je.message() << std::endl; } delegate__( classes ); }
/// Parse @param buffer received from the socket, into a vector of faces void handle_reply ( boost::asio::streambuf & buffer ) { // Convert the buffer into a string std::string json ( ( std::istreambuf_iterator<char>( &buffer ) ), std::istreambuf_iterator<char>() ); std::vector<std::string> classes; std::stringstream ss ( json ); try { boost::property_tree::ptree tree; boost::property_tree::read_json( ss, tree ); // TODO: WARNING Decide upon the actual JSON Format. - TODO: Kostantinos gave me the Specification for the JSON for ( auto child : tree.get_child( "subclasses" ) ) { // std::string member( iter->first ); // classes.push_back ( iter->second.get_value<std::string>(); } } catch( boost::property_tree::json_parser::json_parser_error & je ) { std::cerr << "ontologySubclassOf::handle_reply Error parsing: " << je.filename() << " on line: " << je.line() << std::endl; std::cerr << je.message() << std::endl; } delegate__( classes ); }
/// Parse @param buffer received from the socket, into a vector of faces void handle_reply ( boost::asio::streambuf & buffer ) { std::string json ( ( std::istreambuf_iterator<char>( &buffer ) ), std::istreambuf_iterator<char>() ); std::stringstream ss ( json ); std::vector< rapp::object::qrCode > qrCodes; try { boost::property_tree::ptree tree; boost::property_tree::read_json( ss, tree ); for ( auto child : tree.get_child( "qrs" ) ) { float qr_center_x = -1.; float qr_center_y = -1.; std::string qr_message; for ( auto iter = child.second.begin(); iter!= child.second.end(); ++iter ) { std::string member( iter->first ); if ( member == "qr_center_x" ) qr_center_x = iter->second.get_value<float>(); else if ( member == "qr_center_y" ) qr_center_y = iter->second.get_value<float>(); else if ( member == "qr_message" ) qr_message = iter->second.get_value<std::string>(); } qrCodes.push_back( rapp::object::qrCode ( qr_center_x, qr_center_y, qr_message ) ); } } catch( boost::property_tree::json_parser::json_parser_error & je ) { std::cerr << "qrDetector::handle_reply Error parsing: " << je.filename() << " on line: " << je.line() << std::endl; std::cerr << je.message() << std::endl; } delegate__( qrCodes ); }
/// Parse @param buffer received from the socket, into a vector of faces /// @note we do not do any parsing at all here - we assume the JSON will be handled by the caller void handle_reply ( boost::asio::streambuf & buffer ) { std::string reply ( ( std::istreambuf_iterator<char>( &buffer ) ), std::istreambuf_iterator<char>() ); delegate__ ( reply ); }