12#ifndef MCRL2_ATERMPP_ALGORITHM_H
13#define MCRL2_ATERMPP_ALGORITHM_H
15#include <unordered_map>
26template <
template <
class>
class Builder,
class ReplaceFunction>
29 typedef Builder<replace_aterm_builder<Builder, ReplaceFunction> >
super;
47 super::apply(result, x);
56template <
template <
class>
class Builder,
class ReplaceFunction>
57replace_aterm_builder<Builder, ReplaceFunction>
63template <
template <
class>
class Builder,
class ReplaceFunction>
66 typedef Builder<partial_replace_aterm_builder<Builder, ReplaceFunction> >
super;
81 std::pair<aterm, bool> p =
f(x);
84 super::apply(result, x);
93template <
template <
class>
class Builder,
class ReplaceFunction>
94partial_replace_aterm_builder<Builder, ReplaceFunction>
100template <
template <
class>
class Builder,
class ReplaceFunction>
103 typedef Builder<bottom_up_replace_aterm_builder<Builder, ReplaceFunction> >
super;
107 using super::derived;
120 result =
static_cast<T
>(
f(t));
124template <
template <
class>
class Builder,
class ReplaceFunction>
125bottom_up_replace_aterm_builder<Builder, ReplaceFunction>
131template <
template <
class>
class Builder,
class ReplaceFunction>
134 typedef Builder<cached_bottom_up_replace_aterm_builder<Builder, ReplaceFunction> >
super;
138 using super::derived;
141 std::unordered_map<aterm, aterm>&
cache;
150 auto i =
cache.find(x);
151 if (i !=
cache.end())
163template <
template <
class>
class Builder,
class ReplaceFunction>
164cached_bottom_up_replace_aterm_builder<Builder, ReplaceFunction>
178template <
typename UnaryFunction,
typename Term>
181 return detail::for_each_impl< typename std::add_lvalue_reference< UnaryFunction >::type >(t, op);
188template <
typename Term,
typename MatchPredicate>
192 detail::find_if_impl< typename std::add_lvalue_reference< MatchPredicate >::type >(t, match, output);
203template <
typename Term,
typename MatchPredicate,
typename StopPredicate>
206 return detail::partial_find_if_impl<typename std::add_lvalue_reference<MatchPredicate>::type>(t, match, stop);
214template <
typename Term,
typename MatchPredicate,
typename OutputIterator>
215void find_all_if(
const Term& t, MatchPredicate match, OutputIterator destBegin)
217 OutputIterator i = destBegin;
218 detail::find_all_if_impl< typename std::add_lvalue_reference< MatchPredicate >::type >(t, match, i);
229template <
typename Term,
typename MatchPredicate,
typename StopPredicate,
typename OutputIterator>
232 OutputIterator i = destBegin;
233 detail::partial_find_all_if_impl< typename std::add_lvalue_reference< MatchPredicate >::type,
234 typename std::add_lvalue_reference< StopPredicate >::type >(t, match, stop, i);
245template <
typename Term,
typename ReplaceFunction>
249 detail::make_replace_aterm_builder<atermpp::builder>(r).apply(result,t);
260template <
typename Term>
263 return replace(t, [&](
const aterm& t) {
return t == old_value ? new_value : t; });
275template <
typename Term,
typename ReplaceFunction>
279 detail::make_bottom_up_replace_aterm_builder<atermpp::builder>(r).apply(result, t);
290template <
typename Term>
307template <
typename Term,
typename ReplaceFunction>
311 detail::make_partial_replace_aterm_builder<atermpp::builder>(r).apply(result, t);
325template <
typename Term,
typename ReplaceFunction>
329 detail::make_cached_bottom_up_replace_aterm_builder<atermpp::builder>(r, cache).apply(result, t);
Implementations of algorithms.
add your file description here.
cached_bottom_up_replace_aterm_builder< Builder, ReplaceFunction > make_cached_bottom_up_replace_aterm_builder(ReplaceFunction f, std::unordered_map< aterm, aterm > &cache)
replace_aterm_builder< Builder, ReplaceFunction > make_replace_aterm_builder(ReplaceFunction f)
partial_replace_aterm_builder< Builder, ReplaceFunction > make_partial_replace_aterm_builder(ReplaceFunction f)
bottom_up_replace_aterm_builder< Builder, ReplaceFunction > make_bottom_up_replace_aterm_builder(ReplaceFunction f)
The main namespace for the aterm++ library.
Term replace(const Term &t, ReplaceFunction r)
Replaces each subterm x of t by r(x). The ReplaceFunction r has the following signature: aterm x; ate...
void partial_find_all_if(Term t, MatchPredicate match, StopPredicate stop, OutputIterator destBegin)
Finds all subterms of t that match a given predicate, and writes the found terms to the destination r...
aterm find_if(const Term &t, MatchPredicate match)
Finds a subterm of t that matches a given predicate.
UnaryFunction for_each(Term t, UnaryFunction op)
Calls op(elem) for subterms of the term t.
void find_all_if(const Term &t, MatchPredicate match, OutputIterator destBegin)
Finds all subterms of t that match a given predicate, and writes the found terms to the destination r...
Term partial_replace(Term t, ReplaceFunction r)
Replaces subterms x of t by r(x). The replace function r returns an additional boolean value....
aterm partial_find_if(Term t, MatchPredicate match, StopPredicate stop)
Finds a subterm of t that matches a given predicate. The term is only partially traversed....
Term bottom_up_replace(Term t, ReplaceFunction r)
Replaces each subterm x of t by r(x). The ReplaceFunction r has the following signature: aterm x; ate...
Builder< bottom_up_replace_aterm_builder< Builder, ReplaceFunction > > super
void apply(T &result, const aterm &x)
bottom_up_replace_aterm_builder(ReplaceFunction f_)
Builder< cached_bottom_up_replace_aterm_builder< Builder, ReplaceFunction > > super
std::unordered_map< aterm, aterm > & cache
cached_bottom_up_replace_aterm_builder(ReplaceFunction f_, std::unordered_map< aterm, aterm > &cache_)
void apply(T &result, const aterm &x)
partial_replace_aterm_builder(ReplaceFunction f_)
void apply(T &result, const aterm &x)
Builder< partial_replace_aterm_builder< Builder, ReplaceFunction > > super
void apply(T &result, const aterm &x)
replace_aterm_builder(ReplaceFunction f_)
Builder< replace_aterm_builder< Builder, ReplaceFunction > > super