ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::UndoLog< L > Class Template Reference

an observer that records the invertible events of L, which carry the old values, and brings a structure back to a checkpoint by replaying their inverses through its apply(), in one batch: any structure with apply() becomes undoable, at one event per change More...

#include <ADS/Modification.h>

Public types

using Event = mod::variant_t< L >

Public member functions

template<class E>
requires ( mod::contains_v< E , L > && mod::invertible< E > )
void on (const E &e) noexcept(mod::must_not_throw< E >)
 < an event recorded
template<class E>
requires ( mod::contains_v< E , L > && ! mod::invertible< E > )
void on (const E &) noexcept
 forgets the events recorded, which can no longer be undone: an event with no inverse (the deletion of a node of a graph) is a hole
void on (const mod::Cleared &) noexcept
 forgets the events recorded, which can no longer be undone
void on (const mod::Rebuilt &) noexcept
 forgets the events recorded
template<class A>
void on (const mod::Replaced< A > &) noexcept
 forgets the events recorded
std::size_t checkpoint (void) const
 the checkpoint of now
std::size_t size (void) const
 the events recorded since the oldest checkpoint still valid
template<class S>
void rollback (S &s, std::size_t t)
 \( s \) back to the checkpoint \( t \), by s.apply() of the inverses, in one batch, so that the other observers get their net effect

Detailed description

template<class L>
class ADS::UndoLog< L >

an observer that records the invertible events of L, which carry the old values, and brings a structure back to a checkpoint by replaying their inverses through its apply(), in one batch: any structure with apply() becomes undoable, at one event per change

In pseudocode (beyond the book), with \( R \) the events recorded:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{rollback}( s , t ) \cr 2 & \quad \text{open a batch on } s;\ \text{stop recording} \cr 3 & \quad \textbf{while}\ |R| > t\ \textbf{do} \cr 4 & \qquad e \gets \text{the last event of } R;\ \text{remove it}; \ s.\mathrm{apply}( e^{-1} ) \cr 5 & \quad \text{close the batch};\ \text{record again} \end{array}} \]

Member typedef documentation

◆ Event

template<class L>
using ADS::UndoLog< L >::Event = mod::variant_t< L >

Member function documentation

◆ checkpoint()

template<class L>
std::size_t ADS::UndoLog< L >::checkpoint ( void ) const
inlinenodiscard

the checkpoint of now

◆ on() [1/5]

template<class L>
template<class E>
requires ( mod::contains_v< E , L > && ! mod::invertible< E > )
void ADS::UndoLog< L >::on ( const E & )
inlinenoexcept

forgets the events recorded, which can no longer be undone: an event with no inverse (the deletion of a node of a graph) is a hole

◆ on() [2/5]

template<class L>
template<class E>
requires ( mod::contains_v< E , L > && mod::invertible< E > )
void ADS::UndoLog< L >::on ( const E & e)
inlinenoexcept

< an event recorded

records \( e \)

◆ on() [3/5]

template<class L>
void ADS::UndoLog< L >::on ( const mod::Cleared & )
inlinenoexcept

forgets the events recorded, which can no longer be undone

◆ on() [4/5]

template<class L>
void ADS::UndoLog< L >::on ( const mod::Rebuilt & )
inlinenoexcept

forgets the events recorded

◆ on() [5/5]

template<class L>
template<class A>
void ADS::UndoLog< L >::on ( const mod::Replaced< A > & )
inlinenoexcept

forgets the events recorded

◆ rollback()

template<class L>
template<class S>
void ADS::UndoLog< L >::rollback ( S & s,
std::size_t t )

\( s \) back to the checkpoint \( t \), by s.apply() of the inverses, in one batch, so that the other observers get their net effect

Precondition
\( t \) is a checkpoint of this log, not older than its last Cleared, Rebuilt or Replaced

◆ size()

template<class L>
std::size_t ADS::UndoLog< L >::size ( void ) const
inlinenodiscard

the events recorded since the oldest checkpoint still valid


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