| 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 | |
| 16 | |
| 17 | #ifndef Foundation_SortedDirectoryIterator_INCLUDED |
| 18 | #define Foundation_SortedDirectoryIterator_INCLUDED |
| 19 | |
| 20 | #include "Poco/Foundation.h" |
| 21 | #include "Poco/File.h" |
| 22 | #include "Poco/Path.h" |
| 23 | #include "Poco/DirectoryIterator.h" |
| 24 | #include <deque> |
| 25 | |
| 26 | |
| 27 | namespace Poco |
| 28 | { |
| 29 | |
| 30 | class Foundation_API SortedDirectoryIterator: public DirectoryIterator |
| 31 | /// The SortedDirectoryIterator class is similar to |
| 32 | /// DirectoryIterator class, but places directories before files |
| 33 | /// and sorts content alphabetically. |
| 34 | { |
| 35 | public: |
| 36 | SortedDirectoryIterator(); |
| 37 | /// Creates the end iterator. |
| 38 | |
| 39 | SortedDirectoryIterator(const std::string& path); |
| 40 | /// Creates a directory iterator for the given path. |
| 41 | |
| 42 | SortedDirectoryIterator(const DirectoryIterator& iterator); |
| 43 | /// Creates a directory iterator for the given path. |
| 44 | |
| 45 | SortedDirectoryIterator(const File& file); |
| 46 | /// Creates a directory iterator for the given file. |
| 47 | |
| 48 | SortedDirectoryIterator(const Path& path); |
| 49 | /// Creates a directory iterator for the given path. |
| 50 | |
| 51 | virtual ~SortedDirectoryIterator(); |
| 52 | /// Destroys the DirsFirstDirectoryIterator. |
| 53 | |
| 54 | virtual SortedDirectoryIterator& operator ++(); // prefix |
| 55 | |
| 56 | private: |
| 57 | bool _is_finished; |
| 58 | std::deque<std::string> _directories; |
| 59 | std::deque<std::string> _files; |
| 60 | |
| 61 | void next(); |
| 62 | /// Take next item |
| 63 | void scan(); |
| 64 | /// Scan directory to collect its children directories and files |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | } // namespace Poco |
| 69 | |
| 70 | #endif //Foundation_SortedDirectoryIterator_INCLUDED |
| 71 | |