OSDN Git Service

Merge Tim's fix-x64-warnings-in-bcmenu patch
[winmerge-jp/winmerge-jp.git] / Src / FileFilterMgr.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    License (GPLv2+):
3 //    This program is free software; you can redistribute it and/or modify
4 //    it under the terms of the GNU General Public License as published by
5 //    the Free Software Foundation; either version 2 of the License, or
6 //    (at your option) any later version.
7 //    This program is distributed in the hope that it will be useful, but
8 //    WITHOUT ANY WARRANTY; without even the implied warranty of
9 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 //    General Public License for more details.
11 //    You should have received a copy of the GNU General Public License
12 //    along with this program; if not, write to the Free Software
13 //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
14 /////////////////////////////////////////////////////////////////////////////
15 /**
16  *  @file FileFilterMgr.h
17  *
18  *  @brief Declaration file for FileFilterMgr
19  */ 
20 // ID line follows -- this is updated by SVN
21 // $Id$
22
23 #ifndef FileFilterMgr_h_included
24 #define FileFilterMgr_h_included
25
26 #include <vector>
27 #include "UnicodeString.h"
28 #include "pcre.h"
29
30 struct FileFilterElement;
31 struct FileFilter;
32
33 /**
34  * @brief Return values for many filter functions.
35  */
36 enum FILTER_RETVALUE
37 {
38         FILTER_OK = 0,  /**< Success */
39         FILTER_ERROR_FILEACCESS,  /**< File could not be opened etc. */
40         FILTER_NOTFOUND, /**< Filter not found */
41 };
42
43 /**
44  * @brief File filter manager for handling filefilters.
45  *
46  * The FileFilterMgr loads a collection of named file filters from disk,
47  * and provides lookup access by name, or array access by index, to these
48  * named filters. It also provides test functions for actually using the
49  * filters.
50  *
51  * We are using PCRE for regular expressions. Nice thing in PCRE is it supports
52  * UTF-8 unicode, unlike many other libs. For ANSI builds we use just ansi
53  * strings, and for unicode we must first convert strings to UTF-8.
54  */
55 class FileFilterMgr
56 {
57 private:
58
59 public:
60         ~FileFilterMgr();
61         // Reload filter array from specified directory (passed to CFileFind)
62         void LoadFromDirectory(LPCTSTR dir, LPCTSTR szPattern, LPCTSTR szExt);
63         // Reload an edited filter
64         int ReloadFilterFromDisk(FileFilter * pfilter);
65         int ReloadFilterFromDisk(LPCTSTR szFullPath);
66         // Load a filter from a string
67         void LoadFilterString(LPCTSTR szFilterString);
68         int AddFilter(LPCTSTR szFilterFile);
69         void RemoveFilter(LPCTSTR szFilterFile);
70
71         // access to array of filters
72         int GetFilterCount() const { return (int) m_filters.size(); }
73         String GetFilterName(int i) const;
74         String GetFilterName(const FileFilter *pFilter) const;
75         String GetFilterPath(int i) const;
76         String GetFilterDesc(int i) const;
77         String GetFilterDesc(const FileFilter *pFilter) const;
78         FileFilter * GetFilterByPath(LPCTSTR szFilterName);
79         String GetFullpath(FileFilter * pfilter) const;
80
81         // methods to actually use filter
82         BOOL TestFileNameAgainstFilter(const FileFilter * pFilter, LPCTSTR szFileName) const;
83         BOOL TestDirNameAgainstFilter(const FileFilter * pFilter, LPCTSTR szDirName) const;
84
85         void DeleteAllFilters();
86
87 // Implementation methods
88 protected:
89         // Clear the list of known filters
90         // Load a filter from a file (if syntax is valid)
91         FileFilter * LoadFilterFile(LPCTSTR szFilepath, int & errorcode);
92
93 // Implementation data
94 private:
95         std::vector<FileFilter*> m_filters; /*< List of filters loaded */
96 };
97
98
99 BOOL TestAgainstRegList(const std::vector<FileFilterElement*> *filterList, LPCTSTR szTest);
100 void EmptyFilterList(std::vector<FileFilterElement*> *filterList);
101
102
103 #endif // FileFilterMgr_h_included