OpenASIP 2.2
Loading...
Searching...
No Matches
CostDBEntry.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 CostDBEntry.cc
26 *
27 * Implementation of CostDBEntry class.
28 *
29 * @author Tommi Rantanen 2003 (tommi.rantanen-no.spam-tut.fi)
30 * @author Jari Mäntyneva 2005 (jari.mantyneva-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include "CostDBEntry.hh"
35#include "Application.hh"
36#include "CostDBEntryStatsRF.hh"
37#include "CostDBEntryStatsFU.hh"
38
39/**
40 * Constructor.
41 *
42 * @param key An entry key.
43 */
45 entryKey_(key) {
46}
47
48/**
49 * Constructor.
50 *
51 * Combines two entries into one using weighter as a weighting factor
52 * on interpolating the statistics. Also replacing weighter field in
53 * entry key.
54 *
55 * @param entry1 First entry.
56 * @param entry2 Second entry.
57 * @param weighter A field.
58 */
60 const CostDBEntry& entry1,
61 const CostDBEntry& entry2,
62 const EntryKeyField& weighter) {
63
64 EntryKeyField field1 = entry1.keyFieldOfType(*weighter.type());
65 EntryKeyField field2 = entry2.keyFieldOfType(*weighter.type());
66 double coefficient = weighter.coefficient(field1, field2);
67
68 entryKey_ = entry1.entryKey_->copy();
69 entryKey_->replaceField(new EntryKeyField(weighter));
70 for (StatsTable::const_iterator i = entry1.entryStats_.begin();
71 i != entry1.entryStats_.end(); i++) {
72 for (StatsTable::const_iterator j = entry2.entryStats_.begin();
73 j != entry2.entryStats_.end(); j++) {
74 // newStats cannot be base class type if stats are for FU or RF
75 if (dynamic_cast<CostDBEntryStatsRF*>(*i) &&
76 dynamic_cast<CostDBEntryStatsRF*>(*j)) {
78 *dynamic_cast<CostDBEntryStatsRF*>(*i),
79 *dynamic_cast<CostDBEntryStatsRF*>(*j), coefficient);
80 addStatistics(newStats);
81 } else if (dynamic_cast<CostDBEntryStatsFU*>(*i) &&
82 dynamic_cast<CostDBEntryStatsFU*>(*j)) {
84 *dynamic_cast<CostDBEntryStatsFU*>(*i),
85 *dynamic_cast<CostDBEntryStatsFU*>(*j), coefficient);
86 addStatistics(newStats);
87 } else { // if the entry is Bus or Socket
88 CostDBEntryStats* newStats =
89 new CostDBEntryStats(*(*i), *(*j), coefficient);
90 addStatistics(newStats);
91 }
92 }
93 }
94}
95
96/**
97 * Destructor.
98 */
100 assert(entryKey_ != NULL);
101 delete entryKey_;
102 entryKey_ = NULL;
103
104 for (StatsTable::iterator i = entryStats_.begin();
105 i != entryStats_.end(); i++) {
106 assert(*i != NULL);
107 delete *i;
108 }
109}
110
111/**
112 * Copies the entry.
113 *
114 * Client is responsible of deallocating the memory reserved for the
115 * returned object.
116 *
117 * @return A copy of the entry.
118 */
121 CostDBEntry* newEntry = new CostDBEntry(entryKey_->copy());
122
123 for (StatsTable::const_iterator i = entryStats_.begin();
124 i != entryStats_.end(); i++) {
125 newEntry->addStatistics((*i)->copy());
126 }
127
128 return newEntry;
129}
130
131/**
132 * Returns type of the entry.
133 *
134 * @return Type.
135 */
136const EntryKeyProperty*
138 return entryKey_->type();
139}
140
141/**
142 * Returns demanded field of the entry.
143 *
144 * @param type Type of the field.
145 * @return Demanded entry field.
146 */
151
152/**
153 * Returns demanded field of the entry.
154 *
155 * @param type Type of the field.
156 * @return Demanded entry field.
157 */
159CostDBEntry::keyFieldOfType(std::string type) const {
161}
162
163/**
164 * Returns the number of fields in an entry.
165 *
166 * @return The number of fields in an entry.
167 */
168int
170 return entryKey_->fieldCount();
171}
172
173/**
174 * Returns the field found on the given index.
175 *
176 * The index must be between 0 and the number of entry key - 1.
177 *
178 * @param index Index.
179 * @return The field found on the given index.
180 */
181const EntryKeyField&
182CostDBEntry::field(int index) const {
183 return entryKey_->field(index);
184}
185
186/**
187 * Replaces certain field of the entry.
188 *
189 * @param newField A field.
190 */
191void
195
196/**
197 * Checks whether two entries have equal key.
198 *
199 * @param entry Database entry to compare with.
200 * @return True if two entries have equal key, false otherwise.
201 */
202bool
204 return entryKey_->isEqual(*entry.entryKey_);
205}
206
207/**
208 * Add new statistics into this entry.
209 *
210 * @param newStats Statistics to be added.
211 */
212void
214 entryStats_.push_back(newStats);
215}
216
217
218/**
219 * Returns the number of statistics in the entry.
220 *
221 * @return Number of statistics in the entry.
222 */
223int
225 return entryStats_.size();
226}
227
228/**
229 * Returns the statistics according to given index.
230 *
231 * @param index The index of the statistics.
232 * @return The statistics according to given index.
233 * @throw OutOfRange Index is out of bounds.
234 */
235const CostDBEntryStats&
236CostDBEntry::statistics(int index) const {
237 if (index < 0 || index >= statisticsCount()) {
238 throw OutOfRange(__FILE__, __LINE__, "CostDBEntry::statistics");
239 }
240 return *entryStats_[index];
241}
#define assert(condition)
bool isEqual(const CostDBEntryKey &entryKey) const
EntryKeyField keyFieldOfType(const EntryKeyFieldProperty &fieldType) const
CostDBEntryKey * copy() const
void replaceField(EntryKeyField *newField)
const EntryKeyField & field(int index) const
int fieldCount() const
const EntryKeyProperty * type() const
CostDBEntry(CostDBEntryKey *key)
int fieldCount() const
CostDBEntry * copy() const
const EntryKeyField & field(int index) const
StatsTable entryStats_
Statistics of the entry.
virtual ~CostDBEntry()
const EntryKeyProperty * type() const
CostDBEntryKey * entryKey_
Key of the entry.
void addStatistics(CostDBEntryStats *newStats)
EntryKeyField keyFieldOfType(const EntryKeyFieldProperty &type) const
void replaceField(EntryKeyField *newField)
const CostDBEntryStats & statistics(int index) const
bool isEqualKey(const CostDBEntry &entry) const
int statisticsCount() const
double coefficient(const EntryKeyField &field1, const EntryKeyField &field2) const
const EntryKeyFieldProperty * type() const