Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / kwsys / Glob.hxx.in
blobdc4ad58db7500f8f0d2a4c0d755c18020a0872b1
1 /*=========================================================================
3 Program: KWSys - Kitware System Library
4 Module: $RCSfile: Glob.hxx.in,v $
6 Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
13 =========================================================================*/
14 #ifndef @KWSYS_NAMESPACE@_Glob_hxx
15 #define @KWSYS_NAMESPACE@_Glob_hxx
17 #include <@KWSYS_NAMESPACE@/Configure.h>
18 #include <@KWSYS_NAMESPACE@/Configure.hxx>
20 #include <@KWSYS_NAMESPACE@/stl/string>
21 #include <@KWSYS_NAMESPACE@/stl/vector>
23 /* Define this macro temporarily to keep the code readable. */
24 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
25 # define kwsys_stl @KWSYS_NAMESPACE@_stl
26 #endif
28 namespace @KWSYS_NAMESPACE@
31 class GlobInternals;
33 /** \class Glob
34 * \brief Portable globbing searches.
36 * Globbing expressions are much simpler than regular
37 * expressions. This class will search for files using
38 * globbing expressions.
40 * Finds all files that match a given globbing expression.
42 class @KWSYS_NAMESPACE@_EXPORT Glob
44 public:
45 Glob();
46 ~Glob();
48 //! Find all files that match the pattern.
49 bool FindFiles(const kwsys_stl::string& inexpr);
51 //! Return the list of files that matched.
52 kwsys_stl::vector<kwsys_stl::string>& GetFiles();
54 //! Set recurse to true to match subdirectories.
55 void RecurseOn() { this->SetRecurse(true); }
56 void RecurseOff() { this->SetRecurse(false); }
57 void SetRecurse(bool i) { this->Recurse = i; }
58 bool GetRecurse() { return this->Recurse; }
60 //! Set recurse through symlinks to true if recursion should traverse the
61 // linked-to directories
62 void RecurseThroughSymlinksOn() { this->SetRecurseThroughSymlinks(true); }
63 void RecurseThroughSymlinksOff() { this->SetRecurseThroughSymlinks(false); }
64 void SetRecurseThroughSymlinks(bool i) { this->RecurseThroughSymlinks = i; }
65 bool GetRecurseThroughSymlinks() { return this->RecurseThroughSymlinks; }
67 //! Get the number of symlinks followed through recursion
68 unsigned int GetFollowedSymlinkCount() { return this->FollowedSymlinkCount; }
70 //! Set relative to true to only show relative path to files.
71 void SetRelative(const char* dir);
72 const char* GetRelative();
74 /** Convert the given globbing pattern to a regular expression.
75 There is no way to quote meta-characters. The
76 require_whole_string argument specifies whether the regex is
77 automatically surrounded by "^" and "$" to match the whole
78 string. This is on by default because patterns always match
79 whole strings, but may be disabled to support concatenating
80 expressions more easily (regex1|regex2|etc). */
81 static kwsys_stl::string PatternToRegex(const kwsys_stl::string& pattern,
82 bool require_whole_string = true);
84 protected:
85 //! Process directory
86 void ProcessDirectory(kwsys_stl::string::size_type start,
87 const kwsys_stl::string& dir, bool dir_only);
89 //! Process last directory, but only when recurse flags is on. That is
90 // effectively like saying: /path/to/file/**/file
91 void RecurseDirectory(kwsys_stl::string::size_type start,
92 const kwsys_stl::string& dir, bool dir_only);
94 //! Add regular expression
95 void AddExpression(const char* expr);
97 //! Add a file to the list
98 void AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const char* file);
100 GlobInternals* Internals;
101 bool Recurse;
102 kwsys_stl::string Relative;
103 bool RecurseThroughSymlinks;
104 unsigned int FollowedSymlinkCount;
106 private:
107 Glob(const Glob&); // Not implemented.
108 void operator=(const Glob&); // Not implemented.
111 } // namespace @KWSYS_NAMESPACE@
113 /* Undefine temporary macro. */
114 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
115 # undef kwsys_stl
116 #endif
118 #endif