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_IMPL_FROM_UNSIGNED_TO_VALUE_HH
00028 # define MLN_CONVERT_IMPL_FROM_UNSIGNED_TO_VALUE_HH
00029 
00035 
00036 # include <utility>
00037 # include <mln/value/concept/integer.hh>
00038 # include <mln/core/concept/value.hh>
00039 # include <mln/value/label.hh>
00040 # include <mln/math/round.hh>
00041 
00042 
00043 
00044 
00045 namespace mln
00046 {
00047 
00048   namespace convert
00049   {
00050 
00052     template <typename V>
00053     void
00054     from_to(const unsigned& from, Value<V>& to);
00055 
00057     inline
00058     void
00059     from_to_(const unsigned& from, bool& to);
00060 
00061 # ifndef MLN_INCLUDE_ONLY
00062 
00063       namespace impl
00064       {
00065 
00066         
00067 
00068         template <typename V>
00069         inline
00070         void
00071         from_unsigned_to_value(const unsigned&            from,
00072                                mln::value::Integer<V>&    to)
00073         {
00074           exact(to) = from;
00075         }
00076 
00077         template <unsigned n>
00078         inline
00079         void
00080         from_unsigned_to_value(const unsigned&            from,
00081                                mln::value::label<n>&      to)
00082         {
00083           exact(to) = from;
00084         }
00085 
00086         
00087 
00088         template <typename V>
00089         inline
00090         void
00091         from_unsigned_to_value(const unsigned&,
00092                                Value<V>&)
00093         {
00094           mlc_abort(V)::check();
00095         }
00096 
00097       } 
00098 
00099 
00100       namespace internal
00101       {
00102 
00103         template <typename V>
00104         inline
00105         void
00106         from_unsigned_to_value_dispatch(const unsigned& from, Value<V>& to)
00107         {
00108           impl::from_unsigned_to_value(from, exact(to));
00109         }
00110 
00111       } 
00112 
00113 
00114       namespace over_load
00115       {
00116 
00117         
00118         
00119         template <typename V>
00120         void
00121         from_to_(const unsigned& from, Value<V>& to)
00122         {
00123           internal::from_unsigned_to_value_dispatch(from, to);
00124         }
00125 
00126 
00127         
00128         
00129         inline
00130         void
00131         from_to_(const unsigned& from, bool& to)
00132         {
00133           to = (from != 0u);
00134         }
00135 
00136 
00137       } 
00138 
00139 
00140 # endif // ! MLN_INCLUDE_ONLY
00141 
00142   } 
00143 
00144 } 
00145 
00146 
00147 #endif // ! MLN_CONVERT_IMPL_FROM_UNSIGNED_TO_VALUE_HH