yat  0.12.3pre
DataWeightProxy.h
1 #ifndef _theplu_yat_utility_data_weight_proxy_
2 #define _theplu_yat_utility_data_weight_proxy_
3 
4 // $Id: DataWeightProxy.h 3262 2014-06-22 10:01:04Z peter $
5 
6 /*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010 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 
30 #include <iterator>
31 
32 namespace theplu {
33 namespace yat {
34 namespace utility {
35 
51  template<typename DataIterator, typename WeightIterator>
53  {
54  public:
62  : data_(data), weight_(weight)
63  {
64  using boost::Convertible;
65  // DataIterator::value must be convertible to double
66  BOOST_CONCEPT_ASSERT((Convertible<data_type, double>));
67 
68  // same check for WeightIterator
69  BOOST_CONCEPT_ASSERT((Convertible<weight_type, double>));
70  }
71 
82  typename std::iterator_traits<DataIterator>::reference data(void)
83  {
84  return *data_;
85  }
86 
90  const double& data(void) const { return *data_ ; }
91 
102  typename std::iterator_traits<WeightIterator>::reference weight(void)
103  {
104  return *weight_;
105  }
106 
110  const double& weight(void) const { return *weight_; }
111 
121  {
122  data() = rhs.data();
123  weight() = rhs.weight();
124  return *this;
125  }
126 
131  {
132  data() = rhs.data();
133  weight() = rhs.weight();
134  return *this;
135  }
136 
140  operator DataWeight() const
141  { return DataWeight(this->data(), this->weight()); }
142 
143  private:
144  DataIterator data_;
145  WeightIterator weight_;
146 
147  typedef std::iterator_traits<DataIterator> data_traits;
148  typedef typename data_traits::value_type data_type;
149  typedef typename data_traits::reference data_reference;
150 
151  typedef std::iterator_traits<WeightIterator> weight_traits;
152  typedef typename weight_traits::value_type weight_type;
153  typedef typename weight_traits::reference weight_reference;
154 
155  // using compiler generated copy
156  //DataWeightProxy(const DataWeightProxy&);
157  };
158 
159 }}} // of namespace utility, yat, and theplu
160 
161 #endif
Holds a pair of data and associated weight.
Definition: DataWeight.h:39
Proxy class for DataWeight.
Definition: DataWeightProxy.h:52
DataIterator.
Definition: DataIterator.h:61
DataWeightProxy & operator=(const DataWeight &rhs)
assignment operator
Definition: DataWeightProxy.h:130
DataWeightProxy & operator=(const DataWeightProxy &rhs)
assignment operator
Definition: DataWeightProxy.h:120
const double & data(void) const
Definition: DataWeightProxy.h:90
WeightIterator.
Definition: WeightIterator.h:61
std::iterator_traits< WeightIterator >::reference weight(void)
Definition: DataWeightProxy.h:102
DataWeightProxy(DataIterator data, WeightIterator weight)
Constructor.
Definition: DataWeightProxy.h:61
std::iterator_traits< DataIterator >::reference data(void)
Definition: DataWeightProxy.h:82
const double & weight(void) const
Definition: DataWeightProxy.h:110

Generated on Mon Jun 1 2015 12:29:52 for yat by  doxygen 1.8.5