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 #ifdef HAVE_EXT_HASH_MAP_SET
00036 #include <ext/hash_set>
00037 #if defined(__GNUC__) && __GNUC__ > 2
00038 using __gnu_cxx::hash_set;
00039 #endif
00040 #else
00041 #include <hash_set>
00042 # ifdef _MSC_VER
00043 using stdext::hash_set;
00044 # else
00045 using std::hash_set;
00046 # endif
00047 #endif
00048
00049
00050 #include "text/strings.h"
00051
00052 using namespace IXE::Text;
00053
00054 namespace IXE {
00055
00068
00069
00070 class PatternSet : public hash_set<char const*>
00071 {
00072 public:
00073 typedef hash_set<char const*> Set;
00074 typedef Set::key_type key_type;
00075 typedef Set::value_type value_type;
00076 typedef Set::iterator iterator;
00077 typedef Set::const_iterator const_iterator;
00078
00079
00080
00081
00082 iterator find(char const* file_name) {
00083 return std::find_if(begin(), end(), pattern_match(file_name));
00084 }
00085 const_iterator find(char const* file_name) const {
00086 return std::find_if(begin(), end(), pattern_match(file_name));
00087 }
00088
00089 bool matches(char const* file_name) const {
00090 return find(file_name) != end();
00091 }
00092
00093 void insert(value_type const& n) { Set::insert(::strdup(n)); }
00094
00095 void insert(value_type const& s, size_t n) { Set::insert(strndup(s, n)); }
00096
00097 private:
00098 class pattern_match : public
00099 std::unary_function<value_type const&, bool> {
00100 public:
00101 pattern_match(char const* file_name) :
00102 file_name(file_name) { }
00103 bool operator ()(value_type const& pattern) const {
00104 return !::fnmatch(pattern, file_name, 0);
00105 }
00106 private:
00107 char const* const file_name;
00108 };
00109 };
00110
00111 }
00112
00113 #endif