SortedDirectoryIterator.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // SortedDirectoryIterator.h
  3. //
  4. // Library: Foundation
  5. // Package: Filesystem
  6. // Module: DirectoryIterator
  7. //
  8. // Definition of the SortedDirectoryIterator class.
  9. //
  10. // Copyright (c) 2004-2012, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_SortedDirectoryIterator_INCLUDED
  16. #define Foundation_SortedDirectoryIterator_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/File.h"
  19. #include "Poco/Path.h"
  20. #include "Poco/DirectoryIterator.h"
  21. #include <deque>
  22. namespace Poco
  23. {
  24. class Foundation_API SortedDirectoryIterator: public DirectoryIterator
  25. /// The SortedDirectoryIterator class is similar to
  26. /// DirectoryIterator class, but places directories before files
  27. /// and sorts content alphabetically.
  28. {
  29. public:
  30. SortedDirectoryIterator();
  31. /// Creates the end iterator.
  32. SortedDirectoryIterator(const std::string& path);
  33. /// Creates a directory iterator for the given path.
  34. SortedDirectoryIterator(const DirectoryIterator& iterator);
  35. /// Creates a directory iterator for the given path.
  36. SortedDirectoryIterator(const File& file);
  37. /// Creates a directory iterator for the given file.
  38. SortedDirectoryIterator(const Path& path);
  39. /// Creates a directory iterator for the given path.
  40. virtual ~SortedDirectoryIterator();
  41. /// Destroys the DirsFirstDirectoryIterator.
  42. virtual SortedDirectoryIterator& operator ++(); // prefix
  43. private:
  44. bool _is_finished;
  45. std::deque<std::string> _directories;
  46. std::deque<std::string> _files;
  47. void next();
  48. /// Take next item
  49. void scan();
  50. /// Scan directory to collect its children directories and files
  51. };
  52. } // namespace Poco
  53. #endif //Foundation_SortedDirectoryIterator_INCLUDED