source: trunk/yat/utility/DataWeightProxy.h @ 2122

Last change on this file since 2122 was 2122, checked in by Peter, 12 years ago

Remove implementation of operator==(DataWeightProxy?, DataWeightProxy?)
and rather rely on implicit conversion to DataWeight? and its
operator. This implies the behavior changes but that change is needed
because the previous behavior was very unexpected.

closes #578

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1#ifndef _theplu_yat_utility_data_weight_proxy_
2#define _theplu_yat_utility_data_weight_proxy_
3
4// $Id: DataWeightProxy.h 2122 2009-12-19 14:30:55Z peter $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009 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
28namespace theplu {
29namespace yat {
30namespace utility {
31
32  /**
33     \internal
34
35     \brief Proxy class for DataWeight
36
37     DataIterator and WeightIterator should be a TrivialIterator
38  */
39  template<typename DataIterator, typename WeightIterator>
40  class DataWeightProxy
41  {
42  public:
43    /**
44       \brief Default constructor
45
46       \param data iterator pointing to data to hold
47       \param weight iterator pointing to weight to hold
48     */
49    DataWeightProxy(DataIterator data, WeightIterator weight)
50      : data_(data), weight_(weight) {}
51
52    /**
53       \return reference to data
54     */
55    //typename std::iterator_traits<DataWeight>::reference data(void) const
56    double& data(void) { return *data_; }
57
58    /**
59       \return const reference to data
60     */
61    const double& data(void) const { return *data_ ; }
62
63    /**
64       \return reference to weight
65     */
66    double& weight(void) { return *weight_; }
67
68    /**
69       \return const reference to weight
70     */
71    const double& weight(void) const { return *weight_; }
72
73    /**
74       \brief assignment operator
75     */
76    DataWeightProxy& operator=(const DataWeightProxy& rhs)
77    {
78      data() = rhs.data();
79      weight() = rhs.weight();
80      return *this;
81    }
82
83    /**
84       \brief assignment operator
85     */
86    DataWeightProxy& operator=(const DataWeight& rhs)
87    {
88      data() = rhs.data();
89      weight() = rhs.weight();
90      return *this;
91    }
92
93    /**
94       \brief Conversion to DataWeight
95     */
96    operator DataWeight() const 
97    { return DataWeight(this->data(), this->weight()); }
98
99  private:
100    DataIterator data_;
101    WeightIterator weight_;
102
103    // using compiler generated copy and assignment
104    //DataWeightProxy& operator=(const DataWeightProxy&);
105    //DataWeightProxy(const DataWeightProxy&);
106  };
107
108}}} // of namespace utility, yat, and theplu
109
110#endif
Note: See TracBrowser for help on using the repository browser.