870: Add oln_plain_value, update level::apply, and provide a sample test code.
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add oln_plain_value, update level::apply, and provide a sample test code. * oln/core/internal/f_ch_value.hh (oln_plain_value): New. * oln/core/internal/image_base.hh (include): Add f_ch_value. * oln/level/apply.hh: Inactivate almost the whole code. (apply): Update a single version. * tests/core/apply.cc: New. * tests/core/Makefile.am: Update. oln/core/internal/f_ch_value.hh | 4 oln/core/internal/image_base.hh | 5 + oln/level/apply.hh | 173 ++++++++++++++++++++-------------------- tests/core/Makefile.am | 4 tests/core/apply.cc | 46 ++++++++++ 5 files changed, 146 insertions(+), 86 deletions(-) Index: tests/core/Makefile.am --- tests/core/Makefile.am (revision 869) +++ tests/core/Makefile.am (working copy) @@ -19,6 +19,7 @@ check_PROGRAMS = \ + apply \ dpoint2d \ point2d \ grid \ @@ -41,5 +42,8 @@ # Methods. at_SOURCES = at.cc +# FIXME: Temp! +apply_SOURCES = apply.cc + TESTS = $(check_PROGRAMS) Index: tests/core/apply.cc --- tests/core/apply.cc (revision 0) +++ tests/core/apply.cc (revision 0) @@ -0,0 +1,46 @@ +// 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. + +// FIXME: Move this file into tests/level/. + +#include <oln/core/2d/image2d.hh> +#include <oln/level/apply.hh> + +namespace my +{ + bool negate(bool b) + { + return not b; + } +} + +int main() +{ + using namespace oln; + image2d<bool> ima(3,3); + ima = level::apply(my::negate, ima); +} Index: oln/level/apply.hh --- oln/level/apply.hh (revision 869) +++ oln/level/apply.hh (working copy) @@ -29,9 +29,7 @@ #ifndef OLN_LEVEL_APPLY_HH # define OLN_LEVEL_APPLY_HH -# include <oln/core/abstract/image.hh> -# include <oln/core/abstract/iterator.hh> -# include <oln/core/abstract/functions.hh> +# include <oln/core/concept/image.hh> namespace oln @@ -41,22 +39,23 @@ { /// Fwd decl. - template <typename I, typename V> - oln_plain_value(I, V) - apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)); - - /// Fwd decl. - template <typename I, typename F> - 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); + template <typename R, typename A, typename I> + oln_plain_value(I, R) + apply(R (*fun)(A), const Image<I>& input); + + +// /// Fwd decl. +// template <typename I, typename F> +// 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 @@ -65,85 +64,87 @@ { /// Generic version. - template <typename I, typename V> - oln_plain_value(I, V) - apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)) - { - oln_plain_value(I, V) output(input.topo()); - oln_piter(I) p(input.topo()); - for_all(p) - output(p) = fun(input(p)); - return output; - } - /// Generic version. - template <typename I, typename F> - oln_plain_value(I, typename F::result_value) - apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun) + template <typename R, typename A, typename I> + oln_plain_value(I, R) + apply(R (*fun)(A), const Image<I>& input) { - oln_plain_value(I, typename F::result_value) output(input.topo()); - oln_piter(I) p(input.topo()); + oln_plain_value(I, R) output(input.points()); + oln_piter(I) p(input.points()); for_all(p) - output(p) = fun.exact()(input(p)); + output(p) = fun(input(p)); 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)); - } +// /// Generic version. +// template <typename I, typename F> +// oln_plain_value(I, typename F::result_value) +// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun) +// { +// oln_plain_value(I, typename F::result_value) output(input.topo()); +// oln_piter(I) p(input.topo()); +// for_all(p) +// output(p) = fun.exact()(input(p)); +// 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 /// Facade. - template <typename I, typename V> - oln_plain_value(I, V) - apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)) - { - return impl::apply(input, fun); - } - - /// Facade. - template <typename I, typename F> - oln_plain_value(I, typename F::result_value) - apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun) - { - 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); - } + template <typename R, typename A, typename I> + oln_plain_value(I, R) + apply(R (*fun)(A), const Image<I>& input) + { + return impl::apply(fun, exact(input)); + } + +// /// Facade. +// template <typename I, typename F> +// oln_plain_value(I, typename F::result_value) +// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun) +// { +// 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 Index: oln/core/internal/f_ch_value.hh --- oln/core/internal/f_ch_value.hh (revision 869) +++ oln/core/internal/f_ch_value.hh (working copy) @@ -38,6 +38,10 @@ typename oln::internal::f_ch_value_< stc_type_in(oln, I, skeleton), T >::ret +# define oln_plain_value(I, T) \ +typename oln::internal::f_ch_value_< stc_type_in(oln, oln_plain(I), skeleton), T >::ret + + namespace oln { Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 869) +++ oln/core/internal/image_base.hh (working copy) @@ -416,4 +416,9 @@ } // end of namespace oln +// FIXME: Bad! +# include <oln/core/internal/f_ch_value.hh> + + + #endif // ! OLN_CORE_INTERNAL_IMAGE_BASE_HH
participants (1)
-
Thierry Geraud