• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

from_unsigned_to_value.hh

00001 // Copyright (C) 2009, 2010, 2011 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
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         // Case 1:
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         // Default: no conversion defined.
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       } // end of namespace mln::convert::impl
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       } // end of namespace mln::convert::unsignedernal
00112 
00113 
00114       namespace over_load
00115       {
00116 
00117         // Facades.
00118         // unsigned-> Value
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         // Facades.
00128         // unsigned-> bool
00129         inline
00130         void
00131         from_to_(const unsigned& from, bool& to)
00132         {
00133           to = (from != 0u);
00134         }
00135 
00136 
00137       } // end of namespace mln::convert::over_load
00138 
00139 
00140 # endif // ! MLN_INCLUDE_ONLY
00141 
00142   } // end of namespace mln::convert
00143 
00144 } // end of namespace mln
00145 
00146 
00147 #endif // ! MLN_CONVERT_IMPL_FROM_UNSIGNED_TO_VALUE_HH

Generated on Tue Oct 4 2011 15:23:47 for Milena (Olena) by  doxygen 1.7.1