"Fossies" - the Fresh Open Source Software Archive 
Member "regexxer-0.10/src/undostack.cc" (6 Oct 2011, 2212 Bytes) of package /linux/privat/old/regexxer-0.10.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "undostack.cc" see the
Fossies "Dox" file reference documentation.
1 /*
2 * Copyright (c) 2002-2007 Daniel Elstner <daniel.kitta@gmail.com>
3 *
4 * This file is part of regexxer.
5 *
6 * regexxer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * regexxer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with regexxer; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "undostack.h"
22 #include <glib.h>
23
24
25 namespace
26 {
27
28 enum { PULSE_INTERVAL = 8 };
29
30 class StopUndo {};
31
32 } // anonymous namespace
33
34
35 namespace Regexxer
36 {
37
38 /**** Regexxer::UndoAction *************************************************/
39
40 UndoAction::~UndoAction()
41 {}
42
43 bool UndoAction::undo(const sigc::slot<bool>& pulse)
44 {
45 return do_undo(pulse);
46 }
47
48
49 /**** Regexxer::UndoStack **************************************************/
50
51 UndoStack::UndoStack()
52 {}
53
54 UndoStack::~UndoStack()
55 {
56 // Ensure LIFO order on destruction too.
57 while (!actions_.empty())
58 actions_.pop();
59 }
60
61 void UndoStack::push(const UndoActionPtr& action)
62 {
63 actions_.push(action);
64 }
65
66 bool UndoStack::empty() const
67 {
68 return actions_.empty();
69 }
70
71 void UndoStack::undo_step(const sigc::slot<bool>& pulse)
72 {
73 try
74 {
75 bool skip = false;
76
77 do
78 {
79 g_return_if_fail(!actions_.empty());
80
81 skip = actions_.top()->undo(pulse);
82 actions_.pop();
83 }
84 while (skip);
85 }
86 catch (const StopUndo&)
87 {}
88 }
89
90 bool UndoStack::do_undo(const sigc::slot<bool>& pulse)
91 {
92 unsigned int iteration = 0;
93 bool skip = true;
94
95 while (!actions_.empty())
96 {
97 const bool skip_this = actions_.top()->undo(pulse);
98 actions_.pop();
99
100 if (!skip_this)
101 {
102 skip = false;
103
104 if ((++iteration % PULSE_INTERVAL) == 0 && pulse())
105 throw StopUndo();
106 }
107 }
108
109 return skip;
110 }
111
112 } // namespace Regexxer