OpenWalnut  1.5.0dev
WActionHandler.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <vector>
26 
27 #include "WActionHandler.h"
28 
29 
31 {
32  m_undo = ActionStack( new std::vector< WFiberAction::SPtr >() );
33  m_redo = ActionStack( new std::vector< WFiberAction::SPtr >() );
34 }
35 
37 {
38  m_undo->clear();
39  m_redo->clear();
40 }
41 
43 {
44  m_undo->push_back( action );
45  m_redo->clear();
46 }
47 
49 {
50  if( m_undo->empty() )
51  {
52  return;
53  }
54 
55  WFiberAction::SPtr action = m_undo->back();
56 
57  action->undo();
58 
59  m_undo->pop_back();
60  m_redo->push_back( action );
61 }
62 
64 {
65  if( m_redo->empty() )
66  {
67  return;
68  }
69  WFiberAction::SPtr action = m_redo->back();
70 
71  action->redo();
72 
73  m_redo->pop_back();
74  m_undo->push_back( action );
75 }
~WActionHandler()
Clears the vectors for destruction.
void pushAction(WFiberAction::SPtr action)
Pushes an action to the undo vector and clears the redo vector.
WActionHandler()
Creates the undo and redo vectors.
void redo()
Redos the last action and pushes it to the undo vector.
ActionStack m_redo
The redo vector.
void undo()
Undos the last action and pushes it to the redo vector.
std::shared_ptr< std::vector< WFiberAction::SPtr > > ActionStack
A shared_ptr to a vector of an action.
ActionStack m_undo
The undo vector.
std::shared_ptr< WFiberAction > SPtr
A shared_ptr to this class.
Definition: WFiberAction.h:41