GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
diff_filter.h
1 #ifndef DIFF_FILTER_H
2 #define DIFF_FILTER_H
3 
4 #include "graph_filter.h"
5 #include "linkler_diff.h"
6 #include <iostream>
7 #include <string>
8 
15 template<typename GraphType>
16 class DiffFilter : public GraphFilter<GraphType> {
17  public:
18  typedef typename GraphType::node_value_type V_type;
19  typedef typename GraphType::edge_value_type E_type;
20 
24  enum filter_type { ADDED, REMOVED, UNCHANGED };
25 
33  DiffFilter(std::string filter_name,
34  LinklerDiff* ld,
35  filter_type ft)
36  : GraphFilter<GraphType>(filter_name, "diff") {
37  linkler_diff_ = ld;
38  f_type_ = ft;
39  }
40 
47  DiffFilter(std::string filter_name,
48  filter_type ft)
49  : GraphFilter<GraphType>(filter_name,"diff") {
50  linkler_diff_ = NULL;
51  f_type_ = ft;
52  }
53 
59  linkler_diff_ = ld;
60  }
61 
67  f_type_ = ft;
68  }
69 
75  return clone;
76  }
77 
78  virtual bool operator() (E_type e) {
79  return check(e);
80  }
81 
82  virtual bool operator() (V_type v) {
83  return check(v);
84  }
85 
87  virtual bool enabled() const {
88  if(linkler_diff_ == NULL)
89  return false;
90  return this->enabled_;
91  }
92 
94  template<typename P1, typename P2>
95  bool operator() (std::pair<P1, P2>& m) {
96  return operator()(m.second);
97  }
98  std::string type(){
99  switch(f_type_){
100  case ADDED: return "ADDED";
101  case REMOVED: return "REMOVED";
102  case UNCHANGED: return "UNCHANGED";
103  default: return "";
104  }
105  }
106 
107  private:
108  LinklerDiff* linkler_diff_;
109  filter_type f_type_;
110 
117  template<typename T> bool check(T e) {
118  if(this->enabled_) {
119  if (linkler_diff_ == NULL) {
120  // If no linkler diff has been set the filter should not do
121  // anything.
122  // This case is as if the filter is not enabled.
123  return true;
124  }
125 
126  switch (f_type_) {
127  case ADDED:
128  if (!linkler_diff_->added(e) && !this->inverted_) {
129  return false;
130  } else if(linkler_diff_->added(e) && this->inverted_) {
131  return false;
132  }
133  break;
134  case REMOVED:
135  if (!linkler_diff_->removed(e) && !this->inverted_) {
136  return false;
137  } else if(linkler_diff_->removed(e) && this->inverted_) {
138  return false;
139  }
140  break;
141  case UNCHANGED:
142  default:
143  if((linkler_diff_->added(e) || linkler_diff_->removed(e)) && !this->inverted_) {
144  return false;
145  } else if(!linkler_diff_->added(e) && !linkler_diff_->removed(e) && this->inverted_) {
146  return false;
147  }
148  }
149  }
150  return true;
151  }
152 
153 
154 };
155 
156 #endif
virtual GraphFilter< GraphType > * clone()
Definition: diff_filter.h:73
Definition: diff_filter.h:16
DiffFilter(std::string filter_name, filter_type ft)
Definition: diff_filter.h:47
virtual bool operator()(E_type e)
Returns true if the give edgen matches the filter.
Definition: diff_filter.h:78
void set_filter_type(filter_type ft)
Definition: diff_filter.h:66
Forward declarations for functors.
Definition: defines.h:32
filter_type
Definition: diff_filter.h:24
DiffFilter(std::string filter_name, LinklerDiff *ld, filter_type ft)
Definition: diff_filter.h:33
bool added(SWU *swu)
Definition: linkler_diff.cc:250
bool removed(SWU *swu)
Definition: linkler_diff.cc:270
Definition: linkler_diff.h:14
Definition: graph_filter.h:15
Definition: swu.h:27
void set_LinklerDiff(LinklerDiff *ld)
Definition: diff_filter.h:58
virtual bool enabled() const
Overload the enabled method by graph filter to check for the linkler_diff_ being set or not...
Definition: diff_filter.h:87