source: trunk/yat/utility/DataIterator.h @ 1365

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

working on ticket:369 - created a DataIterator? that seems to work. However, it can't work in a mutable fashion because of limitations in iterator_traits (see #391). Also there should be a WeightIterator? before ticket:369 can be closed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1#ifndef _theplu_yat_utility_data_iterator_
2#define _theplu_yat_utility_data_iterator_
3
4// $Id: DataIterator.h 1365 2008-07-10 20:30:07Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://trac.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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include <boost/iterator/iterator_adaptor.hpp>
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33  /**
34     @brief DataIterator
35  */
36  template<typename Base>
37  class DataIterator
38    : public boost::iterator_adaptor<
39    DataIterator<Base>               // Derived
40    , Base                          // Base
41    , double              // Value
42    , boost::forward_traversal_tag    // CategoryOrTraversal
43    , double
44    >
45
46  {
47  public:
48    explicit DataIterator(Base b)
49      : DataIterator::iterator_adaptor_(b) {}
50
51    double operator*(void) const
52    { return iterator_traits<Base>().data(this->base()); }
53
54  private:
55  };
56
57  /**
58     \brief convenient function to create DataIterator
59
60     Convenient function in same fashion as std::make_pair.
61   */
62  template<typename Base>
63  DataIterator<Base> make_data_iterator(Base base)
64  {
65    return DataIterator<Base>(base);
66  }
67 
68
69
70}}} // of namespace utility, yat, and theplu
71
72#endif
Note: See TracBrowser for help on using the repository browser.