milena r3538: Clean of new function implementation

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-03-16 Frederic Bour <bour@lrde.epita.fr> Clean of new function implementation. * sandbox/fred/mln/core/concept/meta_function.hh, * sandbox/fred/mln/core/concept, * sandbox/fred/mln/core/image/thru_morpher.hh, * sandbox/fred/mln/core/image, * sandbox/fred/mln/core, * sandbox/fred/mln/fun/binary.hh, * sandbox/fred/mln/fun/compose.hh, * sandbox/fred/mln/fun/composition.hh, * sandbox/fred/mln/fun/math/abs.hh, * sandbox/fred/mln/fun/math/cos.hh, * sandbox/fred/mln/fun/math/inf.hh, * sandbox/fred/mln/fun/math/norm.hh, * sandbox/fred/mln/fun/math/sup.hh, * sandbox/fred/mln/fun/math, * sandbox/fred/mln/fun/spe/binary.hh, * sandbox/fred/mln/fun/spe/unary.hh, * sandbox/fred/mln/fun/spe, * sandbox/fred/mln/fun/unary.hh, * sandbox/fred/mln/fun, * sandbox/fred/mln/trait/fun.hh, * sandbox/fred/mln/trait/next/solve.hh, * sandbox/fred/mln/trait/next/solve_binary.hh, * sandbox/fred/mln/trait/next/solve_unary.hh, * sandbox/fred/mln/trait/next, * sandbox/fred/mln/trait, * sandbox/fred/mln: New. Clean files, respecting milena file hierarchy. * sandbox/fred/Makefile, * sandbox/fred/overload.cc, * sandbox/fred/old/site_wrapper.hh, * sandbox/fred/old/value.cc, * sandbox/fred/old/overload.cc: Old files management. * sandbox/fred/tests/Makefile, * sandbox/fred/tests/cos.cc, * sandbox/fred/tests/fun.cc, * sandbox/fred/tests/thru.cc, * sandbox/fred/tests: New. Small test for functions. --- mln/core/concept/meta_function.hh | 203 +++++++++++++++++++++++++ mln/core/image/thru_morpher.hh | 307 ++++++++++++++++++++++++++++++++++++++ mln/fun/binary.hh | 103 ++++++++++++ mln/fun/compose.hh | 100 ++++++++++++ mln/fun/composition.hh | 237 +++++++++++++++++++++++++++++ mln/fun/math/abs.hh | 69 ++++++++ mln/fun/math/cos.hh | 76 +++++++++ mln/fun/math/inf.hh | 69 ++++++++ mln/fun/math/norm.hh | 119 ++++++++++++++ mln/fun/math/sup.hh | 69 ++++++++ mln/fun/spe/binary.hh | 108 +++++++++++++ mln/fun/spe/unary.hh | 201 ++++++++++++++++++++++++ mln/fun/unary.hh | 247 ++++++++++++++++++++++++++++++ mln/trait/fun.hh | 131 ++++++++++++++++ mln/trait/next/solve.hh | 152 ++++++++++++++++++ mln/trait/next/solve_binary.hh | 302 +++++++++++++++++++++++++++++++++++++ mln/trait/next/solve_unary.hh | 171 +++++++++++++++++++++ old/overload.cc | 296 ++++++++++++++++++++++++++++++++++++ old/site_wrapper.hh | 188 +++++++++++++++++++++++ old/value.cc | 24 ++ tests/Makefile | 25 +++ tests/cos.cc | 34 ++++ tests/fun.cc | 108 +++++++++++++ tests/thru.cc | 37 ++++ 24 files changed, 3376 insertions(+) Index: trunk/milena/sandbox/fred/overload.cc (deleted) =================================================================== Index: trunk/milena/sandbox/fred/Makefile (deleted) =================================================================== Index: trunk/milena/sandbox/fred/tests/thru.cc =================================================================== --- trunk/milena/sandbox/fred/tests/thru.cc (revision 0) +++ trunk/milena/sandbox/fred/tests/thru.cc (revision 3538) @@ -0,0 +1,37 @@ +// Meta functions test +#include <mln/fun/essential.hh> +#include <mln/fun/math/cos.hh> +#include <mln/core/image/thru_morpher.hh> +#include <mln/fun/compose.hh> + +#include <mln/core/var.hh> +#include <mln/core/image/image2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/debug/all.hh> +#include <iostream> +#include <typeinfo> + +#define dbg_print(val) std::cout << #val << "\n\t -> \t" << (val) << std::endl + +int main() +{ + using namespace mln; + + fun::cos cos; + typedef image2d<float> I; + I ima(5, 5); + + image2d<value::int_u8> tmp(5, 5); + debug::iota(tmp); + data::fill_with_image(ima, tmp); + + debug::println(ima); + debug::println(thru(cos, ima)); + + thru_image<I, fun::cos::with<fun::cos>::ret::result::with<float>::ret > ima2; + ima2 = thru(cos(cos), ima); + + data::fill_with_image(ima2, (pw::value(tmp) - pw::cst(13.0f)) / pw::cst(12.0f) | tmp.domain()); + + debug::println(ima); +} \ No newline at end of file Index: trunk/milena/sandbox/fred/tests/cos.cc =================================================================== --- trunk/milena/sandbox/fred/tests/cos.cc (revision 0) +++ trunk/milena/sandbox/fred/tests/cos.cc (revision 3538) @@ -0,0 +1,34 @@ +// Meta functions test +#include <mln/fun/math/cos.hh> +#include <mln/fun/compose.hh> + +#include <iostream> + +#define dbg_print(val) std::cout << #val << "\n\t -> \t" << (val) << std::endl +int main() +{ + mln::fun::cos cos; + mln::fun::compose compose; + + double x; + dbg_print(cos(compose)(cos,cos)(x) = 0.857553); + dbg_print(x); + dbg_print(cos(compose)(cos,cos)(0.)); + + // COS + { + mln_invariant(cos(0.) == 1.); + dbg_print(cos(0.)); + dbg_print(cos(mln::math::acos(0.5))); + } + + // COS + { + double x; + dbg_print(cos(x) = 1.); + mln_invariant(cos(x) == 1.); + dbg_print(x); + } + + std::cout << "Ok." << std::endl; +} \ No newline at end of file Index: trunk/milena/sandbox/fred/tests/fun.cc =================================================================== --- trunk/milena/sandbox/fred/tests/fun.cc (revision 0) +++ trunk/milena/sandbox/fred/tests/fun.cc (revision 3538) @@ -0,0 +1,108 @@ +// Meta functions test +#include <mln/fun/math/abs.hh> +#include <mln/fun/math/cos.hh> +#include <mln/fun/math/norm.hh> +// #include <mln/fun/math/inc.hh> +// #include <mln/fun/math/red.hh> + +#include <iostream> + +#define dbg_print(val) std::cout << #val << "\n\t -> \t" << (val) << std::endl +int main() +{ + mln::fun::abs abs; + mln::fun::cos cos; +// mln::fun::inc inc; +// mln::fun::red red; + + mln::fun::norm::l1 l1; + mln::fun::norm::l2 l2; + mln::fun::norm::linfty linfty; + + std::cout << "Read only tests." << std::endl; + std::cout << "----------------" << std::endl; + + // ABS + mln_invariant(abs(-1) == 1); + dbg_print(abs(-1)); + dbg_print(abs(-3.1415926535)); + + int x = 1; +// abs(x) = 2; +// abs.set(x, 2); + +// // INC +// mln_invariant(inc(-1) == 0); +// dbg_print(inc(-1)); +// dbg_print(inc(-3.1415926535)); + + // COS + mln_invariant(cos(0.) == 1.); + dbg_print(cos(0.)); + dbg_print(cos(mln::math::acos(0.5))); + +// // RED +// mln_invariant(red(mln::value::rgb8(8,13,21)) == 8); +// dbg_print(red(mln::value::rgb8(8,13,21))); + + // NORM + mln::algebra::vec<3, double> v; + v[0] = 1; + v[1] = -1; + v[2] = 0; + dbg_print(v); + dbg_print(l1(v)); +// dbg_print(cos(l1)(v)); + dbg_print(l2(v)); + dbg_print(linfty(v)); + + std::cout << "Read/Write tests." << std::endl; + std::cout << "-----------------" << std::endl; + + // INC +// { +// int x; +// dbg_print(inc(x) = 1); +// mln_invariant(inc(x) == 1); +// dbg_print(inc(x)); +// dbg_print(x); +// } + + // COS + { + double x; + dbg_print(cos(x) = 1.); + mln_invariant(cos(x) == 1.); + dbg_print(x); + } + + // RED +// { +// mln::value::rgb8 rgb(8,13,21); +// dbg_print(rgb); +// dbg_print(red(rgb) = 0); +// // FIXME: Doesn't compile! mln_invariant(red(rgb) == 0); +// dbg_print(rgb); +// } + + // NORM + { + dbg_print(v); + dbg_print(l1(v) = 1.0); + dbg_print(l1(v)); + dbg_print(v); +// mln_invariant(l1(v) == 1.0); FIXME: check with epsilon + + dbg_print(l2(v) = 1.0); + dbg_print(l2(v)); + dbg_print(v); +// mln_invariant(l2(v) == 1.0); + + dbg_print(linfty(v) = 1.0); + dbg_print(linfty(v)); + dbg_print(v); +// mln_invariant(linfty(v) == 1.0); + } + + std::cout << "All invariants passed." << std::endl; +} Index: trunk/milena/sandbox/fred/tests/Makefile =================================================================== --- trunk/milena/sandbox/fred/tests/Makefile (revision 0) +++ trunk/milena/sandbox/fred/tests/Makefile (revision 3538) @@ -0,0 +1,25 @@ +TARGET=fun +OBJS=$(TARGET).o + +OLENADIR=../../../.. +MILENADIR=$(OLENADIR)/milena + +CXXFLAGS=-I$(MILENADIR) -I../ -DNDEBUG -O1 -ffast-math +CXX=g++ +LD=g++ +LDFLAGS= +RM=rm + +$(TARGET): $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +%.o: %.cc + $(CXX) $(CXXFLAGS) -c $< + +%.o: %.hh + $(CXX) $(CXXFLAGS) -c $< + +all: $(TARGET) + +clean: + $(RM) -f $(TARGET) *.o *~ Index: trunk/milena/sandbox/fred/mln/trait/fun.hh =================================================================== --- trunk/milena/sandbox/fred/mln/trait/fun.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/trait/fun.hh (revision 3538) @@ -0,0 +1,131 @@ +// Copyright (C) 2007, 2008 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 F 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_TRAIT_FUN_HH +# define MLN_TRAIT_FUN_HH + +# include <mln/metal/bexpr.hh> +# include <mln/metal/if.hh> + +#define mln_trait_fun_is_assignable(Fun) typename mln::trait::fun::is_assignable< Fun >::ret +#define mln_trait_fun_is_assignable_(Fun) mln::trait::fun::is_assignable< Fun >::ret +#define mln_trait_fun_is_assignable__1comma(A, B) typename mln::trait::fun::is_assignable< A, B >::ret +#define mln_trait_fun_is_assignable__1comma_(A, B) mln::trait::fun::is_assignable< A, B >::ret + +#define mln_trait_fun_is_parametrable(Fun) typename mln::trait::fun::is_parametrable< Fun >::ret +#define mln_trait_fun_is_parametrable_(Fun) mln::trait::fun::is_parametrable< Fun >::ret + +#define mln_trait_fun_lvalue(Fun) typename mln::trait::fun::get_lvalue< Fun >::ret +#define mln_trait_fun_param(Fun) typename mln::trait::fun::get_param< Fun >::ret + +namespace mln +{ + + namespace trait + { + + namespace fun + { + + namespace internal + { + + namespace introspect + { + + template <typename T> + struct except_void_t + { + typedef void ret; + }; + + template <> + struct except_void_t<void>; + + template <typename T, typename V> + struct has_lvalue_t + { + typedef metal::false_ ret; + typedef void type; + }; + + template <typename T> + struct has_lvalue_t<T, typename except_void_t<typename T::lvalue>::ret> + { + typedef metal::true_ ret; + typedef typename T::lvalue type; + }; + + template <typename T, typename V> + struct has_param_t + { + typedef metal::false_ ret; + typedef void type; + }; + + template <typename T> + struct has_param_t<T, typename except_void_t<typename T::param>::ret> + { + typedef metal::true_ ret; + typedef typename T::param type; + }; + + } // end of namespace mln::trait::fun::internal::introspect + + } // end of namespace mln::trait::fun::internal + + template <typename F> + struct is_assignable + { + typedef typename internal::introspect::has_lvalue_t<F, void>::ret ret; + }; + + template <typename F> + struct is_parametrable + { + typedef typename internal::introspect::has_param_t<F, void>::ret ret; + }; + + template <typename F> + struct get_lvalue + { + typedef typename internal::introspect::has_lvalue_t<F, void>::type ret; + }; + + template <typename F> + struct get_param + { + typedef typename internal::introspect::has_param_t<F, void>::type ret; + }; + + } // end of namespace mln::trait::fun + + } // end of namespace mln::trait + +} // end of namespace mln + +#endif // ! MLN_TRAIT_FUN_HH Index: trunk/milena/sandbox/fred/mln/trait/next/solve_unary.hh =================================================================== --- trunk/milena/sandbox/fred/mln/trait/next/solve_unary.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/trait/next/solve_unary.hh (revision 3538) @@ -0,0 +1,171 @@ +// Copyright (C) 2006, 2008 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_TRAIT_NEXT_SOLVE_UNARY_HH +# define MLN_TRAIT_NEXT_SOLVE_UNARY_HH + +/*! + * \file mln/trait/next/solve_unary.hh + * + * \brief FIXME + * + * + */ + +# include <mln/core/category.hh> +# include <mln/core/routine/exact.hh> +# include <mln/metal/equal.hh> +# include <mln/metal/if.hh> +# include <mln/metal/ret.hh> +# include <mln/trait/next/solve.hh> + + +// FIXME: Just for the record (use it...) + +# ifndef MLN_DEBUG_TRAITS +# endif // ! MLN_DEBUG_TRAITS + + + +namespace mln +{ + + namespace trait + { + + namespace next + { + + namespace internal + { + + + template < typename Name, + typename Category, + typename T > + struct trait_set_unary_; + + template < typename Name, + template <class> class Category, typename _, + typename T > + struct trait_set_unary_< Name, Category<_>, T > + { + typedef typename mln::trait::next::set_unary_<Name, Category, T>::ret ret; + }; + + + // Fwd decls. + template < typename Name, + typename Category, typename T > + struct get_unary_; + + + template < typename user_ret, /* != not_found and != undefined */ + typename Name, + typename Category, typename T > + struct helper_get_unary_ + { + typedef user_ret ret; // The user has defined 'ret' so we return it. + }; + + + template < typename Name, + typename Category, typename T > + struct helper_get_unary_< /* user_ret == */ not_found, + Name, Category, T > + { + typedef not_found ret; // End of search due to a blocker; 'ret' is not found. + }; + + + template < typename Name, + typename Category, typename T > + struct helper_get_unary_< /* user_ret == */ undefined, + Name, Category, T > + { + typedef typename mln::internal::super_category_< Category, T >::ret Super_Category; + typedef typename get_unary_<Name, Super_Category, T>::ret ret; // No user ret definition => Recursion. + }; + + + template < typename Name, + typename Category, typename T > + struct get_unary_ + { + typedef typename trait_set_unary_<Name, Category, T>::ret user_ret; // First get 'user_ret' + typedef helper_get_unary_<user_ret, Name, Category, T> helper; // Set the helper to make a decision. + typedef mlc_ret(helper) ret; // Return. + }; + + + template < typename precise_ret, + typename Name, + typename Category, typename T > + struct helper_choose_unary_wrt_ /* precise_ret != undefined */ + { + typedef precise_ret ret; // -> A precise ret has been defined so it is it. + }; + + template < typename Name, + typename Category, typename T > + struct helper_choose_unary_wrt_< /* precise_ret == */ undefined, + Name, Category, T > + { + typedef typename get_unary_<Name, Category, T>::ret ret; // -> Go up into the category inheritance + // to fetch a ret from 'set_unary_'s. + }; + + template < typename Name, + typename Category, typename T > + struct helper_solve_unary_ + { + typedef typename set_precise_unary_<Name, T>::ret precise_ret; + typedef helper_choose_unary_wrt_< precise_ret, /* undefined or not (?) */ + Name, Category, T> helper; + typedef mlc_ret(helper) ret; + }; + + } // end of namespace mln::trait::next::internal + + + template < typename Name, + typename T_ > + struct solve_unary + { + typedef mln_exact(T_) T; + typedef typename mln::category<T>::ret Category; + typedef internal::helper_solve_unary_< Name, Category, T > meta_code; + typedef typename meta_code::ret ret; + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_NEXT_SOLVE_UNARY_HH Index: trunk/milena/sandbox/fred/mln/trait/next/solve.hh =================================================================== --- trunk/milena/sandbox/fred/mln/trait/next/solve.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/trait/next/solve.hh (revision 3538) @@ -0,0 +1,152 @@ +// Copyright (C) 2006, 2008 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_TRAIT_NEXT_SOLVE_HH +# define MLN_TRAIT_NEXT_SOLVE_HH + +/*! + * \file mln/trait/next/solve.hh + * + * \brief FIXME + * + * + */ + +# include <mln/core/category.hh> +# include <mln/metal/equal.hh> +# include <mln/metal/if.hh> +# include <mln/metal/ret.hh> +# include <mln/trait/solve.hh> + + +// FIXME: Just for the record (use it...) + +# ifndef MLN_DEBUG_TRAITS +# endif // ! MLN_DEBUG_TRAITS + + +# define mln_trait_nunary(Name, T) typename mln::trait::next::solve_unary< Name, T >::ret +# define mln_trait_nunary_(Name, T) mln::trait::next::solve_unary< Name, T >::ret + +# define mln_trait_nbinary(Name, T1, T2) typename mln::trait::next::solve_binary< Name, T1, T2 >::ret +# define mln_trait_nbinary_(Name, T1, T2) mln::trait::next::solve_binary< Name, T1, T2 >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace next + { + + // Unary case. + + + template < typename Name, + typename T > + struct set_precise_unary_ + { + typedef undefined ret; + }; + + + template < typename Name, + template <class> class Category_T, typename T > + struct set_unary_ + { + typedef undefined ret; + }; + + template < typename Name, + typename T > + struct set_unary_< Name, Unknown, T > // Blocker; top of inheritance. + { + typedef not_found ret; + }; + + + + + // Binary case. + + + template < typename Name, + typename L, + typename R > + struct set_precise_binary_ + { + typedef undefined ret; + }; + + + template < typename Name, + template <class> class Category_L, typename L, + template <class> class Category_R, typename R > + struct set_binary_ + { + typedef undefined ret; + }; + + template < typename Name, + typename L, + template <class> class Category_R, typename R > + struct set_binary_< Name, Unknown, L, Category_R, R > // Left blocker. + { + typedef not_found ret; + }; + + template < typename Name, + template <class> class Category_L, typename L, + typename R > + struct set_binary_< Name, Category_L, L, Unknown, R > // Right blocker. + { + typedef not_found ret; + }; + + template < typename Name, + typename L, + typename R > + struct set_binary_< Name, Unknown, L, Unknown, R > // Blocker. + { + typedef not_found ret; + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + + +# include <mln/trait/next/solve_unary.hh> +# include <mln/trait/next/solve_binary.hh> + + +#endif // ! MLN_TRAIT_NEXT_SOLVE_HH Index: trunk/milena/sandbox/fred/mln/trait/next/solve_binary.hh =================================================================== --- trunk/milena/sandbox/fred/mln/trait/next/solve_binary.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/trait/next/solve_binary.hh (revision 3538) @@ -0,0 +1,302 @@ +// Copyright (C) 2006, 2008, 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_TRAIT_NEXT_SOLVE_BINARY_HH +# define MLN_TRAIT_NEXT_SOLVE_BINARY_HH + +/// \file mln/trait/next/solve_binary.hh +/// +/// FIXME + +# include <mln/core/category.hh> +# include <mln/core/routine/exact.hh> +# include <mln/metal/equal.hh> +# include <mln/metal/if.hh> +# include <mln/metal/ret.hh> +# include <mln/trait/next/solve.hh> + + +// FIXME: Just for the record (use it...) + +# ifndef MLN_DEBUG_TRAITS +# endif // ! MLN_DEBUG_TRAITS + + + +namespace mln +{ + + namespace trait + { + + namespace next + { + + namespace internal + { + + + template < typename Name, + typename Category_L, typename L, + typename Category_R, typename R > + struct trait_set_binary_; + + template < typename Name, + template <class> class Category_L, typename _l, typename L, + template <class> class Category_R, typename _r, typename R > + struct trait_set_binary_< Name, + Category_L<_l>, L, + Category_R<_r>, R > + { + typedef typename mln::trait::next::set_binary_<Name, + Category_L, L, + Category_R, R>::ret ret; + }; + + + // triplet_ret_ + + template < unsigned i_L_, unsigned i_R_, typename ret_ > + struct triplet_ + { + typedef ret_ ret; + }; + + + // merge_triplets_ + + template < typename L_trp, typename R_trp > + struct merge_triplets_; + + template < unsigned L_i_L, unsigned L_i_R, typename L_ret, + unsigned R_i_L, unsigned R_i_R, typename R_ret > + struct merge_triplets_< triplet_<L_i_L, L_i_R, L_ret>, + triplet_<R_i_L, R_i_R, R_ret> > + { + typedef metal::bool_<(L_i_L <= R_i_L && L_i_R <= R_i_R)> take_L; + typedef metal::bool_<(R_i_L <= L_i_L && R_i_R <= L_i_R)> take_R; + typedef metal::or_<take_L, take_R> ok; + typedef typename metal::if_< metal::and_<ok, take_L>, + triplet_<L_i_L, L_i_R, L_ret>, + typename metal::if_< metal::and_<ok, take_R>, + triplet_<R_i_L, R_i_R, R_ret>, + triplet_<0,0, not_found> >::ret >::ret ret; + }; + + template < unsigned i_L, unsigned i_R, typename LR_ret > + struct merge_triplets_< triplet_<i_L, i_R, LR_ret>, + triplet_<i_L, i_R, LR_ret> > + { + typedef triplet_<i_L, i_R, LR_ret> ret; + }; + + + template < unsigned L_i_L, unsigned L_i_R, unsigned L_i_max, + unsigned R_i_L, unsigned R_i_R, unsigned R_i_max > + // L_i_max and R_i_max differ + struct helper_merge_triplets_same_ret_ + { + // The winning couple between L_* and R_* is the one which + // maximum index is the smallest; for instance, with: + // left branch giving L_i_L = 5 and L_i_R = 1 so L_i_max = 5 + // right branch giving L_i_L = 3 and L_i_R = 4 so R_i_max = 4 + // the right branch wins. + enum { i_L = (L_i_max < R_i_max ? L_i_L : R_i_L), + i_R = (L_i_max < R_i_max ? L_i_R : R_i_R) }; + }; + + template < unsigned L_i_L, unsigned L_i_R, unsigned i_max, + unsigned R_i_L, unsigned R_i_R > + // L_i_max is equal to R_i_max + struct helper_merge_triplets_same_ret_< L_i_L, L_i_R, i_max, + R_i_L, R_i_R, i_max > + { + // The winning couple is the one with the minimum index. + enum { L_i_min = (L_i_L < L_i_R ? L_i_L : L_i_R), + R_i_min = (R_i_L < R_i_R ? R_i_L : R_i_R), + i_L = (L_i_min < R_i_min ? L_i_L : R_i_L), + i_R = (L_i_min < R_i_min ? L_i_R : R_i_R) }; + }; + + + template < unsigned L_i_L, unsigned L_i_R, typename LR_ret, + unsigned R_i_L, unsigned R_i_R > + struct merge_triplets_< triplet_<L_i_L, L_i_R, LR_ret>, + triplet_<R_i_L, R_i_R, LR_ret> > + { + typedef helper_merge_triplets_same_ret_< L_i_L, L_i_R, (L_i_L > L_i_R ? L_i_L : L_i_R), + R_i_L, R_i_R, (R_i_L > R_i_R ? R_i_L : R_i_R) > helper; + typedef triplet_<helper::i_L, helper::i_R, LR_ret> ret; + }; + + template < unsigned L_i_L, unsigned L_i_R, typename L_ret > + struct merge_triplets_< triplet_<L_i_L, L_i_R, L_ret>, + triplet_< 0, 0, not_found> > + { + typedef triplet_<L_i_L, L_i_R, L_ret> ret; + }; + + template < unsigned R_i_L, unsigned R_i_R, typename R_ret > + struct merge_triplets_< triplet_< 0, 0, not_found>, + triplet_<R_i_L, R_i_R, R_ret> > + { + typedef triplet_<R_i_L, R_i_R, R_ret> ret; + }; + + template <> // To disambiguate. + struct merge_triplets_< triplet_<0, 0, not_found>, + triplet_<0, 0, not_found> > + { + typedef triplet_<0u,0u, not_found> ret; + }; + + + + // Fwd decl. + template < typename Name, + unsigned i_L, typename Category_L, typename L, + unsigned i_R, typename Category_R, typename R > + struct get_binary_; + + + template < typename user_ret, /* != not_found and != undefined */ + typename Name, + unsigned i_L, typename Category_L, typename L, + unsigned i_R, typename Category_R, typename R > + struct helper_get_binary_ + { + typedef triplet_< i_L, i_R, user_ret > ret; // The user has defined 'ret' so we return it. + }; + + template < typename Name, + unsigned i_L, typename Category_L, typename L, + unsigned i_R, typename Category_R, typename R > + struct helper_get_binary_< /* user_ret == */ not_found, + Name, i_L, Category_L, L, i_R, Category_R, R > + { + typedef triplet_< 0, 0, not_found > ret; // End of search due to a blocker; 'ret' is not found. + }; + + + template < typename Name, + unsigned i_L, typename Category_L, typename L, + unsigned i_R, typename Category_R, typename R > + struct helper_get_binary_< /* user_ret == */ undefined, + Name, i_L,Category_L, L, i_R,Category_R, R > + { + // No user definition for 'ret' so treillis construction in a static recursive way. + + // FIXME: We *do* need to handle this search with a priority! + // FIXME: for a result can be found in both branches... + + typedef typename mln::internal::super_category_< Category_L, L >::ret Super_Category_L; + typedef typename mln::internal::super_category_< Category_R, R >::ret Super_Category_R; + + typedef get_binary_< Name, + i_L + 1, Super_Category_L, L, + i_R, Category_R, R > L_branch; + typedef mlc_ret(L_branch) L_trp; + + typedef get_binary_< Name, + i_L, Category_L, L, + i_R + 1, Super_Category_R, R > R_branch; + typedef mlc_ret(R_branch) R_trp; + + typedef typename merge_triplets_< L_trp, R_trp >::ret ret; + }; + + + template < typename Name, + unsigned i_L, typename Category_L, typename L, + unsigned i_R, typename Category_R, typename R > + struct get_binary_ + { + typedef typename trait_set_binary_<Name, Category_L,L, + Category_R,R>::ret user_ret; // First get 'user_ret' + typedef helper_get_binary_<user_ret, Name, i_L,Category_L,L, + i_R,Category_R,R> helper; // Set the helper to make a decision. + typedef mlc_ret(helper) ret; // Return a triplet. + }; + + + template < typename precise_ret, + typename Name, + typename Category_L, typename L, + typename Category_R, typename R > + struct helper_choose_binary_wrt_ /* precise_ret != undefined */ + { + typedef precise_ret ret; // -> A precise ret has been defined so it is it. + }; + + template < typename Name, + typename Category_L, typename L, + typename Category_R, typename R > + struct helper_choose_binary_wrt_< /* precise_ret == */ undefined, + Name, Category_L, L, Category_R, R > + { + typedef typename get_binary_< Name, + 0, Category_L, L, + 0, Category_R, R >::ret triplet; // Browse upwards the category inheritance + typedef mlc_ret(triplet) ret; // to fetch ret from 'get_binary_'s. + }; + + + template < typename Name, + typename Category_L, typename L, + typename Category_R, typename R > + struct helper_solve_binary_ + { + typedef typename set_precise_binary_<Name, L, R>::ret precise_ret; /* undefined or not (?) */ + typedef helper_choose_binary_wrt_<precise_ret, Name, Category_L,L, Category_R,R> helper; + typedef mlc_ret(helper) ret; + }; + + } // end of namespace mln::trait::internal + + + // FIXME: Postfix solve_binary with a '-'(?) + template < typename Name, + typename L_, + typename R_ > + struct solve_binary + { + typedef mln_exact(L_) L; + typedef mln_exact(R_) R; + typedef typename mln::category<L>::ret Category_L; + typedef typename mln::category<R>::ret Category_R; + typedef internal::helper_solve_binary_< Name, Category_L, L, Category_R, R > meta_code; + typedef typename meta_code::ret ret; + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_NEXT_SOLVE_BINARY_HH Index: trunk/milena/sandbox/fred/mln/core/image/thru_morpher.hh =================================================================== --- trunk/milena/sandbox/fred/mln/core/image/thru_morpher.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/core/image/thru_morpher.hh (revision 3538) @@ -0,0 +1,307 @@ +// Copyright (C) 2007, 2008 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_CORE_IMAGE_THRU_MORPHER_HH +# define MLN_CORE_IMAGE_THRU_MORPHER_HH + +# include <mln/core/internal/image_value_morpher.hh> +# include <mln/core/concept/meta_function.hh> +# include <mln/metal/bexpr.hh> +# include <mln/trait/fun.hh> + +/// +/// \file mln/core/image/thru_morpher.hh +/// +/// \brief Definition of a morpher that morph image values through a function. +/// +/// \todo Debug constness of thru_image + +namespace mln +{ + + // Forward declaration. + template <typename I, typename F> struct thru_image; + + namespace internal + { + template <typename I, typename F> struct thru_image_write; + template <typename I, typename F> struct thru_image_read; + + /// Find correct implementation + template <typename I, typename F> + struct thru_find_impl + { + typedef thru_image_write<I, F> write; + typedef thru_image_read<I, F> read; + typedef mlc_if(mlc_and(typename trait::fun::is_assignable<F>::ret, + mlc_and(mlc_not(mlc_is_const(I)), + mlc_equal(mln_trait_image_pw_io(I), + trait::image::pw_io::read_write))), + write, read) ret; + }; + + /// Data structure for \c mln::thru_image<I>. + template <typename I, typename F> + struct data< thru_image<I, F> > + { + data(I& ima, const F& f); + + I ima_; + // FIXME: value or pointer or whatever ? + F f_; + }; + + } // end of namespace mln::internal + + + namespace trait + { + + template <typename I, typename F> + struct image_< thru_image<I, F> > : image_< typename mln::internal::thru_find_impl<I, F>::ret > // Same as I except... + { + // ...these changes. + typedef trait::image::category::value_morpher category; + typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. + typedef trait::image::value_access::computed value_access; + }; + + template <typename I, typename F> + struct image_< mln::internal::thru_image_write<I, F> > : image_< I > // Same as I except... + { + typedef trait::image::vw_io::read_write vw_io; + }; + + template <typename I, typename F> + struct image_< mln::internal::thru_image_read<I, F> > : image_< I > // Same as I except... + { + typedef trait::image::vw_io::read vw_io; + }; + + } // end of namespace mln::trait + + + + // FIXME: Doc! + + namespace internal + { + + template <typename I, typename F> + class thru_image_read : public internal::image_value_morpher< I, typename F::result, thru_image<I,F> > + { + public: + + /// Skeleton. + typedef thru_image<tag::image_<I>, F> skeleton; + + /// Point_Site associated type. + typedef mln_psite(I) psite; + + /// Value associated type. + typedef typename F::result value; + + /// Return type of read-only access. + typedef typename F::result rvalue; + + rvalue operator()(const mln_psite(I)& p) const; + + }; + + // Inheritance from read ?! + template <typename I, typename F> + class thru_image_write : public thru_image_read<I,F> + { + public: + + /// Type returned by the read-write pixel value operator. +// typedef typename F::template lresult<typename F::argument>::ret lvalue; + typedef typename F::lresult lvalue; + + using thru_image_read<I,F>::operator(); + lvalue operator()(const mln_psite(I)& p); + + }; + } + + template <typename I, typename F> + class thru_image : public internal::thru_find_impl<I, F>::ret + { + public: + + thru_image(); + thru_image(I& ima); + thru_image(I& ima, const F& f); + + void init_(I& ima, const F& f); + + /// Const promotion via conversion. + operator thru_image<const I, F>() const; + }; + + template <typename I, typename F> + thru_image<I, F> thru(const mln::Function<F>& f, + Image<I>& ima); + + template <typename I, typename F> + const thru_image<const I, F> thru(const mln::Function<F>& f, + const Image<I>& ima); + + template <typename I, typename M> + thru_image<I, mln_fun_with(M, mln_value(I))> + thru(const mln::Meta_Function<M>& f, Image<I>& ima); + + template <typename I, typename M> + const thru_image<const I, mln_fun_with(M, mln_value(I))> + thru(const mln::Meta_Function<M>& f, const Image<I>& ima); + +# ifndef MLN_INCLUDE_ONLY + + // internal::data< thru_image<I,S> > + + namespace internal + { + + template <typename I, typename F> + inline + data< thru_image<I, F> >::data(I& ima, const F& f) + : ima_(ima), + f_(f) + { + } + + } // end of namespace mln::internal + + // thru_image<I> + + template <typename I, typename F> + inline + thru_image<I, F>::thru_image() + { + } + + template <typename I, typename F> + inline + thru_image<I, F>::thru_image(I& ima, const F& f) + { + mln_precondition(ima.is_valid()); + init_(ima, f); + } + + template <typename I, typename F> + inline + thru_image<I, F>::thru_image(I& ima) + { + mln_precondition(ima.is_valid()); + init_(ima, mln_value(I)()); + } + + template <typename I, typename F> + inline + void + thru_image<I, F>::init_(I& ima, const F& f) + { + mln_precondition(! this->is_valid()); + mln_precondition(ima.is_valid()); + this->data_ = new internal::data< thru_image<I, F> >(ima, f); + } + + template <typename I, typename F> + inline + thru_image<I, F>::operator thru_image<const I, F>() const + { + thru_image<const I, F> tmp(this->data_->ima_, this->data_->f_); + return tmp; + } + + namespace internal + { + + template <typename I, typename F> + inline + typename thru_image_read<I, F>::rvalue + thru_image_read<I, F>::operator()(const mln_psite(I)& p) const + { + mln_precondition(this->is_valid()); + return this->data_->f_(this->data_->ima_(p)); + } + + template <typename I, typename F> + inline + typename thru_image_write<I, F>::lvalue + thru_image_write<I, F>::operator()(const mln_psite(I)& p) + { + mln_precondition(this->is_valid()); + return this->data_->f_(this->data_->ima_(p)); + } + + } + + // thru + template <typename I, typename F> + thru_image<I, F> thru(const mln::Function<F>& f, + Image<I>& ima) + { + thru_image<I, F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename F> + thru_image<const I, F> thru(const mln::Function<F>& f, + const Image<I>& ima) + { + thru_image<const I, F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename M> + thru_image<I, mln_fun_with(M, mln_value(I))> + thru(const mln::Meta_Function<M>& f, Image<I>& ima) + { + typedef mln_fun_with(M, mln_value(I)) F; + thru_image<I, F> tmp(exact(ima), F()); + + return tmp; + } + + template <typename I, typename M> + thru_image<const I, mln_fun_with(M, mln_value(I))> + thru(const mln::Meta_Function<M>& f, const Image<I>& ima) + { + typedef mln_fun_with(M, mln_value(I)) F; + thru_image<const I, F> tmp(exact(ima), F()); + + return tmp; + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_IMAGE_THRU_MORPHER_HH Index: trunk/milena/sandbox/fred/mln/core/concept/meta_function.hh =================================================================== --- trunk/milena/sandbox/fred/mln/core/concept/meta_function.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/core/concept/meta_function.hh (revision 3538) @@ -0,0 +1,203 @@ +// Copyright (C) 2007, 2008 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 F 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_CONCEPT_META_FUNCTION_HH +# define MLN_CORE_CONCEPT_META_FUNCTION_HH + +/// \file mln/core/concept/meta_function.hh +/// +/// Definition of the concept of mln::Meta_Function. + +# include <mln/core/concept/object.hh> +# include <mln/core/concept/function.hh> + + +# define mln_fun_with(F, T) \ +typename F::template with< T >::ret + +# define mln_fun_with_(F, T) \ +F::with< T >::ret + + +# define mln_fun_result(F, T) \ +typename F::template with< T >::ret::result + + +# define mln_fun_result_(F, T) \ +F::with< T >::ret::result + + + +namespace mln +{ + + // Fwd decl. + template <typename E> struct Meta_Function; + template <typename E> struct Meta_Function_v2v; + template <typename E> struct Meta_Function_vv2v; + + // Meta_Function category flag type. + template <> + struct Meta_Function<void> + { + typedef Object<void> super; + }; + + + /*! \brief Base class for implementation of meta functions. + * + * The parameter \a E is the exact type. + * + * \see mln::doc::Meta_Function for a complete documentation of + * this class contents. + */ + template <typename E> + struct Meta_Function : public Object<E> + { + typedef Meta_Function<void> category; + protected: + Meta_Function(); + }; + + /*----------------------. + | Unary meta function. | + `----------------------*/ + + template <> + struct Meta_Function_v2v<void> { typedef Meta_Function<void> super; }; + + /// Base class for implementation of function-objects from + /// value to value. + /// + /// The parameter \a E is the exact type. + /// + template <typename E> + struct Meta_Function_v2v : public Meta_Function<E> + { + typedef Meta_Function_v2v<void> category; + + protected: + Meta_Function_v2v(); + Meta_Function_v2v(const Meta_Function_v2v&); + }; + + /*-----------------------. + | Binary meta function. | + `-----------------------*/ + + template <> + struct Meta_Function_vv2v<void> { typedef Meta_Function<void> super; }; + + /// Base class for implementation of function-objects from + /// value to value. + /// + /// The parameter \a E is the exact type. + /// + template <typename E> + struct Meta_Function_vv2v : public Meta_Function<E> + { + typedef Meta_Function_vv2v<void> category; + + protected: + Meta_Function_vv2v(); + Meta_Function_vv2v(const Meta_Function_vv2v&); + }; + + namespace fun + { + + // To be specialized when some state (attributes) have to be transfered + // from the meta-function to the function. + // Warning: the first argument has to be an object with the exact type. + template <typename M, typename T> + mln_fun_with(M, T) + unmeta(const M&, T); + + template <typename M, typename T> + void + unmeta(const Meta_Function<M>&, T); // Safety. + + } // end of namespace mln::fun + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename E> + inline + Meta_Function<E>::Meta_Function() + { + // FIXME: Check "with" on E. + } + + template <typename E> + inline + Meta_Function_v2v<E>::Meta_Function_v2v() + { + } + + template <typename E> + inline + Meta_Function_v2v<E>::Meta_Function_v2v(const Meta_Function_v2v<E>& rhs) + : Meta_Function<E>(rhs) + { + } + + template <typename E> + inline + Meta_Function_vv2v<E>::Meta_Function_vv2v() + { + } + + template <typename E> + inline + Meta_Function_vv2v<E>::Meta_Function_vv2v(const Meta_Function_vv2v<E>& rhs) + : Meta_Function<E>(rhs) + { + } + + namespace fun + { + + template <typename M, typename T> + inline + mln_fun_with(M, T) + unmeta(const M&, T) + { + mlc_is_a(M, Meta_Function)::check(); + mln_fun_with(M, T) a; + return a; + } + + } // end of namespace mln::fun + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_CONCEPT_META_FUNCTION_HH Index: trunk/milena/sandbox/fred/mln/fun/composition.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/composition.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/composition.hh (revision 3538) @@ -0,0 +1,237 @@ +// Copyright (C) 2007, 2008 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 F 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_COMPOSITION_HH +# define MLN_FUN_COMPOSITION_HH + +# include <mln/fun/unary.hh> +# include <mln/fun/binary.hh> + +namespace mln +{ + // Composition + namespace fun + { + + namespace internal + { + + // Compositions may take this has initialization parameter + template <typename F, typename G> + struct composition_param + { + composition_param(const F& f, const G& g) : f_(f), g_(g) {} + composition_param() {} + + F f_; + G g_; + }; + + // Composition types... + template <template <class> class CatF, typename F, + template <class> class CatG, typename G> + struct composition; + + // Meta + template <typename F, typename G> + struct composition<mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G> + : mln::fun::unary_param< composition<mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G>, composition_param<F, G> > + { + typedef mln::fun::unary_param< composition<mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G>, composition_param<F, G> > super; + + composition() {}; + composition(const typename super::param& p) : super(p) {}; + + typedef composition exact_type; + }; + + template <typename F, typename G> + struct composition<mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G> + : mln::fun::binary_param< composition<mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G>, composition_param<F, G> > + { + typedef mln::fun::binary_param< composition<mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G>, composition_param<F, G> > super; + + composition() {}; + composition(const typename super::param& p) : super(p) {}; + + typedef composition exact_type; + }; + + // Concrete + template <typename F, typename G> + struct composition<mln::Meta_Function_v2v, F, mln::Function_v2v, G> + { + typedef mln::fun::spe::unary< composition<mln::Meta_Function_v2v, F, mln::Function_vv2v, G>, typename G::argument> exact_type; + }; + + template <typename F, typename G> + struct composition<mln::Meta_Function_v2v, F, mln::Function_vv2v, G> + { + typedef mln::fun::spe::binary< composition<mln::Meta_Function_v2v, F, mln::Function_vv2v, G>, + typename G::argument1, typename G::argument2> exact_type; + }; + + // Unary compositions implementation inherit from composition_unary_impl... + template <bool has_lvalue, typename F, typename F_spe, typename G, typename G_spe> + struct composition_unary_impl_helper; + + template <typename F, typename F_spe, typename G, typename G_spe> + struct composition_unary_impl_helper<false, F, F_spe, G, G_spe> + { + typedef typename G_spe::argument argument; + typedef typename F_spe::result result; + typedef composition_param<F, G> param; + + composition_unary_impl_helper() {} + composition_unary_impl_helper(const param& p) : f_(p.f_), g_(p.g_) {} + + void init(const param& p) + { + f_ = p.f_; + g_ = p.g_; + } + + result read(const argument& x) const + { + return this->f_(this->g_(x)); + } + + protected: + F f_; + G g_; + }; + + template <typename F, typename F_spe, typename G, typename G_spe> + struct composition_unary_impl_helper<true, F, F_spe, G, G_spe> + : composition_unary_impl_helper<false, F, F_spe, G, G_spe> + { + typedef composition_unary_impl_helper<false, F, F_spe, G, G_spe> super; + typedef typename G_spe::lvalue lvalue; + + composition_unary_impl_helper() {} + composition_unary_impl_helper(const typename super::param& p) : super(p) {} + + void write(lvalue l, const typename super::result& x) const + { + typename G_spe::result r(this->g_(l)); + + this->f_.set(r, x); + this->g_.set(l, r); + } + }; + + template <typename F, typename F_spe, typename G, typename G_spe> + struct composition_unary_impl + : composition_unary_impl_helper<mln_trait_fun_is_assignable_(G_spe)::value, F, F_spe, G, G_spe> + { + typedef composition_unary_impl_helper<mln_trait_fun_is_assignable_(G_spe)::value, F, F_spe, G, G_spe> super; + + composition_unary_impl() {} + composition_unary_impl(const typename super::param& p) : super(p) {} + }; + + // Binary compositions implementation inherit from composition_binary_inherit... + template <typename F, typename F_spe, typename G, typename G_spe> + struct composition_binary_impl + { + typedef typename G_spe::argument1 argument1; + typedef typename G_spe::argument2 argument2; + typedef typename F_spe::result result; + typedef composition_param<F, G> param; + + composition_binary_impl() {} + composition_binary_impl(const param& p) : f_(p.f_), g_(p.g_) {} + + void init(const param& p) + { + f_ = p.f_; + g_ = p.g_; + } + + result read(const argument1& a, const argument2& b) const + { + return this->f_(this->g_(a, b)); + } + + protected: + F f_; + G g_; + }; + + } // end of namespace mln::fun::internal + + } // end of namespace mln::fun + + namespace trait + { + + namespace next + { + + template <typename F, typename G, typename T> + struct set_precise_unary_<mln::fun::internal::composition<mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G>, T> + { + typedef typename G::template with<T>::ret G_fun; + typedef typename F::template with<typename G_fun::result>::ret F_fun; + + typedef mln::fun::internal::composition_unary_impl<F, F_fun, G, G_fun> ret; + }; + + template <typename F, typename G, typename T1, typename T2> + struct set_precise_binary_<mln::fun::internal::composition<mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G>, T1, T2> + { + typedef typename G::template with<T1, T2>::ret G_fun; + typedef typename F::template with<typename G_fun::result>::ret F_fun; + + typedef mln::fun::internal::composition_binary_impl<F, F_fun, G, G_fun> ret; + }; + + template <typename F, typename G> + struct set_precise_unary_<mln::fun::internal::composition<mln::Meta_Function_v2v, F, mln::Function_v2v, G>, + typename G::argument> + { + typedef typename F::template with<typename G::result>::ret F_fun; + + typedef mln::fun::internal::composition_unary_impl<F, F_fun, G, G> ret; + }; + + template <typename F, typename G> + struct set_precise_binary_<mln::fun::internal::composition<mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G>, + typename G::argument1, typename G::argument2> + { + typedef typename F::template with<typename G::result>::ret F_fun; + + typedef mln::fun::internal::composition_binary_impl<F, F_fun, G, G> ret; + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + +#endif /* ! MLN_FUN_COMPOSITION_HH */ Index: trunk/milena/sandbox/fred/mln/fun/binary.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/binary.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/binary.hh (revision 3538) @@ -0,0 +1,103 @@ +// Copyright (C) 2007, 2008 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 F 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_BINARY_HH +# define MLN_FUN_BINARY_HH + +# include <mln/core/concept/meta_function.hh> +# include <mln/fun/spe/binary.hh> +# include <mln/trait/next/solve.hh> +# include <mln/trait/fun.hh> + +namespace mln +{ + + namespace fun + { + + template <typename F> + struct binary : mln::Meta_Function_vv2v< binary<F> > + { + + template <typename T1, typename T2> + struct with + { + typedef spe::binary<F, T1, T2> ret; + }; + + template <typename T1, typename T2> + typename with<T1, T2>::ret::result operator()(const T1& a, const T2& b) const + { + typename with<T1, T2>::ret tmp; + return tmp(a, b); + } + + }; + + template <typename F, typename P> + struct binary_param: binary<F> + { + typedef P param; + + binary_param() {}; + binary_param(const param& p) : p_(p) {}; + + void init(const param& p) + { + p_ = p; + } + + param& parameter() + { + return p_; + } + + protected: + param p_; + }; + + template <typename F> + struct binary_param<F, F>: binary<F> + { + typedef F param; + + void init(const param& p) + { + exact(*this) = p; + } + + param& parameter() + { + return exact(*this); + } + }; + + } // end of namespace mln::fun + +} // end of namespace mln + +#endif /* ! MLN_FUN_BINARY_HH */ Index: trunk/milena/sandbox/fred/mln/fun/compose.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/compose.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/compose.hh (revision 3538) @@ -0,0 +1,100 @@ +// Copyright (C) 2007, 2008 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 F 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_COMPOSE_HH +# define MLN_FUN_COMPOSE_HH + +# include <mln/fun/binary.hh> +# include <mln/fun/composition.hh> + +namespace mln +{ + // Composition + namespace fun + { + struct compose : binary<compose> {}; + + namespace internal + { + + template <template <class> class CatF, typename F, template <class> class CatG, typename G> + struct compose_helper + { + typedef F argument1; + typedef G argument2; + + typedef typename composition<CatF, F, CatG, G>::exact_type result; + typedef typename result::param param; + + static result read(const F& f, const G& g) + { + return result(param(f, g)); + } + }; + + } // end of namespace mln::fun::internal + + } // end of namespace mln::fun + + namespace trait + { + + namespace next + { + + // All kinds of supported compositions (meta : unary) with (meta or not : unary or binary) + template <typename F, typename G> + struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G> + { + typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G> ret; + }; + + template <typename F, typename G> + struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G> + { + typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G> ret; + }; + + template <typename F, typename G> + struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Function_v2v, G> + { + typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Function_v2v, G> ret; + }; + + template <typename F, typename G> + struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Function_vv2v, G> + { + typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Function_vv2v, G> ret; + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + +#endif /* ! MLN_FUN_COMPOSE_HH */ Index: trunk/milena/sandbox/fred/mln/fun/spe/binary.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/spe/binary.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/spe/binary.hh (revision 3538) @@ -0,0 +1,108 @@ +// Copyright (C) 2007, 2008 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 F 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_SPE_BINARY_HH +# define MLN_FUN_SPE_BINARY_HH + +# include <mln/core/concept/function.hh> +# include <mln/trait/next/solve.hh> +# include <mln/trait/fun.hh> + +/// \todo Implements parameter support + +namespace mln +{ + + namespace fun + { + + namespace spe + { + + // Forward declaration + template <typename Fun, typename T1, typename T2> + struct binary; + + namespace impl + { + + template <typename Fun, typename T1, typename T2> + struct binary_impl : mln::Function_v2v< binary<Fun, T1, T2> > + { + typedef mln_trait_nbinary(Fun, T1, T2) impl; + + typedef typename impl::argument1 argument1; + typedef typename impl::argument2 argument2; + typedef typename impl::result result; + + binary_impl() + : impl_() + { + } + + binary_impl(const impl& f) + : impl_(f) + { + } + + result operator () (const argument1& a, const argument2& b) const + { + return this->impl_.read(a, b); + } + + protected: + impl impl_; + }; + + } // end of namespace mln::fun::spe::impl + + template <typename Fun, typename T1, typename T2> + struct binary + : impl::binary_impl<Fun, T1, T2> + { + typedef impl::binary_impl<Fun, T1, T2> super; + + binary() + : super() + { + } + + binary(const typename super::impl& f) + : super(f) + { + } + + using super::operator(); + }; + + } // end of namespace mln::fun::spe + + } // end of namespace mln::fun + +} // end of namespace mln + +#endif /* ! MLN_FUN_SPE_BINARY_HH */ Index: trunk/milena/sandbox/fred/mln/fun/spe/unary.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/spe/unary.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/spe/unary.hh (revision 3538) @@ -0,0 +1,201 @@ +// Copyright (C) 2007, 2008 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 F 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_SPE_UNARY_HH +# define MLN_FUN_SPE_UNARY_HH + +# include <mln/core/concept/function.hh> +# include <mln/trait/next/solve.hh> +# include <mln/trait/fun.hh> + +namespace mln +{ + + namespace fun + { + + namespace spe + { + + namespace internal + { + + template <typename Impl> + struct unary_modifier + { + typedef typename Impl::result result; + typedef typename Impl::argument argument; + typedef typename Impl::lvalue lvalue; + typedef unary_modifier lresult; + + // FIXME: "argument& x" or "lvalue x" directly? ~~~ + unary_modifier(const Impl& impl, argument& x) + : x_(&x), impl_(&impl) + { + } + + result to_result() const + { + return impl_->read(*x_); + }; + + operator result() const + { + return to_result(); + }; + + const result& operator = (const result& r) const + { + impl_->write(*x_, r); + return r; + } + + private: + argument *x_; + const Impl *impl_; + }; + + } // end of namespace mln::fun::internal + + // Forward declaration (defined in mln/fun/unary.hh) + template <typename Fun, typename T> + struct unary; + + namespace impl + { + + template <bool set, typename Fun, typename T> + struct unary_impl_set; + + template <typename Fun, typename T> + struct unary_impl_set<false, Fun, T> : mln::Function_v2v< unary<Fun, T> > + { + typedef mln_trait_nunary(Fun, T) impl; + + typedef typename impl::argument argument; + typedef typename impl::result result; + typedef mln_trait_fun_param(impl) param_; + typedef mlc_if(mlc_equal(param_, void), impl, param_) init_param; + + unary_impl_set() {} + + unary_impl_set(const init_param& p) : impl_(p) {} + + result operator () (const argument& value) const + { + return this->impl_.read(value); + } + + protected: + impl impl_; + }; + + template <typename Fun, typename T> + struct unary_impl_set<true, Fun, T> : unary_impl_set<false, Fun, T> + { + typedef unary_impl_set<false, Fun, T> super; + typedef typename super::impl impl; + + typedef typename impl::argument argument; + typedef typename impl::result result; + typedef typename impl::lvalue lvalue; + typedef mln::fun::spe::internal::unary_modifier<impl> lresult; + + unary_impl_set() {} + unary_impl_set(const typename super::init_param& p) : super(p) {} + + void set(lvalue l, const result& r) const + { + this->impl_.write(l, r); + } + + lresult operator () (argument& value) const + { + return lresult(this->impl_, value); + } + + using super::operator(); + }; + + template <bool set, typename Fun, typename T> + struct unary_impl_param; + + template <typename Fun, typename T> + struct unary_impl_param<false, Fun, T> + : impl::unary_impl_set<mln_trait_fun_is_assignable_(mln_trait_nunary(Fun, T))::value, Fun, T> + { + typedef impl::unary_impl_set<mln_trait_fun_is_assignable_(mln_trait_nunary(Fun, T))::value, Fun, T> super; + + unary_impl_param() {} + unary_impl_param(const typename super::init_param& p) : super(p) {} + }; + + template <typename Fun, typename T> + struct unary_impl_param<true, Fun, T> + : unary_impl_param<false, Fun, T> + { + typedef unary_impl_param<false, Fun, T> super; + + unary_impl_param() {} + unary_impl_param(const typename super::init_param& p) : super(p) {} + + typedef typename super::param_ param; + + void init(const param& p) + { + this->impl_.init(p); + } + }; + + } // end of namespace mln::fun::spe::impl + + template <typename Fun, typename T> + struct unary + : impl::unary_impl_param<mln_trait_fun_is_parametrable_(mln_trait_nunary(Fun, T))::value, Fun, T> + { + typedef impl::unary_impl_param<mln_trait_fun_is_parametrable_(mln_trait_nunary(Fun, T))::value, Fun, T> + super; + + unary() {} + unary(const typename super::init_param& p) : super(p) {} + + using super::operator(); + }; + + } // end of namespace mln::fun::spe + + } // end of namespace mln::fun + + template <typename Impl> + std::ostream& operator << (std::ostream& o, const mln::fun::spe::internal::unary_modifier<Impl>& m) + { + return o << m.to_result(); + } + +} // end of namespace mln + +#endif /* ! UNARY_HH */ Index: trunk/milena/sandbox/fred/mln/fun/math/cos.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/math/cos.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/math/cos.hh (revision 3538) @@ -0,0 +1,76 @@ +// Copyright (C) 2007, 2008 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 F 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_MATH_COS_HH +# define MLN_FUN_MATH_COS_HH + +# include <mln/fun/unary.hh> +# include <mln/value/builtin/floatings.hh> +# include <mln/math/acos.hh> +# include <mln/math/cos.hh> + +namespace mln +{ + + // Cosinus, bijective + namespace fun + { + struct cos : unary<cos> {}; + } + + namespace trait + { + + namespace next + { + + template <typename T> + struct set_unary_<mln::fun::cos, mln::value::Floating, T> + { + typedef set_unary_ ret; + typedef T result; + typedef T argument; + typedef T& lvalue; + + static result read(const argument& x) + { + return math::cos(x); + } + + static void write(lvalue l, const result& x) + { + l = math::acos(x); + } + }; + + } + + } + +} + +#endif /* ! MLN_FUN_MATH_COS_HH */ \ No newline at end of file Index: trunk/milena/sandbox/fred/mln/fun/math/abs.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/math/abs.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/math/abs.hh (revision 3538) @@ -0,0 +1,69 @@ +// Copyright (C) 2007, 2008 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 F 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_MATH_ABS_HH +# define MLN_FUN_MATH_ABS_HH + +# include <mln/fun/unary.hh> +# include <mln/value/concept/scalar.hh> +# include <mln/math/abs.hh> + +namespace mln +{ + + // Absolute value, pure + namespace fun + { + struct abs : unary<abs> {}; + } + + namespace trait + { + + namespace next + { + + template <typename T> + struct set_unary_<mln::fun::abs, mln::value::Scalar, T> + { + typedef set_unary_ ret; + typedef T result; + typedef T argument; + + static result read(const argument& x) + { + return math::abs(x); + } + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + +#endif /* ! MLN_FUN_MATH_ABS_HH */ \ No newline at end of file Index: trunk/milena/sandbox/fred/mln/fun/math/sup.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/math/sup.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/math/sup.hh (revision 3538) @@ -0,0 +1,69 @@ +// Copyright (C) 2007, 2008 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 F 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_MATH_SUP_HH +# define MLN_FUN_MATH_SUP_HH + +# include <mln/fun/binary.hh> +# include <mln/math/max.hh> + +namespace mln +{ + + // Cosinus, bijective + namespace fun + { + struct sup : binary<sup> {}; + } + + namespace trait + { + + namespace next + { + + template <typename T, typename T> + struct set_binary_<mln::fun::inf, mln::Object, T, mln::Object, T> + { + typedef set_binary_ ret; + typedef T result; + typedef T argument1; + typedef T argument2; + + static result read(const argument1& a, const argument1& b) + { + return math::max(a, b); + } + }; + + } + + } + +} + +#endif /* ! MLN_FUN_MATH_SUP_HH */ \ No newline at end of file Index: trunk/milena/sandbox/fred/mln/fun/math/norm.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/math/norm.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/math/norm.hh (revision 3538) @@ -0,0 +1,119 @@ +// Copyright (C) 2007, 2008 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 F 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_MATH_NORM_HH +# define MLN_FUN_MATH_NORM_HH + +# include <mln/fun/unary.hh> +# include <mln/norm/all.hh> + +namespace mln +{ + + // Common norm functions, reversible + namespace fun + { + namespace norm + { + struct l1 : unary<l1> {}; + + struct l2 : unary<l2> {}; + + struct linfty : unary<linfty> {}; + } + } + + namespace trait + { + + namespace next + { + + template <unsigned n, typename T> + struct set_precise_unary_<mln::fun::norm::l1, mln::algebra::vec<n, T> > + { + typedef set_precise_unary_ ret; + typedef mln::algebra::vec<n, T> argument; + typedef argument& lvalue; + typedef mln_sum_product(argument,argument) result; + + static result read(const argument& x) + { + return mln::norm::l1(x); + } + + static void write(lvalue l, const result& x) + { + l = l / read(l) * x; + } + }; + + template <unsigned n, typename T> + struct set_precise_unary_<mln::fun::norm::l2, mln::algebra::vec<n, T> > + { + typedef set_precise_unary_ ret; + typedef mln::algebra::vec<n, T> argument; + typedef argument& lvalue; + typedef mln_sum_product(argument,argument) result; + + static result read(const argument& x) + { + return mln::norm::l2(x); + } + + static void write(lvalue l, const result& x) + { + l = l / read(l) * x; + } + }; + + template <unsigned n, typename T> + struct set_precise_unary_<mln::fun::norm::linfty, mln::algebra::vec<n, T> > + { + typedef set_precise_unary_ ret; + typedef mln::algebra::vec<n, T> argument; + typedef argument& lvalue; + typedef mln_sum_product(argument,argument) result; + + static result read(const argument& x) + { + return mln::norm::linfty(x); + } + + static void write(lvalue l, const result& x) + { + l = l / read(l) * x; + } + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + +#endif /* ! NORM_HH */ \ No newline at end of file Index: trunk/milena/sandbox/fred/mln/fun/math/inf.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/math/inf.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/math/inf.hh (revision 3538) @@ -0,0 +1,69 @@ +// Copyright (C) 2007, 2008 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 F 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_MATH_INF_HH +# define MLN_FUN_MATH_INF_HH + +# include <mln/fun/binary.hh> +# include <mln/math/min.hh> + +namespace mln +{ + + // Cosinus, bijective + namespace fun + { + struct inf : binary<inf> {}; + } + + namespace trait + { + + namespace next + { + + template <typename T, typename T> + struct set_binary_<mln::fun::inf, mln::Object, T, mln::Object, T> + { + typedef set_binary_ ret; + typedef T result; + typedef T argument1; + typedef T argument2; + + static result read(const argument1& a, const argument1& b) + { + return math::min(a, b); + } + }; + + } + + } + +} + +#endif /* ! MLN_FUN_MATH_INF_HH */ \ No newline at end of file Index: trunk/milena/sandbox/fred/mln/fun/unary.hh =================================================================== --- trunk/milena/sandbox/fred/mln/fun/unary.hh (revision 0) +++ trunk/milena/sandbox/fred/mln/fun/unary.hh (revision 3538) @@ -0,0 +1,247 @@ +// Copyright (C) 2007, 2008 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 F 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_UNARY_HH +# define MLN_FUN_UNARY_HH + +# include <mln/core/concept/meta_function.hh> +# include <mln/fun/spe/unary.hh> +# include <mln/trait/next/solve.hh> + +namespace mln +{ + + namespace fun + { + + // Forward declarations, for composition with unary::operator()(Fun) + struct compose; + + template <typename F> + struct unary; + + namespace internal + { + + template <typename T> + struct unary_with {}; + + template <bool has_param, typename M, typename T> + struct unary_with_param_helper; + + template <typename M, typename T> + struct unary_with_param_helper<false, M, T> + { + typedef mln::fun::spe::unary<M, T> function; + + static function inst(const M&) + { + return function(); + }; + + }; + + template <typename M, typename T> + struct unary_with_param_helper<true, M, T> + { + typedef mln::fun::spe::unary<M, T> function; + + static function inst(const M& m) + { + return function(m.parameter()); + }; + + }; + + template <bool has_lvalue, typename M, typename T> + struct unary_with_lvalue_helper; + + template <typename M, typename T> + struct unary_with_lvalue_helper<false, M, T> + : unary_with_param_helper<mln_trait_fun_is_parametrable_(M)::value, M, T> + { + typedef unary_with_param_helper<mln_trait_fun_is_parametrable_(M)::value, M, T> super; + typedef typename super::function function; + + static typename function::result call(const M& m, const T& x) + { + function f(super::inst(m)); + return f(x); + } + }; + + template <typename M, typename T> + struct unary_with_lvalue_helper<true, M, T> + : unary_with_lvalue_helper<false, M, T> + { + typedef unary_with_lvalue_helper<false, M, T> super; + typedef typename super::function function; + + static typename function::lresult lcall(const M& m, T& x) + { + function f(super::inst(m)); + return f(x); + } + + static void set(const M& m, typename function::lvalue v, const T& x) + { + function f(super::inst(m)); + f.set(v, x); + } + }; + + template <typename M, typename T> + struct unary_with_helper + : unary_with_lvalue_helper<mln_trait_fun_is_assignable__1comma_(mln::fun::spe::unary<M, T>)::value, M, T> + { + }; + + } // end of namespace mln::fun::internal + + template <typename F> + struct unary: mln::Meta_Function_v2v< F > + { + + template <typename T> + struct with { + typedef mln_trait_nunary(internal::unary_with<F>, T) impl; + typedef typename impl::function ret; + }; + + template <typename T> + typename with<T>::ret::result operator()(const T& v) const + { + return with<T>::impl::call(exact(*this), v); + } + + template <typename T> + typename with<T>::ret::lresult operator()(T& v) const + { + return with<T>::impl::lcall(exact(*this), v); + } + + template <typename T, typename R> + void set(T& v, const R& r) const + { + with<T>::impl::set(exact(*this), v, r); + } + + }; + + template <typename F, typename P> + struct unary_param: unary<F> + { + typedef P param; + + unary_param() {}; + unary_param(const param& p) : p_(p) {}; + + void init(const param& p) + { + p_ = p; + } + + param& parameter() + { + return p_; + } + + const param& parameter() const + { + return p_; + } + + protected: + param p_; + + }; + + template <typename F> + struct unary_param<F, F>: unary<F> + { + typedef F param; + + void init(const param& p) + { + exact(*this) = p; + } + + param& parameter() + { + return exact(*this); + } + + const param& parameter() const + { + return exact(*this); + } + + }; + + } // end of namespace mln::fun + + namespace trait + { + + namespace next + { + + // Any type + template <typename F, typename T> + struct set_unary_< mln::fun::internal::unary_with<F>, mln::Object, T> + { + typedef mln::fun::internal::unary_with_helper<F, T> ret; + }; + + // Meta Function + template <typename F, typename G> + struct set_unary_< mln::fun::internal::unary_with<F>, mln::Meta_Function, G> + { + // FIXME: Workaround for cyclic references (unary -> unary_with -> compose -> unary) + template <typename T> + struct identity + { + typedef T ret; + }; + + typedef set_unary_ ret; + typedef typename identity<mln::fun::compose>::ret::template with<F, G>::ret function; + + static typename function::result call(const F& f, const G& g) + { + function tmp; + return tmp(f, g); + } + }; + + } // end of namespace mln::trait::next + + } // end of namespace mln::trait + +} // end of namespace mln + +#endif /* ! MLN_FUN_UNARY_HH */ Index: trunk/milena/sandbox/fred/old/overload.cc =================================================================== --- trunk/milena/sandbox/fred/old/overload.cc (revision 0) +++ trunk/milena/sandbox/fred/old/overload.cc (revision 3538) @@ -0,0 +1,296 @@ +#include <mln/core/concept/function.hh> +#include <mln/core/concept/value.hh> +#include <mln/fun/internal/resolve.hh> +#include <mln/trait/op/plus.hh> + + +#define mln_result__1comma(Tleft, Tright) \ + typename Tleft, Tright ::result + + +// Avantage de cette methode: +// - la surcharge est rendue effectivement possible pour des familles de types +// et permet de passer en argument une fonction meme s'il existe de multiple definitions +// (^^ sic pour la qualite de l'explication ^^) +// - de maniere souple (set_previse_binary & set_binary). +// +// Inconvenients: +// - beaucoup de code/verbeux +// - necessite de reecrire la resolution a la main +// - l'implementation des differentes surcharge n'est pas aussi intuitive qu'en C++ +// naturel +// - passage par les categories. Impossible de tirer parti de la hierarchie +// "naturelle" des types en C++. +// + +// INF +namespace mln +{ + + // Forward declaration. + namespace fun { + namespace vv2v { + template <typename T> struct inf; + } + } + + + namespace trait + { + + // Default (whatever the category): + // "inf" performs a "min"! + template <template <class> class Category, typename T> + struct set_unary_< fun::vv2v::inf, Category, T > + { + typedef set_unary_< fun::vv2v::inf, Category, T > ret; + + static T exec(const T& t1, const T& t2) + { + return t1 < t2 ? t1 : t2; + } + + // In the case of a binary function with two different argument + // types, we shall instrument this definition with the result + // type... + }; + + } // mln::trait + + + + namespace fun + { + + namespace vv2v + { + + // fun::vv2v::inf<T> + + template <typename T> + struct inf : Function_vv2v< inf<T> > + { + typedef T result; + + typedef mln_fun_internal_resolve(inf) impl; + + T operator()(const T& t1, const T& t2) const + { + return impl::exec(t1, t2); + } + }; + + + // fun::vv2v::meta::inf + + namespace meta + { + + struct inf + { + + // A meta-fun can act as a function :-) + + template <typename T> + T operator()(const T& t1, const T& t2) const + // Here, we know the result type of vv2v::inf<T> so + // we explictly write it. + { + fun::vv2v::inf<T> f; + return f(t1, t2); + } + + // The "meta-fun -> fun" code is similar to the one in + // mln/accu/min.hh + template <typename T> + struct with + { + typedef fun::vv2v::inf<T> ret; + }; + }; + + } // mln::fun::vv2v::meta + + } // mln::fun::vv2v + + } // mln::fun + + // Yay! A special type equipped with a particular 'inf'. + + struct rgb : Value<rgb> + { + typedef rgb enc; + typedef rgb equiv; // Those couple of typedefs are required by the concept. + rgb() {} + rgb(int r, int g, int b) : r(r), g(g), b(b) {} + int r, g, b; + }; + + std::ostream& operator<<(std::ostream& ostr, const rgb& c) + { + ostr << c.r << ' ' << c.g << ' ' << c.b; + } + + namespace trait + { + + template <> + struct set_precise_unary_< fun::vv2v::inf, rgb > + { + typedef set_precise_unary_< fun::vv2v::inf, rgb > ret; + + static rgb exec(const rgb& c1, const rgb& c2) + { + // "Inf" is component-wise "min". + return rgb(c1.r < c2.r ? c1.r : c2.r, + c1.g < c2.g ? c1.g : c2.g, + c1.b < c2.b ? c1.b : c2.b); + } + }; + + } // mln::trait + +} // mln + +// PLUS +namespace mln +{ + + // Forward declaration. + namespace fun { + namespace vv2v { + template <typename L, typename R> struct plus; + } + } + + + namespace trait + { + + // Default (whatever the category): + // "plus(l, r)" performs "l + r"! + template <template <class> class Category_L, typename L, + template <class> class Category_R, typename R> + struct set_binary_< fun::vv2v::plus, + Category_L, L, + Category_R, R> + { + typedef set_binary_< fun::vv2v::plus, Category_L, L, Category_R, R> ret; + + typedef mln_trait_op_plus(L,R) result; + + static result exec(const L& t1, const R& t2) + { + return t1 + t2; + } + + // In the case of a binary function with two different argument + // types, we shall instrument this definition with the result + // type... + }; + + } // mln::trait + + + + namespace fun + { + + namespace vv2v + { + + // fun::vv2v::plus<L,R> + + template <typename L, typename R> + struct plus : Function_vv2v< plus<L,R> > + { + typedef mln_fun_internal_resolve(plus) impl; + typedef mln_result(impl) result; + + result operator()(const L& t1, const R& t2) const + { + return impl::exec(t1, t2); + } + }; + + + // fun::vv2v::meta::plus + + namespace meta + { + + struct plus + { + + // A meta-fun can act as a function :-) + + template <typename L, typename R> + mln_result__1comma(fun::vv2v::plus<L,R>) + operator()(const L& t1, const R& t2) const + // Here, we do NOT know the result type of vv2v::plus<L,R> so + // we cannot explictly write it. + { + fun::vv2v::plus<L,R> f; + return f(t1, t2); + } + + // The "meta-fun -> fun" code is similar to the one in + // mln/accu/min.hh + template <typename L, typename R> + struct with + { + typedef fun::vv2v::plus<L,R> ret; + }; + }; + + } // mln::fun::vv2v::meta + + } // mln::fun::vv2v + + } // mln::fun + + + namespace trait + { + + template <> + struct set_precise_binary_< fun::vv2v::plus, rgb, rgb > + { + typedef set_precise_binary_< fun::vv2v::plus, rgb, rgb > ret; + typedef rgb result; + + static rgb exec(const rgb& c1, const rgb& c2) + { + // "plus" is component-wise "plus". + return rgb(c1.r + c2.r, + c1.g + c2.g, + c1.b + c2.b); + } + }; + + template <> + struct set_precise_binary_< mln::trait::op::plus, rgb, rgb > + { + typedef rgb ret; + }; + + } // mln::trait + +} // mln + + +using namespace mln; + +int main() +{ + fun::vv2v::meta::inf inf; + std::cout << inf(3, 5) << std::endl; + + rgb c1(1, 2, 3), c2(2, 1, 2); + std::cout << inf(c1, c2) << std::endl; + + fun::vv2v::meta::plus plus; + std::cout << plus(plus(3.1f, 5), 3.1415926535) << std::endl; + + std::cout << plus(c1, c2) << std::endl; +} Index: trunk/milena/sandbox/fred/old/value.cc =================================================================== --- trunk/milena/sandbox/fred/old/value.cc (revision 0) +++ trunk/milena/sandbox/fred/old/value.cc (revision 3538) @@ -0,0 +1,24 @@ +#include <mln/core/image/image2d.hh> +#include <mln/opt/at.hh> +#include <mln/debug/iota.hh> +#include <mln/debug/println.hh> +#include <mln/accu/bbox.hh> +#include <mln/canvas/morpho/connected_filter.hh> +#include <mln/core/alias/neighb2d.hh> +#include "value_wrapper.hh" +#include "site_wrapper.hh" + +using namespace mln; + +int main() +{ + typedef mln::image2d<mln::point2d> I; + + I a(8, 8); + for (int i = 0; i < 8; i++) + for (int j = 0; j < 8; j++) + for (int k = 0; k < 2; k++) + opt::at(a, i, j)[k] = 20 + (k ? i : j); + + debug::println(canvas::morpho::connected_filter(a, c4(), morpho::attribute::site_wrapper< accu::bbox<mln::point2d> >(), make::box2d(8, 8), true)); +} \ No newline at end of file Index: trunk/milena/sandbox/fred/old/site_wrapper.hh =================================================================== --- trunk/milena/sandbox/fred/old/site_wrapper.hh (revision 0) +++ trunk/milena/sandbox/fred/old/site_wrapper.hh (revision 3538) @@ -0,0 +1,188 @@ +// Copyright (C) 2007, 2008, 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_MORPHO_ATTRIBUTE_SITE_WRAPPER_HH +# define MLN_MORPHO_ATTRIBUTE_SITE_WRAPPER_HH + +/// \file mln/morpho/attribute/volume.hh +/// +/// Transform an accumulator to a site (when_pix::use_p) accumulator. + +# include <mln/accu/internal/base.hh> +# include <mln/util/pix.hh> + +# define mln_morpho_attribute_use_p_(T) mln::morpho::attribute::site_wrapper< T > +# define mln_morpho_attribute_use_p(T) mln::morpho::attribute::site_wrapper< T > + +namespace mln +{ + + // Forward declaration. + namespace morpho { + namespace attribute { + template <typename T> class site_wrapper; + } + } + + + // Traits. + + namespace trait + { + + template <typename A> + struct accumulator_< morpho::attribute::site_wrapper<A> > + { + typedef accumulator::has_untake::no has_untake; + typedef accumulator::has_set_value::no has_set_site; + typedef accumulator::has_stop::no has_stop; + typedef accumulator::when_pix::use_p when_pix; + }; + + } // end of namespace mln::trait + + namespace morpho + { + + namespace attribute + { + + /// Value wrapper accumulator meta-class. + /// + /// The parameter \p A is the base accumulator to wrap. + template <typename A> + struct site_wrapper + : public mln::accu::internal::base< typename A::result , site_wrapper<A> > + { + typedef typename A::argument argument; + typedef typename A::result result; + + site_wrapper(); + + /// Manipulators. + /// \{ + void init(); + + void take(const argument& v); + template <typename I> + void take(const util::pix<I>& px); + void take(const site_wrapper<A>& other); + + void take_as_init(const argument& v); + template <typename I> + void take_as_init(const util::pix<I>& px); + /// \} + + /// Get the site of the accumulator. + result to_result() const; + + /// Check whether this accu is able to return a result. + bool is_valid() const; + + protected: + /// Delegatee accumulator. + A accu_; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A> + site_wrapper<A>::site_wrapper() + : accu_() + { + } + + template <typename A> + void + site_wrapper<A>::init() + { + accu_.init(); + } + + template <typename A> + void + site_wrapper<A>::take(const argument& v) + { + accu_.take(v); + } + + template <typename A> + template <typename I> + void + site_wrapper<A>::take(const util::pix<I>& px) + { + take(px.v()); + } + + template <typename A> + void + site_wrapper<A>::take(const site_wrapper<A>& other) + { + accu_.take(other.accu_); + } + + template <typename A> + void + site_wrapper<A>::take_as_init(const argument& v) + { + accu_.take_as_init(v); + } + + template <typename A> + template <typename I> + void + site_wrapper<A>::take_as_init(const util::pix<I>& px) + { + accu_.take_as_init(px); + } + + template <typename A> + typename site_wrapper<A>::result + site_wrapper<A>::to_result() const + { + return accu_.to_result(); + } + + template <typename A> + bool + site_wrapper<A>::is_valid() const + { + return accu_.is_valid(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::morpho::attribute + + } // end of namespace mln::morpho + +} // end of namespace mln + + +#endif // ! MLN_MORPHO_ATTRIBUTE_SITE_WRAPPER_HH
participants (1)
-
Frederic Bour