Flow123d  release_2.2.0-914-gf1a3a4f
general_iterator.hh
Go to the documentation of this file.
1 // --------------------------------------------------- GeneralIterator ---------------------------------
2 /*!
3  *
4  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License version 3 as published by the
8  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
9  *
10  * This program 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 General Public License for more details.
13  *
14  *
15  * @file general_iterator.hh
16  * @brief Template GeneralIterator serves as general template for internal iterators.
17  */
18 
19 #ifndef GENERAL_ITERATOR_HH_
20 #define GENERAL_ITERATOR_HH_
21 
22 /** @brief General iterator template.
23  * Provides iterator over objects in some container.
24  *
25  * Requires the template object to implement:
26  * - comparison operator==()
27  * - increment operator++()
28  */
29 template<class Object>
31 {
32 public:
33 // GeneralIterator();
34 
35  GeneralIterator(const Object& object);
36 
37  /// equal operator
38  bool operator==(const GeneralIterator& other);
39  /// non-equal operator
40  bool operator!=(const GeneralIterator& other);
41 
42  /// * dereference operator
43  const Object& operator*() const;
44 
45  /// -> dereference operator
46  const Object* operator->() const;
47 
48  /// prefix increment
50 
51 private:
52  /// Output element of the output mesh.
53  Object object_;
54 };
55 
56 
57 // --------------------------------------------------- GeneralIterator INLINE implementation -----------
58 // inline GeneralIterator::GeneralIterator()
59 // {}
60 
61 template<class Object>
62 inline GeneralIterator<Object>::GeneralIterator(const Object& object)
63 : object_(object)
64 {}
65 
66 template<class Object>
68 {
69  return (object_ == other.object_);
70 }
71 
72 template<class Object>
74 {
75  return !( *this == other);
76 }
77 
78 template<class Object>
79 inline const Object& GeneralIterator<Object>::operator*() const
80 {
81  return object_;
82 }
83 
84 template<class Object>
85 inline const Object* GeneralIterator<Object>::operator->() const
86 {
87  return &object_;
88 }
89 
90 template<class Object>
92 {
93  object_.inc();
94  return (*this);
95 }
96 
97 #endif // GENERAL_ITERATOR_HH_
bool operator!=(const GeneralIterator &other)
non-equal operator
bool operator==(const GeneralIterator &other)
equal operator
Object object_
Output element of the output mesh.
GeneralIterator(const Object &object)
const Object & operator*() const
const Object * operator->() const
-> dereference operator
GeneralIterator & operator++()
prefix increment
General iterator template. Provides iterator over objects in some container.