OpenStructure
sequence_list_iterator.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_SEQ_IMPL_SEQUENCE_LIST_ITERATOR_HH
20 #define OST_SEQ_IMPL_SEQUENCE_LIST_ITERATOR_HH
21 
22 /*
23  Author: Marco Biasini
24  */
25 
26 #include <ost/seq/module_config.hh>
27 namespace ost { namespace seq { namespace impl {
28 
30 template <typename T, typename I>
31 class TEMPLATE_EXPORT SequenceListIterator {
32 public:
33  using ValueType = T;
34  using IteratorType = I;
36 
37  using iterator_category = std::random_access_iterator_tag;
38  using value_type = T; // duplicate
39  using difference_type = std::ptrdiff_t;
40  using pointer = T*;
41  using reference = T&;
42 
43 protected:
44  void UpdateVal()
45  {
46  if (current_it_<end_) {
47  current_val_=ValueType(*current_it_);
48  }
49  }
50 public:
52  current_it_(it), end_(end)
53  {
54  this->UpdateVal();
55  }
56 
58  {
59  return current_val_;
60  }
61 
63  {
64  return &current_val_;
65  }
66 
68  ++current_it_;
69  this->UpdateVal();
70  return *this;
71  }
72 
74  current_it_+=n;
75  this->UpdateVal();
76  return *this;
77  }
79  ClassType ans(current_it_, end_);
80  ans+=n;
81  return *this;
82  }
84  current_it_-=n;
85  this->UpdateVal();
86  return *this;
87  }
88 
90  ClassType ans(*this);
91  ++current_it_;
92  this->UpdateVal();
93  return ans;
94  }
95 
96  bool operator==(const ClassType& rhs) const
97  {
98  return current_it_==rhs.current_it_;
99  }
100 
101  bool operator!=(const ClassType& rhs) const
102  {
103  return !(*this==rhs);
104  }
105 private:
106  IteratorType current_it_;
107  IteratorType end_;
108  ValueType current_val_;
109 };
110 
111 }}}
112 
113 #endif
bool operator!=(const ClassType &rhs) const
std::random_access_iterator_tag iterator_category
SequenceListIterator(IteratorType it, IteratorType end)
bool operator==(const ClassType &rhs) const
pointer_it< T > end(const std::vector< T > &values)
Definition: base.dox:1