Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
iter.h
1 /*
2  * Tool classes for iterators.
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2019, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_ITER_H_
22 #define ELM_ITER_H_
23 
24 namespace elm {
25 
26 // PreIterator class
27 template <class I, class T>
28 class PreIterator {
29 public:
30  typedef T t;
31  typedef T return_t;
32 
33  inline bool operator()() const { return !((I *)this)->ended(); }
34  inline bool operator!() const { return ((I *)this)->ended(); }
35 
36  inline T operator*() const { return ((I *)this)->item(); }
37  inline T operator->() const { return ((I *)this)->item(); }
38 
39  inline I& operator++() { ((I *)this)->next(); return *(I *)this; }
40  inline void operator++(int) { ((I *)this)->next(); }
41 
42  inline bool operator==(const I& i) const { return ((I *)this)->equals(i); }
43  inline bool operator!=(const I& i) const { return !((I *)this)->equals(i); }
44 
45 };
46 
47 // InplacePreIterator class
48 template <class I, class T>
50 public:
51  typedef T t;
52  typedef const T& return_t;
53 
54  inline bool operator()() const { return !((I *)this)->ended(); }
55  inline bool operator!() const { return ((I *)this)->ended(); }
56 
57  inline const T& operator*() const { return ((I *)this)->item(); }
58  inline const T& operator->() const { return ((I *)this)->item(); }
59 
60  inline I& operator++() { ((I *)this)->next(); return *(I *)this; }
61  inline void operator++(int) { ((I *)this)->next(); }
62 
63  inline bool operator==(const I& i) const { return ((I *)this)->equals(i); }
64  inline bool operator!=(const I& i) const { return !((I *)this)->equals(i); }
65 
66 };
67 
68 template <class I, class T>
69 class PreIter {
70 public:
71  inline bool operator()() const { return !((I *)this)->ended(); }
72  inline bool operator!() const { return ((I *)this)->ended(); }
73 
74  inline I& operator++() { ((I *)this)->next(); return *(I *)this; }
75  inline void operator++(int) { ((I *)this)->next(); }
76 
77  inline bool operator==(const I& i) const { return ((I *)this)->equals(i); }
78  inline bool operator!=(const I& i) const { return !((I *)this)->equals(i); }
79 
80 };
81 
82 template <class I, class T>
83 class ConstPreIter {
84 public:
85  inline const T& operator*() const { return ((I *)this)->item(); }
86  inline T operator->() const { return ((I *)this)->item(); }
87 };
88 
89 template <class I, class T>
90 class MutPreIter {
91 public:
92  inline T& operator*() { return ((I *)this)->item(); }
93  inline T operator->() { return ((I *)this)->item(); }
94 };
95 
96 } // elm
97 
98 #endif /* ELM_ITER_H_ */
elm::ConstPreIter
Definition: iter.h:83
elm::PreIterator::return_t
T return_t
Definition: iter.h:31
elm::InplacePreIterator::operator!=
bool operator!=(const I &i) const
Definition: iter.h:64
elm::ConstPreIter::operator*
const T & operator*() const
Definition: iter.h:85
elm::PreIterator::t
T t
Definition: iter.h:30
elm::MutPreIter
Definition: iter.h:90
elm::InplacePreIterator::operator!
bool operator!() const
Definition: iter.h:55
elm::ConstPreIter::operator->
T operator->() const
Definition: iter.h:86
elm::MutPreIter::operator->
T operator->()
Definition: iter.h:93
elm::PreIter::operator++
void operator++(int)
Definition: iter.h:75
elm::InplacePreIterator::operator->
const T & operator->() const
Definition: iter.h:58
elm::InplacePreIterator::operator()
bool operator()() const
Definition: iter.h:54
elm::PreIterator::operator==
bool operator==(const I &i) const
Definition: iter.h:42
elm::PreIter::operator!=
bool operator!=(const I &i) const
Definition: iter.h:78
elm::PreIter::operator++
I & operator++()
Definition: iter.h:74
elm::PreIterator::operator->
T operator->() const
Definition: iter.h:37
elm::InplacePreIterator::t
T t
Definition: iter.h:51
elm::InplacePreIterator::return_t
const typedef T & return_t
Definition: iter.h:52
elm::PreIterator::operator++
I & operator++()
Definition: iter.h:39
elm
Definition: adapter.h:26
elm::InplacePreIterator::operator++
void operator++(int)
Definition: iter.h:61
elm::InplacePreIterator::operator*
const T & operator*() const
Definition: iter.h:57
elm::PreIterator::operator++
void operator++(int)
Definition: iter.h:40
elm::InplacePreIterator::operator++
I & operator++()
Definition: iter.h:60
elm::MutPreIter::operator*
T & operator*()
Definition: iter.h:92
elm::PreIterator::operator!=
bool operator!=(const I &i) const
Definition: iter.h:43
elm::PreIterator::operator!
bool operator!() const
Definition: iter.h:34
elm::PreIterator::operator*
T operator*() const
Definition: iter.h:36
elm::InplacePreIterator::operator==
bool operator==(const I &i) const
Definition: iter.h:63
elm::InplacePreIterator
Definition: iter.h:49
elm::PreIter::operator!
bool operator!() const
Definition: iter.h:72
elm::PreIter::operator==
bool operator==(const I &i) const
Definition: iter.h:77
elm::PreIter::operator()
bool operator()() const
Definition: iter.h:71
elm::PreIterator
Definition: iter.h:28
elm::PreIterator::operator()
bool operator()() const
Definition: iter.h:33
elm::PreIter
Definition: iter.h:69