An update will be applied January 25th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Glob.hxx.in 5.13 KB
Newer Older
1
2
3
/*============================================================================
  KWSys - Kitware System Library
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Andy Cedilnik's avatar
Andy Cedilnik committed
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
Andy Cedilnik's avatar
Andy Cedilnik committed
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
Andy Cedilnik's avatar
Andy Cedilnik committed
12
13
14
#ifndef @KWSYS_NAMESPACE@_Glob_hxx
#define @KWSYS_NAMESPACE@_Glob_hxx

15
16
17
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <@KWSYS_NAMESPACE@/Configure.hxx>

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

21
22
23
24
/* 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

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
{
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public:
  enum MessageType
  {
    error,
    cyclicRecursion
  };

  struct Message
  {
    MessageType type;
    kwsys_stl::string content;

    Message(MessageType t, const kwsys_stl::string& c) :
      type(t),
      content(c)
    {}
    Message(const Message& msg) :
      type(msg.type),
      content(msg.content)
    {}
  };

  typedef kwsys_stl::vector<Message> GlobMessages;
  typedef kwsys_stl::vector<Message>::iterator GlobMessagesIterator;
Andy Cedilnik's avatar
Andy Cedilnik committed
66
67
68
69
70
public:
  Glob();
  ~Glob();

  //! Find all files that match the pattern.
71
72
  bool FindFiles(const kwsys_stl::string& inexpr,
    GlobMessages* messages = 0);
Andy Cedilnik's avatar
Andy Cedilnik committed
73
74

  //! Return the list of files that matched.
75
  kwsys_stl::vector<kwsys_stl::string>& GetFiles();
Andy Cedilnik's avatar
Andy Cedilnik committed
76
77
78
79

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

83
84
85
86
87
88
89
  //! 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; }

90
91
92
  //! Get the number of symlinks followed through recursion
  unsigned int GetFollowedSymlinkCount() { return this->FollowedSymlinkCount; }

93
94
95
  //! 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
96

97
98
99
100
101
102
103
104
  /** 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,
105
106
                                          bool require_whole_string = true,
                                          bool preserve_case = false);
107

108
109
110
111
112
113
114
115
116
  /** Getters and setters for enabling and disabling directory
      listing in recursive and non recursive globbing mode.
      If listing is enabled in recursive mode it also lists
      directory symbolic links even if follow symlinks is enabled. */
  void SetListDirs(bool list) { this->ListDirs=list; }
  bool GetListDirs() const { return this->ListDirs; }
  void SetRecurseListDirs(bool list) { this->RecurseListDirs=list; }
  bool GetRecurseListDirs() const { return this->RecurseListDirs; }

Andy Cedilnik's avatar
Andy Cedilnik committed
117
118
protected:
  //! Process directory
119
  void ProcessDirectory(kwsys_stl::string::size_type start,
120
121
    const kwsys_stl::string& dir,
    GlobMessages* messages);
Andy Cedilnik's avatar
Andy Cedilnik committed
122
123
124

  //! Process last directory, but only when recurse flags is on. That is
  // effectively like saying: /path/to/file/**/file
125
126
127
  bool RecurseDirectory(kwsys_stl::string::size_type start,
    const kwsys_stl::string& dir,
    GlobMessages* messages);
Andy Cedilnik's avatar
Andy Cedilnik committed
128
129

  //! Add regular expression
130
  void AddExpression(const kwsys_stl::string& expr);
Andy Cedilnik's avatar
Andy Cedilnik committed
131

132
  //! Add a file to the list
133
  void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl::string& file);
134
135
136
137

  GlobInternals* Internals;
  bool Recurse;
  kwsys_stl::string Relative;
138
  bool RecurseThroughSymlinks;
139
  unsigned int FollowedSymlinkCount;
140
  kwsys_stl::vector<kwsys_stl::string> VisitedSymlinks;
141
142
  bool ListDirs;
  bool RecurseListDirs;
143
144
145
146

private:
  Glob(const Glob&);  // Not implemented.
  void operator=(const Glob&);  // Not implemented.
Andy Cedilnik's avatar
Andy Cedilnik committed
147
148
149
150
};

} // namespace @KWSYS_NAMESPACE@

151
152
153
154
155
/* Undefine temporary macro.  */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl
#endif

Andy Cedilnik's avatar
Andy Cedilnik committed
156
#endif