milena r1159: Change image_adaptor inheritance to morphers inheritance

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-24 Matthieu Garrigues <garrigues@lrde.epita.fr> Change image_adaptor inheritance to morphers inheritance. * mln/core/decorated_image.hh: Inherit from identity morpher. * mln/core/image_if.hh: Inherit from domain morpher. Move destroy method to the super class image_base. * mln/core/image2d_b.hh, * mln/core/image3d_b.hh, * mln/core/internal/image_base.hh: Update. --- decorated_image.hh | 63 +++++----------------------- image2d_b.hh | 5 -- image3d_b.hh | 6 +- image_if.hh | 109 +++++++++++++------------------------------------ internal/image_base.hh | 11 ++++ 5 files changed, 57 insertions(+), 137 deletions(-) Index: trunk/milena/mln/core/decorated_image.hh =================================================================== --- trunk/milena/mln/core/decorated_image.hh (revision 1158) +++ trunk/milena/mln/core/decorated_image.hh (revision 1159) @@ -28,7 +28,7 @@ #ifndef MLN_CORE_DECORATED_IMAGE_HH # define MLN_CORE_DECORATED_IMAGE_HH -# include <mln/core/internal/image_base.hh> +# include <mln/core/internal/image_identity_morpher.hh> # include <mln/value/proxy.hh> @@ -37,7 +37,7 @@ { // Fwd decl. - template <typename I, typename D> class decorated_image; + template <typename I, typename D> struct decorated_image; namespace internal @@ -72,23 +72,26 @@ // FIXME: Doc! template <typename I, typename D> - class decorated_image : public internal::image_base_< mln_pset(I), decorated_image<I,D> >, - public internal::decorated_image_impl_< I, decorated_image<I,D> > + struct decorated_image : + public internal::decorated_image_impl_< I, decorated_image<I,D> >, + public internal::image_identity_morpher_< I, mln_pset(I), decorated_image<I,D> > { typedef decorated_image<I, D> self_; typedef internal::decorated_image_impl_< I, self_ > impl_; - typedef internal::image_base_< mln_pset(I), decorated_image<I,D> > super_; + typedef internal::image_identity_morpher_< I, mln_pset(I), self_ > super_; + + /// Return type of read-write access. + typedef typename internal::morpher_lvalue_<I>::ret lvalue; + public: + /// Ctors decorated_image(); decorated_image(I& ima, const D& deco); /// Dtor ~decorated_image(); - typedef mln_value(I) value; - typedef mln::value::proxy<const self_> rvalue; - typedef typename impl_::lvalue lvalue; /// Value_Set associated type. typedef mln_vset(I) vset; @@ -96,10 +99,6 @@ /// Skeleton. typedef decorated_image< tag::image<I>, tag::data<D> > skeleton; - - rvalue operator()(const mln_psite(I)& p) const; - lvalue operator()(const mln_psite(I)& p); - mln_value(I) read_(const mln_psite(I)& p) const; /// Const promotion via convertion. @@ -111,13 +110,7 @@ /// Give the decoration. D& decoration(); - /// FIXME : to put into a identity morpher - /// Give the definition domain. - const mln_pset(I)& domain() const; - - /// Give the set of values. - const mln_vset(I)& values() const; - + protected: using super_::data_; }; @@ -172,22 +165,6 @@ mw = 0; } - template <typename I, typename D> - typename decorated_image<I,D>::rvalue - decorated_image<I,D>::operator()(const mln_psite(I)& p) const - { - rvalue tmp(*this, p); - return tmp; - } - - template <typename I, typename D> - typename decorated_image<I,D>::lvalue - decorated_image<I,D>::operator()(const mln_psite(I)& p) - { - lvalue tmp(*this, p); - return tmp; - } - namespace internal { @@ -232,22 +209,6 @@ return this->data_->deco_; } - template <typename I, typename D> - const mln_pset(I)& - decorated_image<I,D>::domain() const - { - mln_precondition(exact(this)->has_data()); - return this->data_->ima_.domain(); - } - - template <typename I, typename D> - const mln_vset(I)& - decorated_image<I,D>::values() const - { - return this->data_->ima_.values(); - } - - // decorate template <typename I, typename D> Index: trunk/milena/mln/core/image_if.hh =================================================================== --- trunk/milena/mln/core/image_if.hh (revision 1158) +++ trunk/milena/mln/core/image_if.hh (revision 1159) @@ -33,7 +33,7 @@ * \brief Definition of a image_if image. */ -# include <mln/core/internal/image_base.hh> +# include <mln/core/internal/image_domain_morpher.hh> # include <mln/core/pset_if.hh> # include <mln/pw/all.hh> @@ -51,13 +51,10 @@ struct data_< image_if<I,F> > { data_(I& ima, const F& f); + data_(I& ima, const pset_if<mln_pset(I), F>& pset); - pset_if<mln_pset(I), F> pset_; - F f_; I ima_; - // FIXME for matthieu: f_ is *also* in pset_; pb: redundancy!!! - // FIXME for matthieu: ctor arg list and attr list should be the *same*! - // FIXME for matthieu: do *not* change order of those lists elements! + pset_if<mln_pset(I), F> pset_; }; } // end of namespace mln::internal @@ -67,25 +64,21 @@ * */ template <typename I, typename F> - struct image_if - : public internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F> > - // FIXME for matthieu: *not* image_base_ *but* image_domain_morpher_ + struct image_if : public internal::image_domain_morpher_< I, + pset_if<mln_pset(I),F>, + image_if<I,F> > { - // Parent - typedef internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F> > super_; - // FIXME for matthieu: this should *not* be public! - // FIXME for matthieu: comments end with a '.' - // FIXME for matthieu: we do not say "parent" but "super". - /// Skeleton. typedef image_if< tag::image<I>, tag::function<F> > skeleton; - - /// Point_Set associated type. + /// Point_Site associated type. typedef pset_if<mln_pset(I), F> pset; + /// Psite type. + typedef mln_psite(pset) psite; + /// Constructor from an image \p ima and a predicate \p f. image_if(I& ima, const F& f); @@ -101,40 +94,16 @@ /// Const promotion via convertion. operator image_if<const I, F>() const; - using super_::data_; - // FIXME for matthieu: this should *not* be public! - - typedef image_if<I,F> self_; - - // FIXME : to put into an identity morpher - // FIXME for matthieu: nope... - - // FIXME for matthieu: most of those typedefs and methods are useless... + protected: - /// Point_Site associated type. - typedef mln_point(I) point; - typedef mln_psite(pset) psite; - - /// Value_Set associated type. - typedef mln_vset(I) vset; - - /// Value associated type. - typedef mln_value(I) value; - - /// Return type of read-only access. - typedef mln_rvalue(I) rvalue; - - typedef typename internal::morpher_lvalue_<I>::ret lvalue; - - /// Read-only access of pixel value at point site \p p. - rvalue operator()(const psite& p) const; + /// Self type. + typedef image_if<I,F> self_; - /// Read-write access of pixel value at point site \p p. - lvalue operator()(const psite& p); + /// Super type. + typedef internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F> > super_; - /// Give the set of values. - const vset& values() const; + using super_::data_; }; @@ -176,8 +145,14 @@ template <typename I, typename F> data_< image_if<I,F> >::data_(I& ima, const F& f) : ima_(ima), - pset_(ima.domain() | f), - f_(f) + pset_(ima.domain() | f) + { + } + + template <typename I, typename F> + data_< image_if<I,F> >::data_(I& ima, const pset_if<mln_pset(I), F>& pset) + : ima_(ima), + pset_(pset) { } @@ -197,6 +172,13 @@ } template <typename I, typename F> + image_if<I,F>::operator image_if<const I, F>() const + { + image_if<const I, F> tmp(this->data_->ima_, this->data_->pset_); + return tmp; + } + + template <typename I, typename F> bool image_if<I,F>::owns_(const mln_psite(I)& p) const { @@ -210,37 +192,8 @@ return data_->pset_; } - template <typename I, typename F> - image_if<I,F>::operator image_if<const I, F>() const - { - image_if<const I, F> tmp(this->data_->ima_, this->data_->f_); - return tmp; - } - template <typename I, typename F> - typename image_if<I,F>::rvalue - image_if<I,F>::operator()(const psite& p) const - { - mln_precondition(exact(this)->owns_(p)); - return data_->ima_(p); - } - - template <typename I, typename F> - typename image_if<I,F>::lvalue - image_if<I,F>::operator()(const psite& p) - { - mln_precondition(exact(this)->owns_(p)); - return data_->ima_(p); - } - - template <typename I, typename F> - const mln_vset(I)& - image_if<I,F>::values() const - { - return data_->ima_.values(); - } - // Operators. Index: trunk/milena/mln/core/internal/image_base.hh =================================================================== --- trunk/milena/mln/core/internal/image_base.hh (revision 1158) +++ trunk/milena/mln/core/internal/image_base.hh (revision 1159) @@ -171,6 +171,8 @@ /// Copy constructor. image_base_(const image_base_& rhs); + /// Detach data from an image (free it if nobody else hold it). + void destroy(); const util::tracked_ptr< internal::data_<E> >& hook_data_() const { return data_; } @@ -192,6 +194,8 @@ template <typename S, typename E> image_base_<S,E>::image_base_(const image_base_& rhs) + : select_image_concept_< typename trait::is_fast<E>::ret, + E >() { mln_precondition(exact(rhs).has_data()); // FIXME: Is-it too restrictive? this->data_ = rhs.data_; @@ -247,6 +251,13 @@ return exact(this)->domain().npoints(); } + template <typename S, typename E> + void + image_base_<S,E>::destroy() + { + data_.clean_(); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::internal Index: trunk/milena/mln/core/image2d_b.hh =================================================================== --- trunk/milena/mln/core/image2d_b.hh (revision 1158) +++ trunk/milena/mln/core/image2d_b.hh (revision 1159) @@ -145,11 +145,6 @@ /// 3). image2d_b(const box2d& b, unsigned bdr = border::thickness); - - /// Detach data from an image (free it if nobody else hold it). - void destroy(); - - /// Initialize an empty image. void init_(const box2d& b, unsigned bdr = border::thickness); Index: trunk/milena/mln/core/image3d_b.hh =================================================================== --- trunk/milena/mln/core/image3d_b.hh (revision 1158) +++ trunk/milena/mln/core/image3d_b.hh (revision 1159) @@ -113,8 +113,8 @@ // End of warning. - /// Parent type - typedef internal::image_primary_< box3d, image3d_b<T> > parent; + /// Super type + typedef internal::image_primary_< box3d, image3d_b<T> > super_; /// Value associated type. typedef T value; @@ -199,7 +199,7 @@ T* buffer(); /// To use the track pointer inherited. - using parent::data_; + using super_::data_; };
participants (1)
-
Matthieu Garrigues