GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
regex_filter.h
1 #ifndef REGEX_FILTER_H_
2 #define REGEX_FILTER_H_
3 
4 #include "graph_filter.h"
5 #include <string>
6 #include <regex.h>
7 
22 template<typename GraphType>
23 class RegexFilter : public GraphFilter<GraphType> {
24  private:
25  std::string regex_pattern_;
26 
27  public:
28  typedef typename GraphType::node_value_type V_type;
29  typedef typename GraphType::edge_value_type E_type;
30 
31  RegexFilter( std::string pattern ) :
32  GraphFilter<GraphType>("", "regex", false, true, true, false) {
33  regex_pattern_ = pattern;
34  }
35 
36  RegexFilter( std::string filter_name, std::string pattern ) :
37  GraphFilter<GraphType>(filter_name, "regex", false, true, true, false) {
38  regex_pattern_ = pattern;
39  }
40 
44  return clone;
45  }
46 
48  virtual bool operator() (E_type edge) {
49  return !this->inverted_;
50  }
51 
54  virtual bool operator() (V_type m) {
55  if(this->enabled_){
56  int status;
57  regex_t re;
58 
59  // Regex compile
60  // Sets pattern as empty string if failed to compile.
61  if(regcomp(&re, regex_pattern_.c_str(), REG_EXTENDED) != 0) {
62  regcomp(&re,"", REG_EXTENDED);
63  }
64 
65  // Status, 0 if match, 1 if not matched
66  status = regexec(&re, m->name().c_str(), 0, 0, 0);
67  regfree(&re); // free mem alocation made by regex compile
68 
69  if (status != 0 && !this->inverted_) { // If no match with pattern
70  return false;
71  } else if(status == 0 && this->inverted_) { // If match
72  return false;
73  }
74  }
75  return true;
76  }
77 
79  template<typename P1, typename P2>
80  bool operator() (std::pair<P1, P2>& m) {
81  return operator()(m.second);
82  }
83 
84  std::string pattern() {
85  return regex_pattern_;
86  }
87 };
88 
89 #endif
Definition: regex_filter.h:23
virtual bool operator()(E_type edge)
Ignores edges - no action.
Definition: regex_filter.h:48
Forward declarations for functors.
Definition: defines.h:32
std::string name() const
Accessor for name.
Definition: swu.cc:151
Definition: graph_filter.h:15
Definition: swu.h:27
virtual GraphFilter< GraphType > * clone()
Clone operation.
Definition: regex_filter.h:42