OpenASIP 2.2
Loading...
Searching...
No Matches
EntryKeyProperty.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 EntryKeyProperty.cc
26 *
27 * Implementation of EntryKeyProperty 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 <string>
35#include <vector>
36
37#include "EntryKeyProperty.hh"
39#include "Application.hh"
40
41using std::string;
42using std::vector;
43
45
46/**
47 * Constructor.
48 *
49 * @param propertyName Type of entry.
50 */
51EntryKeyProperty::EntryKeyProperty(string propertyName): name_(propertyName) {
52}
53
54/**
55 * Destructor.
56 *
57 * Deallocates memory reserved for field types.
58 */
60
61 for (FieldPropertyTable::iterator i = entryFields_.begin();
62 i != entryFields_.end(); i++) {
63
64 assert(*i != NULL);
65 delete *i;
66 *i = NULL;
67 }
68}
69
70/**
71 * Creates field type.
72 *
73 * If exists, returns the old one.
74 *
75 * @param field Type of field.
76 * @return Field type.
77 */
80
81 for (FieldPropertyTable::const_iterator i = entryFields_.begin();
82 i != entryFields_.end(); i++) {
83
84 if ((*i)->name() == field) {
85 return (*i);
86 }
87 }
88
89 EntryKeyFieldProperty* newField = new EntryKeyFieldProperty(field, this);
90 entryFields_.push_back(newField);
91 return newField;
92}
93
94/**
95 * Finds field type.
96 *
97 * If not found, exits.
98 *
99 * @param field Field type.
100 * @return Field type.
101 * @exception KeyNotFound Requested field was not found.
102 */
105 for (FieldPropertyTable::const_iterator i = entryFields_.begin();
106 i != entryFields_.end(); i++) {
107
108 if ((*i)->name() == field) {
109 return (*i);
110 }
111 }
112 throw KeyNotFound(__FILE__, __LINE__, "EntryKeyProperty::fieldProperty");
113 return NULL; // stupid return statement to make compiler quiet
114}
115
116/**
117 * Creates entry type.
118 *
119 * If exists, returns the old one.
120 *
121 * @param type Entry type.
122 * @return Entry type.
123 */
126
127 for (EntryPropertyTable::const_iterator i = entryTypes_.begin();
128 i != entryTypes_.end(); i++) {
129
130 if ((*i)->name() == type) {
131 return (*i);
132 }
133 }
134
135 EntryKeyProperty* newType = new EntryKeyProperty(type);
136 entryTypes_.push_back(newType);
137 return newType;
138}
139
140/**
141 * Finds entry type.
142 *
143 * If not found, exits.
144 *
145 * @param type Entry type.
146 * @return Entry type.
147 * @exception KeyNotFound Requested field was not found.
148 */
151 for (EntryPropertyTable::const_iterator i = entryTypes_.begin();
152 i != entryTypes_.end(); i++) {
153
154 if ((*i)->name() == type) {
155 return (*i);
156 }
157 }
158 throw KeyNotFound(__FILE__, __LINE__, "EntryKeyProperty::find");
159 return NULL; // stupid return statement to make compiler quiet
160}
161
162/**
163 * Deallocates memory reserved for entry types.
164 */
165void
167
168 for (EntryPropertyTable::iterator i = entryTypes_.begin();
169 i != entryTypes_.end(); i++) {
170
171 assert(*i != NULL);
172 delete *i;
173 *i = NULL;
174 }
175 entryTypes_.resize(0);
176}
#define assert(condition)
static EntryKeyProperty * find(std::string type)
static void destroy()
static EntryKeyProperty * create(std::string type)
EntryKeyProperty(std::string propertyName)
EntryKeyFieldProperty * createFieldProperty(std::string field)
std::vector< EntryKeyProperty * > EntryPropertyTable
Table of entry types.
FieldPropertyTable entryFields_
Field types of the entry type.
EntryKeyFieldProperty * fieldProperty(std::string field) const
static EntryPropertyTable entryTypes_
All known entry types.