载入中...
搜索中...
未找到
FactStore.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
9#include "common/Result.h"
10#include "common/Value.h"
11#include "decision/Condition.h"
12
13#include <cstdint>
14#include <optional>
15#include <string>
16#include <string_view>
17#include <unordered_map>
18#include <vector>
19
20namespace eve::emergence {
21
23enum class FactDomain : std::uint8_t {
24 Value,
25 Tag,
28 State,
30 Policy,
31};
32
34enum class FactChange : std::uint8_t { Unchanged = 0, Changed = 1 };
35
42[[nodiscard]] EVENGINE_API_FOUNDATION std::string makeFactKey(FactDomain domain, std::string_view name);
43
49 std::string_view key);
50
61public:
63 void clear();
64
69 [[nodiscard]] FactChange setValue(std::string key, eve::Value value);
71 [[nodiscard]] FactChange setTag(std::string tag, bool present);
73 [[nodiscard]] FactChange setAttribute(std::string key, eve::Value value);
75 [[nodiscard]] FactChange setResource(std::string key, eve::Value value);
77 [[nodiscard]] FactChange setState(std::string key, eve::Value value);
79 [[nodiscard]] FactChange setAuthority(std::string scope, bool granted);
84 [[nodiscard]] FactChange setPolicy(std::string name, decision::ConditionResult result);
85
87 [[nodiscard]] FactChange clearValue(std::string_view key);
89 [[nodiscard]] FactChange clearTag(std::string_view tag);
90
91 [[nodiscard]] std::optional<eve::Value> value(std::string_view key) const override;
92 [[nodiscard]] std::optional<bool> hasTag(std::string_view tag) const override;
93 [[nodiscard]] std::optional<eve::Value> attribute(std::string_view key) const override;
94 [[nodiscard]] std::optional<eve::Value> resource(std::string_view key) const override;
95 [[nodiscard]] std::optional<eve::Value> state(std::string_view key) const override;
96 [[nodiscard]] std::optional<bool> authority(std::string_view scope) const override;
97 [[nodiscard]] std::optional<decision::ConditionResult> policy(std::string_view name,
98 const eve::Value& arguments) const override;
99
101 [[nodiscard]] std::string snapshotJson() const;
106 [[nodiscard]] eve::Result<void> restoreJson(std::string_view json);
107
109 [[nodiscard]] int valueCount() const noexcept { return static_cast<int>(values_.size()); }
110
111private:
112 template <class Map, class T>
113 static FactChange assign(Map& map, std::string key, T value);
114
115 std::unordered_map<std::string, eve::Value> values_;
116 std::unordered_map<std::string, bool> tags_;
117 std::unordered_map<std::string, eve::Value> attributes_;
118 std::unordered_map<std::string, eve::Value> resources_;
119 std::unordered_map<std::string, eve::Value> states_;
120 std::unordered_map<std::string, bool> authorities_;
121 std::unordered_map<std::string, decision::ConditionResult> policies_;
122};
123
124} // namespace eve::emergence
double value
Pure, explainable condition trees shared by gameplay domains.
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::uint32_t key
JobScope scope
std::string name
const std::string * tag
Move-only, checked operation results for the common layer.
std::string resource
Owning, renderer-independent dynamic values.
Move-only operation result carrying either a value or Status.
Definition Result.h:155
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
Explain one condition evaluation in a UI- and log-friendly form.
Definition Condition.h:129
Read-only state boundary used by every condition evaluation.
Definition Condition.h:166
Mutable fact bag that doubles as a read-only Condition evaluation context.
Definition FactStore.h:60
int valueCount() const noexcept
Number of stored value facts.
Definition FactStore.h:109
FactChange
Whether a FactStore mutation changed stored state.
Definition FactStore.h:34
FactDomain
Domain partition of a fact key used by the watch index.
Definition FactStore.h:23
eve::Result< std::pair< FactDomain, std::string > > parseFactKey(std::string_view key)
Parse a canonical watch key into domain and leaf name.
std::string makeFactKey(FactDomain domain, std::string_view name)
Build the canonical watch key for one fact domain.