
2006-09-01 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> * oln/core/abstract/piter.hh (to_point): New. * oln/core/abstract/bbox.hh (pmin, pmax): New overloaded methods. (is_valid, print, operator<<): New. * oln/core/abstract/iter.hh (iter): Change inheritance from any__simple to any__best_memory to fix trouble with multiple inheritance. (ctor): Remove dangerous call to invalidate. * oln/core/abstract/point_nd.hh (operator<<): New. (impl_less): Update. * oln/core/abstract/pset.hh (coord_type): New. * oln/core/2d/point2d.hh (coord_t): Move to public so that this associated type is directly accessible from... * oln/core/gen/bbox.hh (vtypes): ...this set of types. * oln/core/gen/fwd_piter.hh (psup_): Remove. (bbox): New accessor. (impl_next): Rewrite. (print, operator<<): New. (invariant): Strengthen. * oln/core/gen/bkd_piter.hh: Likewise. Index: oln/core/abstract/piter.hh =================================================================== --- oln/core/abstract/piter.hh (revision 515) +++ oln/core/abstract/piter.hh (working copy) @@ -74,6 +74,12 @@ return p_; } + point_t to_point() const + { + precondition(this->is_valid()); + return p_; + } + protected: point_t p_; Index: oln/core/abstract/bbox.hh =================================================================== --- oln/core/abstract/bbox.hh (revision 515) +++ oln/core/abstract/bbox.hh (working copy) @@ -59,6 +59,7 @@ { typedef E exact_t; typedef oln_type_of(E, point) point_t; + typedef oln_type_of(E, coord) coord_t; typedef oln_type_of(point_t, dim) dim; enum { n = mlc_value(dim) }; @@ -79,12 +80,24 @@ return pmin_; } + coord_t pmin(unsigned i) const + { + precondition(is_valid_ and i < n); + return pmin_[i]; + } + const point_t& pmax() const { precondition(is_valid_); return pmax_; } + coord_t pmax(unsigned i) const + { + precondition(is_valid_ and i < n); + return pmax_[i]; + } + unsigned size(unsigned i) const { precondition(is_valid_ and i < n); @@ -148,6 +161,26 @@ return true; } + bool is_valid() const + { + return is_valid_; + } + + void print(std::ostream& ostr) const + { + ostr << "{ pmin=" << pmin_ + << ", pmax=" << pmax_ + << ", valid=" << is_valid_ + << " }"; + } + + friend + std::ostream& operator<<(std::ostream& ostr, const abstract::bbox<E>& bb) + { + bb.print(ostr); + return ostr; + } + // FIXME: Add the scool code below. // invariant { Index: oln/core/abstract/iter.hh =================================================================== --- oln/core/abstract/iter.hh (revision 515) +++ oln/core/abstract/iter.hh (working copy) @@ -41,7 +41,7 @@ /// Abstract iterator class. template <typename E> - class iter : public stc::any__simple<E>, + class iter : public stc::any__best_memory<E>, public oln::type { public: @@ -71,7 +71,6 @@ iter() { - this->invalidate(); } }; // end of class oln::abstract::iter<E> Index: oln/core/abstract/point_nd.hh =================================================================== --- oln/core/abstract/point_nd.hh (revision 515) +++ oln/core/abstract/point_nd.hh (working copy) @@ -97,7 +97,7 @@ bool impl_less(const self_t& rhs) const { - return xtd::lexi(v_, rhs.vec()); + return xtd::lexi_less(v_, rhs.vec()); } E& impl_plus_equal(const dpoint_t& rhs) @@ -153,7 +153,15 @@ } // end of namespace oln::abstract + template <typename E> + std::ostream& operator<<(std::ostream& ostr, const abstract::point_nd<E>& p) + { + ostr << p.vec(); + return ostr; + } + + /// abstract::point_nd + abstract::dpoint_nd template <typename P, typename D> struct case_ < xtd::op_plus, mlc::pair_<P,D>, Index: oln/core/abstract/pset.hh =================================================================== --- oln/core/abstract/pset.hh (revision 515) +++ oln/core/abstract/pset.hh (working copy) @@ -49,6 +49,7 @@ typedef mlc::undefined point_type; typedef mlc::undefined fwd_piter_type; typedef mlc::undefined bkd_piter_type; + typedef mlc::undefined coord_type; // FIXME: Add grid. }; Index: oln/core/2d/point2d.hh =================================================================== --- oln/core/2d/point2d.hh (revision 515) +++ oln/core/2d/point2d.hh (working copy) @@ -60,13 +60,13 @@ { typedef point2d_<C> self_t; typedef abstract::point_nd<self_t> super_t; - typedef oln_type_of(self_t, coord) coord_t; using super_t::v_; public: // Cf. BUG! typedef oln_type_of(self_t, grid) grid_t; + typedef oln_type_of(self_t, coord) coord_t; /// Ctor. point2d_() Index: oln/core/gen/fwd_piter.hh =================================================================== --- oln/core/gen/fwd_piter.hh (revision 515) +++ oln/core/gen/fwd_piter.hh (working copy) @@ -78,52 +78,65 @@ { nop_ = bb_.pmax(); ++nop_[0]; - - psup_ = bb_.pmax().vec(); - for (unsigned i = 0; i < point::n; ++i) - ++psup_[i]; } - + + const bbox_<point>& bbox() const + { + return bb_; + } + void impl_start() { p_ = bb_.pmin(); - invariant(p_ <= nop_); + invariant(implies(p_ != nop_, bb_.has(p_))); } void impl_next() { - invariant(p_ <= nop_); - ++p_[0]; - unsigned i = 0; - while (i + 1 < point::n) + 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 { - if (p_[i] == psup_[i]) - { - p_[i] = bb_.pmin_[i]; - ++p_[i+1]; - } - ++i; + ++p_[i]; + break; } - invariant(p_ <= nop_); + if (p_ == bb_.pmin()) + p_ = nop_; } void impl_invalidate() { - invariant(p_ <= nop_); + invariant(implies(p_ != nop_, bb_.has(p_))); p_ = nop_; } bool impl_is_valid() const { - invariant(p_ <= nop_); + 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_; - point psup_; }; // end of class oln::fwd_piter_<point> Index: oln/core/gen/bkd_piter.hh =================================================================== --- oln/core/gen/bkd_piter.hh (revision 515) +++ oln/core/gen/bkd_piter.hh (working copy) @@ -75,65 +75,54 @@ bkd_piter_(const bbox_<point>& bb) : bb_(bb) - { - nop_ = bb_.pmax(); - ++nop_[0]; + { + nop_ = bb_.pmin(); + --nop_[0]; + } - psup_ = bb_.pmax().vec(); - for (unsigned i = 0; i < point::n; ++i) - ++psup_[i]; - } + const bbox_<point>& bbox() const + { + return bb_; + } void impl_start() - { - p_ = bb_.pmin(); - } + { + p_ = bb_.pmax(); + invariant(implies(p_ != nop_, bb_.has(p_))); + } void impl_next() - { - assert(this->is_valid()); - ++p_[0]; - unsigned i = 0; - while (i + 1 < point::n) - { - if (p_[i] == psup_[i]) - { - p_[i] = bb_.pmin_[i]; - ++p_[i+1]; - } - ++i; - } - } + { + 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_; + } -// def next = -// { -// precondition { is_valid } -// } - void impl_invalidate() - { - assert(this->is_valid()); - p_ = nop_; - } + { + invariant(implies(p_ != nop_, bb_.has(p_))); + p_ = nop_; + } bool impl_is_valid() const - { - return p_ != nop_; - } + { + invariant(implies(p_ != nop_, bb_.has(p_))); + return p_ != nop_; + } protected: bbox_<point> bb_; point nop_; - point psup_; -// invariant -// { -// p <= nop -// } - -// make : [D : type] (data : D) = { @bb = data.bbox } - }; // end of class oln::bkd_piter_<point> Index: oln/core/gen/bbox.hh =================================================================== --- oln/core/gen/bbox.hh (revision 515) +++ oln/core/gen/bbox.hh (working copy) @@ -58,6 +58,7 @@ typedef point point_type; typedef fwd_piter_<point> fwd_piter_type; typedef bkd_piter_<point> bkd_piter_type; + typedef typename point::coord_t coord_type; // BUG! typedef oln_type_of(point, grid) grid_type; // BUG! typedef typename point::grid_t grid_type; };