Upstream | cc2ee17 | 1970-01-12 13:46:40 +0000 | [diff] [blame^] | 1 | /** |
| 2 | * @file string_filter.h |
| 3 | * Filter strings based on 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 STRING_FILTER_H |
| 13 | #define STRING_FILTER_H |
| 14 | |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | /** |
| 19 | * string_filter - filtering of a string based on include/exclude list |
| 20 | * |
| 21 | * This class is an oracle on whether a particular string matches |
| 22 | * the given list of included and excluded strings. |
| 23 | * |
| 24 | * This base class gives a default exact-match semantics. |
| 25 | */ |
| 26 | class string_filter { |
| 27 | public: |
| 28 | string_filter() {} |
| 29 | |
| 30 | /** |
| 31 | * Initialise the filter with the include and exclude list, |
| 32 | * comma-separated. |
| 33 | */ |
| 34 | string_filter(std::string const & include_patterns, |
| 35 | std::string const & exclude_patterns); |
| 36 | |
| 37 | /** |
| 38 | * Initialise the filter with the include and exclude list. |
| 39 | */ |
| 40 | string_filter(std::vector<std::string> const & include_patterns, |
| 41 | std::vector<std::string> const & exclude_patterns); |
| 42 | |
| 43 | virtual ~string_filter() {} |
| 44 | |
| 45 | /// Returns true if the given string matches |
| 46 | virtual bool match(std::string const & str) const; |
| 47 | |
| 48 | protected: |
| 49 | /// include patterns |
| 50 | std::vector<std::string> include; |
| 51 | /// exclude patterns |
| 52 | std::vector<std::string> exclude; |
| 53 | }; |
| 54 | |
| 55 | #endif /* STRING_FILTER_H */ |