00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_CONVERT_CONVERSION_HH
00029 # define OLENA_CONVERT_CONVERSION_HH
00030
00031 # include <mlc/type.hh>
00032 # include <oln/core/image.hh>
00033 # include <oln/core/compose.hh>
00034 # include <ntg/utils/debug.hh>
00035 # include <oln/convert/abstract/conversion.hh>
00036 # include <functional>
00037
00038 namespace oln {
00043 namespace convert {
00044
00054 template<class ConvType, class Base, class InputType>
00055 struct convoutput
00056 {
00057 typedef typename abstract::conversion<ConvType, Base>::template output<InputType>::ret ret;
00058 };
00059
00061 namespace internal {
00065 template <class C, class UF>
00066 struct compconv1_ :
00067 public std::unary_function <typename UF::argument_type,
00068 typename C::template output<typename UF::argument_type>::ret>
00069 {
00070 typedef compconv1_ self_type;
00071
00072 typename self_type::result_type
00073 operator()(typename self_type::argument_type arg) const
00074 {
00075 return conv_(func_(arg));
00076 }
00077
00078 compconv1_(const C& conv, const UF& func)
00079 : conv_(conv), func_(func)
00080 {}
00081 private:
00082 const C conv_;
00083 const UF func_;
00084 };
00085
00089 template <class C, class BF>
00090 struct compconv2_ :
00091 public std::binary_function <typename BF::first_argument_type,
00092 typename BF::second_argument_type,
00093 typename C::template output<typename BF::result_type>::ret>
00094 {
00095 typedef compconv2_ self_type;
00096
00097 typename self_type::result_type
00098 operator()(typename self_type::first_argument_type arg1,
00099 typename self_type::second_argument_type arg2) const
00100 {
00101 return conv_(func_(arg1, arg2));
00102 }
00103
00104 compconv2_(const C &conv, const BF &func)
00105 : conv_(conv), func_(func)
00106 {}
00107 private:
00108 const C conv_;
00109 const BF func_;
00110 };
00111
00112 }
00113
00117 template <class C, class B, class UF>
00118 internal::compconv1_<C, UF>
00119 compconv1(const abstract::conversion<C, B>& conv, const UF &func)
00120 {
00121 return internal::compconv1_<C, UF>(conv.exact(), func);
00122 }
00123
00125 template <class C, class B, class BF>
00126 internal::compconv2_<C, BF>
00127 compconv2(const abstract::conversion<C, B>& conv, const BF &func)
00128 {
00129 return internal::compconv2_<C, BF>(conv.exact(), func);
00130 }
00131
00132
00139 template<class C, class B, class I> inline
00140 typename mute<I, typename convoutput<C, B, oln_value_type(I)>::ret>::ret
00141 apply(const abstract::conversion<C, B>& conv, const oln::abstract::image<I>& input)
00142 {
00143
00144
00145
00146
00147 return apply(compconv1(conv, f_identity<oln_value_type(I)>()), input);
00148 }
00149
00150 }
00151
00152
00153
00154 using convert::convoutput;
00155
00156 }
00157
00158
00159 #endif // OLENA_CONVERT_CONVERSION_HH