00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __CONST_MAP_HH
00018 # define __CONST_MAP_HH
00019
00020 # include "../strategies.hh"
00021 # include <bitset>
00022
00023 namespace aurelia {
00024
00025 template <typename S>
00026 struct const_map_strategy {
00027 S s;
00028 const_map_strategy(const S& s): s(s) {
00029 }
00030
00031 template <int N>
00032 std::bitset<N> operator()(const std::bitset<N>& t) const {
00033 for (unsigned i = 0; i < N; ++i) {
00034 s(t[i]);
00035 }
00036 return t;
00037 }
00038
00039 template <typename T>
00040 T operator()(const T& t) const {
00041 for (typename T::const_iterator i = t.begin(); i != t.end(); ++i)
00042 s(*i);
00043 return t;
00044 }
00045
00046 template <typename Pool>
00047 untyped_term<Pool> operator()(const untyped_term<Pool>& t) const {
00048 typedef untyped_term<Pool> T;
00049 typedef untyped_constructor<Pool> C;
00050
00051 try {
00052 if (t.constructor() != C::AS_EMPTY_LIST)
00053 throw failure();
00054 return t;
00055 } catch (failure) {
00056 if (t.constructor() == C::AS_LIST) {
00057 s(t[0]);
00058 (*this)(t[1]);
00059 return t;
00060 } else
00061 throw failure();
00062 }
00063 }
00064 };
00065
00070 template <typename S>
00071 const_map_strategy<S> const_map(const S& s) {
00072 return const_map_strategy<S>(s);
00073 }
00074
00075 }
00076
00077 #endif