yat  0.8.3pre
DataWeightProxy.h
00001 #ifndef _theplu_yat_utility_data_weight_proxy_
00002 #define _theplu_yat_utility_data_weight_proxy_ 
00003 
00004 // $Id: DataWeightProxy.h 2375 2010-12-13 03:28:46Z peter $
00005 
00006 /*
00007   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
00008   Copyright (C) 2009, 2010 Peter Johansson
00009 
00010   This file is part of the yat library, http://dev.thep.lu.se/yat
00011 
00012   The yat library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU General Public License as
00014   published by the Free Software Foundation; either version 3 of the
00015   License, or (at your option) any later version.
00016 
00017   The yat library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00020   General Public License for more details.
00021 
00022   You should have received a copy of the GNU General Public License
00023   along with yat. If not, see <http://www.gnu.org/licenses/>.
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       // DataIterator::value must be convertible to double
00066       BOOST_CONCEPT_ASSERT((Convertible<data_type, double>));
00067       // this is for function data(void) const
00068       BOOST_CONCEPT_ASSERT((Convertible<data_reference, const double&>));
00069 
00070       // same check for WeightIterator
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     // using compiler generated copy
00161     //DataWeightProxy(const DataWeightProxy&);
00162   };
00163 
00164 }}} // of namespace utility, yat, and theplu
00165 
00166 #endif

Generated on Thu Dec 20 2012 03:12:58 for yat by  doxygen 1.8.0-20120409