载入中...
搜索中...
未找到
PropertyAccess.h
浏览该文件的文档.
1#pragma once
2
4#include "common/Export.h"
5#include "common/Result.h"
7#include "common/Value.h"
8
9#include <cstdint>
10#include <functional>
11#include <map>
12#include <memory>
13#include <optional>
14#include <string>
15#include <string_view>
16#include <vector>
17
18namespace eve::property_access {
19
21enum class PropertyKind {
22 Auto,
23 Bool,
24 Integer,
25 Number,
26 String,
27 Enum,
28 Color,
29 Vec2,
30 Vec3,
31 Vec4,
34 Struct,
35 Array,
36 Map,
37 Action,
39};
40
42enum class PropertyFlag : std::uint64_t {
43 None = 0,
44 ReadOnly = 1ull << 0,
45 Advanced = 1ull << 1,
46 EditorOnly = 1ull << 2,
47 Runtime = 1ull << 3,
48 Transient = 1ull << 4,
49 Dangerous = 1ull << 5,
50 MultiEdit = 1ull << 6
51};
52
55 return static_cast<PropertyFlag>(static_cast<std::uint64_t>(left) | static_cast<std::uint64_t>(right));
56}
59 return static_cast<PropertyFlag>(static_cast<std::uint64_t>(left) & static_cast<std::uint64_t>(right));
60}
62constexpr bool hasFlag(PropertyFlag value, PropertyFlag flag) { return (value & flag) == flag; }
63
66 std::optional<double> minimum;
67 std::optional<double> maximum;
68 std::optional<double> step;
69 std::string units;
70 int precision = 3;
71};
72
86
89 std::string typeId;
90 std::uint32_t version = 1;
91 std::vector<PropertyDescriptor> properties;
92
94 [[nodiscard]] eve::OptionalRef<const PropertyDescriptor> find(const std::string &path) const;
95};
96
98inline constexpr const char *kRuleDiagnosticDetail = "rule";
99
107[[nodiscard]] inline Result<void> rejected(std::string rule, std::string message,
109 DiagnosticDetails details;
110 details.emplace_back(kRuleDiagnosticDetail, std::move(rule));
112 StatusCode::Rejected, Diagnostic::error(code, std::move(message), {}, std::move(details), "property_access")));
113}
114
119[[nodiscard]] inline Result<void> accepted() { return Result<void>::success(); }
120
125[[nodiscard]] inline std::string_view diagnosticRule(const Diagnostic &diagnostic) {
126 for (const auto &[key, value] : diagnostic.details())
127 if (key == kRuleDiagnosticDetail) return value;
128 return {};
129}
130
135[[nodiscard]] inline std::string writeRule(const Result<void> &result) {
136 if (const Diagnostic *error = result.error()) return std::string(diagnosticRule(*error));
137 return {};
138}
139
153[[nodiscard]] EVENGINE_API_FOUNDATION Result<void> validatePropertyValue(const PropertyDescriptor &property,
154 const Value &value);
155
158
166
175
184public:
185 using ChangeCallback = std::function<void(const PropertyChange &)>;
186
188 virtual ~IPropertyAccess() = default;
190 virtual const PropertySchema &schema() const = 0;
192 virtual std::optional<Value> read(const std::string &path) const = 0;
198 [[nodiscard]] virtual Result<void> write(const std::string &path, const Value &value) = 0;
200 virtual std::uint64_t revision() const = 0;
203};
204
205} // namespace eve::property_access
Vocabulary aliases for nullable and checked borrowed references.
SQObjectPtr key
Definition ECS.cpp:155
#define EVENGINE_API_FOUNDATION_INLINE
仅供"只有内联成员"的类型使用的组宏:拥有者 dllexport,消费方不导入。
Definition Export.h:170
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string message
DiagnosticCode code
HexVec3 left
HexVec3 right
Poco::JSON::Object::Ptr result
std::string error
Definition Package.cpp:174
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
Move-only, checked operation results for the common layer.
Owning, renderer-independent dynamic values.
ViewPreparation callback
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
const DiagnosticDetails & details() const noexcept
Structured context in insertion order.
Definition Diagnostic.h:151
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
EVENGINE_API_FOUNDATION public API.
Definition Runtime.h:189
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.cpp:28
Move-only RAII token that owns one observer registration.
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
Renderer- and transaction-independent MVVM property surface.
virtual const PropertySchema & schema() const =0
Return the stable schema exposed by this model.
virtual std::optional< Value > read(const std::string &path) const =0
Read a property value, or nullopt when it is absent.
virtual Result< void > write(const std::string &path, const Value &value)=0
Request a two-way binding write.
std::function< void(const PropertyChange &)> ChangeCallback
virtual Subscription subscribe(ChangeCallback callback)=0
Observe changes until the returned token is destroyed.
virtual ~IPropertyAccess()=default
I property access.
virtual std::uint64_t revision() const =0
Monotonic revision incremented after observable changes.
constexpr const char * kRuleDiagnosticDetail
Reserved DiagnosticDetails key carrying a stable property-access rule id.
std::string writeRule(const Result< void > &result)
Return the primary rule id from a write/validation result.
Result< void > rejected(std::string rule, std::string message, DiagnosticCode code=DiagnosticCode::PreconditionViolation)
Build a rejected write/validation result with a stable rule string.
std::string_view diagnosticRule(const Diagnostic &diagnostic)
Return the projected property-access rule id, or empty when absent.
constexpr bool hasFlag(PropertyFlag value, PropertyFlag flag)
True when flag.
Result< void > accepted()
Build a successful write/validation result.
PropertyChangeState
Availability of a property in an immutable model snapshot.
PropertyFlag
Cross-host property visibility and editing flags.
PropertyKind
Semantic property kind used by renderer-independent presenters.
std::vector< DiagnosticDetail > DiagnosticDetails
Owning collection of diagnostic details with stable insertion order.
Definition Diagnostic.h:88
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
Numeric editing metadata independent of a slider or spin-box widget.
Immutable notification emitted after a model property changes.
One stable property description consumed by any UI shell.
Versioned schema for one view model or editable target.
std::vector< PropertyDescriptor > properties