diff options
Diffstat (limited to 'src/wanda/filesystem.cpp')
| -rw-r--r-- | src/wanda/filesystem.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 <wanda/filesystem.hpp> + +#include <boost/iterator/filter_iterator.hpp> + +#include <random> + +namespace wanda +{ + std::optional<path_list> 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<std::size_t>{0, paths.size() - 1}; + + return paths[distribution(generator)]; + } + +} // namespace wanda
\ No newline at end of file |
