GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
graph_exporter.h
1 #ifndef GRAPH_EXPORTER_
2 #define GRAPH_EXPORTER_
3 
4 #include <iostream>
5 #include <fstream>
6 
7 #include "grapher.h"
8 
9 
17 template< typename GraphType >
19  private:
20  std::ostream& out;
21  GraphType& g_;
22 
23  public:
24 
25  GraphExporter(std::ostream& stream, GraphType& g) : out(stream), g_(g) {
26  }
27 
29  void write_graphml(GraphProperties<GraphType>* extra_properties = 0){
30  out << "graphml output not implemented" << std::endl;
31  }
32 
35  void write_graphviz(GraphProperties<GraphType>* extra_properties = 0) {
36  out << "digraph G {" << std::endl;
37 
38  typename GraphType::node_iterator node = g_.node_begin();
39 
40  for(unsigned int i = 0; node != g_.node_end(); ++node, ++i) {
41  // Print each node
42  out << node->first+1 << " [label=" << node->second->name();
43 
44  // Print dependencies and dependents
45  out << ", dependencies=" << node->second->dependencies()->size() << ", dependents=" << node->second->dependents()->size();
46 
47  // Print out all properties
48  typename GraphType::property_map_t* properties = g_.properties().get_all_properties(node->second);
49  if(properties != NULL) {
50  typename GraphType::property_map_t::iterator it;
51  for(it = properties->begin(); it != properties->end(); it++) {
52  out << "," << it->first << "=" << it->second;
53  }
54  }
55 
56  if(extra_properties != 0) {
57  properties = extra_properties->get_all_properties(node->second);
58  if(properties != NULL) {
59  typename GraphType::property_map_t::iterator it;
60  for(it = properties->begin(); it != properties->end(); it++) {
61  out << "," << it->first << "=" << it->second;
62  }
63  }
64  }
65 
66  // Print the x,y position
67  if(g_.has_layout())
68  out << ", x=" << g_.position(node->second).first << ", y=" << g_.position(node->second).second;
69 
70  // End the line
71  out << "];" << std::endl;
72  }
73 
74  typename GraphType::edge_iterator eit;
75 
76  for(eit = g_.edge_begin(); eit != g_.edge_end(); ++eit) {
77  out << eit->first.first+1 << "->" << eit->first.second+1
78  << " [label=" << (eit->second->absolute() ? "absolute" : "relative") << "];"
79  << std::endl;
80  // TODO: add more edge properties here
81  }
82 
83  out << "}" << std::endl;
84  }
85 
87  void write_csv() {
88  out << "Unfortunately CSV export not implemented yet." << std::endl;
89  }
90 };
91 
92 #endif
void write_csv()
Export to CSV.
Definition: graph_exporter.h:87
void write_graphml(GraphProperties< GraphType > *extra_properties=0)
Write graphml output of the generated graph to the given stream.
Definition: graph_exporter.h:29
GraphProperties< GraphType > & properties()
Fetch the properties.
Definition: grapher.h:155
Definition: graph_exporter.h:18
position_map_t::value_type position(const V_type v)
Fetches the position in a std::pair<int, int> of a specific vertex data.
Definition: grapher.h:173
node_data_t::iterator node_iterator
Type used to iterate over nodes.
Definition: grapher.h:89
void write_graphviz(GraphProperties< GraphType > *extra_properties=0)
Definition: graph_exporter.h:35
Definition: graph_properties.h:7
std::map< std::string, std::string > property_map_t
Type used to map a property (as string) to a value (as string)
Definition: grapher.h:80
bool has_layout()
Returns true if there is a layout.
Definition: grapher.h:150
edge_map_t::iterator edge_iterator
Type used to iterate over edges.
Definition: grapher.h:95