diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2022-09-16 23:28:09 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2022-09-16 23:28:09 +0200 |
| commit | f4d9880d3c9555b48affad727589ef5c093b1841 (patch) | |
| tree | a5552b5a33000a527748ac1c72ca366476af0936 /source/lib/include/wanda/filesystem.hpp | |
| parent | 64922e213ac731279cf3341253e67509adb2dfc8 (diff) | |
| download | wanda-f4d9880d3c9555b48affad727589ef5c093b1841.tar.xz wanda-f4d9880d3c9555b48affad727589ef5c093b1841.zip | |
source: clean up structure
Diffstat (limited to 'source/lib/include/wanda/filesystem.hpp')
| -rw-r--r-- | source/lib/include/wanda/filesystem.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/source/lib/include/wanda/filesystem.hpp b/source/lib/include/wanda/filesystem.hpp new file mode 100644 index 0000000..1975bc5 --- /dev/null +++ b/source/lib/include/wanda/filesystem.hpp @@ -0,0 +1,39 @@ +/** + * @file filesystem.hpp + * @author Felix Morgner (felix.morgner@gmail.com) + * @since 1.0.0 + */ + +#ifndef WANDA_FILESYSTEM_HPP +#define WANDA_FILESYSTEM_HPP + +#include <filesystem> +#include <optional> +#include <vector> + +namespace wanda +{ + /** + * @brief Covenience alias for path lists + */ + using path_list = std::vector<std::filesystem::path>; + + /** + * @brief The default scan filter, allowing only regular files to pass + */ + constexpr inline auto default_filter = [](std::filesystem::path const & path) { + return is_regular_file(path); + }; + + /** + * @brief Scan the given folder for files + */ + std::optional<path_list> scan(std::filesystem::path folder, bool(filter)(std::filesystem::path const &) = default_filter); + + /** + * @brief Pick a random path from the given list + */ + std::filesystem::path random_pick(path_list const & paths); +} // namespace wanda + +#endif
\ No newline at end of file |
