OpenASIP 2.2
Loading...
Searching...
No Matches
Reversible.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2020 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24
25/**
26 * @file Reversible.hh
27 * Declaration of Reversible class; Framework for operations that contain
28 * undo infromation and can be recursively reverted.
29 */
30
31#ifndef TTA_REVERSIBLE_HH
32#define TTA_REVERSIBLE_HH
33
34#include <stack>
35
37public:
38 /** This performs the operation. Returns true if success, false if fail. */
39 virtual bool operator()() = 0;
40 virtual void undo();
41 virtual ~Reversible();
42 void deleteChildren(std::stack<Reversible*>& children);
43 int id() { return id_; }
45protected:
46 bool runPreChild(Reversible *preChild);
47 bool runPostChild(Reversible *preChild);
48 bool runChild(std::stack<Reversible*>& children, Reversible* child);
49 bool runChild(Reversible* child, bool pre);
50
53 void undoAndRemoveChildren(std::stack<Reversible*>& children);
54 virtual void undoOnlyMe();
55
56 // normally no need to touch these directly, only through the helpers.
57 std::stack<Reversible*> preChildren_;
58 std::stack<Reversible*> postChildren_;
59
60private:
61 int id_;
62 static int idCounter_;
63};
64
65#endif
virtual bool operator()()=0
bool runPostChild(Reversible *preChild)
std::stack< Reversible * > preChildren_
Definition Reversible.hh:57
void undoAndRemoveChildren(std::stack< Reversible * > &children)
Definition Reversible.cc:55
static int idCounter_
Definition Reversible.hh:62
std::stack< Reversible * > postChildren_
Definition Reversible.hh:58
virtual void undo()
Definition Reversible.cc:69
void undoAndRemovePreChildren()
Definition Reversible.cc:80
void deleteChildren(std::stack< Reversible * > &children)
Definition Reversible.cc:42
bool runChild(std::stack< Reversible * > &children, Reversible *child)
bool runPreChild(Reversible *preChild)
virtual void undoOnlyMe()
Definition Reversible.cc:98
void undoAndRemovePostChildren()
Definition Reversible.cc:89
virtual ~Reversible()
Definition Reversible.cc:35