aboutsummaryrefslogtreecommitdiff
path: root/source/lib/include/wanda/filesystem.hpp
blob: 1975bc5af1b5c30e6961db9e24e1e0eedbd69d57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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