proto-1.0 108: Add oln::pw::binary_function and clean "nth" stuff

2005-04-04 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> * oln/core/pw/abstract/binary_function.hh: Likewise. * oln/arith/ops.hh: Likewise. * oln/core/pw/times.hh: Handle better point_type and size_type. * oln/core/pw/div.hh: Likewise. * oln/core/pw/plus.hh: Likewise. * oln/core/pw/minus.hh: Likewise. * oln/core/pw/image.hh: Cosmetic change. * oln/core/pw/abstract/function.hh: Move macros to... * oln/core/pw/macros.hh: ... this new file. * oln/core/pw/literal.hh: Likewise. * oln/core/any/dpoint.hh: Add fwd decls. * oln/core/abstract/point.hh (oln_point_type_from_2): New macro. (nth): New method. * oln/core/abstract/witer.hh: Add include to pass sanity check. * oln/core/abstract/dpoint.hh: Likewise. * oln/core/abstract/size.hh (oln_size_type_from_2): New macro. * oln/core/1d/dpoint1d.hh: Add inheritance. (impl_nth): New method. * oln/core/2d/dpoint2d.hh: Likewise. * oln/core/3d/dpoint3d.hh: Likewise. * oln/core/1d/point1d.hh (impl_nth): New method. * oln/core/2d/point2d.hh: Likewise. * oln/core/3d/point3d.hh: Likewise. Index: oln/core/pw/times.hh =================================================================== --- oln/core/pw/times.hh (revision 107) +++ oln/core/pw/times.hh (working copy) @@ -28,7 +28,7 @@ #ifndef OLENA_CORE_PW_TIMES_HH # define OLENA_CORE_PW_TIMES_HH -# include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/abstract/binary_function.hh> # include <oln/core/pw/literal.hh> # include <ntg/all.hh> @@ -44,13 +44,16 @@ template <typename L, typename R> struct traits < times<L, R> > { - typedef oln_pw_point_type(L) point_type; - typedef ntg_return_type(times, oln_pw_value_type(L), oln_pw_value_type(R)) value_type; - typedef oln_pw_size_type(L) size_type; + typedef abstract::binary_function<L, R, times<L, R> > super_type; + typedef typename traits<super_type>::point_type point_type; + typedef typename traits<super_type>::size_type size_type; + typedef ntg_return_type(times, + oln_pw_value_type(L), + oln_pw_value_type(R)) value_type; }; template <typename L, typename R> - struct times : public abstract::function < times<L, R> > + struct times : public abstract::binary_function < L, R, times<L, R> > { typedef times<L, R> self_type; @@ -58,42 +61,28 @@ typedef oln_pw_value_type(self_type) value_type; typedef oln_pw_size_type(self_type) size_type; - L left; - R right; + typedef abstract::binary_function<L, R, self_type> super_type; times(const abstract::function<L>& left, const abstract::function<R>& right) : - left(left.exact()), - right(right.exact()) + super_type(left, right) { } - const size_type& impl_size() const - { - return this->left.size(); - } - const value_type impl_get(const point_type& p) const { return this->left(p) * this->right(p); } - bool impl_hold(const point_type& p) const - { - return this->left.hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - return this->left.hold_large(p); - } }; + } // end of namespace oln::pw } // end of namespace oln + /// Operator * on pwf template <typename L, typename R> Index: oln/core/pw/image.hh =================================================================== --- oln/core/pw/image.hh (revision 107) +++ oln/core/pw/image.hh (working copy) @@ -128,7 +128,7 @@ typedef mlc::no_type delegated_type; - // FIXME: we do not know if it is 2d... + // FIXME: AWFUL we do not know if it is 2d... typedef is_a<abstract::image2d> image_dimension_type; typedef vectorialness_from_valuetype(value_type) image_vectorialness_type; Index: oln/core/pw/div.hh =================================================================== --- oln/core/pw/div.hh (revision 107) +++ oln/core/pw/div.hh (working copy) @@ -28,7 +28,7 @@ #ifndef OLENA_CORE_PW_DIV_HH # define OLENA_CORE_PW_DIV_HH -# include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/abstract/binary_function.hh> # include <oln/core/pw/literal.hh> # include <ntg/all.hh> @@ -44,13 +44,16 @@ template <typename L, typename R> struct traits < div<L, R> > { - typedef oln_pw_point_type(L) point_type; - typedef ntg_return_type(div, oln_pw_value_type(L), oln_pw_value_type(R)) value_type; - typedef oln_pw_size_type(L) size_type; + typedef abstract::binary_function<L, R, div<L, R> > super_type; + typedef typename traits<super_type>::point_type point_type; + typedef typename traits<super_type>::size_type size_type; + typedef ntg_return_type(div, + oln_pw_value_type(L), + oln_pw_value_type(R)) value_type; }; template <typename L, typename R> - struct div : public abstract::function < div<L, R> > + struct div : public abstract::binary_function < L, R, div<L, R> > { typedef div<L, R> self_type; @@ -58,43 +61,29 @@ typedef oln_pw_value_type(self_type) value_type; typedef oln_pw_size_type(self_type) size_type; - L left; - R right; + typedef abstract::binary_function<L, R, self_type> super_type; div(const abstract::function<L>& left, - const abstract::function<R>& right) : - left(left.exact()), - right(right.exact()) + const abstract::function<R>& right) : + super_type(left, right) { } - const size_type& impl_size() const - { - return this->left.size(); - } - const value_type impl_get(const point_type& p) const { precondition(this->right(p) != 0); return this->left(p) / this->right(p); } - bool impl_hold(const point_type& p) const - { - return this->left.hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - return this->left.hold_large(p); - } }; + } // end of namespace oln::pw } // end of namespace oln + /// Operator / on pwf template <typename L, typename R> @@ -107,4 +96,9 @@ } +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 107) +++ oln/core/pw/plus.hh (working copy) @@ -28,7 +28,7 @@ #ifndef OLENA_CORE_PW_PLUS_HH # define OLENA_CORE_PW_PLUS_HH -# include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/abstract/binary_function.hh> # include <oln/core/pw/literal.hh> # include <ntg/all.hh> @@ -44,13 +44,16 @@ template <typename L, typename R> struct traits < plus<L, R> > { - typedef oln_pw_point_type(L) point_type; - typedef ntg_return_type(plus, oln_pw_value_type(L), oln_pw_value_type(R)) value_type; - typedef oln_pw_size_type(L) size_type; + typedef abstract::binary_function<L, R, plus<L, R> > super_type; + typedef typename traits<super_type>::point_type point_type; + typedef typename traits<super_type>::size_type size_type; + typedef ntg_return_type(plus, + oln_pw_value_type(L), + oln_pw_value_type(R)) value_type; }; template <typename L, typename R> - struct plus : public abstract::function < plus<L, R> > + struct plus : public abstract::binary_function < L, R, plus<L, R> > { typedef plus<L, R> self_type; @@ -58,42 +61,28 @@ typedef oln_pw_value_type(self_type) value_type; typedef oln_pw_size_type(self_type) size_type; - L left; - R right; + typedef abstract::binary_function<L, R, self_type> super_type; plus(const abstract::function<L>& left, const abstract::function<R>& right) : - left(left.exact()), - right(right.exact()) + super_type(left, right) { } - const size_type& impl_size() const - { - return this->left.size(); - } - const value_type impl_get(const point_type& p) const { return this->left(p) + this->right(p); } - bool impl_hold(const point_type& p) const - { - return this->left.hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - return this->left.hold_large(p); - } }; + } // end of namespace oln::pw } // end of namespace oln + /// Operator + on pwf template <typename L, typename R> @@ -109,20 +98,5 @@ oln_pw_operator(plus, +, float) oln_pw_operator(plus, +, double) -// template <typename L> -// oln::pw::plus<L, oln::pw::literal<int> > -// operator + (const oln::pw::abstract::function<L>& lhs, -// int value) -// { -// return lhs + oln::pw::literal<int>(value); -// } -// template <typename R> -// oln::pw::plus<oln::pw::literal<int>, R> -// operator + (int value, -// const oln::pw::abstract::function<R>& rhs) -// { -// return oln::pw::literal<int>(value) + rhs; -// } - #endif // ! OLENA_CORE_PW_PLUS_HH Index: oln/core/pw/macros.hh =================================================================== --- oln/core/pw/macros.hh (revision 0) +++ oln/core/pw/macros.hh (revision 0) @@ -0,0 +1,57 @@ +// 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_MACROS_HH +# define OLENA_CORE_PW_MACROS_HH + + + +# define oln_pw_point_type(F) typename oln::pw::traits<F>::point_type +# define oln_pw_value_type(F) typename oln::pw::traits<F>::value_type +# define oln_pw_size_type(F) typename oln::pw::traits<F>::size_type + + +// 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, \ + TYPE value) \ +{ \ + return lhs SYMBOL oln::pw::literal<TYPE>(value); \ +} \ +template <typename R> \ +oln::pw::NAME<oln::pw::literal<TYPE>, R> \ +operator SYMBOL (TYPE value, \ + const oln::pw::abstract::function<R>& rhs) \ +{ \ + return oln::pw::literal<TYPE>(value) SYMBOL rhs; \ +} + + + +#endif // ! OLENA_CORE_PW_MACROS_HH Index: oln/core/pw/abstract/function.hh =================================================================== --- oln/core/pw/abstract/function.hh (revision 107) +++ oln/core/pw/abstract/function.hh (working copy) @@ -30,13 +30,9 @@ # include <mlc/any.hh> # include <oln/core/properties.hh> +# include <oln/core/pw/macros.hh> -# define oln_pw_point_type(T) typename oln::pw::traits<T>::point_type -# define oln_pw_value_type(T) typename oln::pw::traits<T>::value_type -# define oln_pw_size_type(T) typename oln::pw::traits<T>::size_type - - namespace oln { @@ -91,7 +87,7 @@ return this->exact().impl_hold_large(p); } -// minus< literal<value_type>, E> operator-() const; + minus< literal<value_type>, E> operator-() const; protected: function() {} @@ -118,10 +114,11 @@ meth adr = &E::impl_hold_large; adr = 0; } - } + }; + } // end of namespace oln::pw::abstract } // end of namespace oln::pw Index: oln/core/pw/abstract/binary_function.hh =================================================================== --- oln/core/pw/abstract/binary_function.hh (revision 0) +++ oln/core/pw/abstract/binary_function.hh (revision 0) @@ -0,0 +1,150 @@ +// 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_ABSTRACT_BINARY_FUNCTION_HH +# define OLENA_CORE_PW_ABSTRACT_BINARY_FUNCTION_HH + +# include <oln/core/pw/abstract/function.hh> +# include <oln/core/abstract/point.hh> +# include <oln/core/abstract/size.hh> + + + +namespace oln { + + + namespace pw { // means "point-wise" + + + // fwd decls + namespace abstract { + template <typename L, typename R, typename E> struct binary_function; + } + + + template <typename L, typename R, typename E> + struct traits < abstract::binary_function<L, R, E> > + { + typedef oln_pw_point_type(L) left_point_type; + typedef oln_pw_point_type(R) right_point_type; + + typedef oln_point_type_from_2(left_point_type, right_point_type) point_type; + + typedef oln_pw_size_type(L) left_size_type; + typedef oln_pw_size_type(R) right_size_type; + + typedef oln_size_type_from_2(left_size_type, right_size_type) size_type; + }; + + + namespace abstract { + + namespace internal { + + template <typename T1, typename T2> + struct binary_function_helper; + + template <typename T> + struct binary_function_helper < T, T > { + template <typename L, typename R> + static const L& select(const L& l, R) { + return l; + } + }; + + template <typename S> + struct binary_function_helper < S, any_size > { + template <typename L, typename R> + static const L& select(const L& l, R) { + return l; + } + }; + + template <typename S> + struct binary_function_helper < any_size, S > { + template <typename L, typename R> + static const R& select(L, const R& r) { + return r; + } + }; + + } // end of namespace oln::pw::abstract::internal + + + template <typename L, typename R, typename E> + struct binary_function : public function<E> + { + typedef L left_type; + typedef R right_type; + + L left; + R right; + + binary_function(const abstract::function<L>& left, + const abstract::function<R>& right) : + left(left.exact()), + right(right.exact()) + { + } + + typedef abstract::binary_function<L, R, E> self_type; + typedef oln_pw_point_type(self_type) point_type; + typedef oln_pw_size_type(self_type) size_type; + + typedef internal::binary_function_helper<oln_pw_size_type(L), + oln_pw_size_type(R) > _helper_type; + + const size_type& impl_size() const + { + return _helper_type::select(this->left, this->right).size(); + } + + bool impl_hold(const point_type& p) const + { + return _helper_type::select(this->left, this->right).hold(p); + } + + bool impl_hold_large(const point_type& p) const + { + return _helper_type::select(this->left, this->right).hold_large(p); + } + + protected: + binary_function() {} + + }; + + + } // end of namespace oln::pw::abstract + + } // end of namespace oln::pw + +} // end of namespace oln + + + +#endif // ! OLENA_CORE_PW_ABSTRACT_BINARY_FUNCTION_HH Index: oln/core/pw/minus.hh =================================================================== --- oln/core/pw/minus.hh (revision 107) +++ oln/core/pw/minus.hh (working copy) @@ -28,7 +28,7 @@ #ifndef OLENA_CORE_PW_MINUS_HH # define OLENA_CORE_PW_MINUS_HH -# include <oln/core/pw/abstract/function.hh> +# include <oln/core/pw/abstract/binary_function.hh> # include <oln/core/pw/literal.hh> # include <ntg/all.hh> @@ -44,13 +44,16 @@ template <typename L, typename R> struct traits < minus<L, R> > { - typedef oln_pw_point_type(L) point_type; - typedef ntg_return_type(minus, oln_pw_value_type(L), oln_pw_value_type(R)) value_type; - typedef oln_pw_size_type(L) size_type; + typedef abstract::binary_function<L, R, minus<L, R> > super_type; + typedef typename traits<super_type>::point_type point_type; + typedef typename traits<super_type>::size_type size_type; + typedef ntg_return_type(minus, + oln_pw_value_type(L), + oln_pw_value_type(R)) value_type; }; template <typename L, typename R> - struct minus : public abstract::function < minus<L, R> > + struct minus : public abstract::binary_function < L, R, minus<L, R> > { typedef minus<L, R> self_type; @@ -58,52 +61,37 @@ typedef oln_pw_value_type(self_type) value_type; typedef oln_pw_size_type(self_type) size_type; - L left; - R right; + typedef abstract::binary_function<L, R, self_type > super_type; minus(const abstract::function<L>& left, - const abstract::function<R>& right) : - left(left.exact()), - right(right.exact()) + const abstract::function<R>& right) : + super_type(left, right) { } - const size_type& impl_size() const - { - return this->left.size(); - } - const value_type impl_get(const point_type& p) const { return this->left(p) - this->right(p); } - bool impl_hold(const point_type& p) const - { - return this->left.hold(p); - } - - bool impl_hold_large(const point_type& p) const - { - return this->left.hold_large(p); - } - }; // FIXME: uncomment? -// namespace abstract { + namespace abstract { -// template <typename E> -// minus< literal<oln_pw_value_type(E)>, E> -// function<E>::operator-() const -// { -// literal<oln_pw_value_type(E)> lhs(0); -// return lhs - *this; -// } + template <typename E> + minus< literal<oln_pw_value_type(E)>, E> + function<E>::operator-() const + { + typedef literal<oln_pw_value_type(E)> lit_type; + static const lit_type lhs = 0; + minus< lit_type, E> tmp(lhs, this->exact()); + return tmp; + } -// } + } } // end of namespace oln::pw @@ -122,6 +110,9 @@ 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/literal.hh =================================================================== --- oln/core/pw/literal.hh (revision 107) +++ oln/core/pw/literal.hh (working copy) @@ -99,22 +99,6 @@ } // end of namespace oln -# 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, \ - TYPE value) \ -{ \ - return lhs SYMBOL oln::pw::literal<TYPE>(value); \ -} \ -template <typename R> \ -oln::pw::NAME<oln::pw::literal<TYPE>, R> \ -operator SYMBOL (TYPE value, \ - const oln::pw::abstract::function<R>& rhs) \ -{ \ - return oln::pw::literal<TYPE>(value) SYMBOL rhs; \ -} - #endif // ! OLENA_CORE_PW_LITERAL_HH Index: oln/core/any/dpoint.hh =================================================================== --- oln/core/any/dpoint.hh (revision 107) +++ oln/core/any/dpoint.hh (working copy) @@ -28,6 +28,7 @@ #ifndef OLENA_CORE_ANY_DPOINT_HH # define OLENA_CORE_ANY_DPOINT_HH +# include <iostream> # include <oln/core/abstract/dpoint.hh> # include <oln/core/any/point.hh> @@ -35,6 +36,13 @@ namespace oln { + // fwd decls + struct any_point; + namespace abstract { + template <typename P> struct point; + } + + struct any_dpoint : public abstract::dpoint < any_dpoint > { Index: oln/core/abstract/point.hh =================================================================== --- oln/core/abstract/point.hh (revision 107) +++ oln/core/abstract/point.hh (working copy) @@ -29,21 +29,30 @@ # define OLENA_CORE_ABSTRACT_POINT_HH # include <mlc/any.hh> -# include <mlc/bool.hh> - +# include <oln/core/coord.hh> # include <oln/core/properties.hh> +# include <mlc/properties.hh> // FIXME: for better 'meta if' and 'meta eq' +// fwd decl +namespace oln { + struct any_point; +} + + + +# define oln_point_type_from_2(P1, P2) \ +mlc_internal_if( mlc_internal_eq( P2, oln::any_point ), P1, P2 ) + + + /*! \namespace oln ** \brief oln namespace. */ namespace oln { - // fwd decls - - struct any_point; - + // fwd decl namespace abstract { template <typename E> struct point; } @@ -93,9 +102,7 @@ typedef E exact_type; - /// Conversion to any_point (implemented in oln/core/any/point.hh). - operator any_point() const; @@ -139,6 +146,12 @@ return this->exact().impl_minus(rhs); } + coord_t nth(unsigned i) const + { + // FIXME: add precondition + return this->exact().impl_nth(i); + } + protected: point() {} Index: oln/core/abstract/witer.hh =================================================================== --- oln/core/abstract/witer.hh (revision 107) +++ oln/core/abstract/witer.hh (working copy) @@ -30,7 +30,7 @@ # include <mlc/any.hh> # include <mlc/types.hh> - +# include <oln/core/coord.hh> # include <oln/core/properties.hh> # include <string> Index: oln/core/abstract/dpoint.hh =================================================================== --- oln/core/abstract/dpoint.hh (revision 107) +++ oln/core/abstract/dpoint.hh (working copy) @@ -28,8 +28,10 @@ #ifndef OLENA_CORE_ABSTRACT_DPOINT_HH # define OLENA_CORE_ABSTRACT_DPOINT_HH +# include <oln/core/coord.hh> # include <mlc/any.hh> + /*! \namespace oln ** \brief oln namespace. */ @@ -67,6 +69,7 @@ coord_t nth(unsigned i) const { + // FIXME: add precondition return this->exact().impl_nth(i); } Index: oln/core/abstract/size.hh =================================================================== --- oln/core/abstract/size.hh (revision 107) +++ oln/core/abstract/size.hh (working copy) @@ -29,9 +29,22 @@ # define OLENA_CORE_ABSTRACT_SIZE_HH # include <mlc/any.hh> +# include <mlc/properties.hh> // FIXME: for better 'meta if' and 'meta eq' + +// fwd decl namespace oln { + struct any_size; +} + +# define oln_size_type_from_2(S1, S2) \ +mlc_internal_if( mlc_internal_eq( S2, oln::any_size ), S1, S2 ) + + + +namespace oln { + namespace abstract { @@ -70,8 +83,4 @@ -# include <oln/core/any/size.hh> - - - #endif // ! OLENA_CORE_ABSTRACT_SIZE_HH Index: oln/core/1d/dpoint1d.hh =================================================================== --- oln/core/1d/dpoint1d.hh (revision 107) +++ oln/core/1d/dpoint1d.hh (working copy) @@ -29,22 +29,15 @@ # define OLENA_CORE_1D_DPOINT1D_HH # include <ostream> - # include <oln/core/coord.hh> +# include <oln/core/abstract/dpoint.hh> -// FIXME: there's an assumption here: we do not need inheritance for -// dpoints. so abstract::dpoint does not exist... -// FIXME: doc! - -// FIXME: test that coords are defined - - namespace oln { struct point1d; - struct dpoint1d + struct dpoint1d : public abstract::dpoint < dpoint1d > { dpoint1d() { @@ -95,6 +88,13 @@ const coord_t index() const { return index_; } coord_t& index() { return index_; } + coord_t impl_nth(unsigned i) const + { + // FIXME: remove when add in abstract::point + precondition(i == 0); + return index_; + } + protected: coord_t index_; }; Index: oln/core/1d/point1d.hh =================================================================== --- oln/core/1d/point1d.hh (revision 107) +++ oln/core/1d/point1d.hh (working copy) @@ -103,6 +103,13 @@ return this->index_ == rhs.index_; } + coord_t impl_nth(unsigned i) const + { + // FIXME: remove when add in abstract::point + precondition(i == 0); + return index_; + } + protected: coord_t index_; Index: oln/core/2d/dpoint2d.hh =================================================================== --- oln/core/2d/dpoint2d.hh (revision 107) +++ oln/core/2d/dpoint2d.hh (working copy) @@ -29,19 +29,15 @@ # define OLENA_CORE_2D_DPOINT2D_HH # include <iostream> - # include <oln/core/coord.hh> +# include <oln/core/abstract/dpoint.hh> -// FIXME: there's an assumption here: we do not need inheritance for -// dpoints. so abstract::dpoint does not exist... -// FIXME: doc! - namespace oln { struct point2d; - struct dpoint2d + struct dpoint2d : public abstract::dpoint < dpoint2d > { dpoint2d() { @@ -108,8 +104,8 @@ coord_t& row() { return row_; } coord_t& col() { return col_; } - //FIXME : name it impl_nth when dpoint2d derives from abstract::dpoint - coord_t& nth(unsigned i) + + coord_t& impl_nth(unsigned i) { assert(i < 2); Index: oln/core/2d/point2d.hh =================================================================== --- oln/core/2d/point2d.hh (revision 107) +++ oln/core/2d/point2d.hh (working copy) @@ -107,6 +107,14 @@ return this->row_ == rhs.row_ && this->col_ == rhs.col_; } + coord_t impl_nth(unsigned i) const + { + // FIXME: remove when add in abstract::point + precondition(i < 2); + // FIXME: replace by meta-prog when a meta-vec is attribute + return i == 0 ? row_ : col_; + } + protected: coord_t row_, col_; Index: oln/core/3d/dpoint3d.hh =================================================================== --- oln/core/3d/dpoint3d.hh (revision 107) +++ oln/core/3d/dpoint3d.hh (working copy) @@ -29,19 +29,15 @@ # define OLENA_CORE_3D_DPOINT3D_HH # include <iostream> - # include <oln/core/coord.hh> +# include <oln/core/abstract/dpoint.hh> -// FIXME: there's an assumption here: we do not need inheritance for -// dpoints. so abstract::dpoint does not exist... -// FIXME: doc! - namespace oln { struct point3d; - struct dpoint3d + struct dpoint3d : public abstract::dpoint < dpoint3d > { dpoint3d() { @@ -103,6 +99,23 @@ coord_t& col() { return col_; } coord_t& slice() { return slice_; } + coord_t impl_nth(unsigned i) const + { + // FIXME: remove when add in abstract::point + precondition(i < 3); + // FIXME: replace by meta-prog when a meta-vec is attribute + switch (i) { + case 0: + return slice_; + case 1: + return row_; + case 2: + return col_; + } + postcondition(0); + return 0; + } + protected: coord_t slice_, row_, col_; }; Index: oln/core/3d/point3d.hh =================================================================== --- oln/core/3d/point3d.hh (revision 107) +++ oln/core/3d/point3d.hh (working copy) @@ -103,6 +103,23 @@ coord_t& row() { return row_; } coord_t& col() { return col_; } + coord_t impl_nth(unsigned i) const + { + // FIXME: remove when add in abstract::point + precondition(i < 3); + // FIXME: replace by meta-prog when a meta-vec is attribute + switch (i) { + case 0: + return slice_; + case 1: + return row_; + case 2: + return col_; + } + postcondition(0); + return 0; + } + protected: coord_t slice_, row_, col_; }; Index: oln/makefile.src =================================================================== --- oln/makefile.src (revision 107) +++ oln/makefile.src (working copy) @@ -7,6 +7,7 @@ all.hh \ arith/max.hh \ arith/min.hh \ + arith/ops.hh \ basics.hh \ basics1d.hh \ basics2d.hh \ @@ -63,17 +64,20 @@ core/any/point.hh \ core/any/size.hh \ core/apply.hh \ + core/box.hh \ core/ch_value_type.hh \ core/compose.hh \ core/coord.hh \ core/gen/identity.hh \ core/properties.hh \ + core/pw/abstract/binary_function.hh \ core/pw/abstract/function.hh \ core/pw/all.hh \ core/pw/cmp.hh \ core/pw/div.hh \ core/pw/image.hh \ core/pw/literal.hh \ + core/pw/macros.hh \ core/pw/minus.hh \ core/pw/plus.hh \ core/pw/times.hh \ @@ -88,9 +92,13 @@ io/write_image_2d_pnm.hh \ level/compare.hh \ level/fill.hh \ + morpho/cc_tarjan.hh \ morpho/dilation.hh \ morpho/erosion.hh \ morpho/reconstruction.hh \ morpho/splitse.hh \ morpho/stat.hh \ - utils/clone.hh + utils/buffer.hh \ + utils/clone.hh \ + utils/key.hh \ + utils/md5.hh Index: oln/arith/ops.hh =================================================================== --- oln/arith/ops.hh (revision 0) +++ oln/arith/ops.hh (revision 0) @@ -0,0 +1,133 @@ +// 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_OPS_HH +# define OLENA_ARITH_OPS_HH + +# include <oln/core/abstract/image.hh> +# include <oln/core/pw/all.hh> + + +/// Operator + between 2 images. + +template <typename L, typename R> +oln::image_from_pw< oln::pw::plus< oln::pw::image<L>, + oln::pw::image<R> > > +operator + (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::for_all_p(oln::p_value(lhs) + oln::p_value(rhs)); +} + + +/// Operator - between 2 images. + +template <typename L, typename R> +oln::image_from_pw< oln::pw::minus< oln::pw::image<L>, + oln::pw::image<R> > > +operator - (const oln::abstract::image<L>& lhs, + const oln::abstract::image<R>& rhs) +{ + return oln::for_all_p(oln::p_value(lhs) - oln::p_value(rhs)); +} + + +/// Operator - (unary) on image. + +template <typename R> +oln::image_from_pw< oln::pw::minus< oln::pw::literal< oln_pw_value_type(R) >, + oln::pw::image<R> > > +operator - (const oln::abstract::image<R>& rhs) +{ + return oln::for_all_p( - oln::p_value(rhs)); +} + + +/// 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, + const oln::abstract::image<R>& rhs) +{ + return oln::for_all_p(oln::p_value(lhs) * oln::p_value(rhs)); +} + + +/// 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, + const oln::abstract::image<R>& rhs) +{ + return oln::for_all_p(oln::p_value(lhs) / oln::p_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::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::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) + + + +#endif // ! OLENA_ARITH_OPS_HH
participants (2)
-
Damien Thivolle
-
Thierry GERAUD