18 static_assert(std::is_same<iterator_t, recursive_directory_iterator>::value ||
19 std::is_same<iterator_t, directory_iterator>::value,
20 "T must be a valid directory iterator type");
22 using clock_t = std::chrono::steady_clock;
26 cache(
const fs::path& p, clock_t::duration scan_frequency)
28 , scan_frequency_(scan_frequency)
29 , should_refresh_(true)
37 , scan_frequency_(scan_frequency)
38 , should_refresh_(true)
45 , scan_frequency_(rhs.scan_frequency_)
46 , entries_(rhs.entries_)
47 , should_refresh_(rhs.should_refresh_.
load())
48 , filter_(rhs.filter_)
54 : path_(std::move(rhs.path_))
55 , scan_frequency_(rhs.scan_frequency_)
56 , entries_(std::move(rhs.entries_))
57 , should_refresh_(rhs.should_refresh_.load())
58 , filter_(std::move(rhs.filter_))
67 scan_frequency_ = rhs.scan_frequency_;
68 entries_ = rhs.entries_;
69 should_refresh_ = rhs.should_refresh_.load();
70 filter_ = rhs.filter_;
79 path_ = std::move(rhs.path_);
80 scan_frequency_ = std::move(rhs.scan_frequency_);
81 entries_ = std::move(rhs.entries_);
82 should_refresh_ = rhs.should_refresh_.load();
83 filter_ = std::move(rhs.filter_);
106 return entries_.begin();
115 decltype(
auto)
end()
const
117 return entries_.end();
132 return entries_.size();
141 decltype(
auto)
at(
size_t idx)
const
143 return entries_.at(idx);
145 decltype(
auto)
operator[](
size_t idx)
const
147 return entries_[idx];
165 for(
const auto& p : it)
173 entries_.emplace_back();
177 auto filename = absolute_path.filename();
184 std::sort(std::begin(entries_),
186 [](
const auto& lhs,
const auto& rhs)
188 return fs::is_directory(lhs.entry.status()) > fs::is_directory(rhs.entry.status());
191 should_refresh_ =
false;
208 should_refresh_ =
true;
214 if(scan_frequency_ == scan_frequency)
219 scan_frequency_ = scan_frequency;
220 should_refresh_ =
true;
240 bool should_refresh()
const
242 return should_refresh_;
247 using namespace std::literals;
248 constexpr bool is_recursive = std::is_same<iterator_t, recursive_directory_iterator>::value;
255 [
this](
const auto&,
bool)
257 should_refresh_ =
true;
269 clock_t::duration scan_frequency_ = std::chrono::milliseconds(500);
271 mutable std::vector<cache_entry> entries_;
273 mutable std::atomic_bool should_refresh_ = {
true};
275 std::uint64_t watch_id_ = 0;
277 pattern_filter filter_;
291template<
typename Iterator = recursive_directory_iterator>
293 const std::vector<std::string>& includes,
294 const std::vector<std::string>& excludes = {},
295 std::chrono::steady_clock::duration scan_frequency = std::chrono::milliseconds(500))
void * load(bx::FileReaderI *_reader, bx::AllocatorI *_allocator, const char *_filePath, uint32_t *_size)
void set_scan_frequency(clock_t::duration scan_frequency)
cache & operator=(cache &&rhs) noexcept
cache(const fs::path &p, clock_t::duration scan_frequency)
const fs::path & get_path() const
void set_path(const fs::path &path, const fs::pattern_filter &filter)
decltype(auto) size() const
Returns the size for the underlying cached container.
std::chrono::steady_clock clock_t
cache(const fs::path &p, const pattern_filter &filter, clock_t::duration scan_frequency)
decltype(auto) at(size_t idx) const
Directly index into the underlying cached container.
decltype(auto) begin() const
Returns the begin iterator for the underlying cached container and also refreshes the container if ne...
decltype(auto) end() const
Returns the end iterator for the underlying cached container.
cache & operator=(const cache &rhs)
cache(cache &&rhs) noexcept
void refresh() const
Refreshes the cache and updates the timestamp of the last refresh. This operation is slow so try to n...
A filter that combines include and exclude patterns for file/directory filtering.
auto should_include(const fs::path &path) const -> bool
Tests if a path should be included based on the filter rules Logic: (matches any include pattern OR n...
static void unwatch(std::uint64_t key)
Un-watches a previously registered file or directory.
static auto watch(const fs::path &path, const pattern_filter &filter, bool recursive, bool initial_list, clock_t::duration poll_interval, notify_callback callback) -> std::uint64_t
Watches a file or directory for modification and call back the specified std::function....
auto make_filtered_cache(const fs::path &path, const std::vector< std::string > &includes, const std::vector< std::string > &excludes={}, std::chrono::steady_clock::duration scan_frequency=std::chrono::milliseconds(500)) -> cache< Iterator >
Convenience function to create a directory cache with pattern filtering.
auto make_pattern_filter(const std::string &pattern) -> pattern_filter
Convenience function to create a pattern filter from a single wildcard string Maintains backward comp...
path convert_to_protocol(const path &_path)
Oposite of the resolve_protocol this function tries to convert to protocol path from an absolute one.
std::string protocol_path