From 90f99a75d529d24201a8b66565cd7c48bb94ba47 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Fri, 2 Oct 2020 17:35:48 +0200 Subject: [PATCH] scan with callback --- inc/files.h | 2 ++ src/Files.cpp | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/inc/files.h b/inc/files.h index a6069df..50e31bb 100644 --- a/inc/files.h +++ b/inc/files.h @@ -25,7 +25,9 @@ enum class FileType : unsigned char { }; typedef std::function fileNameFilter; +typedef std::function fileCallback; template bool scan(const std::string& path, std::insert_iterator it, bool prefixdir = false, fileNameFilter fnf = fileNameFilter(nullptr)); +bool scan(const std::string& path, fileCallback clb, bool prefixdir = false, fileNameFilter fnf = fileNameFilter(nullptr)); } \ No newline at end of file diff --git a/src/Files.cpp b/src/Files.cpp index 9c18f27..06c92f6 100644 --- a/src/Files.cpp +++ b/src/Files.cpp @@ -42,6 +42,15 @@ void mrbesen::Files::extention(const std::string& path, std::string& ext) { template bool mrbesen::Files::scan(const std::string& path, std::insert_iterator it, bool prefixdir, fileNameFilter fnf) { + return scan(path, [&](const std::string& p, FileType t){ it = p; }, prefixdir, fnf); +} + +//curently only these are supported, because iterators may break on others upon insertion +template bool mrbesen::Files::scan>(const std::string&, std::insert_iterator>, bool, fileNameFilter); +template bool mrbesen::Files::scan>(const std::string&, std::insert_iterator>, bool, fileNameFilter); +template bool mrbesen::Files::scan>(const std::string&, std::insert_iterator>, bool, fileNameFilter); + +bool mrbesen::Files::scan(const std::string& path, fileCallback clb, bool prefixdir, fileNameFilter fnf) { std::string path_ = path; mrbesen::Util::insertEnd(path_, "/"); @@ -62,18 +71,10 @@ bool mrbesen::Files::scan(const std::string& path, std::insert_iterator>(const std::string&, std::insert_iterator>, bool, fileNameFilter); -template bool mrbesen::Files::scan>(const std::string&, std::insert_iterator>, bool, fileNameFilter); -template bool mrbesen::Files::scan>(const std::string&, std::insert_iterator>, bool, fileNameFilter); - -