src/c++/lib/grm/GraphInput.cpp
/**
 * Read paths from JSON
 * @param graph graph to use for the paths
 * @param in_paths Input JSON node with paths
 */
Read paths from JSON
@param graph graph to use for the paths
@param in_paths Input JSON node with paths
Read paths from JSON @param graph graph to use for the paths @param in_paths Input JSON node with paths
std::list<graphtools::Path> pathsFromJson(graphtools::Graph const* graph, Json::Value const& in_paths)
{
    std::list<graphtools::Path> paths;
    assert(in_paths.type() == Json::ValueType::arrayValue);
    std::unordered_map<std::string, NodeId> node_id_map;
    for (NodeId node_id = 0; node_id != graph->numNodes(); ++node_id)
    {
        node_id_map[graph->nodeName(node_id)] = node_id;
    }
    for (const auto& path : in_paths)
    {
        auto const& path_nodes = path["nodes"];
        assert(path_nodes.type() == Json::ValueType::arrayValue);
        std::vector<NodeId> nodes;
        nodes.reserve(path_nodes.size());
        for (const auto& node_json : path_nodes)
        {
            const auto& node_name = node_json.asString();
            assert(node_id_map.count(node_name) == 1);
            nodes.push_back(node_id_map[node_name]);
        }
        paths.emplace_back(graph, 0, nodes, graph->nodeSeq(nodes.back()).size() - 1);
    }
    return paths;
}
std :: list < graphtools :: Path > pathsFromJson ( graphtools :: Graph const * graph , Json :: Value const & in_paths ) { std :: list < graphtools :: Path > paths ; assert ( in_paths . type ( ) == Json :: ValueType :: arrayValue ) ; std :: unordered_map < std :: string , NodeId > node_id_map ; for ( NodeId node_id = 0 ; node_id != graph -> numNodes ( ) ; ++ node_id ) { node_id_map [ graph -> nodeName ( node_id ) ] = node_id ; } for ( const auto & path : in_paths ) { auto const & path_nodes = path [ " " ] ; assert ( path_nodes . type ( ) == Json :: ValueType :: arrayValue ) ; std :: vector < NodeId > nodes ; nodes . reserve ( path_nodes . size ( ) ) ; for ( const auto & node_json : path_nodes ) { const auto & node_name = node_json . asString ( ) ; assert ( node_id_map . count ( node_name ) == 1 ) ; nodes . push_back ( node_id_map [ node_name ] ) ; } paths . emplace_back ( graph , 0 , nodes , graph -> nodeSeq ( nodes . back ( ) ) . size ( ) - 1 ) ; } return paths ; }
Read paths from JSON
 @param graph graph to use for the paths
 @param in_paths Input JSON node with paths
Read paths from JSON @param graph graph to use for the paths @param in_paths Input JSON node with paths