From 161f5ff6d2cb9388c41c66cc3f32df3c22c1b719 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Thu, 5 Mar 2015 06:53:11 +0100 Subject: [PATCH] FileLister now features a non-recursive mode. (files missing from previous changeset) --- cli/filelister.cpp | 22 +++++++++++++++------- cli/filelister.h | 24 ++++++++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/cli/filelister.cpp b/cli/filelister.cpp index 88d92595d..d76aa7767 100644 --- a/cli/filelister.cpp +++ b/cli/filelister.cpp @@ -189,10 +189,12 @@ std::string FileLister::getAbsolutePath(const std::string& path) return absolute_path; } -void FileLister::recursiveAddFiles2(std::set &seen_paths, - std::map &files, - const std::string &path, - const std::set &extra) +void FileLister::addFiles2(std::set &seen_paths, + std::map &files, + const std::string &path, + const std::set &extra, + bool recursive + ) { std::ostringstream oss; oss << path; @@ -228,11 +230,11 @@ void FileLister::recursiveAddFiles2(std::set &seen_paths, } else files[filename] = 0; } - } else { + } else if (recursive) { // Directory seen_paths.insert(absolute_path); - recursiveAddFiles2(seen_paths, files, filename, extra); + addFiles2(seen_paths, files, filename, extra, recursive); } } globfree(&glob_results); @@ -242,7 +244,13 @@ void FileLister::recursiveAddFiles2(std::set &seen_paths, void FileLister::recursiveAddFiles(std::map &files, const std::string &path, const std::set &extra) { std::set seen_paths; - recursiveAddFiles2(seen_paths, files, path, extra); + addFiles2(seen_paths, files, path, extra, true); +} + +void FileLister::addFiles(std::map &files, const std::string &path, const std::set &extra, bool recursive) +{ + std::set seen_paths; + addFiles2(seen_paths, files, path, extra, recursive); } bool FileLister::isDirectory(const std::string &path) diff --git a/cli/filelister.h b/cli/filelister.h index 15757437a..6d5cbbe2c 100644 --- a/cli/filelister.h +++ b/cli/filelister.h @@ -53,6 +53,18 @@ public: */ static void recursiveAddFiles(std::map &files, const std::string &path, const std::set &extra); + /** + * @brief (Recursively) add source files to a map. + * Add source files from given directory and all subdirectries to the + * given map. Only files with accepted extensions + * (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added. + * @param files output map that associates the size of each file with its name + * @param path root path + * @param extra Extra file extensions + * @param extra recursive Enable recursion + */ + static void addFiles(std::map &files, const std::string &path, const std::set &extra, bool recursive); + /** * @brief Is given path a directory? * @return returns true if the path is a directory @@ -68,11 +80,15 @@ public: #ifndef _WIN32 static std::string getAbsolutePath(const std::string& path); - static void recursiveAddFiles2(std::set &seen_paths, - std::map &files, - const std::string &path, - const std::set &extra); +private: + + static void addFiles2(std::set &seen_paths, + std::map &files, + const std::string &path, + const std::set &extra, + bool recursive); #endif + }; /// @}