GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
graph_properties.h
1 #ifndef GRAPH_PROPERTIES_H_
2 #define GRAPH_PROPERTIES_H_
3 
4 #include "grapher.h"
5 
6 template<typename GraphType>
8  public:
9  typedef typename GraphType::node_value_type V_type;
10  typedef typename GraphType::edge_value_type E_type;
11  typedef typename GraphType::index_type_t index_type_t;
12  typedef typename GraphType::property_map_t property_map_t;
13  typedef typename GraphType::node_property_map_t node_property_map_t;
14  typedef typename GraphType::edge_property_map_t edge_property_map_t;
15 
16  ~GraphProperties() {
17  // delete every map in node property map
18  typename node_property_map_t::iterator it = node_property_map_.begin();
19  for (; it != node_property_map_.end(); it++) {
20  delete it->second;
21  }
22 
23  // delete every map in edge property map
24  typename edge_property_map_t::iterator edge_it = edge_property_map_.begin();
25  for (; edge_it != edge_property_map_.end(); edge_it++) {
26  delete edge_it->second;
27  }
28  }
29 
36  void set_property(V_type node, std::string property, std::string value) {
37  typename node_property_map_t::iterator it = node_property_map_.find(node);
38 
39  property_map_t* n = 0;
40  if (it != node_property_map_.end()) {
41  n = it->second;
42  } else {
43  n = new property_map_t();
44  node_property_map_.insert(node_property_map_.end(), std::make_pair(node, n));
45  }
46  (*n)[property] = value;
47  }
48 
55  void set_property(E_type edge, std::string property, std::string value) {
56  typename edge_property_map_t::iterator it = edge_property_map_.find(edge);
57 
58  property_map_t* prop_map = 0;
59  if (it != edge_property_map_.end()) {
60  prop_map = it->second;
61 
62  } else {
63  prop_map = new property_map_t();
64  edge_property_map_.insert(edge_property_map_.end(), std::make_pair(edge, prop_map));
65 
66  (*prop_map)[property] = value;
67  }
68  }
69 
74  std::string get_property(V_type node, std::string property) {
75  typename node_property_map_t::iterator it = node_property_map_.find(node);
76 
77  if (it != node_property_map_.end()) {
78  property_map_t property_map = *node_property_map_[node];
79 
80  typename property_map_t::iterator it2 = property_map.find(property);
81 
82  if (it2 != property_map.end()) {
83  return property_map[property];
84  }
85  }
86 
87  return "";
88  }
89 
94  std::string get_property(E_type edge, std::string property) {
95  typename edge_property_map_t::iterator it = edge_property_map_.find(edge);
96 
97  if (it != edge_property_map_.end()) {
98  property_map_t property_map = *edge_property_map_[edge];
99 
100  typename property_map_t::iterator it2 = property_map.find(property);
101 
102  if (it2 != property_map.end()) {
103  return property_map[property];
104  }
105  }
106 
107  return "";
108  }
109 
113  property_map_t* get_all_properties(V_type node) {
114  typename node_property_map_t::iterator it = node_property_map_.find(node);
115 
116  if (it != node_property_map_.end()) {
117  return node_property_map_[node];
118  }
119 
120  return NULL;
121  }
122 
126  property_map_t* get_all_properties(E_type edge) {
127  typename edge_property_map_t::iterator it = edge_property_map_.find(edge);
128 
129  if (it != edge_property_map_.end()) {
130  return edge_property_map_[edge];
131  }
132 
133  return NULL;
134  }
135 
137  void clear() {
138  typename node_property_map_t::iterator it = node_property_map_.begin();
139  for (; it != node_property_map_.end(); it++) {
140  delete it->second;
141  }
142  node_property_map_.clear();
143 
144  typename edge_property_map_t::iterator edge_it = edge_property_map_.begin();
145 
146  for (; edge_it != edge_property_map_.end(); edge_it++) {
147  delete edge_it->second;
148  }
149  edge_property_map_.clear();
150  }
151 
152  private:
154  node_property_map_t node_property_map_;
155 
157  edge_property_map_t edge_property_map_;
158 
159 };
160 
161 #endif
property_map_t * get_all_properties(E_type edge)
Definition: graph_properties.h:126
std::string get_property(E_type edge, std::string property)
Definition: graph_properties.h:94
void set_property(V_type node, std::string property, std::string value)
Definition: graph_properties.h:36
property_map_t * get_all_properties(V_type node)
Definition: graph_properties.h:113
Forward declarations for functors.
Definition: defines.h:32
void set_property(E_type edge, std::string property, std::string value)
Definition: graph_properties.h:55
void clear()
Clear all properties for both nodes and edges.
Definition: graph_properties.h:137
std::string get_property(V_type node, std::string property)
Definition: graph_properties.h:74
Definition: graph_properties.h:7
Definition: swu.h:27
std::map< E_type, property_map_t *, E_CompareFunctor > edge_property_map_t
Type used to map an edge type to its propertymap.
Definition: grapher.h:86
std::map< V_type, property_map_t *, V_CompareFunctor > node_property_map_t
Type used to map a node type to its propertymap.
Definition: grapher.h:83
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
unsigned int index_type_t
The type of index used for the nodes in the graph.
Definition: grapher.h:52