Commit e1b3bd77 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Rely on Argument-Dependent Lookup (ADL) in from_to_ overloads.

	* mln/accu/count_labels.hh,
	* mln/convert/from_to.hxx	,
	* mln/convert/to.hh,
	* mln/core/alias/point1d.hh,
	* mln/core/alias/point2d.hh,
	* mln/core/alias/point3d.hh,
	* mln/core/dpoint.hh,
	* mln/core/internal/neighborhood_base.hh,
	* mln/core/point.hh,
	* mln/core/site_set/p_centered.hh,
	* mln/core/site_set/p_vaccess.hh,
	* mln/fun/v2v/hsl_to_rgb.hh,
	* mln/fun/v2v/rgb_to_hsl.hh,
	* mln/io/magick/save.hh,
	* mln/io/plot/save.hh,
	* mln/labeling/blobs_and_compute.hh,
	* mln/labeling/value_and_compute.hh,
	* mln/make/w_window2d.hh,
	* mln/win/multiple.hh,
	* mln/win/multiple_size.hh,
	* tests/accu/site_set/rectangularity.cc,
	* tests/core/other/graph_elt_neighborhood.cc,
	* tests/core/other/graph_elt_window.cc,
	* tests/core/other/point_set_compatibility.cc,
	* tests/draw/graph.cc: Update forward declarations and includes.

	* mln/algebra/vec.hh,
	* mln/convert/from_to.hh,
	* mln/convert/impl/from_double_to_value.hh,
	* mln/convert/impl/from_float_to_value.hh,
	* mln/convert/impl/from_image_to_site_set.hh,
	* mln/convert/impl/from_int_to_value.hh,
	* mln/convert/impl/from_unsigned_to_value.hh,
	* mln/convert/impl/from_value_to_value.hh,
	* mln/core/alias/neighb2d.hh,
	* mln/core/alias/neighb3d.hh,
	* mln/core/alias/window1d.hh,
	* mln/core/alias/window2d.hh,
	* mln/core/alias/window3d.hh,
	* mln/core/concept/accumulator.hh,
	* mln/core/concept/gdpoint.hh,
	* mln/core/concept/gpoint.hh,
	* mln/core/concept/image.hh,
	* mln/core/concept/proxy.hh,
	* mln/core/concept/site_set.hh,
	* mln/core/concept/window.hh,
	* mln/core/image/graph_window_if_piter.hh,
	* mln/core/image/image1d.hh,
	* mln/core/mixed_neighb.hh,
	* mln/core/neighb.hh,
	* mln/core/site_set/operators.hh,
	* mln/core/w_window.hh,
	* mln/fun/i2v/array.hh,
	* mln/util/object_id.hh,
	* mln/value/hsl.hh,
	* mln/value/int_u.hh,
	* mln/value/label.hh,
	* mln/value/qt/rgb32.hh,
	* mln/value/rgb.hh,
	* mln/histo/array.hh,
	* mln/util/array.hh: Move from_to_ overloads in the same namespace
	as their first argument.
parent 183d8311
2012-05-10 Guillaume Lazzara <z@lrde.epita.fr>
Rely on Argument-Dependent Lookup (ADL) in from_to_ overloads.
* mln/accu/count_labels.hh,
* mln/convert/from_to.hxx ,
* mln/convert/to.hh,
* mln/core/alias/point1d.hh,
* mln/core/alias/point2d.hh,
* mln/core/alias/point3d.hh,
* mln/core/dpoint.hh,
* mln/core/internal/neighborhood_base.hh,
* mln/core/point.hh,
* mln/core/site_set/p_centered.hh,
* mln/core/site_set/p_vaccess.hh,
* mln/fun/v2v/hsl_to_rgb.hh,
* mln/fun/v2v/rgb_to_hsl.hh,
* mln/io/magick/save.hh,
* mln/io/plot/save.hh,
* mln/labeling/blobs_and_compute.hh,
* mln/labeling/value_and_compute.hh,
* mln/make/w_window2d.hh,
* mln/win/multiple.hh,
* mln/win/multiple_size.hh,
* tests/accu/site_set/rectangularity.cc,
* tests/core/other/graph_elt_neighborhood.cc,
* tests/core/other/graph_elt_window.cc,
* tests/core/other/point_set_compatibility.cc,
* tests/draw/graph.cc: Update forward declarations and includes.
* mln/algebra/vec.hh,
* mln/convert/from_to.hh,
* mln/convert/impl/from_double_to_value.hh,
* mln/convert/impl/from_float_to_value.hh,
* mln/convert/impl/from_image_to_site_set.hh,
* mln/convert/impl/from_int_to_value.hh,
* mln/convert/impl/from_unsigned_to_value.hh,
* mln/convert/impl/from_value_to_value.hh,
* mln/core/alias/neighb2d.hh,
* mln/core/alias/neighb3d.hh,
* mln/core/alias/window1d.hh,
* mln/core/alias/window2d.hh,
* mln/core/alias/window3d.hh,
* mln/core/concept/accumulator.hh,
* mln/core/concept/gdpoint.hh,
* mln/core/concept/gpoint.hh,
* mln/core/concept/image.hh,
* mln/core/concept/proxy.hh,
* mln/core/concept/site_set.hh,
* mln/core/concept/window.hh,
* mln/core/image/graph_window_if_piter.hh,
* mln/core/image/image1d.hh,
* mln/core/mixed_neighb.hh,
* mln/core/neighb.hh,
* mln/core/site_set/operators.hh,
* mln/core/w_window.hh,
* mln/fun/i2v/array.hh,
* mln/util/object_id.hh,
* mln/value/hsl.hh,
* mln/value/int_u.hh,
* mln/value/label.hh,
* mln/value/qt/rgb32.hh,
* mln/value/rgb.hh,
* mln/histo/array.hh,
* mln/util/array.hh: Move from_to_ overloads in the same namespace
as their first argument.
2012-05-07 Guillaume Lazzara <z@lrde.epita.fr>
 
* mln/registration/icp.hh: Add a missing initialization.
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of Olena.
//
......@@ -30,6 +31,7 @@
///
/// Define an accumulator that counts the number of different labels.
# include <vector>
# include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh>
# include <mln/metal/is_a.hh>
......
// Copyright (C) 2006, 2008, 2009, 2011 EPITA Research and Development
// Laboratory (LRDE)
// Copyright (C) 2006, 2008, 2009, 2011, 2012 EPITA Research and
// Development Laboratory (LRDE)
//
// This file is part of Olena.
//
......@@ -69,6 +69,14 @@ namespace mln
mln_sum_product(C,C) l2(const algebra::vec<n,C>& vec);
}
namespace value {
template <unsigned n> struct rgb;
}
template <typename G, typename C> struct point;
template <typename E> struct Gpoint;
// end of forward declarations
namespace trait
{
......@@ -261,6 +269,38 @@ namespace mln
vec& operator=(const mat<n, 1, U>& rhs);
};
/// \internal Conversion: vec -> rgb.
template <typename T, unsigned m>
void from_to_(const vec<3,T>& from, value::rgb<m>& to_);
/// \internal Conversion: vec<1,C1> -> point<G,C2>
template <typename C1, typename G, typename C2>
inline
void
from_to_(const vec<1,C1>& from, point<G,C2>& to);
/// \internal Conversion: vec<n,C1> -> point<G,C2>
template <unsigned n, typename C1, typename G, typename C2>
void
from_to_(const vec<n,C1>& from, point<G,C2>& to);
/// \internal Conversion: vec<1,C1> -> point<G,C1>
template <typename C1, typename G>
inline
void
from_to_(const vec<1,C1>& from, point<G,C1>& to);
/// \internal Conversion: vec<n,C1> -> point<G,C1>
template <unsigned n, typename C1, typename G>
void
from_to_(const vec<n,C1>& from, point<G,C1>& to);
/// \internal Conversion: vec -> gpoint
template <unsigned n, typename T, typename P>
void
from_to_(const vec<n,T>& from, Gpoint<P>& to);
} // end of namespace mln::algebra
......@@ -434,6 +474,46 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
namespace internal
{
template <typename C, typename C2>
inline
C
convert_data_(metal::bool_<false>, const C2& v)
{
return static_cast<C>(v);
}
template <typename C, typename C2>
inline
C
convert_data_(metal::bool_<true>, const C2& v)
{
return static_cast<C>(round(v));
}
template <typename C, typename C2>
inline
C
convert_data(const C2& v)
{
// If (C != float && C != double) && (C2 == float || C2 == double)
// => We want to round the value.
// Otherwise we can just statically cast.
//
return convert_data_<C>(
typename mlc_and(
mlc_and(mlc_is_not(C,float),
mlc_is_not(C,double)),
mlc_or(mlc_is(C2,float),
mlc_is(C2, double)))::eval(), v);
}
} // end of namespace mln::internal
namespace algebra
{
......@@ -733,6 +813,87 @@ namespace mln
}
// Conversions
template <typename T, unsigned m>
inline
void
from_to_(const vec<3,T>& from, value::rgb<m>& to)
{
algebra::vec<3, unsigned> tmp;
for (unsigned i = 0; i < 3; ++i)
tmp[i] = static_cast<unsigned>(from[i]); // FIXME: Use from_to_ instead of cast.
to = value::rgb<m>(tmp);
}
template <unsigned n, typename C1, typename G, typename C2>
inline
void
from_to_(const mln::algebra::vec<n,C1>& from, point<G,C2>& to)
{
mlc_converts_to(C1, C2)::check();
enum { dim = G::dim };
mlc_bool(G::dim == n)::check();
unsigned j = 0;
for (unsigned i = dim - 2; i < dim; ++i)
to[i] = mln::internal::convert_data<C2>(from[j++]);
for (unsigned i = 2; i < dim; ++i, ++j)
to[i-j] = mln::internal::convert_data<C2>(from[j]);
}
template <typename C1, typename G, typename C2>
inline
void
from_to_(const mln::algebra::vec<1,C1>& from, point<G,C2>& to)
{
mlc_converts_to(C1, C2)::check();
enum { dim = G::dim };
mlc_bool(G::dim == 1)::check();
to[0] = mln::internal::convert_data<C2>(from[0]);
}
template <unsigned n, typename C1, typename G>
inline
void
from_to_(const mln::algebra::vec<n,C1>& from, point<G,C1>& to)
{
enum { dim = G::dim };
mlc_bool(G::dim == n)::check();
unsigned j = 0;
for (unsigned i = dim - 2; i < dim; ++i)
to[i] = from[j++];
for (unsigned i = 2; i < dim; ++i, ++j)
to[i-j] = from[j];
}
template <typename C1, typename G>
inline
void
from_to_(const mln::algebra::vec<1,C1>& from, point<G,C1>& to)
{
enum { dim = G::dim };
mlc_bool(G::dim == 1)::check();
to[0] = from[0];
}
template <unsigned n, typename T, typename P>
inline
void
from_to_(const vec<n,T>& from, Gpoint<P>& to_)
{
mlc_bool(P::dim == n)::check();
P& to = exact(to_);
for (unsigned i = 0; i < n; ++i)
to[i] = static_cast< typename P::coord >(from[i]); // FIXME: cast -> best effort...
}
} // end of namespace mln::algebra
......
// Copyright (C) 2008, 2009, 2010 EPITA Research and Development
// Copyright (C) 2008, 2009, 2010, 2012 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
......@@ -38,7 +38,6 @@
/// \todo Find a solution for g++-2.95 and '...'; see FIXME below.
# include <mln/convert/impl/all.hh>
# include <mln/convert/from_to.hxx>
# include <mln/metal/abort.hh>
# include <mln/metal/converts_to.hh>
......@@ -64,8 +63,71 @@ namespace mln
from_to(const F& from, T& to);
} // end of namespace mln::convert
} // end of namespace mln
# ifndef MLN_INCLUDE_ONLY
// Exact same type.
template <typename T>
inline
void
from_to_(const T& from, T& to)
{
to = from;
}
// Default conversion.
template <typename F, typename T>
inline
void
from_to_(const F& from, T& to)
{
to = mln::value::cast<T>(from);
}
namespace mln
{
// Exact same type.
template <typename T>
inline
void
from_to_(const T& from, T& to)
{
to = from;
}
// Object -> Object (F not convertible towards T)
// No conversion exists!
template <typename F, typename T>
void
from_to_(const Object<F>&, Object<T>&)
{
// This particular from-to is not defined!
//
// Either this conversion is meaningless or an overload is
// missing.
mlc_abort(F)::check();
}
// Object -> Object
template <typename T>
inline
void
from_to_(const Object<T>& from, Object<T>& to)
{
exact(to) = exact(from);
}
namespace convert
{
namespace internal
{
......@@ -128,7 +190,7 @@ namespace mln
from_to_dispatch(metal::false_,
const Object<F>& from, Object<T>& to)
{
over_load::from_to_(exact(from), exact(to));
from_to_(exact(from), exact(to));
}
......@@ -158,7 +220,7 @@ namespace mln
from_to_dispatch(metal::false_, const F& from,
metal::false_, T& to)
{
over_load::from_to_(from, to);
from_to_(from, to);
}
......@@ -169,7 +231,7 @@ namespace mln
from_to_dispatch(metal::true_, const F& from,
metal::false_, T& to)
{
over_load::from_to_(exact(from), to);
from_to_(exact(from), to);
}
......@@ -180,7 +242,7 @@ namespace mln
from_to_dispatch(metal::false_, const F& from,
metal::true_, T& to)
{
over_load::from_to_(from, exact(to));
from_to_(from, exact(to));
}
// Object -> Object
......@@ -197,58 +259,6 @@ namespace mln
} // end of namespace mln::convert::internal
namespace over_load
{
// Object -> Object (F not convertible towards T)
// No conversion exists!
template <typename F, typename T>
void
from_to_(const Object<F>&, Object<T>&)
{
// This particular from-to is not defined!
//
// Either this conversion is meaningless or an overload is
// missing.
mlc_abort(F)::check();
}
// Object -> Object
template <typename T>
inline
void
from_to_(const Object<T>& from, Object<T>& to)
{
exact(to) = exact(from);
}
// Exact same type.
template <typename T>
inline
void
from_to_(const T& from, T& to)
{
to = from;
}
// Default conversion.
template <typename F, typename T>
inline
void
from_to_(const F& from, T& to)
{
to = mln::value::cast<T>(from);
}
} // end of namespace mln::convert::over_load
// Facade
template <typename F, typename T>
......@@ -263,11 +273,11 @@ namespace mln
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
} // end of namespace mln
# endif // ! MLN_INCLUDE_ONLY
#endif // ! MLN_CONVERT_FROM_TO_HH
// Copyright (C) 2008, 2009, 2010, 2011 EPITA Research and Development
// Laboratory (LRDE)
// Copyright (C) 2008, 2009, 2010, 2011, 2012 EPITA Research and
// Development Laboratory (LRDE)
//
// This file is part of Olena.
//
......@@ -29,78 +29,9 @@
/// \internal \file mln/convert/from_to.hxx
// All overloaded "convert::from_to" routines have to be declared in
// the present file. It allows for *deferred* use of these routines.
# include <mln/core/def/all.hh>
# include <mln/core/grids.hh>
# include <mln/util/couple.hh>
//FIXME: have a forward declaration.
# include <vector>
# include <set>
namespace mln
{
// Forward declarations.
template <typename E> struct Accumulator;
template <typename E> struct Gdpoint;
template <typename E> struct Gpoint;
template <typename E> struct Image;
template <typename E> struct Object;
template <typename E> struct Proxy;
template <typename E> struct Site_Set;
template <typename E> struct Value;
template <typename E> struct Weighted_Window;
template <typename E> struct Window;
template <typename G, typename C> struct dpoint;
template <typename G, typename C> struct point;
template <typename D> class neighb;
template <typename D> class window;
template <typename D, typename W> struct w_window;
template <typename T> struct image1d;
namespace algebra {
template <unsigned n, typename T> class vec;
template <unsigned d, typename C> class h_vec;
}
namespace fun {
namespace i2v {
template <typename T> class array;
}
}
namespace histo {
template <typename T> struct array;
}
namespace util {
template <typename T> class array;
template <typename Tag, typename V> class object_id;
}
namespace value {
namespace qt { struct rgb32; }
template <unsigned n> struct rgb;
template <typename H, typename S, typename L> class hsl_;
template <unsigned n> struct int_u;
template <unsigned n> struct label;
}
// end of Forward declarations.
// convert::to
namespace convert
{
......@@ -108,378 +39,10 @@ namespace mln
T
to(const O& from);
} // end of namespace mln::convert
// convert::from_to
namespace convert
{
// Facade
template <typename F, typename T>
void
from_to(const F& from, T& to);
namespace over_load
{
// Guard.
template <typename F, typename T>
void
from_to_(const Object<F>&, Object<T>&);
// end of Guard.
// Object -> Object
template <typename T>
void
from_to_(const Object<T>& from, Object<T>& to);
// Object -> Object
template <typename T>
void
from_to_(const T& from, T& to);
// point -> point.
template <typename G, typename C1, typename C2>
inline
void
from_to_(const point<G,C1>& from, point<G,C2>& to);
// algebra::vec -> point
template <unsigned n, typename C1, typename G, typename C2>
void
from_to_(const algebra::vec<n,C1>& from, point<G,C2>& to);
// algebra::vec -> point
template <unsigned n, typename C1, typename G>
void
from_to_(const algebra::vec<n,C1>& from, point<G,C1>& to);
// algebra::vec -> Gpoint.
template <unsigned n, typename T, typename P>
void
from_to_(const algebra::vec<n,T>& from, Gpoint<P>& to_);
// algebra::vec -> rgb.
template <typename T, unsigned m>
void
from_to_(const algebra::vec<3,T>& from, value::rgb<m>& to);
// bool -> rgb.
template <unsigned m>