comparison OrthancStone/Sources/Toolbox/UndoRedoStack.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Toolbox/UndoRedoStack.cpp@30deba7bc8e2
children 8563ea5d8ae4
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "UndoRedoStack.h"
23
24 #include <OrthancException.h>
25
26 #include <cassert>
27
28 namespace OrthancStone
29 {
30 void UndoRedoStack::Clear(UndoRedoStack::Stack::iterator from)
31 {
32 for (Stack::iterator it = from; it != stack_.end(); ++it)
33 {
34 assert(*it != NULL);
35 delete *it;
36 }
37
38 stack_.erase(from, stack_.end());
39 }
40
41
42 UndoRedoStack::UndoRedoStack() :
43 current_(stack_.end())
44 {
45 }
46
47
48 UndoRedoStack::~UndoRedoStack()
49 {
50 Clear(stack_.begin());
51 }
52
53
54 void UndoRedoStack::Add(ICommand* command)
55 {
56 if (command == NULL)
57 {
58 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
59 }
60
61 Clear(current_);
62
63 stack_.push_back(command);
64 current_ = stack_.end();
65 }
66
67
68 void UndoRedoStack::Undo()
69 {
70 if (current_ != stack_.begin())
71 {
72 --current_;
73
74 assert(*current_ != NULL);
75 (*current_)->Undo();
76 }
77 }
78
79 void UndoRedoStack::Redo()
80 {
81 if (current_ != stack_.end())
82 {
83 assert(*current_ != NULL);
84 (*current_)->Redo();
85
86 ++current_;
87 }
88 }
89 }