OpenASIP  2.0
UnconditionalGuardEncoding.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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  * @file UnconditionalGuardEncoding.cc
26  *
27  * Implementation of UnconditionalGuardEncoding class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
36 #include "GuardField.hh"
37 #include "ObjectState.hh"
38 
39 using std::string;
40 
41 const std::string UnconditionalGuardEncoding::
42 OSNAME_UNCONDITIONAL_GUARD_ENCODING = "uc_guard_encoding";
43 
44 /**
45  * The constructor.
46  *
47  * Registers the encoding to the given guard field automatically.
48  *
49  * @param inverted Indicates whether the encoding is for always-true or
50  * always-false guard expression.
51  * @param encoding The encoding for unconditional guard.
52  * @param parent The parent guard field.
53  * @exception ObjectAlreadyExists If the guard field has an encoding for the
54  * same unconditional guard expression
55  * already, or if the given encoding is
56  * already assigned.
57  */
59  bool inverted, unsigned int encoding, GuardField& parent)
60  : GuardEncoding(inverted, encoding) {
61  parent.addGuardEncoding(*this);
62  setParent(&parent);
63 }
64 
65 /**
66  * The constructor.
67  *
68  * Loads the state of the object from the given ObjectState instance.
69  *
70  * @param state The ObjectState instance.
71  * @param parent The parent guard field.
72  * @exception ObjectStateLoadingException If an error occurs while loading
73  * the state.
74  * @exception ObjectAlreadyExists If the guard field has an encoding for the
75  * same unconditional guard expression
76  * already, of if the encoding in the
77  * ObjectState instance is already assigned.
78  */
80  const ObjectState* state, GuardField& parent)
81  : GuardEncoding(state) {
82  if (state->name() != OSNAME_UNCONDITIONAL_GUARD_ENCODING) {
83  const string procName =
84  "UnconditionalGuardEncoding::UnconditionalGuardEncoding";
85  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
86  }
87 
88  parent.addGuardEncoding(*this);
89  setParent(&parent);
90 }
91 
92 /**
93  * The destructor.
94  */
96  GuardField* oldParent = parent();
97  setParent(NULL);
98  oldParent->removeUnconditionalGuardEncoding(*this);
99 }
100 
101 
102 /**
103  * Saves the state of the object to an ObjectState instance.
104  *
105  * @return The newly created ObjectState instance.
106  */
111  return state;
112 }
UnconditionalGuardEncoding.hh
ObjectStateLoadingException
Definition: Exception.hh:551
GuardField.hh
GuardField::removeUnconditionalGuardEncoding
void removeUnconditionalGuardEncoding(UnconditionalGuardEncoding &encoding)
Definition: GuardField.cc:252
ObjectState
Definition: ObjectState.hh:59
GuardField
Definition: GuardField.hh:55
ObjectState::setName
void setName(const std::string &name)
GuardField::addGuardEncoding
void addGuardEncoding(GPRGuardEncoding &encoding)
Definition: GuardField.cc:141
UnconditionalGuardEncoding::UnconditionalGuardEncoding
UnconditionalGuardEncoding(bool inverted, unsigned int encoding, GuardField &parent)
Definition: UnconditionalGuardEncoding.cc:58
GuardEncoding::setParent
void setParent(GuardField *parent)
Definition: GuardEncoding.cc:137
GuardEncoding
Definition: GuardEncoding.hh:45
ObjectState.hh
UnconditionalGuardEncoding::saveState
virtual ObjectState * saveState() const
Definition: UnconditionalGuardEncoding.cc:108
ObjectState::name
std::string name() const
UnconditionalGuardEncoding::OSNAME_UNCONDITIONAL_GUARD_ENCODING
static const std::string OSNAME_UNCONDITIONAL_GUARD_ENCODING
ObjectState name for unconditional guard encoding.
Definition: UnconditionalGuardEncoding.hh:57
UnconditionalGuardEncoding::~UnconditionalGuardEncoding
virtual ~UnconditionalGuardEncoding()
Definition: UnconditionalGuardEncoding.cc:95
GuardEncoding::saveState
virtual ObjectState * saveState() const
Definition: GuardEncoding.cc:123
GuardEncoding::parent
GuardField * parent() const
Definition: GuardEncoding.cc:90