fix up wscript/build issues in exportvis after merge with master
[ardour.git] / libs / pbd / pbd / pathscanner.h
1 /*
2     Copyright (C) 2000-2007 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __libmisc_pathscanner_h__
21 #define __libmisc_pathscanner_h__
22
23 #include <vector>
24 #include <string>
25 #include <regex.h>
26
27 #include "pbd/libpbd_visibility.h"
28
29 class LIBPBD_API PathScanner
30
31 {
32   public:
33         std::vector<std::string *> *operator() (const std::string &dirpath,
34                                                 bool (*filter)(const std::string &, void *arg),
35                                                 void *arg, 
36                                                 bool match_fullpath = true,
37                                                 bool return_fullpath = true,
38                                                 long limit = -1,
39                                                 bool recurse = false) {
40                 return run_scan (dirpath,
41                                  (bool (PathScanner::*)(const std::string &)) 0, 
42                                  filter, 
43                                  arg,
44                                  match_fullpath,
45                                  return_fullpath, 
46                                  limit, recurse);
47         }
48
49         std::vector<std::string *> *operator() (const std::string &dirpath,
50                                                 const std::string &regexp,
51                                                 bool match_fullpath = true,
52                                                 bool return_fullpath = true,
53                                                 long limit = -1,
54                                                 bool recurse = false);
55         
56         std::string *find_first (const std::string &dirpath,
57                                  const std::string &regexp,
58                                  bool match_fullpath = true,
59                                  bool return_fullpath = true);
60         
61         std::string *find_first (const std::string &dirpath,
62                                  bool (*filter)(const std::string &, void *),
63                                  void *arg,
64                                  bool match_fullpath = true,
65                                  bool return_fullpath = true);
66         
67   private:
68         regex_t compiled_pattern;
69         
70         bool regexp_filter (const std::string &str) {
71                 return regexec (&compiled_pattern, str.c_str(), 0, 0, 0) == 0;
72         }
73         
74         std::vector<std::string *> *run_scan (const std::string &dirpath,
75                                               bool (PathScanner::*mfilter) (const std::string &),
76                                               bool (*filter)(const std::string &, void *),
77                                               void *arg,
78                                               bool match_fullpath,
79                                               bool return_fullpath,
80                                               long limit,
81                                               bool recurse = false);
82
83         std::vector<std::string *> *run_scan_internal (std::vector<std::string*>*, 
84                                                        const std::string &dirpath,
85                                                        bool (PathScanner::*mfilter) (const std::string &),
86                                                        bool (*filter)(const std::string &, void *),
87                                                        void *arg,
88                                                        bool match_fullpath,
89                                                        bool return_fullpath,
90                                                        long limit,
91                                                        bool recurse = false);
92 };
93
94 #endif // __libmisc_pathscanner_h__