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

Last change on this file since 1380 was 1380, checked in by Peter, 13 years ago

working on #363

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1#ifndef _theplu_yat_utility_data_weight_
2#define _theplu_yat_utility_data_weight_
3
4// $Id: DataWeight.h 1380 2008-07-16 22:36:23Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://trac.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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "iterator_traits.h"
28
29#include <vector>
30
31namespace theplu {
32namespace yat {
33namespace utility {
34
35  /**
36     \brief Holds a pair of data and associated weight
37  */
38  class DataWeight
39  {
40  public:
41    /**
42       \brief Default constructor
43
44       \param data data vaule 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 data are equal
80   */
81  bool operator==(const DataWeight&, const DataWeight&);
82
83  /**
84     \brief inequality operator
85
86     \return true if data are inequal
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  rhs > lhs
108   */
109  bool operator<=(const DataWeight&, const DataWeight&);
110
111  /**
112     \brief comparison operator
113
114     \return true if  rhs < lhs
115   */
116  bool operator>=(const DataWeight&, const DataWeight&);
117
118
119  /**
120     Specialization for std::vector<DataWeight>::iterator
121   */
122  template<>
123  struct weighted_iterator_traits<std::vector<DataWeight>::iterator> {
124    /**
125       iterator to vector<DataWeight> is weighted
126    */
127    typedef weighted_iterator_tag type;
128  };
129
130
131  /**
132     Specialization for std::vector<DataWeight>::const_iterator
133   */
134  template<>
135  struct weighted_iterator_traits<std::vector<DataWeight>::const_iterator> {
136    /**
137       const_iterator to vector<DataWeight> is weighted
138    */
139    typedef weighted_iterator_tag type;
140  };
141
142}}} // of namespace utility, yat, and theplu
143
144#endif
Note: See TracBrowser for help on using the repository browser.