Skip to main content

StateToIdMapPair Class Template

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

Declaration

template <typename LState, typename RState, typename TId> class helios::engine::state::StateToIdMapPair<LState, RState, TId> { ... }

Public Member Functions Index

template <typename LState, typename RState, typename TId>
StateToIdMapPair &add (LState state, TId id)

Adds an ID for the left state type. More...

template <typename LState, typename RState, typename TId>
StateToIdMapPair &add (RState state, TId id)

Adds an ID for the right state type. More...

template <typename LState, typename RState, typename TId>
auto ids (const LState stateLft, const RState stateRgt) const -> std::span< const TId >

Returns IDs for a state combination. More...

template <typename LState, typename RState, typename TId>
voidfreeze ()

Freezes both underlying maps. More...

Private Member Functions Index

template <typename LState, typename RState, typename TId>
voidmergeInto (std::vector< TId > &out, std::span< const TId > lft, std::span< const TId > rgt) const

Merges two sorted ID lists into the output. More...

Private Member Attributes Index

template <typename LState, typename RState, typename TId>
StateToIdMap< LState, TId >lft_

Map for the left state type. More...

template <typename LState, typename RState, typename TId>
StateToIdMap< RState, TId >rgt_

Map for the right state type. More...

template <typename LState, typename RState, typename TId>
std::vector< TId >combined_

Buffer for merged results. More...

Description

Combines two StateToIdMap instances for dual-state lookups.

Allows associating IDs with two different state types (e.g., GameState and MatchState). When queried, returns the union of IDs from both maps for the given state combination.

Template Parameters
LState

The left/primary state type.

RState

The right/secondary state type.

TId

The ID type to associate with states.

Definition at line 39 of file StateToIdMapPair.ixx.

Public Member Functions

add()

template <typename LState, typename RState, typename TId>
StateToIdMapPair & helios::engine::state::StateToIdMapPair< LState, RState, TId >::add (LState state, TId id)
inline

Adds an ID for the left state type.

Parameters
state

The state to associate the ID with.

id

The ID to add.

Returns

Reference to this map for chaining.

Definition at line 82 of file StateToIdMapPair.ixx.

83 lft_.add(state, id);
84 return *this;
85 }

Reference helios::engine::state::StateToIdMap< TState, TId >::add.

add()

template <typename LState, typename RState, typename TId>
StateToIdMapPair & helios::engine::state::StateToIdMapPair< LState, RState, TId >::add (RState state, TId id)
inline

Adds an ID for the right state type.

Parameters
state

The state to associate the ID with.

id

The ID to add.

Returns

Reference to this map for chaining.

Definition at line 95 of file StateToIdMapPair.ixx.

96 rgt_.add(state, id);
97 return *this;
98 }

Reference helios::engine::state::StateToIdMap< TState, TId >::add.

freeze()

template <typename LState, typename RState, typename TId>
void helios::engine::state::StateToIdMapPair< LState, RState, TId >::freeze ()
inline

Freezes both underlying maps.

Definition at line 127 of file StateToIdMapPair.ixx.

127 void freeze() {
128 lft_.freeze();
129 rgt_.freeze();
130 }

Reference helios::engine::state::StateToIdMap< TState, TId >::freeze.

ids()

template <typename LState, typename RState, typename TId>
std::span< const TId > helios::engine::state::StateToIdMapPair< LState, RState, TId >::ids (const LState stateLft, const RState stateRgt)
inline

Returns IDs for a state combination.

Returns the sorted union of IDs from both maps. Both maps must be frozen before calling this method.

Parameters
stateLft

The left state to query.

stateRgt

The right state to query.

Returns

Span of IDs for the state combination.

Definition at line 111 of file StateToIdMapPair.ixx.

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 }

References helios::engine::state::StateToIdMap< TState, TId >::ids, helios::engine::state::StateToIdMap< TState, TId >::isFrozen and helios::registerComponents.

Referenced by helios::engine::rendering::viewport::systems::StateToViewportPolicyUpdateSystem< StateLft, StateRgt >::update.

Private Member Functions

mergeInto()

template <typename LState, typename RState, typename TId>
void helios::engine::state::StateToIdMapPair< LState, RState, TId >::mergeInto (std::vector< TId > & out, std::span< const TId > lft, std::span< const TId > rgt)
inline

Merges two sorted ID lists into the output.

Parameters
out

The output vector.

lft

IDs from the left map.

rgt

IDs from the right map.

Definition at line 63 of file StateToIdMapPair.ixx.

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 }

Private Member Attributes

combined_

template <typename LState, typename RState, typename TId>
std::vector<TId> helios::engine::state::StateToIdMapPair< LState, RState, TId >::combined_
mutable

Buffer for merged results.

Definition at line 54 of file StateToIdMapPair.ixx.

54 mutable std::vector<TId> combined_;

lft_

template <typename LState, typename RState, typename TId>
StateToIdMap<LState, TId> helios::engine::state::StateToIdMapPair< LState, RState, TId >::lft_

Map for the left state type.

Definition at line 44 of file StateToIdMapPair.ixx.

rgt_

template <typename LState, typename RState, typename TId>
StateToIdMap<RState, TId> helios::engine::state::StateToIdMapPair< LState, RState, TId >::rgt_

Map for the right state type.

Definition at line 49 of file StateToIdMapPair.ixx.


The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.