Flow123d  release_3.0.0-506-g34af125
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 Iter 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>
30 class Iter
31 {
32 public:
33 // Iter();
34 
35  Iter(const Object& object);
36 
37  /// equal operator
38  bool operator==(const Iter& other);
39  /// non-equal operator
40  bool operator!=(const Iter& other);
41 
42  /// * dereference operator
43  const Object& operator*() const;
44 
45  /// -> dereference operator
46  const Object* operator->() const;
47 
48  /// prefix increment
49  Iter& operator++();
50 
51 private:
52  /// Output element of the output mesh.
53  Object object_;
54 };
55 
56 
57 /**
58  * Create iterator from object
59  */
60 template<class Object>
61 Iter<Object> make_iter(Object obj) {
62  return Iter<Object>(obj);
63 }
64 
65 
66 // --------------------------------------------------- Iter INLINE implementation -----------
67 // inline Iter::Iter()
68 // {}
69 
70 template<class Object>
71 inline Iter<Object>::Iter(const Object& object)
72 : object_(object)
73 {}
74 
75 template<class Object>
76 inline bool Iter<Object>::operator==(const Iter& other)
77 {
78  return (object_ == other.object_);
79 }
80 
81 template<class Object>
82 inline bool Iter<Object>::operator!=(const Iter& other)
83 {
84  return !( *this == other);
85 }
86 
87 template<class Object>
88 inline const Object& Iter<Object>::operator*() const
89 {
90  return object_;
91 }
92 
93 template<class Object>
94 inline const Object* Iter<Object>::operator->() const
95 {
96  return &object_;
97 }
98 
99 template<class Object>
101 {
102  object_.inc();
103  return (*this);
104 }
105 
106 #endif // GENERAL_ITERATOR_HH_
const Object * operator->() const
-> dereference operator
Iter< Object > make_iter(Object obj)
Iter & operator++()
prefix increment
bool operator==(const Iter &other)
equal operator
Iter(const Object &object)
bool operator!=(const Iter &other)
non-equal operator
const Object & operator*() const
General iterator template. Provides iterator over objects in some container.
Object object_
Output element of the output mesh.