OpenASIP  2.0
EntryKeyField.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 EntryKeyField.cc
26  *
27  * Implementation of EntryKeyField 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 "EntryKeyField.hh"
35 #include "Application.hh"
36 
37 
38 /**
39  * Constructor.
40  *
41  * @param fieldData Value of the field.
42  * @param type Type of the field.
43  */
45  EntryKeyData* fieldData,
46  const EntryKeyFieldProperty* type):
47  data_(fieldData), properties_(type) {
48 }
49 
50 /**
51  * Copy constructor.
52  *
53  * @param old A field.
54  */
56  data_(old.data_->copy()), properties_(old.properties_) {
57 }
58 
59 /**
60  * Destructor.
61  *
62  * Deallocates memory reserved for the value of the field.
63  */
65  assert(data_ != NULL);
66  delete data_;
67  data_ = NULL;
68 }
69 
70 /**
71  * Assignment operator.
72  *
73  * @param old A field.
74  * @return A copy of the field.
75  */
78  if (this != &old) {
79  data_ = old.data_->copy();
81  }
82  return *this;
83 }
84 
85 /**
86  * Checks if two fields are equal.
87  *
88  * @param field A field.
89  * @return True if two integers are equal, otherwise false.
90  */
91 bool
93  return data_->isEqual(field.data_);
94 }
95 
96 /**
97  * Checks if this field is greater than another field.
98  *
99  * @param field A field.
100  * @return True if this field is greater than another field, otherwise false.
101  */
102 bool
104  return data_->isGreater(field.data_);
105 }
106 
107 /**
108  * Checks if this field is smaller than another field.
109  *
110  * @param field A field.
111  * @return True if this field is smaller than another field, otherwise false.
112  */
113 bool
115  return data_->isSmaller(field.data_);
116 }
117 
118 /**
119  * Returns the relative position between two fields.
120  *
121  * Returns the field's relative position to the first field compared
122  * to the second. For example, if this field has value 14, the first
123  * field has 10 and the second 20, relative position would be 0.4.
124  *
125  * @param field1 First field.
126  * @param field2 Second field.
127  * @return The relative position between two fields.
128  */
129 double
131  const EntryKeyField& field1,
132  const EntryKeyField& field2) const {
133 
134  return data_->coefficient(field1.data_, field2.data_);
135 }
136 
137 /**
138  * Returns value of the field as a string.
139  *
140  * @return Value of the field as a string.
141  */
142 std::string
144  return data_->toString();
145 }
EntryKeyFieldProperty
Definition: EntryKeyFieldProperty.hh:47
EntryKeyField::~EntryKeyField
virtual ~EntryKeyField()
Definition: EntryKeyField.cc:64
EntryKeyField
Definition: EntryKeyField.hh:45
EntryKeyField::isGreater
bool isGreater(const EntryKeyField &field) const
Definition: EntryKeyField.cc:103
assert
#define assert(condition)
Definition: Application.hh:86
EntryKeyData
Definition: EntryKeyData.hh:53
EntryKeyData::coefficient
virtual double coefficient(const EntryKeyData *, const EntryKeyData *) const =0
Returns the relative position between two data.
Application.hh
EntryKeyField::coefficient
double coefficient(const EntryKeyField &field1, const EntryKeyField &field2) const
Definition: EntryKeyField.cc:130
EntryKeyField::operator=
EntryKeyField & operator=(const EntryKeyField &old)
Definition: EntryKeyField.cc:77
EntryKeyData::isEqual
virtual bool isEqual(const EntryKeyData *) const =0
Checks if two data are equal.
EntryKeyData::copy
virtual EntryKeyData * copy() const =0
Copies data.
EntryKeyData::isGreater
virtual bool isGreater(const EntryKeyData *) const =0
Checks if this data is greater than another data.
EntryKeyField.hh
EntryKeyField::properties_
const EntryKeyFieldProperty * properties_
Type of the field.
Definition: EntryKeyField.hh:64
EntryKeyField::EntryKeyField
EntryKeyField(EntryKeyData *fieldData, const EntryKeyFieldProperty *type)
Definition: EntryKeyField.cc:44
EntryKeyData::isSmaller
virtual bool isSmaller(const EntryKeyData *) const =0
Checks if this data is smaller than another data.
EntryKeyField::toString
std::string toString() const
Definition: EntryKeyField.cc:143
EntryKeyField::isEqual
bool isEqual(const EntryKeyField &field) const
Definition: EntryKeyField.cc:92
EntryKeyField::data_
EntryKeyData * data_
Value of the field.
Definition: EntryKeyField.hh:62
EntryKeyData::toString
virtual std::string toString() const =0
Converts the data into a string.
EntryKeyField::isSmaller
bool isSmaller(const EntryKeyField &field) const
Definition: EntryKeyField.cc:114