2 Copyright (c) 2002-2009 Tampere University.
4 This file is part of TTA-Based Codesign Environment (TCE).
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:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
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.
27 * Inline implementation of SelectSet class.
29 * @author Tommi Rantanen 2004 (tommi.rantanen-no.spam-tut.fi)
30 * @author Jari Mäntyneva 2005 (jari.mantyneva-no.spam-tut.fi)
34 #include "Application.hh"
40 * @param type Type of the field.&%
42 template <bool (EntryKeyField::*select)(const EntryKeyField&) const,
43 bool (EntryKeyField::*unSelect)(const EntryKeyField&) const>
44 SelectSet<select, unSelect>::SelectSet(const EntryKeyFieldProperty* type):
51 template <bool (EntryKeyField::*select)(const EntryKeyField&) const,
52 bool (EntryKeyField::*unSelect)(const EntryKeyField&) const>
53 SelectSet<select, unSelect>::~SelectSet() {
57 * Filters out entries which do not satisfy selection criteria.
59 * However, equal values are accepted.
61 * @param searchKey Search key.
62 * @param components Entries from which to find. Updated to contain
63 * entries that matched the search request.
65 template <bool (EntryKeyField::*select)(const EntryKeyField&) const,
66 bool (EntryKeyField::*unSelect)(const EntryKeyField&) const>
68 SelectSet<select, unSelect>::quickFilter(
69 const CostDBEntryKey& searchKey,
70 CostDBTypes::EntryTable& components) {
72 CostDBTypes::EntryTable filtered;
73 EntryKeyField searchField = searchKey.keyFieldOfType(*fieldType());
75 for (CostDBTypes::EntryTable::iterator i = components.begin();
76 i != components.end(); i++) {
78 EntryKeyField field = (*i)->keyFieldOfType(*fieldType());
79 if (field.isEqual(searchField) || (field.*select)(searchField)) {
80 filtered.push_back(*i);
83 components = filtered;
88 * Searches for database entries that satisfies selection criteria.
90 * However, equal values are accepted.
92 * Filtering does not require a search key since QuickFilter()
93 * guarantees that unacceptable entries do not exist.
95 * Only the best matches are returned, i.e. if two entries has only
96 * the field to which search is applied different, closer one to the
97 * search key is chosen.
99 * @param components Entries from which to find. Updated to contain
100 * entries that matched the search request.
102 template <bool (EntryKeyField::*select)(const EntryKeyField&) const,
103 bool (EntryKeyField::*unSelect)(const EntryKeyField&) const>
105 SelectSet<select, unSelect>::filter(
106 const CostDBEntryKey&,
107 CostDBTypes::EntryTable& components) {
109 CostDBTypes::EntryTable filtered;
111 for (CostDBTypes::EntryTable::iterator i1 = components.begin();
112 i1 != components.end(); i1++) {
114 EntryKeyField field1 = (*i1)->keyFieldOfType(*fieldType());
116 bool addEntry = true;
118 for (CostDBTypes::EntryTable::iterator i2 = filtered.begin();
119 i2 != filtered.end(); i2++) {
121 if (!onlyThisFieldDiffers(fieldType(), *(*i1), *(*i2))) {
125 EntryKeyField field2 = (*i2)->keyFieldOfType(*fieldType());
127 if ((field1.*unSelect)(field2)) {
130 } else if ((field1.*select)(field2)) {
132 } else if (field1.isEqual(field2)) {
138 filtered.push_back(*i1);
143 components = filtered;