From 8ddba0bcd11a2248e2eb731f1d276148b4aa04ce Mon Sep 17 00:00:00 2001 From: Marian Krivos Date: Wed, 20 Feb 2013 09:44:25 +0100 Subject: [PATCH] SF Feature requests #168 and #163 - part 3 --- Foundation/CMakeLists.txt | 3 - Foundation/Makefile | 2 +- Foundation/include/Poco/DirectoryIterator.h | 2 +- .../include/Poco/RecursiveDirectoryIterator.h | 374 ++++++++---------- .../Poco/RecursiveDirectoryIteratorImpl.h | 135 +++---- .../RecursiveDirectoryIteratorStrategies.h | 8 +- .../include/Poco/SortedDirectoryIterator.h | 55 ++- Foundation/src/RecursiveDirectoryIterator.cpp | 6 - .../RecursiveDirectoryIteratorStrategies.cpp | 14 +- Foundation/src/SortedDirectoryIterator.cpp | 105 +++-- 10 files changed, 304 insertions(+), 400 deletions(-) delete mode 100644 Foundation/src/RecursiveDirectoryIterator.cpp diff --git a/Foundation/CMakeLists.txt b/Foundation/CMakeLists.txt index 9f188b975..77b060bdf 100644 --- a/Foundation/CMakeLists.txt +++ b/Foundation/CMakeLists.txt @@ -52,7 +52,6 @@ set( BASE_SRCS src/DigestEngine.cpp src/DigestStream.cpp src/DirectoryIterator.cpp - src/RecursiveDirectoryIterator.cpp src/RecursiveDirectoryIteratorStrategies.cpp src/DirectoryWatcher.cpp src/Environment.cpp @@ -116,8 +115,6 @@ set( BASE_SRCS src/RWLock.cpp src/Random.cpp src/RandomStream.cpp - src/RecursiveDirectoryIterator.cpp - src/RecursiveDirectoryIteratorStrategies.cpp src/RefCountedObject.cpp src/RegularExpression.cpp src/RotateStrategy.cpp diff --git a/Foundation/Makefile b/Foundation/Makefile index f72bfe293..85043471b 100644 --- a/Foundation/Makefile +++ b/Foundation/Makefile @@ -21,7 +21,7 @@ objects = ArchiveStrategy Ascii ASCIIEncoding AsyncChannel \ NestedDiagnosticContext Notification NotificationCenter \ NotificationQueue PriorityNotificationQueue TimedNotificationQueue \ NullStream NumberFormatter NumberParser NumericString AbstractObserver \ - Path PatternFormatter Process PurgeStrategy RWLock Random RandomStream RecursiveDirectoryIterator \ + Path PatternFormatter Process PurgeStrategy RWLock Random RandomStream \ RecursiveDirectoryIteratorStrategies RegularExpression RefCountedObject Runnable RotateStrategy Condition \ SHA1Engine Semaphore SharedLibrary SimpleFileChannel \ SignalHandler SplitterChannel SortedDirectoryIterator Stopwatch StreamChannel \ diff --git a/Foundation/include/Poco/DirectoryIterator.h b/Foundation/include/Poco/DirectoryIterator.h index 2b5232534..9c6747568 100644 --- a/Foundation/include/Poco/DirectoryIterator.h +++ b/Foundation/include/Poco/DirectoryIterator.h @@ -109,7 +109,7 @@ public: bool operator == (const DirectoryIterator& iterator) const; bool operator != (const DirectoryIterator& iterator) const; -public: +protected: Path _path; File _file; diff --git a/Foundation/include/Poco/RecursiveDirectoryIterator.h b/Foundation/include/Poco/RecursiveDirectoryIterator.h index 5bbe87adf..43b6b2ef9 100644 --- a/Foundation/include/Poco/RecursiveDirectoryIterator.h +++ b/Foundation/include/Poco/RecursiveDirectoryIterator.h @@ -35,6 +35,7 @@ // DEALINGS IN THE SOFTWARE. // + #ifndef Foundation_RecursiveDirectoryIterator_INCLUDE #define Foundation_RecursiveDirectoryIterator_INCLUDE @@ -44,6 +45,7 @@ #include "Poco/RecursiveDirectoryIteratorImpl.h" #include "Poco/RecursiveDirectoryIteratorStrategies.h" + namespace Poco { @@ -54,27 +56,27 @@ class RecursiveDirectoryIteratorImpl; template class RecursiveDirectoryIterator -/// The RecursiveDirectoryIterator class is used to enumerate -/// all files in a directory and its subdirectories. -/// -/// RecursiveDirectoryIterator has some limitations: -/// * only forward iteration (++) is supported -/// * an iterator copied from another one will always -/// point to the same file as the original iterator, -/// even is the original iterator has been advanced -/// (all copies of an iterator share their state with -/// the original iterator) -/// -/// The class can follow different traversal strategies: -/// * depth-first strategy; -/// * siblings-first strategy. -/// The stategies are set by template parameter. -/// There are two corresponding typedefs: -/// * SimpleRecursiveDirectoryIterator; -/// * SiblingsFirstRecursiveDirectoryIterator. -/// -/// The depth of traversal can be limited by constructor -/// parameter maxDepth (which sets the infinite depth by default). + /// The RecursiveDirectoryIterator class is used to enumerate + /// all files in a directory and its subdirectories. + /// + /// RecursiveDirectoryIterator has some limitations: + /// * only forward iteration (++) is supported + /// * an iterator copied from another one will always + /// point to the same file as the original iterator, + /// even is the original iterator has been advanced + /// (all copies of an iterator share their state with + /// the original iterator) + /// + /// The class can follow different traversal strategies: + /// * depth-first strategy; + /// * siblings-first strategy. + /// The stategies are set by template parameter. + /// There are two corresponding typedefs: + /// * SimpleRecursiveDirectoryIterator; + /// * SiblingsFirstRecursiveDirectoryIterator. + /// + /// The depth of traversal can be limited by constructor + /// parameter maxDepth (which sets the infinite depth by default). { public: typedef RecursiveDirectoryIterator MyType; @@ -83,53 +85,150 @@ public: { D_INFINITE = 0 }; - /// Constant for infinite traverse depth. + /// Constant for infinite traverse depth. - RecursiveDirectoryIterator(); - /// Creates the end iterator. + RecursiveDirectoryIterator() + /// Creates the end iterator. + : _pImpl(0) + { + } RecursiveDirectoryIterator(const std::string& path, UInt16 maxDepth = D_INFINITE); - /// Creates a recursive directory iterator for the given path. + /// Creates a recursive directory iterator for the given path. - RecursiveDirectoryIterator(const MyType& iterator); - /// Creates a copy of another recursive directory iterator. + RecursiveDirectoryIterator(const MyType& iterator) + /// Creates a copy of another recursive directory iterator. + : _pImpl(iterator._pImpl), _path(iterator._path), _file(iterator._file) + { + } - RecursiveDirectoryIterator(const DirectoryIterator& iterator, UInt16 maxDepth = D_INFINITE); - /// Creates a recursive directory iterator for the path of - /// non-recursive directory iterator. + RecursiveDirectoryIterator(const DirectoryIterator& iterator, UInt16 maxDepth = D_INFINITE) + /// Creates a recursive directory iterator for the path of + /// non-recursive directory iterator. + : _pImpl(new ImplType(iterator->path(), maxDepth)), _path(Path(_pImpl->get())), _file(_path) + { + } - RecursiveDirectoryIterator(const File& file, UInt16 maxDepth = D_INFINITE); - /// Creates a recursive directory iterator for the given path. + RecursiveDirectoryIterator(const File& file, UInt16 maxDepth = D_INFINITE) + /// Creates a recursive directory iterator for the given path. + : _pImpl(new ImplType(file.path(), maxDepth)), _path(Path(_pImpl->get())), _file(_path) + { + } - RecursiveDirectoryIterator(const Path& path, UInt16 maxDepth = D_INFINITE); - /// Creates a recursive directory iterator for the given path. + RecursiveDirectoryIterator(const Path& path, UInt16 maxDepth = D_INFINITE) + /// Creates a recursive directory iterator for the given path. + : _pImpl(new ImplType(path.toString(), maxDepth)), _path(Path(_pImpl->get())), _file(_path) + { + } - ~RecursiveDirectoryIterator(); - /// Destroys the DirectoryIterator. - const std::string& name() const; - /// Returns the current filename. + ~RecursiveDirectoryIterator() + /// Destroys the DirectoryIterator. + { + if (_pImpl) + _pImpl->release(); + } - const Poco::Path& path() const; - /// Returns the current path. + const std::string& name() const + /// Returns the current filename. + { + return _path.getFileName(); + } - UInt16 depth() const; - /// Depth of recursion (counting from 1). + const Poco::Path& path() const + /// Returns the current path. + { + return _path; + } - UInt16 maxDepth() const; - /// Max depth of recursion (counting from 1). + UInt16 depth() const + /// Depth of recursion (counting from 1). + { + return _pImpl->depth(); + } - MyType& operator =(const MyType& it); - MyType& operator =(const File& file); - MyType& operator =(const Path& path); - MyType& operator =(const std::string& path); + UInt16 maxDepth() const + /// Max depth of recursion (counting from 1). + { + return _pImpl->maxDepth(); + } - MyType& operator ++(); - const File& operator *() const; - File& operator *(); - const File* operator ->() const; - File* operator ->(); + MyType& operator =(const MyType& it) + { + if (_pImpl) + _pImpl->release(); + _pImpl = it._pImpl; + if (_pImpl) + { + _pImpl->duplicate(); + _path = it._path; + _file = _path; + } + return *this; + } + + MyType& operator =(const File& file) + { + if (_pImpl) + _pImpl->release(); + _pImpl = new ImplType(file.path()); + _path = Path(_pImpl->get()); + _file = _path; + return *this; + } + + + MyType& operator =(const Path& path) + { + if (_pImpl) + _pImpl->release(); + _pImpl = new ImplType(path.toString()); + _path = Path(_pImpl->get()); + _file = _path; + return *this; + } + + MyType& operator =(const std::string& path) + { + if (_pImpl) + _pImpl->release(); + _pImpl = new ImplType(path); + _path = Path(_pImpl->get()); + _file = _path; + return *this; + } + + MyType& operator ++() + { + if (_pImpl) + { + _path = Path(_pImpl->next()); + _file = _path; + } + return *this; + } + + const File& operator *() const + { + return _file; + } + + File& operator *() + { + return _file; + } + + const File* operator ->() const + { + return &_file; + } + + File* operator ->() + { + return &_file; + } + template friend inline bool operator ==(const RecursiveDirectoryIterator& a, const RecursiveDirectoryIterator& b); @@ -144,6 +243,7 @@ private: File _file; }; + // // friend comparsion operators // @@ -159,172 +259,6 @@ inline bool operator !=(const RecursiveDirectoryIterator& a, const Recursive return a.path().toString() != b.path().toString();; } -// -// inlines -// -template -inline const std::string& -RecursiveDirectoryIterator::name() const -{ - return _path.getFileName(); -} - -template -inline const Path& -RecursiveDirectoryIterator::path() const -{ - return _path; -} - -template -inline UInt16 RecursiveDirectoryIterator::depth() const -{ - return _pImpl->depth(); -} - -template -inline UInt16 RecursiveDirectoryIterator::maxDepth() const -{ - return _pImpl->maxDepth(); -} - -template -inline const File& -RecursiveDirectoryIterator::operator *() const -{ - return _file; -} - -template -inline File& -RecursiveDirectoryIterator::operator *() -{ - return _file; -} - -template -inline const File* -RecursiveDirectoryIterator::operator ->() const -{ - return &_file; -} - -template -inline File* -RecursiveDirectoryIterator::operator ->() -{ - return &_file; -} - -// -// not inlines -// -template -RecursiveDirectoryIterator::RecursiveDirectoryIterator() - : _pImpl(0) -{ -} - -template -RecursiveDirectoryIterator::RecursiveDirectoryIterator(const std::string& path, UInt16 maxDepth) - : _pImpl(new ImplType(path, maxDepth)), _path(Path(_pImpl->get())), _file(_path) -{ -} - -template -RecursiveDirectoryIterator::RecursiveDirectoryIterator(const MyType& iterator) - : _pImpl(iterator._pImpl), _path(iterator._path), _file(iterator._file) -{ -} - -template -RecursiveDirectoryIterator::RecursiveDirectoryIterator(const DirectoryIterator& iterator, UInt16 maxDepth) - : _pImpl(new ImplType(iterator->path(), maxDepth)), _path(Path(_pImpl->get())), _file(_path) -{ -} - -template -RecursiveDirectoryIterator::RecursiveDirectoryIterator(const File& file, UInt16 maxDepth) - : _pImpl(new ImplType(file.path(), maxDepth)), _path(Path(_pImpl->get())), _file(_path) -{ -} - -template -RecursiveDirectoryIterator::RecursiveDirectoryIterator(const Path& path, UInt16 maxDepth) - : _pImpl(new ImplType(path.toString(), maxDepth)), _path(Path(_pImpl->get())), _file(_path) -{ -} - -template -RecursiveDirectoryIterator::~RecursiveDirectoryIterator() -{ - if (_pImpl) - _pImpl->release(); -} - -template -RecursiveDirectoryIterator& -RecursiveDirectoryIterator::operator =(const MyType& it) -{ - if (_pImpl) - _pImpl->release(); - _pImpl = it._pImpl; - if (_pImpl) - { - _pImpl->duplicate(); - _path = it._path; - _file = _path; - } - return *this; -} - -template -RecursiveDirectoryIterator& -RecursiveDirectoryIterator::operator =(const File& file) -{ - if (_pImpl) - _pImpl->release(); - _pImpl = new ImplType(file.path()); - _path = Path(_pImpl->get()); - _file = _path; - return *this; -} - -template -RecursiveDirectoryIterator& -RecursiveDirectoryIterator::operator =(const Path& path) -{ - if (_pImpl) - _pImpl->release(); - _pImpl = new ImplType(path.toString()); - _path = Path(_pImpl->get()); - _file = _path; - return *this; -} - -template -RecursiveDirectoryIterator& -RecursiveDirectoryIterator::operator =(const std::string& path) -{ - if (_pImpl) - _pImpl->release(); - _pImpl = new ImplType(path); - _path = Path(_pImpl->get()); - _file = _path; - return *this; -} - -template -RecursiveDirectoryIterator& -RecursiveDirectoryIterator::operator ++() -{ - if (_pImpl) - { - _path = Path(_pImpl->next()); - _file = _path; - } - return *this; -} // // exported instances @@ -334,12 +268,14 @@ RecursiveDirectoryIterator ; template class Foundation_API RecursiveDirectoryIterator ; + // // typedefs // typedef RecursiveDirectoryIterator SimpleRecursiveDirectoryIterator; typedef RecursiveDirectoryIterator SiblingsFirstRecursiveDirectoryIterator; + } // namespace Poco #endif // Foundation_RecursiveDirectoryIterator_INCLUDE diff --git a/Foundation/include/Poco/RecursiveDirectoryIteratorImpl.h b/Foundation/include/Poco/RecursiveDirectoryIteratorImpl.h index d99c5a3fa..fa4d7193b 100644 --- a/Foundation/include/Poco/RecursiveDirectoryIteratorImpl.h +++ b/Foundation/include/Poco/RecursiveDirectoryIteratorImpl.h @@ -35,6 +35,7 @@ // DEALINGS IN THE SOFTWARE. // + #ifndef Foundation_RecursiveDirectoryIteratorImpl_INCLUDE #define Foundation_RecursiveDirectoryIteratorImpl_INCLUDE @@ -43,6 +44,7 @@ #include #include + namespace Poco { @@ -57,105 +59,72 @@ public: { D_INFINITE = 0 }; - /// Constant for infinite traverse depth. + /// Constant for infinite traverse depth. - RecursiveDirectoryIteratorImpl(const std::string& path, UInt16 maxDepth = D_INFINITE); - ~RecursiveDirectoryIteratorImpl(); + RecursiveDirectoryIteratorImpl(const std::string& path, UInt16 maxDepth = D_INFINITE) + : _maxDepth(maxDepth), _traverseStrategy(std::ptr_fun(depthFun), _maxDepth), _isFinished(false), _rc(1) + { + _itStack.push(DirectoryIterator(path)); + _current = _itStack.top()->path(); + } - void duplicate(); - void release(); - UInt16 depth() const; - UInt16 maxDepth() const; + ~RecursiveDirectoryIteratorImpl() + { + } - const std::string& get() const; - const std::string& next(); + inline void duplicate() + { + ++_rc; + } + + inline void release() + { + if (--_rc == 0) + delete this; + } + + inline UInt16 depth() const + { + return depthFun(_itStack); + } + + inline UInt16 maxDepth() const + { + return _maxDepth; + } + + inline const std::string& get() const + { + return _current; + } + const std::string& next() + { + if (_isFinished) + return _current; + + _current = _traverseStrategy.next(&_itStack, &_isFinished); + + return _current; + } private: typedef std::stack Stack; - static UInt16 depthFun(const Stack& stack); - /// Function which implements the logic of determining - /// recursion depth. + static UInt16 depthFun(const Stack& stack) + /// Function which implements the logic of determining + /// recursion depth. + { + return stack.size(); + } UInt16 _maxDepth; TTraverseStrategy _traverseStrategy; - bool _isFinished; - Stack _itStack; std::string _current; int _rc; }; -// -// inlines -// -template -inline void RecursiveDirectoryIteratorImpl::duplicate() -{ - ++_rc; -} - -template -inline void RecursiveDirectoryIteratorImpl::release() -{ - if (--_rc == 0) - delete this; -} - -template -inline UInt16 RecursiveDirectoryIteratorImpl::depth() const -{ - return depthFun(_itStack); -} - -template -inline UInt16 RecursiveDirectoryIteratorImpl::maxDepth() const -{ - return _maxDepth; -} - -template -inline const std::string& -RecursiveDirectoryIteratorImpl::get() const -{ - return _current; -} - -template -inline UInt16 RecursiveDirectoryIteratorImpl::depthFun(const Stack& stack) -{ - return stack.size(); -} - -// -// not inlines -// -template -RecursiveDirectoryIteratorImpl::RecursiveDirectoryIteratorImpl(const std::string& path, UInt16 maxDepth) - : _maxDepth(maxDepth), _traverseStrategy(std::ptr_fun(depthFun), _maxDepth), _isFinished(false) -{ - _itStack.push(DirectoryIterator(path)); - _current = _itStack.top()->path(); -} - -template -RecursiveDirectoryIteratorImpl::~RecursiveDirectoryIteratorImpl() -{ - -} - -template -const std::string& -RecursiveDirectoryIteratorImpl::next() -{ - if (_isFinished) - return _current; - - _current = _traverseStrategy.next(&_itStack, &_isFinished); - - return _current; -} } // namespace Poco diff --git a/Foundation/include/Poco/RecursiveDirectoryIteratorStrategies.h b/Foundation/include/Poco/RecursiveDirectoryIteratorStrategies.h index c3b6c2f45..7142ee9e5 100644 --- a/Foundation/include/Poco/RecursiveDirectoryIteratorStrategies.h +++ b/Foundation/include/Poco/RecursiveDirectoryIteratorStrategies.h @@ -35,6 +35,7 @@ // DEALINGS IN THE SOFTWARE. // + #ifndef Foundation_RecursiveDirectoryIteratorStategies_INCLUDE #define Foundation_RecursiveDirectoryIteratorStategies_INCLUDE @@ -44,6 +45,7 @@ #include #include + namespace Poco { @@ -57,7 +59,7 @@ public: { D_INFINITE = 0 }; - /// Constant for infinite traverse depth. + /// Constant for infinite traverse depth. TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth = D_INFINITE); @@ -66,7 +68,6 @@ protected: DepthFunPtr _depthDeterminer; UInt16 _maxDepth; - DirectoryIterator _itEnd; private: @@ -75,6 +76,7 @@ private: TraverseBase& operator=(const TraverseBase&); }; + class ChildrenFirstTraverse: public TraverseBase { public: @@ -88,6 +90,7 @@ private: ChildrenFirstTraverse& operator=(const ChildrenFirstTraverse&); }; + class SiblingsFirstTraverse: public TraverseBase { public: @@ -103,6 +106,7 @@ private: std::stack > _dirsStack; }; + } // namespace Poco #endif // Foundation_RecursiveDirectoryIteratorStategies_INCLUDE diff --git a/Foundation/include/Poco/SortedDirectoryIterator.h b/Foundation/include/Poco/SortedDirectoryIterator.h index 4c42aac7b..4b6684d21 100644 --- a/Foundation/include/Poco/SortedDirectoryIterator.h +++ b/Foundation/include/Poco/SortedDirectoryIterator.h @@ -39,7 +39,6 @@ #ifndef Foundation_SortedDirectoryIterator_INCLUDED #define Foundation_SortedDirectoryIterator_INCLUDED - #include "Poco/Foundation.h" #include "Poco/File.h" #include "Poco/Path.h" @@ -47,49 +46,47 @@ #include -namespace Poco { +namespace Poco +{ - -class Foundation_API SortedDirectoryIterator : public DirectoryIterator - /// The SortedDirectoryIterator class is similar to - /// DirectoryIterator class, but places directories before files - /// and sorts content alphabetically. +class Foundation_API SortedDirectoryIterator: public DirectoryIterator + /// The SortedDirectoryIterator class is similar to + /// DirectoryIterator class, but places directories before files + /// and sorts content alphabetically. { public: - SortedDirectoryIterator(); - /// Creates the end iterator. + SortedDirectoryIterator(); + /// Creates the end iterator. - SortedDirectoryIterator(const std::string& path); - /// Creates a directory iterator for the given path. + SortedDirectoryIterator(const std::string& path); + /// Creates a directory iterator for the given path. - SortedDirectoryIterator(const DirectoryIterator& iterator); - /// Creates a directory iterator for the given path. + SortedDirectoryIterator(const DirectoryIterator& iterator); + /// Creates a directory iterator for the given path. - SortedDirectoryIterator(const File& file); - /// Creates a directory iterator for the given file. + SortedDirectoryIterator(const File& file); + /// Creates a directory iterator for the given file. - SortedDirectoryIterator(const Path& path); - /// Creates a directory iterator for the given path. + SortedDirectoryIterator(const Path& path); + /// Creates a directory iterator for the given path. - virtual ~SortedDirectoryIterator(); - /// Destroys the DirsFirstDirectoryIterator. + virtual ~SortedDirectoryIterator(); + /// Destroys the DirsFirstDirectoryIterator. - virtual SortedDirectoryIterator& operator ++ (); // prefix + virtual SortedDirectoryIterator& operator ++(); // prefix private: - bool _is_finished; - std::deque _directories; - std::deque _files; + bool _is_finished; + std::deque _directories; + std::deque _files; - void next(); - /// Take next item - void scan(); - /// Scan directory to collect its children directories and files + void next(); + /// Take next item + void scan(); + /// Scan directory to collect its children directories and files }; } // namespace Poco - #endif //Foundation_SortedDirectoryIterator_INCLUDED - diff --git a/Foundation/src/RecursiveDirectoryIterator.cpp b/Foundation/src/RecursiveDirectoryIterator.cpp deleted file mode 100644 index 9037df0f6..000000000 --- a/Foundation/src/RecursiveDirectoryIterator.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Poco/RecursiveDirectoryIterator.h" - -namespace Poco { - - -} diff --git a/Foundation/src/RecursiveDirectoryIteratorStrategies.cpp b/Foundation/src/RecursiveDirectoryIteratorStrategies.cpp index 774e3748c..c5093ef16 100644 --- a/Foundation/src/RecursiveDirectoryIteratorStrategies.cpp +++ b/Foundation/src/RecursiveDirectoryIteratorStrategies.cpp @@ -33,8 +33,10 @@ // DEALINGS IN THE SOFTWARE. // + #include "Poco/RecursiveDirectoryIteratorStrategies.h" + namespace Poco { @@ -44,23 +46,26 @@ using namespace std; // TraverseBase // TraverseBase::TraverseBase(DepthFunPtr depthDeterminer, UInt16 maxDepth) - : _depthDeterminer(depthDeterminer), _maxDepth(maxDepth) + : _depthDeterminer(depthDeterminer), _maxDepth(maxDepth) { } + inline bool TraverseBase::isFiniteDepth() { return _maxDepth != D_INFINITE; } + // // ChildrenFirstTraverse // ChildrenFirstTraverse::ChildrenFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth) - : TraverseBase(depthDeterminer, maxDepth) + : TraverseBase(depthDeterminer, maxDepth) { } + const string ChildrenFirstTraverse::next(Stack* itStack, bool* isFinished) { // pointer mustn't point to NULL and iteration mustn't be finished @@ -108,15 +113,17 @@ const string ChildrenFirstTraverse::next(Stack* itStack, bool* isFinished) return itStack->top()->path(); } + // // SiblingsFirstTraverse // SiblingsFirstTraverse::SiblingsFirstTraverse(DepthFunPtr depthDeterminer, UInt16 maxDepth) - : TraverseBase(depthDeterminer, maxDepth) + : TraverseBase(depthDeterminer, maxDepth) { _dirsStack.push(queue()); } + const string SiblingsFirstTraverse::next(Stack* itStack, bool* isFinished) { // pointer mustn't point to NULL and iteration mustn't be finished @@ -168,4 +175,5 @@ const string SiblingsFirstTraverse::next(Stack* itStack, bool* isFinished) return itStack->top()->path(); } + } // namespace Poco diff --git a/Foundation/src/SortedDirectoryIterator.cpp b/Foundation/src/SortedDirectoryIterator.cpp index 0bcd57dbb..73131d2cd 100644 --- a/Foundation/src/SortedDirectoryIterator.cpp +++ b/Foundation/src/SortedDirectoryIterator.cpp @@ -33,49 +33,48 @@ // DEALINGS IN THE SOFTWARE. // - #include "Poco/SortedDirectoryIterator.h" #include -namespace Poco { - +namespace Poco +{ SortedDirectoryIterator::SortedDirectoryIterator() - : DirectoryIterator(), _is_finished(true) + : DirectoryIterator(), _is_finished(true) { } SortedDirectoryIterator::SortedDirectoryIterator(const std::string& path) - : DirectoryIterator(path), _is_finished(false) + : DirectoryIterator(path), _is_finished(false) { - scan(); - next(); + scan(); + next(); } SortedDirectoryIterator::SortedDirectoryIterator(const DirectoryIterator& iterator) - : DirectoryIterator(iterator), _is_finished(false) + : DirectoryIterator(iterator), _is_finished(false) { - scan(); - next(); + scan(); + next(); } SortedDirectoryIterator::SortedDirectoryIterator(const File& file) - : DirectoryIterator(file), _is_finished(false) + : DirectoryIterator(file), _is_finished(false) { - scan(); - next(); + scan(); + next(); } SortedDirectoryIterator::SortedDirectoryIterator(const Path& path) - : DirectoryIterator(path), _is_finished(false) + : DirectoryIterator(path), _is_finished(false) { - scan(); - next(); + scan(); + next(); } @@ -83,56 +82,56 @@ SortedDirectoryIterator::~SortedDirectoryIterator() { } - -SortedDirectoryIterator& SortedDirectoryIterator::operator ++ () +SortedDirectoryIterator& SortedDirectoryIterator::operator ++() { - if (!_is_finished) - { - next(); - } - return *this; + if (!_is_finished) + { + next(); + } + return *this; } void SortedDirectoryIterator::scan() { - DirectoryIterator end_it; - while (*this != end_it) - { - if ((*this)->isDirectory()) - _directories.push_back(_path.toString()); - else - _files.push_back(_path.toString()); + DirectoryIterator end_it; + while (*this != end_it) + { + if ((*this)->isDirectory()) + _directories.push_back(_path.toString()); + else + _files.push_back(_path.toString()); - DirectoryIterator::operator++(); - } + DirectoryIterator::operator++(); + } - std::sort(_directories.begin(), _directories.end()); - std::sort(_files.begin(), _files.end()); + std::sort(_directories.begin(), _directories.end()); + std::sort(_files.begin(), _files.end()); } void SortedDirectoryIterator::next() { - DirectoryIterator end_it; - if (!_directories.empty()) - { - _path.assign(_directories.front()); - _directories.pop_front(); - _file = _path; - } - else if (!_files.empty()) - { - _path.assign(_files.front()); - _files.pop_front(); - _file = _path; - } - else - { - _is_finished = true; - _path = end_it.path(); - _file = _path; - } + DirectoryIterator end_it; + if (!_directories.empty()) + { + _path.assign(_directories.front()); + _directories.pop_front(); + _file = _path; + } + else if (!_files.empty()) + { + _path.assign(_files.front()); + _files.pop_front(); + _file = _path; + } + else + { + _is_finished = true; + _path = end_it.path(); + _file = _path; + } } + } // namespace Poco