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
28 namespace @KWSYS_NAMESPACE@
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
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 relative to true to only show relative path to files.
61 void SetRelative(const char* dir
);
62 const char* GetRelative();
64 /** Convert the given globbing pattern to a regular expression.
65 There is no way to quote meta-characters. The
66 require_whole_string argument specifies whether the regex is
67 automatically surrounded by "^" and "$" to match the whole
68 string. This is on by default because patterns always match
69 whole strings, but may be disabled to support concatenating
70 expressions more easily (regex1|regex2|etc). */
71 static kwsys_stl::string
PatternToRegex(const kwsys_stl::string
& pattern
,
72 bool require_whole_string
= true);
76 void ProcessDirectory(kwsys_stl::string::size_type start
,
77 const kwsys_stl::string
& dir
, bool dir_only
);
79 //! Process last directory, but only when recurse flags is on. That is
80 // effectively like saying: /path/to/file/**/file
81 void RecurseDirectory(kwsys_stl::string::size_type start
,
82 const kwsys_stl::string
& dir
, bool dir_only
);
84 //! Add regular expression
85 void AddExpression(const char* expr
);
87 //! Add a file to the list
88 void AddFile(kwsys_stl::vector
<kwsys_stl::string
>& files
, const char* file
);
90 GlobInternals
* Internals
;
92 kwsys_stl::string Relative
;
95 Glob(const Glob
&); // Not implemented.
96 void operator=(const Glob
&); // Not implemented.
99 } // namespace @KWSYS_NAMESPACE@
101 /* Undefine temporary macro. */
102 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS