libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNBlockIterator.h
Go to the documentation of this file.
1 /* Copyright 2009-2014 INSA Lyon, CoReNum
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNBlockIterator.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNBlockIterator_HEADER
23 #define CRNBlockIterator_HEADER
24 
26 
28 class block_iterator: public std::iterator<std::random_access_iterator_tag, SObject>
29 {
30  public:
32  /* constructors */
33  block_iterator():it() {}
34  block_iterator(const block_iterator&) = default;
35  block_iterator(block_iterator&&) = default;
36  block_iterator(const Vector::iterator &current):it(current) {}
37  virtual ~block_iterator() {}
38 
39  block_iterator& operator=(const block_iterator&) = default;
41  /* forward iterator */
42  const block_iterator& operator++() { ++it; return *this; }
43  block_iterator operator++(int) { block_iterator bis(it); ++it; return bis; }
44  bool operator==(block_iterator const &other) const { return it == other.it; }
45  bool operator!=(block_iterator const &other) const { return it != other.it; }
46  reference operator*() const { return *it; }
47  SBlock AsBlock() const { return std::static_pointer_cast<Block>(*it); }
48  SBlock operator->() const { return std::static_pointer_cast<Block>(*it); }
49  /* bidirectional iterator */
50  block_iterator& operator--() { --it; return *this; }
51  block_iterator operator--(int) { block_iterator bis(it); --it; return bis; }
52  /* random access iterator */
53  ptrdiff_t operator-(block_iterator const &rhs) const { return it - rhs.it; }
54  bool operator<(block_iterator const &other) const { return it < other.it; }
55  bool operator>(block_iterator const &other) const { return it > other.it; }
56  bool operator<=(block_iterator const &other) const { return it <= other.it; }
57  bool operator>=(block_iterator const &other) const { return it >= other.it; }
58  block_iterator operator+(int step) const { return block_iterator(it + step); }
59  block_iterator operator-(int step) const { return block_iterator(it - step); }
60  const block_iterator& operator+=(int step) { it += step; return *this; }
61  const block_iterator& operator-=(int step) { it -= step; return *this; }
62  reference operator[](int index) { return it[index]; }
63  private:
64  Vector::iterator it;
65 };
66 
68 class const_block_iterator: public std::iterator<std::random_access_iterator_tag, SCObject>
69 {
70  public:
71  /* constructors */
73  const_block_iterator(const block_iterator &other):it(other.it) {}
76  const_block_iterator(const Vector::const_iterator &current):it(current) {}
77  virtual ~const_block_iterator() {}
78 
81  /* forward iterator */
82  const const_block_iterator& operator++() { ++it; return *this; }
83  const_block_iterator operator++(int) { const_block_iterator bis(it); ++it; return bis; }
84  bool operator==(const_block_iterator const &other) const { return it == other.it; }
85  bool operator!=(const_block_iterator const &other) const { return it != other.it; }
86  value_type operator*() const { return *it; }
87  SCBlock AsBlock() const { return std::static_pointer_cast<const Block>(*it); }
88  SCBlock operator->() const { return std::static_pointer_cast<const Block>(*it); }
89  /* bidirectional iterator */
90  const_block_iterator& operator--() { --it; return *this; }
91  const_block_iterator operator--(int) { const_block_iterator bis(it); --it; return bis; }
92  /* random access iterator */
93  ptrdiff_t operator-(const_block_iterator const &rhs) const { return it - rhs.it; }
94  bool operator<(const_block_iterator const &other) const { return it < other.it; }
95  bool operator>(const_block_iterator const &other) const { return it > other.it; }
96  bool operator<=(const_block_iterator const &other) const { return it <= other.it; }
97  bool operator>=(const_block_iterator const &other) const { return it >= other.it; }
98  const_block_iterator operator+(int step) const { return const_block_iterator(it + step); }
99  const_block_iterator operator-(int step) const { return const_block_iterator(it - step); }
100  const const_block_iterator& operator+=(int step) { it += step; return *this; }
101  const const_block_iterator& operator-=(int step) { it -= step; return *this; }
102  value_type operator[](int index) const { return it[index]; }
103  private:
104  Vector::const_iterator it;
105 };
106 
107 
108 
109 #endif
110 
111 
bool operator>(const_block_iterator const &other) const
const_block_iterator(const block_iterator &other)
bool operator==(block_iterator const &other) const
virtual ~const_block_iterator()
bool operator<=(const_block_iterator const &other) const
const_block_iterator & operator--()
const_block_iterator & operator=(const const_block_iterator &)=default
const block_iterator & operator+=(int step)
Iterator on the blocks of a child tree.
bool operator>=(block_iterator const &other) const
block_iterator operator+(int step) const
bool operator!=(const_block_iterator const &other) const
bool operator==(const_block_iterator const &other) const
const const_block_iterator & operator+=(int step)
block_iterator operator-(int step) const
ptrdiff_t operator-(block_iterator const &rhs) const
const_block_iterator operator++(int)
const_block_iterator(const Vector::const_iterator &current)
const block_iterator & operator++()
block_iterator & operator--()
const const_block_iterator & operator++()
SBlock operator->() const
block_iterator operator--(int)
const_block_iterator operator-(int step) const
block_iterator & operator=(const block_iterator &)=default
bool operator>=(const_block_iterator const &other) const
SBlock AsBlock() const
bool operator<=(block_iterator const &other) const
const_block_iterator operator+(int step) const
reference operator*() const
bool operator>(block_iterator const &other) const
const const_block_iterator & operator-=(int step)
block_iterator operator++(int)
const_block_iterator operator--(int)
const block_iterator & operator-=(int step)
SCBlock AsBlock() const
ptrdiff_t operator-(const_block_iterator const &rhs) const
value_type operator[](int index) const
SCBlock operator->() const
block_iterator(const Vector::iterator &current)
const Iterator on the blocks of a child tree
virtual ~block_iterator()
friend class Block::const_block_iterator
bool operator<(const_block_iterator const &other) const
reference operator[](int index)
value_type operator*() const
bool operator!=(block_iterator const &other) const
bool operator<(block_iterator const &other) const