2009-09-28 19:37:35 +04:00
|
|
|
/*============================================================================
|
|
|
|
KWSys - Kitware System Library
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2009-09-28 19:37:35 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2009-09-28 19:37:35 +04:00
|
|
|
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.
|
|
|
|
============================================================================*/
|
2005-10-18 22:08:55 +04:00
|
|
|
#ifndef @KWSYS_NAMESPACE@_Glob_hxx
|
|
|
|
#define @KWSYS_NAMESPACE@_Glob_hxx
|
|
|
|
|
2005-12-10 20:09:24 +03:00
|
|
|
#include <@KWSYS_NAMESPACE@/Configure.h>
|
|
|
|
#include <@KWSYS_NAMESPACE@/Configure.hxx>
|
|
|
|
|
2005-10-18 22:08:55 +04:00
|
|
|
#include <@KWSYS_NAMESPACE@/stl/string>
|
|
|
|
#include <@KWSYS_NAMESPACE@/stl/vector>
|
|
|
|
|
2005-12-10 20:09:24 +03:00
|
|
|
/* 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
|
2005-10-18 22:08:55 +04:00
|
|
|
|
|
|
|
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.
|
2005-10-19 18:47:19 +04:00
|
|
|
bool FindFiles(const kwsys_stl::string& inexpr);
|
2005-10-18 22:08:55 +04:00
|
|
|
|
|
|
|
//! Return the list of files that matched.
|
2005-10-19 18:47:19 +04:00
|
|
|
kwsys_stl::vector<kwsys_stl::string>& GetFiles();
|
2005-10-18 22:08:55 +04:00
|
|
|
|
|
|
|
//! Set recurse to true to match subdirectories.
|
|
|
|
void RecurseOn() { this->SetRecurse(true); }
|
|
|
|
void RecurseOff() { this->SetRecurse(false); }
|
2006-03-22 00:02:47 +03:00
|
|
|
void SetRecurse(bool i) { this->Recurse = i; }
|
|
|
|
bool GetRecurse() { return this->Recurse; }
|
|
|
|
|
2008-08-20 21:24:16 +04:00
|
|
|
//! 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; }
|
|
|
|
|
2008-09-11 22:34:04 +04:00
|
|
|
//! Get the number of symlinks followed through recursion
|
|
|
|
unsigned int GetFollowedSymlinkCount() { return this->FollowedSymlinkCount; }
|
|
|
|
|
2006-03-22 00:02:47 +03:00
|
|
|
//! Set relative to true to only show relative path to files.
|
|
|
|
void SetRelative(const char* dir);
|
|
|
|
const char* GetRelative();
|
2005-10-18 22:08:55 +04:00
|
|
|
|
2006-08-21 22:17:58 +04:00
|
|
|
/** 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,
|
2009-09-14 21:45:40 +04:00
|
|
|
bool require_whole_string = true,
|
|
|
|
bool preserve_case = false);
|
2006-08-21 22:17:58 +04:00
|
|
|
|
2005-10-18 22:08:55 +04:00
|
|
|
protected:
|
|
|
|
//! Process directory
|
2006-03-22 00:02:47 +03:00
|
|
|
void ProcessDirectory(kwsys_stl::string::size_type start,
|
2011-09-06 21:07:52 +04:00
|
|
|
const kwsys_stl::string& dir);
|
2005-10-18 22:08:55 +04:00
|
|
|
|
|
|
|
//! Process last directory, but only when recurse flags is on. That is
|
|
|
|
// effectively like saying: /path/to/file/**/file
|
2005-10-19 18:47:19 +04:00
|
|
|
void RecurseDirectory(kwsys_stl::string::size_type start,
|
2011-09-06 21:07:52 +04:00
|
|
|
const kwsys_stl::string& dir);
|
2005-10-18 22:08:55 +04:00
|
|
|
|
|
|
|
//! Add regular expression
|
|
|
|
void AddExpression(const char* expr);
|
|
|
|
|
2006-03-22 00:02:47 +03:00
|
|
|
//! 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;
|
2008-08-20 21:24:16 +04:00
|
|
|
bool RecurseThroughSymlinks;
|
2008-09-11 22:34:04 +04:00
|
|
|
unsigned int FollowedSymlinkCount;
|
2007-08-16 15:38:47 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
Glob(const Glob&); // Not implemented.
|
|
|
|
void operator=(const Glob&); // Not implemented.
|
2005-10-18 22:08:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace @KWSYS_NAMESPACE@
|
|
|
|
|
2006-08-27 20:35:54 +04:00
|
|
|
/* Undefine temporary macro. */
|
|
|
|
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
|
|
|
|
# undef kwsys_stl
|
|
|
|
#endif
|
|
|
|
|
2005-10-18 22:08:55 +04:00
|
|
|
#endif
|