载入中...
搜索中...
未找到
EditorDocumentService.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6
7#include <functional>
8#include <optional>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13namespace eve::editor {
14
31
40
43
51
56 std::string title;
57 std::string resourceUri;
60 std::string diskContentHash;
61 std::vector<StableId> viewIds;
62 std::vector<EditorDiagnostic> diagnostics;
63
65 bool dirty() const { return revision.edit != revision.saved; }
66};
67
76
83
86public:
88 virtual ~IAtomicDocumentStore() = default;
90 virtual Result<StoredDocument> read(const std::string& resourceUri) const = 0;
92 virtual Result<StoredDocument> compareAndSwap(const std::string& resourceUri, Revision expectedRevision,
93 const std::string& expectedContentHash,
94 const EditorValue& content) = 0;
95};
96
99public:
101 Result<StoredDocument> read(const std::string& resourceUri) const override;
103 Result<StoredDocument> compareAndSwap(const std::string& resourceUri, Revision expectedRevision,
104 const std::string& expectedContentHash,
105 const EditorValue& content) override;
106
107private:
108 std::unordered_map<std::string, StoredDocument> documents_;
109};
110
119public:
121 using ContentValidator = std::function<Result<void>(const EditorValue&)>;
122
124 explicit DocumentService(IAtomicDocumentStore* store) : store_(store) {}
125
127 Result<DocumentSnapshot> open(DocumentKey key, std::string title, std::string resourceUri,
128 EditorValue initialContent = {});
130 Result<DocumentSnapshot> edit(const DocumentId& document, EditorValue content,
131 std::optional<Revision> expectedRevision = std::nullopt);
133 Result<SaveTicket> requestSave(const DocumentId& document);
135 Result<DocumentSnapshot> executeSave(const SaveTicket& ticket);
137 Result<EditorValue> content(const DocumentId& document) const;
139 Result<DocumentSnapshot> snapshot(const DocumentId& document) const;
141 std::vector<DocumentSnapshot> documents() const;
149 Result<DocumentSnapshot> reconcileExternal(const DocumentId& document);
156 Result<DocumentSnapshot> reconcileExternal(const DocumentId& document, ContentValidator validator);
158 Result<void> close(const DocumentId& document);
159
160private:
161 struct OpenDocument {
162 DocumentSnapshot snapshot;
163 EditorValue content;
164 };
165 struct PendingSave {
166 SaveTicket ticket;
167 EditorValue content;
168 };
169
170 static Result<DocumentSnapshot> error(EditorStatus status, const char* rule, std::string message);
171
172 IAtomicDocumentStore* store_ = nullptr;
173 std::unordered_map<DocumentId, OpenDocument, StrongEditorIdHash<DocumentId>> open_;
174 std::unordered_map<StableId, PendingSave, StrongEditorIdHash<StableId>> pendingSaves_;
175 std::uint64_t ticketSequence_ = 0;
176};
177
178} // namespace eve::editor
std::string title
#define EVENGINE_API_ORCHESTRATION
Definition Export.h:111
std::string message
std::uint32_t key
wgpu::PopErrorScopeStatus status
std::string error
Definition Package.cpp:60
Move-only operation result carrying either a value or Status.
Definition Result.h:155
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:314
Id128 public API.
Definition Identity.h:112
Deterministic owning value tree shared by authoring hosts.
Document coordinator with revision-safe requestSave/executeSave sequencing.
std::function< Result< void >(const EditorValue &)> ContentValidator
Synchronous content validator borrowed only for one external reconciliation call.
DocumentService(IAtomicDocumentStore *store)
Document service.
Compare-and-swap persistence boundary used by DocumentService.
virtual ~IAtomicDocumentStore()=default
Releases IAtomicDocumentStore resources.
virtual Result< StoredDocument > read(const std::string &resourceUri) const =0
Read the latest value for a resource URI.
virtual Result< StoredDocument > compareAndSwap(const std::string &resourceUri, Revision expectedRevision, const std::string &expectedContentHash, const EditorValue &content)=0
Replace a value only when the expected disk revision still matches.
Deterministic in-memory CAS store suitable for tests and transient tools.
DocumentState
Lifecycle state visible to workspaces and close coordination.
eve::editing::Revision Revision
DocumentKind
Authoring document category used to choose controllers and views.
Stable document identity; paths are deliberately excluded.
auto operator<=>(const DocumentKey &) const =default
Operator <=>.
Separate edit, saved and external-store revision clocks.
Immutable document metadata snapshot.
bool dirty() const
True when the latest edit revision has not been saved.
std::vector< EditorDiagnostic > diagnostics
Immutable save request capturing one exact edit revision.
Value snapshot returned by an atomic document store.