demotool/undo.cc

46 lines
903 B
C++
Raw Normal View History

2017-11-22 10:01:37 +01:00
#include "externals.hh"
#include "undo.hh"
/*= A_UndoAction ===============================================================*/
A_UndoAction::~A_UndoAction( )
{}
/*= T_UndoManager ==============================================================*/
void T_UndoManager::undo( ) noexcept
{
if ( pos_ > 0 ) {
pos_ --;
actions_[ ( start_ + pos_ ) % MaxUndo ]->undo( );
}
}
void T_UndoManager::redo( ) noexcept
{
if ( pos_ < count_ ) {
pos_ ++;
actions_[ ( start_ + pos_ ) % MaxUndo ]->redo( );
}
}
void T_UndoManager::addAction(
P_UndoAction action ) noexcept
{
assert( action );
while ( pos_ < count_ ) {
count_ --;
actions_[ ( start_ + count_ ) % MaxUndo ].clear( );
}
if ( count_ == MaxUndo ) {
actions_[ start_ ] = std::move( action );
start_ = ( start_ + 1 ) % MaxUndo;
} else {
actions_[ ( start_ + pos_ ) % MaxUndo ] = std::move( action );
count_ ++;
pos_ ++;
}
}