
2005-04-29 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Add some function objects. * oln/funobj/abstract/binary.hh: New file. * oln/funobj/abstract/unary.hh: Likewise. * oln/funobj/meta.hh: Likewise. * oln/funobj/arith.hh: Likewise. * oln/funobj/logic.hh: Likewise. * oln/funobj/cmp.hh: Likewise. * oln/core/typedefs.hh: Update with new typedef decls. Update of oln/core/pw/* * oln/core/pw/binary_op.hh: New file. * oln/core/pw/unary_op.hh: New file. * oln/core/pw/times.hh, * oln/core/pw/div.hh, * oln/core/pw/plus.hh, * oln/core/pw/minus.hh: Remove, replace by... * oln/core/pw/arith.hh: ...this new file. * oln/core/pw/image.hh (image_from_pw): Rename as... (image_from_pwf): ...this. (pw::image): Rename as... (pw::value): ...this. (p_value): Rename as... (pw_value): ...this. * oln/core/pw/image.hh: Move some parts into... * oln/core/pw/value.hh: ...this new file. * oln/core/pw/check.hh: ...and this new file. * oln/core/pw/macros.hh: Update. * oln/core/pw/abstract/function.hh (ensure): Add. (operator-, operator!): Comment because not updated yet. (~function): Use mlc_check_method_impl. * oln/core/pw/abstract/unary_function.hh (input): Rename as... (arg): ...this. (T): Rename as... (A): ...this. * oln/core/pw/apply.hh: Update. * oln/core/pw/literal.hh (p_lit): Rename as... (p_literal): ...this. * oln/core/pw/logic.hh: Update. * oln/core/pw/cmp.hh: Likewise. * oln/core/pw/all.hh: Likewise. * oln/arith/ops.hh: Likewise. * oln/arith/logic.hh: Likewise. * oln/arith/cmp.hh: New file. Fix morpho for geodesic_dilation to work. * oln/morpho/elementary_dilation.hh: New file. * oln/morpho/tags.hh (max_nbh, impl_max_nbh): New methods. * oln/funobj/accum.hh (max_accumulator_init): New fun obj. * oln/morpho/geodesic_dilation.hh (operator<=): Remove thanks to oln/arith/cmp.hh. * oln/morpho/geodesic_erosion.hh: Likewise. * oln/morpho/stat.hh (local_max_nbh): New routine. Index: oln/funobj/abstract/binary.hh =================================================================== --- oln/funobj/abstract/binary.hh (revision 0) +++ oln/funobj/abstract/binary.hh (revision 0) @@ -0,0 +1,187 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_ABSTRACT_BINARY_HH +# define OLENA_CORE_FUNOBJ_ABSTRACT_BINARY_HH + +# include <mlc/any.hh> +# include <mlc/contract.hh> +# include <mlc/types.hh> +# include <ntg/all.hh> +# include <oln/core/abstract/image.hh> + + +// Macros. + +# define oln_fun2_type_of(Fun2Type, Alias) \ +mlc_type_of(oln, oln::category::fun2, Fun2Type, Alias) + +# define oln_fun2_type_2_of(Fun2Type,_2, Alias) \ +mlc_type_2_of(oln, oln::category::fun2, Fun2Type,_2, Alias) + + + + +namespace oln +{ + + namespace category + { + struct fun2; + } + + + template <> + struct set_default_props < category::fun2 > + { + typedef mlc::undefined_type res_type; + typedef mlc::undefined_type left_type; + typedef mlc::undefined_type right_type; + }; + + + template <typename F> + struct get_props < category::fun2, F > + { + typedef oln_fun2_type_of(F, res) res_type; + typedef oln_fun2_type_of(F, left) left_type; + typedef oln_fun2_type_of(F, right) right_type; + + static void echo(std::ostream& ostr) + { + ostr << "props_of( oln::category::fun1, " << mlc_to_string(F) << " ) =" << std::endl + << "{" << std::endl + << "\t res_type = " << mlc_to_string(res_type) << std::endl + << "\t left_type = " << mlc_to_string(left_type) << std::endl + << "\t right_type = " << mlc_to_string(right_type) << std::endl + << "}" << std::endl; + } + + static void ensure() + { + mlc::is_ok< res_type >::ensure(); + mlc::is_ok< left_type >::ensure(); + mlc::is_ok< right_type >::ensure(); + } + }; + + + + namespace f_ + { + + + template <typename F, typename L, typename R> + struct binary_meta_result + { + typedef mlc::no_type ret; + }; + + + namespace abstract { + + // binary + + template <typename E> + struct binary : public mlc::any<E> + { + typedef oln_fun2_type_of(E, res) res_type; + typedef oln_fun2_type_of(E, left) left_type; + typedef oln_fun2_type_of(E, right) right_type; + + const res_type operator()(const left_type& left, const right_type& right) const + { + return this->exact().impl_binop(left, right); + } + + protected: + + binary() + {} + + ~binary() + { + get_props<category::fun2, E>::ensure(); + mlc_check_method_impl_2(E, const res_type, binop, const left_type&, + const right_type&, const); + } + }; + + + // mbinary + + template <typename E> + struct mbinary : public mlc::any<E> + { + template <typename L, typename R> + const typename binary_meta_result<E,L,R>::ret + operator()(const L& left, const R& right) const + { + return this->exact().impl_binop(left, right); + } + + protected: + + mbinary() {} + }; + + + } // end of namespace oln::abstract + + + + + // fwd decl + template <template <typename, typename> class F> struct binary_meta; + + // result + template <template <typename, typename> class F, typename L, typename R> + struct binary_meta_result < binary_meta<F>, L, R > + { + typedef oln_fun2_type_2_of(F<L,R>, res) ret; + }; + + // class + template <template <typename, typename> class F> + struct binary_meta : public abstract::mbinary< binary_meta<F> > + { + template <typename L, typename R> + const oln_fun2_type_2_of(F<L,R>, res) + impl_binop(const L& l, const R& r) const + { + static F<L,R> f; + return f(l, r); + } + }; + + } // end of namespace oln::f_ + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_FUNOBJ_ABSTRACT_BINARY_HH Index: oln/funobj/abstract/unary.hh =================================================================== --- oln/funobj/abstract/unary.hh (revision 0) +++ oln/funobj/abstract/unary.hh (revision 0) @@ -0,0 +1,169 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_ABSTRACT_UNARY_HH +# define OLENA_CORE_FUNOBJ_ABSTRACT_UNARY_HH + +# include <mlc/any.hh> +# include <mlc/contract.hh> +# include <ntg/all.hh> +# include <oln/core/abstract/image.hh> + + +// Macros. + +# define oln_fun1_type_of(Fun1Type, Alias) \ +mlc_type_of(oln, oln::category::fun1, Fun1Type, Alias) + + +namespace oln +{ + + namespace category + { + struct fun1; + } + + + template <> + struct set_default_props < category::fun1 > + { + typedef mlc::undefined_type res_type; + typedef mlc::undefined_type arg_type; + }; + + + template <typename F> + struct get_props < category::fun1, F > + { + typedef oln_fun1_type_of(F, res) res_type; + typedef oln_fun1_type_of(F, arg) arg_type; + + static void echo(std::ostream& ostr) + { + ostr << "props_of( oln::category::fun1, " << mlc_to_string(F) << " ) =" << std::endl + << "{" << std::endl + << "\t res_type = " << mlc_to_string(res_type) << std::endl + << "\t arg_type = " << mlc_to_string(arg_type) << std::endl + << "}" << std::endl; + } + + static void ensure() + { + mlc::is_ok< res_type >::ensure(); + mlc::is_ok< arg_type >::ensure(); + } + }; + + + namespace f_ + { + + template <typename F, typename T> + struct unary_meta_result + { + typedef mlc::no_type ret; + }; + + + namespace abstract { + + // unary + + template <typename E> + struct unary : public mlc::any<E> + { + typedef oln_fun1_type_of(E, res) res_type; + typedef oln_fun1_type_of(E, arg) arg_type; + const res_type operator()(const arg_type& arg) const + { + return this->exact().impl_unop(arg); + } + protected: + unary() {} + ~unary() + { + get_props<category::fun1, E>::ensure(); + mlc_check_method_impl(E, const res_type, unop, const arg_type&, const); + } + }; + + // munary + + template <typename E> + struct munary : public mlc::any<E> + { + template <typename T> + const typename unary_meta_result<E,T>::ret + operator()(const T& arg) const + { + return this->exact().impl_unop(arg); + } + protected: + munary() {} + }; + + + } // end of namespace oln::abstract + + + + + /// Meta unary function that relies on a unary function. + + + // fwd decl + template <template <typename> class F> struct unary_meta; + + // result + template <template <typename> class F, typename T> + struct unary_meta_result < unary_meta<F>, T > + { + typedef oln_fun1_type_of(F<T>, res) ret; + }; + + // class + template <template <typename> class F> + struct unary_meta : public abstract::munary< unary_meta<F> > + { + template <typename T> + const oln_fun1_type_of(F<T>, res) + impl_unop(const T& arg) const + { + static F<T> f; + return f(arg); + } + }; + + + } // end of namespace oln::f_ + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_FUNOBJ_ABSTRACT_UNARY_HH Index: oln/funobj/meta.hh =================================================================== --- oln/funobj/meta.hh (revision 0) +++ oln/funobj/meta.hh (revision 0) @@ -0,0 +1,85 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_META_HH +# define OLENA_CORE_FUNOBJ_META_HH + +# include <oln/funobj/abstract/unary.hh> +# include <oln/funobj/abstract/binary.hh> + + +namespace oln +{ + + /// Plus. + + + // fwd decl + namespace f_ { + template <typename L, typename R> struct plus; + } + + // super type + template <typename L, typename R> + struct set_super_type < f_::plus<L,R> > { typedef f_::abstract::binary< f_::plus<L,R> > ret; }; + + // props + template <typename L, typename R> + struct set_props < category::fun2, f_::plus<L,R> > + { + typedef ntg_return_type(plus, L, R) res_type; + typedef L left_type; + typedef R right_type; + }; + + namespace f_ + { + + // class + template <typename L, typename R> + struct plus : public oln_super2_of_(f_::plus<L,R>) + { + typedef plus<L,R> self_type; + + const oln_fun2_type_of(self_type, res) + impl_binop(const L& left, const R& right) const + { + return left + right; + } + }; + + } // end of namespace oln::f_ + + + static f_::binary_meta<f_::plus> f_plus; + + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_FUNOBJ_META_HH Index: oln/funobj/arith.hh =================================================================== --- oln/funobj/arith.hh (revision 0) +++ oln/funobj/arith.hh (revision 0) @@ -0,0 +1,143 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_ARITH_HH +# define OLENA_CORE_FUNOBJ_ARITH_HH + +# include <oln/funobj/abstract/unary.hh> +# include <oln/funobj/abstract/binary.hh> + + +# define oln_decl_funobj_binary(OperatorName, OperatorSymbol) \ + \ + namespace f_ { \ + template <typename L, typename R> struct OperatorName##_; \ + } \ + \ + template <typename L, typename R> \ + struct set_super_type < f_::OperatorName##_<L,R> > \ + { \ + typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \ + }; \ + \ + template <typename L, typename R> \ + struct set_props < category::fun2, f_::OperatorName##_<L,R> > \ + { \ + typedef ntg_return_type(OperatorName, L, R) res_type; \ + typedef L left_type; \ + typedef R right_type; \ + }; \ + \ + namespace f_ \ + { \ + \ + template <typename L, typename R> \ + struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \ + { \ + typedef OperatorName##_<L,R> self_type; \ + \ + const oln_fun2_type_of(self_type, res) \ + impl_binop(const L& left, const R& right) const \ + { \ + return left OperatorSymbol right; \ + } \ + }; \ + \ + } \ + \ + typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \ + static f_##OperatorName##_type f_##OperatorName; \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n + + + + + + +# define oln_decl_funobj_cmp(OperatorName, OperatorSymbol) \ + \ + namespace f_ { \ + template <typename L, typename R> struct OperatorName##_; \ + } \ + \ + template <typename L, typename R> \ + struct set_super_type < f_::OperatorName##_<L,R> > \ + { \ + typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \ + }; \ + \ + template <typename L, typename R> \ + struct set_props < category::fun2, f_::OperatorName##_<L,R> > \ + { \ + typedef bool res_type; \ + typedef L left_type; \ + typedef R right_type; \ + }; \ + \ + namespace f_ \ + { \ + \ + template <typename L, typename R> \ + struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \ + { \ + typedef OperatorName##_<L,R> self_type; \ + \ + const oln_fun2_type_of(self_type, res) \ + impl_binop(const L& left, const R& right) const \ + { \ + return left OperatorSymbol right; \ + } \ + }; \ + \ + } \ + \ + typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \ + static f_##OperatorName##_type f_##OperatorName; \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n + + + +namespace oln +{ + + oln_decl_funobj_binary(plus, +); + oln_decl_funobj_binary(minus, -); + oln_decl_funobj_binary(times, *); + oln_decl_funobj_binary(div, /); + oln_decl_funobj_binary(mod, %); + + // FIXME: min, max? + // FIXME: uminus? + + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_FUNOBJ_ARITH_HH Index: oln/funobj/accum.hh =================================================================== --- oln/funobj/accum.hh (revision 174) +++ oln/funobj/accum.hh (working copy) @@ -142,6 +142,35 @@ }; + /// Max accumulator with initialization value. + + template <class T> + struct max_accumulator_init + { + + template <typename U> + max_accumulator_init(const U& init) : + acc_(init) + {} + + void operator()(T t) + { + if (acc_ < t) + acc_ = t; + } + + operator T() const + { + return acc_; + } + + private: + + T acc_; + + }; + + } // end of namespace oln::funobj } // end of namespace oln Index: oln/funobj/logic.hh =================================================================== --- oln/funobj/logic.hh (revision 0) +++ oln/funobj/logic.hh (revision 0) @@ -0,0 +1,97 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_LOGIC_HH +# define OLENA_CORE_FUNOBJ_LOGIC_HH + +# include <oln/funobj/abstract/binary.hh> + + + + +# define oln_decl_funobj_logic(OperatorName, OperatorBody) \ + \ + namespace f_ { \ + template <typename L, typename R> struct OperatorName##_; \ + } \ + \ + template <typename L, typename R> \ + struct set_super_type < f_::OperatorName##_<L,R> > \ + { \ + typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \ + }; \ + \ + template <typename L, typename R> \ + struct set_props < category::fun2, f_::OperatorName##_<L,R> > \ + { \ + typedef bool res_type; \ + typedef L left_type; \ + typedef R right_type; \ + }; \ + \ + namespace f_ \ + { \ + \ + template <typename L, typename R> \ + struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \ + { \ + typedef OperatorName##_<L,R> self_type; \ + \ + const oln_fun2_type_of(self_type, res) \ + impl_binop(const L& lhs, const R& rhs) const \ + { \ + return OperatorBody; \ + } \ + }; \ + \ + } \ + \ + typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \ + static f_##OperatorName##_type f_##OperatorName; \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n + + + +namespace oln +{ + + oln_decl_funobj_logic( and, lhs && rhs); + oln_decl_funobj_logic(nand, !(lhs && rhs)); + oln_decl_funobj_logic( or, lhs || rhs); + oln_decl_funobj_logic( nor, !(lhs || rhs)); + oln_decl_funobj_logic( xor, (lhs && !rhs) || (!lhs && rhs)); + oln_decl_funobj_logic(xnor, (lhs && rhs) || (!lhs && !rhs)); + + // FIXME: what about 'not'?!!! + + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_FUNOBJ_LOGIC_HH Index: oln/funobj/cmp.hh =================================================================== --- oln/funobj/cmp.hh (revision 0) +++ oln/funobj/cmp.hh (revision 0) @@ -0,0 +1,97 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_FUNOBJ_CMP_HH +# define OLENA_CORE_FUNOBJ_CMP_HH + +# include <oln/funobj/abstract/binary.hh> + + + + +# define oln_decl_funobj_cmp(OperatorName, OperatorSymbol) \ + \ + namespace f_ { \ + template <typename L, typename R> struct OperatorName##_; \ + } \ + \ + template <typename L, typename R> \ + struct set_super_type < f_::OperatorName##_<L,R> > \ + { \ + typedef f_::abstract::binary< f_::OperatorName##_<L,R> > ret; \ + }; \ + \ + template <typename L, typename R> \ + struct set_props < category::fun2, f_::OperatorName##_<L,R> > \ + { \ + typedef bool res_type; \ + typedef L left_type; \ + typedef R right_type; \ + }; \ + \ + namespace f_ \ + { \ + \ + template <typename L, typename R> \ + struct OperatorName##_ : public oln_super2_of_(f_::OperatorName##_<L,R>) \ + { \ + typedef OperatorName##_<L,R> self_type; \ + \ + const oln_fun2_type_of(self_type, res) \ + impl_binop(const L& left, const R& right) const \ + { \ + return left OperatorSymbol right; \ + } \ + }; \ + \ + } \ + \ + typedef f_::binary_meta<f_::OperatorName##_> f_##OperatorName##_type; \ + static f_##OperatorName##_type f_##OperatorName; \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n + + + +namespace oln +{ + + oln_decl_funobj_cmp(eq, ==); + oln_decl_funobj_cmp(neq, !=); + + oln_decl_funobj_cmp(less, <); + oln_decl_funobj_cmp(leq, <=); + + oln_decl_funobj_cmp(greater, >); + oln_decl_funobj_cmp(geq, >=); + + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_FUNOBJ_CMP_HH Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 174) +++ oln/core/typedefs.hh (working copy) @@ -41,6 +41,13 @@ # define oln_super_of_(Type) \ oln::internal::get_super_type<Type>::ret +# define oln_super2_of_(Type,_2) \ +oln::internal::get_super_type<Type,_2>::ret + +# define oln_super3_of_(Type,_2,_3) \ +oln::internal::get_super_type<Type,_2,_3>::ret + + # define oln_super_of(Type) \ typename oln_super_of_(Type) @@ -109,6 +116,14 @@ mlc_decl_typedef(coord_type); + // category::fun1 and 2 + + mlc_decl_typedef(res_type); + mlc_decl_typedef(arg_type); + mlc_decl_typedef(left_type); + mlc_decl_typedef(right_type); + + } // end of namespace oln Index: oln/core/pw/times.hh =================================================================== --- oln/core/pw/times.hh (revision 174) +++ oln/core/pw/times.hh (working copy) @@ -1,107 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_TIMES_HH -# define OLENA_CORE_PW_TIMES_HH - -# include <oln/core/pw/abstract/binary_function.hh> -# include <oln/core/pw/literal.hh> -# include <ntg/all.hh> -# include <oln/core/pw/macros.hh> - - -namespace oln { - - // fwd decl - namespace pw { - template <typename L, typename R> struct times; - } - - // super type - template <typename L, typename R> - struct set_super_type < pw::times<L, R> > { typedef pw::abstract::binary_function<L, R, pw::times<L, R> > ret; }; - - // props - template <typename L, typename R> - struct set_props < category::pw, pw::times<L, R> > - { - typedef ntg_return_type(times, - oln_pw_type_of(L, value), - oln_pw_type_of(R, value)) value_type; - }; - - - namespace pw { - - template <typename L, typename R> - struct times : public abstract::binary_function < L, R, times<L, R> > - { - typedef times<L, R> self_type; - - typedef oln_pw_type_of(self_type, point) point_type; - typedef oln_pw_type_of(self_type, value) value_type; - typedef oln_pw_type_of(self_type, size) size_type; - - typedef abstract::binary_function<L, R, self_type> super_type; - - times(const abstract::function<L>& left, - const abstract::function<R>& right) : - super_type(left, right) - { - } - - const value_type impl_get(const point_type& p) const - { - return this->left(p) * this->right(p); - } - - }; - - - } // end of namespace oln::pw - -} // end of namespace oln - - - -/// Operator * on pwf - -template <typename L, typename R> -oln::pw::times<L, R> operator * (const oln::pw::abstract::function<L>& lhs, - const oln::pw::abstract::function<R>& rhs) -{ - precondition(lhs.size() == rhs.size()); - oln::pw::times<L, R> tmp(lhs, rhs); - return tmp; -} - -oln_pw_operator(times, *, int) -oln_pw_operator(times, *, float) -oln_pw_operator(times, *, double) - - -#endif // ! OLENA_CORE_PW_TIMES_HH Index: oln/core/pw/binary_op.hh =================================================================== --- oln/core/pw/binary_op.hh (revision 0) +++ oln/core/pw/binary_op.hh (revision 0) @@ -0,0 +1,94 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_BINARY_OP_HH +# define OLENA_CORE_PW_BINARY_OP_HH + +# include <mlc/is_a.hh> +# include <oln/core/pw/abstract/binary_function.hh> +# include <oln/funobj/abstract/binary.hh> + + +namespace oln { + + + // fwd decl + namespace pw { + template <typename F, typename L, typename R> struct binary_op; + } + + // super type + template <typename F, typename L, typename R> + struct set_super_type < pw::binary_op<F,L,R> > { typedef pw::abstract::binary_function< L, R, pw::binary_op<F,L,R> > ret; }; + + // props + template <typename F, typename L, typename R> + struct set_props < category::pw, pw::binary_op<F,L,R> > + { + typedef typename f_::binary_meta_result<F,L,R>::ret value_type; + }; + + + + namespace pw { + + + template <typename F, typename L, typename R> + struct binary_op : public abstract::binary_function< L, R, binary_op<F,L,R> > + { + typedef binary_op<F,L,R> self_type; + typedef abstract::binary_function<L,R,self_type> super_type; + + F fun; + + binary_op(const abstract::function<L>& left, + const abstract::function<R>& right) : + super_type(left, right), + fun() + { + mlc_is_a(F, f_::binary_meta)::ensure(); + } + + typedef oln_pw_type_of(self_type, point) point_type; + typedef oln_pw_type_of(self_type, value) value_type; + + const value_type impl_get(const point_type& p) const + { + const value_type tmp = this->fun(this->left(p), this->right(p)); + return tmp; + } + + }; + + + } // end of namespace oln::pw + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_PW_BINARY_OP_HH Index: oln/core/pw/image.hh =================================================================== --- oln/core/pw/image.hh (revision 174) +++ oln/core/pw/image.hh (working copy) @@ -28,12 +28,9 @@ #ifndef OLENA_CORE_PW_IMAGE_HH # define OLENA_CORE_PW_IMAGE_HH -# include <mlc/any.hh> -# include <mlc/cmp.hh> -# include <oln/core/box.hh> -# include <oln/core/abstract/image_typeness.hh> # include <oln/core/abstract/image_entry.hh> # include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/value.hh> // FIXME: remove # include <oln/core/2d/grid2d.hh> @@ -46,85 +43,15 @@ // fwd decl - namespace pw { - template <typename I> struct image; - } + template <typename F> class image_from_pwf; - // super type - template <typename I> - struct set_super_type < pw::image<I> > { typedef pw::abstract::function< pw::image<I> > ret; }; - - // props - template <typename I> - struct set_props < category::pw, pw::image<I> > - { - typedef oln_type_of(I, point) point_type; - typedef oln_type_of(I, value) value_type; - typedef oln_type_of(I, size) size_type; - }; - - - namespace pw { // means "point-wise" - - template <typename I> - struct image : public abstract::function < image<I> > - { - oln::box<const I> ima; - - image(const oln::abstract::image<I>& ima) : - ima(ima) - { - } - - typedef oln_type_of(I, point) point_type; - typedef oln_type_of(I, value) value_type; - typedef oln_type_of(I, size) size_type; - - const size_type& impl_size() const - { - return this->ima.size(); - } - - const value_type impl_get(const point_type& p) const - { - return this->ima.get(p); - } - - bool impl_hold(const point_type& p) const - { - return this->ima.hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - return this->ima.hold_large(p); - } - - }; - - } // end of namespace oln::pw - - - /// Routine that takes an image and outputs a "point value" object - - template <typename I> - pw::image<I> p_value(const abstract::image<I>& ima) - { - pw::image<I> tmp(ima); - return tmp; - } - - - // fwd decl - template <typename F> class image_from_pw; - // super template <typename F> - struct set_super_type < image_from_pw<F> > { typedef abstract::image_entry< image_from_pw<F> > ret; }; + struct set_super_type < image_from_pwf<F> > { typedef abstract::image_entry< image_from_pwf<F> > ret; }; // props template <typename F> - struct set_props < category::image, image_from_pw<F> > + struct set_props < category::image, image_from_pwf<F> > { typedef oln_pw_type_of(F, point) point_type; typedef oln_pw_type_of(F, value) value_type; @@ -143,22 +70,22 @@ }; - /// Class image_from_pw<F>. + /// Class image_from_pwf<F>. template <typename F> - struct image_from_pw : public abstract::image_entry< image_from_pw<F> > + struct image_from_pwf : public abstract::image_entry< image_from_pwf<F> > { - typedef image_from_pw<F> self_type; + typedef image_from_pwf<F> self_type; F fun; - image_from_pw(const pw::abstract::function<F>& fun) : + image_from_pwf(const pw::abstract::function<F>& fun) : fun(fun.exact()) { this->exact_ptr = this; } - image_from_pw(const self_type& rhs) : + image_from_pwf(const self_type& rhs) : fun(rhs.fun) { this->exact_ptr = this; @@ -200,85 +127,48 @@ }; + /// Routine image_for_all_p. template <typename F> - image_from_pw<F> image_for_all_p(const pw::abstract::function<F>& fun) + image_from_pwf<F> image_for_all_p(const pw::abstract::function<F>& fun) { - image_from_pw<F> tmp(fun); + image_from_pwf<F> tmp(fun); return tmp; } - // FIXME: below, produce an error instead of correcting the client code (?) + /// Specialization of image_for_all_p (so that "image_for_all_p(pw_value(ima)) == ima"). - /// Specialization of image_for_all_p (so that "image_for_all_p(p_value(ima)) == ima"). - template <typename I> - const I& image_for_all_p(const pw::image<I>& pv) + const I& image_for_all_p(const pw::value<I>& pwv) { - return pv.ima.unbox(); + return pwv.ima.unbox(); } - /// Specialization of p_value (so that "p_value(image_for_all_p(fun)) == fun"). - template <typename F> - F p_value(const image_from_pw<F>& ima) - { - return ima.fun; - } + /// Specializations of image_for_all_p to produce compile-time errors. + // FIXME: struct OLENA_ERROR__arg_of__image_for_all_p__should_be_a_point_wise_function(); + template <typename I> + void image_for_all_p(const abstract::image<I>&) + {} + template <typename P> + void image_for_all_p(const abstract::point<P>&) + {} + /// Specialization of pw_value (so that "pw_value(image_for_all_p(fun)) == fun"). - - /// Routine check. - - template <typename I> - bool check(const abstract::binary_image<I>& pred) + template <typename F> + F pw_value(const image_from_pwf<F>& ima) { - oln_type_of(I, fwd_piter) p(pred.size()); - for_all_p (p) - if (! pred[p]) - return false; - return true; + F tmp = ima.fun; + return tmp; } - namespace pw { - /// Routine oln::pw::check. - - template <typename F> - bool check(const pw::abstract::function<F>& pred) - { - mlc::eq< oln_typeness_of(oln_pw_type_of(F, value)), typeness::binary_tag >::ensure(); - return oln::check(image_for_all_p(pred)); - } - - } // end of namespace oln::pw - - - - // FIXME: Does not work with g++-3.4. - /// Specialization of image_for_all_p that gives a compile-time error. - -// template <typename I> -// void image_for_all_p(const abstract::image<I>&) -// { -// struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_an_image(); -// } - -// /// Specialization of image_for_all_p that gives a compile-time error. - -// template <typename P> -// void image_for_all_p(const abstract::point<P>&) -// { -// struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_a_point(); -// } - - - } // end of namespace oln Index: oln/core/pw/div.hh =================================================================== --- oln/core/pw/div.hh (revision 174) +++ oln/core/pw/div.hh (working copy) @@ -1,109 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_DIV_HH -# define OLENA_CORE_PW_DIV_HH - -# include <oln/core/pw/abstract/binary_function.hh> -# include <oln/core/pw/literal.hh> -# include <ntg/all.hh> -# include <oln/core/pw/macros.hh> - - -namespace oln { - - // fwd decl - namespace pw { - template <typename L, typename R> struct div; - } - - // super type - template <typename L, typename R> - struct set_super_type < pw::div<L, R> > { typedef pw::abstract::binary_function<L, R, pw::div<L, R> > ret; }; - - // props - template <typename L, typename R> - struct set_props < category::pw, pw::div<L, R> > - { - typedef ntg_return_type(div, - oln_pw_type_of(L, value), - oln_pw_type_of(R, value)) value_type; - }; - - - namespace pw { - - template <typename L, typename R> - struct div : public abstract::binary_function < L, R, div<L, R> > - { - typedef div<L, R> self_type; - - typedef oln_pw_type_of(self_type, point) point_type; - typedef oln_pw_type_of(self_type, value) value_type; - typedef oln_pw_type_of(self_type, size) size_type; - - typedef abstract::binary_function<L, R, self_type> super_type; - - div(const abstract::function<L>& left, - const abstract::function<R>& right) : - super_type(left, right) - { - } - - const value_type impl_get(const point_type& p) const - { - precondition(this->right(p) != 0); - return this->left(p) / this->right(p); - } - - }; - - - } // end of namespace oln::pw - -} // end of namespace oln - - - -/// Operator / on pwf - -template <typename L, typename R> -oln::pw::div<L, R> operator / (const oln::pw::abstract::function<L>& lhs, - const oln::pw::abstract::function<R>& rhs) -{ - precondition(lhs.size() == rhs.size()); - oln::pw::div<L, R> tmp(lhs, rhs); - return tmp; -} - - -oln_pw_operator(div, /, int) -oln_pw_operator(div, /, float) -oln_pw_operator(div, /, double) - - -#endif // ! OLENA_CORE_PW_DIV_HH Index: oln/core/pw/plus.hh =================================================================== --- oln/core/pw/plus.hh (revision 174) +++ oln/core/pw/plus.hh (working copy) @@ -1,107 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_PLUS_HH -# define OLENA_CORE_PW_PLUS_HH - -# include <oln/core/pw/abstract/binary_function.hh> -# include <oln/core/pw/literal.hh> -# include <oln/core/pw/macros.hh> -# include <ntg/all.hh> - - -namespace oln { - - // fwd decl - namespace pw { - template <typename L, typename R> struct plus; - } - - // super type - template <typename L, typename R> - struct set_super_type < pw::plus<L, R> > { typedef pw::abstract::binary_function<L, R, pw::plus<L, R> > ret; }; - - // props - template <typename L, typename R> - struct set_props < category::pw, pw::plus<L, R> > - { - typedef ntg_return_type(plus, - oln_pw_type_of(L, value), - oln_pw_type_of(R, value)) value_type; - }; - - - namespace pw { - - template <typename L, typename R> - struct plus : public abstract::binary_function < L, R, plus<L, R> > - { - typedef plus<L, R> self_type; - - typedef oln_pw_type_of(self_type, point) point_type; - typedef oln_pw_type_of(self_type, value) value_type; - typedef oln_pw_type_of(self_type, size) size_type; - - typedef abstract::binary_function<L, R, self_type> super_type; - - plus(const abstract::function<L>& left, - const abstract::function<R>& right) : - super_type(left, right) - { - } - - const value_type impl_get(const point_type& p) const - { - return this->left(p) + this->right(p); - } - - }; - - - } // end of namespace oln::pw - -} // end of namespace oln - - - -/// Operator + on pwf - -template <typename L, typename R> -oln::pw::plus<L, R> operator + (const oln::pw::abstract::function<L>& lhs, - const oln::pw::abstract::function<R>& rhs) -{ - precondition(lhs.size() == rhs.size()); - oln::pw::plus<L, R> tmp(lhs, rhs); - return tmp; -} - -oln_pw_operator(plus, +, int) -oln_pw_operator(plus, +, float) -oln_pw_operator(plus, +, double) - - -#endif // ! OLENA_CORE_PW_PLUS_HH Index: oln/core/pw/macros.hh =================================================================== --- oln/core/pw/macros.hh (revision 174) +++ oln/core/pw/macros.hh (working copy) @@ -28,53 +28,60 @@ #ifndef OLENA_CORE_PW_MACROS_HH # define OLENA_CORE_PW_MACROS_HH +# include <oln/core/pw/unary_op.hh> +# include <oln/core/pw/binary_op.hh> +# include <oln/core/pw/literal.hh> -// FIXME: rename? -# define oln_pw_operator(NAME, SYMBOL, TYPE) \ -template <typename L> \ -oln::pw::NAME<L, oln::pw::literal<TYPE> > \ -operator SYMBOL (const oln::pw::abstract::function<L>& lhs, \ - const TYPE& value) \ -{ \ - return lhs SYMBOL oln::pw::literal<TYPE>(value); \ -} \ -template <typename R> \ -oln::pw::NAME<oln::pw::literal<TYPE>, R> \ -operator SYMBOL (const TYPE& value, \ - const oln::pw::abstract::function<R>& rhs) \ -{ \ - return oln::pw::literal<TYPE>(value) SYMBOL rhs; \ -} +# define oln_pw_decl_binary(OperatorName, OperatorSymbol) \ + \ +template <typename L, typename R> \ +const oln::pw::binary_op< oln::f_##OperatorName##_type, \ + L, R > \ +operator OperatorSymbol (const oln::pw::abstract::function<L>& lhs, \ + const oln::pw::abstract::function<R>& rhs) \ +{ \ + precondition(lhs.size() == rhs.size()); \ + oln::pw::binary_op< oln::f_##OperatorName##_type, \ + L, R > tmp(lhs, rhs); \ + return tmp; \ +} \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n -// FIXME: rename? -# define oln_pw_cmp_operator(NAME, SYMBOL, TYPE) \ -template <typename L> \ -oln::pw::cmp<L, oln::pw::literal<TYPE>, oln::pw::internal::NAME> \ -operator SYMBOL (const oln::pw::abstract::function<L>& lhs, \ - const TYPE& value) \ -{ \ - return lhs SYMBOL oln::pw::literal<TYPE>(value); \ -} \ -template <typename R> \ -oln::pw::cmp<oln::pw::literal<TYPE>, R, oln::pw::internal::NAME> \ -operator SYMBOL (const TYPE& value, \ - const oln::pw::abstract::function<R>& rhs) \ -{ \ - return oln::pw::literal<TYPE>(value) SYMBOL rhs; \ -} +# define oln_pw_decl_binary_with_lit(OperatorName, OperatorSymbol, LiteralType) \ + \ +template <typename L> \ +const oln::pw::binary_op< oln::f_##OperatorName##_type, \ + L, oln::pw::literal<LiteralType> > \ +operator OperatorSymbol (const oln::pw::abstract::function<L>& lhs, \ + const LiteralType& rhs) \ +{ \ + precondition(lhs.size() == rhs.size()); \ + oln::pw::binary_op< oln::f_##OperatorName##_type, \ + L, oln::pw::literal<LiteralType> > tmp(lhs, rhs); \ + return tmp; \ +} \ + \ +template <typename R> \ +const oln::pw::binary_op< oln::f_##OperatorName##_type, \ + oln::pw::literal<LiteralType>, R > \ +operator OperatorSymbol (const LiteralType& lhs, \ + const oln::pw::abstract::function<R>& rhs) \ +{ \ + precondition(lhs.size() == rhs.size()); \ + oln::pw::binary_op< oln::f_##OperatorName##_type, \ + oln::pw::literal<LiteralType>, R > tmp(lhs, rhs); \ + return tmp; \ +} \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n -// FIXME: rename? -# define oln_pw_cmp_operators(TYPE) \ -oln_pw_cmp_operator(eq, ==, TYPE) \ -oln_pw_cmp_operator(neq, !=, TYPE) \ -oln_pw_cmp_operator(geq, >=, TYPE) \ -oln_pw_cmp_operator(leq, <=, TYPE) \ -oln_pw_cmp_operator(g, >, TYPE) \ -oln_pw_cmp_operator(l, <, TYPE) + + #endif // ! OLENA_CORE_PW_MACROS_HH Index: oln/core/pw/apply.hh =================================================================== --- oln/core/pw/apply.hh (revision 174) +++ oln/core/pw/apply.hh (working copy) @@ -78,15 +78,15 @@ F f_; apply1(const mlc::abstract::unary_function<F>& f, - const abstract::function<T>& input) : - super_type(input), + const abstract::function<T>& arg) : + super_type(arg), f_(f.exact()) { } const value_type impl_get(const point_type& p) const { - return f_(this->input(p)); + return f_(this->arg(p)); } }; Index: oln/core/pw/minus.hh =================================================================== --- oln/core/pw/minus.hh (revision 174) +++ oln/core/pw/minus.hh (working copy) @@ -1,123 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_MINUS_HH -# define OLENA_CORE_PW_MINUS_HH - -# include <oln/core/pw/abstract/binary_function.hh> -# include <oln/core/pw/literal.hh> -# include <ntg/all.hh> -# include <oln/core/pw/macros.hh> - - -namespace oln { - - // fwd decl - namespace pw { - template <typename L, typename R> struct minus; - } - - // super type - template <typename L, typename R> - struct set_super_type < pw::minus<L, R> > { typedef pw::abstract::binary_function<L, R, pw::minus<L, R> > ret; }; - - // props - template <typename L, typename R> - struct set_props < category::pw, pw::minus<L, R> > - { - typedef ntg_return_type(minus, - oln_pw_type_of(L, value), - oln_pw_type_of(R, value)) value_type; - }; - - - namespace pw { - - template <typename L, typename R> - struct minus : public abstract::binary_function < L, R, minus<L, R> > - { - typedef minus<L, R> self_type; - - typedef oln_pw_type_of(self_type, point) point_type; - typedef oln_pw_type_of(self_type, value) value_type; - typedef oln_pw_type_of(self_type, size) size_type; - - typedef abstract::binary_function<L, R, self_type > super_type; - - minus(const abstract::function<L>& left, - const abstract::function<R>& right) : - super_type(left, right) - { - } - - const value_type impl_get(const point_type& p) const - { - return this->left(p) - this->right(p); - } - - }; - - - // impl of abstract::function<E>::operator-() - - namespace abstract { - - template <typename E> - minus<literal<oln_pw_type_of(E, value)>, E> - function<E>::operator-() const - { - typedef literal<oln_pw_type_of(E, value)> lit_type; - static const lit_type lhs = 0; - minus< lit_type, E> tmp(lhs, this->exact()); - return tmp; - } - - } // end of namespace oln::pw::abstract - - - } // end of namespace oln::pw - -} // end of namespace oln - - -/// Operator - on pwf - -template <typename L, typename R> -oln::pw::minus<L, R> operator - (const oln::pw::abstract::function<L>& lhs, - const oln::pw::abstract::function<R>& rhs) -{ - precondition(lhs.size() == rhs.size()); - oln::pw::minus<L, R> tmp(lhs, rhs); - return tmp; -} - -oln_pw_operator(minus, -, int) -oln_pw_operator(minus, -, float) -oln_pw_operator(minus, -, double) - - -#endif // ! OLENA_CORE_PW_MINUS_HH Index: oln/core/pw/unary_op.hh =================================================================== --- oln/core/pw/unary_op.hh (revision 0) +++ oln/core/pw/unary_op.hh (revision 0) @@ -0,0 +1,91 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_UNARY_OP_HH +# define OLENA_CORE_PW_UNARY_OP_HH + +# include <mlc/is_a.hh> +# include <oln/core/pw/abstract/unary_function.hh> +# include <oln/funobj/abstract/unary.hh> + + + +namespace oln { + + + // fwd decl + namespace pw { + template <typename F, typename A> struct unary_op; + } + + // super type + template <typename F, typename A> + struct set_super_type < pw::unary_op<F,A> > { typedef pw::abstract::unary_function< A, pw::unary_op<F,A> > ret; }; + + // props + template <typename F, typename A> + struct set_props < category::pw, pw::unary_op<F,A> > + { + typedef typename f_::unary_meta_result<F,A>::ret value_type; + }; + + + namespace pw { + + template <typename F, typename A> + struct unary_op : public abstract::unary_function< A, pw::unary_op<F,A> > + { + typedef unary_op<F,A> self_type; + typedef abstract::unary_function<A,self_type> super_type; + + F fun; + + unary_op(const abstract::function<A>& arg) : + super_type(arg), + fun() + { + mlc_is_a(F, f_::unary_meta)::ensure(); + } + + typedef oln_pw_type_of(self_type, point) point_type; + typedef oln_pw_type_of(self_type, value) value_type; + + const value_type impl_get(const point_type& p) const + { + const value_type tmp = this->fun(this->arg(p)); + return tmp; + } + + }; + + + } // end of namespace oln::pw + +} // end of namespace oln + + +#endif // ! OLENA_CORE_PW_UNARY_OP_HH Index: oln/core/pw/literal.hh =================================================================== --- oln/core/pw/literal.hh (revision 174) +++ oln/core/pw/literal.hh (working copy) @@ -96,13 +96,17 @@ /// Routine that takes a literal and outputs a "point-wise literal" object template <typename T> - pw::literal<T> p_lit(const T& value) + pw::literal<T> p_literal(const T& value) { pw::literal<T> tmp(value); return tmp; } + // FIXME: Specializations of p_literal to produce compile-time errors. + // ... + + } // end of namespace oln Index: oln/core/pw/logic.hh =================================================================== --- oln/core/pw/logic.hh (revision 174) +++ oln/core/pw/logic.hh (working copy) @@ -28,157 +28,46 @@ #ifndef OLENA_CORE_PW_LOGIC_HH # define OLENA_CORE_PW_LOGIC_HH -# include <oln/core/abstract/image_typeness.hh> -# include <oln/core/pw/abstract/function.hh> -# include <oln/core/pw/cmp.hh> +# include <oln/funobj/logic.hh> +# include <oln/core/pw/macros.hh> -namespace oln { +oln_pw_decl_binary(and, and); +oln_pw_decl_binary(or, or); +oln_pw_decl_binary(xor, xor); +// FIXME: not? - namespace pw { - // FIXME: move somewhere else - namespace internal - { - struct not_ { - template <typename T> - bool operator()(const T& rhs) const { - return !rhs; - } - }; - struct and_ { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs && rhs; - } - }; - struct nand_ { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return !(lhs && rhs); - } - }; - struct or_ { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs || rhs; - } - }; - struct nor_ { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return !(lhs || rhs); - } - }; - struct xor_ { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return (lhs && !rhs) || (!lhs && rhs); - } - }; - struct xnor_ { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return (lhs && rhs) || (!lhs && !rhs); - } - }; - } // end of oln::pw::internal +# define oln_pw_decl_logic_lit(LiteralType) \ + \ +oln_pw_decl_binary_with_lit(and, and, LiteralType); \ +oln_pw_decl_binary_with_lit(or, or, LiteralType); \ +oln_pw_decl_binary_with_lit(xor, xor, LiteralType); \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n - } // end of namespace oln::pw - // fwd decl - namespace pw { - template <typename R> struct not_; - } +namespace ntg { + struct bin; +} - // super type - template <typename R> - struct set_super_type < pw::not_<R> > { typedef pw::abstract::function < pw::not_<R> > ret; }; +oln_pw_decl_logic_lit(bool); +oln_pw_decl_logic_lit(ntg::bin); - // props - template <typename R> - struct set_props < category::pw, pw::not_<R> > - { - typedef oln_pw_type_of(R, point) point_type; - typedef oln_pw_type_of(R, size) size_type; - typedef bool value_type; - }; - namespace pw - { - template <typename R> - struct not_ : public abstract::function < not_<R> > - { - typedef not_<R> self_type; +// template <typename E> +// not_<E> +// function<E>::operator!() const +// { +// mlc::eq< oln_typeness_of(oln_pw_type_of(E, value)), typeness::binary_tag >::ensure(); +// not_<E> tmp(this->exact()); +// return tmp; +// } - typedef oln_pw_type_of(R, point) point_type; - typedef oln_pw_type_of(R, size) size_type; - typedef oln_pw_type_of(R, value) value_type; - R right; - not_(const abstract::function<R>& right) : - right(right.exact()) - { - } - - const bool impl_get(const point_type& p) const - { - return ! this->right(p); - } - - const size_type& impl_size() const - { - return this->right.size(); - } - - bool impl_hold(const point_type& p) const - { - return this->right.hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - return this->right.hold_large(p); - } - - }; - - - // impl of abstract::function<E>::operator!() - - namespace abstract { - - template <typename E> - not_<E> - function<E>::operator!() const - { - mlc::eq< oln_typeness_of(oln_pw_type_of(E, value)), typeness::binary_tag >::ensure(); - not_<E> tmp(this->exact()); - return tmp; - } - - } // end of namespace oln::pw::abstract - - - } // end of namespace oln::pw - - -} // end of namespace oln - - - -/// Ops on pwf - -oln_pw_decl_cmp_op(and_, &&) -oln_pw_decl_cmp_op(or_, ||) - -oln_pw_cmp_operator(and_, &&, bool) -oln_pw_cmp_operator(or_, ||, bool) - - #endif // ! OLENA_CORE_PW_LOGIC_HH Index: oln/core/pw/abstract/unary_function.hh =================================================================== --- oln/core/pw/abstract/unary_function.hh (revision 174) +++ oln/core/pw/abstract/unary_function.hh (working copy) @@ -40,20 +40,20 @@ // fwd decl namespace pw { namespace abstract { - template <typename T, typename E> struct unary_function; + template <typename A, typename E> struct unary_function; } } // super type - template <typename T, typename E> - struct set_super_type < pw::abstract::unary_function<T, E> > { typedef pw::abstract::function<E> ret; }; + template <typename A, typename E> + struct set_super_type < pw::abstract::unary_function<A, E> > { typedef pw::abstract::function<E> ret; }; // props - template <typename T, typename E> - struct set_props < category::pw, pw::abstract::unary_function<T, E> > + template <typename A, typename E> + struct set_props < category::pw, pw::abstract::unary_function<A, E> > { - typedef oln_pw_type_of(T, point) point_type; - typedef oln_pw_type_of(T, size) size_type; + typedef oln_pw_type_of(A, point) point_type; + typedef oln_pw_type_of(A, size) size_type; }; @@ -61,15 +61,15 @@ namespace abstract { - template <typename T, typename E> + template <typename A, typename E> struct unary_function : public function<E> { - typedef T input_type; + typedef A arg_type; - T input; + A arg; - unary_function(const abstract::function<T>& input) : - input(input.exact()) + unary_function(const abstract::function<A>& arg) : + arg(arg.exact()) { } @@ -78,17 +78,17 @@ const size_type& impl_size() const { - return input.size(); + return arg.size(); } bool impl_hold(const point_type& p) const { - return input.hold(p); + return arg.hold(p); } bool impl_hold_large(const point_type& p) const { - return input.hold_large(p); + return arg.hold_large(p); } protected: Index: oln/core/pw/abstract/function.hh =================================================================== --- oln/core/pw/abstract/function.hh (revision 174) +++ oln/core/pw/abstract/function.hh (working copy) @@ -71,6 +71,13 @@ << "\t size_type = " << mlc_to_string(size_type) << std::endl << "}" << std::endl; } + + static void ensure() + { + mlc::is_ok< point_type >::ensure(); + mlc::is_ok< value_type >::ensure(); + mlc::is_ok< size_type >::ensure(); + } }; @@ -80,9 +87,10 @@ namespace abstract { template <typename E> struct function; } - template <typename L, typename R> struct minus; template <typename T> struct literal; - template <typename F> struct not_; + // FIXME:... +// template <typename L, typename R> struct minus; +// template <typename F> struct not_; namespace abstract { @@ -114,34 +122,23 @@ return this->exact().impl_hold_large(p); } - minus<literal<value_type>, E> operator-() const; - not_<E> operator!() const; + // FIXME:... +// minus<literal<value_type>, E> operator-() const; +// not_<E> operator!() const; protected: - function() {} + function() + {} + ~function() { - { // impl_size - typedef const size_type& (E::*meth)() const; - meth adr = &E::impl_size; - adr = 0; - } - { // impl_get - typedef const value_type (E::*meth)(const point_type&) const; - meth adr = &E::impl_get; - adr = 0; - } - { // impl_hold - typedef bool (E::*meth)(const point_type&) const; - meth adr = &E::impl_hold; - adr = 0; - } - { // impl_hold_large - typedef bool (E::*meth)(const point_type&) const; - meth adr = &E::impl_hold_large; - adr = 0; - } + get_props<category::pw, E>::ensure(); + + mlc_check_method_impl(E, const size_type&, size, , const); + mlc_check_method_impl(E, const value_type, get, const point_type&, const); + mlc_check_method_impl(E, bool, hold, const point_type&, const); + mlc_check_method_impl(E, bool, hold_large, const point_type&, const); } }; Index: oln/core/pw/arith.hh =================================================================== --- oln/core/pw/arith.hh (revision 0) +++ oln/core/pw/arith.hh (revision 0) @@ -0,0 +1,60 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_ARITH_HH +# define OLENA_CORE_PW_ARITH_HH + +# include <oln/funobj/arith.hh> +# include <oln/core/pw/macros.hh> + + +oln_pw_decl_binary( plus, + ); +oln_pw_decl_binary( minus, - ); +oln_pw_decl_binary( times, * ); +oln_pw_decl_binary( div, / ); +oln_pw_decl_binary( mod, % ); + +// FIXME: uminus? + + +# define oln_pw_decl_arith_lit(LiteralType) \ + \ +oln_pw_decl_binary_with_lit( plus, +, LiteralType); \ +oln_pw_decl_binary_with_lit( minus, -, LiteralType); \ +oln_pw_decl_binary_with_lit( times, +, LiteralType); \ +oln_pw_decl_binary_with_lit( div, /, LiteralType); \ +oln_pw_decl_binary_with_lit( mod, %, LiteralType); \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n + + +oln_pw_decl_arith_lit(int); +oln_pw_decl_arith_lit(float); +oln_pw_decl_arith_lit(double); + + +#endif // ! OLENA_CORE_PW_ARITH_HH Index: oln/core/pw/all.hh =================================================================== --- oln/core/pw/all.hh (revision 174) +++ oln/core/pw/all.hh (working copy) @@ -29,19 +29,17 @@ # define OLENA_CORE_PW_ALL_HH -# include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/value.hh> # include <oln/core/pw/image.hh> # include <oln/core/pw/literal.hh> +// FIXME: # include <oln/core/pw/ternary.hh> # include <oln/core/pw/cmp.hh> +# include <oln/core/pw/arith.hh> # include <oln/core/pw/logic.hh> -# include <oln/core/pw/plus.hh> -# include <oln/core/pw/minus.hh> -# include <oln/core/pw/times.hh> -# include <oln/core/pw/div.hh> +# include <oln/core/pw/check.hh> +# include <oln/core/pw/apply.hh> -// FIXME: xor mod... - #endif // ! OLENA_CORE_PW_ALL_HH Index: oln/core/pw/value.hh =================================================================== --- oln/core/pw/value.hh (revision 0) +++ oln/core/pw/value.hh (revision 0) @@ -0,0 +1,123 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_VALUE_HH +# define OLENA_CORE_PW_VALUE_HH + +# include <oln/core/box.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/pw/abstract/function.hh> + + +namespace oln { + + + // fwd decl + namespace pw { + template <typename I> struct value; + } + + // super type + template <typename I> + struct set_super_type < pw::value<I> > { typedef pw::abstract::function< pw::value<I> > ret; }; + + // props + template <typename I> + struct set_props < category::pw, pw::value<I> > + { + typedef oln_type_of(I, point) point_type; + typedef oln_type_of(I, value) value_type; + typedef oln_type_of(I, size) size_type; + }; + + + namespace pw { // means "point-wise" + + template <typename I> + struct value : public abstract::function < value<I> > + { + oln::box<const I> ima; + + value(const oln::abstract::image<I>& ima) : + ima(ima) + { + } + + typedef oln_type_of(I, point) point_type; + typedef oln_type_of(I, value) value_type; + typedef oln_type_of(I, size) size_type; + + const size_type& impl_size() const + { + return this->ima.size(); + } + + const value_type impl_get(const point_type& p) const + { + return this->ima.get(p); + } + + bool impl_hold(const point_type& p) const + { + return this->ima.hold(p); + } + + bool impl_hold_large(const point_type& p) const + { + return this->ima.hold_large(p); + } + + }; + + } // end of namespace oln::pw + + + /// Routine that takes an image and outputs a "point value" object + + template <typename I> + pw::value<I> pw_value(const abstract::image<I>& ima) + { + pw::value<I> tmp(ima); + return tmp; + } + + + /// Specializations of pw_value to produce compile-time errors. + // FIXME: struct OLENA_ERROR__arg_of__pw_value__should_be_a_image(); + + template <typename P> + void pw_value(const abstract::point<P>&) + {} + + // FIXME: add abstract::piter, etc. + + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_PW_VALUE_HH Index: oln/core/pw/check.hh =================================================================== --- oln/core/pw/check.hh (revision 0) +++ oln/core/pw/check.hh (revision 0) @@ -0,0 +1,60 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_CHECK_HH +# define OLENA_CORE_PW_CHECK_HH + +# include <mlc/cmp.hh> +# include <oln/core/abstract/image_typeness.hh> +# include <oln/core/pw/image.hh> + + +namespace oln { + + namespace pw { + + + template <typename F> + bool check(const abstract::function<F>& pred) + { + mlc::eq< oln_typeness_of(oln_pw_type_of(F, value)), typeness::binary_tag >::ensure(); + typedef image_from_pwf<F> I; + I ima(pred); + oln_type_of(I, fwd_piter) p(ima.size()); + for_all_p (p) + if (not ima[p]) + return false; + return true; + } + + + } // end of namespace oln::pw + +} // end of namespace oln + + +#endif // ! OLENA_CORE_PW_CHECK_HH Index: oln/core/pw/cmp.hh =================================================================== --- oln/core/pw/cmp.hh (revision 174) +++ oln/core/pw/cmp.hh (working copy) @@ -28,140 +28,35 @@ #ifndef OLENA_CORE_PW_CMP_HH # define OLENA_CORE_PW_CMP_HH -# include <oln/core/pw/abstract/binary_function.hh> +# include <oln/funobj/cmp.hh> # include <oln/core/pw/macros.hh> -namespace oln { +oln_pw_decl_binary( eq, == ); +oln_pw_decl_binary( neq, != ); +oln_pw_decl_binary( less, < ); +oln_pw_decl_binary( leq, <= ); +oln_pw_decl_binary( greater, > ); +oln_pw_decl_binary( geq, >= ); - namespace pw { +# define oln_pw_decl_cmp_lit(LiteralType) \ + \ +oln_pw_decl_binary_with_lit( eq, ==, LiteralType); \ +oln_pw_decl_binary_with_lit( neq, !=, LiteralType); \ +oln_pw_decl_binary_with_lit( less, < , LiteralType); \ +oln_pw_decl_binary_with_lit( leq, <=, LiteralType); \ +oln_pw_decl_binary_with_lit( greater, > , LiteralType); \ +oln_pw_decl_binary_with_lit( geq, >=, LiteralType); \ + \ +struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n - // FIXME: move somewhere else - namespace internal - { - struct eq { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs == rhs; - } - }; - struct neq { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs != rhs; - } - }; - struct geq { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs >= rhs; - } - }; - struct leq { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs <= rhs; - } - }; - struct g { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs > rhs; - } - }; - struct l { - template <typename L, typename R> - bool operator()(const L& lhs, const R& rhs) const { - return lhs < rhs; - } - }; - } // end of oln::pw::internal +oln_pw_decl_cmp_lit(int); +oln_pw_decl_cmp_lit(float); +oln_pw_decl_cmp_lit(double); - } // end of namespace pw - - // fwd decl - namespace pw { - template <typename L, typename R, typename C> struct cmp; - } - - // super type - template <typename L, typename R, typename C> - struct set_super_type < pw::cmp<L, R, C> > { typedef pw::abstract::binary_function<L, R, pw::cmp<L, R, C> > ret; }; - - // props - template <typename L, typename R, typename C> - struct set_props < category::pw, pw::cmp<L, R, C> > - { - typedef bool value_type; - }; - - - - - namespace pw - { - - template <typename L, typename R, typename C> - struct cmp : public abstract::binary_function < L, R, cmp<L, R, C> > - { - typedef cmp<L, R, C> self_type; - - typedef oln_pw_type_of(self_type, point) point_type; - typedef oln_pw_type_of(self_type, value) value_type; - typedef oln_pw_type_of(self_type, size) size_type; - - typedef abstract::binary_function<L, R, self_type> super_type; - - cmp(const abstract::function<L>& left, - const abstract::function<R>& right) : - super_type(left, right) - { - } - - const bool impl_get(const point_type& p) const - { - static const C cmpfun = C(); - return cmpfun(this->left(p), this->right(p)); - } - - }; - - } // end of namespace oln::pw - - -} // end of namespace oln - - - -/// Ops on pwf - -# define oln_pw_decl_cmp_op(NAME, SYMBOL) \ -template <typename L, typename R> \ -oln::pw::cmp<L, R, oln::pw::internal:: NAME > \ -operator SYMBOL (const oln::pw::abstract::function<L>& lhs, \ - const oln::pw::abstract::function<R>& rhs) \ -{ \ - precondition(lhs.size() == rhs.size()); \ - oln::pw::cmp<L, R, oln::pw::internal:: NAME > tmp(lhs, rhs); \ - return tmp; \ -} - -oln_pw_decl_cmp_op(eq, ==) -oln_pw_decl_cmp_op(neq, !=) -oln_pw_decl_cmp_op(geq, >=) -oln_pw_decl_cmp_op(leq, <=) -oln_pw_decl_cmp_op(g, >) -oln_pw_decl_cmp_op(l, <) - -oln_pw_cmp_operators(int) -oln_pw_cmp_operators(float) -oln_pw_cmp_operators(double) - - - #endif // ! OLENA_CORE_PW_CMP_HH Index: oln/morpho/elementary_dilation.hh =================================================================== --- oln/morpho/elementary_dilation.hh (revision 0) +++ oln/morpho/elementary_dilation.hh (revision 0) @@ -0,0 +1,113 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_ELEMENTARY_DILATION_HH +# define OLENA_MORPHO_ELEMENTARY_DILATION_HH + +# include <oln/utils/record.hh> +# include <oln/core/gen/image_with_nbh.hh> +# include <oln/morpho/tags.hh> + + +namespace oln { + + namespace morpho { + + + + // Fwd decl of elementary dilation's facade. + + template<typename K, typename I> + oln_type_of(I, concrete) elementary_dilation(const tag::kind<K>& kind, + const abstract::image_with_nbh<I>& input); + + // Facade for classical elementary dilation. + + template<typename I> + oln_type_of(I, concrete) elementary_dilation(const abstract::image_with_nbh<I>& input) + { + return elementary_dilation(tag::classical, input); + } + + + + namespace impl { + + + // generic + + template<typename K, typename I> + oln_type_of(I, concrete) elementary_dilation_(const tag::kind<K>& kind, + const abstract::image_with_nbh<I>& input) + { + entering("->generic"); + registering(input, "input"); + + oln_type_of(I, concrete) output(input.size(), "output"); + + oln_type_of(I, piter) p(input.size()); + for_all_p (p) + output[p] = kind.max_nbh(input, p); + + exiting("->generic"); + return output; + } + + + // add some other impls here... + + + } // end of namespace oln::morpho::impl + + + + + /// Generic elementary_dilation (facade). + + template<typename K, typename I> + oln_type_of(I, concrete) elementary_dilation(const tag::kind<K>& kind, + const abstract::image_with_nbh<I>& input) + { + entering("morpho::elementary_dilation"); + registering(input, "input"); + + oln_type_of(I, concrete) output("output"); + output = impl::elementary_dilation_(kind, input.exact()); + + exiting("morpho::elementary_dilation"); + return output; + } + + + + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLENA_MORPHO_ELEMENTARY_DILATION_HH Index: oln/morpho/tags.hh =================================================================== --- oln/morpho/tags.hh (revision 174) +++ oln/morpho/tags.hh (working copy) @@ -84,6 +84,15 @@ return this->exact().impl_min_nbh(input, p); } + // max value in input of neighborhoods of p + template <typename I> + oln_type_of(I, value) + max_nbh(const abstract::image_with_nbh<I>& input, + const oln_type_of(I, point)& p) const + { + return this->exact().impl_max_nbh(input, p); + } + }; @@ -119,6 +128,15 @@ return morpho::local_min_nbh(input, p); } + // max value in input of neighborhoods of p + template <typename I> + oln_type_of(I, value) + impl_max_nbh(const abstract::image_with_nbh<I>& input, + const oln_type_of(I, point)& p) const + { + return morpho::local_max_nbh(input, p); + } + }; const classical_type classical = classical_type(); Index: oln/morpho/geodesic_dilation.hh =================================================================== --- oln/morpho/geodesic_dilation.hh (revision 174) +++ oln/morpho/geodesic_dilation.hh (working copy) @@ -32,22 +32,14 @@ # include <mlc/contract.hh> # include <oln/utils/record.hh> -# include <oln/core/pw/all.hh> +# include <oln/arith/cmp.hh> # include <oln/core/gen/image_with_nbh.hh> // FIXME: should be in core/abstract/ (?) # include <oln/morpho/elementary_dilation.hh> -// FIXME: such routines should be written somewhere else... -template <typename L, typename R> -bool operator <= (const oln::abstract::image<L>& lhs, - const oln::abstract::image<R>& rhs) -{ - return oln::pw::check(oln::p_value(lhs) <= oln::p_value(rhs)); -} - namespace oln { namespace morpho { Index: oln/morpho/stat.hh =================================================================== --- oln/morpho/stat.hh (revision 174) +++ oln/morpho/stat.hh (working copy) @@ -58,7 +58,6 @@ return minval; } - template <typename I> oln_type_of(I, value) local_min_nbh(const abstract::image_with_nbh<I>& input, const oln_type_of(I, point)& p) @@ -110,7 +109,20 @@ return maxval; } + template <typename I> + oln_type_of(I, value) local_max_nbh(const abstract::image_with_nbh<I>& input, + const oln_type_of(I, point)& p) + { + oln_type_of(I, niter) n(input); + funobj::max_accumulator_init<oln_type_of(I, value)> maxval(input[p]); + + for_all_n_of_p (n, p) + if (input.hold(n)) + maxval(input[n]); + return maxval; + } + /// Local max on a set. template <typename I, typename W> Index: oln/morpho/geodesic_erosion.hh =================================================================== --- oln/morpho/geodesic_erosion.hh (revision 174) +++ oln/morpho/geodesic_erosion.hh (working copy) @@ -32,23 +32,13 @@ # include <mlc/contract.hh> # include <oln/utils/record.hh> -# include <oln/core/pw/all.hh> +# include <oln/arith/cmp.hh> # include <oln/core/gen/image_with_nbh.hh> // FIXME: should be in core/abstract/ (?) # include <oln/morpho/elementary_erosion.hh> -// FIXME: such routines should be written somewhere else... -template <typename L, typename R> -bool operator >= (const oln::abstract::image<L>& lhs, - const oln::abstract::image<R>& rhs) -{ - return oln::pw::check(oln::p_value(lhs) >= oln::p_value(rhs)); -} - - - namespace oln { namespace morpho { Index: oln/arith/ops.hh =================================================================== --- oln/arith/ops.hh (revision 174) +++ oln/arith/ops.hh (working copy) @@ -29,108 +29,129 @@ # define OLENA_ARITH_OPS_HH # include <oln/core/abstract/image.hh> -# include <oln/core/abstract/image_typeness.hh> -# include <oln/core/pw/all.hh> +# include <oln/core/pw/image.hh> +# include <oln/core/pw/value.hh> +# include <oln/core/pw/arith.hh> -/// Operator + between 2 images. +/// Operator '+' between 2 images. template <typename L, typename R> -oln::image_from_pw< oln::pw::plus< oln::pw::image<L>, - oln::pw::image<R> > > +oln::image_from_pwf< oln::pw::binary_op< oln::f_plus_type, + oln::pw::value<L>, + oln::pw::value<R> > > operator + (const oln::abstract::image<L>& lhs, const oln::abstract::image<R>& rhs) { - return oln::image_for_all_p(oln::p_value(lhs) + oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) + oln::pw_value(rhs)); } -/// Operator - between 2 images. +/// Operator '-' between 2 images. template <typename L, typename R> -oln::image_from_pw< oln::pw::minus< oln::pw::image<L>, - oln::pw::image<R> > > +oln::image_from_pwf< oln::pw::binary_op< oln::f_minus_type, + oln::pw::value<L>, + oln::pw::value<R> > > operator - (const oln::abstract::image<L>& lhs, const oln::abstract::image<R>& rhs) { - return oln::image_for_all_p(oln::p_value(lhs) - oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) - oln::pw_value(rhs)); } -/// Operator - (unary) on image. +/// Operator '*' between 2 images. -template <typename R> -oln::image_from_pw< oln::pw::minus< oln::pw::literal< oln_pw_type_of(R, value) >, - oln::pw::image<R> > > -operator - (const oln::abstract::image<R>& rhs) +template <typename L, typename R> +oln::image_from_pwf< oln::pw::binary_op< oln::f_times_type, + oln::pw::value<L>, + oln::pw::value<R> > > +operator * (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) { - return oln::image_for_all_p( - oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) * oln::pw_value(rhs)); } -/// Operator * between 2 images. +/// Operator '/' between 2 images. template <typename L, typename R> -oln::image_from_pw< oln::pw::times< oln::pw::image<L>, - oln::pw::image<R> > > -operator * (const oln::abstract::image<L>& lhs, +oln::image_from_pwf< oln::pw::binary_op< oln::f_div_type, + oln::pw::value<L>, + oln::pw::value<R> > > +operator / (const oln::abstract::image<L>& lhs, const oln::abstract::image<R>& rhs) { - return oln::image_for_all_p(oln::p_value(lhs) * oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) / oln::pw_value(rhs)); } -/// Operator / between 2 images. +/// Operator '%' between 2 images. template <typename L, typename R> -oln::image_from_pw< oln::pw::div< oln::pw::image<L>, - oln::pw::image<R> > > -operator / (const oln::abstract::image<L>& lhs, +oln::image_from_pwf< oln::pw::binary_op< oln::f_mod_type, + oln::pw::value<L>, + oln::pw::value<R> > > +operator % (const oln::abstract::image<L>& lhs, const oln::abstract::image<R>& rhs) { - return oln::image_for_all_p(oln::p_value(lhs) / oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) % oln::pw_value(rhs)); } -# define oln_decl_binary_operator(NAME, SYMBOL, TYPE) \ -template <typename L> \ -oln::image_from_pw< oln::pw::NAME< oln::pw::image<L>, \ - oln::pw::literal<TYPE> > > \ -operator SYMBOL (const oln::abstract::image<L>& lhs, \ - TYPE value) \ -{ \ - return oln::image_for_all_p(oln::p_value(lhs) SYMBOL oln::p_lit(value)); \ -} \ -template <typename R> \ -oln::image_from_pw< oln::pw::NAME< oln::pw::literal<TYPE>, \ - oln::pw::image<R> > > \ -operator SYMBOL (TYPE value, \ - const oln::abstract::image<R>& rhs) \ -{ \ - return oln::image_for_all_p(oln::p_lit(value) SYMBOL oln::p_value(rhs)); \ -} +// FIXME... +// /// Operator - (unary) on image. -oln_decl_binary_operator(plus, +, int) -oln_decl_binary_operator(plus, +, float) -oln_decl_binary_operator(plus, +, double) +// template <typename R> +// oln::image_from_pw< oln::pw::minus< oln::pw::literal< oln_pw_type_of(R, value) >, +// oln::pw::image<R> > > +// operator - (const oln::abstract::image<R>& rhs) +// { +// return oln::image_for_all_p( - oln::p_value(rhs)); +// } -oln_decl_binary_operator(minus, -, int) -oln_decl_binary_operator(minus, -, float) -oln_decl_binary_operator(minus, -, double) -oln_decl_binary_operator(times, *, int) -oln_decl_binary_operator(times, *, float) -oln_decl_binary_operator(times, *, double) -oln_decl_binary_operator(div, /, int) -oln_decl_binary_operator(div, /, float) -oln_decl_binary_operator(div, /, double) +// # define oln_decl_binary_operator(NAME, SYMBOL, TYPE) \ +// template <typename L> \ +// oln::image_from_pw< oln::pw::NAME< oln::pw::image<L>, \ +// oln::pw::literal<TYPE> > > \ +// operator SYMBOL (const oln::abstract::image<L>& lhs, \ +// TYPE value) \ +// { \ +// return oln::image_for_all_p(oln::p_value(lhs) SYMBOL oln::p_lit(value)); \ +// } \ +// template <typename R> \ +// oln::image_from_pw< oln::pw::NAME< oln::pw::literal<TYPE>, \ +// oln::pw::image<R> > > \ +// operator SYMBOL (TYPE value, \ +// const oln::abstract::image<R>& rhs) \ +// { \ +// return oln::image_for_all_p(oln::p_lit(value) SYMBOL oln::p_value(rhs)); \ +// } +// oln_decl_binary_operator(plus, +, int) +// oln_decl_binary_operator(plus, +, float) +// oln_decl_binary_operator(plus, +, double) +// oln_decl_binary_operator(minus, -, int) +// oln_decl_binary_operator(minus, -, float) +// oln_decl_binary_operator(minus, -, double) + +// oln_decl_binary_operator(times, *, int) +// oln_decl_binary_operator(times, *, float) +// oln_decl_binary_operator(times, *, double) + +// oln_decl_binary_operator(div, /, int) +// oln_decl_binary_operator(div, /, float) +// oln_decl_binary_operator(div, /, double) + + + // template <typename I, typename F> // void operator + (const oln::abstract::image<I>&, // const oln::pw::abstract::function<F>&) Index: oln/arith/logic.hh =================================================================== --- oln/arith/logic.hh (revision 174) +++ oln/arith/logic.hh (working copy) @@ -25,47 +25,64 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_LOGIC_OPS_HH -# define OLENA_LOGIC_OPS_HH +#ifndef OLENA_ARITH_LOGIC_HH +# define OLENA_ARITH_LOGIC_HH # include <oln/core/abstract/image.hh> -# include <oln/core/abstract/image_typeness.hh> -# include <oln/core/pw/all.hh> +# include <oln/core/pw/image.hh> +# include <oln/core/pw/value.hh> +# include <oln/core/pw/logic.hh> /// Operator 'and' between 2 binary images. template <typename L, typename R> -oln::image_from_pw< oln::pw::cmp< oln::pw::image<L>, - oln::pw::image<R>, oln::pw::internal::and_ > > -operator && (const oln::abstract::binary_image<L>& lhs, - const oln::abstract::binary_image<R>& rhs) +const oln::image_from_pwf< oln::pw::binary_op< oln::f_and_type, + oln::pw::value<L>, + oln::pw::value<R> > > +operator and (const oln::abstract::binary_image<L>& lhs, + const oln::abstract::binary_image<R>& rhs) { - return oln::image_for_all_p(oln::p_value(lhs) && oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) and oln::pw_value(rhs)); } /// Operator 'or' between 2 binary images. template <typename L, typename R> -oln::image_from_pw< oln::pw::cmp< oln::pw::image<L>, - oln::pw::image<R>, oln::pw::internal::or_ > > -operator || (const oln::abstract::binary_image<L>& lhs, +const oln::image_from_pwf< oln::pw::binary_op< oln::f_or_type, + oln::pw::value<L>, + oln::pw::value<R> > > +operator or (const oln::abstract::binary_image<L>& lhs, const oln::abstract::binary_image<R>& rhs) { - return oln::image_for_all_p(oln::p_value(lhs) || oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) or oln::pw_value(rhs)); } -/// Unary operator 'not' on a binary image. +/// Operator 'xor' between 2 binary images. -template <typename I> -oln::image_from_pw< oln::pw::not_< oln::pw::image<I> > > -operator ! (const oln::abstract::binary_image<I>& rhs) +template <typename L, typename R> +const oln::image_from_pwf< oln::pw::binary_op< oln::f_xor_type, + oln::pw::value<L>, + oln::pw::value<R> > > +operator xor (const oln::abstract::binary_image<L>& lhs, + const oln::abstract::binary_image<R>& rhs) { - return oln::image_for_all_p(!oln::p_value(rhs)); + return oln::image_for_all_p(oln::pw_value(lhs) xor oln::pw_value(rhs)); } +// FIXME... +// /// Unary operator 'not' on a binary image. -#endif // ! OLENA_LOGIC_OPS_HH +// template <typename I> +// oln::image_from_pw< oln::pw::not_< oln::pw::image<I> > > +// operator ! (const oln::abstract::binary_image<I>& rhs) +// { +// return oln::image_for_all_p(!oln::p_value(rhs)); +// } + + + +#endif // ! OLENA_ARITH_LOGIC_HH Index: oln/arith/cmp.hh =================================================================== --- oln/arith/cmp.hh (revision 0) +++ oln/arith/cmp.hh (revision 0) @@ -0,0 +1,96 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_ARITH_CMP_HH +# define OLENA_ARITH_CMP_HH + +# include <oln/core/abstract/image.hh> +# include <oln/core/pw/cmp.hh> +# include <oln/core/pw/check.hh> + + +/// Operator '==' between 2 images. + +template <typename L, typename R> +bool operator == (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::pw::check(oln::pw_value(lhs) == oln::pw_value(rhs)); +} + + +/// Operator '!=' between 2 images. + +template <typename L, typename R> +bool operator != (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::pw::check(oln::pw_value(lhs) != oln::pw_value(rhs)); +} + + +/// Operator '<' between 2 images. + +template <typename L, typename R> +bool operator < (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::pw::check(oln::pw_value(lhs) < oln::pw_value(rhs)); +} + + +/// Operator '<=' between 2 images. + +template <typename L, typename R> +bool operator <= (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::pw::check(oln::pw_value(lhs) <= oln::pw_value(rhs)); +} + + +/// Operator '>' between 2 images. + +template <typename L, typename R> +bool operator > (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::pw::check(oln::pw_value(lhs) > oln::pw_value(rhs)); +} + + +/// Operator '>=' between 2 images. + +template <typename L, typename R> +bool operator >= (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::pw::check(oln::pw_value(lhs) >= oln::pw_value(rhs)); +} + + +#endif // ! OLENA_ARITH_CMP_HH