1 | // |
---|---|
2 | // RecursiveDirectoryIteratorStategies.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Filesystem |
6 | // Module: RecursiveDirectoryIterator |
7 | // |
8 | // Definitions of the RecursiveDirectoryIterator stategy classes. |
9 | // |
10 | // Copyright (c) 2012, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED |
18 | #define Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/DirectoryIterator.h" |
23 | #include <stack> |
24 | #include <queue> |
25 | #include <functional> |
26 | |
27 | |
28 | namespace Poco { |
29 | |
30 | |
31 | class Foundation_API TraverseBase |
32 | { |
33 | public: |
34 | typedef std::stack<DirectoryIterator> Stack; |
35 | typedef std::function<UInt16(const Stack&)> DepthFunPtr; |
36 | |
37 | enum |
38 | { |
39 | D_INFINITE = 0 /// Special value for infinite traverse depth. |
40 | }; |
41 | |
42 | TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE); |
43 | |
44 | protected: |
45 | bool isFiniteDepth(); |
46 | bool isDirectory(Poco::File& file); |
47 | |
48 | DepthFunPtr _depthDeterminer; |
49 | UInt16 _maxDepth; |
50 | DirectoryIterator _itEnd; |
51 | |
52 | private: |
53 | TraverseBase(); |
54 | TraverseBase(const TraverseBase&); |
55 | TraverseBase& operator=(const TraverseBase&); |
56 | }; |
57 | |
58 | |
59 | class Foundation_API ChildrenFirstTraverse: public TraverseBase |
60 | { |
61 | public: |
62 | ChildrenFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE); |
63 | |
64 | const std::string next(Stack* itStack, bool* isFinished); |
65 | |
66 | private: |
67 | ChildrenFirstTraverse(); |
68 | ChildrenFirstTraverse(const ChildrenFirstTraverse&); |
69 | ChildrenFirstTraverse& operator=(const ChildrenFirstTraverse&); |
70 | }; |
71 | |
72 | |
73 | class Foundation_API SiblingsFirstTraverse: public TraverseBase |
74 | { |
75 | public: |
76 | SiblingsFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE); |
77 | |
78 | const std::string next(Stack* itStack, bool* isFinished); |
79 | |
80 | private: |
81 | SiblingsFirstTraverse(); |
82 | SiblingsFirstTraverse(const SiblingsFirstTraverse&); |
83 | SiblingsFirstTraverse& operator=(const SiblingsFirstTraverse&); |
84 | |
85 | std::stack<std::queue<std::string> > _dirsStack; |
86 | }; |
87 | |
88 | |
89 | } // namespace Poco |
90 | |
91 | |
92 | #endif // Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED |
93 |