908: Adapt gen_box and point1d class to the new box hierarchy.

Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Adapt gen_box and point1d class to the new box hierarchy. * tests/core/image1d.cc, oln/core/rle/rle_pset.hh, * core/internal/point_set_base.hh: change vtypes. * oln/core/1d/box1d.hh: box1d is know a real class. * oln/core/2d/box2d.hh: add a constructor. * oln/core/gen/box.hh: adapt gen_box. * oln/core/internal/box.hh: fix a bug. oln/core/1d/box1d.hh | 60 ++++++ oln/core/2d/box2d.hh | 12 - oln/core/gen/box.hh | 344 +----------------------------------- oln/core/internal/box.hh | 53 ++--- oln/core/internal/point_set_base.hh | 3 oln/core/rle/rle_pset.hh | 1 tests/core/image1d.cc | 1 7 files changed, 108 insertions(+), 366 deletions(-) Index: tests/core/image1d.cc --- tests/core/image1d.cc (revision 907) +++ tests/core/image1d.cc (working copy) @@ -38,6 +38,7 @@ // Fill a 1D image using its iterator. image1d<char> ima1(3); + image1d<char>::box box1 = ima1.points(); image1d<char>::piter p1(ima1.points()); for_all(p1) ima1(p1) = 1; Index: oln/core/rle/rle_pset.hh --- oln/core/rle/rle_pset.hh (revision 907) +++ oln/core/rle/rle_pset.hh (working copy) @@ -61,6 +61,7 @@ { typedef P point; + typedef gen_box<P> box; typedef rle_pset_fwd_piter_<P> fwd_piter; typedef rle_pset_bkd_piter_<P> bkd_piter; }; Index: oln/core/1d/box1d.hh --- oln/core/1d/box1d.hh (revision 907) +++ oln/core/1d/box1d.hh (working copy) @@ -35,8 +35,64 @@ namespace oln { - // FIXME: box1d should be an actual type, not an alias... - typedef gen_box<point1d> box1d; + // Forward declarations + struct box1d; + + // Super type + template <> + struct super_trait_< box1d > + { + typedef box1d current; + typedef internal::box_<box1d> ret; + }; + + // Virtual types + template <> + struct vtypes<box1d> + { + typedef point1d point; + typedef box1d box; + }; + + // Class box1d + class box1d : public internal::box_< box1d > + { + typedef box1d current; + typedef internal::box_< box1d > super; + public: + // Note: we can't use stc_using because box1d isn't a templated class + typedef super::point point; + + box1d(); + box1d(const box1d::from_to_t& dat); + box1d(const point1d& pmin, const point1d& pmax); + template <typename D> + box1d(const internal::initializer_<D>& data); + }; + +# ifndef OLN_INCLUDE_ONLY + + box1d::box1d() + { + } + + box1d::box1d(const box1d::from_to_t& dat) : + super(dat) + { + } + + box1d::box1d(const point1d& pmin, const point1d& pmax) : + super(pmin, pmax) + { + } + + template <typename D> + box1d::box1d(const internal::initializer_<D>& data) : + super(data) + { + } + +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/2d/box2d.hh --- oln/core/2d/box2d.hh (revision 907) +++ oln/core/2d/box2d.hh (working copy) @@ -36,10 +36,6 @@ namespace oln { - // Fwd decl. - template <typename P> class box_; - - // Forward declarations struct box2d; @@ -71,6 +67,8 @@ box2d(); box2d(const box2d::from_to_t& dat); box2d(const point2d& pmin, const point2d& pmax); + template <typename D> + box2d(const internal::initializer_<D>& data); }; namespace internal @@ -103,6 +101,12 @@ { } + template <typename D> + box2d::box2d(const internal::initializer_<D>& data) : + super(data) + { + } + namespace internal { Index: oln/core/gen/box.hh --- oln/core/gen/box.hh (revision 907) +++ oln/core/gen/box.hh (working copy) @@ -31,7 +31,7 @@ # include <oln/core/concept/point.hh> # include <oln/core/concept/iterator_on_points.hh> -# include <oln/core/internal/point_set_base.hh> +# include <oln/core/internal/box.hh> namespace oln @@ -40,8 +40,6 @@ // Forward declarations. template <typename P> class gen_box; - template <typename P> class gen_box_fwd_piter_; - template <typename P> class gen_box_bkd_piter_; // Super type declaration. @@ -49,7 +47,7 @@ struct super_trait_< gen_box<P> > { typedef gen_box<P> current__; - typedef internal::point_set_base_<current__> ret; + typedef internal::box_<current__> ret; }; @@ -58,150 +56,35 @@ struct vtypes< gen_box<P> > { typedef P point; - typedef gen_box_fwd_piter_<P> fwd_piter; - typedef gen_box_bkd_piter_<P> bkd_piter; + typedef gen_box<P> box; }; /// Generic box class based on a point class. template <typename P> - class gen_box : public internal::point_set_base_< gen_box<P> >, + class gen_box : public internal::box_< gen_box<P> >, private mlc::assert_< mlc_is_a(P, Point) > { typedef gen_box<P> current; - typedef internal::point_set_base_<current> super; - - typedef internal::initializer_< - internal::pair< internal::from_t<P>, internal::to_t<P> > - > from_to_t; - + typedef internal::box_<current> super; public: - stc_using(point); stc_using(box); - private: - typedef stc_type(point, dim) dim__; - enum { n = mlc_value(dim__) }; public: gen_box(); gen_box(const P& pmin, const P& pmax); - gen_box(const from_to_t& data); + gen_box(const typename gen_box<P>::from_to_t& data); template <typename D> gen_box(const internal::initializer_<D>& data); - unsigned impl_npoints() const; - bool impl_has(const P& p) const; - const gen_box<P>& impl_bbox() const; - - const P& pmin() const; - P& pmin(); - const P& pmax() const; - P& pmax(); - - protected: - point pmin_, pmax_; - }; // end of class oln::gen_box<P> - template <typename P> - std::ostream& operator<<(std::ostream& ostr, const gen_box<P>& b) - { - return ostr << "{ " << b.pmin() << " .. " << b.pmax() << " }"; - } - - - // -------------------- iterators on gen_box<P> - - - - - /// Super types. - - template <typename P> - struct super_trait_< gen_box_fwd_piter_<P> > - { - typedef gen_box_fwd_piter_<P> current__; - typedef Iterator_on_Points<current__> ret; - }; - - template <typename P> - struct super_trait_< gen_box_bkd_piter_<P> > - { - typedef gen_box_bkd_piter_<P> current__; - typedef Iterator_on_Points<current__> ret; - }; - - - /// Virtual types. - - template <typename P> - struct vtypes< gen_box_fwd_piter_<P> > - { - typedef P point; - }; - - template <typename P> - struct vtypes< gen_box_bkd_piter_<P> > - { - typedef P point; - }; - - - /// Class gen_box_fwd_piter_<P>. - - template <typename P> - class gen_box_fwd_piter_ : public Iterator_on_Points< gen_box_fwd_piter_<P> >, - private mlc::assert_< mlc_is_a(P, Point) > - { - public: - gen_box_fwd_piter_(); - gen_box_fwd_piter_(const Point_Set< gen_box<P> >& b); - void set_box(const gen_box<P>& b); - - void impl_start(); - void impl_next(); - void impl_invalidate(); - bool impl_is_valid() const; - P impl_to_point() const; - const P* impl_point_adr() const; - - private: - gen_box<P> b_; - P p_, nop_; - }; - - - /// Class gen_box_bkd_piter_<P>. - - template <typename P> - class gen_box_bkd_piter_ : public Iterator_on_Points< gen_box_bkd_piter_<P> >, - private mlc::assert_< mlc_is_a(P, Point) > - { - public: - gen_box_bkd_piter_(); - gen_box_bkd_piter_(const Point_Set< gen_box<P> >& b); - void set_box(const gen_box<P>& b); - - void impl_start(); - void impl_next(); - void impl_invalidate(); - bool impl_is_valid() const; - P impl_to_point() const; - const P* impl_point_adr() const; - - private: - gen_box<P> b_; - P p_, nop_; - }; - - - # ifndef OLN_INCLUDE_ONLY @@ -215,225 +98,22 @@ } template <typename P> - gen_box<P>::gen_box(const P& pmin, const P& pmax) + gen_box<P>::gen_box(const P& pmin, const P& pmax) : + super(pmin, pmax) { - for (unsigned i = 0; i < n; ++i) - precondition(pmax[i] >= pmin[i]); - this->pmin_ = pmin; - this->pmax_ = pmax; } template <typename P> - gen_box<P>::gen_box(const typename gen_box<P>::from_to_t& dat) + gen_box<P>::gen_box(const typename gen_box<P>::from_to_t& data) : + super(data) { - this->pmin_ = dat->first.value; - this->pmax_ = dat->second.value; } template <typename P> template <typename D> - gen_box<P>::gen_box(const internal::initializer_<D>& data) - { - bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value()); - postcondition(box_ok); - } - - template <typename P> - unsigned - gen_box<P>::impl_npoints() const - { - unsigned count = 1; - for (unsigned i = 0; i < n; ++i) - count *= (this->pmax_[i] - this->pmin_[i] + 1); - return count; - } - - template <typename P> - bool - gen_box<P>::impl_has(const P& p) const - { - for (unsigned i = 0; i < n; ++i) - if (p[i] < this->pmin_[i] or p[i] > this->pmax_[i]) - return false; - return true; - } - - template <typename P> - const gen_box<P>& - gen_box<P>::impl_bbox() const - { - return *this; - } - - template <typename P> - const P& - gen_box<P>::pmin() const - { - for (unsigned i = 0; i < n; ++i) - invariant(this->pmin_[i] <= this->pmax_[i]); - return this->pmin_; - } - - template <typename P> - const P& - gen_box<P>::pmax() const - { - for (unsigned i = 0; i < n; ++i) - invariant(this->pmax_[i] >= this->pmin_[i]); - return this->pmax_; - } - - template <typename P> - P& - gen_box<P>::pmin() - { - return this->pmin_; - } - - template <typename P> - P& - gen_box<P>::pmax() - { - return this->pmax_; - } - - - // -------------------- gen_box_fwd_piter_<P> - - - template <typename P> - gen_box_fwd_piter_<P>::gen_box_fwd_piter_() - { - } - - template <typename P> - gen_box_fwd_piter_<P>::gen_box_fwd_piter_(const Point_Set< gen_box<P> >& b) - { - this->set_box(exact(b)); - } - - template <typename P> - void gen_box_fwd_piter_<P>::set_box(const gen_box<P>& b) - { - b_ = b; - nop_ = b_.pmax(); - ++nop_[0]; - p_ = nop_; - } - - template <typename P> - void gen_box_fwd_piter_<P>::impl_start() - { - p_ = b_.pmin(); - } - - template <typename P> - void gen_box_fwd_piter_<P>::impl_next() - { - for (int i = P::n - 1; i >= 0; --i) - if (p_[i] == b_.pmax()[i]) - p_[i] = b_.pmin()[i]; - else - { - ++p_[i]; - break; - } - if (p_ == b_.pmin()) - p_ = nop_; - } - - template <typename P> - void gen_box_fwd_piter_<P>::impl_invalidate() - { - p_ = nop_; - } - - template <typename P> - bool gen_box_fwd_piter_<P>::impl_is_valid() const - { - return p_ != nop_; - } - - template <typename P> - P gen_box_fwd_piter_<P>::impl_to_point() const - { - return p_; - } - - template <typename P> - const P* gen_box_fwd_piter_<P>::impl_point_adr() const - { - return &p_; - } - - - - // -------------------- gen_box_bkd_piter_<P> - - - template <typename P> - gen_box_bkd_piter_<P>::gen_box_bkd_piter_() - { - } - - template <typename P> - gen_box_bkd_piter_<P>::gen_box_bkd_piter_(const Point_Set< gen_box<P> >& b) - { - this->set_box(exact(b)); - } - - template <typename P> - void gen_box_bkd_piter_<P>::set_box(const gen_box<P>& b) - { - b_ = b; - nop_ = b_.pmin(); - --nop_[0]; - p_ = nop_; - } - - template <typename P> - void gen_box_bkd_piter_<P>::impl_start() - { - p_ = b_.pmax(); - } - - template <typename P> - void gen_box_bkd_piter_<P>::impl_next() - { - for (int i = P::n - 1; i >= 0; --i) - if (p_[i] == b_.pmin()[i]) - p_[i] = b_.pmax()[i]; - else - { - --p_[i]; - break; - } - if (p_ == b_.pmax()) - p_ = nop_; - } - - template <typename P> - void gen_box_bkd_piter_<P>::impl_invalidate() - { - p_ = nop_; - } - - template <typename P> - bool gen_box_bkd_piter_<P>::impl_is_valid() const - { - return p_ != nop_; - } - - template <typename P> - P gen_box_bkd_piter_<P>::impl_to_point() const - { - return p_; - } - - template <typename P> - const P* gen_box_bkd_piter_<P>::impl_point_adr() const + gen_box<P>::gen_box(const internal::initializer_<D>& data) : + super(data) { - return &p_; } # endif // !OLN_INCLUDE_ONLY Index: oln/core/internal/box.hh --- oln/core/internal/box.hh (revision 907) +++ oln/core/internal/box.hh (working copy) @@ -39,18 +39,14 @@ // Forward declarations. - namespace internal - { - template <typename Exact> class box_; + namespace internal { template <typename Exact> class box_; } template <typename Exact> class box_fwd_piter_; template <typename Exact> class box_bkd_piter_; - } // Super type declaration. template <typename Exact> struct super_trait_< internal::box_<Exact> > { - // typedef box_<Exact> current__; typedef internal::point_set_base_<Exact> ret; }; @@ -59,9 +55,8 @@ template <typename Exact> struct vtypes< internal::box_<Exact> > { - //typedef point2d point; - typedef stc::final< internal::box_fwd_piter_<Exact> > fwd_piter; - typedef stc::final< internal::box_bkd_piter_<Exact> > bkd_piter; + typedef stc::final< box_fwd_piter_<Exact> > fwd_piter; + typedef stc::final< box_bkd_piter_<Exact> > bkd_piter; }; @@ -103,6 +98,8 @@ box_(); box_(const point& pmin, const point& pmax); box_(const from_to_t& data); + template <typename D> + box_(const internal::initializer_<D>& data); point pmin_, pmax_; @@ -121,20 +118,19 @@ - /// Super types. template <typename B> - struct super_trait_< internal::box_fwd_piter_<B> > + struct super_trait_< box_fwd_piter_<B> > { - typedef internal::box_fwd_piter_<B> current__; + typedef box_fwd_piter_<B> current__; typedef Iterator_on_Points<current__> ret; }; template <typename B> - struct super_trait_<internal:: box_bkd_piter_<B> > + struct super_trait_<box_bkd_piter_<B> > { - typedef internal::box_bkd_piter_<B> current__; + typedef box_bkd_piter_<B> current__; typedef Iterator_on_Points<current__> ret; }; @@ -142,20 +138,18 @@ /// Virtual types. template <typename B> - struct vtypes< internal::box_fwd_piter_<B> > + struct vtypes< box_fwd_piter_<B> > { typedef typename B::point point; }; template <typename B> - struct vtypes< internal::box_bkd_piter_<B> > + struct vtypes< box_bkd_piter_<B> > { typedef typename B::point point; }; - namespace internal - { /// Class box_fwd_piter_<P>. template <typename B> @@ -168,7 +162,7 @@ stc_using(point); box_fwd_piter_(); - box_fwd_piter_(const Point_Set< B >& b); + box_fwd_piter_(const B& b); void set_box(const B& b); void impl_start(); @@ -196,7 +190,7 @@ stc_using(point); box_bkd_piter_(); - box_bkd_piter_(const Point_Set< B >& b); + box_bkd_piter_(const B& b); void set_box(const B& b); void impl_start(); @@ -216,6 +210,8 @@ # ifndef OLN_INCLUDE_ONLY + namespace internal + { // -------------------- box_<Exact> @@ -242,6 +238,13 @@ this->pmax_ = dat->second.value; } + template <typename Exact> + template <typename D> + box_<Exact>::box_(const internal::initializer_<D>& data) + { + bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value()); + postcondition(box_ok); + } template <typename Exact> unsigned @@ -301,7 +304,7 @@ { return this->pmax_; } - + } // -------------------- box_fwd_piter_<B> @@ -312,9 +315,9 @@ } template <typename B> - box_fwd_piter_<B>::box_fwd_piter_(const Point_Set< B >& b) + box_fwd_piter_<B>::box_fwd_piter_(const B& b) { - this->set_box(exact(b)); + this->set_box(b); } template <typename B> @@ -389,9 +392,9 @@ } template <typename B> - box_bkd_piter_<B>::box_bkd_piter_(const Point_Set< B >& b) + box_bkd_piter_<B>::box_bkd_piter_(const B& b) { - this->set_box(exact(b)); + this->set_box(b); } template <typename B> @@ -456,8 +459,6 @@ } # endif // OLN_INCLUDE_ONLY - } // end of namespace internal - } // end of namespace oln Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 907) +++ oln/core/internal/point_set_base.hh (working copy) @@ -84,13 +84,12 @@ typedef stc::abstract point; typedef stc::abstract fwd_piter; typedef stc::abstract bkd_piter; + typedef stc::abstract box; typedef stc_deferred(point) point__; typedef stc_deferred(fwd_piter) fwd_piter__; typedef stc::final< stc::is<Point_Set> > category; - //FIXME: - typedef gen_box<point__> box; typedef stc::final< oln_grid(point__) > grid; typedef stc::final< fwd_piter__ > piter; };
participants (1)
-
Nicolas Ballas