OpenASIP 2.2
Loading...
Searching...
No Matches
CostDatabaseRegistry.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 CostDatabaseRegistry.cc
26 *
27 * Implementation of CostDatabaseRegistry class.
28 *
29 * @author Jari Mäntyneva 2007 (jari.mantyneva-no.spam-tut.fi)
30 * @note rating: red
31 */
33#include "AssocTools.hh"
34#include "HDBManager.hh"
35#include "Application.hh"
36#include "CostDatabase.hh"
37
39
40/**
41 * Constructor.
42 */
45
46/**
47 * Destructor.
48 */
53
54/**
55 * Creates and returns an instance of cost database registry.
56 *
57 * @return An instance of cost database registry.
58 */
61
62 if (instance_ == NULL) {
64 }
65 return *instance_;
66}
67
68/**
69 * Returns CostDatabase that is build against the HDB at given path.
70 *
71 * In case the CostDatabase is not found in registry, tries to generate it.
72 *
73 * @param hdbFileName File name of the HDB to build the CostDatabase against.
74 * @return The CostDatabase build against the HDB file.
75 * @exception Exception In case there was a problem while creating the
76 * CostDatabase.
77 */
87
88/**
89 * Adds CostDatabase and HDB used in the CostDatabase in to the registry.
90 *
91 * @param costDatabase The cost database to be added in to the registry.
92 * @param hdb The HDB that is used to create the CostDatabase.
93 */
94void
96 CostDatabase* costDatabase, const HDB::HDBManager& hdb) {
97
99 delete costDatabase;
100 costDatabase = NULL;
101 return;
102 }
103 registry_[&hdb] = costDatabase;
104}
105
106/**
107 * Returns true if the registry contains a CostDatabase build against the
108 * given HDB.
109 *
110 * @param hdb The HDB that is used in creating the CostDatabase.
111 * @return True if the registry contains a CostDatabase build against the
112 * given HDB.
113 */
114bool
116
118 return true;
119 } else {
120 return false;
121 }
122}
123
124/**
125 * Returns the total number of stored CostDatabases.
126 *
127 * @return Count of stored CostDatabases.
128 */
129int
134
135/**
136 * Returns the CostDatabase from given index.
137 *
138 * @return The CostDatabase from the given index.
139 * @exception OutOfRange Is thrown if index is bigger than the CostDatabase
140 * count.
141 */
144 if (index > (registry_.size() - 1)) {
145 throw OutOfRange(__FILE__, __LINE__,
146 "CostDatabaseRegistry::costDatavase(unsigned int)");
147 }
148 std::map<const HDB::HDBManager*, CostDatabase*>::const_iterator iter =
149 registry_.begin();
150 for (unsigned int counter = 0; iter != registry_.end(); iter++) {
151 if (counter == index) {
152 break;
153 } else {
154 counter++;
155 }
156 }
157 return *(*iter).second;
158}
159
160/**
161 * Returns the full path of the HDB with given index.
162 *
163 * @return The HDB file path.
164 * @exception OutOfRange Is thrown if index is out of range.
165 */
166std::string
168 if (index > (registry_.size() - 1)) {
169 throw OutOfRange(__FILE__, __LINE__,
170 "CostDatabaseRegistry::hdbPath(unsigned int)");
171 }
172 std::map<const HDB::HDBManager*, CostDatabase*>::const_iterator iter =
173 registry_.begin();
174
175 for (unsigned c = 0; iter != registry_.end(); iter++) {
176 if (c == index) return (*iter).first->fileName();
177 c++;
178 }
179 assert(false);
180}
#define assert(condition)
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
static void deleteAllValues(ContainerType &aMap)
std::string hdbPath(unsigned int index)
bool hasCostDatabase(const HDB::HDBManager &hdb)
static CostDatabaseRegistry & instance()
CostDatabase & costDatabase(const HDB::HDBManager &hdb)
void addCostDatabase(CostDatabase *costDatabase, const HDB::HDBManager &hdb)
CostDatabaseRegistry()
CostDatabase registry must be created with instance() method.
static CostDatabaseRegistry * instance_
Unique instance of the class.
std::map< const HDB::HDBManager *, CostDatabase * > registry_
All created CostDatabasess are stored in this map.
static CostDatabase & instance(const HDB::HDBManager &hdb)