
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update point set hierarchy with Box. * oln/level/apply_inplace.hh: Fix. * oln/core/concept/point_set.hh (include): Update. (operator<<): Add decl. * oln/core/gen/pset_compare.hh (operator<=, op_leq_), (operator>=, op_geq_, operator>, op_greater_): New. * oln/core/internal/op_pset_such_as_fp2b.hh (box): New. * oln/core/internal/box.hh (include): Update. (pmin, pmax): Rename as... (impl_pmin, impl_pmax): ...these. (set_box): Remove; move code into... (box): ...this ctor. (box_fwd_piter_, box_bkd_piter_): Strengthen sigs; Remove version without arg. (b_): Add &. * oln/core/internal/point_set_base.hh (point_set_selector_): Simplify. (super_trait_): Update. (point_set_base_): Change inheritance to point_set_selector_. * oln/core/internal/utils.hh (pair): New overload. * oln/core/internal/op_image_restricted_to_pset.hh: Add precondition and postconditions. core/concept/point_set.hh | 15 +++-- core/gen/pset_compare.hh | 75 +++++++++++++++++++++++---- core/internal/box.hh | 74 ++++++-------------------- core/internal/op_image_restricted_to_pset.hh | 3 + core/internal/op_pset_such_as_fp2b.hh | 1 core/internal/point_set_base.hh | 27 ++------- core/internal/utils.hh | 28 +++++++++- level/apply_inplace.hh | 4 - 8 files changed, 133 insertions(+), 94 deletions(-) Index: oln/level/apply_inplace.hh --- oln/level/apply_inplace.hh (revision 908) +++ oln/level/apply_inplace.hh (working copy) @@ -42,7 +42,7 @@ template <typename F, typename I> void - apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input) + apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input); template <typename R, typename A, typename I> void @@ -83,7 +83,7 @@ void apply_inplace(R (*f)(A), Mutable_Image<I>& input) { - impl::apply_inplace_(functorize_v2v(fun), exact(input)); + impl::apply_inplace_(functorize_v2v(f), exact(input)); } # endif Index: oln/core/concept/point_set.hh --- oln/core/concept/point_set.hh (revision 908) +++ oln/core/concept/point_set.hh (working copy) @@ -29,8 +29,7 @@ # define OLN_CORE_CONCEPT_POINT_SET_HH # include <iostream> -# include <oln/core/concept/point.hh> -# include <oln/core/concept/iterator.hh> // for "for_all" +# include <oln/core/concept/iterator_on_points.hh> namespace oln @@ -85,6 +84,9 @@ template <typename Ps> std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts); + template <typename B> + std::ostream& operator<<(std::ostream& ostr, const Box<B>& b); + # ifndef OLN_INCLUDE_ONLY @@ -151,14 +153,19 @@ std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts) { ostr << "{ "; - typename Ps::piter p(pts); + oln_piter(Ps) p(pts); for_all(p) ostr << p << ' '; // FIXME: Add ','? return ostr << " }"; } + template <typename B> + std::ostream& operator<<(std::ostream& ostr, const Box<B>& b) + { + return ostr << "{ " << b.pmin() << " .. " << b.pmax() << " }"; + } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/gen/pset_compare.hh --- oln/core/gen/pset_compare.hh (revision 908) +++ oln/core/gen/pset_compare.hh (working copy) @@ -42,6 +42,15 @@ template <typename L, typename R> bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs); + template <typename L, typename R> + bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs); + + template <typename L, typename R> + bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs); + + template <typename L, typename R> + bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs); + # ifndef OLN_INCLUDE_ONLY @@ -72,16 +81,13 @@ return true; } - /* // Version for Boxes. - FIXME: Activate. template <typename L, typename R> bool op_eq_(const Box<L>& lhs, const Box<R>& rhs) { return lhs.pmin() = rhs.pmin() and lhs.pmax() = rhs.pmax(); } - */ // Point_Set L < Point_Set R @@ -109,23 +115,49 @@ return true; } - /* - // Version for Boxes. - FIXME: Activate. + + // Box L <= Box R. + template <typename L, typename R> - bool op_less_(const Box<L>& lhs, const Box<R>& rhs) + bool op_leq_(const Box<L>& lhs, const Box<R>& rhs) { - // subset test (i.e., lhs <= rhs) for (unsigned i = 0; i < L::n; ++i) { if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i]) return false; } - // proper (strict) test - return lhs != rhs; + return true; + } + + // Box L < Box R. + + template <typename L, typename R> + bool op_less_(const Box<L>& lhs, const Box<R>& rhs) + { + return op_leq_(lhs, rhs) and lhs != rhs; + } + + // Box L >= Box R. + + template <typename L, typename R> + bool op_geq_(const Box<L>& lhs, const Box<R>& rhs) + { + for (unsigned i = 0; i < L::n; ++i) + { + if (lhs.pmin()[i] > rhs.pmin()[i] or lhs.pmax()[i] < rhs.pmax()[i]) + return false; + } + return true; + } + + // Box L > Box R. + + template <typename L, typename R> + bool op_greater_(const Box<L>& lhs, const Box<R>& rhs) + { + return op_geq_(lhs, rhs) and lhs != rhs; } - */ } // end of namespace oln::impl @@ -141,12 +173,33 @@ } template <typename L, typename R> + bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs) + { + assert_same_grid_<L, R>::check(); + return impl::op_leq_(exact(lhs), exact(rhs)); + } + + template <typename L, typename R> bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs) { assert_same_grid_<L, R>::check(); return impl::op_less_(exact(lhs), exact(rhs)); } + template <typename L, typename R> + bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs) + { + assert_same_grid_<L, R>::check(); + return impl::op_geq_(exact(lhs), exact(rhs)); + } + + template <typename L, typename R> + bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs) + { + assert_same_grid_<L, R>::check(); + return impl::op_greater_(exact(lhs), exact(rhs)); + } + # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/internal/op_pset_such_as_fp2b.hh --- oln/core/internal/op_pset_such_as_fp2b.hh (revision 908) +++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy) @@ -64,6 +64,7 @@ template <typename S, typename F> struct vtypes< internal::current > { + typedef oln_box(S) box; 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; Index: oln/core/internal/box.hh --- oln/core/internal/box.hh (revision 908) +++ oln/core/internal/box.hh (working copy) @@ -28,9 +28,6 @@ #ifndef OLN_CORE_INTERNAL_BOX_HH # define OLN_CORE_INTERNAL_BOX_HH -//# include <oln/core/concept/point.hh> -# include <oln/core/concept/point_set.hh> -# include <oln/core/concept/iterator_on_points.hh> # include <oln/core/internal/point_set_base.hh> @@ -89,10 +86,10 @@ bool impl_has(const point& p) const; const Exact& impl_bbox() const; - const point& pmin() const; - point& pmin(); - const point& pmax() const; - point& pmax(); + const point& impl_pmin() const; + point& impl_pmin(); + const point& impl_pmax() const; + point& impl_pmax(); protected: box_(); @@ -105,11 +102,6 @@ }; // end of class oln::box_<P> - template <typename Exact> - std::ostream& operator<<(std::ostream& ostr, const box_<Exact>& b) - { - return ostr << "{ " << b.pmin() << " .. " << b.pmax() << " }"; - } } // end of namespace internal @@ -161,9 +153,7 @@ public: stc_using(point); - box_fwd_piter_(); - box_fwd_piter_(const B& b); - void set_box(const B& b); + box_fwd_piter_(const Point_Set<B>& b); void impl_start(); void impl_next(); @@ -173,8 +163,8 @@ const point* impl_point_adr() const; private: - B b_; - point p_, nop_; + const B& b_; + point nop_, p_; }; @@ -189,9 +179,7 @@ public: stc_using(point); - box_bkd_piter_(); - box_bkd_piter_(const B& b); - void set_box(const B& b); + box_bkd_piter_(const Point_Set<B>& b); void impl_start(); void impl_next(); @@ -201,8 +189,8 @@ const point* impl_point_adr() const; private: - B b_; - point p_, nop_; + const B& b_; + point nop_, p_; }; @@ -275,7 +263,7 @@ template <typename Exact> const typename box_<Exact>::point& - box_<Exact>::pmin() const + box_<Exact>::impl_pmin() const { for (unsigned i = 0; i < n; ++i) invariant(this->pmin_[i] <= this->pmax_[i]); @@ -284,7 +272,7 @@ template <typename Exact> const typename box_<Exact>::point& - box_<Exact>::pmax() const + box_<Exact>::impl_pmax() const { for (unsigned i = 0; i < n; ++i) invariant(this->pmax_[i] >= this->pmin_[i]); @@ -293,14 +281,14 @@ template <typename Exact> typename box_<Exact>::point& - box_<Exact>::pmin() + box_<Exact>::impl_pmin() { return this->pmin_; } template <typename Exact> typename box_<Exact>::point& - box_<Exact>::pmax() + box_<Exact>::impl_pmax() { return this->pmax_; } @@ -308,23 +296,10 @@ // -------------------- box_fwd_piter_<B> - - template <typename B> - box_fwd_piter_<B>::box_fwd_piter_() - { - } - template <typename B> - box_fwd_piter_<B>::box_fwd_piter_(const B& b) + box_fwd_piter_<B>::box_fwd_piter_(const Point_Set<B>& b) + : b_(exact(b)) { - this->set_box(b); - } - - template <typename B> - void - box_fwd_piter_<B>::set_box(const B& b) - { - b_ = b; nop_ = b_.pmax(); ++nop_[0]; p_ = nop_; @@ -385,23 +360,10 @@ // -------------------- box_bkd_piter_<P> - - template <typename B> - box_bkd_piter_<B>::box_bkd_piter_() - { - } - template <typename B> - box_bkd_piter_<B>::box_bkd_piter_(const B& b) - { - this->set_box(b); - } - - template <typename B> - void - box_bkd_piter_<B>::set_box(const B& b) + box_bkd_piter_<B>::box_bkd_piter_(const Point_Set<B>& b) + : b_(exact(b)) { - b_ = b; nop_ = b_.pmin(); --nop_[0]; p_ = nop_; Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 908) +++ oln/core/internal/point_set_base.hh (working copy) @@ -38,15 +38,12 @@ namespace internal { - template <bool Is_box, typename Exact> - struct point_set_selector_; - - template <typename Exact> - struct point_set_selector_< true, Exact > : public Box<Exact> + template <typename Box_ptr, typename Exact> + struct point_set_selector_ : public Point_Set<Exact> {}; template <typename Exact> - struct point_set_selector_< false, Exact > : public Point_Set<Exact> + struct point_set_selector_< Exact*, Exact > : public Box<Exact> {}; } // end of namespace oln::internal @@ -56,28 +53,20 @@ // point_set_base_ class - /// Fwd decls. + // Fwd decls. namespace internal { template <typename Exact> struct point_set_base_; } template <typename P> class gen_box; - /// Super type. + // Super type. template <typename Exact> struct super_trait_< internal::point_set_base_<Exact> > { - typedef Point_Set<Exact> ret; - - /* - FIXME: Activate to replace the above code. - - typedef stc_deferred(box) box__; - typedef mlc::eq_<box__, Exact> test__; - typedef internal::point_set_selector_<mlc_bool(test__), Exact> ret; - */ + typedef internal::point_set_selector_< stc_deferred(box)*, Exact > ret; }; - /// Virtual types. + // Virtual types. template <typename Exact> struct vtypes< internal::point_set_base_<Exact> > { @@ -101,7 +90,7 @@ /// Base class for point sets. template <typename Exact> - struct point_set_base_ : public Point_Set<Exact> // FIXME: Change inheritance. + struct point_set_base_ : public super_trait_< point_set_base_<Exact> >::ret { protected: point_set_base_(); Index: oln/core/internal/utils.hh --- oln/core/internal/utils.hh (revision 908) +++ oln/core/internal/utils.hh (working copy) @@ -96,10 +96,34 @@ }; template <typename T1, typename T2> - struct pair< T1, T2* >; + struct pair< T1*, T2* > + { + typedef pair<T1*,T2*> self_t; + + // Not impled. + pair(); + pair(const self_t&); + void operator=(const self_t&); + // end of Not impled. + + pair(T1* p_first, T2* p_second) + : first(*p_first), + second(*p_second) + { + precondition(p_first != 0); + precondition(p_second != 0); + } + T1& first; + T2& second; + ~pair() + { + delete &first; + delete &second; + } + }; template <typename T1, typename T2> - struct pair< T1*, T2* >; + struct pair< T1, T2* >; /// Simple triplet class. Index: oln/core/internal/op_image_restricted_to_pset.hh --- oln/core/internal/op_image_restricted_to_pset.hh (revision 908) +++ oln/core/internal/op_image_restricted_to_pset.hh (working copy) @@ -129,6 +129,7 @@ template <typename I, typename S> current::special_op_(I& ima, S& subset) { + precondition(subset <= ima.points()); this->data_ = new data(ima, subset); } @@ -187,6 +188,7 @@ bool subset_ok = init(this_->data__()->second, with, dat); postcondition(image_ok); postcondition(subset_ok); + postcondition(this_->points() <= this_->image().points()); return image_ok and subset_ok; } @@ -202,6 +204,7 @@ bool subset_ok = init(target.data__()->second, with, dat); postcondition(image_ok); postcondition(subset_ok); + postcondition(target.points() <= target.image().points()); return image_ok and subset_ok; }