Glob.hxx.in 3.8 KB
Newer Older
Andy Cedilnik's avatar
Andy Cedilnik committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*=========================================================================

  Program:   KWSys - Kitware System Library
  Module:    Glob.hxx.in

  Copyright (c) Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_Glob_hxx
#define @KWSYS_NAMESPACE@_Glob_hxx

17 18 19
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <@KWSYS_NAMESPACE@/Configure.hxx>

Andy Cedilnik's avatar
Andy Cedilnik committed
20 21 22
#include <@KWSYS_NAMESPACE@/stl/string>
#include <@KWSYS_NAMESPACE@/stl/vector>

23 24 25 26
/* Define this macro temporarily to keep the code readable.  */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl
#endif
Andy Cedilnik's avatar
Andy Cedilnik committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

namespace @KWSYS_NAMESPACE@
{

class GlobInternals;

/** \class Glob
 * \brief Portable globbing searches.
 *
 * Globbing expressions are much simpler than regular
 * expressions. This class will search for files using
 * globbing expressions.
 *
 * Finds all files that match a given globbing expression.
 */
class @KWSYS_NAMESPACE@_EXPORT Glob
{
public:
  Glob();
  ~Glob();

  //! Find all files that match the pattern.
49
  bool FindFiles(const kwsys_stl::string& inexpr);
Andy Cedilnik's avatar
Andy Cedilnik committed
50 51

  //! Return the list of files that matched.
52
  kwsys_stl::vector<kwsys_stl::string>& GetFiles();
Andy Cedilnik's avatar
Andy Cedilnik committed
53 54 55 56

  //! Set recurse to true to match subdirectories.
  void RecurseOn() { this->SetRecurse(true); }
  void RecurseOff() { this->SetRecurse(false); }
57 58 59
  void SetRecurse(bool i) { this->Recurse = i; }
  bool GetRecurse() { return this->Recurse; }

60 61 62 63 64 65 66
  //! Set recurse through symlinks to true if recursion should traverse the
  // linked-to directories
  void RecurseThroughSymlinksOn() { this->SetRecurseThroughSymlinks(true); }
  void RecurseThroughSymlinksOff() { this->SetRecurseThroughSymlinks(false); }
  void SetRecurseThroughSymlinks(bool i) { this->RecurseThroughSymlinks = i; }
  bool GetRecurseThroughSymlinks() { return this->RecurseThroughSymlinks; }

67 68 69
  //! Set relative to true to only show relative path to files.
  void SetRelative(const char* dir);
  const char* GetRelative();
Andy Cedilnik's avatar
Andy Cedilnik committed
70

71 72 73 74 75 76 77 78 79 80
  /** Convert the given globbing pattern to a regular expression.
      There is no way to quote meta-characters.  The
      require_whole_string argument specifies whether the regex is
      automatically surrounded by "^" and "$" to match the whole
      string.  This is on by default because patterns always match
      whole strings, but may be disabled to support concatenating
      expressions more easily (regex1|regex2|etc).  */
  static kwsys_stl::string PatternToRegex(const kwsys_stl::string& pattern,
                                          bool require_whole_string = true);

Andy Cedilnik's avatar
Andy Cedilnik committed
81 82
protected:
  //! Process directory
83
  void ProcessDirectory(kwsys_stl::string::size_type start,
84
    const kwsys_stl::string& dir, bool dir_only);
Andy Cedilnik's avatar
Andy Cedilnik committed
85 86 87

  //! Process last directory, but only when recurse flags is on. That is
  // effectively like saying: /path/to/file/**/file
88 89
  void RecurseDirectory(kwsys_stl::string::size_type start,
    const kwsys_stl::string& dir, bool dir_only);
Andy Cedilnik's avatar
Andy Cedilnik committed
90 91 92 93

  //! Add regular expression
  void AddExpression(const char* expr);

94 95 96 97 98 99
  //! Add a file to the list
  void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file);

  GlobInternals* Internals;
  bool Recurse;
  kwsys_stl::string Relative;
100
  bool RecurseThroughSymlinks;
101 102 103 104

private:
  Glob(const Glob&);  // Not implemented.
  void operator=(const Glob&);  // Not implemented.
Andy Cedilnik's avatar
Andy Cedilnik committed
105 106 107 108
};

} // namespace @KWSYS_NAMESPACE@

109 110 111 112 113
/* Undefine temporary macro.  */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl
#endif

Andy Cedilnik's avatar
Andy Cedilnik committed
114
#endif