1 #ifndef GRAPHML_WRITER_HPP 
    2 #define GRAPHML_WRITER_HPP 
    4 #include "Graph/map_graph.hpp" 
    7 #include "util/common.hpp" 
   20 void create_prop(std::string * str)
 
   26         for (
size_t i = 0 ; i < T::max_prop ; i++)
 
   28             str[i] = std::string(T::attributes::name[i]);
 
   34         for (
size_t i = 0 ; i < T::max_prop ; i++)
 
   36             str[i] = 
"attr" + std::to_string(i);
 
   80         n_attr = 
sizeof(a_name.name)/
sizeof(std::string);
 
   94         n_attr = G::V_type::max_prop;
 
  128             if (
typeid(T) == 
typeid(
float))
 
  130             else if (
typeid(T) == 
typeid(
double))
 
  131                 v_prop += 
"<key id=\"vk" + std::to_string(
cnt) + 
"\" for=\"node\" attr.name=\"" + 
attributes_names[
cnt] + 
"\" attr.type=\"double\"/>\n";
 
  132             else if (
typeid(T) == 
typeid(
int))
 
  134             else if (
typeid(T) == 
typeid(
long int))
 
  136             else if (
typeid(T) == 
typeid(
bool))
 
  137                 v_prop += 
"<key id=\"vk" + std::to_string(
cnt) + 
"\" for=\"node\" attr.name=\"" + 
attributes_names[
cnt] + 
"\" attr.type=\"boolean\"/>\n";
 
  138             else if (
typeid(T) == 
typeid(std::string))
 
  139                 v_prop += 
"<key id=\"vk" + std::to_string(
cnt) + 
"\" for=\"node\" attr.name=\"" + 
attributes_names[
cnt] + 
"\" attr.type=\"string\"/>\n";
 
  159     const typename G::V_container & 
vo;
 
  186     inline vertex_node(std::string & 
v_node, 
const typename G::V_container & n_obj, 
typename G::V_type::attributes & a_name)
 
  190         n_attr = 
sizeof(a_name.name)/
sizeof(std::string);
 
  200     inline vertex_node(std::string & 
v_node, 
const typename G::V_container && n_obj, 
typename G::V_type::attributes & a_name)
 
  202     {std::cerr << 
"Error: " <<__FILE__ << 
":" << __LINE__ << 
" Passing a temporal object\n";};
 
  217         n_attr = G::V_type::max_prop;
 
  242     {std::cerr << 
"Error: " <<__FILE__ << 
":" << __LINE__ << 
" Passing a temporal object\n";};
 
  253         v_node += 
"<node id=\"n"+ std::to_string(v_c) + 
"\">\n";
 
  282             if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
float))
 
  283                 v_node += 
"  <data key=\"vk" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  284             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
double))
 
  285                 v_node += 
"  <data key=\"vk" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  286             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
int))
 
  287                 v_node += 
"  <data key=\"vk" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  288             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
long int))
 
  289                 v_node += 
"  <data key=\"vk" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  290             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
bool))
 
  291                 v_node += 
"  <data key=\"vk" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  292             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(std::string))
 
  293                 v_node += 
"  <data key=\"vk" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  340         n_attr = 
sizeof(a_name.name)/
sizeof(std::string);
 
  354         n_attr = G::E_type::max_prop;
 
  382             if (
typeid(T) == 
typeid(
float))
 
  384             else if (
typeid(T) == 
typeid(
double))
 
  385                 e_prop += 
"<key id=\"ek" + std::to_string(
cnt) + 
"\" for=\"edge\" attr.name=\"" + 
attributes_names[
cnt] + 
"\" attr.type=\"double\"/>\n";
 
  386             else if (
typeid(T) == 
typeid(
int))
 
  388             else if (
typeid(T) == 
typeid(
long int))
 
  390             else if (
typeid(T) == 
typeid(
bool))
 
  391                 e_prop += 
"<key id=\"ek" + std::to_string(
cnt) + 
"\" for=\"edge\" attr.name=\"" + 
attributes_names[
cnt] + 
"\" attr.type=\"boolean\"/>\n";
 
  392             else if (
typeid(T) == 
typeid(std::string))
 
  393                 e_prop += 
"<key id=\"ek" + std::to_string(
cnt) + 
"\" for=\"edge\" attr.name=\"" + 
attributes_names[
cnt] + 
"\" attr.type=\"string\"/>\n";
 
  413     typename G::E_container & 
vo;
 
  439     edge_node(std::string & 
e_node, 
typename G::E_container & n_obj, 
typename G::E_type::attributes & a_name)
 
  443         n_attr = 
sizeof(a_name.name)/
sizeof(std::string);
 
  458         n_attr = G::E_type::max_prop;
 
  485         e_node += 
"<edge id=\"e"+ std::to_string(v_c) + 
"\" source=\"n" + std::to_string(s) + 
"\" target=\"n" + std::to_string(d) + 
"\">\n";
 
  514             if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
float))
 
  515                 e_node += 
"  <data key=\"ek" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  516             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
double))
 
  517                 e_node += 
"  <data key=\"ek" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  518             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
int))
 
  519                 e_node += 
"  <data key=\"ek" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  520             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
long int))
 
  521                 e_node += 
"  <data key=\"ek" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  522             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(
bool))
 
  523                 e_node += 
"  <data key=\"ek" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  524             else if (
typeid(decltype(
vo.template get<T::value>())) == 
typeid(std::string))
 
  525                 e_node += 
"  <data key=\"ek" + std::to_string(
cnt) + 
"\">" + std::to_string(
vo.template get<T::value>()) + 
"</data>\n";
 
  538 template <
typename Graph>
 
  556         std::string v_out(
"");
 
  562         boost::mpl::for_each_ref< typename Graph::V_type::type >(vp);
 
  584         boost::mpl::for_each_ref< typename Graph::E_type::type >(ep);
 
  604         auto it = 
g.getVertexIterator();
 
  609             auto v = 
g.vertex(it.get());
 
  618             boost::mpl::for_each_ref< boost::mpl::range_c<int,0,Graph::V_type::max_prop> >(vn);
 
  646         auto it = 
g.getEdgeIterator();
 
  652             auto obj = 
g.edge(it.get());
 
  658             en.
new_node(nc,it.source(),it.target());
 
  661             boost::mpl::for_each_ref< boost::mpl::range_c<int,0,Graph::E_type::max_prop> >(en);
 
  694     bool write(std::string file, std::string graph_name=
"Graph")
 
  697         std::string gml_header;
 
  699         std::string vertex_list;
 
  701         std::string gml_header_end;
 
  703         std::string graph_header;
 
  705         std::string graph_header_end;
 
  707         std::string edge_list;
 
  709         std::string vertex_prop_header;
 
  711         std::string edge_prop_header;
 
  714         gml_header = 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\ 
  715         <graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n\ 
  716             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\ 
  717             xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\n\ 
  718              http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n";
 
  721         graph_header = 
"<graph id=\"" + graph_name + 
"\" edgedefault=\"undirected\">\n";
 
  723         graph_header_end =  
"</graph>\n";
 
  738         gml_header_end = 
"</graphml>";
 
  742         std::ofstream ofs(file);
 
  745         if (ofs.is_open() == 
false)
 
  746         {std::cerr << 
"Error cannot creare the graphML file: " + file;}
 
  748         ofs << gml_header << graph_header << vertex_prop_header << edge_prop_header <<
 
  749                vertex_list << edge_list << graph_header_end << gml_header_end;
 
this class is a functor for "for_each" algorithm 
 
int n_attr
Number of attributes name defined into the vertex. 
 
std::string & v_prop
vertex properties 
 
bool to_destroy
indicate if attributes_names is to destroy 
 
std::string * attributes_names
Attribute names. 
 
vertex_prop(std::string &v_prop)
Constructor. 
 
vertex_node(std::string &v_node, const typename G::V_container &n_obj)
Constructor. 
 
int n_attr
Number of attributes name defined into the vertex. 
 
bool to_destroy
indicate if attributes_names is to destroy 
 
void end_node()
Close a node. 
 
this class is a functor for "for_each" algorithm 
 
const G::V_container & vo
Vertex object container. 
 
void new_node(size_t v_c, size_t s, size_t d)
Create a new node. 
 
int cnt
Properties counter. 
 
std::string get_vertex_list()
Get the string containing the set of vertices. 
 
std::string get_edge_list()
return the edge list as a string 
 
int cnt
Properties counter. 
 
edge_node(std::string &e_node, typename G::E_container &n_obj, typename G::E_type::attributes &a_name)
Constructor. 
 
void new_node(size_t v_c)
Create a new node. 
 
bool write(std::string file, std::string graph_name="Graph")
It write a GraphML file from a graph. 
 
int cnt
Properties counter. 
 
std::string & e_prop
edge properties 
 
std::string & e_node
edge node string 
 
edge_node(std::string &e_node, typename G::E_container &n_obj)
Constructor. 
 
int n_attr
Number of attributes name defined into the vertex. 
 
vertex_node(std::string &v_node, const typename G::V_container &n_obj, typename G::V_type::attributes &a_name)
Constructor. 
 
int n_attr
Number of attributes name defined into the vertex. 
 
std::string * attributes_names
Attribute names. 
 
this class is a functor for "for_each" algorithm 
 
std::string get_vertex_properties_list()
It get the vertex properties list. 
 
std::string * attributes_names
Attribute names. 
 
vertex_prop(std::string &v_prop, typename G::V_type::attributes &a_name)
Constructor. 
 
void operator()(T &t)
It call the functor for each member. 
 
void operator()(T &t)
It call the functor for each member. 
 
std::string * attributes_names
Attribute names. 
 
edge_prop(std::string &e_prop, typename G::E_type::attributes &a_name)
Constructor. 
 
this class is a functor for "for_each" algorithm 
 
std::string & v_node
vertex node string 
 
bool to_destroy
indicate if attributes_names is to destroy 
 
G::E_container & vo
Vertex object container. 
 
void end_node()
Close a node. 
 
int cnt
Properties counter. 
 
edge_prop(std::string &e_prop)
Constructor. 
 
std::string get_edge_properties_list()
It get the edge properties list. 
 
bool to_destroy
indicate if attributes_names is to destroy