901: Add pw_value and operators on functions.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add pw_value and operators on functions. * oln/core/concept/generator.hh, * oln/core/gen/literal.hh, * oln/core/gen/fun_ops.hh: New. * tests/core/image1d.cc, * tests/core/pw_value.cc: Update. * tests/core/Makefile.am (check_PROGRAMS): Clean. Add image1d and pw_value. * oln/level/fill.hh: Remove too restrictive const&. * oln/core/equipment.hh (result, oln_result, oln_rvalue): New. * oln/core/gen/pw_value.hh: Update. * oln/core/gen/fun.hh (fun_p2b_): New specialization for binary images. * oln/core/internal/image_base.hh (operator|): Likewise. Add a FIXME as a reminder. oln/core/concept/generator.hh | 60 +++++++ oln/core/equipment.hh | 4 oln/core/gen/fun.hh | 22 ++ oln/core/gen/fun_ops.hh | 325 ++++++++++++++++++++++++++++++++++++++++ oln/core/gen/literal.hh | 158 +++++++++++++++++++ oln/core/gen/pw_value.hh | 80 ++++----- oln/core/internal/image_base.hh | 17 ++ oln/level/fill.hh | 6 tests/core/Makefile.am | 20 +- tests/core/image1d.cc | 24 +- tests/core/pw_value.cc | 14 - 11 files changed, 653 insertions(+), 77 deletions(-) Index: tests/core/image1d.cc --- tests/core/image1d.cc (revision 900) +++ tests/core/image1d.cc (working copy) @@ -28,33 +28,33 @@ /// Test oln::image1d. #include <cassert> -// FIXME: We should not include oln/basics1d.hh, but -// oln/core/1d/image1d.hh (and oln/core/1d/neigh1d.hh ?). -#include <oln/basics1d.hh> +#include <oln/core/1d/image1d.hh> #include <oln/level/fill.hh> int main() { + using namespace oln; + // Fill a 1D image using its iterator. - oln::image1d<char> ima1(3); - oln_vtype_(oln::image1d<char>, piter) p1(ima1.topo()); + image1d<char> ima1(3); + image1d<char>::piter p1(ima1.points()); for_all(p1) ima1(p1) = 1; // Fill a 1D image using a classic loop. - oln::image1d<int> ima2(ima1.topo()); + image1d<int> ima2(ima1.points()); for (unsigned i = 0; i < 3; ++i) - ima2(oln::point1d(i)) = 2; + ima2(i) = 2; - // Fill a 1D image using the routine oln::level::fill. - oln::image1d<long> ima3(ima1.topo()); - oln::level::fill(ima3, 3); + // Fill a 1D image using the routine level::fill. + image1d<long> ima3(ima1.points()); + level::fill(ima3, 3); // Add the three images. - oln::image1d<long> sum(ima1.topo()); - oln_vtype_(oln::image1d<long>, piter) p(sum.topo()); + image1d<long> sum(ima1.points()); + image1d<long>::piter p(sum.points()); for_all(p) sum(p) = ima1(p) + ima2(p) + ima3(p); // And check the sum. Index: tests/core/pw_value.cc --- tests/core/pw_value.cc (revision 900) +++ tests/core/pw_value.cc (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -29,9 +29,9 @@ #include <cassert> -#include <oln/basics2d.hh> +#include <oln/core/2d/image2d.hh> #include <oln/core/gen/pw_value.hh> - +#include <oln/debug/iota.hh> int main() @@ -39,12 +39,12 @@ using namespace oln; point2d p(0,0); - image2d<int> ima1(3,3); - ima1(p) = 1; + image2d<double> ima1(3,3); + ima1(p) = 1.; - image2d<float> ima2(3,3); + image2d<double> ima2(3,3); ima2(p) = 2.3; - double d = ((pw_value(ima1) + 4 * pw_value(ima2)) / .2)(p); + double d = ((pw_value(ima1) + pw_value(ima2) * literal(4.)) / literal(.2))(p); assert(d > 50.9999 and d < 51.0001); } Index: tests/core/Makefile.am --- tests/core/Makefile.am (revision 900) +++ tests/core/Makefile.am (working copy) @@ -19,31 +19,35 @@ check_PROGRAMS = \ - rle_image \ - sparse_image \ apply \ + at \ dpoint2d \ - point2d \ grid \ + image1d \ image2d \ neighb2d \ npoints \ + point2d \ + pw_value \ + rle_image \ + sparse_image \ subset \ - window2d \ - at + window2d # Images and auxiliary structures. dpoint2d_SOURCES = dpoint2d.cc -point2d_SOURCES = point2d.cc grid_SOURCES = grid.cc +image1d_SOURCES = image1d.cc image2d_SOURCES = image2d.cc neighb2d_SOURCES = neighb2d.cc npoints_SOURCES = npoints.cc -subset_SOURCES = subset.cc -window2d_SOURCES = window2d.cc +point2d_SOURCES = point2d.cc +pw_value_SOURCES = pw_value.cc rle_image_SOURCES = rle_image.cc sparse_image_SOURCES = sparse_image.cc +subset_SOURCES = subset.cc +window2d_SOURCES = window2d.cc # Methods. at_SOURCES = at.cc Index: oln/level/fill.hh --- oln/level/fill.hh (revision 900) +++ oln/level/fill.hh (working copy) @@ -54,7 +54,7 @@ void fill(Mutable_Image<I>& input, const V values[]); template <typename I, typename V, typename P> - void fill(Mutable_Image<I>& input, V (*fun)(const P&)); + void fill(Mutable_Image<I>& input, V (*fun)(P)); @@ -100,7 +100,7 @@ } template <typename I, typename V, typename P> - void fill(Mutable_Image<I>& input, V (*fun)(const P&)) + void fill(Mutable_Image<I>& input, V (*fun)(P)) { oln_piter(I) p(input.points()); for_all(p) @@ -134,7 +134,7 @@ } template <typename I, typename V, typename P> - void fill(Mutable_Image<I>& input, V (*fun)(const P&)) + void fill(Mutable_Image<I>& input, V (*fun)(P)) { impl::fill(exact(input), fun); } Index: oln/core/concept/generator.hh --- oln/core/concept/generator.hh (revision 0) +++ oln/core/concept/generator.hh (revision 0) @@ -0,0 +1,60 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_CONCEPT_GENERATOR_HH +# define OLN_CORE_CONCEPT_GENERATOR_HH + +# include <oln/core/concept/function.hh> + + +namespace oln +{ + + // void -> Value. + + template <typename Exact> + struct Generator : public Function<Exact> + { + protected: + Generator(); + }; + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + Generator<Exact>::Generator() + { + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_CONCEPT_GENERATOR_HH Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 900) +++ oln/core/equipment.hh (working copy) @@ -131,10 +131,14 @@ # define oln_qiter(T) oln_typename_shortcut__(T, qiter) // r + stc_decl_associated_type( result ); stc_decl_associated_type( right ); stc_decl_associated_type( rvalue ); stc_decl_associated_type( rvaluep ); +# define oln_result(T) oln_typename_shortcut__(T, result) +# define oln_rvalue(T) oln_typename_shortcut__(T, rvalue) + // s stc_decl_associated_type( std_container ); stc_decl_associated_type( skeleton ); Index: oln/core/gen/pw_value.hh --- oln/core/gen/pw_value.hh (revision 900) +++ oln/core/gen/pw_value.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory +// Copyright (C) 2005, 2006, 2007 EPITA Research and Development +// Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,79 +29,68 @@ #ifndef OLN_CORE_GEN_PW_VALUE_HH # define OLN_CORE_GEN_PW_VALUE_HH -# include <oln/core/abstract/image.hh> -# include <xtd/abstract/meta_nary_fun.hh> -# include <xtd/math.hh> +# include <oln/core/concept/image.hh> +# include <oln/core/gen/fun_ops.hh> - -namespace xtd +namespace oln { - // Fwd decl. - template <typename I> - class pw_value_type; - - - template <typename I, typename A> - struct res_< pw_value_type<I>, A > + namespace ERROR { - typedef oln_rvalue(I) ret; - }; + template <typename I> + struct pw_value_works_on_images_not_on_; + } // end of namespace oln::ERROR template <typename I> - class pw_value_type : public xtd::abstract::meta_nary_fun_< 1, pw_value_type<I> > + class pw_value_ : public Function_p2v< pw_value_<I> >, + private mlc::assert_< mlc_is_a(I, Image), + ERROR::pw_value_works_on_images_not_on_<I> > { public: + typedef oln_point(I) argument; // FIXME: psite? + typedef oln_value(I) result; - pw_value_type(const I& ima); - - template <typename P> - oln_rvalue(I) impl_calc(const P& p) const; + pw_value_(const Point_Wise_Accessible_Image<I>& ima); + oln_value(I) operator()(const oln_point(I)& p) const; protected: - - const I ima_; + const I& ima_; }; + template <typename I> + pw_value_<I> + pw_value(const Image<I>& ima); + + # ifndef OLN_INCLUDE_ONLY template <typename I> - template <typename A> - oln_rvalue(I) - pw_value_type<I>::impl_calc(const A& a) const - { - mlc::assert_< mlc::or_< mlc_is_a(A, oln::abstract::point), - mlc_is_a(A, oln::abstract::iterator_on_points) > >::check(); - return ima_(a); + pw_value_<I>::pw_value_(const Point_Wise_Accessible_Image<I>& ima) + : ima_(exact(ima)) + { } template <typename I> - pw_value_type<I>::pw_value_type(const I& ima) - : ima_(ima) + oln_value(I) + pw_value_<I>::operator()(const oln_point(I)& p) const { + precondition(this->ima_.owns_(p)); + return this->ima_(p); } -# endif - - -} // end of namespace xtd - - -namespace oln -{ - template <typename I> - xtd::m1expr_< xtd::pw_value_type<I>, xtd::arg_<1> > - pw_value(const abstract::image<I>& ima) + pw_value_<I> + pw_value(const Point_Wise_Accessible_Image<I>& ima) { - xtd::pw_value_type<I> pwv(ima.exact()); - using xtd::_1; - return pwv(_1); // expects one argument (for instance a point) or an expression :) + pw_value_<I> tmp(ima); + return tmp; } +# endif // ! OLN_INCLUDE_ONLY + } // end of namespace oln Index: oln/core/gen/fun.hh --- oln/core/gen/fun.hh (revision 900) +++ oln/core/gen/fun.hh (working copy) @@ -30,7 +30,7 @@ # include <oln/core/internal/category_of.hh> # include <oln/core/concept/function.hh> -# include <oln/core/concept/point.hh> +# include <oln/core/concept/image.hh> # include <oln/core/concept/value.hh> @@ -116,6 +116,25 @@ F f_; }; + // Specialization. + template <typename I> + struct fun_p2b_< Binary_Image<I> > : public Function_p2b< fun_p2b_< Binary_Image<I> > > + { + typedef const oln_point(I)& argument; + typedef oln_rvalue(I) result; + + fun_p2b_(const Binary_Image<I>& ima) + : ima_(exact(ima)) + {} + + result operator()(argument arg) const + { + return this->ima_(arg); + } + + private: + I ima_; + }; @@ -164,7 +183,6 @@ } - } // end of namespace oln Index: oln/core/gen/literal.hh --- oln/core/gen/literal.hh (revision 0) +++ oln/core/gen/literal.hh (revision 0) @@ -0,0 +1,158 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_LITERAL_HH +# define OLN_CORE_GEN_LITERAL_HH + +# include <oln/core/concept/function.hh> +# include <oln/core/concept/generator.hh> +# include <oln/core/concept/point.hh> +# include <oln/core/concept/value.hh> + + + + +namespace oln +{ + + + + // ----------------------------- literal_<T> + + + template <typename T> + struct literal_ : public Generator< literal_<T> > + { + typedef T result; + + literal_(const T& val) : val_(val) {} + + const result& operator()() const + { + return this->val_; + } + + const result& value() const + { + return this->val_; + } + + private: + T val_; + }; + + + // literal + template <typename T> + literal_<T> + literal(const T& val) + { + literal_<T> tmp(val); + return tmp; + } + + + // ----------------------------- lit_p2v_<P,T> + + + // Fwd decl. + template <typename P, typename T> struct lit_p2v_; + + // Category. + namespace internal + { + template <typename P, typename T> + struct set_category_of_< lit_p2v_<P,T> > + { + typedef stc::is< Function_p2v > ret; + }; + } + + // Class. + template <typename P, typename T> + struct lit_p2v_ : public Function_p2v< lit_p2v_<P,T> > + { + typedef P argument; + typedef T result; + + lit_p2v_(const T& val) + : val_(val) + { + } + + result operator()(argument) const + { + return this->val_; + } + + private: + T val_; + }; + + + // ----------------------------- lit_p2b_<P,B> + + + // Fwd decl. + template <typename P, typename B> struct lit_p2b_; + + // Category. + namespace internal + { + template <typename P, typename B> + struct set_category_of_< lit_p2b_<P,B> > + { + typedef stc::is< Function_p2b > ret; + }; + } + + // Class. + template <typename P, typename B> + struct lit_p2b_ : public Function_p2b< lit_p2b_<P,B> > + { + typedef P argument; + typedef B result; + + lit_p2b_(const B& val) + : val_(val) + { + } + + result operator()(argument) const + { + return this->val_; + } + + private: + B val_; + }; + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_LITERAL_HH Index: oln/core/gen/fun_ops.hh --- oln/core/gen/fun_ops.hh (revision 0) +++ oln/core/gen/fun_ops.hh (revision 0) @@ -0,0 +1,325 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_FUN_OPS_HH +# define OLN_CORE_GEN_FUN_OPS_HH + +# include <oln/core/concept/function.hh> +# include <oln/core/concept/point.hh> +# include <oln/core/gen/literal.hh> + + + +# define oln_decl_p2v_cmp_(Name, Sym) \ + \ + template <typename L, typename R> struct p2v_##Name##_; \ + \ + namespace internal \ + { \ + template <typename L, typename R> \ + struct set_category_of_< p2v_##Name##_<L,R> > \ + { \ + typedef stc::is< Function_p2b > ret; \ + }; \ + } \ + \ + template <typename L, typename R> \ + struct p2v_##Name##_ : public Function_p2b< p2v_##Name##_<L,R> > \ + { \ + typedef oln_arg_of_(L) argument; \ + typedef bool result; /* FIXME: trait! */ \ + \ + p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \ + : left_(exact(left)), \ + right_(exact(right)) \ + { \ + } \ + bool operator()(argument arg) const \ + { \ + return this->left_(arg) Sym this->right_(arg); \ + } \ + private: \ + L left_; \ + R right_; \ + }; \ + \ + template <typename L, typename R> \ + p2v_##Name##_<L,R> \ + operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ + mlc::assert_equal_< oln_argument(L), oln_argument(R) >::check(); \ + p2v_##Name##_<L,R> tmp(left, right); \ + return tmp; \ + } \ + \ + template <typename L, typename R> \ + p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \ + operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + lit_p2v_<oln_argument(L), R> right_(right.value()); \ + p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \ + return tmp; \ + } \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + +# define oln_decl_p2v_arith_(Name, Sym) \ + \ + template <typename L, typename R> struct p2v_##Name##_; \ + \ + namespace internal \ + { \ + template <typename L, typename R> \ + struct set_category_of_< p2v_##Name##_<L,R> > \ + { \ + typedef stc::is< Function_p2v > ret; \ + }; \ + } \ + \ + template <typename L, typename R> \ + struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<L,R> > \ + { \ + typedef oln_arg_of_(L) argument; \ + typedef oln_res_of_(L) result; /* FIXME: trait! */ \ + \ + p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \ + : left_(exact(left)), \ + right_(exact(right)) \ + { \ + } \ + result operator()(argument arg) const \ + { \ + return this->left_(arg) Sym this->right_(arg); \ + } \ + private: \ + L left_; \ + R right_; \ + }; \ + \ + template <typename L, typename R> \ + p2v_##Name##_<L,R> \ + operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ + p2v_##Name##_<L,R> tmp(left, right); \ + return tmp; \ + } \ + \ + template <typename L, typename R> \ + p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \ + operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + lit_p2v_<oln_argument(L), R> right_(right.value()); \ + p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \ + return tmp; \ + } \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + +# define oln_decl_p2v_un_(Name, Sym) \ + \ + template <typename T> struct p2v_##Name##_; \ + \ + namespace internal \ + { \ + template <typename T> \ + struct set_category_of_< p2v_##Name##_<T> > \ + { \ + typedef stc::is< Function_p2v > ret; \ + }; \ + } \ + \ + template <typename T> \ + struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<T> > \ + { \ + typedef oln_arg_of_(T) argument; \ + typedef oln_res_of_(T) result; /* FIXME: trait! */ \ + \ + p2v_##Name##_(const Function_p2v<T>& oper) \ + : oper_(exact(oper)) \ + { \ + } \ + result operator()(argument arg) const \ + { \ + return Sym this->oper_(arg); \ + } \ + private: \ + T oper_; \ + }; \ + \ + template <typename T> \ + p2v_##Name##_<T> \ + operator Sym (const Function_p2v<T>& oper) \ + { \ + p2v_##Name##_<T> tmp(oper); \ + return tmp; \ + } \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + +# define oln_decl_p2b_bin_(Name, Sym) \ + \ + template <typename L, typename R> struct p2b_##Name##_; \ + \ + namespace internal \ + { \ + template <typename L, typename R> \ + struct set_category_of_< p2b_##Name##_<L,R> > \ + { \ + typedef stc::is< Function_p2b > ret; \ + }; \ + } \ + \ + template <typename L, typename R> \ + struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<L,R> > \ + { \ + typedef oln_arg_of_(L) argument; \ + typedef oln_res_of_(L) result; \ + \ + p2b_##Name##_(const Function_p2b<L>& left, const Function_p2b<R>& right) \ + : left_(exact(left)), \ + right_(exact(right)) \ + { \ + } \ + result operator()(argument arg) const \ + { \ + return this->left_(arg) Sym this->right_(arg); \ + } \ + private: \ + L left_; \ + R right_; \ + }; \ + \ + template <typename L, typename R> \ + p2b_##Name##_<L,R> \ + operator Sym (const Function_p2b<L>& left, const Function_p2b<R>& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ + p2b_##Name##_<L,R> tmp(left, right); \ + return tmp; \ + } \ + \ + template <typename L, typename R> \ + p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > \ + operator Sym (const Function_p2b<L>& left, const literal_<R>& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + lit_p2b_<oln_argument(L), R> right_(right.value()); \ + p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > tmp(left, right_); \ + return tmp; \ + } \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + + +# define oln_decl_p2b_un_(Name, Sym) \ + \ + template <typename T> struct p2b_##Name##_; \ + \ + namespace internal \ + { \ + template <typename T> \ + struct set_category_of_< p2b_##Name##_<T> > \ + { \ + typedef stc::is< Function_p2b > ret; \ + }; \ + } \ + \ + template <typename T> \ + struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<T> > \ + { \ + typedef oln_arg_of_(T) argument; \ + typedef oln_res_of_(T) result; /* FIXME: trait! */ \ + \ + p2b_##Name##_(const Function_p2b<T>& oper) \ + : oper_(exact(oper)) \ + { \ + } \ + result operator()(argument arg) const \ + { \ + return Sym this->oper_(arg); \ + } \ + private: \ + T oper_; \ + }; \ + \ + template <typename T> \ + p2b_##Name##_<T> \ + operator Sym (const Function_p2b<T>& oper) \ + { \ + p2b_##Name##_<T> tmp(oper); \ + return tmp; \ + } \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + +namespace oln +{ + + oln_decl_p2v_cmp_( eq, = ); + oln_decl_p2v_cmp_( not_eq, != ); + oln_decl_p2v_cmp_( less, < ); + oln_decl_p2v_cmp_( leq, <= ); + oln_decl_p2v_cmp_( greater, > ); + oln_decl_p2v_cmp_( geq, >= ); + + oln_decl_p2v_arith_( plus, + ); + oln_decl_p2v_arith_( minus, - ); + oln_decl_p2v_arith_( times, * ); + oln_decl_p2v_arith_( div, / ); + oln_decl_p2v_arith_( mod, % ); + + oln_decl_p2v_un_( uminus, - ); + + oln_decl_p2b_bin_( and, && ); + oln_decl_p2b_bin_( or, || ); + oln_decl_p2b_bin_( xor, ^ ); + // FIXME: nand, nor, xnor? + + oln_decl_p2b_un_( not, ! ); + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_FUN_OPS_HH Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 900) +++ oln/core/internal/image_base.hh (working copy) @@ -504,6 +504,23 @@ return tmp; } + + // Specialization. + + template <typename I, typename J> + op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > + operator | (const Image<I>& ima, const Binary_Image<J>& f_ima_b) + { + // FIXME: Activate precondition(f_ima_b.points() >= ima.points()); + mlc::assert_equal_< oln_point(I), oln_point(J) >::check(); + op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), f_ima_b); + return tmp; + } + + + // FIXME: What about Mutable_Image so that "ima | something" can be left-value? + + } // end of namespace oln /// \}
participants (1)
-
Thierry Geraud