PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
filesystem_snapshot_internal.h
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <filesystem>
6#include <memory>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace pixelbullet::filesystem
13{
15{
16 std::string logical_path;
17 std::filesystem::path physical_path;
18 bool exists = false;
19 std::optional<std::filesystem::file_time_type> last_write_time;
20};
21
23{
24 std::string logical_path;
25 std::filesystem::path physical_path;
26};
27
28enum class NativeFileSnapshotBatchMode
29{
30 None,
31 BatchedExact,
32 BatchedWithFallback,
33 PerRecordFallback,
34};
35
36enum class NativeSnapshotBackend
37{
38 None,
39 StdFilesystem,
40 NativeWin32,
41 Fallback,
42};
43
44class NativeSnapshotProbeCache
45{
46public:
47 NativeSnapshotProbeCache();
48 ~NativeSnapshotProbeCache();
49 NativeSnapshotProbeCache(NativeSnapshotProbeCache&&) noexcept;
50 NativeSnapshotProbeCache& operator=(NativeSnapshotProbeCache&&) noexcept;
51 NativeSnapshotProbeCache(const NativeSnapshotProbeCache&) = delete;
52 NativeSnapshotProbeCache& operator=(const NativeSnapshotProbeCache&) = delete;
53
54 void Clear() noexcept;
55
56private:
57 struct Impl;
58 std::unique_ptr<Impl> impl_;
59
60 friend struct NativeSnapshotProbeCacheAccess;
61};
62
64{
65 bool collect_trusted_watched_directories = true;
66 NativeSnapshotProbeCache* probe_cache = nullptr;
67};
68
70{
71 std::vector<NativeFileSnapshot> snapshots;
72 std::vector<std::filesystem::path> watched_directories;
73 bool watched_directories_trusted = false;
74 NativeFileSnapshotBatchMode mode = NativeFileSnapshotBatchMode::None;
75 NativeSnapshotBackend backend = NativeSnapshotBackend::None;
76 std::size_t request_count = 0u;
77 std::size_t directory_group_count = 0u;
78 std::size_t fallback_count = 0u;
79 std::size_t probe_cache_hit_count = 0u;
80 std::size_t probe_cache_miss_count = 0u;
81 std::size_t probe_cache_reused_entry_count = 0u;
82 float directory_enumeration_milliseconds = 0.0f;
83 float fallback_milliseconds = 0.0f;
84 float trusted_directory_milliseconds = 0.0f;
85 float snapshot_assembly_milliseconds = 0.0f;
86};
87
89{
90 std::string logical_path;
91 std::filesystem::path physical_path;
92 bool exists = false;
93 bool is_directory = false;
94 std::optional<std::int64_t> last_write_time_ticks;
95 std::string detail;
96};
97
99{
100 std::string logical_path;
101 std::filesystem::path physical_path;
102};
103
104enum class NativeDirectorySnapshotBatchMode
105{
106 None,
107 BatchedExact,
108 BatchedWithFallback,
109 PerRecordFallback,
110};
111
113{
114 std::vector<NativeDirectorySnapshot> snapshots;
115 NativeDirectorySnapshotBatchMode mode = NativeDirectorySnapshotBatchMode::None;
116 NativeSnapshotBackend backend = NativeSnapshotBackend::None;
117 std::size_t request_count = 0u;
118 std::size_t parent_directory_group_count = 0u;
119 std::size_t fallback_count = 0u;
120 std::size_t probe_cache_hit_count = 0u;
121 std::size_t probe_cache_miss_count = 0u;
122 std::size_t probe_cache_reused_entry_count = 0u;
123 float parent_directory_enumeration_milliseconds = 0.0f;
124 float fallback_milliseconds = 0.0f;
125 float snapshot_assembly_milliseconds = 0.0f;
126};
127
129{
130 std::string logical_path;
131 std::filesystem::path physical_path;
132 std::string directory_name_key;
133};
134
136{
137 std::filesystem::path parent_directory;
138 std::vector<std::size_t> entry_indices;
139};
140
142{
143 std::vector<NativeDirectorySnapshotPlanEntry> entries;
144 std::vector<NativeDirectorySnapshotPlanGroup> groups;
145};
146
147[[nodiscard]] std::int64_t FileTimeToTicks(std::filesystem::file_time_type time) noexcept;
148[[nodiscard]] std::filesystem::file_time_type FileTimeFromTicks(std::int64_t ticks) noexcept;
149[[nodiscard]] std::string_view ToString(NativeSnapshotBackend backend) noexcept;
150[[nodiscard]] bool CaptureDirectoryWriteTimeTicks(const std::filesystem::path& directory, std::int64_t& ticks, std::string& detail);
151[[nodiscard]] NativeDirectorySnapshot CaptureDirectoryWriteTimeSnapshot(std::string logical_path, const std::filesystem::path& directory);
153CaptureDirectoryWriteTimeSnapshotsBatched(const std::vector<NativeDirectorySnapshotBatchRequest>& requests,
154 NativeSnapshotProbeCache* probe_cache = nullptr);
155[[nodiscard]] NativeDirectorySnapshotBatchResult CaptureDirectoryWriteTimeSnapshotsPlanned(const NativeDirectorySnapshotPlan& plan,
156 NativeSnapshotProbeCache* probe_cache = nullptr);
157[[nodiscard]] std::optional<std::filesystem::path> FindNearestExistingDirectory(const std::filesystem::path& physical_path);
158[[nodiscard]] NativeFileSnapshot CaptureResolvedFileSnapshot(std::string logical_path, const std::filesystem::path& resolved_path);
159[[nodiscard]] NativeFileSnapshotBatchResult CaptureResolvedFileSnapshotsBatched(const std::vector<NativeFileSnapshotBatchRequest>& requests,
160 const NativeFileSnapshotBatchOptions& options = {});
161[[nodiscard]] bool NativeFileSnapshotsEqual(const NativeFileSnapshot& lhs, const NativeFileSnapshot& rhs) noexcept;
162} // namespace pixelbullet::filesystem
Definition filesystem_snapshot_internal.h:45
Definition filesystem_snapshot_internal.h:99
Definition filesystem_snapshot_internal.h:113
Definition filesystem_snapshot_internal.h:129
Definition filesystem_snapshot_internal.h:136
Definition filesystem_snapshot_internal.h:142
Definition filesystem_snapshot_internal.h:89
Definition filesystem_snapshot_internal.h:64
Definition filesystem_snapshot_internal.h:23
Definition filesystem_snapshot_internal.h:70
Definition filesystem_snapshot_internal.h:15
Definition filesystem_snapshot_internal.cc:278