00001 #ifndef _theplu_yat_utility_data_weight_proxy_ 00002 #define _theplu_yat_utility_data_weight_proxy_ 00003 00004 // $Id: DataWeightProxy.h 1797 2009-02-12 18:07:10Z peter $ 00005 00006 /* 00007 Copyright (C) 2008 Jari Häkkinen, Peter Johansson 00008 00009 This file is part of the yat library, http://dev.thep.lu.se/yat 00010 00011 The yat library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License as 00013 published by the Free Software Foundation; either version 3 of the 00014 License, or (at your option) any later version. 00015 00016 The yat library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with yat. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 #include "DataWeight.h" 00026 00027 namespace theplu { 00028 namespace yat { 00029 namespace utility { 00030 00038 template<typename DataIterator, typename WeightIterator> 00039 class DataWeightProxy 00040 { 00041 public: 00048 DataWeightProxy(DataIterator data, WeightIterator weight) 00049 : data_(data), weight_(weight) {} 00050 00054 //typename std::iterator_traits<DataWeight>::reference data(void) const 00055 double& data(void) { return *data_; } 00056 00060 const double& data(void) const { return *data_ ; } 00061 00065 double& weight(void) { return *weight_; } 00066 00070 const double& weight(void) const { return *weight_; } 00071 00075 DataWeightProxy& operator=(const DataWeightProxy& rhs) 00076 { 00077 data() = rhs.data(); 00078 weight() = rhs.weight(); 00079 return *this; 00080 } 00081 00085 DataWeightProxy& operator=(const DataWeight& rhs) 00086 { 00087 data() = rhs.data(); 00088 weight() = rhs.weight(); 00089 return *this; 00090 } 00091 00095 operator DataWeight() const 00096 { return DataWeight(this->data(), this->weight()); } 00097 00098 private: 00099 DataIterator data_; 00100 WeightIterator weight_; 00101 00102 // using compiler generated copy and assignment 00103 //DataWeightProxy& operator=(const DataWeightProxy&); 00104 //DataWeightProxy(const DataWeightProxy&); 00105 }; 00106 00107 00111 template<typename DataIterator, typename WeightIterator> 00112 bool operator==(const DataWeightProxy<DataIterator, WeightIterator>& lhs, 00113 const DataWeightProxy<DataIterator, WeightIterator>& rhs) 00114 { 00115 return lhs.data()==rhs.data() && lhs.weight()==rhs.weight(); 00116 } 00117 00118 }}} // of namespace utility, yat, and theplu 00119 00120 #endif