2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add oln::level::apply_inplace.
* tests/level/apply_inplace.cc: New.
* oln/level/assign.hh: Typo.
* oln/level/apply.hh (apply_inplace): New.
* oln/level/fill.hh (include): Fix.
* oln/core/traits.hh (include): Add xtd/math/ops.hh.
Index: tests/level/apply_inplace.cc
===================================================================
--- tests/level/apply_inplace.cc (revision 0)
+++ tests/level/apply_inplace.cc (revision 0)
@@ -0,0 +1,40 @@
+#include <oln/basics2d.hh>
+#include <oln/debug/print.hh>
+
+#include <oln/level/apply.hh>
+#include <oln/level/assign.hh>
+#include <oln/level/clone.hh>
+#include <oln/level/fill.hh>
+
+
+
+struct chessboard_2d : public oln::abstract::fun_p2v< chessboard_2d >
+{
+ bool operator()(const oln::point2d& p) const
+ {
+ return (p.row() + p.col()) % 2;
+ }
+};
+
+
+struct negate : public oln::abstract::fun_v2v< negate >
+{
+ bool operator()(bool b) const
+ {
+ return not b;
+ }
+};
+
+
+
+int main()
+{
+ using namespace oln;
+ image2d<bool> ima(3,3);
+
+ oln::level::fill(ima, chessboard_2d());
+ debug::print(ima);
+
+ oln::level::apply_inplace(ima, negate());
+ debug::print(ima);
+}
Index: oln/level/assign.hh
===================================================================
--- oln/level/assign.hh (revision 679)
+++ oln/level/assign.hh (working copy)
@@ -45,8 +45,7 @@
namespace level
{
- /// Fwd decls.
-
+ /// Fwd decl.
template <typename Idest, typename Isrc>
void assign(abstract::mutable_image<Idest>& dest, const
abstract::image<Isrc>& src);
Index: oln/level/apply.hh
===================================================================
--- oln/level/apply.hh (revision 679)
+++ oln/level/apply.hh (working copy)
@@ -50,7 +50,15 @@
oln_plain_value(I, typename F::result_value)
apply(const abstract::image<I>& input, const
abstract::fun_v2v<F>& fun);
+ /// Fwd decl.
+ template <typename I, typename V>
+ void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&));
+ /// Fwd decl.
+ template <typename I, typename F>
+ void apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun);
+
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
@@ -80,6 +88,27 @@
return output;
}
+
+ /// Generic version.
+ template <typename I, typename V>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
+ {
+ oln_piter(I) p(input.topo());
+ for_all(p)
+ input(p) = fun(input(p));
+ }
+
+ /// Generic version.
+ template <typename I, typename F>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
+ {
+ oln_piter(I) p(input.topo());
+ for_all(p)
+ input(p) = fun.exact()(input(p));
+ }
+
} // end of namespace oln::level::impl
@@ -99,6 +128,23 @@
return impl::apply(input, fun);
}
+
+ /// Facade.
+ template <typename I, typename V>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
+ {
+ return impl::apply_inplace(input, fun);
+ }
+
+ /// Facade.
+ template <typename I, typename F>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
+ {
+ return impl::apply_inplace(input, fun);
+ }
+
# endif
} // end of namespace oln::level
Index: oln/level/fill.hh
===================================================================
--- oln/level/fill.hh (revision 679)
+++ oln/level/fill.hh (working copy)
@@ -31,13 +31,9 @@
# include <iostream>
-# include <mlc/assert.hh>
-# include <mlc/is_a.hh>
-
# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/iterator.hh>
# include <oln/core/abstract/functions.hh>
-# include <oln/core/automatic/image/mutable_image.hh>
namespace oln
@@ -75,8 +71,7 @@
/// Fwd decl.
template <typename I, typename F>
- void fill(abstract::mutable_image<I>& input,
- const abstract::fun_p2v<F>& fun);
+ void fill(abstract::mutable_image<I>& input, const
abstract::fun_p2v<F>& fun);
# ifndef OLN_INCLUDE_ONLY
@@ -115,11 +110,9 @@
/// Generic version.
template <typename I, typename F>
- void fill(abstract::mutable_image<I>& input,
- const abstract::fun_p2v<F>& fun)
+ void fill(abstract::mutable_image<I>& input, const
abstract::fun_p2v<F>& fun)
{
oln_piter(I) p(input.topo());
- unsigned i = 0;
for_all(p)
input(p) = fun.exact()(p);
}
@@ -150,8 +143,7 @@
/// Facade.
template <typename I, typename F>
- void fill(abstract::mutable_image<I>& input,
- const abstract::fun_p2v<F>& fun)
+ void fill(abstract::mutable_image<I>& input, const
abstract::fun_p2v<F>& fun)
{
return impl::fill(input.exact(), fun);
}
Index: oln/core/traits.hh
===================================================================
--- oln/core/traits.hh (revision 678)
+++ oln/core/traits.hh (working copy)
@@ -32,6 +32,7 @@
# include <mlc/assert.hh>
# include <mlc/abort.hh>
# include <xtd/optraits.hh>
+# include <xtd/math/ops.hh>
# include <stc/exact.hh>
# include <oln/core/type.hh>