OpenASIP  2.0
OperationModule.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 OperationModule.cc
26  *
27  * Definition of OperationModule class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: yellow
31  * @note reviewed 7 September 2004 by pj, jn, jm, ao
32  */
33 
34 #include <string>
35 
36 #include "OperationModule.hh"
37 #include "FileSystem.hh"
38 
39 using std::string;
40 
41 /// Property file extension.
42 const string OperationModule::PROPERTY_FILE_EXTENSION = ".opp";
43 /// Behavior file extension.
44 const string OperationModule::BEHAVIOR_FILE_EXTENSION = ".opb";
45 /// Source file extension.
47 
48 /**
49  * Constructor.
50  *
51  * @param name The name of the module.
52  * @param path The path of the module.
53  */
55  const std::string& name,
56  const std::string& path) : path_(path), name_(name) {
57 }
58 
59 /**
60  * Copy constructor.
61  *
62  * @param om The module to be copied.
63  */
65  name_ = om.name();
67 }
68 
69 /**
70  * Destructor.
71  */
73 }
74 
75 /**
76  * Assignment operator.
77  *
78  * @param om Module to be assigned.
79  */
82  name_ = om.name();
84  return *this;
85 }
86 
87 /**
88  * Checks whether OperationModule has behavior definition file.
89  *
90  * @return True if OperationModule has behavior definition file.
91  */
92 bool
94  return (FileSystem::fileExists(
96 }
97 
98 /**
99  * Returns the name of the behavior module.
100  *
101  * @return The name of the behavior module.
102  * @exception FileNotFound If behavior module is not found.
103  */
104 string
106  if (!definesBehavior()) {
107  std::string method = "OperationModule::behaviorModule()";
108  std::string msg = "Behavior file not found: " + behaviorFileName();
109  throw FileNotFound(__FILE__, __LINE__, method, msg);
110  }
111 
113 }
114 
115 /**
116  * Returns the name of the properties module.
117  *
118  * @return The name of the properties module.
119  */
120 string
123 }
124 
125 /**
126  * Checks whether module has behavior source file.
127  *
128  * @return True if module has behavior source file.
129  */
130 bool
132  return (FileSystem::fileExists(
135 }
136 
137 /**
138  * Returns the name of the behavior source code file.
139  *
140  * @return The name of the behavior source code file.
141  * @exception FileNotFound If behavior source file not found.
142  */
143 string
145  if (!hasBehaviorSource()) {
146  std::string method = "OperationModule::behaviorSourceModule()";
147  std::string msg = "Behavior source file not found.";
148  throw FileNotFound(__FILE__, __LINE__, method, msg);
149  }
150 
152 }
153 
154 /**
155  * Returns the name of the module.
156  *
157  * @return The name of the module.
158  */
159 std::string
161  return name_;
162 }
163 
164 /**
165  * Returns the name of the behavior file name.
166  *
167  * @return The name of the behavior file name.
168  */
169 std::string
172 }
173 
174 /**
175  * Returns the name of the properties file.
176  *
177  * @return The name of the properties file.
178  */
179 std::string
182 }
183 
184 /**
185  * Returns the name of the code file.
186  *
187  * @return The name of the code file.
188  */
189 std::string
192 }
193 
194 //////////////////////////////////////////////////////////////////////////////
195 // NullOperationModule
196 //////////////////////////////////////////////////////////////////////////////
197 
199 
200 /**
201  * Constructor.
202  */
204 }
205 
206 /**
207  * Destructor.
208  */
210 }
211 
212 /**
213  * Writes a message to error log and aborts the program.
214  *
215  * @return Never returns.
216  */
217 string
219  abortWithError("name()");
220  return "";
221 }
222 
223 /**
224  * Writes a message to error log and aborts the program.
225  *
226  * @return Never returns.
227  */
228 bool
230  abortWithError("definesBehavior()");
231  return false;
232 }
233 
234 /**
235  * Writes a message to error log and aborts the program.
236  *
237  * @return Never returns.
238  * @exception FileNotFound If behavior module is not found.
239  */
240 string
242  abortWithError("behaviorModule()");
243  return "";
244 }
245 
246 /**
247  * Writes a message to error log and aborts the program.
248  *
249  * @return Never returns.
250  */
251 string
253 
254  abortWithError("propertiesModule()");
255  return "";
256 }
257 
258 /**
259  * Writes a message to error log and aborts the program.
260  *
261  * @return Never returns.
262  */
263 bool
265  abortWithError("hasBehaviorSource()");
266  return false;
267 }
268 
269 /**
270  * Writes a message to error log and aborts the program.
271  *
272  * @return Never returns.
273  * @exception FileNotFound Doesn't throw.
274  */
275 string
277  abortWithError("behaviorSourceModule()");
278  return "";
279 }
NullOperationModule::~NullOperationModule
virtual ~NullOperationModule()
Definition: OperationModule.cc:209
OperationModule::definesBehavior
virtual bool definesBehavior() const
Definition: OperationModule.cc:93
FileSystem.hh
FileNotFound
Definition: Exception.hh:224
NullOperationModule::name
virtual std::string name() const
Definition: OperationModule.cc:218
OperationModule::~OperationModule
virtual ~OperationModule()
Definition: OperationModule.cc:72
NullOperationModule::behaviorModule
virtual std::string behaviorModule() const
Definition: OperationModule.cc:241
NullOperationModule::definesBehavior
virtual bool definesBehavior() const
Definition: OperationModule.cc:229
OperationModule::OperationModule
OperationModule(const std::string &name, const std::string &path)
Definition: OperationModule.cc:54
OperationModule::behaviorModule
virtual std::string behaviorModule() const
Definition: OperationModule.cc:105
NullOperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:252
OperationModule::path_
std::string path_
The path of the module.
Definition: OperationModule.hh:75
OperationModule::name_
std::string name_
The name of the module.
Definition: OperationModule.hh:77
NullOperationModule::NullOperationModule
NullOperationModule()
Definition: OperationModule.cc:203
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:121
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
OperationModule::behaviorSourceModule
virtual std::string behaviorSourceModule() const
Definition: OperationModule.cc:144
FileSystem::directoryOfPath
static std::string directoryOfPath(const std::string fileName)
Definition: FileSystem.cc:79
OperationModule::BEHAVIOR_SOURCE_FILE_EXTENSION
static const std::string BEHAVIOR_SOURCE_FILE_EXTENSION
File extension of operation behavior source file.
Definition: OperationModule.hh:72
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
NullOperationModule::instance_
static NullOperationModule instance_
Unique instance of NullOperationModule.
Definition: OperationModule.hh:108
NullOperationModule::behaviorSourceModule
virtual std::string behaviorSourceModule() const
Definition: OperationModule.cc:276
FileSystem::fileExists
static bool fileExists(const std::string fileName)
OperationModule
Definition: OperationModule.hh:46
OperationModule::hasBehaviorSource
virtual bool hasBehaviorSource() const
Definition: OperationModule.cc:131
OperationModule::operator=
OperationModule & operator=(const OperationModule &om)
Definition: OperationModule.cc:81
OperationModule::BEHAVIOR_FILE_EXTENSION
static const std::string BEHAVIOR_FILE_EXTENSION
File extension of operation behavior file.
Definition: OperationModule.hh:70
NullOperationModule::hasBehaviorSource
virtual bool hasBehaviorSource() const
Definition: OperationModule.cc:264
OperationModule::PROPERTY_FILE_EXTENSION
static const std::string PROPERTY_FILE_EXTENSION
File extension of operation property file.
Definition: OperationModule.hh:68
NullOperationModule
Definition: OperationModule.hh:88
OperationModule::behaviorSourceFileName
std::string behaviorSourceFileName() const
Definition: OperationModule.cc:190
OperationModule::name
virtual std::string name() const
Definition: OperationModule.cc:160
OperationModule::behaviorFileName
std::string behaviorFileName() const
Definition: OperationModule.cc:170
OperationModule::propertyFileName
std::string propertyFileName() const
Definition: OperationModule.cc:180
OperationModule.hh