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 "Poco/BasicEvent.h" |
24 | #include "Poco/EventArgs.h" |
25 | #include <stack> |
26 | #include <queue> |
27 | #include <functional> |
28 | |
29 | |
30 | namespace Poco { |
31 | |
32 | |
33 | class Foundation_API TraverseBase |
34 | { |
35 | public: |
36 | typedef std::stack<DirectoryIterator> Stack; |
37 | typedef std::pointer_to_unary_function<const Stack&, UInt16> DepthFunPtr; |
38 | |
39 | enum |
40 | { |
41 | D_INFINITE = 0 /// Special value for infinite traverse depth. |
42 | }; |
43 | |
44 | Poco::BasicEvent<const std::string> traverseError; |
45 | |
46 | TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE); |
47 | |
48 | protected: |
49 | bool isFiniteDepth(); |
50 | bool isDirectory(Poco::File& file); |
51 | |
52 | DepthFunPtr _depthDeterminer; |
53 | UInt16 _maxDepth; |
54 | DirectoryIterator _itEnd; |
55 | |
56 | private: |
57 | TraverseBase(); |
58 | TraverseBase(const TraverseBase&); |
59 | TraverseBase& operator=(const TraverseBase&); |
60 | }; |
61 | |
62 | |
63 | class Foundation_API ChildrenFirstTraverse: public TraverseBase |
64 | { |
65 | public: |
66 | ChildrenFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE); |
67 | |
68 | const std::string next(Stack* itStack, bool* isFinished); |
69 | |
70 | private: |
71 | ChildrenFirstTraverse(); |
72 | ChildrenFirstTraverse(const ChildrenFirstTraverse&); |
73 | ChildrenFirstTraverse& operator=(const ChildrenFirstTraverse&); |
74 | }; |
75 | |
76 | |
77 | class Foundation_API SiblingsFirstTraverse: public TraverseBase |
78 | { |
79 | public: |
80 | SiblingsFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE); |
81 | |
82 | const std::string next(Stack* itStack, bool* isFinished); |
83 | |
84 | private: |
85 | SiblingsFirstTraverse(); |
86 | SiblingsFirstTraverse(const SiblingsFirstTraverse&); |
87 | SiblingsFirstTraverse& operator=(const SiblingsFirstTraverse&); |
88 | |
89 | std::stack<std::queue<std::string> > _dirsStack; |
90 | }; |
91 | |
92 | |
93 | } // namespace Poco |
94 | |
95 | |
96 | #endif // Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED |
97 |