yat  0.21pre
DataWeightProxy.h
1 #ifndef _theplu_yat_utility_data_weight_proxy_
2 #define _theplu_yat_utility_data_weight_proxy_
3 
4 // $Id: DataWeightProxy.h 4254 2022-11-21 23:40:41Z peter $
5 
6 /*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010, 2016, 2017, 2022 Peter Johansson
9 
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11 
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16 
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #include "DataWeight.h"
27 
28 #include <boost/concept/assert.hpp>
29 #include <boost/iterator/iterator_concepts.hpp>
30 #include <boost/iterator/iterator_traits.hpp>
31 
32 #include <iterator>
33 
34 namespace theplu {
35 namespace yat {
36 namespace utility {
37 
53  template<typename DataIterator, typename WeightIterator>
55  {
56  public:
64  : data_(data), weight_(weight)
65  {
66  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<DataIterator>));
67  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<WeightIterator>));
68 
69  using boost::Convertible;
70  // DataIterator::value must be convertible to double
71  BOOST_CONCEPT_ASSERT((Convertible<data_type, double>));
72 
73  // same check for WeightIterator
74  BOOST_CONCEPT_ASSERT((Convertible<weight_type, double>));
75  }
76 
80  DataWeightProxy(const DataWeightProxy& other) = default;
81 
92  typename boost::iterator_reference<DataIterator>::type data(void)
93  {
94  return *data_;
95  }
96 
100  const double& data(void) const { return *data_ ; }
101 
112  typename boost::iterator_reference<WeightIterator>::type weight(void)
113  {
114  return *weight_;
115  }
116 
120  const double& weight(void) const { return *weight_; }
121 
131  {
132  data() = rhs.data();
133  weight() = rhs.weight();
134  return *this;
135  }
136 
141  {
142  data() = rhs.data();
143  weight() = rhs.weight();
144  return *this;
145  }
146 
150  operator DataWeight() const
151  { return DataWeight(this->data(), this->weight()); }
152 
153  private:
154  DataIterator data_;
155  WeightIterator weight_;
156 
157  typedef typename boost::iterator_value<DataIterator>::type data_type;
158  typedef typename boost::iterator_reference<DataIterator>::type data_reference;
159 
160  typedef typename boost::iterator_value<WeightIterator>::type weight_type;
161  typedef
162  typename boost::iterator_reference<WeightIterator>::type weight_reference;
163 
164  // using compiler generated copy
165  //DataWeightProxy(const DataWeightProxy&);
166  };
167 
168 }}} // of namespace utility, yat, and theplu
169 
170 #endif
boost::iterator_reference< DataIterator >::type data(void)
Definition: DataWeightProxy.h:92
The Department of Theoretical Physics namespace as we define it.
Holds a pair of data and associated weight.
Definition: DataWeight.h:39
Proxy class for DataWeight.
Definition: DataWeightProxy.h:54
DataIterator.
Definition: DataIterator.h:63
DataWeightProxy & operator=(const DataWeight &rhs)
assignment operator
Definition: DataWeightProxy.h:140
const double & weight(void) const
Definition: DataWeightProxy.h:120
const double & data(void) const
Definition: DataWeightProxy.h:100
DataWeightProxy & operator=(const DataWeightProxy &rhs)
assignment operator
Definition: DataWeightProxy.h:130
WeightIterator.
Definition: WeightIterator.h:64
boost::iterator_reference< WeightIterator >::type weight(void)
Definition: DataWeightProxy.h:112
DataWeightProxy(DataIterator data, WeightIterator weight)
Constructor.
Definition: DataWeightProxy.h:63

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14