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_))
68 scan_frequency_ = rhs.scan_frequency_;
69 entries_ = rhs.entries_;
70 should_refresh_ = rhs.should_refresh_.load();
71 filter_ = rhs.filter_;
81 path_ = std::move(rhs.path_);
82 scan_frequency_ = std::move(rhs.scan_frequency_);
83 entries_ = std::move(rhs.entries_);
84 should_refresh_ = rhs.should_refresh_.load();
85 filter_ = std::move(rhs.filter_);
108 return entries_.begin();
117 decltype(
auto)
end()
const
119 return entries_.end();
134 return entries_.size();
143 decltype(
auto)
at(
size_t idx)
const
145 return entries_.at(idx);
147 decltype(
auto)
operator[](
size_t idx)
const
149 return entries_[idx];
167 for(
const auto& p : it)
175 entries_.emplace_back();
179 auto filename = absolute_path.filename();
186 std::sort(std::begin(entries_),
188 [](
const auto& lhs,
const auto& rhs)
190 return fs::is_directory(lhs.entry.status()) > fs::is_directory(rhs.entry.status());
193 should_refresh_ =
false;
206 should_refresh_ =
true;
218 should_refresh_ =
true;
224 if(scan_frequency_ == scan_frequency)
229 scan_frequency_ = scan_frequency;
230 should_refresh_ =
true;
250 bool should_refresh()
const
252 return should_refresh_;
257 using namespace std::literals;
258 constexpr bool is_recursive = std::is_same<iterator_t, recursive_directory_iterator>::value;
265 [
this](
const auto&,
bool)
267 should_refresh_ =
true;
268 },
"directory_cache");
283 clock_t::duration scan_frequency_ = std::chrono::milliseconds(500);
285 mutable std::vector<cache_entry> entries_;
287 mutable std::atomic_bool should_refresh_ = {
true};
289 std::uint64_t watch_id_ = 0;
291 pattern_filter filter_;
305template<
typename Iterator = recursive_directory_iterator>
307 const std::vector<std::string>& includes,
308 const std::vector<std::string>& excludes = {},
309 std::chrono::steady_clock::duration scan_frequency = std::chrono::milliseconds(500))
void * load(bx::FileReaderI *_reader, bx::AllocatorI *_allocator, const bx::FilePath &_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, const std::string &watcher_name="") -> std::uint64_t
Watches a file or directory for modification and call back the specified std::function....
const fs::path * filename
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