mCRL2
Loading...
Searching...
No Matches
builder.h
Go to the documentation of this file.
1// Author(s): 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_BUILDER_H
13#define MCRL2_ATERMPP_BUILDER_H
14
17
18namespace atermpp {
19
20template <typename Derived>
21struct builder
22{
23 Derived& derived()
24 {
25 return static_cast<Derived&>(*this);
26 }
27
28 // Enter object
29 template <typename T>
30 void enter(const T&)
31 {}
32
33 // Leave object
34 template <typename T>
35 void leave(const T&)
36 {}
37
38 template <class T>
39 void apply(T& result, const aterm_int& x)
40 {
41 derived().enter(x);
42 derived().leave(x);
43 result=x;
44 }
45
46 template <class T>
47 void apply(T& result, const aterm_list& x)
48 {
49 derived().enter(x);
50 make_term_list(static_cast<aterm_list&>(result), x.begin(), x.end(), [&](aterm& r, const aterm& v) { return derived().apply(r, v); } ) ;
51 derived().leave(x);
52
53 // return mcrl2::workaround::return_std_move(result);
54 }
55
56 /* template <class T>
57 void apply(T& result, const aterm& x)
58 {
59 derived().enter(x);
60 make_term_appl(result, x.function() , x.begin(), x.end(), [&](aterm& r, const aterm& v) { return derived().apply(r, v); } );
61 derived().leave(x);
62
63 // return mcrl2::workaround::return_std_move(result);
64 } */
65
66 template <class T>
67 void apply(T& result, const aterm& x)
68 {
69 derived().enter(x);
70 if (x.type_is_list())
71 {
72 derived().apply(result, atermpp::down_cast<aterm_list>(x));
73 }
74 else if (x.type_is_int())
75 {
76 derived().apply(result, atermpp::down_cast<aterm_int>(x));
77 }
78 else // It is an application, other than a list or an int.
79 {
80 make_term_appl(result, x.function() , x.begin(), x.end(), [&](aterm& r, const aterm& v) { return derived().apply(r, v); } );
81 }
82 derived().leave(x);
83 }
84};
85
86} // namespace atermpp
87
88#endif // MCRL2_ATERMPP_BUILDER_H
Term containing an integer.
An integer term stores a single std::size_t value. It carries no arguments.
Definition aterm_int.h:26
const_iterator end() const
Returns a const_iterator pointing past the last argument.
Definition aterm.h:172
const_iterator begin() const
Returns an iterator pointing to the first argument.
Definition aterm.h:165
const function_symbol & function() const
Returns the function symbol belonging to an aterm.
Definition aterm.h:144
A list of aterm objects.
Definition aterm_list.h:24
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
Definition aterm_list.h:282
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
bool type_is_list() const noexcept
Dynamic check whether the term is an aterm_list.
Definition aterm_core.h:72
bool type_is_int() const noexcept
Dynamic check whether the term is an aterm_int.
Definition aterm_core.h:63
The main namespace for the aterm++ library.
Definition algorithm.h:21
void make_term_list(term_list< Term > &target)
Make an empty list and put it in target;.
Definition aterm_list.h:314
void make_term_appl(Term &target, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Constructor an aterm in a variable based on a function symbol and an forward iterator providing the a...
Definition aterm.h:213
void leave(const T &)
Definition builder.h:35
Derived & derived()
Definition builder.h:23
void enter(const T &)
Definition builder.h:30
void apply(T &result, const aterm_int &x)
Definition builder.h:39
void apply(T &result, const aterm &x)
Definition builder.h:67
void apply(T &result, const aterm_list &x)
Definition builder.h:47