OpenASIP  2.0
InterPassData.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 InterPassData.cc
26  *
27  * Definition of InterPassData class.
28  *
29  * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "InterPassData.hh"
34 #include "InterPassDatum.hh"
35 #include "MapTools.hh"
36 
37 /**
38  * Constructor.
39  */
41 }
42 
43 /**
44  * Destructor.
45  *
46  * Deletes all added InterPassDatum objects.
47  */
50 }
51 
52 /**
53  * Returns a reference to the datum associated with the given key.
54  *
55  * It is allowed to modify the returned object directly.
56  *
57  * @param key The key.
58  * @returns The datum.
59  * @exception KeyNotFound thrown if the key is not found.
60  */
62 InterPassData::datum(const std::string& key) {
63  if (!MapTools::containsKey(data_, key))
64  throw KeyNotFound(__FILE__, __LINE__, __func__);
65 
66  return *data_[key];
67 }
68 
69 /**
70  * Returns true if there is a datum for the given key.
71  *
72  * @return True if there is a datum for the given key.
73  */
74 bool
75 InterPassData::hasDatum(const std::string& key) const {
76  return MapTools::containsKey(data_, key);
77 }
78 
79 /**
80  * Sets a datum for the given key.
81  *
82  * Ownership of the datum is transferred. Possible previously existing
83  * datum at the given key is deleted.
84  *
85  * @param key The key of the datum.
86  * @param datum The datum object.
87  */
88 void
89 InterPassData::setDatum(const std::string& key, InterPassDatum* datum) {
90 
91  if (MapTools::containsKey(data_, key))
92  delete data_[key];
93  data_[key] = datum;
94 }
95 
96 void
97 InterPassData::removeDatum(const std::string& key) {
98  if (MapTools::containsKey(data_, key)) {
99  delete data_[key];
100  data_.erase(key);
101  }
102 }
MapTools.hh
MapTools::deleteAllValues
static void deleteAllValues(MapType &aMap)
InterPassData::~InterPassData
virtual ~InterPassData()
Definition: InterPassData.cc:48
InterPassDatum.hh
__func__
#define __func__
Definition: Application.hh:67
InterPassData::hasDatum
bool hasDatum(const std::string &key) const
Definition: InterPassData.cc:75
InterPassDatum
Definition: InterPassDatum.hh:47
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
InterPassData.hh
InterPassData::removeDatum
void removeDatum(const std::string &key)
Definition: InterPassData.cc:97
KeyNotFound
Definition: Exception.hh:285
InterPassData::data_
std::map< std::string, InterPassDatum * > data_
container for the data
Definition: InterPassData.hh:59
InterPassData::datum
InterPassDatum & datum(const std::string &key)
Definition: InterPassData.cc:62
InterPassData::setDatum
void setDatum(const std::string &key, InterPassDatum *datum)
Definition: InterPassData.cc:89
InterPassData::InterPassData
InterPassData()
Definition: InterPassData.cc:40