OSDN Git Service

Remove unused declarations
[winmerge-jp/winmerge-jp.git] / Src / FileFilterMgr.h
index 0d945fd..88d1b35 100644 (file)
@@ -1,39 +1,36 @@
-/////////////////////////////////////////////////////////////////////////////
-// FileFilterMgr.h : declaration file
-//
-// The FileFilterMgr loads a collection of named file filters from disk,
-// and provides lookup access by name, or array access by index, to these
-// named filters. It also provides test functions for actually using the filters.
-/////////////////////////////////////////////////////////////////////////////
-//    License (GPLv2+):
-//    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
-//    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-//    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-/////////////////////////////////////////////////////////////////////////////
+// SPDX-License-Identifier: GPL-2.0-or-later
 /**
  *  @file FileFilterMgr.h
  *
  *  @brief Declaration file for FileFilterMgr
  */ 
-// RCS ID line follows -- this is updated by CVS
-// $Id$
+#pragma once
 
-#ifndef FileFilter_h_included
-#define FileFilter_h_included
+#include <vector>
+#include "UnicodeString.h"
+#include "FileFilter.h"
 
-// Uses MFC C++ template containers
-#ifndef __AFXTEMPL_H__
-#include <afxtempl.h>
-#endif
-
-struct FileFilter;
+/**
+ * @brief Return values for many filter functions.
+ */
+enum FILTER_RETVALUE
+{
+       FILTER_OK = 0,  /**< Success */
+       FILTER_ERROR_FILEACCESS,  /**< File could not be opened etc. */
+       FILTER_NOTFOUND, /**< Filter not found */
+};
 
 /**
  * @brief File filter manager for handling filefilters.
  *
  * The FileFilterMgr loads a collection of named file filters from disk,
  * and provides lookup access by name, or array access by index, to these
- * named filters. It also provides test functions for actually using the filters.
+ * named filters. It also provides test functions for actually using the
+ * filters.
+ *
+ * We are using PCRE for regular expressions. Nice thing in PCRE is it supports
+ * UTF-8 unicode, unlike many other libs. For ANSI builds we use just ansi
+ * strings, and for unicode we must first convert strings to UTF-8.
  */
 class FileFilterMgr
 {
@@ -42,47 +39,105 @@ private:
 public:
        ~FileFilterMgr();
        // Reload filter array from specified directory (passed to CFileFind)
-       void LoadFromDirectory(LPCTSTR szPattern, LPCTSTR szExt);
+       void LoadFromDirectory(const String& dir, const String& szPattern, const String& szExt);
        // Reload an edited filter
-       void ReloadFilterFromDisk(FileFilter * pfilter);
-       void ReloadFilterFromDisk(LPCTSTR szFullPath);
-       // Load a filter from a string
-       void LoadFilterString(LPCTSTR szFilterString);
+       int ReloadFilterFromDisk(FileFilter * pfilter);
+       int ReloadFilterFromDisk(const String& szFullPath);
+       int AddFilter(const String& szFilterFile);
+       void RemoveFilter(const String& szFilterFile);
 
        // access to array of filters
-       int GetFilterCount() const { return m_filters.GetSize(); }
-       CString GetFilterName(int i) const;
-       CString GetFilterPath(int i) const;
-       CString GetFilterDesc(int i) const;
-       FileFilter * GetFilterByPath(LPCTSTR szFilterName);
-       CString GetFullpath(FileFilter * pfilter) const;
+       int GetFilterCount() const { return (int) m_filters.size(); }
+       String GetFilterName(int i) const;
+       String GetFilterName(const FileFilter *pFilter) const;
+       String GetFilterPath(int i) const;
+       String GetFilterDesc(int i) const;
+       String GetFilterDesc(const FileFilter *pFilter) const;
+       FileFilter * GetFilterByPath(const String& szFilterName);
+       FileFilter * GetFilterByIndex(int i);
+       String GetFullpath(FileFilter * pfilter) const;
 
        // methods to actually use filter
-       BOOL TestFileNameAgainstFilter(FileFilter * pFilter, LPCTSTR szFileName);
-       BOOL TestDirNameAgainstFilter(FileFilter * pFilter, LPCTSTR szDirName);
+       bool TestFileNameAgainstFilter(const FileFilter * pFilter, const String& szFileName) const;
+       bool TestDirNameAgainstFilter(const FileFilter * pFilter, const String& szDirName) const;
 
+       void DeleteAllFilters();
+       void CloneFrom(const FileFilterMgr* fileFilterMgr);
 
 // Implementation methods
 protected:
        // Clear the list of known filters
-       void DeleteAllFilters();
        // Load a filter from a file (if syntax is valid)
-       FileFilter * LoadFilterFile(LPCTSTR szFilepath, LPCTSTR szFilename);
+       FileFilter * LoadFilterFile(const String& szFilepath, int & errorcode);
 
 // Implementation data
 private:
-       CTypedPtrArray<CPtrArray, FileFilter *> m_filters;
+       std::vector<FileFilterPtr> m_filters; /*< List of filters loaded */
 };
 
 
-// I think that CRegExp doesn't copy correctly (I get heap corruption in CRegList::program)
-// so I'm using pointers to avoid its copy constructor
-// Perry, 2003-05-18
+bool TestAgainstRegList(const std::vector<FileFilterElementPtr> *filterList, const String& szTest);
 
-class CRegExp;
-typedef CTypedPtrList<CPtrList, CRegExp*>RegList;
-BOOL TestAgainstRegList(const RegList & reglist, LPCTSTR szTest);
-void DeleteRegList(RegList & reglist);
+/**
+ * @brief Return name of filter.
+ *
+ * @param [in] i Index of filter.
+ * @return Name of filter in given index.
+ */
+inline String FileFilterMgr::GetFilterName(int i) const
+{
+       return m_filters[i]->name; 
+}
 
+/**
+ * @brief Return name of filter.
+ * @param [in] pFilter Filter to get name for.
+ * @return Given filter's name.
+ */
+inline String FileFilterMgr::GetFilterName(const FileFilter *pFilter) const
+{
+       return pFilter->name; 
+}
 
-#endif // FileFilter_h_included
+/**
+ * @brief Return description of filter.
+ *
+ * @param [in] i Index of filter.
+ * @return Description of filter in given index.
+ */
+inline String FileFilterMgr::GetFilterDesc(int i) const
+{
+       return m_filters[i]->description; 
+}
+
+/**
+ * @brief Return description of filter.
+ * @param [in] pFilter Filter to get description for.
+ * @return Given filter's description.
+ */
+inline String FileFilterMgr::GetFilterDesc(const FileFilter *pFilter) const
+{
+       return pFilter->description;
+}
+
+/**
+ * @brief Return full path to filter.
+ *
+ * @param [in] i Index of filter.
+ * @return Full path of filter in given index.
+ */
+inline String FileFilterMgr::GetFilterPath(int i) const
+{
+       return m_filters[i]->fullpath;
+}
+
+/**
+ * @brief Return full path to filter.
+ *
+ * @param [in] pFilter Pointer to filter.
+ * @return Full path of filter.
+ */
+inline String FileFilterMgr::GetFullpath(FileFilter * pfilter) const
+{
+       return pfilter->fullpath;
+}