• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file glob_filter.h
3  * Filter strings based on globbed exclude/include list
4  *
5  * @remark Copyright 2002 OProfile authors
6  * @remark Read the file COPYING
7  *
8  * @author Philippe Elie
9  * @author John Levon
10  */
11 
12 #ifndef GLOB_FILTER_H
13 #define GLOB_FILTER_H
14 
15 #include "string_filter.h"
16 
17 /**
18  * glob_filter - filtering of a string based on globbed include/exclude list
19  *
20  * This class is an oracle on whether a particular string matches
21  * the given list of included and excluded strings.
22  *
23  * This class gives glob-based matches on each pattern, as with fnmatch(3)
24  */
25 class glob_filter : public string_filter {
26 public:
27 	/**
28 	 * Initialise the filter with the include and exclude list,
29 	 * comma-separated.
30 	 */
glob_filter(std::string const & include_patterns,std::string const & exclude_patterns)31 	glob_filter(std::string const & include_patterns,
32 	            std::string const & exclude_patterns)
33 		: string_filter(include_patterns, exclude_patterns) {}
34 
35 	/**
36 	 * Initialise the filter with the include and exclude list.
37 	 */
glob_filter(std::vector<std::string> const & include_patterns,std::vector<std::string> const & exclude_patterns)38 	glob_filter(std::vector<std::string> const & include_patterns,
39 	            std::vector<std::string> const & exclude_patterns)
40 		: string_filter(include_patterns, exclude_patterns) {}
41 
42 	/// Returns true if the given string matches
43 	virtual bool match(std::string const & str) const;
44 
45 protected:
46 
47 	/// function object for fnmatching
48 	struct fnmatcher {
fnmatcherfnmatcher49 		fnmatcher(std::string const & str) : str_(str) {}
50 
51 		bool operator()(std::string const & s);
52 
53 		std::string const & str_;
54 	};
55 };
56 
57 #endif /* GLOB_FILTER_H */
58