source: trunk/yat/utility/DataWeight.h @ 1734

Last change on this file since 1734 was 1734, checked in by Peter, 12 years ago

Added some docs. Also modified the comparison operators to return what
the corresponding double operator returns for data(). This was always
true before when the comparisons included NaN.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1#ifndef _theplu_yat_utility_data_weight_
2#define _theplu_yat_utility_data_weight_
3
4// $Id: DataWeight.h 1734 2009-01-16 19:20:57Z peter $
5
6/*
7  Copyright (C) 2008, 2009 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25namespace theplu {
26namespace yat {
27namespace utility {
28
29  /**
30     \brief Holds a pair of data and associated weight
31
32     The class has comparison operators (declared outside class) that
33     are designed to ignore the weights, and behaves like the
34     corresponding double operator behaves for data().
35
36     \since New in yat 0.5
37  */
38  class DataWeight
39  {
40  public:
41    /**
42       \brief Default constructor
43
44       \param data data value to hold
45       \param weight weight value to hold
46     */
47    explicit DataWeight(double data=0.0, double weight=1.0);
48
49    /**
50       \return reference to data
51     */
52    double& data(void);
53
54    /**
55       \return const reference to data
56     */
57    const double& data(void) const;
58
59    /**
60       \return reference to weight
61     */
62    double& weight(void);
63
64    /**
65       \return const reference to weight
66     */
67    const double& weight(void) const;
68  private:
69    double data_;
70    double weight_;
71    // using compiler generated copy
72    // DataWeight(const DataWeight&)
73    // DataWeight& operator=(const DataWeight&);
74  };
75
76  /**
77     \brief equality operator
78
79     \return true if lhs.data() == rhs.data()
80   */
81  bool operator==(const DataWeight& lhs, const DataWeight& rhs);
82
83  /**
84     \brief inequality operator
85
86     \return true if lhs.data() != rhs.data()
87   */
88  bool operator!=(const DataWeight&, const DataWeight&);
89
90  /**
91     \brief comparison operator
92
93     \return true if lhs data is less than rhs data
94   */
95  bool operator<(const DataWeight&, const DataWeight&);
96
97  /**
98     \brief comparison operator
99
100     \return true if lhs data is greater than rhs data
101   */
102  bool operator>(const DataWeight&, const DataWeight&);
103
104  /**
105     \brief comparison operator
106
107     \return true if lhs.data() <= rhs.data()
108   */
109  bool operator<=(const DataWeight&, const DataWeight&);
110
111  /**
112     \brief comparison operator
113
114     \return true if lhs.data() >= rhs.data()
115   */
116  bool operator>=(const DataWeight&, const DataWeight&);
117
118
119}}} // of namespace utility, yat, and theplu
120
121#endif
Note: See TracBrowser for help on using the repository browser.