
2006-09-18 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Rename bbox point iterators. * oln/core/abstract/iterator_on_points.hh (p_): Remove. Abstract classes should not have attributes. (to_point): Turn abstract. (point_adr): New. * oln/core/gen/fwd_piter.hh: Update and rename as... * oln/core/gen/bbox_fwd_piter.hh: ...this. * oln/core/gen/bkd_piter.hh: Update and rename as... * oln/core/gen/bbox_bkd_piter.hh: ...this. * oln/core/2d/aliases.hh: Update. * oln/core/gen/bbox.hh: Update. * oln/basics2d.hh: Update. Index: oln/core/abstract/iterator_on_points.hh =================================================================== --- oln/core/abstract/iterator_on_points.hh (revision 550) +++ oln/core/abstract/iterator_on_points.hh (working copy) @@ -68,22 +68,26 @@ public: - operator point_t() const + point_t to_point() const { precondition(this->is_valid()); - return p_; + return this->exact().impl_to_point(); } - point_t to_point() const + const point_t* point_adr() const { + return this->exact().impl_point_adr(); + } + + // Concrete method. + operator point_t() const + { precondition(this->is_valid()); - return p_; + return this->to_point(); } protected: - point_t p_; - iterator_on_points() { } Index: oln/core/2d/aliases.hh =================================================================== --- oln/core/2d/aliases.hh (revision 550) +++ oln/core/2d/aliases.hh (working copy) @@ -39,8 +39,8 @@ template <typename C> class dpoint2d_; template <typename P> class bbox_; template <typename P> class topo_bbox_; - template <typename P> class fwd_piter_; - template <typename P> class bkd_piter_; + template <typename P> class bbox_fwd_piter_; + template <typename P> class bbox_bkd_piter_; class grid2d; /// \} @@ -51,8 +51,8 @@ typedef dpoint2d_<int> dpoint2d; typedef bbox_<point2d> bbox2d; - typedef fwd_piter_<point2d> fwd_piter2d; - typedef bkd_piter_<point2d> bkd_piter2d; + typedef bbox_fwd_piter_<point2d> fwd_piter2d; + typedef bbox_bkd_piter_<point2d> bkd_piter2d; typedef topo_bbox_<point2d> topo2d; typedef point2d_<float> point2df; Index: oln/core/gen/fwd_piter.hh =================================================================== --- oln/core/gen/fwd_piter.hh (revision 550) +++ oln/core/gen/fwd_piter.hh (working copy) @@ -1,164 +0,0 @@ -// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_FWD_PITER_HH -# define OLENA_CORE_GEN_FWD_PITER_HH - -# include <oln/core/abstract/iterator_on_points.hh> -# include <oln/core/abstract/point.hh> -# include <oln/core/gen/bbox.hh> - - -namespace oln -{ - - - // Forward declaration. - template <typename point> class fwd_piter_; - - - // Super type declaration. - template <typename point> - struct set_super_type< fwd_piter_<point> > - { - typedef fwd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> ret; - }; - - - /// Virtual types associated to oln::fwd_piter_<point>. - template <typename point> - struct vtypes< fwd_piter_<point> > - { - typedef point point_type; - typedef oln_type_of(point, grid) grid_type; - }; - - - - /// Abstract forward point iterator class. - template <typename point> - class fwd_piter_ : public abstract::iterator_on_points< fwd_piter_<point> >, - private mlc::assert_< mlc_is_a(point, abstract::point) > - { - typedef fwd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> super_t; - - using super_t::p_; - - public: - - fwd_piter_(const bbox_<point>& bb) - : bb_(bb) - { - nop_ = bb_.pmax(); - ++nop_[0]; - } - -// template <typename T> -// fwd_piter_(const abstract::topo<T>& t) -// { -// mlc::assert_< mlc_is_a(T, abstract::topo_with_bbox) >::check(); -// bb_ = t.exact().bbox(); -// nop_ = bb_.pmax(); -// ++nop_[0]; -// } - -// template <typename Data> -// fwd_piter_(const Data& data) -// : bb_(data.bbox()) -// { -// nop_ = bb_.pmax(); -// ++nop_[0]; -// } - - const bbox_<point>& bbox() const - { - return bb_; - } - - void impl_start() - { - p_ = bb_.pmin(); - invariant(implies(p_ != nop_, bb_.has(p_))); - } - - void impl_next() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - for (int i = point::n - 1; i >= 0; --i) - if (p_[i] == bb_.pmax(i)) - p_[i] = bb_.pmin(i); - else - { - ++p_[i]; - break; - } - if (p_ == bb_.pmin()) - p_ = nop_; - } - - void impl_invalidate() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - p_ = nop_; - } - - bool impl_is_valid() const - { - invariant(implies(p_ != nop_, bb_.has(p_))); - return p_ != nop_; - } - - void print(std::ostream& ostr) const - { - ostr << "{ bb=" << bb_ - << ", p=" << p_ - << ", nop=" << nop_ - << " }"; - } - - friend - std::ostream& operator<<(std::ostream& ostr, const fwd_piter_<point>& i) - { - i.print(ostr); - return ostr; - } - - protected: - - bbox_<point> bb_; - point nop_; - - }; // end of class oln::fwd_piter_<point> - - -} // end of namespace oln - - -#endif // ! OLENA_CORE_GEN_FWD_PITER_HH Index: oln/core/gen/bkd_piter.hh =================================================================== --- oln/core/gen/bkd_piter.hh (revision 550) +++ oln/core/gen/bkd_piter.hh (working copy) @@ -1,132 +0,0 @@ -// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_BKD_PITER_HH -# define OLENA_CORE_GEN_BKD_PITER_HH - -# include <oln/core/abstract/iterator_on_points.hh> -# include <oln/core/abstract/point.hh> -# include <oln/core/gen/bbox.hh> - - -namespace oln -{ - - - // Forward declaration. - template <typename point> class bkd_piter_; - - - // Super type declaration. - template <typename point> - struct set_super_type< bkd_piter_<point> > - { - typedef bkd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> ret; - }; - - - /// Virtual types associated to oln::bbox_<point>. - template <typename point> - struct vtypes< bkd_piter_<point> > - { - typedef point point_type; - typedef oln_type_of(point, grid) grid_type; - }; - - - - /// Abstract forward point iterator class. - template <typename point> - class bkd_piter_ : public abstract::iterator_on_points< bkd_piter_<point> >, - private mlc::assert_< mlc_is_a(point, abstract::point) > - { - typedef bkd_piter_<point> self_t; - typedef abstract::iterator_on_points<self_t> super_t; - - using super_t::p_; - - public: - - bkd_piter_(const bbox_<point>& bb) - : bb_(bb) - { - nop_ = bb_.pmin(); - --nop_[0]; - } - - const bbox_<point>& bbox() const - { - return bb_; - } - - void impl_start() - { - p_ = bb_.pmax(); - invariant(implies(p_ != nop_, bb_.has(p_))); - } - - void impl_next() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - for (int i = point::n - 1; i >= 0; --i) - if (p_[i] == bb_.pmin(i)) - p_[i] = bb_.pmax(i); - else - { - --p_[i]; - break; - } - if (p_ == bb_.pmax()) - p_ = nop_; - } - - void impl_invalidate() - { - invariant(implies(p_ != nop_, bb_.has(p_))); - p_ = nop_; - } - - bool impl_is_valid() const - { - invariant(implies(p_ != nop_, bb_.has(p_))); - return p_ != nop_; - } - - protected: - - bbox_<point> bb_; - point nop_; - - }; // end of class oln::bkd_piter_<point> - - -} // end of namespace oln - - -#endif // ! OLENA_CORE_GEN_BKD_PITER_HH Index: oln/core/gen/bbox.hh =================================================================== --- oln/core/gen/bbox.hh (revision 550) +++ oln/core/gen/bbox.hh (working copy) @@ -38,8 +38,8 @@ // Forward declarations. template <typename point> class bbox_; - template <typename point> class fwd_piter_; - template <typename point> class bkd_piter_; + template <typename point> class bbox_fwd_piter_; + template <typename point> class bbox_bkd_piter_; // Super type declaration. @@ -56,8 +56,8 @@ struct vtypes< bbox_<point> > { typedef point point_type; - typedef fwd_piter_<point> fwd_piter_type; - typedef bkd_piter_<point> bkd_piter_type; + typedef bbox_fwd_piter_<point> fwd_piter_type; + typedef bbox_bkd_piter_<point> bkd_piter_type; typedef bbox_<point> bbox_type; Index: oln/core/gen/bbox_fwd_piter.hh =================================================================== --- oln/core/gen/bbox_fwd_piter.hh (revision 549) +++ oln/core/gen/bbox_fwd_piter.hh (working copy) @@ -26,8 +26,8 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_CORE_GEN_FWD_PITER_HH -# define OLENA_CORE_GEN_FWD_PITER_HH +#ifndef OLENA_CORE_GEN_BBOX_FWD_PITER_HH +# define OLENA_CORE_GEN_BBOX_FWD_PITER_HH # include <oln/core/abstract/iterator_on_points.hh> # include <oln/core/abstract/point.hh> @@ -39,21 +39,21 @@ // Forward declaration. - template <typename point> class fwd_piter_; + template <typename point> class bbox_fwd_piter_; // Super type declaration. template <typename point> - struct set_super_type< fwd_piter_<point> > + struct set_super_type< bbox_fwd_piter_<point> > { - typedef fwd_piter_<point> self_t; + typedef bbox_fwd_piter_<point> self_t; typedef abstract::iterator_on_points<self_t> ret; }; - /// Virtual types associated to oln::fwd_piter_<point>. + /// Virtual types associated to oln::bbox_fwd_piter_<point>. template <typename point> - struct vtypes< fwd_piter_<point> > + struct vtypes< bbox_fwd_piter_<point> > { typedef point point_type; typedef oln_type_of(point, grid) grid_type; @@ -63,25 +63,24 @@ /// Abstract forward point iterator class. template <typename point> - class fwd_piter_ : public abstract::iterator_on_points< fwd_piter_<point> >, - private mlc::assert_< mlc_is_a(point, abstract::point) > + class bbox_fwd_piter_ : public abstract::iterator_on_points< bbox_fwd_piter_<point> >, + private mlc::assert_< mlc_is_a(point, abstract::point) > { - typedef fwd_piter_<point> self_t; + typedef bbox_fwd_piter_<point> self_t; typedef abstract::iterator_on_points<self_t> super_t; - using super_t::p_; - public: - fwd_piter_(const bbox_<point>& bb) - : bb_(bb) + bbox_fwd_piter_(const bbox_<point>& bb) + : p_(), + bb_(bb) { nop_ = bb_.pmax(); ++nop_[0]; } // template <typename T> -// fwd_piter_(const abstract::topo<T>& t) +// bbox_fwd_piter_(const abstract::topo<T>& t) // { // mlc::assert_< mlc_is_a(T, abstract::topo_with_bbox) >::check(); // bb_ = t.exact().bbox(); @@ -90,7 +89,7 @@ // } // template <typename Data> -// fwd_piter_(const Data& data) +// bbox_fwd_piter_(const Data& data) // : bb_(data.bbox()) // { // nop_ = bb_.pmax(); @@ -135,6 +134,16 @@ return p_ != nop_; } + point impl_to_point() const + { + return p_; + } + + const point* impl_point_adr() const + { + return &p_; + } + void print(std::ostream& ostr) const { ostr << "{ bb=" << bb_ @@ -144,7 +153,7 @@ } friend - std::ostream& operator<<(std::ostream& ostr, const fwd_piter_<point>& i) + std::ostream& operator<<(std::ostream& ostr, const bbox_fwd_piter_<point>& i) { i.print(ostr); return ostr; @@ -152,13 +161,14 @@ protected: + point p_; bbox_<point> bb_; point nop_; - }; // end of class oln::fwd_piter_<point> + }; // end of class oln::bbox_fwd_piter_<point> } // end of namespace oln -#endif // ! OLENA_CORE_GEN_FWD_PITER_HH +#endif // ! OLENA_CORE_GEN_BBOX_FWD_PITER_HH Index: oln/core/gen/bbox_bkd_piter.hh =================================================================== --- oln/core/gen/bbox_bkd_piter.hh (revision 549) +++ oln/core/gen/bbox_bkd_piter.hh (working copy) @@ -26,8 +26,8 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_CORE_GEN_BKD_PITER_HH -# define OLENA_CORE_GEN_BKD_PITER_HH +#ifndef OLENA_CORE_GEN_BBOX_BKD_PITER_HH +# define OLENA_CORE_GEN_BBOX_BKD_PITER_HH # include <oln/core/abstract/iterator_on_points.hh> # include <oln/core/abstract/point.hh> @@ -39,21 +39,21 @@ // Forward declaration. - template <typename point> class bkd_piter_; + template <typename point> class bbox_bkd_piter_; // Super type declaration. template <typename point> - struct set_super_type< bkd_piter_<point> > + struct set_super_type< bbox_bkd_piter_<point> > { - typedef bkd_piter_<point> self_t; + typedef bbox_bkd_piter_<point> self_t; typedef abstract::iterator_on_points<self_t> ret; }; /// Virtual types associated to oln::bbox_<point>. template <typename point> - struct vtypes< bkd_piter_<point> > + struct vtypes< bbox_bkd_piter_<point> > { typedef point point_type; typedef oln_type_of(point, grid) grid_type; @@ -63,18 +63,17 @@ /// Abstract forward point iterator class. template <typename point> - class bkd_piter_ : public abstract::iterator_on_points< bkd_piter_<point> >, - private mlc::assert_< mlc_is_a(point, abstract::point) > + class bbox_bkd_piter_ : public abstract::iterator_on_points< bbox_bkd_piter_<point> >, + private mlc::assert_< mlc_is_a(point, abstract::point) > { - typedef bkd_piter_<point> self_t; + typedef bbox_bkd_piter_<point> self_t; typedef abstract::iterator_on_points<self_t> super_t; - using super_t::p_; - public: - bkd_piter_(const bbox_<point>& bb) - : bb_(bb) + bbox_bkd_piter_(const bbox_<point>& bb) + : p_(), + bb_(bb) { nop_ = bb_.pmin(); --nop_[0]; @@ -118,15 +117,26 @@ return p_ != nop_; } + point impl_to_point() const + { + return p_; + } + + const point* impl_point_adr() const + { + return &p_; + } + protected: + point p_; bbox_<point> bb_; point nop_; - }; // end of class oln::bkd_piter_<point> + }; // end of class oln::bbox_bkd_piter_<point> } // end of namespace oln -#endif // ! OLENA_CORE_GEN_BKD_PITER_HH +#endif // ! OLENA_CORE_GEN_BBOX_BKD_PITER_HH Index: oln/basics2d.hh =================================================================== --- oln/basics2d.hh (revision 550) +++ oln/basics2d.hh (working copy) @@ -41,11 +41,11 @@ # include <oln/core/gen/bbox.hh> namespace oln { template class bbox_<point2d>; } -# include <oln/core/gen/fwd_piter.hh> -namespace oln { template class fwd_piter_<point2d>; } +# include <oln/core/gen/bbox_fwd_piter.hh> +namespace oln { template class bbox_fwd_piter_<point2d>; } -# include <oln/core/gen/bkd_piter.hh> -namespace oln { template class bkd_piter_<point2d>; } +# include <oln/core/gen/bbox_bkd_piter.hh> +namespace oln { template class bbox_bkd_piter_<point2d>; } # include <oln/core/gen/topo_bbox.hh> namespace oln { template class topo_bbox_<point2d>; }