
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Provide more suitable niter classes. * oln/core/gen/niter_has.hh: New. * oln/debug/print_nbh.hh (impl): Remove; useless. * oln/core/concept/image.hh (Image_with_Nbh): Overload nbhood access. * oln/core/concept/image_identity.hh: Update. * oln/core/equipment.hh (oln_pset): New. * oln/core/internal/piter_adaptor.hh (point): Set final. * oln/core/internal/op_pset_such_as_fp2b.hh (point): Remove. * oln/core/internal/op_image_plus_nbh.hh (include): Update. (fwd_niter, bkd_niter): Update. core/concept/image.hh | 12 ++- core/concept/image_identity.hh | 12 ++- core/equipment.hh | 1 core/gen/niter_has.hh | 126 ++++++++++++++++++++++++++++++++++ core/internal/op_image_plus_nbh.hh | 22 ++++- core/internal/op_pset_such_as_fp2b.hh | 1 core/internal/piter_adaptor.hh | 4 - debug/print_nbh.hh | 38 ---------- 8 files changed, 168 insertions(+), 48 deletions(-) Index: oln/debug/print_nbh.hh --- oln/debug/print_nbh.hh (revision 895) +++ oln/debug/print_nbh.hh (working copy) @@ -45,14 +45,10 @@ # ifndef OLN_INCLUDE_ONLY - namespace impl - { - - // Image + // Generic version. template <typename I> - void print_nbh(const Image<I>&, - const I& input, std::ostream& ostr) + void print_nbh(const Image_with_Nbh<I>& input, std::ostream& ostr = std::cout) { oln_piter(I) p(input.points()); oln_niter(I) n(p, input); @@ -60,41 +56,11 @@ { ostr << input(p) << ": "; for_all(n) - if (input.owns_(n)) ostr << input(n) << " "; ostr << std::endl; } } - - // Point_Wise_Accessible_Image - - template <typename I> - void print_nbh(const Point_Wise_Accessible_Image<I>&, - const I& input, std::ostream& ostr) - { - oln_piter(I) p(input.points()); - oln_niter(I) n(p, input); - for_all(p) - { - ostr << input(p) << ": "; - for_all(n) - if (input.has(n)) - ostr << input(n) << " "; - ostr << std::endl; - } - } - - } // end of namespace oln::debug::impl - - - // facade - template <typename I> - void print_nbh(const Image_with_Nbh<I>& input, std::ostream& ostr) - { - impl::print_nbh(exact(input), exact(input), ostr); - } - # endif // ! OLN_INCLUDE_ONLY Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 895) +++ oln/core/concept/image.hh (working copy) @@ -156,7 +156,8 @@ stc_typename(bkd_niter); typedef fwd_niter niter; - nbh nbhood() const; + const nbh& nbhood() const; + nbh& nbhood(); protected: Image_with_Nbh(); @@ -458,13 +459,20 @@ // ----------------------------------- Image_with_Nbh<Exact> template <typename Exact> - typename Image_with_Nbh<Exact>::nbh + const typename Image_with_Nbh<Exact>::nbh& Image_with_Nbh<Exact>::nbhood() const { return exact(this)->impl_nbhood(); } template <typename Exact> + typename Image_with_Nbh<Exact>::nbh& + Image_with_Nbh<Exact>::nbhood() + { + return exact(this)->impl_nbhood(); + } + + template <typename Exact> Image_with_Nbh<Exact>::Image_with_Nbh() { } Index: oln/core/concept/image_identity.hh --- oln/core/concept/image_identity.hh (revision 895) +++ oln/core/concept/image_identity.hh (working copy) @@ -64,7 +64,8 @@ struct set_impl< Image_with_Nbh, behavior::identity, Exact > : public virtual Any<Exact> { stc_typename(nbh); - nbh impl_nbhood() const; + const nbh& impl_nbhood() const; + nbh& impl_nbhood(); }; @@ -211,12 +212,19 @@ /// Concept-class "Image_with_Nbh". template <typename Exact> - typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh + const typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh& set_impl< Image_with_Nbh, behavior::identity, Exact >::impl_nbhood() const { return exact(this)->image().nbhood(); } + template <typename Exact> + typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh& + set_impl< Image_with_Nbh, behavior::identity, Exact >::impl_nbhood() + { + return exact(this)->image().nbhood(); + } + /// Concept-class "Image_with_Border". Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 895) +++ oln/core/equipment.hh (working copy) @@ -123,6 +123,7 @@ # define oln_piter(T) oln_typename_shortcut__(T, piter) # define oln_plain(T) oln_typename_shortcut__(T, plain) # define oln_point(T) oln_typename_shortcut__(T, point) +# define oln_pset(T) oln_typename_shortcut__(T, pset) // q stc_decl_associated_type( qiter ); Index: oln/core/gen/niter_has.hh --- oln/core/gen/niter_has.hh (revision 0) +++ oln/core/gen/niter_has.hh (revision 0) @@ -0,0 +1,126 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_NITER_HAS_HH +# define OLN_CORE_GEN_NITER_HAS_HH + +# include <oln/core/internal/piter_adaptor.hh> +# include <oln/core/gen/dpoints_piter.hh> + + +namespace oln +{ + + +# define current niter_has_<It, Ps> + // -------------------- + +# define super internal::piter_adaptor_< current > + + + // Fwd decl. + template <typename It, typename Ps> class niter_has_; + + + // Super type. + template <typename It, typename Ps> + struct super_trait_< current > + { + typedef super ret; + }; + + + // Virtual type. + template <typename It, typename Ps> + struct vtypes< current > + { + typedef It adapted; + }; + + + // Forward point iterator class on a set of dpoints. + template <typename It, typename Ps> + class niter_has_ : public super + { + public: + + // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points). + + template <typename Pl, typename I> + niter_has_(const Pl& p, const Image_with_Nbh<I>& ima); + + void impl_start(); + void impl_next(); + + protected: + + const Ps pset_; + + }; // end of class oln::niter_has_<P> + + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename It, typename Ps> + template <typename Pl, typename I> + current::niter_has_(const Pl& p, const Image_with_Nbh<I>& ima) + : + super( It(p, ima) ), + pset_( ima.points() ) + { + } + + template <typename It, typename Ps> + void + current::impl_start() + { + this->p_.start(); + while (this->p_.is_valid() and not this->pset_.has(this->p_)) + this->p_.next(); + } + + template <typename It, typename Ps> + void + current::impl_next() + { + do + this->p_.next(); + while (this->p_.is_valid() and not this->pset_.has(this->p_)); + } + +# endif // ! OLN_INCLUDE_ONLY + +# undef super +# undef current + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_NITER_HAS_HH Index: oln/core/internal/op_pset_such_as_fp2b.hh --- oln/core/internal/op_pset_such_as_fp2b.hh (revision 895) +++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy) @@ -64,7 +64,6 @@ template <typename S, typename F> struct vtypes< internal::current > { - typedef typename S::point point; typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter; typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter; }; Index: oln/core/internal/piter_adaptor.hh --- oln/core/internal/piter_adaptor.hh (revision 895) +++ oln/core/internal/piter_adaptor.hh (working copy) @@ -51,8 +51,10 @@ template <typename Exact> struct vtypes< internal::piter_adaptor_<Exact> > { - typedef stc::abstract point; typedef stc::abstract adapted; + + typedef stc_deferred(adapted) adapted__; + typedef stc::final< oln_point(adapted__) > point; }; Index: oln/core/internal/op_image_plus_nbh.hh --- oln/core/internal/op_image_plus_nbh.hh (revision 895) +++ oln/core/internal/op_image_plus_nbh.hh (working copy) @@ -29,9 +29,10 @@ # define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH # include <oln/core/concept/neighborhood.hh> +# include <oln/core/internal/image_base.hh> # include <oln/core/gen/op.hh> # include <oln/core/gen/dpoints_piter.hh> -# include <oln/core/internal/image_base.hh> +# include <oln/core/gen/niter_has.hh> namespace oln @@ -62,14 +63,15 @@ struct vtypes< internal::current > { typedef op_<I, plus, N> Exact; - typedef stc_type(I, point) point__; typedef I delegatee; typedef internal::pair<I,N> data; typedef N nbh; - typedef dpoints_fwd_piter_<point__> fwd_niter; - typedef dpoints_bkd_piter_<point__> bkd_niter; + + // FIXME: Wrong! + typedef niter_has_< dpoints_fwd_piter_<oln_point(I)>, oln_pset(I) > fwd_niter; + typedef niter_has_< dpoints_bkd_piter_<oln_point(I)>, oln_pset(I) > bkd_niter; typedef op_<oln_plain(I), plus, N> plain; typedef op_<pl::rec<I>, plus, N> skeleton; @@ -96,7 +98,7 @@ delegatee& impl_image(); const delegatee& impl_image() const; - nbh impl_nbhood() const; + const nbh& impl_nbhood() const; nbh& impl_nbhood(); protected: @@ -160,13 +162,21 @@ } template <typename I, typename N> - typename current::nbh + const typename current::nbh& current::impl_nbhood() const { assert(this->has_data()); return this->data_->second; } + template <typename I, typename N> + typename current::nbh& + current::impl_nbhood() + { + assert(this->has_data()); + return this->data_->second; + } + } // end of namespace oln::internal