diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/poco/Foundation/src/DirectoryIteratorStrategy.cpp | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/DirectoryIteratorStrategy.cpp')
-rw-r--r-- | contrib/libs/poco/Foundation/src/DirectoryIteratorStrategy.cpp | 336 |
1 files changed, 168 insertions, 168 deletions
diff --git a/contrib/libs/poco/Foundation/src/DirectoryIteratorStrategy.cpp b/contrib/libs/poco/Foundation/src/DirectoryIteratorStrategy.cpp index 57a5b36c4e..21c9755bb4 100644 --- a/contrib/libs/poco/Foundation/src/DirectoryIteratorStrategy.cpp +++ b/contrib/libs/poco/Foundation/src/DirectoryIteratorStrategy.cpp @@ -1,168 +1,168 @@ -// -// RecursiveDirectoryIteratorStategies.cpp -// -// Library: Foundation -// Package: Filesystem -// Module: RecursiveDirectoryIterator -// -// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/DirectoryIteratorStrategy.h" - - -namespace Poco { - - -// -// TraverseBase -// -TraverseBase::TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth) - : _depthDeterminer(depthDeterminer), _maxDepth(maxDepth) -{ -} - - -inline bool TraverseBase::isFiniteDepth() -{ - return _maxDepth != D_INFINITE; -} - - -bool TraverseBase::isDirectory(Poco::File& file) -{ - try - { - return file.isDirectory(); - } - catch (...) - { - return false; - } -} - - -// -// ChildrenFirstTraverse -// -ChildrenFirstTraverse::ChildrenFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth) - : TraverseBase(depthDeterminer, maxDepth) -{ -} - - -const std::string ChildrenFirstTraverse::next(Stack* itStack, bool* isFinished) -{ - // pointer mustn't point to NULL and iteration mustn't be finished - poco_check_ptr(isFinished); - poco_assert(!(*isFinished)); - - std::stack<DirectoryIterator> it; - - //_depthDeterminer(it); - - // go deeper into not empty directory - // (if depth limit allows) - bool isDepthLimitReached = isFiniteDepth() && _depthDeterminer(*itStack) >= _maxDepth; - if (!isDepthLimitReached && isDirectory(*itStack->top())) - { - DirectoryIterator child_it(itStack->top().path()); - // check if directory is empty - if (child_it != _itEnd) - { - itStack->push(child_it); - return child_it->path(); - } - } - - ++(itStack->top()); - - poco_assert(!itStack->empty()); - // return up until there isn't right sibling - while (itStack->top() == _itEnd) - { - itStack->pop(); - - // detect end of traversal - if (itStack->empty()) - { - *isFinished = true; - return _itEnd->path(); - } - else - { - ++(itStack->top()); - } - } - - return itStack->top()->path(); -} - - -// -// SiblingsFirstTraverse -// -SiblingsFirstTraverse::SiblingsFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth) - : TraverseBase(depthDeterminer, maxDepth) -{ - _dirsStack.push(std::queue<std::string>()); -} - - -const std::string SiblingsFirstTraverse::next(Stack* itStack, bool* isFinished) -{ - // pointer mustn't point to NULL and iteration mustn't be finished - poco_check_ptr(isFinished); - poco_assert(!(*isFinished)); - - // add dirs to queue (if depth limit allows) - bool isDepthLimitReached = isFiniteDepth() && _depthDeterminer(*itStack) >= _maxDepth; - if (!isDepthLimitReached && isDirectory(*itStack->top())) - { - const std::string& p = itStack->top()->path(); - _dirsStack.top().push(p); - } - - ++(itStack->top()); - - poco_assert(!itStack->empty()); - // return up until there isn't right sibling - while (itStack->top() == _itEnd) - { - // try to find first not empty directory and go deeper - while (!_dirsStack.top().empty()) - { - std::string dir = _dirsStack.top().front(); - _dirsStack.top().pop(); - DirectoryIterator child_it(dir); - - // check if directory is empty - if (child_it != _itEnd) - { - itStack->push(child_it); - _dirsStack.push(std::queue<std::string>()); - return child_it->path(); - } - } - - // if fail go upper - itStack->pop(); - _dirsStack.pop(); - - // detect end of traversal - if (itStack->empty()) - { - *isFinished = true; - return _itEnd->path(); - } - } - - return itStack->top()->path(); -} - - -} // namespace Poco +// +// RecursiveDirectoryIteratorStategies.cpp +// +// Library: Foundation +// Package: Filesystem +// Module: RecursiveDirectoryIterator +// +// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/DirectoryIteratorStrategy.h" + + +namespace Poco { + + +// +// TraverseBase +// +TraverseBase::TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth) + : _depthDeterminer(depthDeterminer), _maxDepth(maxDepth) +{ +} + + +inline bool TraverseBase::isFiniteDepth() +{ + return _maxDepth != D_INFINITE; +} + + +bool TraverseBase::isDirectory(Poco::File& file) +{ + try + { + return file.isDirectory(); + } + catch (...) + { + return false; + } +} + + +// +// ChildrenFirstTraverse +// +ChildrenFirstTraverse::ChildrenFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth) + : TraverseBase(depthDeterminer, maxDepth) +{ +} + + +const std::string ChildrenFirstTraverse::next(Stack* itStack, bool* isFinished) +{ + // pointer mustn't point to NULL and iteration mustn't be finished + poco_check_ptr(isFinished); + poco_assert(!(*isFinished)); + + std::stack<DirectoryIterator> it; + + //_depthDeterminer(it); + + // go deeper into not empty directory + // (if depth limit allows) + bool isDepthLimitReached = isFiniteDepth() && _depthDeterminer(*itStack) >= _maxDepth; + if (!isDepthLimitReached && isDirectory(*itStack->top())) + { + DirectoryIterator child_it(itStack->top().path()); + // check if directory is empty + if (child_it != _itEnd) + { + itStack->push(child_it); + return child_it->path(); + } + } + + ++(itStack->top()); + + poco_assert(!itStack->empty()); + // return up until there isn't right sibling + while (itStack->top() == _itEnd) + { + itStack->pop(); + + // detect end of traversal + if (itStack->empty()) + { + *isFinished = true; + return _itEnd->path(); + } + else + { + ++(itStack->top()); + } + } + + return itStack->top()->path(); +} + + +// +// SiblingsFirstTraverse +// +SiblingsFirstTraverse::SiblingsFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth) + : TraverseBase(depthDeterminer, maxDepth) +{ + _dirsStack.push(std::queue<std::string>()); +} + + +const std::string SiblingsFirstTraverse::next(Stack* itStack, bool* isFinished) +{ + // pointer mustn't point to NULL and iteration mustn't be finished + poco_check_ptr(isFinished); + poco_assert(!(*isFinished)); + + // add dirs to queue (if depth limit allows) + bool isDepthLimitReached = isFiniteDepth() && _depthDeterminer(*itStack) >= _maxDepth; + if (!isDepthLimitReached && isDirectory(*itStack->top())) + { + const std::string& p = itStack->top()->path(); + _dirsStack.top().push(p); + } + + ++(itStack->top()); + + poco_assert(!itStack->empty()); + // return up until there isn't right sibling + while (itStack->top() == _itEnd) + { + // try to find first not empty directory and go deeper + while (!_dirsStack.top().empty()) + { + std::string dir = _dirsStack.top().front(); + _dirsStack.top().pop(); + DirectoryIterator child_it(dir); + + // check if directory is empty + if (child_it != _itEnd) + { + itStack->push(child_it); + _dirsStack.push(std::queue<std::string>()); + return child_it->path(); + } + } + + // if fail go upper + itStack->pop(); + _dirsStack.pop(); + + // detect end of traversal + if (itStack->empty()) + { + *isFinished = true; + return _itEnd->path(); + } + } + + return itStack->top()->path(); +} + + +} // namespace Poco |