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 43 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 86 of file StateToIdMapPair.ixx.

86 StateToIdMapPair& add(LState state, TId id) {
87 lft_.add(state, id);
88 return *this;
89 }

Reference helios::engine::state::StateToIdMapPair< LState, RState, TId >::add.

Referenced by helios::engine::state::StateToIdMapPair< LState, RState, TId >::add and helios::engine::state::StateToIdMapPair< LState, RState, 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 99 of file StateToIdMapPair.ixx.

99 StateToIdMapPair& add(RState state, TId id) {
100 rgt_.add(state, id);
101 return *this;
102 }

Reference helios::engine::state::StateToIdMapPair< LState, RState, 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 131 of file StateToIdMapPair.ixx.

131 void freeze() {
132 lft_.freeze();
133 rgt_.freeze();
134 }

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 nodiscard

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 115 of file StateToIdMapPair.ixx.

115 [[nodiscard]] std::span<const TId> ids(const LState stateLft, const RState stateRgt) const {
116
117 assert(lft_.isFrozen() && rgt_.isFrozen() && "Cannot merge if sources are not frozen.");
118
119 if (!lft_.isFrozen() || !rgt_.isFrozen()) {
120 return {};
121 }
122
123 mergeInto(combined_, lft_.ids(stateLft), rgt_.ids(stateRgt));
124
125 return combined_;
126 }

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 67 of file StateToIdMapPair.ixx.

67 void mergeInto(std::vector<TId>& out, std::span<const TId> lft, std::span<const TId> rgt) const {
68
69 out.clear();
70
71 out.reserve(lft.size() + rgt.size());
72
73 std::set_union(lft.begin(), lft.end(), rgt.begin(), rgt.end(), std::back_inserter(out));
74 }

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 58 of file StateToIdMapPair.ixx.

58 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 48 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 53 of file StateToIdMapPair.ixx.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.