* mln/convert/from_to.hxx: add more forward declarations.
* mln/convert/impl/all.hh: include from_double_to_value.hh.
* mln/convert/impl/from_double_to_value.hh: new file. Add a new
dispatch for double conversion.
---
milena/ChangeLog | 11 ++
milena/mln/convert/from_to.hxx | 13 ++
milena/mln/convert/impl/all.hh | 1 +
milena/mln/convert/impl/from_double_to_value.hh | 157 +++++++++++++++++++++++
4 files changed, 182 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/convert/impl/from_double_to_value.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 2a5fb87..6364251 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,16 @@
2009-01-09 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add from_double_to_value dispatch in from_to.
+
+ * mln/convert/from_to.hxx: add more forward declarations.
+
+ * mln/convert/impl/all.hh: include from_double_to_value.hh.
+
+ * mln/convert/impl/from_double_to_value.hh: new file. Add a new
+ dispatch for double conversion.
+
+2009-01-09 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Remove a useless test in level/median.
* tests/level/Makefile.am,
diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx
index 793da8b..e2cbe3d 100644
--- a/milena/mln/convert/from_to.hxx
+++ b/milena/mln/convert/from_to.hxx
@@ -194,6 +194,19 @@ namespace mln
void
from_to_(const Value<F>& from, Value<T>& to);
+ // double-> Value
+ template <typename V>
+ void
+ from_to_(const double& from, Value<V>& to);
+
+ // double-> unsigned
+ void
+ from_to_(const double& from, unsigned& to);
+
+ // double-> int
+ void
+ from_to_(const double& from, int& to);
+
// float -> Value
template <typename V>
void
diff --git a/milena/mln/convert/impl/all.hh b/milena/mln/convert/impl/all.hh
index a7ef79b..1a33732 100644
--- a/milena/mln/convert/impl/all.hh
+++ b/milena/mln/convert/impl/all.hh
@@ -33,6 +33,7 @@
/// File that includes all from-to conversion routines.
+# include <mln/convert/impl/from_double_to_value.hh>
# include <mln/convert/impl/from_float_to_value.hh>
# include <mln/convert/impl/from_image_to_site_set.hh>
# include <mln/convert/impl/from_int_to_value.hh>
diff --git a/milena/mln/convert/impl/from_double_to_value.hh
b/milena/mln/convert/impl/from_double_to_value.hh
new file mode 100644
index 0000000..fc1d23e
--- /dev/null
+++ b/milena/mln/convert/impl/from_double_to_value.hh
@@ -0,0 +1,157 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CONVERT_IMPL_FROM_DOUBLE_TO_VALUE_HH
+# define MLN_CONVERT_IMPL_FROM_DOUBLE_TO_VALUE_HH
+
+/// \file mln/convert/impl/from_double_to_value.hh
+///
+/// General conversion procedure from a double to a value.
+///
+/// \todo Augment code + add checks.
+
+# include <utility>
+# include <mln/value/concept/integer.hh>
+# include <mln/value/concept/floating.hh>
+# include <mln/core/concept/value.hh>
+# include <mln/math/round.hh>
+
+
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Conversion of a double \p from towards a value \p to.
+ template <typename V>
+ void
+ from_to(const double& from, Value<V>& to);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Case 1:
+
+ template <typename V>
+ inline
+ void
+ from_double_to_value(const double& from,
+ mln::value::Integer<V>& to)
+ {
+ exact(to) = math::round<V>()(from);
+ }
+
+ // Case 2:
+
+ template <typename V>
+ inline
+ void
+ from_double_to_value(const double& from,
+ mln::value::Floating<V>& to)
+ {
+ exact(to) = from;
+ }
+
+
+ // Default: no conversion defined.
+
+ template <typename V>
+ inline
+ void
+ from_double_to_value(const double& from,
+ Value<V>& to)
+ {
+ mlc_abort(V)::check();
+ }
+
+ } // end of namespace mln::convert::impl
+
+
+ namespace internal
+ {
+
+ template <typename V>
+ inline
+ void
+ from_double_to_value_dispatch(const double& from, Value<V>& to)
+ {
+ impl::from_double_to_value(from, exact(to));
+ }
+
+ } // end of namespace mln::convert::internal
+
+
+ namespace over_load
+ {
+
+ // Facades.
+
+
+ // double-> Value
+ template <typename V>
+ inline
+ void
+ from_to_(const double& from, Value<V>& to)
+ {
+ internal::from_double_to_value_dispatch(from, to);
+ }
+
+ // double-> unsigned
+ inline
+ void
+ from_to_(const double& from,
+ unsigned& to)
+ {
+ mln_precondition(from >= 0);
+ to = math::round<unsigned>()(from);
+ }
+
+ // double-> int
+ inline
+ void
+ from_to_(const double& from,
+ int& to)
+ {
+ to = math::round<int>()(from);
+ }
+
+ } // end of namespace mln::convert::over_load
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_IMPL_FROM_DOUBLE_TO_VALUE_HH
--
1.5.6.5