yat  0.13.2pre
WeightedIterator.h
1 #ifndef _theplu_yat_utility_weighted_iterator_
2 #define _theplu_yat_utility_weighted_iterator_
3 
4 // $Id: WeightedIterator.h 2375 2010-12-13 03:28:46Z peter $
5 
6 /*
7  Copyright (C) 2008, 2009, 2010 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 #include "DataWeightProxy.h"
27 
28 #include <boost/iterator/iterator_facade.hpp>
29 
30 #include <iterator>
31 
32 namespace theplu {
33 namespace yat {
34 namespace utility {
35 
57  template<typename DataIterator, typename WeightIterator>
59  : public boost::iterator_facade<
60  WeightedIterator<DataIterator, WeightIterator>,
61  DataWeight,
62  typename std::iterator_traits<DataIterator>::iterator_category,
63  DataWeightProxy<DataIterator, WeightIterator> >
64 
65  {
66  public:
71 
76 
85  {}
86 
91  : d_iter_(d), w_iter_(w)
92  {}
93 
97  const DataIterator& data_base(void) const { return d_iter_; }
98 
102  const WeightIterator& weight_base(void) const { return w_iter_; }
103 
108  {
110  w_iter_+n);
111  }
112 
113 
122  template<typename D2, typename W2>
124  typename boost::enable_if_convertible<D2,DataIterator>::type* = 0,
125  typename boost::enable_if_convertible<W2,WeightIterator>::type* = 0)
126  : d_iter_(other.data_base()), w_iter_(other.weight_base()) {}
127 
128 
129  private:
130  friend class boost::iterator_core_access;
131 
132  DataIterator d_iter_;
133  WeightIterator w_iter_;
134 
135  void advance(size_t n)
136  { std::advance(d_iter_, n); std::advance(w_iter_, n); }
137 
138  void decrement(void) { --d_iter_; --w_iter_; }
139 
140  typename std::iterator_traits<DataIterator>::difference_type
141  distance_to(const WeightedIterator& other) const
142  { return std::distance(d_iter_, other.d_iter_); }
143 
144  utility::DataWeightProxy<DataIterator, WeightIterator>
145  dereference(void) const
146  { return DataWeightProxy<DataIterator, WeightIterator>(d_iter_,
147  w_iter_);
148  }
149 
150  bool equal(const WeightedIterator& other) const
151  { return d_iter_==other.d_iter_ && w_iter_==other.w_iter_; }
152 
153  void increment(void) { ++d_iter_; ++w_iter_; }
154 
155  };
156 
164  template<typename DataIterator, typename WeightIterator>
165  WeightedIterator<DataIterator, WeightIterator>
167  {
169  }
170 
171 }}} // of namespace utility, yat, and theplu
172 
173 #endif
DataIterator data_iterator
DataIterator.
Definition: WeightedIterator.h:70
WeightedIterator.
Definition: WeightedIterator.h:58
DataWeightProxy< DataIterator, WeightIterator > operator[](int n) const
element operator
Definition: WeightedIterator.h:107
WeightedIterator< DataIterator, WeightIterator > weighted_iterator(DataIterator data, WeightIterator weight)
convenient function to create WeightedIterator
Definition: WeightedIterator.h:166
Proxy class for DataWeight.
Definition: DataWeightProxy.h:52
const DataIterator & data_base(void) const
Definition: WeightedIterator.h:97
DataIterator.
Definition: DataIterator.h:62
WeightedIterator(DataIterator d, WeightIterator w)
Constructor.
Definition: WeightedIterator.h:90
WeightIterator weight_iterator
DataIterator.
Definition: WeightedIterator.h:75
WeightIterator.
Definition: WeightIterator.h:61
const WeightIterator & weight_base(void) const
Definition: WeightedIterator.h:102
WeightedIterator(void)
Default Constructor.
Definition: WeightedIterator.h:84
WeightedIterator(WeightedIterator< D2, W2 > other, typename boost::enable_if_convertible< D2, DataIterator >::type *=0, typename boost::enable_if_convertible< W2, WeightIterator >::type *=0)
Conversion constructor.
Definition: WeightedIterator.h:123

Generated on Wed Jan 4 2017 02:23:07 for yat by  doxygen 1.8.5