
https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Cleaning point set classes. * oln/core/point_set_entry.hh: Rename as... * oln/core/internal/point_set_base.hh: ...this and update. * oln/core/abstract/point_set.hh: Rename as... * oln/core/concept/point_set.hh: ...this and update. * oln/core/abstract/iterator.hh: Rename as... * oln/core/concept/iterator.hh: ...this and update. * oln/core/abstract/iterator_on_points.hh: Rename as... * oln/core/concept/iterator_on_points.hh: ...this and update. * oln/core/abstract/point_set/point_set_being_random_accessible.hh, * oln/core/abstract/point_set/point_set_having_known_size.hh, * oln/core/abstract/point_set/hierarchies.hh, * oln/core/abstract/point_set/all.hh, * oln/core/abstract/point_set/point_set_being_connected.hh, * oln/core/abstract/point_set/point_set_having_bbox.hh: Remove. * oln/core/gen/bbox.hh: Split and rename as... * oln/core/gen/box.hh: ...this and update... * oln/core/gen/fbbox.hh: ...and this and update. * oln/core/gen/bbox_fwd_piter.hh, * oln/core/gen/bbox_bkd_piter.hh: Remove because merge with... * oln/core/gen/box.hh: ...this. * oln/core/gen/pset_.hh: Rename as... * oln/core/gen/pset.hh: ...this and update. * oln/core/gen/pset_list.hh: Rename as... * oln/core/gen/plist.hh: ...this and update. * oln/core/gen/pset_vec.hh: Rename as... * oln/core/gen/pvec.hh: ...this and update. * oln/core/gen/piter_on_std_based_pset.hh: Rename as... * oln/core/internal/point_set_std_based.hh: ...this and update. * oln/core/2d/aliases.hh: Update. * oln/core/equipment.hh: Update. * oln/core/2d/box2d.hh: New. 2d/aliases.hh | 11 - 2d/box2d.hh | 44 ++++ concept/iterator.hh | 74 ++----- concept/iterator_on_points.hh | 120 +++-------- concept/point_set.hh | 107 ++++------ equipment.hh | 34 ++- gen/box.hh | 420 ++++++++++++++++++++++++++-------------- gen/fbbox.hh | 127 ++++++++++++ gen/plist.hh | 149 +++----------- gen/pset.hh | 129 ++---------- gen/pvec.hh | 144 ++++--------- internal/point_set_base.hh | 72 +++--- internal/point_set_std_based.hh | 343 +++++++++++++++++++++----------- 13 files changed, 951 insertions(+), 823 deletions(-) Index: oln/core/concept/iterator_on_points.hh --- oln/core/concept/iterator_on_points.hh (revision 843) +++ oln/core/concept/iterator_on_points.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2003, 2004, 2005, 2006 EPITA Research and +// Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -26,131 +26,79 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_ABSTRACT_ITERATOR_ON_POINTS_HH -# define OLN_CORE_ABSTRACT_ITERATOR_ON_POINTS_HH +#ifndef OLN_CORE_CONCEPT_ITERATOR_ON_POINTS_HH +# define OLN_CORE_CONCEPT_ITERATOR_ON_POINTS_HH -# include <oln/core/abstract/iterator.hh> -# include <oln/core/abstract/point.hh> +# include <ostream> +# include <oln/core/concept/iterator.hh> +# include <oln/core/concept/point.hh> namespace oln { + /// Concept-class "Iterator_on_Points". - // Forward declaration. - namespace abstract { template <typename E> class iterator_on_points; } - - - // Super type declaration. - template <typename E> - struct set_super_type< abstract::iterator_on_points<E> > - { - typedef abstract::iterator<E> ret; - }; - - - /// Virtual types associated to abstract::iterator_on_points<E>. - template <typename E> - struct vtypes< abstract::iterator_on_points<E> > - { - typedef stc::abstract point_type; -# ifndef OLENA_USE_SCOOP_ALT - typedef oln_deduce_deferred_vtype(E, point, coord) coord_type; -# endif // !OLENA_USE_SCOOP_ALT - }; - -# ifdef OLENA_USE_SCOOP_ALT - template <typename E> - struct single_vtype< abstract::iterator_on_points<E>, - typedef_::coord_type > - { - typedef oln_deduce_deferred_vtype(E, point, coord) ret; - }; -# endif // OLENA_USE_SCOOP_ALT - - - namespace abstract - { - - /// Abstract point iterator class. - template <typename E> - class iterator_on_points : public abstract::iterator<E> + template <typename Exact> + struct Iterator_on_Points : public Iterator<Exact> { - typedef oln_point(E) point_t; + stc_typename(point); - public: + point to_point() const; + const point* point_adr() const; - point_t to_point() const; - - const point_t* point_adr() const; - - // Concrete method. - operator point_t() const; + // Default. + operator point() const; protected: + Iterator_on_Points(); - iterator_on_points(); - - ~iterator_on_points(); + }; // end of class oln::Iterator_on_Points<Exact> - }; // end of class oln::abstract::iterator_on_points<E> - - template <typename E> - std::ostream& operator<<(std::ostream& ostr, const iterator_on_points<E>& pit); + template <typename Exact> + std::ostream& operator<<(std::ostream& ostr, const Iterator_on_Points<Exact>& pit); # ifndef OLN_INCLUDE_ONLY - template <typename E> - typename iterator_on_points<E>::point_t - iterator_on_points<E>::to_point() const + template <typename Exact> + typename Iterator_on_Points<Exact>::point + Iterator_on_Points<Exact>::to_point() const { precondition(this->is_valid()); - return this->exact().impl_to_point(); + return exact(this)->impl_to_point(); } - template <typename E> - const typename iterator_on_points<E>::point_t* - iterator_on_points<E>::point_adr() const + template <typename Exact> + const typename Iterator_on_Points<Exact>::point* + Iterator_on_Points<Exact>::point_adr() const { - return this->exact().impl_point_adr(); + return exact(this)->impl_point_adr(); } - template <typename E> - // Concrete method. - iterator_on_points<E>::operator typename iterator_on_points<E>::point_t() const + template <typename Exact> + Iterator_on_Points<Exact>::operator typename Iterator_on_Points<Exact>::point() const { precondition(this->is_valid()); return this->to_point(); } - template <typename E> - iterator_on_points<E>::iterator_on_points() + template <typename Exact> + Iterator_on_Points<Exact>::Iterator_on_Points() { + mlc::assert_< mlc_is_a(typename Iterator_on_Points<Exact>::point, Point) >::check(); } - template <typename E> - iterator_on_points<E>::~iterator_on_points() - { - mlc::assert_defined_< typename iterator_on_points<E>::point_t >::check(); - mlc::assert_< mlc_is_a(typename iterator_on_points<E>::point_t, abstract::point) >::check(); - } - - - template <typename E> - std::ostream& operator<<(std::ostream& ostr, const iterator_on_points<E>& pit) + template <typename Exact> + std::ostream& operator<<(std::ostream& ostr, const Iterator_on_Points<Exact>& pit) { return ostr << pit.to_point(); } - # endif - } // end of namespace oln::abstract - - } // end of namespace oln -#endif // ! OLN_CORE_ABSTRACT_ITERATOR_ON_POINTS_HH +#endif // ! OLN_CORE_CONCEPT_ITERATOR_ON_POINTS_HH Index: oln/core/concept/point_set.hh --- oln/core/concept/point_set.hh (revision 843) +++ oln/core/concept/point_set.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2007 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 @@ -25,92 +25,89 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_ABSTRACT_POINT_SET_HH -# define OLN_CORE_ABSTRACT_POINT_SET_HH +#ifndef OLN_CORE_CONCEPT_POINT_SET_HH +# define OLN_CORE_CONCEPT_POINT_SET_HH -# include <oln/core/typedefs.hh> +# include <ostream> +# include <oln/core/equipment.hh> namespace oln { - namespace abstract - { - - - /// Abstract point class. - template <typename E> - class point_set : public virtual stc::any__simple<E>, - public virtual oln::type - { - public: - bool is_valid() const; + /// Concept-class "Point_Set". - struct decl + template <typename Exact> + struct Point_Set : public Any<Exact> { - oln_virtual_typedef(point); - - oln_virtual_typedef(piter); - oln_virtual_typedef(fwd_piter); - oln_virtual_typedef(bkd_piter); - - oln_virtual_typedef(bbox); // provides .bbox() - oln_virtual_typedef(is_random_accessible); // provides .has(p) - oln_virtual_typedef(has_known_size); // provides .npoints() - oln_virtual_typedef(is_connected); // provides, e.g., .nrows() - - // derived from point: - oln_virtual_typedef(coord); - oln_virtual_typedef(grid); - oln_virtual_typedef(dim); - - decl(); - }; - - ~point_set(); + stc_typename(point); + stc_typename(grid); + stc_typename(piter); + stc_typename(fwd_piter); + stc_typename(bkd_piter); + stc_typename(box); + + // FIXME: Add coord and dim? + + unsigned npoints() const; + bool has(const point& p) const; + const box& bbox() const; protected: + Point_Set(); + + }; // end of oln::Point_Set<Exact> - point_set(); - }; // end of class oln::abstract::point_set<E> + template <typename Ps> + std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts); # ifndef OLN_INCLUDE_ONLY - template <typename E> - bool point_set<E>::is_valid() const + template <typename Exact> + unsigned + Point_Set<Exact>::npoints() const { - return this->exact().impl_is_valid(); + return exact(this)->impl_npoints(); } - template <typename E> - point_set<E>::decl::decl() + template <typename Exact> + bool + Point_Set<Exact>::has(const typename Point_Set<Exact>::point& p) const { - // coherence check: - // FIXME: Rec? -// mlc::assert_equal_< oln_grid(fwd_piter), oln_grid(point) >::check(); -// mlc::assert_equal_< oln_grid(bkd_piter), oln_grid(point) >::check(); + return exact(this)->impl_has(); } - template <typename E> - point_set<E>::point_set() + template <typename Exact> + const typename Point_Set<Exact>::box& + Point_Set<Exact>::bbox() const { + return exact(this)->impl_bbox(); } - template <typename E> - point_set<E>::~point_set() + template <typename Exact> + Point_Set<Exact>::Point_Set() { - decl(); } -# endif + template <typename Ps> + std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts) + { + ostr << "{ "; + typename Ps::piter p(pts); + for_all(p) + ostr << p << ' '; // FIXME: Add ','? + return ostr << " }"; + } + + +# endif - } // end of namespace oln::abstract } // end of namespace oln -#endif // ! OLN_CORE_ABSTRACT_POINT_SET_HH +#endif // ! OLN_CORE_CONCEPT_POINT_SET_HH Index: oln/core/concept/iterator.hh --- oln/core/concept/iterator.hh (revision 843) +++ oln/core/concept/iterator.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2003, 2004, 2005, 2006 EPITA Research and +// Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -26,92 +26,74 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_ABSTRACT_ITERATOR_HH -# define OLN_CORE_ABSTRACT_ITERATOR_HH +#ifndef OLN_CORE_CONCEPT_ITERATOR_HH +# define OLN_CORE_CONCEPT_ITERATOR_HH -# include <oln/core/typedefs.hh> +# include <oln/core/equipment.hh> -namespace oln -{ - - namespace abstract { template <typename E> class iterator; } +/// Macro for_all. +# define for_all(i) for (i.start(); i.is_valid(); i.next()) - template <typename E> - struct set_super_type< abstract::iterator<E> > - { - typedef mlc::none ret; - }; - namespace abstract +namespace oln { - /// Abstract iterator class. - template <typename E> - class iterator : public stc::any__best_memory<E>, - public oln::type - { - public: + /// Concept-class "Iterator". + template <typename Exact> + struct Iterator : public Any<Exact> + { void start(); - void next(); - void invalidate(); - bool is_valid() const; protected: + Iterator(); - iterator(); - - }; // end of class oln::abstract::iterator<E> + }; // end of class oln::Iterator<Exact> # ifndef OLN_INCLUDE_ONLY - template <typename E> - void iterator<E>::start() + template <typename Exact> + void Iterator<Exact>::start() { - this->exact().impl_start(); + exact(this)->impl_start(); } - template <typename E> - void iterator<E>::next() + template <typename Exact> + void Iterator<Exact>::next() { precondition(this->is_valid()); - this->exact().impl_next(); + exact(this)->impl_next(); } - template <typename E> - void iterator<E>::invalidate() + template <typename Exact> + void Iterator<Exact>::invalidate() { - this->exact().impl_invalidate(); + exact(this)->impl_invalidate(); } - template <typename E> - bool iterator<E>::is_valid() const + template <typename Exact> + bool Iterator<Exact>::is_valid() const { - return this->exact().impl_is_valid(); + return exact(this)->impl_is_valid(); } - template <typename E> - iterator<E>::iterator() + template <typename Exact> + Iterator<Exact>::Iterator() { } # endif - } // end of namespace oln::abstract - - } // end of namespace oln -#define for_all(i) for (i.start(); i.is_valid(); i.next()) - -#endif // ! OLN_CORE_ABSTRACT_ITERATOR_HH +#endif // ! OLN_CORE_CONCEPT_ITERATOR_HH Index: oln/core/2d/aliases.hh --- oln/core/2d/aliases.hh (revision 843) +++ oln/core/2d/aliases.hh (working copy) @@ -35,12 +35,8 @@ /// Forward declarations. /// \{ - template <unsigned D> struct grid_; - template <typename C> class point2d_; - template <typename C> class dpoint2d_; template <typename D> class neighb_; template <typename D> class window_; - template <typename P> class bbox_; template <typename P> class topo_lbbox_; template <typename P> class fwd_piter_bbox_; template <typename P> class bkd_piter_bbox_; @@ -51,15 +47,10 @@ /// Aliases. /// \{ - typedef grid_<2> grid2d; - - typedef point2d_<int> point2d; - typedef dpoint2d_<int> dpoint2d; typedef neighb_<dpoint2d> neighb2d; typedef window_<dpoint2d> window2d; - typedef bbox_<point2d> bbox2d; typedef topo_lbbox_<point2d> topo2d; typedef fwd_piter_bbox_<point2d> fwd_piter2d; @@ -68,8 +59,6 @@ typedef fwd_qiter_win_<point2d> fwd_qiter2d; typedef bkd_qiter_win_<point2d> bkd_qiter2d; - typedef point2d_<float> point2df; - typedef dpoint2d_<float> dpoint2df; /// \} Index: oln/core/2d/box2d.hh --- oln/core/2d/box2d.hh (revision 0) +++ oln/core/2d/box2d.hh (revision 0) @@ -0,0 +1,44 @@ +// Copyright (C) 2007 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 OLN_CORE_2D_BOX2D_HH +# define OLN_CORE_2D_BOX2D_HH + +# include <oln/core/gen/box.hh> +# include <oln/core/2d/point2d.hh> + + +namespace oln +{ + + typedef box_<point2d> box2d; + +} // end of namespace oln + + +#endif // ! OLN_CORE_2D_BOX2D_HH + Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 843) +++ oln/core/equipment.hh (working copy) @@ -39,22 +39,36 @@ # include <oln/stc/scoop.hxx> // FIXME: Remove "oln/" later. - - stc_decl_associated_type(grid); + // b + stc_decl_associated_type( bkd_piter ); + stc_decl_associated_type( box ); + // c stc_decl_associated_type(coord); + // d + stc_decl_associated_type( data ); stc_decl_associated_type(dim); - stc_decl_associated_type(point); stc_decl_associated_type(dpoint); - stc_decl_associated_type(psite); + // f + stc_decl_associated_type( fwd_piter ); + // g + stc_decl_associated_type( grid ); + // i stc_decl_associated_type(index); - stc_decl_associated_type(value); - stc_decl_associated_type(rvalue); + // l stc_decl_associated_type(lvalue); - stc_decl_associated_type(iter); - stc_decl_associated_type(data); - stc_decl_associated_type(box); - stc_decl_associated_type(pset); + // n stc_decl_associated_type(n); + // p + stc_decl_associated_type( piter ); + stc_decl_associated_type( point ); + stc_decl_associated_type( pset ); + stc_decl_associated_type( psite ); + // r + stc_decl_associated_type( rvalue ); + // s + stc_decl_associated_type( std_container ); + // v + stc_decl_associated_type( value ); } // end of namespace oln Index: oln/core/gen/box.hh --- oln/core/gen/box.hh (revision 843) +++ oln/core/gen/box.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2003, 2004, 2005, 2006 EPITA Research and +// Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007 EPITA Research and // Development Laboratory // // This file is part of the Olena Library. This library is free @@ -26,239 +26,385 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_GEN_BBOX_HH -# define OLN_CORE_GEN_BBOX_HH +#ifndef OLN_CORE_GEN_BOX_HH +# define OLN_CORE_GEN_BOX_HH -# include <oln/core/point_set_entry.hh> -# include <oln/core/abstract/point.hh> +# include <oln/core/concept/point.hh> +# include <oln/core/concept/iterator_on_points.hh> +# include <oln/core/internal/point_set_base.hh> namespace oln { // Forward declarations. - template <typename point_t> class bbox_; - template <typename point_t> class bbox_fwd_piter_; - template <typename point_t> class bbox_bkd_piter_; + template <typename P> class box_; + template <typename P> class box_fwd_piter_; + template <typename P> class box_bkd_piter_; // Super type declaration. - template <typename point_t> - struct set_super_type< bbox_<point_t> > + template <typename P> + struct super_trait_< box_<P> > { - typedef bbox_<point_t> self_t; - typedef point_set_entry<self_t> ret; + typedef box_<P> current__; + typedef internal::point_set_base_<current__> ret; }; - /// Virtual types associated to oln::bbox_<point_t>. - template <typename point_t> - struct vtypes< bbox_<point_t> > - { - typedef point_t point_type; - typedef bbox_fwd_piter_<point_t> fwd_piter_type; - typedef bbox_bkd_piter_<point_t> bkd_piter_type; - - typedef bbox_<point_t> bbox_type; - - typedef mlc::true_ is_random_accessible_type; - typedef mlc::true_ has_known_size_type; - typedef mlc::true_ is_connected_type; + /// Virtual types associated to oln::box_<P>. + template <typename P> + struct vtypes< box_<P> > + { + typedef P point; + typedef box_fwd_piter_<P> fwd_piter; + typedef box_bkd_piter_<P> bkd_piter; }; - /// Bounding box class based on a point class. - template <typename point_t> - class bbox_ : public point_set_entry< bbox_<point_t> >, - private mlc::assert_< mlc_is_a(point_t, abstract::point) > + /// Generic box class based on a point class. + + template <typename P> + class box_ : public internal::point_set_base_< box_<P> >, + private mlc::assert_< mlc_is_a(P, Point) > { - // Make self_type public so that is can be used to define a - // virtual type of oln::topo_bbox_ and oln::topo_lbbox_. + typedef box_<P> current; + typedef internal::point_set_base_<current> super; public: - typedef bbox_<point_t> self_type; + + stc_using(point); + stc_using(box); private: - typedef point_set_entry<self_type> super_t; + typedef stc_type(point, dim) dim__; + enum { n = mlc_value(dim__) }; - typedef oln_vtype(point_t, coord) coord_t; + public: - typedef oln_vtype(point_t, dim) dim; - enum { n = mlc_value(dim) }; + box_(); + box_(const P& pmin, const P& pmax); - public: + unsigned impl_npoints() const; + bool impl_has(const P& p) const; + const box_<P>& impl_bbox() const; - bbox_(); + const P& pmin() const; + P& pmin(); + const P& pmax() const; + P& pmax(); - bbox_(const point_t& pmin, const point_t& pmax); + protected: + point pmin_, pmax_; - bbox_(const bbox_<point_t>& rhs); + }; // end of class oln::box_<P> - bbox_<point_t>& operator=(const bbox_<point_t>& rhs); - unsigned impl_npoints() const; - bool impl_has(const point_t& p) const; - void flush(); + // -------------------- iterators on box_<P> - void init_with(const point_t& p); - void update_with(const point_t& p); - void take(const point_t& p); - // FIXME: Add "update : (rhs : exact)" + /// Super types. + + template <typename P> + struct super_trait_< box_fwd_piter_<P> > + { + typedef box_fwd_piter_<P> current__; + typedef Iterator_on_Points<current__> ret; + }; + + template <typename P> + struct super_trait_< box_bkd_piter_<P> > + { + typedef box_bkd_piter_<P> current__; + typedef Iterator_on_Points<current__> ret; + }; + - bool includes(const bbox_<point_t>& rhs) const; + /// Virtual types. + template <typename P> + struct vtypes< box_fwd_piter_<P> > + { + typedef P point; + }; + + template <typename P> + struct vtypes< box_bkd_piter_<P> > + { + typedef P point; + }; + + + /// Class box_fwd_piter_<P>. + + template <typename P> + class box_fwd_piter_ : public Iterator_on_Points< box_fwd_piter_<P> >, + private mlc::assert_< mlc_is_a(P, Point) > + { + public: + box_fwd_piter_(); + box_fwd_piter_(const Point_Set< box_<P> >& b); + void set_box(const 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; - void impl_print(std::ostream& ostr) const; + private: + box_<P> b_; + P p_, nop_; + }; - protected: - bool is_valid_; + /// Class box_bkd_piter_<P>. + + template <typename P> + class box_bkd_piter_ : public Iterator_on_Points< box_bkd_piter_<P> >, + private mlc::assert_< mlc_is_a(P, Point) > + { + public: + box_bkd_piter_(); + box_bkd_piter_(const Point_Set< box_<P> >& b); + void set_box(const 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: + box_<P> b_; + P p_, nop_; + }; - }; // end of class oln::bbox_<point_t> # ifndef OLN_INCLUDE_ONLY - template <typename point_t> - bbox_<point_t>::bbox_() + + // -------------------- box_<P> + + + template <typename P> + box_<P>::box_() { - flush(); } - template <typename point_t> - bbox_<point_t>::bbox_(const point_t& pmin, const point_t& pmax) + template <typename P> + box_<P>::box_(const P& pmin, const P& pmax) { + for (unsigned i = 0; i < n; ++i) + precondition(pmax[i] >= pmin[i]); this->pmin_ = pmin; this->pmax_ = pmax; - is_valid_ = true; + } + template <typename P> + unsigned + box_<P>::impl_npoints() const + { + unsigned count = 1; for (unsigned i = 0; i < n; ++i) - precondition(pmax[i] >= pmin[i]); + count *= (this->pmax_[i] - this->pmin_[i] + 1); + return count; } - template <typename point_t> - bbox_<point_t>::bbox_(const bbox_<point_t>& rhs) + template <typename P> + bool + box_<P>::impl_has(const P& p) const { - // FIXME: Remove these 3 lines? - precondition(rhs.is_valid()); for (unsigned i = 0; i < n; ++i) - precondition(rhs.pmax_[i] >= rhs.pmin_[i]); + if (p[i] < this->pmin_[i] or p[i] > this->pmax_[i]) + return false; + return true; + } - this->pmin_ = rhs.pmin_; - this->pmax_ = rhs.pmax_; - is_valid_ = rhs.is_valid_; + template <typename P> + const box_<P>& + box_<P>::impl_bbox() const + { + return *this; + } + template <typename P> + const P& + box_<P>::pmin() const + { for (unsigned i = 0; i < n; ++i) - postcondition(this->pmax_[i] >= this->pmin_[i]); + invariant(pmin[i] <= pmax[i]); + return this->pmin_; } - template <typename point_t> - bbox_<point_t>& bbox_<point_t>::operator=(const bbox_<point_t>& rhs) + template <typename P> + const P& + box_<P>::pmax() const { - // FIXME: Remove these 3 lines? - precondition(rhs.is_valid()); for (unsigned i = 0; i < n; ++i) - precondition(rhs.pmax_[i] >= rhs.pmin_[i]); + invariant(pmax[i] >= pmin[i]); + return this->pmax_; + } - this->pmin_ = rhs.pmin_; - this->pmax_ = rhs.pmax_; - is_valid_ = rhs.is_valid_; + template <typename P> + P& + box_<P>::pmin() + { + return this->pmin_; + } - for (unsigned i = 0; i < n; ++i) - postcondition(this->pmax_[i] >= this->pmin_[i]); + template <typename P> + P& + box_<P>::pmax() + { + return this->pmax_; + } - return *this; + + + // -------------------- box_fwd_piter_<P> + + + template <typename P> + box_fwd_piter_<P>::box_fwd_piter_() + { } - template <typename point_t> - unsigned bbox_<point_t>::impl_npoints() const + template <typename P> + box_fwd_piter_<P>::box_fwd_piter_(const Point_Set< box_<P> >& b) { - unsigned count = 1; - for (unsigned i = 0; i < n; ++i) - count *= this->len(i); - return count; + this->set_box(exact(b)); } - template <typename point_t> - bool bbox_<point_t>::impl_has(const point_t& p) const + template <typename P> + void box_fwd_piter_<P>::set_box(const box_<P>& b) { - precondition(is_valid_); - for (unsigned i = 0; i < n; ++i) - if (p[i] < this->pmin_[i] or p[i] > this->pmax_[i]) - return false; - return true; + b_ = b; + nop_ = b_.pmax(); + ++nop_[0]; + p_ = nop_; } - template <typename point_t> - void bbox_<point_t>::flush() + template <typename P> + void box_fwd_piter_<P>::impl_start() { - is_valid_ = false; + p_ = b_.pmin(); } - template <typename point_t> - void bbox_<point_t>::init_with(const point_t& p) + template <typename P> + void box_fwd_piter_<P>::impl_next() { - precondition(not is_valid_); - this->pmin_ = p; - this->pmax_ = p; - is_valid_ = true; + 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 point_t> - void bbox_<point_t>::update_with(const point_t& p) + template <typename P> + void box_fwd_piter_<P>::impl_invalidate() { - precondition(is_valid_); - for (unsigned i = 0; i < n; ++i) - if (p[i] < this->pmin_[i]) - this->pmin_[i] = p[i]; - else if (p[i] > this->pmax_[i]) - this->pmax_[i] = p[i]; + p_ = nop_; } - template <typename point_t> - void bbox_<point_t>::take(const point_t& p) + template <typename P> + bool box_fwd_piter_<P>::impl_is_valid() const { - if (not is_valid_) + return p_ != nop_; + } + + template <typename P> + P box_fwd_piter_<P>::impl_to_point() const { - init_with(p); - return; + return p_; } - for (unsigned i = 0; i < n; ++i) - if (p[i] < this->pmin_[i]) - this->pmin_[i] = p[i]; - else if (p[i] > this->pmax_[i]) - this->pmax_[i] = p[i]; + + template <typename P> + const P* box_fwd_piter_<P>::impl_point_adr() const + { + return &p_; } - template <typename point_t> - bool bbox_<point_t>::includes(const bbox_<point_t>& rhs) const + + + // -------------------- box_bkd_piter_<P> + + + template <typename P> + box_bkd_piter_<P>::box_bkd_piter_() { - precondition(is_valid_ and rhs.is_valid()); - for (unsigned i = 0; i < n; ++i) - if (rhs.pmin()[i] < this->pmin_[i] or rhs.pmax()[i] > this->pmax_[i]) - return false; - return true; } - template <typename point_t> - bool bbox_<point_t>::impl_is_valid() const + template <typename P> + box_bkd_piter_<P>::box_bkd_piter_(const Point_Set< box_<P> >& b) + { + this->set_box(exact(b)); + } + + template <typename P> + void box_bkd_piter_<P>::set_box(const box_<P>& b) + { + b_ = b; + nop_ = b_.pmin(); + --nop_[0]; + p_ = nop_; + } + + template <typename P> + void box_bkd_piter_<P>::impl_start() + { + p_ = b_.pmax(); + } + + template <typename P> + void 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 box_bkd_piter_<P>::impl_invalidate() + { + p_ = nop_; + } + + template <typename P> + bool box_bkd_piter_<P>::impl_is_valid() const + { + return p_ != nop_; + } + + template <typename P> + P box_bkd_piter_<P>::impl_to_point() const { - return is_valid_; + return p_; } - template <typename point_t> - void bbox_<point_t>::impl_print(std::ostream& ostr) const + template <typename P> + const P* box_bkd_piter_<P>::impl_point_adr() const { - ostr << "{ pmin=" << this->pmin_ - << ", pmax=" << this->pmax_ - << ", valid=" << is_valid_ - << " }"; + return &p_; } # endif @@ -267,4 +413,4 @@ } // end of namespace oln -#endif // ! OLN_CORE_GEN_BBOX_HH +#endif // ! OLN_CORE_GEN_BOX_HH Index: oln/core/gen/plist.hh --- oln/core/gen/plist.hh (revision 843) +++ oln/core/gen/plist.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2007 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 @@ -25,157 +25,78 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_GEN_PSET_LIST_HH -# define OLN_CORE_GEN_PSET_LIST_HH +#ifndef OLN_CORE_GEN_PLIST_HH +# define OLN_CORE_GEN_PLIST_HH # include <list> - -# include <oln/core/point_set_entry.hh> -# include <oln/core/abstract/point.hh> +# include <oln/core/internal/point_set_std_based.hh> namespace oln { - // Forward declarations. - template <typename point_t> class pset_list; - template <typename C> class fwd_piter_on_std_based_pset; - template <typename C> class bkd_piter_on_std_based_pset; + /// Fwd decl. + template <typename P> class plist_; - // Super type declaration. - template <typename point_t> - struct set_super_type< pset_list<point_t> > + // Super type. + template <typename P> + struct super_trait_< plist_<P> > { - typedef pset_list<point_t> self_t; - typedef point_set_entry<self_t> ret; + typedef plist_<P> current__; + typedef internal::point_set_std_based_<current__> ret; }; - /// Virtual types associated to oln::pset_list<point_t>. - template <typename point_t> - struct vtypes< pset_list<point_t> > - { - typedef point_t point_type; - typedef fwd_piter_on_std_based_pset< std::list<point_t> > fwd_piter_type; - typedef bkd_piter_on_std_based_pset< std::list<point_t> > bkd_piter_type; - - typedef mlc::false_ is_random_accessible_type; - typedef mlc::true_ has_known_size_type; - typedef mlc::false_ is_connected_type; + /// Virtual types. + template <typename P> + struct vtypes< plist_<P> > + { + typedef std::list<P> std_container; }; - /// Bounding box class based on a point class. - template <typename point_t> - class pset_list : public point_set_entry< pset_list<point_t> >, - private mlc::assert_< mlc_is_a(point_t, abstract::point) > - { - typedef pset_list<point_t> self_type; - typedef point_set_entry<self_type> super_t; + /// Point set class based on std::list. + template <typename P> + class plist_ : public internal::point_set_std_based_< plist_<P> > + { public: - pset_list(); - pset_list(const pset_list<point_t>& rhs); - pset_list<point_t>& operator=(const pset_list<point_t>& rhs); - - unsigned impl_npoints() const; - bool impl_is_valid() const; - void impl_print(std::ostream& ostr) const; - - pset_list<point_t>& append(const point_t& p); - pset_list<point_t>& prepend(const point_t& p); - - const std::list<point_t>& container() const; - std::list<point_t>& container(); - - protected: - - std::list<point_t> lp_; + plist_(); + plist_<P>& append(const P& p); + plist_<P>& prepend(const P& p); - }; // end of class oln::pset_list<point_t> + }; // end of class oln::plist_<P>. # ifndef OLN_INCLUDE_ONLY - template <typename point_t> - pset_list<point_t>::pset_list() + template <typename P> + plist_<P>::plist_() { } - template <typename point_t> - pset_list<point_t>::pset_list(const pset_list<point_t>& rhs) + template <typename P> + plist_<P>& plist_<P>::append(const P& p) { - lp_ = rhs.lp_; - } - - template <typename point_t> - pset_list<point_t>& pset_list<point_t>::operator=(const pset_list<point_t>& rhs) - { - lp_ = rhs.lp_; + this->con_.push_back(p); + this->take_(p); return *this; } - template <typename point_t> - unsigned pset_list<point_t>::impl_npoints() const - { - return lp_.size(); - } - - template <typename point_t> - bool pset_list<point_t>::impl_is_valid() const + template <typename P> + plist_<P>& plist_<P>::prepend(const P& p) { - return true; - } - - template <typename point_t> - void pset_list<point_t>::impl_print(std::ostream& ostr) const - { - typename std::list<point_t>::const_iterator it; - ostr << "{ "; - for (it = lp_.begin(); it != lp_.end(); ++it) - ostr << *it << ' '; - ostr << "}"; - } - - template <typename point_t> - pset_list<point_t>& pset_list<point_t>::append(const point_t& p) - { - precondition(std::find(lp_.begin(), lp_.end(), p) - = lp_.end()); - lp_.push_back(p); - return *this; - } - - template <typename point_t> - pset_list<point_t>& pset_list<point_t>::prepend(const point_t& p) - { - precondition(std::find(lp_.begin(), lp_.end(), p) - = lp_.end()); - lp_.push_front(p); + this->con_.push_front(p); + this->take_(p); return *this; } - template <typename point_t> - const std::list<point_t>& pset_list<point_t>::container() const - { - return lp_; - } - - template <typename point_t> - std::list<point_t>& pset_list<point_t>::container() - { - return lp_; - } - # endif } // end of namespace oln -# include <oln/core/gen/piter_on_std_based_pset.hh> - - -#endif // ! OLN_CORE_GEN_PSET_LIST_HH +#endif // ! OLN_CORE_GEN_PLIST_HH Index: oln/core/gen/pvec.hh --- oln/core/gen/pvec.hh (revision 843) +++ oln/core/gen/pvec.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2007 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 @@ -25,139 +25,82 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_GEN_PSET_VEC_HH -# define OLN_CORE_GEN_PSET_VEC_HH +#ifndef OLN_CORE_GEN_PVEC_HH +# define OLN_CORE_GEN_PVEC_HH # include <vector> - -# include <oln/core/point_set_entry.hh> -# include <oln/core/abstract/point.hh> +# include <oln/core/internal/point_set_std_based.hh> namespace oln { - // Forward declarations. - template <typename point_t> class pset_vec; - template <typename C> class fwd_piter_on_std_based_pset; - template <typename C> class bkd_piter_on_std_based_pset; + /// Fwd decl. + template <typename P> class pvec_; - // Super type declaration. - template <typename point_t> - struct set_super_type< pset_vec<point_t> > + // Super type. + template <typename P> + struct super_trait_< pvec_<P> > { - typedef pset_vec<point_t> self_t; - typedef point_set_entry<self_t> ret; + typedef pvec_<P> current__; + typedef internal::point_set_std_based_<current__> ret; }; - /// Virtual types associated to oln::pset_vec<point_t>. - template <typename point_t> - struct vtypes< pset_vec<point_t> > - { - typedef point_t point_type; - typedef fwd_piter_on_std_based_pset< std::vector<point_t> > fwd_piter_type; - typedef bkd_piter_on_std_based_pset< std::vector<point_t> > bkd_piter_type; - - typedef mlc::false_ is_random_accessible_type; - typedef mlc::true_ has_known_size_type; - typedef mlc::false_ is_connected_type; + /// Virtual types. + template <typename P> + struct vtypes< pvec_<P> > + { + typedef std::vector<P> std_container; }; - /// Bounding box class based on a point class. - template <typename point_t> - class pset_vec : public point_set_entry< pset_vec<point_t> >, - private mlc::assert_< mlc_is_a(point_t, abstract::point) > - { - typedef pset_vec<point_t> self_type; - typedef point_set_entry<self_type> super_t; + /// Point set class based on std::set. + template <typename P> + class pvec_ : public internal::point_set_std_based_< pvec_<P> > + { public: - pset_vec(); - pset_vec(const pset_vec<point_t>& rhs); - pset_vec<point_t>& operator=(const pset_vec<point_t>& rhs); - - unsigned impl_npoints() const; - bool impl_is_valid() const; - void impl_print(std::ostream& ostr) const; - - pset_vec<point_t>& append(const point_t& p); - - const std::vector<point_t>& container() const; - std::vector<point_t>& container(); + pvec_(); + pvec_<P>& append(const P& p); + const P& operator[](unsigned i) const; + P& operator[](unsigned i); - protected: - - std::vector<point_t> vp_; - - }; // end of class oln::pset_vec<point_t> + }; // end of class oln::pvec_<P>. # ifndef OLN_INCLUDE_ONLY - template <typename point_t> - pset_vec<point_t>::pset_vec() + template <typename P> + pvec_<P>::pvec_() { } - template <typename point_t> - pset_vec<point_t>::pset_vec(const pset_vec<point_t>& rhs) + template <typename P> + pvec_<P>& + pvec_<P>::append(const P& p) { - vp_ = rhs.vp_; - } - - template <typename point_t> - pset_vec<point_t>& pset_vec<point_t>::operator=(const pset_vec<point_t>& rhs) - { - vp_ = rhs.vp_; + this->con_.push_back(p); + this->take_(p); return *this; } - template <typename point_t> - unsigned pset_vec<point_t>::impl_npoints() const + template <typename P> + const P& + pvec_<P>::operator[](unsigned i) const { - return vp_.size(); + precondition(i < this->npoints()); + return this->con_[i]; } - template <typename point_t> - bool pset_vec<point_t>::impl_is_valid() const + template <typename P> + P& pvec_<P>::operator[](unsigned i) { - return true; - } - - template <typename point_t> - void pset_vec<point_t>::impl_print(std::ostream& ostr) const - { - typename std::vector<point_t>::const_iterator it; - ostr << "{ "; - for (it = vp_.begin(); it != vp_.end(); ++it) - ostr << *it << ' '; - ostr << "}"; - } - - template <typename point_t> - pset_vec<point_t>& pset_vec<point_t>::append(const point_t& p) - { - precondition(std::find(vp_.begin(), vp_.end(), p) - = vp_.end()); - vp_.push_back(p); - return *this; - } - - template <typename point_t> - const std::vector<point_t>& pset_vec<point_t>::container() const - { - return vp_; - } - - template <typename point_t> - std::vector<point_t>& pset_vec<point_t>::container() - { - return vp_; + precondition(i < this->npoints()); + return this->con_[i]; } # endif @@ -165,7 +108,4 @@ } // end of namespace oln -# include <oln/core/gen/piter_on_std_based_pset.hh> - - -#endif // ! OLN_CORE_GEN_PSET_VEC_HH +#endif // ! OLN_CORE_GEN_PVEC_HH Index: oln/core/gen/fbbox.hh --- oln/core/gen/fbbox.hh (revision 0) +++ oln/core/gen/fbbox.hh (revision 0) @@ -0,0 +1,127 @@ +// Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007 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 OLN_CORE_GEN_FBBOX_HH +# define OLN_CORE_GEN_FBBOX_HH + +# include <oln/core/gen/box.hh> +# include <oln/core/concept/point.hh> + + +namespace oln +{ + + + /// Bounding box function based on a point class. + + template <typename P> + class fbbox_ : private mlc::assert_< mlc_is_a(P, Point) > + { + private: + typedef stc_type(P, dim) dim__; + enum { n = mlc_value(dim__) }; + + public: + + fbbox_(); + operator box_<P>() const; + + bool is_valid() const; + void flush(); + fbbox_<P>& take(const P& p); + const box_<P>& box() const; + + private: + bool is_valid_; + box_<P> b_; + + }; // end of class oln::fbbox_<P> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename P> + fbbox_<P>::fbbox_() + { + this->flush(); + } + + template <typename P> + fbbox_<P>::operator box_<P>() const + { + precondition(this->is_valid_); + return this->b_; + } + + template <typename P> + bool fbbox_<P>::is_valid() const + { + return this->is_valid_; + } + + template <typename P> + void fbbox_<P>::flush() + { + is_valid_ = false; + } + + template <typename P> + fbbox_<P>& fbbox_<P>::take(const P& p) + { + if (not this->is_valid_) + { + this->b_.pmin() = p; + this->b_.pmax() = p; + this->is_valid_ = true; + } + else + { + for (unsigned i = 0; i < n; ++i) + if (p[i] < this->b_.pmin()[i]) + this->b_.pmin()[i] = p[i]; + else if (p[i] > this->b_.pmax()[i]) + this->b_.pmax()[i] = p[i]; + } + return *this; + } + + template <typename P> + const box_<P>& fbbox_<P>::box() const + { + precondition(this->is_valid_); + return this->b_; + } + +# endif + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_FBBOX_HH Index: oln/core/gen/pset.hh --- oln/core/gen/pset.hh (revision 843) +++ oln/core/gen/pset.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2007 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 @@ -29,142 +29,65 @@ # define OLN_CORE_GEN_PSET_HH # include <set> - -# include <oln/core/point_set_entry.hh> -# include <oln/core/abstract/point.hh> +# include <oln/core/internal/point_set_std_based.hh> namespace oln { - // Forward declarations. - template <typename point_t> class pset_; - template <typename C> class fwd_piter_on_std_based_pset; - template <typename C> class bkd_piter_on_std_based_pset; + /// Fwd decl. + template <typename P> class pset_; - // Super type declaration. - template <typename point_t> - struct set_super_type< pset_<point_t> > + // Super type. + template <typename P> + struct super_trait_< pset_<P> > { - typedef pset_<point_t> self_t; - typedef point_set_entry<self_t> ret; + typedef pset_<P> current__; + typedef internal::point_set_std_based_<current__> ret; }; - /// Virtual types associated to oln::pset_<point_t>. - template <typename point_t> - struct vtypes< pset_<point_t> > - { - typedef point_t point_type; - typedef fwd_piter_on_std_based_pset< std::set<point_t> > fwd_piter_type; - typedef bkd_piter_on_std_based_pset< std::set<point_t> > bkd_piter_type; - - typedef mlc::false_ is_random_accessible_type; - typedef mlc::true_ has_known_size_type; - typedef mlc::false_ is_connected_type; + /// Virtual types. + template <typename P> + struct vtypes< pset_<P> > + { + typedef std::set<P> std_container; }; - /// Bounding box class based on a point class. - template <typename point_t> - class pset_ : public point_set_entry< pset_<point_t> >, - private mlc::assert_< mlc_is_a(point_t, abstract::point) > - { - typedef pset_<point_t> self_type; - typedef point_set_entry<self_type> super_t; + /// Point set class based on std::set. + template <typename P> + class pset_ : public internal::point_set_std_based_< pset_<P> > + { public: pset_(); - pset_(const pset_<point_t>& rhs); - pset_<point_t>& operator=(const pset_<point_t>& rhs); - - unsigned impl_npoints() const; - bool impl_is_valid() const; - void impl_print(std::ostream& ostr) const; - - pset_<point_t>& insert(const point_t& p); - - const std::set<point_t>& container() const; - std::set<point_t>& container(); - - protected: - - std::set<point_t> sp_; + pset_<P>& insert(const P& p); - }; // end of class oln::pset_<point_t> + }; // end of class oln::pset_<P>. # ifndef OLN_INCLUDE_ONLY - template <typename point_t> - pset_<point_t>::pset_() + template <typename P> + pset_<P>::pset_() { } - template <typename point_t> - pset_<point_t>::pset_(const pset_<point_t>& rhs) + template <typename P> + pset_<P>& pset_<P>::insert(const P& p) { - sp_ = rhs.sp_; - } - - template <typename point_t> - pset_<point_t>& pset_<point_t>::operator=(const pset_<point_t>& rhs) - { - sp_ = rhs.sp_; + this->con_.insert(p); + this->take_(p); return *this; } - template <typename point_t> - unsigned pset_<point_t>::impl_npoints() const - { - return sp_.size(); - } - - template <typename point_t> - bool pset_<point_t>::impl_is_valid() const - { - return true; - } - - template <typename point_t> - void pset_<point_t>::impl_print(std::ostream& ostr) const - { - typename std::set<point_t>::const_iterator it; - ostr << "{ "; - for (it = sp_.begin(); it != sp_.end(); ++it) - ostr << *it << ' '; - ostr << "}"; - } - - template <typename point_t> - pset_<point_t>& pset_<point_t>::insert(const point_t& p) - { - precondition(sp_.find(p) = sp_.end()); - sp_.insert(p); - return *this; - } - - template <typename point_t> - const std::set<point_t>& pset_<point_t>::container() const - { - return sp_; - } - - template <typename point_t> - std::set<point_t>& pset_<point_t>::container() - { - return sp_; - } - # endif } // end of namespace oln -# include <oln/core/gen/piter_on_std_based_pset.hh> - - #endif // ! OLN_CORE_GEN_PSET_HH Index: oln/core/internal/point_set_std_based.hh --- oln/core/internal/point_set_std_based.hh (revision 843) +++ oln/core/internal/point_set_std_based.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2007 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 @@ -25,247 +25,348 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_GEN_PITER_ON_STD_BASED_PSET_HH -# define OLN_CORE_GEN_PITER_ON_STD_BASED_PSET_HH +#ifndef OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH +# define OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH -# include <oln/core/abstract/point.hh> -# include <oln/core/abstract/iterator_on_points.hh> +# include <ostream> +# include <algorithm> + +# include <oln/core/internal/point_set_base.hh> +# include <oln/core/concept/iterator_on_points.hh> +# include <oln/core/gen/fbbox.hh> namespace oln { - // Fwd_piter version. - // ------------------ - - - // Forward declaration. - template <typename C> class fwd_piter_on_std_based_pset; + /// Fwd decl. + namespace internal { template <typename Exact> struct point_set_std_based_; } + template <typename P> class pset_std_based_fwd_piter_; + template <typename P> class pset_std_based_bkd_piter_; - // Super. - template <typename C> - struct set_super_type< fwd_piter_on_std_based_pset<C> > + /// Super type. + template <typename Exact> + struct super_trait_< internal::point_set_std_based_<Exact> > { - typedef abstract::iterator_on_points< fwd_piter_on_std_based_pset<C> > ret; + typedef internal::point_set_base_<Exact> ret; }; - // Vtypes. - template <typename C> - struct vtypes< fwd_piter_on_std_based_pset<C> > - { - typedef typename C::value_type point_type; + /// Virtual types. + template <typename Exact> + struct vtypes< internal::point_set_std_based_<Exact> > + { + typedef stc::abstract std_container; + + typedef stc_deferred(std_container) std_container__; + typedef stc::final< typename std_container__::value_type > point; + typedef stc::final< pset_std_based_fwd_piter_<std_container__> > fwd_piter; + typedef stc::final< pset_std_based_bkd_piter_<std_container__> > bkd_piter; }; - // Class. - template <typename C> - class fwd_piter_on_std_based_pset : + namespace internal + { + + /// Base class for point sets defined over std containers. - public abstract::iterator_on_points< fwd_piter_on_std_based_pset<C> >, - private mlc::assert_< mlc_is_a(typename C::value_type, abstract::point) > + template <typename Exact> + struct point_set_std_based_ : public point_set_base_<Exact> { + typedef point_set_base_<Exact> super; public: - fwd_piter_on_std_based_pset(const C& container); - template <typename point_set> - fwd_piter_on_std_based_pset(const point_set& ps); + stc_using(point); + stc_using(box); - void impl_start(); - void impl_next(); - void impl_invalidate(); - bool impl_is_valid() const; - typename C::value_type impl_to_point() const; - const typename C::value_type* impl_point_adr() const; + unsigned impl_npoints() const; + bool impl_has(const point& p) const; + const box& impl_bbox() const; - private: + stc_typename(std_container); + const std_container& con() const; - const C& container_; - typename C::const_iterator it_; + protected: + + point_set_std_based_(); + + void take_(const point& p); + + std_container con_; + fbbox_<point> fb_; + + }; // end of class point_set_std_based_<Exact> + + + template <typename Exact> + std::ostream& operator<<(std::ostream& ostr, + const point_set_std_based_<Exact>& pts) + { + typename Exact::fwd_piter i(pts); + ostr << "{ "; + for_all(i) + ostr << i.to_point() << ' '; + ostr << "}"; + } + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + unsigned + point_set_std_based_<Exact>::impl_npoints() const + { + return this->con_.size(); + } + + template <typename Exact> + bool + point_set_std_based_<Exact>::impl_has(const typename point_set_std_based_<Exact>::point& p) const + { + return std::find(this->con_.begin(), this->con_.end(), p) != this->con_.end(); + } + + template <typename Exact> + const typename point_set_std_based_<Exact>::box& + point_set_std_based_<Exact>::impl_bbox() const + { + precondition(this->fb_.is_valid()); + return this->fb_.box(); + } + + template <typename Exact> + point_set_std_based_<Exact>::point_set_std_based_() + { + } + + template <typename Exact> + void + point_set_std_based_<Exact>::take_(const typename point_set_std_based_<Exact>::point& p) + { + this->fb_.take(p); + } + + template <typename Exact> + const typename point_set_std_based_<Exact>::std_container& + point_set_std_based_<Exact>::con() const + { + this->con_; + } + +# endif + + } // end of namespace oln::internal - }; // end of class fwd_piter_on_std_based_pset<C> - // Bkd_piter version. - // ------------------ + // -------------------- iterators on classes deriving from internal::point_set_std_based_<Exact> - // Forward declaration. - template <typename C> class bkd_piter_on_std_based_pset; + // Super types. - // Super. template <typename C> - struct set_super_type< bkd_piter_on_std_based_pset<C> > + struct super_trait_< pset_std_based_fwd_piter_<C> > { - typedef abstract::iterator_on_points< bkd_piter_on_std_based_pset<C> > ret; + typedef pset_std_based_fwd_piter_<C> current__; + typedef Iterator_on_Points<current__> ret; }; + template <typename C> + struct super_trait_< pset_std_based_bkd_piter_<C> > + { + typedef pset_std_based_bkd_piter_<C> current__; + typedef Iterator_on_Points<current__> ret; + }; + + + + /// Virtual types. - // Vtypes. template <typename C> - struct vtypes< bkd_piter_on_std_based_pset<C> > + struct vtypes< pset_std_based_fwd_piter_<C> > { - typedef typename C::value_type point_type; + typedef typename C::value_type point; }; + template <typename C> + struct vtypes< pset_std_based_bkd_piter_<C> > + { + typedef typename C::value_type point; + }; + + + // Class pset_std_based_fwd_piter_<C>. - // Class. template <typename C> - class bkd_piter_on_std_based_pset : + class pset_std_based_fwd_piter_ : public Iterator_on_Points< pset_std_based_fwd_piter_<C> > + { + typedef pset_std_based_fwd_piter_<C> current; + typedef Iterator_on_Points<current> super; + public: + + stc_using(point); + + template <typename Ps> + pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& con); + + void impl_start(); + void impl_next(); + void impl_invalidate(); + bool impl_is_valid() const; + point impl_to_point() const; + const point* impl_point_adr() const; + + private: + + const C& con_; + typename C::const_iterator it_; + + }; // end of class pset_std_based_fwd_piter_<C> + + + // Class pset_std_based_bkd_piter_<C>. - public abstract::iterator_on_points< bkd_piter_on_std_based_pset<C> >, - private mlc::assert_< mlc_is_a(typename C::value_type, abstract::point) > + template <typename C> + class pset_std_based_bkd_piter_ : public Iterator_on_Points< pset_std_based_bkd_piter_<C> > { + typedef pset_std_based_bkd_piter_<C> current; + typedef Iterator_on_Points<current> super; public: - bkd_piter_on_std_based_pset(const C& container); - template <typename point_set> - bkd_piter_on_std_based_pset(const point_set& ps); + stc_using(point); + + template <typename Ps> + pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts); void impl_start(); void impl_next(); void impl_invalidate(); bool impl_is_valid() const; - typename C::value_type impl_to_point() const; - const typename C::value_type* impl_point_adr() const; + point impl_to_point() const; + const point* impl_point_adr() const; private: - const C& container_; + const C& con_; typename C::const_reverse_iterator it_; - }; // end of class bkd_piter_on_std_based_pset<C> - + }; // end of class pset_std_based_bkd_piter_<C> # ifndef OLN_INCLUDE_ONLY - // fwd_piter_on_std_based_pset<C> + // -------------------- pset_std_based_fwd_piter_<C> - template <typename C> - fwd_piter_on_std_based_pset<C>::fwd_piter_on_std_based_pset(const C& container) - : container_(container) - { - this->invalidate(); - } template <typename C> - template <typename point_set> - fwd_piter_on_std_based_pset<C>::fwd_piter_on_std_based_pset(const point_set& ps) - : container_(ps.exact().container()) + template <typename Ps> + pset_std_based_fwd_piter_<C>::pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& pts) + : con_(pts.con()) { - this->invalidate(); + this->it_ = this->con_.end(); } template <typename C> - void fwd_piter_on_std_based_pset<C>::impl_start() + void pset_std_based_fwd_piter_<C>::impl_start() { - it_ = container_.begin(); + this->it_ = this->con_.begin(); } template <typename C> - void fwd_piter_on_std_based_pset<C>::impl_next() + void pset_std_based_fwd_piter_<C>::impl_next() { - ++it_; + ++this->it_; } template <typename C> - void fwd_piter_on_std_based_pset<C>::impl_invalidate() + void pset_std_based_fwd_piter_<C>::impl_invalidate() { - it_ = container_.end(); + this->it_ = this->con_.end(); } template <typename C> - bool fwd_piter_on_std_based_pset<C>::impl_is_valid() const + bool pset_std_based_fwd_piter_<C>::impl_is_valid() const { - return it_ != container_.end(); + return this->it_ != this->con_.end(); } template <typename C> - typename C::value_type - fwd_piter_on_std_based_pset<C>::impl_to_point() const + typename pset_std_based_fwd_piter_<C>::point + pset_std_based_fwd_piter_<C>::impl_to_point() const { - return *it_; + return *this->it_; } template <typename C> - const typename C::value_type* - fwd_piter_on_std_based_pset<C>::impl_point_adr() const + const typename pset_std_based_fwd_piter_<C>::point* + pset_std_based_fwd_piter_<C>::impl_point_adr() const { - return 0; - // FIXME: Read below. - // "&(*it_)" is not correct because the std does not ensure that - // "*it_" is dereferenceable (Cf. std trivial iterator concept). - // However, "::point_adr()" is only required so that an iterator - // based on another iterator (e.g., a niter constructed from a - // piter) can stick to the point location of the latter. This - // is not required for iterators on point set so this method should - // be optional. + return &(*(this->it_)); + // FIXME: "&(*it_)" is not always correct because the std does not + // ensure that "*it_" is dereferenceable (Cf. std trivial iterator + // concept). However, "::point_adr()" is only required so that an + // iterator based on another iterator (e.g., a niter constructed + // from a piter) can stick to the point location of the latter. + // This is not required for iterators on point set so this method + // should be optional. } - // bkd_piter_on_std_based_pset<C> - + // -------------------- pset_std_based_bkd_piter_<C> - template <typename C> - bkd_piter_on_std_based_pset<C>::bkd_piter_on_std_based_pset(const C& container) - : container_(container) - { - this->invalidate(); - } template <typename C> - template <typename point_set> - bkd_piter_on_std_based_pset<C>::bkd_piter_on_std_based_pset(const point_set& ps) - : container_(ps.exact().container()) + template <typename Ps> + pset_std_based_bkd_piter_<C>::pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts) + : con_(pts.con()) { - this->invalidate(); + this->it_ = this->con_.rend(); } template <typename C> - void bkd_piter_on_std_based_pset<C>::impl_start() + void pset_std_based_bkd_piter_<C>::impl_start() { - it_ = container_.rbegin(); + this->it_ = this->con_.rbegin(); } template <typename C> - void bkd_piter_on_std_based_pset<C>::impl_next() + void pset_std_based_bkd_piter_<C>::impl_next() { - ++it_; + ++this->it_; } template <typename C> - void bkd_piter_on_std_based_pset<C>::impl_invalidate() + void pset_std_based_bkd_piter_<C>::impl_invalidate() { - it_ = container_.rend(); + this->it_ = this->con_.rend(); } template <typename C> - bool bkd_piter_on_std_based_pset<C>::impl_is_valid() const + bool pset_std_based_bkd_piter_<C>::impl_is_valid() const { - return it_ != container_.rend(); + return this->it_ != this->con_.rend(); } template <typename C> - typename C::value_type - bkd_piter_on_std_based_pset<C>::impl_to_point() const + typename pset_std_based_bkd_piter_<C>::point + pset_std_based_bkd_piter_<C>::impl_to_point() const { - return *it_; + return *this->it_; } template <typename C> - const typename C::value_type* - bkd_piter_on_std_based_pset<C>::impl_point_adr() const + const typename pset_std_based_bkd_piter_<C>::point* + pset_std_based_bkd_piter_<C>::impl_point_adr() const { - return 0; - // FIXME: Read comments in the fwd version of this method. + return &(*(this->it_)); + // FIXME: Read comments in pset_std_based_fwd_piter_<C>. } @@ -275,4 +376,4 @@ } // end of namespace oln -#endif // ! OLN_CORE_GEN_PITER_ON_STD_BASED_PSET_HH +#endif // ! OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 843) +++ oln/core/internal/point_set_base.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2007 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 @@ -25,74 +25,70 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_POINT_SET_ENTRY_HH -# define OLN_CORE_POINT_SET_ENTRY_HH +#ifndef OLN_CORE_INTERNAL_POINT_SET_BASE_HH +# define OLN_CORE_INTERNAL_POINT_SET_BASE_HH -# include <oln/core/abstract/entry.hh> -# include <oln/core/abstract/point_set/all.hh> +# include <oln/core/concept/point_set.hh> namespace oln { - /// Fwd decl. - template <typename E> struct point_set_entry; + /// Fwd decls. + namespace internal { template <typename Exact> struct point_set_base_; } + template <typename P> class box_; - template <typename E> - struct set_super_type< point_set_entry<E> > + /// Super type. + template <typename Exact> + struct super_trait_< internal::point_set_base_<Exact> > { - typedef mlc::none ret; + typedef Point_Set<Exact> ret; }; - /// Virtual types associated to point_set_entry<E>. - - template <typename E> - struct vtypes< point_set_entry<E> > + /// Virtual types. + template <typename Exact> + struct vtypes< internal::point_set_base_<Exact> > { - typedef stc::abstract point_type; - - typedef stc::abstract fwd_piter_type; - typedef stc::abstract bkd_piter_type; - - typedef mlc::none bbox_type; - typedef stc::abstract is_random_accessible_type; - typedef stc::abstract has_known_size_type; - typedef stc::abstract is_connected_type; - - // final. - typedef oln_deduce_vtype(E, point, coord) coord_type; - typedef oln_deduce_vtype(E, point, grid) grid_type; - typedef oln_deduce_vtype(E, point, dim) dim_type; - typedef oln_fwd_piter(E) piter_type; + typedef stc::abstract point; + typedef stc::abstract fwd_piter; + typedef stc::abstract bkd_piter; + + typedef stc_deferred(point) point__; + typedef stc_deferred(fwd_piter) fwd_piter__; + + typedef stc::final< box_<point__> > box; + typedef stc::final<stc_type(point__, grid)> grid; + typedef stc::final<fwd_piter__> piter; }; + namespace internal + { - /// Entry class for point sets: point_set_entry<E> is an alias for - /// entry< abstract::point_set, E>. + /// Base class for point sets. - template <typename E> - struct point_set_entry : public entry< abstract::point_set, E> + template <typename Exact> + struct point_set_base_ : public Point_Set<Exact> { protected: - point_set_entry(); + point_set_base_(); }; - # ifndef OLN_INCLUDE_ONLY - template <typename E> - point_set_entry<E>::point_set_entry() + template <typename Exact> + point_set_base_<Exact>::point_set_base_() { } # endif + } // end of namespace oln::internal } // end of namespace oln -#endif // ! OLN_CORE_POINT_SET_ENTRY_HH +#endif // ! OLN_CORE_INTERNAL_POINT_SET_BASE_HH