1 #ifndef UTOPIA_DATAIO_GRAPH_LOAD_HH
2 #define UTOPIA_DATAIO_GRAPH_LOAD_HH
6 #include <boost/graph/graphml.hpp>
7 #include <boost/graph/graphviz.hpp>
8 #include <boost/property_map/dynamic_property_map.hpp>
38 template <
typename Graph>
40 boost::dynamic_properties pmaps)
43 const auto format = get_as<std::string>(
"format", cfg,
"dot");
49 std::ifstream ifs(abs_file_path.c_str());
50 if (not ifs.is_open()) {
51 throw std::invalid_argument(
52 "Failed opening file for loading graph! Make sure there "
53 "exists a file at " + abs_file_path +
"!"
58 if (format ==
"graphviz" or format ==
"gv" or format ==
"dot") {
59 boost::read_graphviz(ifs, g, pmaps);
61 }
else if (format ==
"graphml") {
62 boost::read_graphml(ifs, g, pmaps);
65 throw std::invalid_argument(
66 "The given file format is not supported. The file format needs "
67 "to be one of 'graphviz' / 'gv' / 'dot' or 'graphml' "
68 "and needs to be specified in the config's format node, e.g. "
69 "load_from_file: { format: graphml }.");
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
std::string get_abs_filepath(const Config &cfg)
Extracts an absolute file path from a configuration.
Definition: filesystem.hh:73
Graph load_graph(const Config &cfg, boost::dynamic_properties pmaps)
Load a graph.
Definition: graph_load.hh:39