OpenASIP 2.2
Loading...
Searching...
No Matches
UnitImplementationLocation.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 UnitImplementationLocation.cc
26 *
27 * Implementation of UnitImplementationLocation class.
28 *
29 * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include <vector>
35
38#include "FileSystem.hh"
39#include "ObjectState.hh"
40
41using std::string;
42using std::vector;
43
44namespace IDF {
45
47 "unit_implementation";
48const string UnitImplementationLocation::OSKEY_ID = "id";
49const string UnitImplementationLocation::OSKEY_UNIT_NAME = "unit_name";
50const string UnitImplementationLocation::OSKEY_HDB_FILE = "hdb_file";
51
52
53/**
54 * The constructor.
55 *
56 * @param hdbFile The database that contains the implementation.
57 * @param id ID of the RF or FU entry in the database.
58 * @param unitName Name of the corresponding unit in ADF.
59 */
61 const std::string& hdbFile,
62 int id,
63 const std::string& unitName) :
64 hdbFile_(hdbFile), id_(id), unitName_(unitName), parent_(NULL) {
65}
66
67
68/**
69 * The constructor.
70 *
71 * Loads the state of the object from the given ObjectState instance.
72 *
73 * @param state The ObjectState instance.
74 * @exception ObjectStateLoadingException If the given ObjectState instance
75 * is invalid.
76 */
78 : hdbFile_(""), id_(0), unitName_(""), parent_(NULL) {
79 /// this is used by NullFUImplementationLocation
80 if (state == NULL)
81 return;
82 loadState(state);
83}
84
85/**
86 * The destructor.
87 */
90
91
92/**
93 * Returns the absolute path to the HDB file.
94 *
95 * @return Absolute path to the HDB file.
96 * @exception FileNotFound If the HDB file is not found in the search paths.
97 */
98std::string
100 vector<string> paths = Environment::hdbPaths();
101 if (parent_) {
102 paths.insert(
104 }
105 TCEString expandedPath(hdbFile_);
106 expandedPath.replaceString("tce:", "");
107 expandedPath = FileSystem::expandTilde(expandedPath);
108 return FileSystem::findFileInSearchPaths(paths, expandedPath);
109}
110
111/**
112 * Returns the path to the file, which was defined in IDF.
113 *
114 * @return Path to the HDB in IDF file.
115 */
116std::string
120
121/**
122 * Returns the entry ID in HDB.
123 *
124 * @return The entry ID.
125 */
126int
128 return id_;
129}
130
131
132/**
133 * Returns the name of the unit in ADF.
134 *
135 * @return The name of the unit.
136 */
137std::string
141
142
143/**
144 * Sets the parent of the object.
145 *
146 * @param parent The parent MachineImplementation instance.
147 * @exception InvalidData If the parent is already set.
148 */
149void
151 if (parent_ != NULL) {
152 throw InvalidData(__FILE__, __LINE__, __func__);
153 }
154
155 parent_ = &parent;
156}
157
158/**
159 * Loads the state of the object from the given ObjectState instance.
160 *
161 * @exception ObjectStateLoadingException If the given ObjectState instance.
162 */
163void
165 const string procName = "UnitImplementationLocation::loadState";
166
167 if (state->name() != OSNAME_UNIT_IMPLEMENTATION) {
168 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
169 }
170
171 try {
173 id_ = state->intAttribute(OSKEY_ID);
175 } catch (const Exception& exception) {
177 __FILE__, __LINE__, procName, exception.errorMessage());
178 }
179}
180
181/**
182 * Saves the state of the object to an ObjectState instance.
183 *
184 * @return The newly created ObjectState instance.
185 */
194
195/**
196 * Sets the absolute path to the HDB file.
197 *
198 * @param file Absolute path to the HDB file.
199 */
200void
202 hdbFile_ = file;
203}
204
205
206/**
207 * Sets the entry ID in HDB.
208 */
209void
213
214}
#define __func__
static std::vector< std::string > hdbPaths(bool libraryPathsOnly=false)
std::string errorMessage() const
Definition Exception.cc:123
static std::string directoryOfPath(const std::string fileName)
Definition FileSystem.cc:79
static std::string findFileInSearchPaths(const std::vector< std::string > &searchPaths, const std::string &file)
static std::string expandTilde(const std::string &stringWithTilde)
static const std::string OSNAME_UNIT_IMPLEMENTATION
ObjectState name for unit implementation.
static const std::string OSKEY_ID
ObjectState attribute key for the entry ID.
UnitImplementationLocation(const std::string &hdbFile, int id, const std::string &unitName)
std::string hdbFile_
Name of the HDB file.
void loadState(const ObjectState *state)
virtual void setHDBFile(std::string file)
virtual void setParent(MachineImplementation &parent)
static const std::string OSKEY_UNIT_NAME
Objectstate attribute key for the name of the unit.
MachineImplementation * parent_
The parent MachineImplementation instance.
static const std::string OSKEY_HDB_FILE
ObjectState attribute key for the name of the HDB file.
std::string unitName_
Name of the unit in ADF.
void setAttribute(const std::string &name, const std::string &value)
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string name() const
TCEString & replaceString(const std::string &old, const std::string &newString)
Definition TCEString.cc:94