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

Last change on this file since 1537 was 1537, checked in by Peter, 13 years ago

refs #368 - redesign to solve some issues regarding mutable functionality in WeightedIterator?

  • 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 1537 2008-09-26 22:37:33Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "DataWeight.h"
26
27namespace theplu {
28namespace yat {
29namespace utility {
30
31  /**
32     \internal
33
34     \brief Proxy class for DataWeight
35
36     DataIterator and WeightIterator should be a TrivialIterator
37  */
38  template<typename DataIterator, typename WeightIterator>
39  class DataWeightProxy
40  {
41  public:
42    /**
43       \brief Default constructor
44
45       \param data iterator pointing to data to hold
46       \param weight iterator pointing to weight to hold
47     */
48    DataWeightProxy(DataIterator data, WeightIterator weight)
49      : data_(data), weight_(weight) {}
50
51    /**
52       \return reference to data
53     */
54    double& data(void) { return *data_; }
55
56    /**
57       \return const reference to data
58     */
59    const double& data(void) const { return *data_ ; }
60
61    /**
62       \return reference to weight
63     */
64    double& weight(void) { return *weight_; }
65
66    /**
67       \return const reference to weight
68     */
69    const double& weight(void) const { return *weight_; }
70
71    /**
72       \brief assignment operator
73     */
74    DataWeightProxy& operator=(const DataWeight& rhs)
75    {
76      data() = rhs.data();
77      weight() = rhs.weight();
78      return *this;
79    }
80
81    /**
82       \brief Conversion to DataWeight
83     */
84    operator DataWeight() const { return DataWeight(data(), weight()); }
85
86  private:
87    DataIterator data_;
88    WeightIterator weight_;
89
90    // using compiler generated copy and assignment
91    //DataWeightProxy& operator=(const DataWeightProxy&);
92    //DataWeightProxy(const DataWeightProxy&);
93  };
94
95 
96  /**
97     \brief equality operator
98   */
99  template<typename DataIterator, typename WeightIterator>
100  bool operator==(const DataWeightProxy<DataIterator, WeightIterator>& lhs,
101                  const DataWeightProxy<DataIterator, WeightIterator>& rhs)
102  {
103    return lhs.data()==rhs.data() && lhs.weight()==rhs.weight();
104  }
105
106}}} // of namespace utility, yat, and theplu
107
108#endif
Note: See TracBrowser for help on using the repository browser.