00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef IXE_PatternSet_H
00026 #define IXE_PatternSet_H
00027
00028
00029 #include "platform.h"
00030
00031
00032 #include <algorithm>
00033 #include <fnmatch.h>
00034
00035
00036 #include "include/unordered_set.h"
00037 #include "text/strings.h"
00038
00039 using namespace IXE::Text;
00040
00041 namespace IXE {
00042
00055
00056
00057 class PatternSet : public unordered_set<char const*>
00058 {
00059 public:
00060 typedef unordered_set<char const*> Set;
00061 typedef Set::key_type key_type;
00062 typedef Set::value_type value_type;
00063 typedef Set::iterator iterator;
00064 typedef Set::const_iterator const_iterator;
00065
00066
00067
00068
00069 iterator find(char const* file_name) {
00070 return std::find_if(begin(), end(), pattern_match(file_name));
00071 }
00072 const_iterator find(char const* file_name) const {
00073 return std::find_if(begin(), end(), pattern_match(file_name));
00074 }
00075
00076 bool matches(char const* file_name) const {
00077 return find(file_name) != end();
00078 }
00079
00080 void insert(value_type const& n) { Set::insert(::strdup(n)); }
00081
00082 void insert(value_type const& s, size_t n) { Set::insert(strndup(s, n)); }
00083
00084 private:
00085 class pattern_match : public
00086 std::unary_function<value_type const&, bool> {
00087 public:
00088 pattern_match(char const* file_name) :
00089 file_name(file_name) { }
00090 bool operator ()(value_type const& pattern) const {
00091 return !::fnmatch(pattern, file_name, 0);
00092 }
00093 private:
00094 char const* const file_name;
00095 };
00096 };
00097
00098 }
00099
00100 #endif