1379 |
16 Jul 08 |
peter |
1 |
#ifndef _theplu_yat_utility_data_weight_ |
4200 |
19 Aug 22 |
peter |
2 |
#define _theplu_yat_utility_data_weight_ |
1379 |
16 Jul 08 |
peter |
3 |
|
1379 |
16 Jul 08 |
peter |
// $Id$ |
1379 |
16 Jul 08 |
peter |
5 |
|
1379 |
16 Jul 08 |
peter |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009 Peter Johansson |
1379 |
16 Jul 08 |
peter |
9 |
|
1469 |
02 Sep 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1379 |
16 Jul 08 |
peter |
11 |
|
1379 |
16 Jul 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1379 |
16 Jul 08 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
1379 |
16 Jul 08 |
peter |
License, or (at your option) any later version. |
1379 |
16 Jul 08 |
peter |
16 |
|
1379 |
16 Jul 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1379 |
16 Jul 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1379 |
16 Jul 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1379 |
16 Jul 08 |
peter |
General Public License for more details. |
1379 |
16 Jul 08 |
peter |
21 |
|
1379 |
16 Jul 08 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1379 |
16 Jul 08 |
peter |
24 |
*/ |
1379 |
16 Jul 08 |
peter |
25 |
|
1379 |
16 Jul 08 |
peter |
26 |
namespace theplu { |
1379 |
16 Jul 08 |
peter |
27 |
namespace yat { |
1379 |
16 Jul 08 |
peter |
28 |
namespace utility { |
1379 |
16 Jul 08 |
peter |
29 |
|
1379 |
16 Jul 08 |
peter |
30 |
/** |
1379 |
16 Jul 08 |
peter |
\brief Holds a pair of data and associated weight |
1533 |
25 Sep 08 |
peter |
32 |
|
1734 |
16 Jan 09 |
peter |
The class has comparison operators (declared outside class) that |
1734 |
16 Jan 09 |
peter |
are designed to ignore the weights, and behaves like the |
1734 |
16 Jan 09 |
peter |
corresponding double operator behaves for data(). |
1734 |
16 Jan 09 |
peter |
36 |
|
1533 |
25 Sep 08 |
peter |
\since New in yat 0.5 |
1379 |
16 Jul 08 |
peter |
38 |
*/ |
1379 |
16 Jul 08 |
peter |
39 |
class DataWeight |
1379 |
16 Jul 08 |
peter |
40 |
{ |
1379 |
16 Jul 08 |
peter |
41 |
public: |
1379 |
16 Jul 08 |
peter |
42 |
/** |
1379 |
16 Jul 08 |
peter |
\brief Default constructor |
1379 |
16 Jul 08 |
peter |
44 |
|
1469 |
02 Sep 08 |
peter |
\param data data value to hold |
1379 |
16 Jul 08 |
peter |
\param weight weight value to hold |
1379 |
16 Jul 08 |
peter |
47 |
*/ |
1379 |
16 Jul 08 |
peter |
48 |
explicit DataWeight(double data=0.0, double weight=1.0); |
1379 |
16 Jul 08 |
peter |
49 |
|
1379 |
16 Jul 08 |
peter |
50 |
/** |
1379 |
16 Jul 08 |
peter |
\return reference to data |
1379 |
16 Jul 08 |
peter |
52 |
*/ |
1379 |
16 Jul 08 |
peter |
53 |
double& data(void); |
1379 |
16 Jul 08 |
peter |
54 |
|
1379 |
16 Jul 08 |
peter |
55 |
/** |
1379 |
16 Jul 08 |
peter |
\return const reference to data |
1379 |
16 Jul 08 |
peter |
57 |
*/ |
1379 |
16 Jul 08 |
peter |
58 |
const double& data(void) const; |
1379 |
16 Jul 08 |
peter |
59 |
|
1379 |
16 Jul 08 |
peter |
60 |
/** |
1379 |
16 Jul 08 |
peter |
\return reference to weight |
1379 |
16 Jul 08 |
peter |
62 |
*/ |
1379 |
16 Jul 08 |
peter |
63 |
double& weight(void); |
1379 |
16 Jul 08 |
peter |
64 |
|
1379 |
16 Jul 08 |
peter |
65 |
/** |
1379 |
16 Jul 08 |
peter |
\return const reference to weight |
1379 |
16 Jul 08 |
peter |
67 |
*/ |
1379 |
16 Jul 08 |
peter |
68 |
const double& weight(void) const; |
1379 |
16 Jul 08 |
peter |
69 |
private: |
1379 |
16 Jul 08 |
peter |
70 |
double data_; |
1379 |
16 Jul 08 |
peter |
71 |
double weight_; |
1379 |
16 Jul 08 |
peter |
// using compiler generated copy |
1379 |
16 Jul 08 |
peter |
// DataWeight(const DataWeight&) |
1379 |
16 Jul 08 |
peter |
// DataWeight& operator=(const DataWeight&); |
1379 |
16 Jul 08 |
peter |
75 |
}; |
1379 |
16 Jul 08 |
peter |
76 |
|
1379 |
16 Jul 08 |
peter |
77 |
/** |
1379 |
16 Jul 08 |
peter |
\brief equality operator |
1379 |
16 Jul 08 |
peter |
79 |
|
1734 |
16 Jan 09 |
peter |
\return true if lhs.data() == rhs.data() |
1887 |
31 Mar 09 |
peter |
81 |
|
1887 |
31 Mar 09 |
peter |
\relates DataWeight |
1379 |
16 Jul 08 |
peter |
83 |
*/ |
1734 |
16 Jan 09 |
peter |
84 |
bool operator==(const DataWeight& lhs, const DataWeight& rhs); |
1379 |
16 Jul 08 |
peter |
85 |
|
1379 |
16 Jul 08 |
peter |
86 |
/** |
1379 |
16 Jul 08 |
peter |
\brief inequality operator |
1379 |
16 Jul 08 |
peter |
88 |
|
1734 |
16 Jan 09 |
peter |
\return true if lhs.data() != rhs.data() |
1887 |
31 Mar 09 |
peter |
90 |
|
1887 |
31 Mar 09 |
peter |
\relates DataWeight |
1379 |
16 Jul 08 |
peter |
92 |
*/ |
1379 |
16 Jul 08 |
peter |
93 |
bool operator!=(const DataWeight&, const DataWeight&); |
1379 |
16 Jul 08 |
peter |
94 |
|
1379 |
16 Jul 08 |
peter |
95 |
/** |
1379 |
16 Jul 08 |
peter |
\brief comparison operator |
1379 |
16 Jul 08 |
peter |
97 |
|
2003 |
13 Jun 09 |
peter |
\return less_nan(lhs.data(), rhs.data()) |
1887 |
31 Mar 09 |
peter |
99 |
|
2003 |
13 Jun 09 |
peter |
\see less_nan |
2003 |
13 Jun 09 |
peter |
101 |
|
1887 |
31 Mar 09 |
peter |
\relates DataWeight |
1379 |
16 Jul 08 |
peter |
103 |
*/ |
1379 |
16 Jul 08 |
peter |
104 |
bool operator<(const DataWeight&, const DataWeight&); |
1379 |
16 Jul 08 |
peter |
105 |
|
1379 |
16 Jul 08 |
peter |
106 |
/** |
1379 |
16 Jul 08 |
peter |
\brief comparison operator |
1379 |
16 Jul 08 |
peter |
108 |
|
2003 |
13 Jun 09 |
peter |
\return \a rhs < \a lhs |
1887 |
31 Mar 09 |
peter |
110 |
|
1887 |
31 Mar 09 |
peter |
\relates DataWeight |
1379 |
16 Jul 08 |
peter |
112 |
*/ |
1379 |
16 Jul 08 |
peter |
113 |
bool operator>(const DataWeight&, const DataWeight&); |
1379 |
16 Jul 08 |
peter |
114 |
|
1379 |
16 Jul 08 |
peter |
115 |
/** |
1379 |
16 Jul 08 |
peter |
\brief comparison operator |
1379 |
16 Jul 08 |
peter |
117 |
|
2003 |
13 Jun 09 |
peter |
\return true if \a lhs < \a rhs or lhs == rhs |
1887 |
31 Mar 09 |
peter |
119 |
|
1887 |
31 Mar 09 |
peter |
\relates DataWeight |
1379 |
16 Jul 08 |
peter |
121 |
*/ |
1379 |
16 Jul 08 |
peter |
122 |
bool operator<=(const DataWeight&, const DataWeight&); |
1379 |
16 Jul 08 |
peter |
123 |
|
1379 |
16 Jul 08 |
peter |
124 |
/** |
1379 |
16 Jul 08 |
peter |
\brief comparison operator |
1379 |
16 Jul 08 |
peter |
126 |
|
4200 |
19 Aug 22 |
peter |
\return true if \a lhs > rhs or \a lhs == \a rhs |
1887 |
31 Mar 09 |
peter |
128 |
|
1887 |
31 Mar 09 |
peter |
\relates DataWeight |
1379 |
16 Jul 08 |
peter |
130 |
*/ |
1379 |
16 Jul 08 |
peter |
131 |
bool operator>=(const DataWeight&, const DataWeight&); |
1379 |
16 Jul 08 |
peter |
132 |
|
1379 |
16 Jul 08 |
peter |
133 |
|
1379 |
16 Jul 08 |
peter |
134 |
}}} // of namespace utility, yat, and theplu |
1379 |
16 Jul 08 |
peter |
135 |
|
1379 |
16 Jul 08 |
peter |
136 |
#endif |