123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109(******************************************************************************)(* *)(* Copyright (C) 2012 Pietro Abate <pietro.abate@pps.jussieu.fr> *)(* *)(* This library is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as *)(* published by the Free Software Foundation, either version 3 of the *)(* License, or (at your option) any later version. A special linking *)(* exception to the GNU Lesser General Public License applies to this *)(* library, see the COPYING file for more information. *)(* *)(******************************************************************************)moduletypeG=sigtypettypevertexmoduleE:sigtypetvalsrc:t->vertexvaldst:t->vertexendvalis_directed:boolvaliter_vertex:(vertex->unit)->t->unitvaliter_edges_e:(E.t->unit)->t->unitendmodulePrint(G:G)(L:sigvalvertex_properties:(string*string*stringoption)listvaledge_properties:(string*string*stringoption)listvalmap_vertex:G.vertex->(string*string)listvalmap_edge:G.E.t->(string*string)listvalvertex_uid:G.vertex->intvaledge_uid:G.E.t->intend)=structletheader="<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" \
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns \
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">";;letdata_ppfmt(key,value)=Format.fprintffmt"<data key=\"%s\">%s</data>"keyvalueletpp_typefmttproptypdefault=Format.fprintffmt"<key id=\"%s\" for=\"%s\" attr.name=\"%s\" attr.type=\"%s\">"proptproptyp;matchdefaultwith|None->Format.fprintffmt"</key>\n"|Somes->beginFormat.fprintffmt"\n <default>%s</default>\n"s;Format.fprintffmt"</key>\n"endletprintfmtgraph=Format.fprintffmt"%s\n"header;(* node attributed declaration *)List.iter(fun(prop,typ,default)->pp_typefmt"node"proptypdefault)L.vertex_properties;(* edge attributed declaration *)List.iter(fun(prop,typ,default)->pp_typefmt"edge"proptypdefault)L.edge_properties;letdirected=ifG.is_directedthen"edgedefault=\"directed\""else""inFormat.fprintffmt"<graph id=\"G\" %s>\n"directed;(* vertex printer *)G.iter_vertex(funvertex->letid=L.vertex_uidvertexinletl=L.map_vertexvertexinFormat.fprintffmt" <node id=\"n%d\">\n"id;List.iter(Format.fprintffmt" %a\n"data_pp)l;Format.fprintffmt" </node>\n")graph;(* edge printer *)G.iter_edges_e(funedge->letn1=L.vertex_uid(G.E.srcedge)inletn2=L.vertex_uid(G.E.dstedge)inleteid=L.edge_uidedgeinletl=L.map_edgeedgeinFormat.fprintffmt" <edge id=\"e%d\" source=\"n%d\" target=\"n%d\">\n"eidn1n2;List.iter(Format.fprintffmt" %a\n"data_pp)l;Format.fprintffmt" </edge>\n")graph;Format.fprintffmt"</graph>\n";Format.fprintffmt"</graphml>\n"end(*
Local Variables:
compile-command: "make -C .."
End:
*)