Player12
An open source football management simulator
Loading...
Searching...
No Matches
NavHistory Class Reference

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ NavHistory()

NavHistory::NavHistory ( std::size_t  capacity = DEFAULT_CAPACITY)
explicit

Member Function Documentation

◆ back()

template<typename Valid >
std::optional< NavEntry > NavHistory::back ( const Valid &  valid)
inline

Steps back to the previous screen valid accepts.

◆ capacity()

std::size_t NavHistory::capacity ( ) const
inline

◆ clear()

void NavHistory::clear ( )

Forgets every entry (a career was started or loaded).

◆ current()

std::optional< NavEntry > NavHistory::current ( ) const

Screen shown now, if any was recorded.

◆ findBack()

template<typename Valid >
std::optional< std::size_t > NavHistory::findBack ( const Valid &  valid) const
inlineprivate

◆ findForward()

template<typename Valid >
std::optional< std::size_t > NavHistory::findForward ( const Valid &  valid) const
inlineprivate

◆ forward()

template<typename Valid >
std::optional< NavEntry > NavHistory::forward ( const Valid &  valid)
inline

Steps forward to the next screen valid accepts.

◆ peekBack()

template<typename Valid >
std::optional< NavEntry > NavHistory::peekBack ( const Valid &  valid) const
inline

Previous screen valid accepts, without moving.

◆ peekForward()

template<typename Valid >
std::optional< NavEntry > NavHistory::peekForward ( const Valid &  valid) const
inline

Next screen valid accepts, without moving.

◆ position()

std::size_t NavHistory::position ( ) const
inline

Index of the current entry (0 when empty).

◆ size()

std::size_t NavHistory::size ( ) const
inline

◆ stepBackTo()

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.

◆ visit()

void NavHistory::visit ( const NavEntry &  entry)

Records a newly shown screen (repeating the current: ignored).

Member Data Documentation

◆ cursor

std::size_t NavHistory::cursor = 0
private

◆ DEFAULT_CAPACITY

constexpr std::size_t NavHistory::DEFAULT_CAPACITY = 50
staticconstexpr

◆ entries

std::vector<NavEntry> NavHistory::entries
private

◆ limit

std::size_t NavHistory::limit
private

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