From 6d84be2051ad471323a34041b2d153b1e2733419 Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Thu, 18 Feb 2016 15:38:33 +0100 Subject: [PATCH] working on directory_only_iterator --- include/nana/filesystem/filesystem.hpp | 13 +++--- include/nana/filesystem/filesystem_ext.hpp | 48 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index 61ce8223..88b9dbd0 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -297,15 +297,12 @@ namespace nana { namespace experimental { namespace filesystem std::uintmax_t file_size(const path& p); //uintmax_t file_size(const path& p, error_code& ec) noexcept; - inline bool is_directory(file_status s) { return s.type() == file_type::directory ;} - bool is_directory(const path& p); - inline bool is_directory(const directory_entry& d) - { - return is_directory(d.status()); - } - //bool is_directory(const path& p, error_code& ec) noexcept; + inline bool is_directory(file_status s) noexcept + { return s.type() == file_type::directory ;} - //bool is_regular_file(file_status s) noexcept; + bool is_directory(const path& p); + + //bool is_directory(const path& p, error_code& ec) noexcept; inline bool is_empty(const path& p) { diff --git a/include/nana/filesystem/filesystem_ext.hpp b/include/nana/filesystem/filesystem_ext.hpp index 0e75b249..35aeec7c 100644 --- a/include/nana/filesystem/filesystem_ext.hpp +++ b/include/nana/filesystem/filesystem_ext.hpp @@ -26,18 +26,56 @@ namespace nana {namespace experimental {namespace filesystem {namespace ext { constexpr auto def_rootname = "Root/"; #endif -// nana::experimental::filesystem::path_user()); // REPLACE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! to filesystem_ext.hhp +// nana::experimental::filesystem::path_user()); // REPLACE !!!!!!!!!! to filesystem_ext.hhp -template // DI = directory_iterator from std, boost, or nana +inline bool is_directory(const directory_entry& d) noexcept +{ + return is_directory(d.status()); +} + + +template // DI = directory_iterator from std, boost, or nana : return directory_entry class directory_only_iterator : public DI { - // if (!this->is_directory()) continue; + DI& find_first() + { + while(( (*this) != DI{}) || !is_directory((*this)) ) + this->DI::operator++(); + return (*this); + } +public: + template + directory_only_iterator(Arg&&... arg ): DI(std::forward(arg)...) + { + find_first(); + } + directory_only_iterator& operator++() + { + this->DI::operator++(); + return find_first(); + } }; -template // DI = directory_iterator from std, boost, or nana +template // DI = directory_iterator from std, boost, or nana : value_type directory_entry class regular_file_only_iterator : public DI { - // if (this->is_directory()) continue; + DI& find_first() + { + while(( (*this) != DI{}) || !is_regular_file(*this) ) + this->DI::operator++(); + return (*this); + } +public: + template + regular_file_only_iterator(Arg&&... arg ): DI(std::forward(arg)...) + { + find_first(); + } + regular_file_only_iterator& operator++() + { + this->DI::operator++(); + return find_first(); + } }; }}}}