https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add proper inheritance to functions.
* mln/core/concept/doc/neighborhood.hh,
* mln/core/concept/neighborhood.hh,
* mln/core/neighb.hh (point): New.
* mln/convert/to_image.hh
(helper_dim_, helper_image_from_): New in mln::internal.
(image_from_): New in mln.
(mln_image_from): New macro.
(to_image): Fix; now generalized.
* mln/metal/all.hh: New.
* mln/metal/equal.hh: Update.
(mlc_equal): New.
* mln/metal/if.hh: New.
* mln/metal/is_a.hh: New.
* mln/metal/unptr.hh: New.
* mln/metal/unqualif.hh: New.
* mln/metal/unref.hh: New.
* mln/core/concept/function.hh (result): New in Function_p2b.
* mln/fun/internal: New directory.
* mln/pw/cst.hh: Precise inheritance.
* mln/pw/value.hh: Likewise.
(select_function_): Move to...
* mln/fun/internal/selector.hh: ...this new file.
(select_function_): Rename as...
(selector_): ...this.
* mln/fun/c.hh: New.
* mln/convert/to_fun.hh: New.
* mln/convert/to_window.hh (to_window): New overload.
* mln/estim/mean.hh (mean): New overload.
* mln/estim/sum.hh: New.
* mln/level/run.hh: Rename as...
* mln/level/compute.hh: ...this.
(run): Rename as...
(compute): ...this.
* tests/w_window2d_int.cc: Augment.
mln/convert/to_fun.hh | 77 ++++++++++++++++
mln/convert/to_image.hh | 59 ++++++++++--
mln/convert/to_window.hh | 29 ++++--
mln/core/concept/doc/neighborhood.hh | 3
mln/core/concept/function.hh | 1
mln/core/concept/neighborhood.hh | 2
mln/core/neighb.hh | 3
mln/estim/mean.hh | 28 +++++
mln/estim/sum.hh | 88 ++++++++++++++++++
mln/fun/c.hh | 85 +++++++++++++++++
mln/fun/internal/selector.hh | 168 +++++++++++++++++++++++++++++++++++
mln/level/compute.hh | 18 +--
mln/metal/all.hh | 58 ++++++++++++
mln/metal/equal.hh | 16 +--
mln/metal/if.hh | 85 +++++++++++++++++
mln/metal/is_a.hh | 88 ++++++++++++++++++
mln/metal/unptr.hh | 58 ++++++++++++
mln/metal/unqualif.hh | 58 ++++++++++++
mln/metal/unref.hh | 58 ++++++++++++
mln/pw/cst.hh | 13 +-
mln/pw/value.hh | 21 ----
tests/pw_value.cc | 1
tests/w_window2d_int.cc | 24 +++--
23 files changed, 968 insertions(+), 73 deletions(-)
Index: tests/w_window2d_int.cc
--- tests/w_window2d_int.cc (revision 1052)
+++ tests/w_window2d_int.cc (working copy)
@@ -35,23 +35,22 @@
#include <mln/convert/to_image.hh>
#include <mln/convert/to_w_window.hh>
-#include <mln/debug/println.hh>
+#include <mln/convert/to_fun.hh>
+#include <mln/estim/sum.hh>
-struct my_f : mln::Function_p2v< my_f >
-{
- typedef int result;
- int operator()(const mln::point2d& p) const
+
+int f(mln::point2d p)
{
return p.row() + p.col();
}
-};
int main()
{
using namespace mln;
+ {
int ws[] = { -1, 0, 1,
-2, 0, 2,
-1, 0, 1 };
@@ -60,7 +59,16 @@
image2d_b<int> ima = convert::to_image(w_win);
w_window2d_int w_win_2 = convert::to_w_window(ima);
mln_assertion(w_win_2 = w_win);
+ }
+
+ {
+ w_window2d_int w_win = make::w_window(win::rectangle2d(3, 5),
+ convert::to_fun(f));
+ // -3 -2 -1 0 +1
+ // -2 -1 0 +1 +2
+ // -1 0 +1 +2 +3
+ image2d_b<int> ima = convert::to_image(w_win);
+ mln_assertion(estim::sum(ima) = 0);
+ }
- w_window2d_int tmp = make::w_window(win::rectangle2d(3, 5), my_f());
- debug::println(convert::to_image(tmp));
}
Index: tests/pw_value.cc
--- tests/pw_value.cc (revision 1052)
+++ tests/pw_value.cc (working copy)
@@ -43,6 +43,5 @@
image2d_b<int> ima(3, 3);
point2d p = make::point2d(1, 1);
ima(p) = 51;
-
mln_assertion( (pw::value(ima) = pw::cst(51))(p) = true );
}
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 1052)
+++ mln/convert/to_image.hh (working copy)
@@ -45,36 +45,73 @@
# include <mln/level/fill.hh>
+# define mln_image_from(Src, Value) typename mln::image_from_< Src, Value >::ret
+
+
+
namespace mln
{
+ // FIXME: Move elsewhere.
+ namespace internal
+ {
+
+ template <typename T>
+ struct helper_dim_
+ {
+ typedef mln_point(T) P;
+ enum { value = P::dim };
+ };
+
+ template <unsigned dim, typename V> struct helper_image_from_;
+
+ template <typename V>
+ struct helper_image_from_< 2, V >
+ {
+ typedef image2d_b<V> ret;
+ };
+
+ } // end of namespace mln::internal
+
+
+ // FIXME: Doc + move elsewhere!
+ template <typename T, typename V>
+ struct image_from_
+ {
+ enum { dim = internal::helper_dim_<T>::value };
+ typedef typename internal::helper_image_from_< dim, V >::ret ret;
+ };
+
+
+
namespace convert
{
+
/// Convert a point set \p pset into a binary image.
template <typename S>
- image2d_b<bool> to_image(const Point_Set<S>& pset);
+ mln_image_from(S, bool) to_image(const Point_Set<S>& pset);
/// Convert a window \p win into a binary image.
template <typename W>
- image2d_b<bool> to_image(const Window<W>& win);
+ mln_image_from(W, bool) to_image(const Window<W>& win);
/// Convert a neighborhood \p nbh into a binary image.
template <typename N>
- image2d_b<bool> to_image(const Neighborhood<N>& nbh);
+ mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh);
/// Convert a weighted window \p w_win into an image.
template <typename W>
- image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win);
+ mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>&
w_win);
# ifndef MLN_INCLUDE_ONLY
template <typename S>
- image2d_b<bool> to_image(const Point_Set<S>& pset_)
+ mln_image_from(S, bool) to_image(const Point_Set<S>& pset_)
{
const S& pset = exact(pset_);
- image2d_b<bool> ima(pset.bbox());
+ mln_image_from(S, bool) ima(pset.bbox());
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
@@ -83,14 +120,14 @@
}
template <typename W>
- image2d_b<bool> to_image(const Window<W>& win_)
+ mln_image_from(W, bool) to_image(const Window<W>& win_)
{
const W& win = exact(win_);
mln_precondition(! win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(win);
- image2d_b<bool> ima(b);
+ mln_image_from(W, bool) ima(b);
level::fill(ima, false);
mln_qiter(W) q(win, P::zero);
for_all(q)
@@ -99,20 +136,20 @@
}
template <typename N>
- image2d_b<bool> to_image(const Neighborhood<N>& nbh)
+ mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh)
{
return to_image(convert::to_window(nbh));
}
template <typename W>
- image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win_)
+ mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>&
w_win_)
{
const W& w_win = exact(w_win_);
mln_precondition(! w_win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(w_win);
- image2d_b<mln_weight(W)> ima(b);
+ mln_image_from(W, mln_weight(W)) ima(b);
mln_qiter(W) q(w_win, P::zero);
for_all(q)
ima(q) = q.w();
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1052)
+++ mln/convert/to_window.hh (working copy)
@@ -33,9 +33,10 @@
* \brief Conversions to mln::window.
*/
-# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
namespace mln
@@ -48,9 +49,13 @@
template <typename N>
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
- /// Convert a binary image \p input into a window.
+ /// Convert a binary image \p ima into a window.
template <typename I>
- window<mln_dpoint(I)> to_window(const Image<I>& input);
+ window<mln_dpoint(I)> to_window(const Image<I>& ima);
+
+ /// Convert a point set \p pset into a window.
+ template <typename S, typename F>
+ window<mln_dpoint(S)> to_window(const Point_Set<S>& pset);
# ifndef MLN_INCLUDE_ONLY
@@ -69,21 +74,27 @@
}
template <typename I>
- window<mln_dpoint(I)> to_window(const Image<I>& input_)
+ window<mln_dpoint(I)> to_window(const Image<I>& ima_)
{
- const I& input = exact(input_);
- mln_precondition(input.has_data());
- // FIXME: Check that input is binary!
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ // FIXME: Check that ima is binary!
typedef mln_dpoint(I) D;
typedef mln_point(D) P;
window<D> win;
- mln_piter(I) p(input.domain());
+ mln_piter(I) p(ima.domain());
for_all(p)
- if (input(p))
+ if (ima(p))
win.insert(p - P::zero);
return win;
}
+ template <typename S, typename F>
+ window<mln_dpoint(S)> to_window(const Point_Set<S>& pset)
+ {
+ return to_window(pw::cst(true) | pset);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
Index: mln/convert/to_fun.hh
--- mln/convert/to_fun.hh (revision 0)
+++ mln/convert/to_fun.hh (revision 0)
@@ -0,0 +1,77 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_TO_FUN_HH
+# define MLN_CONVERT_TO_FUN_HH
+
+/*! \file mln/convert/to_fun.hh
+ *
+ * \brief Conversions towards some mln::Function.
+ */
+
+# include <mln/pw/value.hh>
+# include <mln/fun/c.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a C unary function into an mln::fun::C.
+ template <typename R, typename A>
+ fun::C<R(*)(A)> to_fun(R (*f)(A));
+
+ /// Convert an image into a function.
+ template <typename I>
+ pw::value_<I> to_fun(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename R, typename A>
+ fun::C<R(*)(A)> to_fun(R (*f_)(A))
+ {
+ fun::C<R(*)(A)> f(f_);
+ return f;
+ }
+
+ template <typename I>
+ pw::value_<I> to_fun(const Image<I>& ima)
+ {
+ return pw::value(ima);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_FUN_HH
Index: mln/estim/sum.hh
--- mln/estim/sum.hh (revision 0)
+++ mln/estim/sum.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_ESTIM_SUM_HH
+# define MLN_ESTIM_SUM_HH
+
+/*! \file mln/estim/sum.hh
+ *
+ * \brief Compute the sum pixel value.
+ */
+
+# include <mln/accu/sum.hh>
+# include <mln/level/compute.hh>
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+ /*! \brief Compute the sum value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \return The sum value.
+ */
+ template <typename I>
+ mln_sum(mln_value(I)) sum(const Image<I>& input);
+
+
+ /*! \brief Compute the sum value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] result The sum value.
+ */
+ template <typename I, typename S>
+ void sum(const Image<I>& input, S& result);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_sum(mln_value(I)) sum(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ return level::compute(input, accu::sum<mln_value(I)>()).to_value();
+ }
+
+ template <typename I, typename S>
+ void sum(const Image<I>& input, S& result)
+ {
+ mln_precondition(exact(input).has_data());
+ result = level::compute(input,
+ accu::sum<mln_value(I), S>()).to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_SUM_HH
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1052)
+++ mln/estim/mean.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/accu/mean.hh>
-# include <mln/level/run.hh>
+# include <mln/level/compute.hh>
namespace mln
@@ -46,20 +46,40 @@
/*! \brief Compute the mean value of the pixels of image \p input.
*
* \param[in] input The image.
+ * \return The mean value.
*/
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input);
+ /*! \brief Compute the mean value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] result The mean value.
+ *
+ * The free parameter \c S is the type used to compute the
+ * summation.
+ */
+ template <typename S, typename I, typename M>
+ void mean(const Image<I>& input, M& result);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input)
{
mln_precondition(exact(input).has_data());
- typedef mln_value(I) V;
- typedef mln_sum(V) S;
- return level::run(input, accu::mean<V, S>()).to_value();
+ return level::compute(input,
+ accu::mean<mln_value(I)>()).to_value();
+ }
+
+ template <typename S, typename I, typename M>
+ void mean(const Image<I>& input, M& result)
+ {
+ mln_precondition(exact(input).has_data());
+ result = level::compute(input,
+ accu::mean<mln_value(I), S, M>()).to_value();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/pw/cst.hh
--- mln/pw/cst.hh (revision 1052)
+++ mln/pw/cst.hh (working copy)
@@ -33,7 +33,7 @@
* \brief FIXME.
*/
-# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/selector.hh>
namespace mln
@@ -45,11 +45,12 @@
// FIXME: Doc!
template <typename T>
- struct cst_ : public Function_p2v< cst_<T> >
+ struct cst_
+ : fun::internal::selector_p2_<T, cst_<T> >::ret
{
typedef T result;
- cst_(T t);
+ cst_(const T& t);
template <typename P>
T operator()(const P&) const;
@@ -62,7 +63,7 @@
// FIXME: Doc!
template <typename T>
- cst_<T> cst(T t);
+ cst_<T> cst(const T& t);
# ifndef MLN_INCLUDE_ONLY
@@ -70,7 +71,7 @@
// pw::cst_<T>
template <typename T>
- cst_<T>::cst_(T t)
+ cst_<T>::cst_(const T& t)
: t_(t)
{
}
@@ -86,7 +87,7 @@
// pw::cst(t)
template <typename T>
- cst_<T> cst(T t)
+ cst_<T> cst(const T& t)
{
cst_<T> tmp(t);
return tmp;
Index: mln/pw/value.hh
--- mln/pw/value.hh (revision 1052)
+++ mln/pw/value.hh (working copy)
@@ -33,9 +33,8 @@
* \brief FIXME.
*/
-# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/selector.hh>
# include <mln/core/concept/image.hh>
-# include <mln/value/props.hh>
@@ -45,26 +44,12 @@
namespace pw
{
- // FIXME: Move!
-
- namespace internal
- {
-
- template <typename K, typename E>
- struct select_function_ : Function_p2v<E>
- {};
-
- template <typename E>
- struct select_function_< value::binary_kind, E > : Function_p2b<E>
- {};
-
- } // end of namespace mln::pw::internal
-
// FIXME: Doc!
template <typename I>
- struct value_ : public internal::select_function_< mln_value_kind(I),
value_<I> >
+ struct value_
+ : fun::internal::selector_p2_< mln_value(I), value_<I> >::ret
{
typedef mln_value(I) result;
value_(const I& ima);
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 1052)
+++ mln/core/neighb.hh (working copy)
@@ -58,6 +58,9 @@
/// Dpoint associated type.
typedef D dpoint;
+ /// Point associated type.
+ typedef mln_point(D) point;
+
/*! \brief Point_Iterator type to browse the points of a generic
* neighborhood w.r.t. the ordering of delta-points.
*/
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1052)
+++ mln/core/concept/function.hh (working copy)
@@ -99,6 +99,7 @@
template <typename E>
struct Function_p2b : public Function_p2v<E>
{
+ typedef bool result;
protected:
Function_p2b();
};
Index: mln/core/concept/neighborhood.hh
--- mln/core/concept/neighborhood.hh (revision 1052)
+++ mln/core/concept/neighborhood.hh (working copy)
@@ -52,6 +52,7 @@
typedef bkd_niter;
typedef dpoint;
+ typedef point;
*/
protected:
@@ -68,6 +69,7 @@
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
typedef mln_dpoint(E) dpoint;
+ typedef mln_point(E) point;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/neighborhood.hh
--- mln/core/concept/doc/neighborhood.hh (revision 1052)
+++ mln/core/concept/doc/neighborhood.hh (working copy)
@@ -59,6 +59,9 @@
/// Dpoint associated type.
typedef void dpoint;
+
+ /// Point associated type.
+ typedef void point;
};
} // end of namespace mln::doc
Index: mln/fun/c.hh
--- mln/fun/c.hh (revision 0)
+++ mln/fun/c.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_FUN_C_HH
+# define MLN_FUN_C_HH
+
+/*! \file mln/fun/c.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/fun/internal/selector.hh>
+# include <mln/metal/unqualif.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ template <typename F> struct C;
+
+
+ // FIXME: Doc!
+ template <typename R, typename A>
+ struct C< R (*)(A) >
+ :
+ fun::internal::selector_< R, A, C<R(*)(A)> >::ret
+ {
+ C(R (*f)(A));
+ typedef R result;
+ R operator()(const mlc_unqualif(A)& a) const;
+ protected:
+ R (*f_)(A);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename R, typename A>
+ C<R(*)(A)>::C(R (*f)(A))
+ : f_(f)
+ {
+ }
+
+ template <typename R, typename A>
+ R
+ C<R(*)(A)>::operator()(const mlc_unqualif(A)& a) const
+ {
+ return f_(a);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_P2B_C_HH
Index: mln/fun/internal/selector.hh
--- mln/fun/internal/selector.hh (revision 0)
+++ mln/fun/internal/selector.hh (revision 0)
@@ -0,0 +1,168 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_FUN_INTERNAL_SELECTOR_HH
+# define MLN_FUN_INTERNAL_SELECTOR_HH
+
+/*! \file mln/fun/internal/selector.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/core/concept/point.hh>
+# include <mln/metal/unqualif.hh>
+# include <mln/metal/if.hh>
+# include <mln/metal/is_a.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace internal
+ {
+
+ // Function_v2v
+ // |
+ // + -- Function_i2v
+ // |
+ // + -- Function_p2v
+ // |
+ // + -- Function_p2b
+ // |
+ // + -- Function_p2p
+
+ enum
+ {
+ b_,
+ i_,
+ p_,
+ v_
+ };
+
+ template <int arg, int res, typename E> struct helper_selector_;
+
+ // no b2* type => v2v type
+ template <typename E>
+ struct helper_selector_< b_, b_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, i_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, p_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, v_, E > { typedef Function_v2v<E> ret; };
+
+ // i2* => only i2v type
+ template <typename E>
+ struct helper_selector_< i_, b_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, i_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, p_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, v_, E > { typedef Function_i2v<E> ret; };
+
+ // p2*
+ template <typename E>
+ struct helper_selector_< p_, b_, E > { typedef Function_p2b<E> ret; };
+ template <typename E>
+ struct helper_selector_< p_, i_, E > { typedef Function_p2v<E> ret; };
// no p2i type => p2v
+ template <typename E>
+ struct helper_selector_< p_, p_, E > { typedef Function_p2p<E> ret; };
+ template <typename E>
+ struct helper_selector_< p_, v_, E > { typedef Function_p2v<E> ret; };
+
+ // v2* => only v2v type
+ template <typename E>
+ struct helper_selector_< v_, b_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, i_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, p_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, v_, E > { typedef Function_v2v<E> ret; };
+
+
+ // tag_
+
+ template <typename T> struct tag_;
+
+ template <>
+ struct tag_< bool >
+ {
+ enum { value = b_ };
+ };
+
+ template <>
+ struct tag_< unsigned >
+ {
+ enum { value = i_ };
+ };
+
+ template <typename T>
+ struct tag_
+ {
+ enum { value = mlc_is_a(T, Point)::to_bool
+ ? p_
+ : v_ };
+ };
+
+
+ template <typename R_, typename A_, typename E>
+ struct selector_
+ {
+ typedef mlc_unqualif(R_) R;
+ typedef mlc_unqualif(A_) A;
+ enum { arg = tag_<A>::value,
+ res = tag_<R>::value };
+ typedef typename helper_selector_<arg, res, E>::ret ret;
+ private:
+ selector_();
+ };
+
+
+ template <typename R_, typename E>
+ struct selector_p2_
+ {
+ typedef mlc_unqualif(R_) R;
+ enum { res = tag_<R>::value };
+ typedef typename helper_selector_<p_, res, E>::ret ret;
+ private:
+ selector_p2_();
+ };
+
+ } // end of namespace mln::fun::internal
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_INTERNAL_SELECTOR_HH
Index: mln/metal/unqualif.hh
--- mln/metal/unqualif.hh (revision 0)
+++ mln/metal/unqualif.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_METAL_UNQUALIF_HH
+# define MLN_METAL_UNQUALIF_HH
+
+# include <mln/metal/unconst.hh>
+# include <mln/metal/unptr.hh>
+# include <mln/metal/unref.hh>
+
+
+# define mlc_unqualif(T) typename mln::metal::unqualif< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unqualif
+ {
+ typedef mlc_unref(T) tmp1;
+ typedef mlc_unconst(tmp1) tmp2;
+ typedef mlc_unptr(tmp2) ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNQUALIF_HH
Index: mln/metal/if.hh
--- mln/metal/if.hh (revision 0)
+++ mln/metal/if.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_CORE_METAL_IF_HH
+# define MLN_CORE_METAL_IF_HH
+
+/*! \file mln/metal/if.hh
+ *
+ * \brief Definition of an "if-then-else" expression type.
+ */
+
+# include <mln/metal/bool.hh>
+
+# define mlc_if(Cond, Then, Else) typename mln::metal::if_< Cond, Then, Else
>::ret
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace internal
+ {
+
+ template <bool cond, typename Then, typename Else>
+ struct helper_if_;
+
+ template <typename Then, typename Else>
+ struct helper_if_< true, Then, Else >
+ {
+ typedef Then ret;
+ };
+
+ template <typename Then, typename Else>
+ struct helper_if_< false, Then, Else >
+ {
+ typedef Else ret;
+ };
+
+ } // end of namespace mln::metal::internal
+
+
+ /*! \brief "if-then-else" expression.
+ *
+ * FIXME: Doc!
+ */
+ template <typename Cond, typename Then, typename Else>
+ struct if_ : internal::helper_if_< Cond::value, Then, Else >
+ {
+ // ret is inherited.
+ };
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_METAL_IF_HH
Index: mln/metal/equal.hh
--- mln/metal/equal.hh (revision 1052)
+++ mln/metal/equal.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_METAL_EQUAL_HH
# define MLN_METAL_EQUAL_HH
+# include <mln/metal/bool.hh>
+
+
+# define mlc_equal(T1, T2) mln::metal::equal< T1, T2 >
+
namespace mln
{
@@ -36,15 +41,12 @@
{
template <typename T1, typename T2>
- struct equal
- {
- };
+ struct equal : false_
+ {};
template <typename T>
- struct equal< T, T >
- {
- static void check() {}
- };
+ struct equal< T, T > : true_
+ {};
} // end of namespace mln::metal
Index: mln/metal/unptr.hh
--- mln/metal/unptr.hh (revision 0)
+++ mln/metal/unptr.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_METAL_UNPTR_HH
+# define MLN_METAL_UNPTR_HH
+
+
+# define mlc_unptr(T) typename mln::metal::unptr< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unptr
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unptr< T* >
+ {
+ typedef mlc_unptr(T) ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNPTR_HH
Index: mln/metal/all.hh
--- mln/metal/all.hh (revision 0)
+++ mln/metal/all.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_METAL_ALL_HH
+# define MLN_METAL_ALL_HH
+
+/*! \file mln/metal/all.hh
+ *
+ * \brief File that includes all meta-programming tools.
+ */
+
+namespace mln
+{
+
+ /// Namespace of meta-programming tools.
+ namespace metal {}
+
+} // end of namespace mln
+
+
+# include <mln/metal/bexpr.hh> // <- bool.hh
+# include <mln/metal/equal.hh>
+# include <mln/metal/if.hh>
+# include <mln/metal/is_a.hh>
+# include <mln/metal/math.hh>
+# include <mln/metal/none.hh>
+# include <mln/metal/unqualif.hh> // <- unconst.hh, unptr.hh, unref.hh
+# include <mln/metal/vec.hh>
+
+# include <mln/metal/same_coord.hh>
+# include <mln/metal/same_point.hh>
+
+
+#endif // ! MLN_METAL_ALL_HH
Index: mln/metal/is_a.hh
--- mln/metal/is_a.hh (revision 0)
+++ mln/metal/is_a.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_CORE_METAL_IS_A_HH
+# define MLN_CORE_METAL_IS_A_HH
+
+/*! \file mln/metal/is_a.hh
+ *
+ * \brief Definition of a type that means "is_a".
+ */
+
+
+# define mlc_is_a(T, U) mln::metal::is_a< T, U >
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace internal
+ {
+
+ typedef char yes_;
+ struct no_ { char dummy[2]; };
+
+ template <typename T>
+ struct make_
+ {
+ static T* ptr();
+ };
+
+ template <typename T, template <class> class U>
+ struct helper_is_a_
+ {
+
+ template<class V>
+ static yes_ selector(U<V>*);
+ static no_ selector(...);
+ };
+
+ } // end of namespace mln::metal::internal
+
+
+
+ /*! \brief "is_a" check.
+ *
+ * FIXME: Doc!
+ */
+ template <typename T, template <class> class U>
+ struct is_a : bool_<( sizeof(
internal::helper_is_a_<T,U>::selector(internal::make_<T>::ptr()) )
+ =
+ sizeof( internal::yes_ ) )>::type
+ {};
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_METAL_IS_A_HH
Index: mln/metal/unref.hh
--- mln/metal/unref.hh (revision 0)
+++ mln/metal/unref.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// 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_METAL_UNREF_HH
+# define MLN_METAL_UNREF_HH
+
+
+# define mlc_unref(T) typename mln::metal::unref< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unref
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unref< T& >
+ {
+ typedef T ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNREF_HH
Index: mln/level/compute.hh
--- mln/level/compute.hh (revision 1052)
+++ mln/level/compute.hh (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_LEVEL_RUN_HH
-# define MLN_LEVEL_RUN_HH
+#ifndef MLN_LEVEL_COMPUTE_HH
+# define MLN_LEVEL_COMPUTE_HH
-/*! \file mln/level/run.hh
+/*! \file mln/level/compute.hh
*
- * \brief Run an accumulator onto image pixel values.
+ * \brief Compute an accumulator onto image pixel values.
*/
# include <mln/level/take.hh>
@@ -42,26 +42,26 @@
namespace level
{
- /*! Run an accumulator onto the pixel values of the image \p input.
+ /*! Compute an accumulator onto the pixel values of the image \p input.
*
* \param[in] input The input image.
* \param[in] a The accumulator.
* \return A resulting accumulator.
*
- * This routine runs: \n
+ * This routine computes: \n
* res = \p a \n
* res.init() \n
* level::take(res, \p input) \n
* return res \n
*/
template <typename I, typename A>
- A run(const Image<I>& input, const Accumulator<A>& a);
+ A compute(const Image<I>& input, const Accumulator<A>& a);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename A>
- A run(const Image<I>& input, const Accumulator<A>& a)
+ A compute(const Image<I>& input, const Accumulator<A>& a)
{
A res = exact(a);
res.init();
@@ -76,4 +76,4 @@
} // end of namespace mln
-#endif // ! MLN_LEVEL_RUN_HH
+#endif // ! MLN_LEVEL_COMPUTE_HH