FileLister now features a non-recursive mode. (files missing from previous changeset)

This commit is contained in:
Alexander Mai 2015-03-05 06:53:11 +01:00
parent b5f0eec44a
commit 161f5ff6d2
2 changed files with 35 additions and 11 deletions

View File

@ -189,10 +189,12 @@ std::string FileLister::getAbsolutePath(const std::string& path)
return absolute_path; return absolute_path;
} }
void FileLister::recursiveAddFiles2(std::set<std::string> &seen_paths, void FileLister::addFiles2(std::set<std::string> &seen_paths,
std::map<std::string, std::size_t> &files, std::map<std::string, std::size_t> &files,
const std::string &path, const std::string &path,
const std::set<std::string> &extra) const std::set<std::string> &extra,
bool recursive
)
{ {
std::ostringstream oss; std::ostringstream oss;
oss << path; oss << path;
@ -228,11 +230,11 @@ void FileLister::recursiveAddFiles2(std::set<std::string> &seen_paths,
} else } else
files[filename] = 0; files[filename] = 0;
} }
} else { } else if (recursive) {
// Directory // Directory
seen_paths.insert(absolute_path); seen_paths.insert(absolute_path);
recursiveAddFiles2(seen_paths, files, filename, extra); addFiles2(seen_paths, files, filename, extra, recursive);
} }
} }
globfree(&glob_results); globfree(&glob_results);
@ -242,7 +244,13 @@ void FileLister::recursiveAddFiles2(std::set<std::string> &seen_paths,
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra) void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra)
{ {
std::set<std::string> seen_paths; std::set<std::string> seen_paths;
recursiveAddFiles2(seen_paths, files, path, extra); addFiles2(seen_paths, files, path, extra, true);
}
void FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, bool recursive)
{
std::set<std::string> seen_paths;
addFiles2(seen_paths, files, path, extra, recursive);
} }
bool FileLister::isDirectory(const std::string &path) bool FileLister::isDirectory(const std::string &path)

View File

@ -53,6 +53,18 @@ public:
*/ */
static void recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra); static void recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &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<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, bool recursive);
/** /**
* @brief Is given path a directory? * @brief Is given path a directory?
* @return returns true if the path is a directory * @return returns true if the path is a directory
@ -68,11 +80,15 @@ public:
#ifndef _WIN32 #ifndef _WIN32
static std::string getAbsolutePath(const std::string& path); static std::string getAbsolutePath(const std::string& path);
static void recursiveAddFiles2(std::set<std::string> &seen_paths, private:
static void addFiles2(std::set<std::string> &seen_paths,
std::map<std::string, std::size_t> &files, std::map<std::string, std::size_t> &files,
const std::string &path, const std::string &path,
const std::set<std::string> &extra); const std::set<std::string> &extra,
bool recursive);
#endif #endif
}; };
/// @} /// @}