morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
change_types.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4#include <cstddef>
5#include <cstdint>
6#include <glaze/glaze.hpp>
7#include <optional>
8#include <string>
9#include <vector>
10
11/// @file
12/// The plain data a derived change is made of. This header includes nothing of the registry or the
13/// forms layer, so the wire types can use it.
14
15namespace morph::effects {
16
17/// @brief The most keys one `RecordChange` carries.
18///
19/// The wire readers refuse a record entry with more keys, so a producer never emits one: a change that
20/// would name more rows is reported as a whole-type change (keys absent), which over-notifies but never
21/// misses. The bound keeps one peer-supplied list from forcing an unbounded allocation.
22inline constexpr std::size_t kMaxChangeKeys = 4096;
23
24/// @brief A change to the rows of one record type.
26 /// The record's wire name.
27 std::string record;
28 /// The keys of the rows that changed, each as raw JSON; absent when the whole type changed.
29 std::optional<std::vector<glz::raw_json>> keys;
30};
31
32/// @brief A change to the state of one model instance.
34 /// The model's registered type name.
35 std::string modelType;
36 /// The instance id.
37 std::uint64_t instance = 0;
38 /// The directory key's text for a keyed shared instance; empty for a private one.
39 std::string primary;
40};
41
42/// @brief What one successful execute changed.
43struct Changes {
44 /// Record topics, one entry per record type.
45 std::vector<RecordChange> records;
46 /// Instance topics.
47 std::vector<InstanceChange> instances;
48
49 /// @brief Whether nothing changed.
50 /// @return True when there are no record and no instance changes.
51 [[nodiscard]] bool empty() const { return records.empty() && instances.empty(); }
52};
53
54} // namespace morph::effects
constexpr std::size_t kMaxChangeKeys
The most keys one RecordChange carries.
What one successful execute changed.
std::vector< RecordChange > records
Record topics, one entry per record type.
bool empty() const
Whether nothing changed.
std::vector< InstanceChange > instances
Instance topics.
A change to the state of one model instance.
std::uint64_t instance
The instance id.
std::string primary
The directory key's text for a keyed shared instance; empty for a private one.
std::string modelType
The model's registered type name.
A change to the rows of one record type.
std::string record
The record's wire name.
std::optional< std::vector< glz::raw_json > > keys
The keys of the rows that changed, each as raw JSON; absent when the whole type changed.