Flow123d  release_3.0.0-1190-g0f314ad
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 of type ObjectIn in some container.
24  *
25  * Operators '*' and '->' returns objects of type ObjectOut
26  *
27  * Requires the template object to implement:
28  * - comparison operator==()
29  * - increment operator++()
30  */
31 template<class ObjectIn, class ObjectOut>
33 {
34 public:
35 // IterConvert();
36 
37  IterConvert(const ObjectIn& object);
38 
39  /// equal operator
40  bool operator==(const IterConvert& other);
41  /// non-equal operator
42  bool operator!=(const IterConvert& other);
43 
44  /// * dereference operator
45  const ObjectOut& operator*() const;
46 
47  /// -> dereference operator
48  const ObjectOut* operator->() const;
49 
50  /// prefix increment
52 
53 private:
54  /// Output element of the output mesh.
55  ObjectIn object_;
56  mutable ObjectOut out_;
57 };
58 
59 
60 /**
61  * @brief General iterator template.
62  *
63  * Same as previous but doesn't provide specialization of operators '*' and '->'.
64  */
65 template<class Object>
67 
68 
69 /**
70  * Create iterator from object
71  */
72 template<class Object>
73 Iter<Object> make_iter(Object obj) {
74  return Iter<Object>(obj);
75 }
76 
77 /**
78  * Create convertible iterator from object
79  */
80 template<class ObjectIn, class ObjectOut>
83 }
84 
85 
86 // --------------------------------------------------- Iter INLINE implementation -----------
87 // inline IterConvert::IterConvert()
88 // {}
89 
90 template<class ObjectIn, class ObjectOut>
91 inline IterConvert<ObjectIn, ObjectOut>::IterConvert(const ObjectIn& object)
92 : object_(object)
93 {}
94 
95 template<class ObjectIn, class ObjectOut>
97 {
98  return (object_ == other.object_);
99 }
100 
101 template<class ObjectIn, class ObjectOut>
103 {
104  return !( *this == other);
105 }
106 
107 template<class ObjectIn, class ObjectOut>
108 inline const ObjectOut& IterConvert<ObjectIn, ObjectOut>::operator*() const
109 {
110  out_ = (ObjectOut)object_;
111  return out_;
112 }
113 
114 template<class ObjectIn, class ObjectOut>
115 inline const ObjectOut* IterConvert<ObjectIn, ObjectOut>::operator->() const
116 {
117  out_ = (ObjectOut)object_;
118  return &out_;
119 }
120 
121 template<class ObjectIn, class ObjectOut>
123 {
124  object_.inc();
125  return (*this);
126 }
127 
128 #endif // GENERAL_ITERATOR_HH_
IterConvert & operator++()
prefix increment
Iter< Object > make_iter(Object obj)
ObjectOut out_
const ObjectOut * operator->() const
-> dereference operator
ObjectIn object_
Output element of the output mesh.
IterConvert(const ObjectIn &object)
bool operator!=(const IterConvert &other)
non-equal operator
const ObjectOut & operator*() const
General iterator template. Provides iterator over objects of type ObjectIn in some container...
bool operator==(const IterConvert &other)
equal operator