mCRL2
Loading...
Searching...
No Matches
aterm_appl_iterator.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote, Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_ATERMPP_DETAIL_ATERM_APPL_ITERATOR_H
13#define MCRL2_ATERMPP_DETAIL_ATERM_APPL_ITERATOR_H
14
16
17namespace atermpp
18{
19
21template <typename Term>
23{
24 friend class aterm;
25
26 template < class Derived, class Base >
28 typename std::enable_if<
29 std::is_base_of<aterm, Base>::value &&
30 std::is_base_of<aterm, Derived>::value
31 >::type*);
32
33
34 protected:
35 const Term* m_term;
36
39 term_appl_iterator(const Term* t)
40 : m_term(t)
41 {}
42
43 public:
44 typedef Term value_type;
45 typedef const Term& reference;
46 typedef const Term* pointer;
47 typedef ptrdiff_t difference_type;
48 typedef std::random_access_iterator_tag iterator_category;
49
53 : m_term(other.m_term)
54 {}
55
60 {
61 m_term=other.m_term;
62 return *this;
63 }
64
67 const Term& operator*() const
68 {
69 return *m_term;
70 }
71
74 const Term* operator->() const
75 {
76 return m_term;
77 }
78
82 const Term& operator[](difference_type n) const
83 {
84 return *(m_term+n);
85 }
86
90 {
91 ++m_term;
92 return *this;
93 }
94
98 {
99 term_appl_iterator temp=*this;
100 ++m_term;
101 return temp;
102 }
103
107 {
108 --m_term;
109 return *this;
110 }
111
115 {
116 term_appl_iterator temp=*this;
117 --m_term;
118 return *this;
119 }
120
125 {
126 m_term+=n;
127 return *this;
128 }
129
134 {
135 m_term-=n;
136 return *this;
137 }
138
141 term_appl_iterator operator+(ptrdiff_t n) const
142 {
143 term_appl_iterator temp=*this;
144 return temp.m_term+n;
145 }
146
149 term_appl_iterator operator-(ptrdiff_t n) const
150 {
151 term_appl_iterator temp=*this;
152 return temp.m_term-n;
153 }
154
158 ptrdiff_t operator-(const term_appl_iterator& other) const
159 {
160 return m_term-other.m_term;
161 }
162
166 ptrdiff_t distance_to(const term_appl_iterator& other) const
167 {
168 return other.m_term-m_term;
169 }
170
171
175 bool operator ==(const term_appl_iterator& other) const
176 {
177 return m_term == other.m_term;
178 }
179
183 bool operator !=(const term_appl_iterator& other) const
184 {
185 return m_term != other.m_term;
186 }
187
191 bool operator <(const term_appl_iterator& other) const
192 {
193 return m_term < other.m_term;
194 }
195
199 bool operator <=(const term_appl_iterator& other) const
200 {
201 return m_term <= other.m_term;
202 }
203
207 bool operator >(const term_appl_iterator& other) const
208 {
209 return m_term > other.m_term;
210 }
211
215 bool operator >=(const term_appl_iterator& other) const
216 {
217 return m_term >= other.m_term;
218 }
219};
220
221namespace detail
222{
224 template < class Derived, class Base >
226 typename std::enable_if<
227 std::is_base_of<aterm, Base>::value &&
228 std::is_base_of<aterm, Derived>::value
229 >::type* /* = nullptr */)
230 {
231 static_assert(sizeof(Derived) == sizeof(_aterm*),
232 "term_appl_iterator only works on aterm classes to which no extra fields are added");
233 static_assert(sizeof(Base) == sizeof(_aterm*),
234 "term_appl_iterator only works on aterm classes to which no extra fields are added");
235 return term_appl_iterator<Derived>(reinterpret_cast<const Derived*>(a.m_term));
236 }
237
238} // namespace detail
239
240} // namespace atermpp
241
242#endif // MCRL2_ATERMPP_DETAIL_ATERM_APPL_ITERATOR_H
This is the class to which an aterm points.
Definition aterm_core.h:48
Iterator for term_appl.
term_appl_iterator operator++(int)
Postfix increment.
bool operator==(const term_appl_iterator &other) const
Equality of iterators.
bool operator<(const term_appl_iterator &other) const
Comparison of iterators.
term_appl_iterator(const term_appl_iterator &other)
The copy constructor.
bool operator>=(const term_appl_iterator &other) const
Comparison of iterators.
term_appl_iterator operator-(ptrdiff_t n) const
Decrease by a constant value.
term_appl_iterator & operator=(const term_appl_iterator &other)
The assignment operator.
term_appl_iterator & operator--()
Prefix decrement.
ptrdiff_t operator-(const term_appl_iterator &other) const
The negative distance from this to the other iterator.
std::random_access_iterator_tag iterator_category
bool operator<=(const term_appl_iterator &other) const
Comparison of iterators.
term_appl_iterator & operator++()
Prefix increment.
term_appl_iterator & operator-=(difference_type n)
Decrease the iterator with n steps.
const Term & operator[](difference_type n) const
The dereference operator.
term_appl_iterator operator+(ptrdiff_t n) const
Increase by a constant value.
bool operator!=(const term_appl_iterator &other) const
Inequality of iterators.
term_appl_iterator operator--(int)
Post decrement an iterator.
const Term * operator->() const
Dereference the current iterator.
term_appl_iterator & operator+=(difference_type n)
Increase the iterator with n steps.
bool operator>(const term_appl_iterator &other) const
Comparison of iterators.
const Term & operator*() const
The dereference operator.
term_appl_iterator(const Term *t)
Constructor.
ptrdiff_t distance_to(const term_appl_iterator &other) const
Provide the distance to the other iterator.
term_appl_iterator< Derived > aterm_appl_iterator_cast(term_appl_iterator< Base > a, typename std::enable_if< std::is_base_of< aterm, Base >::value &&std::is_base_of< aterm, Derived >::value >::type *=nullptr)
This function can be used to translate an term_appl_iterator of one sort into another.
The main namespace for the aterm++ library.
Definition algorithm.h:21