DirectoryIteratorStrategy.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED
  16. #define Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/DirectoryIterator.h"
  19. #include <stack>
  20. #include <queue>
  21. #include <functional>
  22. namespace Poco {
  23. class Foundation_API TraverseBase
  24. {
  25. public:
  26. typedef std::stack<DirectoryIterator> Stack;
  27. typedef std::pointer_to_unary_function<const Stack&, UInt16> DepthFunPtr;
  28. enum
  29. {
  30. D_INFINITE = 0 /// Special value for infinite traverse depth.
  31. };
  32. TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE);
  33. protected:
  34. bool isFiniteDepth();
  35. bool isDirectory(Poco::File& file);
  36. DepthFunPtr _depthDeterminer;
  37. UInt16 _maxDepth;
  38. DirectoryIterator _itEnd;
  39. private:
  40. TraverseBase();
  41. TraverseBase(const TraverseBase&);
  42. TraverseBase& operator=(const TraverseBase&);
  43. };
  44. class Foundation_API ChildrenFirstTraverse: public TraverseBase
  45. {
  46. public:
  47. ChildrenFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE);
  48. const std::string next(Stack* itStack, bool* isFinished);
  49. private:
  50. ChildrenFirstTraverse();
  51. ChildrenFirstTraverse(const ChildrenFirstTraverse&);
  52. ChildrenFirstTraverse& operator=(const ChildrenFirstTraverse&);
  53. };
  54. class Foundation_API SiblingsFirstTraverse: public TraverseBase
  55. {
  56. public:
  57. SiblingsFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE);
  58. const std::string next(Stack* itStack, bool* isFinished);
  59. private:
  60. SiblingsFirstTraverse();
  61. SiblingsFirstTraverse(const SiblingsFirstTraverse&);
  62. SiblingsFirstTraverse& operator=(const SiblingsFirstTraverse&);
  63. std::stack<std::queue<std::string> > _dirsStack;
  64. };
  65. } // namespace Poco
  66. #endif // Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED