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 #ifndef MLN_CONVERT_FROM_TO_HH
00028 # define MLN_CONVERT_FROM_TO_HH
00029 
00039 
00040 # include <mln/convert/impl/all.hh>
00041 # include <mln/convert/from_to.hxx>
00042 
00043 # include <mln/metal/abort.hh>
00044 # include <mln/metal/converts_to.hh>
00045 # include <mln/metal/is.hh>
00046 # include <mln/metal/is_a.hh>
00047 
00048 # include <mln/value/cast.hh>
00049 
00050 namespace mln
00051 {
00052 
00053   
00054   template <typename E> struct Object;
00055   template <typename E> struct Value;
00056   template <typename E> struct Site_Set;
00057   template <typename E> struct Image;
00058 
00059   namespace convert
00060   {
00061 
00062     template <typename F, typename T>
00063     void
00064     from_to(const F& from, T& to);
00065 
00066 
00067 # ifndef MLN_INCLUDE_ONLY
00068 
00069     namespace internal
00070     {
00071 
00072       
00073 
00074       
00075       template <typename I, typename S>
00076       inline
00077       void
00078       from_to_dispatch(const Image<I>& from, Site_Set<S>& to)
00079       {
00080         mlc_is(mln_trait_site_set_contents(S),
00081             mln::trait::site_set::contents::dynamic)::check();
00082         mln_precondition(exact(from).is_valid());
00083         mln::convert::impl::from_image_to_site_set(from, to);
00084       }
00085 
00086 
00087       
00088       template <typename S, typename I>
00089       inline
00090       void
00091       from_to_dispatch(const Site_Set<S>& from, Image<I>& to)
00092       {
00093         mlc_converts_to(mln_site(S), mln_site(I))::check(); 
00094         mln_precondition(exact(from).is_valid());
00095         mln::convert::impl::from_site_set_to_image(from, to);
00096       }
00097 
00098 
00099       
00100       template <typename F, typename T>
00101       inline
00102       void
00103       from_to_dispatch(const Value<F>& from, Value<T>& to)
00104       {
00105         mln::convert::impl::from_value_to_value(from, to);
00106       }
00107 
00108 
00109 
00110       
00111 
00112       
00113       
00114       template <typename F, typename T>
00115       inline
00116       void
00117       from_to_dispatch(metal::true_,
00118                        const Object<F>& from, Object<T>& to)
00119       {
00120         exact(to) = exact(from);
00121       }
00122 
00123 
00124       
00125       template <typename F, typename T>
00126       inline
00127       void
00128       from_to_dispatch(metal::false_,
00129                        const Object<F>& from, Object<T>& to)
00130       {
00131         over_load::from_to_(exact(from), exact(to));
00132       }
00133 
00134 
00135 
00136       
00137 
00138       
00139       template <typename F, typename T>
00140       inline
00141       void
00142       from_to_dispatch(const Object<F>& from, Object<T>& to)
00143       {
00144         typedef mlc_converts_to(F, T) F_converts_to_T; 
00145         internal::from_to_dispatch(F_converts_to_T(),
00146                                    exact(from), exact(to));
00147       }
00148 
00149 
00150 
00151       
00152       
00153 
00154       
00155       template <typename F, typename T>
00156       inline
00157       void
00158       from_to_dispatch(metal::false_,  const F& from,
00159                        metal::false_,  T&       to)
00160       {
00161         over_load::from_to_(from, to);
00162       }
00163 
00164 
00165       
00166       template <typename F, typename T>
00167       inline
00168       void
00169       from_to_dispatch(metal::true_,  const F& from,
00170                        metal::false_, T&       to)
00171       {
00172         over_load::from_to_(exact(from), to);
00173       }
00174 
00175 
00176       
00177       template <typename F, typename T>
00178       inline
00179       void
00180       from_to_dispatch(metal::false_, const F& from,
00181                        metal::true_,  T&       to)
00182       {
00183         over_load::from_to_(from, exact(to));
00184       }
00185 
00186       
00187       template <typename F, typename T>
00188       inline
00189       void
00190       from_to_dispatch(metal::true_,  const F& from,
00191                        metal::true_,  T&       to)
00192       {
00193         internal::from_to_dispatch(exact(from), exact(to));
00194       }
00195 
00196 
00197     } 
00198 
00199 
00200     namespace over_load
00201     {
00202 
00203 
00204       
00205       
00206       template <typename F, typename T>
00207       void
00208       from_to_(const Object<F>&, Object<T>&)
00209       {
00210         
00211         
00212         
00213         
00214         mlc_abort(F)::check();
00215       }
00216 
00217 
00218       
00219       template <typename T>
00220       inline
00221       void
00222       from_to_(const Object<T>& from, Object<T>& to)
00223       {
00224         exact(to) = exact(from);
00225       }
00226 
00227 
00228       
00229       template <typename T>
00230       inline
00231       void
00232       from_to_(const T& from, T& to)
00233       {
00234         to = from;
00235       }
00236 
00237 
00238       
00239       template <typename F, typename T>
00240       inline
00241       void
00242       from_to_(const F& from, T& to)
00243       {
00244         to = mln::value::cast<T>(from);
00245       }
00246 
00247 
00248     } 
00249 
00250 
00251 
00252     
00253 
00254     template <typename F, typename T>
00255     inline
00256     void
00257     from_to(const F& from, T& to)
00258     {
00259       typedef mlc_is_a(F, Object) F_is_object;
00260       typedef mlc_is_a(T, Object) T_is_object;
00261       internal::from_to_dispatch(F_is_object(), from,
00262                                  T_is_object(), to);
00263     }
00264 
00265 
00266 # endif // ! MLN_INCLUDE_ONLY
00267 
00268   } 
00269 
00270 } 
00271 
00272 
00273 #endif // ! MLN_CONVERT_FROM_TO_HH