GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
dependency_degree_filter.h
1 #ifndef DEPENDENCY_DEGREE_FILTER_H_
2 #define DEPENDENCY_DEGREE_FILTER_H_
3 
4 #include <string>
5 #include <iostream>
6 #include "graph_filter.h"
7 
16 template<typename GraphType>
17 class DependencyDegreeFilter : public GraphFilter<GraphType> {
18 public:
19  typedef typename GraphType::node_value_type V_type;
20  typedef typename GraphType::edge_value_type E_type;
21  typedef typename GraphType::index_type_t index_type_t;
22 
31  DependencyDegreeFilter(std::string filter_name,
32  int min_degree,
33  int max_degree,
34  bool dependents = true,
35  bool dependencies = true) :
36  GraphFilter<GraphType>(filter_name, "dependency_degree", false, true, true, false) {
37  min_degree_ = min_degree;
38  max_degree_ = max_degree;
39  dependents_ = dependents;
40  dependencies_ = dependencies;
41  }
42 
51  int max_degree,
52  bool dependents = true,
53  bool dependencies = true) :
54  GraphFilter<GraphType>("", "dependency_degree", false, true, true, false) {
55  min_degree_ = min_degree;
56  max_degree_ = max_degree;
57  dependents_ = dependents;
58  dependencies_ = dependencies;
59  }
60 
66  return clone;
67  }
68 
72  virtual bool operator() (E_type edge) {
73  (void)edge;
74  return !(this->inverted_);
75  }
76 
82  virtual bool operator() (V_type m) {
83  if(this->enabled_) {
84  bool include = false;
85 
86  unsigned int degree = 0;
87  if(dependencies_)
88  degree += m->dependencies()->size();
89  if(dependents_)
90  degree += m->dependents()->size();
91 
92  // if the degree falls in the range include it
93  if(min_degree_ < 0 || degree >= static_cast<unsigned int>(min_degree_)) {
94  if(max_degree_ < 0 || degree <= static_cast<unsigned int>(max_degree_)) {
95  include = true;
96  }
97  }
98 
99  if(!include && !this->inverted_)
100  return false;
101  if(include && this->inverted_)
102  return false;
103  }
104  return true;
105  }
106 
112  dependents_ = dependents;
113  }
114 
120  dependencies_ = dependencies;
121  }
122 
126  template<typename P1, typename P2>
127  bool operator() (std::pair<P1, P2>& m) {
128  return operator()(m.second);
129  }
130 
134  int min_degree() {
135  return min_degree_;
136  }
137 
141  int max_degree() {
142  return max_degree_;
143  }
144 
148  bool dependents() {
149  return dependents_;
150  }
151 
155  bool dependencies() {
156  return dependencies_;
157  }
158 
159 private:
161  int min_degree_;
163  int max_degree_;
165  bool dependents_;
167  bool dependencies_;
168 };
169 
170 #endif
DependencyDegreeFilter(int min_degree, int max_degree, bool dependents=true, bool dependencies=true)
Definition: dependency_degree_filter.h:50
void set_dependents(bool dependents)
Definition: dependency_degree_filter.h:111
Forward declarations for functors.
Definition: defines.h:32
int min_degree()
Definition: dependency_degree_filter.h:134
void set_dependencies(bool dependencies)
Definition: dependency_degree_filter.h:119
SwuDependencySet * dependencies()
Accessor for the set of dependencies.
Definition: swu.cc:143
SwuDependentSet * dependents()
Accessor for the set of dependents.
Definition: swu.cc:147
Definition: graph_filter.h:15
bool dependents()
Definition: dependency_degree_filter.h:148
Definition: swu.h:27
DependencyDegreeFilter(std::string filter_name, int min_degree, int max_degree, bool dependents=true, bool dependencies=true)
Definition: dependency_degree_filter.h:31
bool dependencies()
Definition: dependency_degree_filter.h:155
Definition: dependency_degree_filter.h:17
virtual GraphFilter< GraphType > * clone()
Definition: dependency_degree_filter.h:64
unsigned int index_type_t
The type of index used for the nodes in the graph.
Definition: grapher.h:52
virtual bool operator()(E_type edge)
Definition: dependency_degree_filter.h:72
int max_degree()
Definition: dependency_degree_filter.h:141