From ed419140280553b070943b7ba539120a26ff5686 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 11 Dec 2018 07:42:05 +0100 Subject: wanda: restructure directory hierarchy --- src/wanda/filesystem.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/wanda/filesystem.cpp (limited to 'src/wanda/filesystem.cpp') diff --git a/src/wanda/filesystem.cpp b/src/wanda/filesystem.cpp new file mode 100644 index 0000000..01dff43 --- /dev/null +++ b/src/wanda/filesystem.cpp @@ -0,0 +1,29 @@ +#include + +#include + +#include + +namespace wanda +{ + std::optional scan(std::filesystem::path source, bool(filter)(std::filesystem::path const &)) + { + if (!std::filesystem::is_directory(source)) + { + return std::nullopt; + } + + auto first = boost::make_filter_iterator(filter, std::filesystem::recursive_directory_iterator{source}); + auto last = boost::make_filter_iterator(filter, std::filesystem::recursive_directory_iterator{}); + return path_list{first, last}; + } + + std::filesystem::path random_pick(path_list const & paths) + { + static auto generator = std::mt19937{std::random_device{}()}; + auto distribution = std::uniform_int_distribution{0, paths.size() - 1}; + + return paths[distribution(generator)]; + } + +} // namespace wanda \ No newline at end of file -- cgit v1.2.3