00001 #ifndef _theplu_yat_utility_data_weight_proxy_
00002 #define _theplu_yat_utility_data_weight_proxy_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "DataWeight.h"
00027
00028 #include <boost/concept/assert.hpp>
00029
00030 #include <iterator>
00031
00032 namespace theplu {
00033 namespace yat {
00034 namespace utility {
00035
00051 template<typename DataIterator, typename WeightIterator>
00052 class DataWeightProxy
00053 {
00054 public:
00061 DataWeightProxy(DataIterator data, WeightIterator weight)
00062 : data_(data), weight_(weight)
00063 {
00064 using boost::Convertible;
00065
00066 BOOST_CONCEPT_ASSERT((Convertible<data_type, double>));
00067
00068 BOOST_CONCEPT_ASSERT((Convertible<data_reference, const double&>));
00069
00070
00071 BOOST_CONCEPT_ASSERT((Convertible<weight_type, double>));
00072 BOOST_CONCEPT_ASSERT((Convertible<weight_reference, const double&>));
00073 }
00074
00085 typename std::iterator_traits<DataIterator>::reference data(void)
00086 {
00087 BOOST_CONCEPT_ASSERT((boost::Convertible<data_reference, double>));
00088 return *data_;
00089 }
00090
00094 const double& data(void) const { return *data_ ; }
00095
00106 typename std::iterator_traits<WeightIterator>::reference weight(void)
00107 {
00108 BOOST_CONCEPT_ASSERT((boost::Convertible<weight_reference, double>));
00109 return *weight_;
00110 }
00111
00115 const double& weight(void) const { return *weight_; }
00116
00125 DataWeightProxy& operator=(const DataWeightProxy& rhs)
00126 {
00127 data() = rhs.data();
00128 weight() = rhs.weight();
00129 return *this;
00130 }
00131
00135 DataWeightProxy& operator=(const DataWeight& rhs)
00136 {
00137 data() = rhs.data();
00138 weight() = rhs.weight();
00139 return *this;
00140 }
00141
00145 operator DataWeight() const
00146 { return DataWeight(this->data(), this->weight()); }
00147
00148 private:
00149 DataIterator data_;
00150 WeightIterator weight_;
00151
00152 typedef std::iterator_traits<DataIterator> data_traits;
00153 typedef typename data_traits::value_type data_type;
00154 typedef typename data_traits::reference data_reference;
00155
00156 typedef std::iterator_traits<WeightIterator> weight_traits;
00157 typedef typename weight_traits::value_type weight_type;
00158 typedef typename weight_traits::reference weight_reference;
00159
00160
00161
00162 };
00163
00164 }}}
00165
00166 #endif