yat  0.14.5pre
DataWeightProxy.h
1 #ifndef _theplu_yat_utility_data_weight_proxy_
2 #define _theplu_yat_utility_data_weight_proxy_
3 
4 // $Id: DataWeightProxy.h 3550 2017-01-03 05:41:02Z peter $
5 
6 /*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010, 2016, 2017 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 
87  typename boost::iterator_reference<DataIterator>::type data(void)
88  {
89  return *data_;
90  }
91 
95  const double& data(void) const { return *data_ ; }
96 
107  typename boost::iterator_reference<WeightIterator>::type weight(void)
108  {
109  return *weight_;
110  }
111 
115  const double& weight(void) const { return *weight_; }
116 
126  {
127  data() = rhs.data();
128  weight() = rhs.weight();
129  return *this;
130  }
131 
136  {
137  data() = rhs.data();
138  weight() = rhs.weight();
139  return *this;
140  }
141 
145  operator DataWeight() const
146  { return DataWeight(this->data(), this->weight()); }
147 
148  private:
149  DataIterator data_;
150  WeightIterator weight_;
151 
152  typedef typename boost::iterator_value<DataIterator>::type data_type;
153  typedef typename boost::iterator_reference<DataIterator>::type data_reference;
154 
155  typedef typename boost::iterator_value<WeightIterator>::type weight_type;
156  typedef
157  typename boost::iterator_reference<WeightIterator>::type weight_reference;
158 
159  // using compiler generated copy
160  //DataWeightProxy(const DataWeightProxy&);
161  };
162 
163 }}} // of namespace utility, yat, and theplu
164 
165 #endif
boost::iterator_reference< DataIterator >::type data(void)
Definition: DataWeightProxy.h:87
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:135
DataWeightProxy & operator=(const DataWeightProxy &rhs)
assignment operator
Definition: DataWeightProxy.h:125
const double & data(void) const
Definition: DataWeightProxy.h:95
WeightIterator.
Definition: WeightIterator.h:64
boost::iterator_reference< WeightIterator >::type weight(void)
Definition: DataWeightProxy.h:107
DataWeightProxy(DataIterator data, WeightIterator weight)
Constructor.
Definition: DataWeightProxy.h:63
const double & weight(void) const
Definition: DataWeightProxy.h:115

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5