OpenASIP
2.2
Loading...
Searching...
No Matches
src
base
mach
MachinePart.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 MachinePart.cc
26
*
27
* Implementation of MachinePart class and derived Component and SubComponent
28
* classes.
29
*
30
* @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
31
* @note reviewed 17 Jun 2003 by jn, pj, jm, ll
32
* @note rating: red
33
*/
34
35
#include <string>
36
37
#include "
MachinePart.hh
"
38
#include "
MachineTester.hh
"
39
#include "
MOMTextGenerator.hh
"
40
#include "
Application.hh
"
41
#include "
ObjectState.hh
"
42
43
using
std::string;
44
using
boost::format;
45
46
namespace
TTAMachine
{
47
48
/////////////////////////////////////////////////////////////////////////////
49
// MachinePart
50
/////////////////////////////////////////////////////////////////////////////
51
52
/**
53
* Constructor.
54
*/
55
MachinePart::MachinePart
() : id_(idCounter_++){
56
}
57
58
59
/**
60
* Destructor.
61
*/
62
MachinePart::~MachinePart
() {
63
}
64
65
int
MachinePart::idCounter_
= 0;
66
67
68
/////////////////////////////////////////////////////////////////////////////
69
// Component
70
/////////////////////////////////////////////////////////////////////////////
71
72
const
string
Component::OSNAME_COMPONENT
=
"component"
;
73
const
string
Component::OSKEY_NAME
=
"name"
;
74
75
/**
76
* Constructor.
77
*
78
* @param name Name of the component.
79
* @exception InvalidName If the given name is not a valid name for a
80
* component.
81
*/
82
Component::Component
(
const
std::string& name)
83
:
MachinePart
(), name_(name), machine_(NULL) {
84
if
(!
MachineTester::isValidComponentName
(
name
)) {
85
const
string
procName =
"Component::Component"
;
86
MOMTextGenerator
textGen;
87
format errorMsg = textGen.
text
(
MOMTextGenerator::TXT_INVALID_NAME
);
88
errorMsg %
name
;
89
throw
InvalidName
(__FILE__, __LINE__, procName, errorMsg.str());
90
}
91
}
92
93
/**
94
* Constructor.
95
*
96
* Loads the name from the given ObjectState object.
97
*
98
* @param state The ObjectState instance from which the name is loaded.
99
* @exception ObjectStateLoadingException If the given ObjectState instance
100
* is invalid.
101
*/
102
Component::Component
(
const
ObjectState
* state) :
MachinePart
(), machine_(NULL) {
103
try
{
104
setName
(state->
stringAttribute
(
OSKEY_NAME
));
105
}
catch
(
const
Exception
& e) {
106
string
procName =
"Component::Component"
;
107
throw
ObjectStateLoadingException
(
108
__FILE__, __LINE__, procName, e.
errorMessage
());
109
}
110
}
111
112
/**
113
* Destructor.
114
*/
115
Component::~Component
() {
116
}
117
118
119
/**
120
* Returns the name of the component.
121
*
122
* @return Name of the component.
123
*/
124
TCEString
125
Component::name
()
const
{
126
return
name_
;
127
}
128
129
130
/**
131
* Sets the name of the component.
132
*
133
* @param name The new name.
134
* @exception ComponentAlreadExists Sub class implementations may throw the
135
* exception if there exists another
136
* component by the same name in the machine
137
* already.
138
* @exception InvalidName If the given name is not a valid name for
139
* a component.
140
*/
141
void
142
Component::setName
(
const
std::string& name) {
143
if
(!
MachineTester::isValidComponentName
(
name
)) {
144
const
string
procName =
"Component::setName"
;
145
MOMTextGenerator
textGen;
146
format errorMsg = textGen.
text
(
MOMTextGenerator::TXT_INVALID_NAME
);
147
errorMsg %
name
;
148
throw
InvalidName
(__FILE__, __LINE__, procName, errorMsg.str());
149
}
150
151
name_
=
name
;
152
}
153
154
/**
155
* Ensures that the component is registered to the same machine as the
156
* given component.
157
*
158
* @param component The component.
159
* @exception IllegalRegistration If the components are not registered to the
160
* same machine.
161
*/
162
void
163
Component::ensureRegistration
(
const
Component
& component)
const
{
164
if
(
machine
() == NULL ||
machine
() != component.
machine
()) {
165
const
string
procName =
"Component::ensureRegistration"
;
166
throw
IllegalRegistration
(__FILE__, __LINE__, procName);
167
}
168
}
169
170
/**
171
* Returns true if the component is registered to a machine, otherwise false.
172
*
173
* @return True if the component is registered to a machine, otherwise
174
* false.
175
*/
176
bool
177
Component::isRegistered
()
const
{
178
return
(
machine_
!= NULL);
179
}
180
181
182
/**
183
* Creates a new ObjectState instance and saves the name of the component
184
* into it.
185
*
186
* @return The newly created ObjectState instance.
187
*/
188
ObjectState
*
189
Component::saveState
()
const
{
190
ObjectState
* state =
new
ObjectState
(
OSNAME_COMPONENT
);
191
state->
setAttribute
(
OSKEY_NAME
,
name
());
192
return
state;
193
}
194
195
196
/**
197
* Loads the name of the component from the given ObjectState instance.
198
*
199
* @param state The ObjectState instance.
200
* @exception ObjectStateLoadingException If the machine already contains
201
* same type of component with the
202
* same name.
203
*/
204
void
205
Component::loadState
(
const
ObjectState
* state) {
206
const
string
procName =
"Component::loadState"
;
207
208
try
{
209
string
name
= state->
stringAttribute
(
OSKEY_NAME
);
210
setName
(
name
);
211
}
catch
(
const
KeyNotFound
& e) {
212
throw
ObjectStateLoadingException
(__FILE__, __LINE__, procName);
213
}
catch
(
const
ComponentAlreadyExists
& e) {
214
MOMTextGenerator
textGenerator;
215
format text = textGenerator.
text
(
216
MOMTextGenerator::TXT_SAME_NAME
);
217
text % state->
stringAttribute
(
OSKEY_NAME
);
218
throw
ObjectStateLoadingException
(
219
__FILE__, __LINE__, procName, text.str());
220
}
catch
(
const
InvalidName
& e) {
221
MOMTextGenerator
textGenerator;
222
format text = textGenerator.
text
(
223
MOMTextGenerator::TXT_INVALID_NAME
);
224
text % state->
stringAttribute
(
OSKEY_NAME
);
225
throw
ObjectStateLoadingException
(
226
__FILE__, __LINE__, procName, text.str());
227
}
228
}
229
230
/////////////////////////////////////////////////////////////////////////////
231
// SubComponent
232
/////////////////////////////////////////////////////////////////////////////
233
234
/**
235
* Constructor.
236
*/
237
SubComponent::SubComponent
() :
MachinePart
() {
238
}
239
240
241
/**
242
* Destructor.
243
*/
244
SubComponent::~SubComponent
() {
245
}
246
247
}
Application.hh
MOMTextGenerator.hh
MachinePart.hh
MachineTester.hh
ObjectState.hh
ComponentAlreadyExists
Definition
Exception.hh:510
Exception
Definition
Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition
Exception.cc:123
IllegalRegistration
Definition
Exception.hh:532
InvalidName
Definition
Exception.hh:827
KeyNotFound
Definition
Exception.hh:285
MOMTextGenerator
Definition
MOMTextGenerator.hh:40
MOMTextGenerator::TXT_INVALID_NAME
@ TXT_INVALID_NAME
Definition
MOMTextGenerator.hh:84
MOMTextGenerator::TXT_SAME_NAME
@ TXT_SAME_NAME
Definition
MOMTextGenerator.hh:83
MachineTester::isValidComponentName
static bool isValidComponentName(const std::string &name)
Definition
MachineTester.cc:312
ObjectStateLoadingException
Definition
Exception.hh:551
ObjectState
Definition
ObjectState.hh:59
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition
ObjectState.cc:100
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition
ObjectState.cc:249
TCEString
Definition
TCEString.hh:53
TTAMachine::Component
Definition
MachinePart.hh:90
TTAMachine::Component::setName
virtual void setName(const std::string &name)
Definition
MachinePart.cc:142
TTAMachine::Component::machine
virtual Machine * machine() const
TTAMachine::Component::loadState
virtual void loadState(const ObjectState *state)
Definition
MachinePart.cc:205
TTAMachine::Component::OSKEY_NAME
static const std::string OSKEY_NAME
ObjectState attribute key for the name of the component.
Definition
MachinePart.hh:137
TTAMachine::Component::OSNAME_COMPONENT
static const std::string OSNAME_COMPONENT
ObjectState name for component.
Definition
MachinePart.hh:135
TTAMachine::Component::~Component
virtual ~Component()
Definition
MachinePart.cc:115
TTAMachine::Component::Component
Component(const std::string &name)
Definition
MachinePart.cc:82
TTAMachine::Component::name_
std::string name_
Name of the component.
Definition
MachinePart.hh:153
TTAMachine::Component::isRegistered
virtual bool isRegistered() const
Definition
MachinePart.cc:177
TTAMachine::Component::machine_
Machine * machine_
Machine to which the component is registered.
Definition
MachinePart.hh:155
TTAMachine::Component::ensureRegistration
virtual void ensureRegistration(const Component &component) const
Definition
MachinePart.cc:163
TTAMachine::Component::name
virtual TCEString name() const
Definition
MachinePart.cc:125
TTAMachine::Component::saveState
virtual ObjectState * saveState() const
Definition
MachinePart.cc:189
TTAMachine::MachinePart
Definition
MachinePart.hh:57
TTAMachine::MachinePart::idCounter_
static int idCounter_
Id just for comparison for sets and maps. More deterministic than pointer to the object.
Definition
MachinePart.hh:74
TTAMachine::MachinePart::~MachinePart
virtual ~MachinePart()
Definition
MachinePart.cc:62
TTAMachine::MachinePart::MachinePart
MachinePart()
Definition
MachinePart.cc:55
TTAMachine::SubComponent::SubComponent
SubComponent()
Definition
MachinePart.cc:237
TTAMachine::SubComponent::~SubComponent
virtual ~SubComponent()
Definition
MachinePart.cc:244
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition
TextGenerator.cc:94
TTAMachine
Definition
Assembler.hh:48
Generated by
1.9.8