OpenASIP  2.0
FUGuardEncoding.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 FUGuardEncoding.cc
26  *
27  * Implementation of FUGuardEncoding class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "FUGuardEncoding.hh"
36 #include "GuardField.hh"
37 #include "ObjectState.hh"
38 
39 using std::string;
40 
41 const std::string FUGuardEncoding::OSNAME_FU_GUARD_ENCODING = "fu_guard_enc";
42 const std::string FUGuardEncoding::OSKEY_FU_NAME = "fu_name";
43 const std::string FUGuardEncoding::OSKEY_PORT_NAME = "port_name";
44 
45 /**
46  * The constructor.
47  *
48  * Creates a guard encoding and registers it into the given guard field. The
49  * guard expression is identified by the name of function unit and port, and
50  * the "invert" flag, all given as parameters.
51  *
52  * @param fu Name of the function unit.
53  * @param port Name of the port.
54  * @param inverted The "invert" flag.
55  * @param encoding The control code of the guard expression.
56  * @param parent The parent guard field.
57  * @exception ObjectAlreadyExists If the guard expression is already encoded
58  * in the parent field, or if the given control
59  * code is already assigned to another guard
60  * expression.
61  */
63  const std::string& fu, const std::string& port, bool inverted,
64  unsigned int encoding, GuardField& parent)
65  : GuardEncoding(inverted, encoding), functionUnit_(fu), port_(port) {
66  parent.addGuardEncoding(*this);
67  setParent(&parent);
68 }
69 
70 /**
71  * The constructor.
72  *
73  * Loads the state of the object from the given ObjectState instance.
74  *
75  * @param state The ObjectState instance.
76  * @param parent The parent guard field.
77  * @exception ObjectStateLoadingException If an error occurs while loading the
78  * state.
79  * @exception ObjectAlreadyExists If the guard expression if already encoded
80  * in the parent field, or if the given control
81  * code is already assigned to another guard
82  * expression.
83  */
85  : GuardEncoding(state), functionUnit_(""), port_("") {
86  const string procName = "FUGuardEncoding::FUGuardEncoding";
87 
88  if (state->name() != OSNAME_FU_GUARD_ENCODING) {
89  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
90  }
91 
92  try {
95  } catch (const Exception& exception) {
97  __FILE__, __LINE__, procName, exception.errorMessage());
98  }
99 
100  parent.addGuardEncoding(*this);
101  setParent(&parent);
102 }
103 
104 /**
105  * The destructor.
106  */
108  GuardField* parent = this->parent();
109  setParent(NULL);
110  parent->removeGuardEncoding(*this);
111 }
112 
113 
114 /**
115  * Returns the name of the function unit that contains the port of this guard
116  * expression.
117  *
118  * @return The name of the function unit.
119  */
120 std::string
122  return functionUnit_;
123 }
124 
125 
126 /**
127  * Returns the name of the FU port of this guard expression.
128  *
129  * @return The name of the FU port.
130  */
131 std::string
133  return port_;
134 }
135 
136 
137 /**
138  * Saves the state of the object to an ObjectState instance.
139  *
140  * @return The newly created ObjectState instance.
141  */
147  state->setAttribute(OSKEY_PORT_NAME, port());
148  return state;
149 }
FUGuardEncoding::OSKEY_PORT_NAME
static const std::string OSKEY_PORT_NAME
ObjectState attribute key for the name of the port.
Definition: FUGuardEncoding.hh:65
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
FUGuardEncoding::saveState
virtual ObjectState * saveState() const
Definition: FUGuardEncoding.cc:143
ObjectStateLoadingException
Definition: Exception.hh:551
GuardField.hh
FUGuardEncoding::~FUGuardEncoding
virtual ~FUGuardEncoding()
Definition: FUGuardEncoding.cc:107
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
FUGuardEncoding::functionUnit
std::string functionUnit() const
Definition: FUGuardEncoding.cc:121
GuardEncoding::setParent
void setParent(GuardField *parent)
Definition: GuardEncoding.cc:137
FUGuardEncoding.hh
GuardEncoding
Definition: GuardEncoding.hh:45
FUGuardEncoding::FUGuardEncoding
FUGuardEncoding(const std::string &fu, const std::string &port, bool inverted, unsigned int encoding, GuardField &parent)
Definition: FUGuardEncoding.cc:62
FUGuardEncoding::OSNAME_FU_GUARD_ENCODING
static const std::string OSNAME_FU_GUARD_ENCODING
ObjectState name for FU guard encoding.
Definition: FUGuardEncoding.hh:61
FUGuardEncoding::functionUnit_
std::string functionUnit_
Name of the function unit.
Definition: FUGuardEncoding.hh:69
ObjectState.hh
Exception
Definition: Exception.hh:54
ObjectState::name
std::string name() const
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
GuardField::removeGuardEncoding
void removeGuardEncoding(GPRGuardEncoding &encoding)
Definition: GuardField.cc:163
FUGuardEncoding::port
std::string port() const
Definition: FUGuardEncoding.cc:132
FUGuardEncoding::OSKEY_FU_NAME
static const std::string OSKEY_FU_NAME
ObjectState attribute key for the name of the function unit.
Definition: FUGuardEncoding.hh:63
GuardEncoding::saveState
virtual ObjectState * saveState() const
Definition: GuardEncoding.cc:123
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
FUGuardEncoding::port_
std::string port_
Name of the port.
Definition: FUGuardEncoding.hh:71
GuardEncoding::parent
GuardField * parent() const
Definition: GuardEncoding.cc:90