OpenASIP 2.2
Loading...
Searching...
No Matches
CostDBEntryKey.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 CostDBEntryKey.cc
26 *
27 * Implementation of CostDBEntryKey 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 "CostDBEntryKey.hh"
35#include "Application.hh"
36#include <iostream>
37
38/**
39 * Constructor.
40 *
41 * @param entryType Type of the entry key.
42 */
44 type_(entryType) {
45}
46
47/**
48 * Destructor.
49 *
50 * Deallocates memory reserved for the fields of the entry key.
51 */
53 for (FieldTable::iterator i = fields_.begin(); i != fields_.end(); i++) {
54 assert(*i != NULL);
55 delete *i;
56 *i = NULL;
57 }
58}
59
60/**
61 * Copies the entry key.
62 *
63 * Client is responsible of deallocating the memory reserved for the
64 * returned object.
65 *
66 * @return A copy of the entry key.
67 */
70
72
73 for (FieldTable::const_iterator i = fields_.begin();
74 i != fields_.end(); i++) {
75
76 copy->addField(new EntryKeyField(*(*i)));
77 }
78 return copy;
79}
80
81/**
82 * Adds certain field to the entry key.
83 *
84 * @param field A field to be added.
85 * @exception ObjectAlreadyExists Equal field already exists.
86 */
87void
89 for (FieldTable::iterator i = fields_.begin(); i != fields_.end(); i++) {
90 if ((*i)->type() == field->type()) {
92 __FILE__, __LINE__, "CostDBEntryKey::addField");
93 }
94 }
95 fields_.push_back(field);
96}
97
98/**
99 * Replaces certain field of the entry key.
100 *
101 * @param newField A field.
102 * @exception KeyNotFound Equal field was not found.
103 */
104void
106 for (FieldTable::iterator i = fields_.begin(); i != fields_.end(); i++) {
107 if ((*i)->type() == newField->type()) {
108 delete *i;
109 *i = newField;
110 return;
111 }
112 }
113 throw KeyNotFound(__FILE__, __LINE__, "CostDBEntry::replaceField");
114}
115
116/**
117 * Returns demanded field of the entry key.
118 *
119 * @param fieldType Type of the field.
120 * @exception KeyNotFound Requested field type was not found.
121 */
124 for (FieldTable::const_iterator i = fields_.begin();
125 i != fields_.end(); i++) {
126 if ((*i)->type() == &fieldType) {
127 return *(*i);
128 }
129 }
130 throw KeyNotFound(__FILE__, __LINE__, "CostDBEntry::keyFieldOfType");
131 return *fields_[0];// stupid return statement to make compiler quiet
132}
133
134/**
135 * Returns demanded field of the entry key.
136 *
137 * @return type Type of the field.
138 */
140CostDBEntryKey::keyFieldOfType(std::string fieldType) const {
141
142 return keyFieldOfType(*type_->fieldProperty(fieldType));
143}
144
145/**
146 * Compares if two entry keys are equal.
147 *
148 * @param entryKey An entry key.
149 * @return True if two entry keys are equal, otherwise false.
150 */
151bool
153
154 if (type() == entryKey.type()) {
155 bool isMatch = true;
156 for (FieldTable::const_iterator f = fields_.begin();
157 f != fields_.end(); f++) {
158
159 if (!(*f)->isEqual(entryKey.keyFieldOfType(*(*f)->type()))) {
160 isMatch = false;
161 break;
162 }
163 }
164 if (isMatch) {
165 return true;
166 }
167 }
168 return false;
169}
170
171/**
172 * Returns the field found on the given index.
173 *
174 * The index must be between 0 and the number of fields - 1.
175 *
176 * @param index Index.
177 * @return The field found on the given index.
178 * @exception OutOfRange Index was out of range.
179 */
180const EntryKeyField&
181CostDBEntryKey::field(int index) const {
182 if (index >= fieldCount() || index < 0) {
183 throw OutOfRange(__FILE__, __LINE__, "CostDBEntryKey::field");
184 }
185 return *fields_[index];
186}
#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
const EntryKeyProperty * type_
Type of the entry key.
CostDBEntryKey(const EntryKeyProperty *entryType)
void addField(EntryKeyField *field)
int fieldCount() const
virtual ~CostDBEntryKey()
FieldTable fields_
Fields of the entry key.
const EntryKeyProperty * type() const
const EntryKeyFieldProperty * type() const
EntryKeyFieldProperty * fieldProperty(std::string field) const