|
Player12
An open source football management simulator
|
Browser-style history of the screens visited in a career. More...
#include <nav_history.h>
Public Member Functions | |
| NavHistory (std::size_t capacity=DEFAULT_CAPACITY) | |
| void | visit (const NavEntry &entry) |
| Records a newly shown screen (repeating the current: ignored). | |
| void | clear () |
| Forgets every entry (a career was started or loaded). | |
| void | stepBackTo (const NavEntry &entry) |
Steps back onto entry, a screen shown beneath the current one that the history cannot step back to (never recorded, dropped by the capacity, or rejected as invalid): the nearest earlier copy becomes current, else entry is inserted before the current one. The current entry stays ahead, for Forward. | |
| std::optional< NavEntry > | current () const |
| Screen shown now, if any was recorded. | |
| template<typename Valid > | |
| std::optional< NavEntry > | peekBack (const Valid &valid) const |
Previous screen valid accepts, without moving. | |
| template<typename Valid > | |
| std::optional< NavEntry > | peekForward (const Valid &valid) const |
Next screen valid accepts, without moving. | |
| template<typename Valid > | |
| std::optional< NavEntry > | back (const Valid &valid) |
Steps back to the previous screen valid accepts. | |
| template<typename Valid > | |
| std::optional< NavEntry > | forward (const Valid &valid) |
Steps forward to the next screen valid accepts. | |
| std::size_t | size () const |
| std::size_t | capacity () const |
| std::size_t | position () const |
| Index of the current entry (0 when empty). | |
Static Public Attributes | |
| static constexpr std::size_t | DEFAULT_CAPACITY = 50 |
Private Member Functions | |
| template<typename Valid > | |
| std::optional< std::size_t > | findBack (const Valid &valid) const |
| template<typename Valid > | |
| std::optional< std::size_t > | findForward (const Valid &valid) const |
Private Attributes | |
| std::vector< NavEntry > | entries |
| std::size_t | cursor = 0 |
| std::size_t | limit |
Browser-style history of the screens visited in a career.
visit() records a newly shown screen and drops everything ahead of the current one, like following a link after going back in a browser. back() and forward() move through the list, skipping entries the caller no longer accepts (a player who left the game, a screen closed while out of work) and entries identical to the current one. The oldest entry goes once the capacity is reached. No allocation after construction.
|
explicit |
|
inline |
Steps back to the previous screen valid accepts.
|
inline |
| void NavHistory::clear | ( | ) |
Forgets every entry (a career was started or loaded).
| std::optional< NavEntry > NavHistory::current | ( | ) | const |
Screen shown now, if any was recorded.
|
inlineprivate |
|
inlineprivate |
|
inline |
Steps forward to the next screen valid accepts.
|
inline |
Previous screen valid accepts, without moving.
|
inline |
Next screen valid accepts, without moving.
|
inline |
Index of the current entry (0 when empty).
|
inline |
| void NavHistory::stepBackTo | ( | const NavEntry & | entry | ) |
Steps back onto entry, a screen shown beneath the current one that the history cannot step back to (never recorded, dropped by the capacity, or rejected as invalid): the nearest earlier copy becomes current, else entry is inserted before the current one. The current entry stays ahead, for Forward.
| void NavHistory::visit | ( | const NavEntry & | entry | ) |
Records a newly shown screen (repeating the current: ignored).
|
private |
|
staticconstexpr |
|
private |
|
private |