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

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

refs #368 - added several tests. Left now is to add specializations for trait classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_yat_utility_data_weight_proxy_
2#define _theplu_yat_utility_data_weight_proxy_
3
4// $Id: DataWeightProxy.h 1538 2008-09-27 04:27:55Z 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    //typename std::iterator_traits<DataWeight>::reference data(void) const
55    double& data(void) { return *data_; }
56
57    /**
58       \return const reference to data
59     */
60    const double& data(void) const { return *data_ ; }
61
62    /**
63       \return reference to weight
64     */
65    double& weight(void) { return *weight_; }
66
67    /**
68       \return const reference to weight
69     */
70    const double& weight(void) const { return *weight_; }
71
72    /**
73       \brief assignment operator
74     */
75    DataWeightProxy& operator=(const DataWeightProxy& rhs)
76    {
77      data() = rhs.data();
78      weight() = rhs.weight();
79      return *this;
80    }
81
82    /**
83       \brief assignment operator
84     */
85    DataWeightProxy& operator=(const DataWeight& rhs)
86    {
87      data() = rhs.data();
88      weight() = rhs.weight();
89      return *this;
90    }
91
92    /**
93       \brief Conversion to DataWeight
94     */
95    operator DataWeight() const 
96    { return DataWeight(this->data(), this->weight()); }
97
98  private:
99    DataIterator data_;
100    WeightIterator weight_;
101
102    // using compiler generated copy and assignment
103    //DataWeightProxy& operator=(const DataWeightProxy&);
104    //DataWeightProxy(const DataWeightProxy&);
105  };
106
107 
108  /**
109     \brief equality operator
110   */
111  template<typename DataIterator, typename WeightIterator>
112  bool operator==(const DataWeightProxy<DataIterator, WeightIterator>& lhs,
113                  const DataWeightProxy<DataIterator, WeightIterator>& rhs)
114  {
115    return lhs.data()==rhs.data() && lhs.weight()==rhs.weight();
116  }
117
118}}} // of namespace utility, yat, and theplu
119
120#endif
Note: See TracBrowser for help on using the repository browser.