GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
set_property_action.h
1 #ifndef SET_PROPERTY_ACTION_
2 #define SET_PROPERTY_ACTION_
3 
4 #include <string>
5 
6 #include "graph_filter.h"
7 #include "graph_action.h"
8 #include "graph_properties.h"
9 
15 template<typename GraphType>
16 class SetPropertyAction : public GraphAction<GraphType> {
17  public:
18  typedef typename GraphType::node_value_type V_type;
19  typedef typename GraphType::edge_value_type E_type;
20  typedef typename GraphType::index_type_t index_type_t;
21  typedef std::map<std::string, std::string> PropertyMap;
22  typedef PropertyMap::iterator iterator;
23  typedef PropertyMap::const_iterator const_iterator;
24 
31  GraphFilter<GraphType>* property_filter) :
32  GraphAction<GraphType>(property_filter),
33  properties_(properties)
34  {
35  }
36 
39  GraphAction<GraphType>(copy), properties_(copy.properties_), property_values_(copy.property_values_) {
40  }
41 
46  virtual bool operator() (E_type edge) {
47  if (this->filter_->enabled() && this->filter_->edges()) {
48  if (this->run_filter(edge)) {
49  for (iterator it = begin(); it != end(); ++it) {
50  properties_.set_property(edge, it->first, it->second);
51  }
52  }
53  }
54 
55  return true;
56  }
57 
62  virtual bool operator() (V_type m) {
63  if(this->filter_->enabled() && this->filter_->nodes())
64  if(this->run_filter(m))
65  for(iterator it = begin(); it != end(); ++it)
66  properties_.set_property(m, it->first, it->second);
67 
68  return true;
69  }
70 
72  template<typename P1, typename P2>
73  bool operator() (std::pair<P1, P2>& m) {
74  return operator()(m.second);
75  }
76 
78  iterator begin() { return property_values_.begin(); }
79 
81  iterator end() { return property_values_.end(); }
82 
84  void set_property(std::string name, std::string value) {
85  property_values_[name] = value;
86  }
87 
90  std::string get_property(std::string name) {
91  return property_values_[name];
92  }
93 
94  private:
95  GraphProperties<GraphType>& properties_;
96  PropertyMap property_values_;
97 };
98 
99 #endif
virtual bool operator()(E_type edge)
Definition: set_property_action.h:46
SetPropertyAction(SetPropertyAction &copy)
Copy constructor.
Definition: set_property_action.h:38
Forward declarations for functors.
Definition: defines.h:32
void set_property(std::string name, std::string value)
Sets a specific property to be set when finding nodes matching the filter.
Definition: set_property_action.h:84
iterator begin()
Returns an iterator to the beginning of a map of property name/values.
Definition: set_property_action.h:78
Definition: graph_action.h:13
SetPropertyAction(GraphProperties< GraphType > &properties, GraphFilter< GraphType > *property_filter)
Definition: set_property_action.h:30
Definition: graph_filter.h:15
Definition: graph_properties.h:7
Definition: swu.h:27
bool run_filter(P arg)
Definition: graph_action.h:70
iterator end()
Returns an iterator to the end of a map of property name/values.
Definition: set_property_action.h:81
std::string get_property(std::string name)
Definition: set_property_action.h:90
GraphFilter< GraphType > * filter_
The filter is used to indicate whether the action should be taken or not.
Definition: graph_action.h:79
unsigned int index_type_t
The type of index used for the nodes in the graph.
Definition: grapher.h:52
Definition: set_property_action.h:16