Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/graph/adjacency_list.hpp>
- #include <boost/graph/graphml.hpp>
- #include <boost/graph/graph_utility.hpp>
- #include <fstream>
- #include <string>
- #include <sstream>
- using namespace boost;
- using namespace std;
- struct VertexProperties { string url, description; };
- struct EdgeProperties { string url, description; };
- struct GraphProperties { string title; };
- int main(int argc, char **argv)
- {
- string path(argc == 2 ? argv[1] : "simple_graph.graphml");
- typedef adjacency_list<vecS, vecS, directedS, VertexProperties, EdgeProperties, GraphProperties> DirectedGraph;
- typedef dynamic_properties Properties;
- DirectedGraph graph(0);
- Properties props(ignore_other_properties);
- props.property("url", get(&VertexProperties::url, graph));
- props.property("description", get(&VertexProperties::description, graph));
- props.property("url", get(&EdgeProperties::url, graph));
- props.property("description", get(&EdgeProperties::description, graph));
- map<string, string> attribute_name2name;
- associative_property_map<map<string, string>> graphname_map(attribute_name2name);
- props.property("title", graphname_map);
- ifstream file(path.c_str());
- if (!file.is_open()) {
- cout << "loading file failed." << endl;
- return 1;
- }
- // This fixes incompatibilities in yEd's .graphml export:
- string line;
- stringstream validated;
- while (getline(file, line)) {
- auto np = string::npos;
- if (line.find("yfiles.type=\"") != np && (line.find("attr.name=\"") == np ||
- line.find("attr.type=") == np)) {
- auto p = line.find("/>");
- if (p == np) {
- cerr << "parse error" << endl;
- return 1;
- }
- line.insert(p, " attr.name=\"dummy\" attr.type=\"string\"");
- validated << line << '\n';
- } else {
- validated << line << '\n';
- }
- }
- file.close();
- try {
- read_graphml(validated, graph, props);
- graph[graph_bundle].title = get(graphname_map, "title");
- cout << "\"" << graph[graph_bundle].title << "\"" << endl;
- } catch(parse_error& e) {
- cerr << e.what() << endl;
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement