One phase in a TrafficLight program.
More...
#include <TrafficLight.hpp>
|
| | TrafficLightPhase (Delay const duration) |
| | Construct a phase with the given duration and an empty green set.
|
| | TrafficLightPhase (Delay const duration, std::unordered_map< Id, std::unordered_set< Direction > > greenSet) |
| | Construct a phase with a duration and a pre-built green set.
|
| void | addGreen (Id const streetId, Direction const direction) |
| | Mark a specific direction on a street as green.
|
| void | addGreen (Id const streetId, std::initializer_list< Direction > directions) |
| | Mark several directions on a street as green.
|
| void | addGreen (Id const streetId) |
| | Mark a street as green for ALL directions (inserts Direction::ANY). This is the typical entry produced by auto-deduction.
|
| auto | containsStreet (Id const streetId) const |
| | Check if a street is present in the green set, regardless of direction.
|
| auto | containsGreen (Id const streetId, Direction const direction) const |
| | Exact lookup — does NOT apply the direction-fallback ladder. Use TrafficLight::isGreen() for the full resolved query.
|
| auto | duration () const |
| | Get the phase duration in ticks.
|
| void | setDuration (Delay const duration) |
| | Set the phase duration (used by the optimiser — does not affect the green set or the running state machine counter).
|
| auto const & | greenSet () const |
| | Get a read-only view of the green set.
|
|
bool | operator== (TrafficLightPhase const &other) const |
|
bool | operator!= (TrafficLightPhase const &other) const |
One phase in a TrafficLight program.
A phase owns:
- a duration : how many ticks it stays active.
- a green set : unordered_map<streetId, unordered_set<Direction>> listing every (street, direction) that is green.
Streets absent from the green set are implicitly red. Direction fallback resolution is applied at query time by TrafficLight, not here — containsGreen() performs an exact lookup only.
◆ TrafficLightPhase() [1/2]
| dsf::mobility::TrafficLightPhase::TrafficLightPhase |
( |
Delay const | duration | ) |
|
|
inlineexplicit |
Construct a phase with the given duration and an empty green set.
- Parameters
-
| duration | Duration of the phase in ticks. |
◆ TrafficLightPhase() [2/2]
| dsf::mobility::TrafficLightPhase::TrafficLightPhase |
( |
Delay const | duration, |
|
|
std::unordered_map< Id, std::unordered_set< Direction > > | greenSet ) |
|
inline |
Construct a phase with a duration and a pre-built green set.
- Parameters
-
| duration | Duration of the phase in ticks. |
| greenSet | Unordered map of streetId to the set of green directions for that street. |
◆ addGreen() [1/3]
| void dsf::mobility::TrafficLightPhase::addGreen |
( |
Id const | streetId | ) |
|
|
inline |
Mark a street as green for ALL directions (inserts Direction::ANY). This is the typical entry produced by auto-deduction.
- Parameters
-
◆ addGreen() [2/3]
| void dsf::mobility::TrafficLightPhase::addGreen |
( |
Id const | streetId, |
|
|
Direction const | direction ) |
|
inline |
Mark a specific direction on a street as green.
- Parameters
-
| streetId | Street identifier. |
| direction | Direction to mark as green. |
◆ addGreen() [3/3]
| void dsf::mobility::TrafficLightPhase::addGreen |
( |
Id const | streetId, |
|
|
std::initializer_list< Direction > | directions ) |
|
inline |
Mark several directions on a street as green.
- Parameters
-
| streetId | Street identifier. |
| directions | List of directions to mark as green for the given street. |
◆ containsGreen()
| auto dsf::mobility::TrafficLightPhase::containsGreen |
( |
Id const | streetId, |
|
|
Direction const | direction ) const |
|
inline |
Exact lookup — does NOT apply the direction-fallback ladder. Use TrafficLight::isGreen() for the full resolved query.
- Parameters
-
| streetId | Street identifier. |
| direction | Direction of the movement. |
- Returns
- True if the (streetId, direction) pair is present in the green set.
◆ containsStreet()
| auto dsf::mobility::TrafficLightPhase::containsStreet |
( |
Id const | streetId | ) |
const |
|
inline |
Check if a street is present in the green set, regardless of direction.
- Returns
- True if the street is present in the green set, regardless of direction.
◆ duration()
| auto dsf::mobility::TrafficLightPhase::duration |
( |
| ) |
const |
|
inline |
Get the phase duration in ticks.
- Returns
- Duration of the phase in ticks.
◆ greenSet()
| auto const & dsf::mobility::TrafficLightPhase::greenSet |
( |
| ) |
const |
|
inline |
Get a read-only view of the green set.
- Returns
- Read-only view of the green set.
◆ setDuration()
| void dsf::mobility::TrafficLightPhase::setDuration |
( |
Delay const | duration | ) |
|
|
inline |
Set the phase duration (used by the optimiser — does not affect the green set or the running state machine counter).
- Parameters
-
| duration | New duration for the phase in ticks. |
The documentation for this class was generated from the following file: