mCRL2
Loading...
Searching...
No Matches
aterm_list_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_ATERM_LIST_ITERATOR_H
13#define MCRL2_ATERMPP_ATERM_LIST_ITERATOR_H
14
16
17namespace atermpp
18{
19
21namespace detail
22{
23 template <class Term>
24 class _aterm_list;
25}
26
28
30template <typename Term>
32{
33 template<class T>
34 friend class term_list;
35
36 protected:
37 const detail::_aterm_list<Term>* m_list;
38
42 : m_list(static_cast<const detail::_aterm_list<Term>*>(l))
43 {
44 assert(l->function()==detail::g_term_pool().as_list()
46 }
47
48 public:
49 typedef Term value_type;
50 typedef Term& reference;
51 typedef Term* pointer;
52 typedef ptrdiff_t difference_type;
53 typedef std::forward_iterator_tag iterator_category;
54
57 : m_list(nullptr)
58 {}
59
63 : m_list(other.m_list)
64 {
65 }
66
70 {
71 m_list=other.m_list;
72 return *this;
73 }
74
76 const Term& operator*() const
77 {
78 assert(m_list->function()==detail::g_term_pool().as_list());
79 return m_list->head();
80 }
81
83 const Term* operator->() const
84 {
85 assert(m_list->function()==detail::g_term_pool().as_list());
86 return &m_list->head();
87 }
88
91 {
92 assert(m_list->function() == detail::g_term_pool().as_list());
93 m_list = static_cast<detail::_aterm_list<Term>*>(detail::address(m_list->tail()));
94 return *this;
95 }
96
99 {
100 assert(m_list->function() == detail::g_term_pool().as_list());
101 const term_list_iterator temp = *this;
102 m_list = static_cast<detail::_aterm_list<Term>*>(detail::address(m_list->tail()));
103 return temp;
104 }
105
109 bool operator ==(const term_list_iterator& other) const
110 {
111 return m_list == other.m_list;
112 }
113
117 bool operator !=(const term_list_iterator& other) const
118 {
119 return m_list != other.m_list;
120 }
121
125 bool operator <(const term_list_iterator& other) const
126 {
127 return m_list < other.m_list;
128 }
129
133 bool operator <=(const term_list_iterator& other) const
134 {
135 return m_list <= other.m_list;
136 }
137
141 bool operator >(const term_list_iterator& other) const
142 {
143 return m_list > other.m_list;
144 }
145
149 bool operator >=(const term_list_iterator& other) const
150 {
151 return m_list >= other.m_list;
152 }
153
154};
155
157template <typename Term>
159{
160 template<class T>
161 friend class term_list;
162
163 protected:
164 std::size_t m_position; // m_position refers one above the position to be deliverd.
165 std::unique_ptr<detail::_aterm_list<Term> const*[]> m_list_element_references;
166
170 : m_position(reinterpret_cast<const detail::_aterm_list<Term>*>(l)->size()),
171 m_list_element_references((m_position==0?nullptr:new typename detail::_aterm_list<Term> const*[m_position]))
172 {
173 assert(l->function()==detail::g_term_pool().as_list()
175 std::size_t j=0;
176 for(detail::_aterm_list<Term> const* t=reinterpret_cast<detail::_aterm_list<Term> const*>(l);
177 t->function()==detail::g_term_pool().as_list();
178 t=reinterpret_cast<detail::_aterm_list<Term> const*>(detail::address(t->tail())), j++)
179 {
181 }
182 }
183
184 public:
185 typedef Term value_type;
186 typedef Term& reference;
187 typedef Term* pointer;
188 typedef ptrdiff_t difference_type;
189 typedef std::forward_iterator_tag iterator_category;
190
193 : m_position(0),
195 {
196 }
197
201
205
207 const Term& operator*() const
208 {
209 assert(m_list_element_references[m_position-1]->function()==detail::g_term_pool().as_list());
210 return m_list_element_references[m_position-1]->head();
211 }
212
214 const Term* operator->() const
215 {
216 assert(m_list_element_references[m_position-1]->function()==detail::g_term_pool().as_list());
217 return &(m_list_element_references[m_position-1]->head());
218 }
219
222 {
223 assert(m_list_element_references[m_position-1]->function() == detail::g_term_pool().as_list());
224 m_position--;
225 return *this;
226 }
227
229 void operator++(int)
230 {
231 assert(m_list_element_references[m_position-1]->function() == detail::g_term_pool().as_list());
232 m_position--;
233 }
234
239 {
240 return m_position == other.m_position;
241 }
242
247 {
248 return !(*this == other);
249 }
250
254 bool operator <(const reverse_term_list_iterator& other) const
255 {
256 return m_position < other.position;
257 }
258
263 {
264 return m_position <= other.m_position;
265 }
266
270 bool operator >(const reverse_term_list_iterator& other) const
271 {
272 return m_position > other.m_position;
273 }
274
279 {
280 return m_position >= other.m_position;
281 }
282
283};
284
285} // namespace atermpp
286
287#endif // MCRL2_ATERMPP_ATERM_LIST_ITERATOR_H
This is the class to which an aterm points.
Definition aterm_core.h:48
const function_symbol & function() const noexcept
Definition aterm_core.h:55
const function_symbol & as_empty_list() noexcept
Definition aterm_pool.h:124
const function_symbol & as_list() noexcept
Definition aterm_pool.h:121
Reverse iterator for term_list.
reverse_term_list_iterator & operator=(const reverse_term_list_iterator &other)=delete
Assignment is not available.
bool operator>=(const reverse_term_list_iterator &other) const
Comparison of iterators.
bool operator>(const reverse_term_list_iterator &other) const
Comparison of iterators.
reverse_term_list_iterator()
Default constructor.
bool operator==(const reverse_term_list_iterator &other) const
Equality of iterators.
reverse_term_list_iterator(detail::_aterm const *l)
Constructor from an aterm which must be a list.
bool operator<=(const reverse_term_list_iterator &other) const
Comparison of iterators.
reverse_term_list_iterator & operator++()
Prefix increment operator on iterator.
const Term & operator*() const
Dereference operator on an iterator.
bool operator<(const reverse_term_list_iterator &other) const
Comparison of iterators.
const Term * operator->() const
Arrow operator on an iterator.
reverse_term_list_iterator(const reverse_term_list_iterator &other)=delete
The copy constructor is not available.
std::unique_ptr< detail::_aterm_list< Term > const *[]> m_list_element_references
bool operator!=(const reverse_term_list_iterator &other) const
Inequality of iterators.
void operator++(int)
Postfix increment operator on iterator.
std::forward_iterator_tag iterator_category
Iterator for term_list.
const detail::_aterm_list< Term > * m_list
term_list_iterator()
Default constructor.
std::forward_iterator_tag iterator_category
bool operator<=(const term_list_iterator &other) const
Comparison of iterators.
bool operator<(const term_list_iterator &other) const
Comparison of iterators.
term_list_iterator & operator=(const term_list_iterator &other)
Assignment.
term_list_iterator operator++(int)
Postfix increment operator on iterator.
bool operator>(const term_list_iterator &other) const
Comparison of iterators.
term_list_iterator(const term_list_iterator &other)
Copy constructor.
const Term & operator*() const
Dereference operator on an iterator.
term_list_iterator(const detail::_aterm *l)
Constructor from an aterm which must be a list.
bool operator>=(const term_list_iterator &other) const
Comparison of iterators.
bool operator!=(const term_list_iterator &other) const
Inequality of iterators.
term_list_iterator & operator++()
Prefix increment operator on iterator.
bool operator==(const term_list_iterator &other) const
Equality of iterators.
const Term * operator->() const
Arrow operator on an iterator.
A list of aterm objects.
Definition aterm_list.h:24
_aterm * address(const unprotected_aterm_core &t)
Definition aterm_core.h:239
aterm_pool & g_term_pool()
obtain a reference to the global aterm pool.
The main namespace for the aterm++ library.
Definition algorithm.h:21