cmGlob.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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.
  12. =========================================================================*/
  13. #ifndef cmGlob_h
  14. #define cmGlob_h
  15. #include "cmStandardIncludes.h"
  16. class cmGlobInternal;
  17. /** \class cmGlob
  18. * \brief Helper class for performing globbing searches.
  19. *
  20. * Finds all files that match a given globbing expression.
  21. */
  22. class cmGlob
  23. {
  24. public:
  25. cmGlob();
  26. ~cmGlob();
  27. //! Find all files that match the pattern.
  28. bool FindFiles(const std::string& inexpr);
  29. //! Return the list of files that matched.
  30. std::vector<std::string>& GetFiles();
  31. //! Set recurse to true to match subdirectories.
  32. void RecurseOn() { this->SetRecurse(true); }
  33. void RecurseOff() { this->SetRecurse(false); }
  34. void SetRecurse(bool i) { m_Recurse = i; }
  35. bool GetRecurse() { return m_Recurse; }
  36. protected:
  37. //! Process directory
  38. void ProcessDirectory(std::string::size_type start,
  39. const std::string& dir, bool dir_only);
  40. //! Process last directory, but only when recurse flags is on. That is
  41. // effectively like saying: /path/to/file/**/file
  42. void RecurseDirectory(std::string::size_type start,
  43. const std::string& dir, bool dir_only);
  44. //! Escape all non-alphanumeric characters in pattern.
  45. void Escape(int ch, char* buffer);
  46. //!
  47. // Translate a shell PATTERN to a regular expression.
  48. // There is no way to quote meta-characters.
  49. std::string ConvertExpression(const std::string& expr);
  50. //! Add regular expression
  51. void AddExpression(const char* expr);
  52. cmGlobInternal* m_Internals;
  53. bool m_Recurse;
  54. };
  55. #endif