2023-02-08 11:04:11 +00:00
|
|
|
//
|
|
|
|
// RecursiveDirectoryIteratorStategies.h
|
|
|
|
//
|
|
|
|
// Library: Foundation
|
|
|
|
// Package: Filesystem
|
|
|
|
// Module: RecursiveDirectoryIterator
|
|
|
|
//
|
2023-02-10 11:20:48 +00:00
|
|
|
// Definitions of the RecursiveDirectoryIterator strategy classes.
|
2023-02-08 11:04:11 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
|
|
|
// and Contributors.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED
|
|
|
|
#define Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
2023-02-13 09:22:33 +00:00
|
|
|
#include <queue>
|
|
|
|
#include <stack>
|
|
|
|
#include "Poco/DirectoryIterator.h"
|
|
|
|
#include "Poco/Foundation.h"
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Foundation_API TraverseBase
|
|
|
|
{
|
|
|
|
public:
|
2023-02-13 09:22:33 +00:00
|
|
|
typedef std::stack<DirectoryIterator> Stack;
|
|
|
|
typedef std::function<UInt16(const Stack &)> DepthFunPtr;
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
D_INFINITE = 0 /// Special value for infinite traverse depth.
|
|
|
|
};
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
protected:
|
2023-02-13 09:22:33 +00:00
|
|
|
bool isFiniteDepth();
|
|
|
|
bool isDirectory(Poco::File & file);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
DepthFunPtr _depthDeterminer;
|
|
|
|
UInt16 _maxDepth;
|
|
|
|
DirectoryIterator _itEnd;
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
private:
|
2023-02-13 09:22:33 +00:00
|
|
|
TraverseBase();
|
|
|
|
TraverseBase(const TraverseBase &);
|
|
|
|
TraverseBase & operator=(const TraverseBase &);
|
2023-02-08 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
class Foundation_API ChildrenFirstTraverse : public TraverseBase
|
2023-02-08 11:04:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-02-13 09:22:33 +00:00
|
|
|
ChildrenFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
const std::string next(Stack * itStack, bool * isFinished);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
private:
|
2023-02-13 09:22:33 +00:00
|
|
|
ChildrenFirstTraverse();
|
|
|
|
ChildrenFirstTraverse(const ChildrenFirstTraverse &);
|
|
|
|
ChildrenFirstTraverse & operator=(const ChildrenFirstTraverse &);
|
2023-02-08 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
class Foundation_API SiblingsFirstTraverse : public TraverseBase
|
2023-02-08 11:04:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-02-13 09:22:33 +00:00
|
|
|
SiblingsFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
const std::string next(Stack * itStack, bool * isFinished);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
private:
|
2023-02-13 09:22:33 +00:00
|
|
|
SiblingsFirstTraverse();
|
|
|
|
SiblingsFirstTraverse(const SiblingsFirstTraverse &);
|
|
|
|
SiblingsFirstTraverse & operator=(const SiblingsFirstTraverse &);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
std::stack<std::queue<std::string>> _dirsStack;
|
2023-02-08 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Poco
|
|
|
|
|
|
|
|
|
|
|
|
#endif // Foundation_RecursiveDirectoryIteratorStrategy_INCLUDED
|