yat  0.10.4pre
DataWeightProxy.h
1 #ifndef _theplu_yat_utility_data_weight_proxy_
2 #define _theplu_yat_utility_data_weight_proxy_
3 
4 // $Id: DataWeightProxy.h 2375 2010-12-13 03:28:46Z 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  // this is for function data(void) const
68  BOOST_CONCEPT_ASSERT((Convertible<data_reference, const double&>));
69 
70  // same check for WeightIterator
71  BOOST_CONCEPT_ASSERT((Convertible<weight_type, double>));
72  BOOST_CONCEPT_ASSERT((Convertible<weight_reference, const double&>));
73  }
74 
85  typename std::iterator_traits<DataIterator>::reference data(void)
86  {
87  BOOST_CONCEPT_ASSERT((boost::Convertible<data_reference, double>));
88  return *data_;
89  }
90 
94  const double& data(void) const { return *data_ ; }
95 
106  typename std::iterator_traits<WeightIterator>::reference weight(void)
107  {
108  BOOST_CONCEPT_ASSERT((boost::Convertible<weight_reference, double>));
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 std::iterator_traits<DataIterator> data_traits;
153  typedef typename data_traits::value_type data_type;
154  typedef typename data_traits::reference data_reference;
155 
156  typedef std::iterator_traits<WeightIterator> weight_traits;
157  typedef typename weight_traits::value_type weight_type;
158  typedef typename weight_traits::reference weight_reference;
159 
160  // using compiler generated copy
161  //DataWeightProxy(const DataWeightProxy&);
162  };
163 
164 }}} // of namespace utility, yat, and theplu
165 
166 #endif

Generated on Mon Nov 11 2013 09:41:44 for yat by  doxygen 1.8.1