载入中...
搜索中...
未找到
PropertyAccess.h
浏览该文件的文档.
1#pragma once
2
4#include "common/Export.h"
6#include "common/Value.h"
7
8#include <cstdint>
9#include <functional>
10#include <map>
11#include <memory>
12#include <optional>
13#include <string>
14#include <vector>
15
16namespace eve::property_access {
17
19enum class PropertyKind {
20 Auto,
21 Bool,
22 Integer,
23 Number,
24 String,
25 Enum,
26 Color,
27 Vec2,
28 Vec3,
29 Vec4,
32 Struct,
33 Array,
34 Map,
35 Action,
37};
38
40enum class PropertyFlag : std::uint64_t {
41 None = 0,
42 ReadOnly = 1ull << 0,
43 Advanced = 1ull << 1,
44 EditorOnly = 1ull << 2,
45 Runtime = 1ull << 3,
46 Transient = 1ull << 4,
47 Dangerous = 1ull << 5,
48 MultiEdit = 1ull << 6
49};
50
53 return static_cast<PropertyFlag>(static_cast<std::uint64_t>(left) | static_cast<std::uint64_t>(right));
54}
57 return static_cast<PropertyFlag>(static_cast<std::uint64_t>(left) & static_cast<std::uint64_t>(right));
58}
60constexpr bool hasFlag(PropertyFlag value, PropertyFlag flag) { return (value & flag) == flag; }
61
64 std::optional<double> minimum;
65 std::optional<double> maximum;
66 std::optional<double> step;
67 std::string units;
68 int precision = 3;
69};
70
84
87 std::string typeId;
88 std::uint32_t version = 1;
89 std::vector<PropertyDescriptor> properties;
90
92 [[nodiscard]] eve::OptionalRef<const PropertyDescriptor> find(const std::string &path) const;
93};
94
97 bool accepted = false;
98 std::string code;
99 std::string message;
100
102 static WriteResult success() { return {true, {}, {}}; }
104 static WriteResult reject(std::string code, std::string message) {
105 return {false, std::move(code), std::move(message)};
106 }
107};
108
122EVENGINE_API_FOUNDATION WriteResult validatePropertyValue(const PropertyDescriptor &property, const Value &value);
123
126
134
143
152public:
153 using ChangeCallback = std::function<void(const PropertyChange &)>;
154
156 virtual ~IPropertyAccess() = default;
158 virtual const PropertySchema &schema() const = 0;
160 virtual std::optional<Value> read(const std::string &path) const = 0;
162 virtual WriteResult write(const std::string &path, const Value &value) = 0;
164 virtual std::uint64_t revision() const = 0;
167};
168
169} // namespace eve::property_access
double value
Vocabulary aliases for nullable and checked borrowed references.
#define EVENGINE_API_FOUNDATION_INLINE
仅供"只有内联成员"的类型使用的组宏:拥有者 dllexport,消费方不导入。
Definition Export.h:170
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
HexVec3 left
HexVec3 right
std::string path
Definition PlayHost.cpp:110
Owning, renderer-independent dynamic values.
ViewPreparation callback
EVENGINE_API_FOUNDATION public API.
Definition Runtime.h:189
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.
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.
virtual WriteResult write(const std::string &path, const Value &value)=0
Request a two-way binding write.
constexpr bool hasFlag(PropertyFlag value, PropertyFlag flag)
True when flag.
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::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
Result of a model write, including a stable diagnostic code.
static WriteResult success()
Success.
static WriteResult reject(std::string code, std::string message)
Reject.