899: Add type of 'image such_as f:b->p' and factor Image::has as final.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add type of 'image such_as f:b->p' and factor Image::has as final. * tests/core/neighb2d.cc: Fix. * oln/core/internal/op_image_such_as_fp2b.hh: New. * oln/core/gen/pset_such_as.hh: Remove; obsolete. * oln/core/concept/image.hh (has): New final impl. (Point_Wise_Accessible_Image): Remove get_impl inheritance. * oln/core/concept/image_identity.hh: Update. * oln/core/rle/rle_image.hh, * oln/core/sparse/sparse_image.hh, * oln/core/1d/image1d.hh, * oln/core/1d/image1d_b.hh, * oln/core/2d/image2d.hh, * oln/core/2d/image2d_b.hh, * oln/core/gen/single_value_image.hh (impl_has): Remove. * oln/core/internal/op_pset_such_as_fp2b.hh (point): New vtype. (point): Remove this vtype from iterators. * oln/core/internal/point_set_base.hh: Cosmetic. * oln/core/internal/op_image_restricted_to_pset.hh: Cosmetic. * oln/core/internal/image_base.hh (oln_decl_op_such_as): New version for "Image such_as Function_p2b". (operator |): New specialization for C functions. oln/core/1d/image1d.hh | 9 - oln/core/1d/image1d_b.hh | 9 - oln/core/2d/image2d.hh | 8 - oln/core/2d/image2d_b.hh | 10 -- oln/core/concept/image.hh | 7 - oln/core/concept/image_identity.hh | 20 ---- oln/core/gen/single_value_image.hh | 9 - oln/core/internal/image_base.hh | 22 ++++ oln/core/internal/op_image_restricted_to_pset.hh | 11 -- oln/core/internal/op_image_such_as_fp2b.hh | 114 +++++++++++++++++++++++ oln/core/internal/op_pset_such_as_fp2b.hh | 11 +- oln/core/internal/point_set_base.hh | 3 oln/core/rle/rle_image.hh | 9 - oln/core/sparse/sparse_image.hh | 8 - tests/core/neighb2d.cc | 2 15 files changed, 151 insertions(+), 101 deletions(-) Index: tests/core/neighb2d.cc --- tests/core/neighb2d.cc (revision 898) +++ tests/core/neighb2d.cc (working copy) @@ -38,7 +38,7 @@ unsigned run(const oln::Image_with_Nbh<I>& input) { oln_piter(I) p(input.points()); - oln_niter(I) n(p, input.nbhood()); + oln_niter(I) n(p, input); unsigned count = 0; for_all(p) Index: oln/core/rle/rle_image.hh --- oln/core/rle/rle_image.hh (revision 898) +++ oln/core/rle/rle_image.hh (working copy) @@ -98,8 +98,6 @@ /// pset impl_points() const : return image pset pset impl_points() const; - /// bool impl_has(const point& p) const : rle_image has p? - bool impl_has(const point& p) const; /// bool impl_owns_(const psite& p) const : same has impl_has bool impl_owns_(const psite& p) const; /// void insert(const point& p, unsigned len, value val) : insert a new range on the image @@ -128,13 +126,6 @@ template <typename P, typename T> bool - rle_image<P, T>::impl_has(const typename rle_image<P, T>::point& p) const - { - return this->data_->first.has(p); - } - - template <typename P, typename T> - bool rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const { return this->data_->first.has(p.start_); Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 898) +++ oln/core/concept/image.hh (working copy) @@ -217,11 +217,11 @@ /// Concept-class "Point_Wise_Accessible_Image". template <typename Exact> - struct Point_Wise_Accessible_Image : public virtual Image<Exact>, - public automatic::get_impl<Point_Wise_Accessible_Image, Exact> + struct Point_Wise_Accessible_Image : public virtual Image<Exact> { stc_using_from(Image, point); + // final bool has(const point& p) const; protected: @@ -512,7 +512,8 @@ bool Point_Wise_Accessible_Image<Exact>::has(const typename Point_Wise_Accessible_Image<Exact>::point& p) const { - return exact(this)->impl_has(p); + // FIXME: precondition(this->owns_(p)); ? + return this->points().has(p); } template <typename Exact> Index: oln/core/concept/image_identity.hh --- oln/core/concept/image_identity.hh (revision 898) +++ oln/core/concept/image_identity.hh (working copy) @@ -104,16 +104,6 @@ }; - /// Concept-class "Point_Wise_Accessible_Image". - - template <typename Exact> - struct set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact > : public virtual Any<Exact> - { - stc_typename(point); - bool impl_has(const point& p) const; - }; - - /// Concept-class "Value_Wise_Accessible_Image". template <typename Exact> @@ -270,16 +260,6 @@ } - /// Concept-class "Point_Wise_Accessible_Image". - - template <typename Exact> - bool - set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact >::impl_has(const typename set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact >::point& p) const - { - return exact(this)->image().has(p); - } - - /// Concept-class "Value_Wise_Accessible_Image". template <typename Exact> Index: oln/core/sparse/sparse_image.hh --- oln/core/sparse/sparse_image.hh (revision 898) +++ oln/core/sparse/sparse_image.hh (working copy) @@ -83,7 +83,6 @@ sparse_image(); pset impl_points() const; - bool impl_has(const point& p) const; bool impl_owns_(const psite& p) const; void insert(const point& p, unsigned len, const std::vector<value>& val); rvalue impl_read(const psite& p) const; @@ -109,13 +108,6 @@ template <typename P, typename T> bool - sparse_image<P, T>::impl_has(const typename sparse_image<P, T>::point& p) const - { - return this->data_->first.has(p); - } - - template <typename P, typename T> - bool sparse_image<P, T>::impl_owns_(const typename sparse_image<P, T>::psite& p) const { return this->data_->first.has(p.start_); Index: oln/core/1d/image1d.hh --- oln/core/1d/image1d.hh (revision 898) +++ oln/core/1d/image1d.hh (working copy) @@ -87,8 +87,6 @@ bool impl_owns_(const point1d& p) const; - bool impl_has(const point1d& p) const; - const T& impl_read(const point1d& p) const; const T& impl_index_read(unsigned i) const; @@ -130,13 +128,6 @@ } template <typename T> - bool image1d<T>::impl_has(const point1d& p) const - { - assert(this->has_data()); - return this->data_->has(p.ind()); - } - - template <typename T> const T& image1d<T>::impl_read(const point1d& p) const { assert(this->has_data()); Index: oln/core/1d/image1d_b.hh --- oln/core/1d/image1d_b.hh (revision 898) +++ oln/core/1d/image1d_b.hh (working copy) @@ -97,8 +97,6 @@ bool impl_owns_(const point1d& p) const; - bool impl_has(const point1d& p) const; - const T& impl_read(const point1d& p) const; const T& impl_index_read(unsigned i) const; @@ -148,13 +146,6 @@ } template <typename T> - bool image1d_b<T>::impl_has(const point1d& p) const - { - assert(this->has_data()); - return this->data_->third.has(p); - } - - template <typename T> const T& image1d_b<T>::impl_read(const point1d& p) const { assert(this->has_data()); Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 898) +++ oln/core/2d/image2d.hh (working copy) @@ -87,7 +87,6 @@ bool impl_owns_(const point2d& p) const; - bool impl_has(const point2d& p) const; bool impl_has_at(int row, int col) const; const T& impl_read(const point2d& p) const; @@ -136,13 +135,6 @@ } template <typename T> - bool image2d<T>::impl_has(const point2d& p) const - { - assert(this->has_data()); - return this->data_->has(p.row(), p.col()); - } - - template <typename T> bool image2d<T>::impl_has_at(int row, int col) const { assert(this->has_data()); Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 898) +++ oln/core/2d/image2d_b.hh (working copy) @@ -135,7 +135,6 @@ bool impl_owns_(const point2d& p) const; - bool impl_has(const point2d& p) const; bool impl_has_at(int row, int col) const; const T& impl_read(const point2d& p) const; @@ -188,17 +187,10 @@ } template <typename T> - bool image2d_b<T>::impl_has(const point2d& p) const - { - assert(this->has_data()); - return this->data_->box.has(p); - } - - template <typename T> bool image2d_b<T>::impl_has_at(int row, int col) const { assert(this->has_data()); - return this->data_->box.has(point2d(row, col)); + return this->data_->array.has(row, col); } template <typename T> Index: oln/core/gen/single_value_image.hh --- oln/core/gen/single_value_image.hh (revision 898) +++ oln/core/gen/single_value_image.hh (working copy) @@ -89,7 +89,6 @@ single_value_image(const Ps& ps, const T& val); bool impl_owns_(const point& p) const; - bool impl_has (const point& p) const; rvalue impl_read(const point&) const; @@ -124,14 +123,6 @@ } template <typename Ps, typename T> - bool - single_value_image<Ps, T>::impl_has(const typename single_value_image<Ps, T>::point& p) const - { - assert(this->has_data()); - return this->data_->first.has(p); - } - - template <typename Ps, typename T> typename single_value_image<Ps, T>::rvalue single_value_image<Ps, T>::impl_read(const typename single_value_image<Ps, T>::point&) const { Index: oln/core/internal/op_pset_such_as_fp2b.hh --- oln/core/internal/op_pset_such_as_fp2b.hh (revision 898) +++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy) @@ -42,7 +42,7 @@ special_op_< stc::is<Point_Set>, S, such_as, stc::is<Function_p2b>, F > - /// Fwd decls. + // Fwd decls. namespace internal { template <typename S, typename F> class current; @@ -52,7 +52,7 @@ - /// Super type. + // Super type. template <typename S, typename F> struct super_trait_< internal::current > { @@ -60,10 +60,11 @@ }; - /// Virtual types. + // Virtual types. template <typename S, typename F> struct vtypes< internal::current > { + typedef oln_point(S) point; typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter; typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter; }; @@ -72,7 +73,7 @@ namespace internal { - /// Implementation class the result of "Point_Set S | Function_p2b F". + /// Implementation class for the result of "Point_Set S | Function_p2b F". template <typename S, typename F> class current @@ -197,7 +198,6 @@ template <typename S, typename F> struct vtypes< current > { - typedef typename S::point point; typedef typename S::fwd_piter adapted; }; @@ -274,7 +274,6 @@ template <typename S, typename F> struct vtypes< current > { - typedef typename S::point point; typedef typename S::fwd_piter adapted; }; Index: oln/core/internal/op_image_such_as_fp2b.hh --- oln/core/internal/op_image_such_as_fp2b.hh (revision 0) +++ oln/core/internal/op_image_such_as_fp2b.hh (revision 0) @@ -0,0 +1,114 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH +# define OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH + +# include <oln/core/internal/op_image_restricted_to_pset.hh> +# include <oln/core/internal/op_pset_such_as_fp2b.hh> + + +namespace oln +{ + + +# define current \ + special_op_< stc::is<Image>, I, such_as, stc::is<Function_p2b>, F > + + + // Fwd decl. + namespace internal { template <typename I, typename F> class current; } + + + // Super type. + template <typename I, typename F> + struct super_trait_< internal::current > + { + typedef op_< const oln_pset(I), such_as, F > S; + typedef internal::special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, const S > ret; + }; + + +# define super \ + super_trait_< internal::current >::ret + + + // Virtual types. + template <typename I, typename F> + struct vtypes< internal::current > + { + }; + + + namespace internal + { + + /// Implementation class for the result of "Image I | Function_p2b F". + + template <typename I, typename F> + class current : public super + { + public: + + stc_using(point); + stc_using(box); + + protected: + special_op_(); + special_op_(I& ima, F& f); + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename I, typename F> + current::special_op_() + { + } + + template <typename I, typename F> + current::special_op_(I& ima, F& f) + : super(ima, (ima.points() | f)) + { + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::internal + + + // Fixme: Activate init + + +# undef super +# undef current + + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 898) +++ oln/core/internal/point_set_base.hh (working copy) @@ -111,8 +111,7 @@ template <typename S, typename B, typename P> op_<const S, such_as, const fun_p2b_<B (*)(P)> > - operator | (const Point_Set<S>& lhs, - B (*f)(P)) + operator | (const Point_Set<S>& lhs, B (*f)(P)) { typedef oln_strip_(P) P_; mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. Index: oln/core/internal/op_image_restricted_to_pset.hh --- oln/core/internal/op_image_restricted_to_pset.hh (revision 898) +++ oln/core/internal/op_image_restricted_to_pset.hh (working copy) @@ -40,12 +40,7 @@ special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S > -// /// Fwd decls. -// template <typename Exact> struct Image; -// template <typename Exact> struct Point_Set; - - - /// Super type. + // Super type. template <typename I, typename S> struct super_trait_< internal::current > { @@ -53,7 +48,7 @@ }; - /// Virtual types. + // Virtual types. template <typename I, typename S> struct vtypes< internal::current > { @@ -73,7 +68,7 @@ namespace internal { - /// Implementation class the result of "Image I | Point_Set S". + /// Implementation class for the result of "Image I | Point_Set S". template <typename I, typename S> class special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S > Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 898) +++ oln/core/internal/image_base.hh (working copy) @@ -477,11 +477,33 @@ # include <oln/core/internal/f_ch_value.hh> # include <oln/core/internal/op_image_restricted_to_pset.hh> +# include <oln/core/internal/op_image_such_as_fp2b.hh> namespace oln { + // Image | Point_Set ( ima restricted_to pset ) + oln_decl_op_restricted_to(Image, Point_Set); + + // Image | Function_p2b ( ima such_as "f : p -> b" + // is ima restricted_to (ima.points such_as f) ) + oln_decl_op_such_as(Image, Function_p2b); + + + // Specialization. + + template <typename I, typename B, typename P> + op_<const I, such_as, const fun_p2b_<B (*)(P)> > + operator | (const Image<I>& ima, B (*f)(P)) + { + typedef oln_strip_(P) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. + mlc::assert_equal_< P_, oln_point(I) >::check(); + op_<const I, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(ima), f); + return tmp; + } + } // end of namespace oln /// \}
participants (1)
-
Thierry Geraud