aboutsummaryrefslogtreecommitdiff
path: root/src/filesystem.cpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2018-11-26 23:19:40 +0100
committerFelix Morgner <felix.morgner@gmail.com>2018-11-26 23:19:40 +0100
commit97390d565eca8004edb1d262c282aaf9e47c3b7b (patch)
tree7590e094e17a9e8732fc48b76b8f38c4ba866e9b /src/filesystem.cpp
parentbae92cea3bcbacd7883499da61a0e54f13da6d23 (diff)
downloadwanda-97390d565eca8004edb1d262c282aaf9e47c3b7b.tar.xz
wanda-97390d565eca8004edb1d262c282aaf9e47c3b7b.zip
fs: implement filesystem access
Diffstat (limited to 'src/filesystem.cpp')
-rw-r--r--src/filesystem.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/filesystem.cpp b/src/filesystem.cpp
new file mode 100644
index 0000000..4dfa183
--- /dev/null
+++ b/src/filesystem.cpp
@@ -0,0 +1,30 @@
+#include "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