r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[ardour.git] / libs / pbd / pbd / pathscanner.h
1 #ifndef __libmisc_pathscanner_h__
2 #define __libmisc_pathscanner_h__
3
4 #include <vector>
5 #include <string>
6 #include <regex.h>
7
8 using std::string;
9 using std::vector;
10
11 class PathScanner
12
13 {
14   public:
15     vector<string *> *operator() (const string &dirpath,
16                                   bool (*filter)(const string &, void *arg),
17                                   void *arg, 
18                                   bool match_fullpath = true,
19                                   bool return_fullpath = true,
20                                   long limit = -1) {
21             return run_scan (dirpath,
22                              (bool (PathScanner::*)(const string &)) 0, 
23                              filter, 
24                              arg,
25                              match_fullpath,
26                              return_fullpath, 
27                              limit);
28     }
29
30     vector<string *> *operator() (const string &dirpath,
31                                   const string &regexp,
32                                   bool match_fullpath = true,
33                                   bool return_fullpath = true,
34                                   long limit = -1);
35
36     
37     string *find_first (const string &dirpath,
38                         const string &regexp,
39                         bool match_fullpath = true,
40                         bool return_fullpath = true);
41
42     string *find_first (const string &dirpath,
43                         bool (*filter)(const string &, void *),
44                         void *arg,
45                         bool match_fullpath = true,
46                         bool return_fullpath = true);
47
48   private:
49     regex_t compiled_pattern;
50     
51     bool regexp_filter (const string &str) {
52             return regexec (&compiled_pattern, str.c_str(), 0, 0, 0) == 0;
53     }
54
55     vector<string *> *run_scan (const string &dirpath,
56                                 bool (PathScanner::*mfilter) (const string &),
57                                 bool (*filter)(const string &, void *),
58                                 void *arg,
59                                 bool match_fullpath,
60                                 bool return_fullpath,
61                                 long limit);
62     
63
64 };
65
66 #endif // __libmisc_pathscanner_h__