OpenASIP  2.0
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 
36 class Reversible {
37 public:
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_; }
45 protected:
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 
60 private:
61  int id_;
62  static int idCounter_;
63 };
64 
65 #endif
Reversible::postChildren_
std::stack< Reversible * > postChildren_
Definition: Reversible.hh:58
Reversible::idCounter_
static int idCounter_
Definition: Reversible.hh:62
Reversible::undoAndRemovePreChildren
void undoAndRemovePreChildren()
Definition: Reversible.cc:80
Reversible::id_
int id_
Definition: Reversible.hh:61
Reversible::undoAndRemoveChildren
void undoAndRemoveChildren(std::stack< Reversible * > &children)
Definition: Reversible.cc:55
Reversible::operator()
virtual bool operator()()=0
Reversible
Definition: Reversible.hh:36
Reversible::preChildren_
std::stack< Reversible * > preChildren_
Definition: Reversible.hh:57
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
Reversible::undoOnlyMe
virtual void undoOnlyMe()
Definition: Reversible.cc:98
Reversible::deleteChildren
void deleteChildren(std::stack< Reversible * > &children)
Definition: Reversible.cc:42
Reversible::~Reversible
virtual ~Reversible()
Definition: Reversible.cc:35
Reversible::runChild
bool runChild(std::stack< Reversible * > &children, Reversible *child)
Definition: Reversible.cc:109
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
Reversible::undoAndRemovePostChildren
void undoAndRemovePostChildren()
Definition: Reversible.cc:89
Reversible::Reversible
Reversible()
Definition: Reversible.hh:44
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
Reversible::id
int id()
Definition: Reversible.hh:43