Skip to main content

StateToIdMapPair.ixx File

Combined policy mapping two state types to IDs. More...

Included Headers

#include <vector> #include <span> #include <helios-engine-config.h> #include <cassert> #include <bit> #include <algorithm> #include <iterator> #include <helios.engine.core.types> #include <helios.engine.state.types> #include <helios.engine.state.StateToIdMap>

Namespaces Index

namespacehelios
namespaceengine
namespacestate

Classes Index

classStateToIdMapPair<LState, RState, TId>

Combines two StateToIdMap instances for dual-state lookups. More...

Description

Combined policy mapping two state types to IDs.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <vector>
8#include <span>
10#include <cassert>
11#include <bit>
12#include <algorithm>
13#include <iterator>
14
15export module helios.engine.state.StateToIdMapPair;
16
17import helios.engine.state.StateToIdMap;
18
19import helios.engine.state.types;
20
21import helios.engine.core.types;
22
23using namespace helios::engine::state::types;
24
25export namespace helios::engine::state {
26
38 template<typename LState, typename RState, typename TId>
40
45
50
54 mutable std::vector<TId> combined_;
55
63 void mergeInto(std::vector<TId>& out, std::span<const TId> lft, std::span<const TId> rgt) const {
64
65 out.clear();
66
67 out.reserve(lft.size() + rgt.size());
68
69 std::set_union(lft.begin(), lft.end(), rgt.begin(), rgt.end(), std::back_inserter(out));
70 }
71
72 public:
73
83 lft_.add(state, id);
84 return *this;
85 }
86
96 rgt_.add(state, id);
97 return *this;
98 }
99
111 [[nodiscard]] std::span<const TId> ids(const LState stateLft, const RState stateRgt) const {
112
113 assert(lft_.isFrozen() && rgt_.isFrozen() && "Cannot merge if sources are not frozen.");
114
115 if (!lft_.isFrozen() || !rgt_.isFrozen()) {
116 return {};
117 }
118
119 mergeInto(combined_, lft_.ids(stateLft), rgt_.ids(stateRgt));
120
121 return combined_;
122 }
123
127 void freeze() {
128 lft_.freeze();
129 rgt_.freeze();
130 }
131
132 };
133
134
135}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.