698: Add point-set types based on std containers.

2006-11-07 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Add point-set types based on std containers. * oln/core/gen/piter_on_std_based_pset.hh: New. * oln/core/gen/pset_list.hh: New. * oln/core/gen/pset_vec.hh: New. * oln/core/gen/pset_.hh: New. * oln/Makefile.am: Update. 2006-11-06 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Index: oln/core/gen/piter_on_std_based_pset.hh =================================================================== --- oln/core/gen/piter_on_std_based_pset.hh (revision 0) +++ oln/core/gen/piter_on_std_based_pset.hh (revision 0) @@ -0,0 +1,278 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_PITER_ON_STD_BASED_PSET_HH +# define OLN_CORE_GEN_PITER_ON_STD_BASED_PSET_HH + +# include <oln/core/abstract/point.hh> +# include <oln/core/abstract/iterator_on_points.hh> + + +namespace oln +{ + + + // Fwd_piter version. + // ------------------ + + + // Forward declaration. + template <typename C> class fwd_piter_on_std_based_pset; + + + // Super. + template <typename C> + struct set_super_type< fwd_piter_on_std_based_pset<C> > + { + typedef abstract::iterator_on_points< fwd_piter_on_std_based_pset<C> > ret; + }; + + + // Vtypes. + template <typename C> + struct vtypes< fwd_piter_on_std_based_pset<C> > + { + typedef typename C::value_type point_type; + }; + + + // Class. + template <typename C> + class fwd_piter_on_std_based_pset : + + public abstract::iterator_on_points< fwd_piter_on_std_based_pset<C> >, + private mlc::assert_< mlc_is_a(typename C::value_type, abstract::point) > + { + public: + fwd_piter_on_std_based_pset(const C& container); + + template <typename point_set> + fwd_piter_on_std_based_pset(const point_set& ps); + + 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; + + private: + + const C& container_; + typename C::const_iterator it_; + + }; // end of class fwd_piter_on_std_based_pset<C> + + + + // Bkd_piter version. + // ------------------ + + + // Forward declaration. + template <typename C> class bkd_piter_on_std_based_pset; + + + // Super. + template <typename C> + struct set_super_type< bkd_piter_on_std_based_pset<C> > + { + typedef abstract::iterator_on_points< bkd_piter_on_std_based_pset<C> > ret; + }; + + + // Vtypes. + template <typename C> + struct vtypes< bkd_piter_on_std_based_pset<C> > + { + typedef typename C::value_type point_type; + }; + + + // Class. + template <typename C> + class bkd_piter_on_std_based_pset : + + public abstract::iterator_on_points< bkd_piter_on_std_based_pset<C> >, + private mlc::assert_< mlc_is_a(typename C::value_type, abstract::point) > + { + public: + bkd_piter_on_std_based_pset(const C& container); + + template <typename point_set> + bkd_piter_on_std_based_pset(const point_set& ps); + + 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; + + private: + + const C& container_; + typename C::const_reverse_iterator it_; + + }; // end of class bkd_piter_on_std_based_pset<C> + + + + +# ifndef OLN_INCLUDE_ONLY + + + // fwd_piter_on_std_based_pset<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()) + { + this->invalidate(); + } + + template <typename C> + void fwd_piter_on_std_based_pset<C>::impl_start() + { + it_ = container_.begin(); + } + + template <typename C> + void fwd_piter_on_std_based_pset<C>::impl_next() + { + ++it_; + } + + template <typename C> + void fwd_piter_on_std_based_pset<C>::impl_invalidate() + { + it_ = container_.end(); + } + + template <typename C> + bool fwd_piter_on_std_based_pset<C>::impl_is_valid() const + { + return it_ != container_.end(); + } + + template <typename C> + typename C::value_type + fwd_piter_on_std_based_pset<C>::impl_to_point() const + { + return *it_; + } + + template <typename C> + const typename C::value_type* + fwd_piter_on_std_based_pset<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. + } + + + // bkd_piter_on_std_based_pset<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()) + { + this->invalidate(); + } + + template <typename C> + void bkd_piter_on_std_based_pset<C>::impl_start() + { + it_ = container_.rbegin(); + } + + template <typename C> + void bkd_piter_on_std_based_pset<C>::impl_next() + { + ++it_; + } + + template <typename C> + void bkd_piter_on_std_based_pset<C>::impl_invalidate() + { + it_ = container_.rend(); + } + + template <typename C> + bool bkd_piter_on_std_based_pset<C>::impl_is_valid() const + { + return it_ != container_.rend(); + } + + template <typename C> + typename C::value_type + bkd_piter_on_std_based_pset<C>::impl_to_point() const + { + return *it_; + } + + template <typename C> + const typename C::value_type* + bkd_piter_on_std_based_pset<C>::impl_point_adr() const + { + return 0; + // FIXME: Read comments in the fwd version of this method. + } + + +# endif + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_PITER_ON_STD_BASED_PSET_HH Index: oln/core/gen/pset_list.hh =================================================================== --- oln/core/gen/pset_list.hh (revision 0) +++ oln/core/gen/pset_list.hh (revision 0) @@ -0,0 +1,181 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_PSET_LIST_HH +# define OLN_CORE_GEN_PSET_LIST_HH + +# include <list> + +# include <oln/core/point_set_entry.hh> +# include <oln/core/abstract/point.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; + + + // Super type declaration. + template <typename point_t> + struct set_super_type< pset_list<point_t> > + { + typedef pset_list<point_t> self_t; + typedef point_set_entry<self_t> 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_know_size_type; + typedef mlc::false_ is_connected_type; + }; + + + /// 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; + + 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_; + + }; // end of class oln::pset_list<point_t> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename point_t> + pset_list<point_t>::pset_list() + { + } + + template <typename point_t> + pset_list<point_t>::pset_list(const pset_list<point_t>& rhs) + { + 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_; + 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 + { + 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); + 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 Index: oln/core/gen/pset_vec.hh =================================================================== --- oln/core/gen/pset_vec.hh (revision 0) +++ oln/core/gen/pset_vec.hh (revision 0) @@ -0,0 +1,171 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_PSET_VEC_HH +# define OLN_CORE_GEN_PSET_VEC_HH + +# include <vector> + +# include <oln/core/point_set_entry.hh> +# include <oln/core/abstract/point.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; + + + // Super type declaration. + template <typename point_t> + struct set_super_type< pset_vec<point_t> > + { + typedef pset_vec<point_t> self_t; + typedef point_set_entry<self_t> 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_know_size_type; + typedef mlc::false_ is_connected_type; + }; + + + /// 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; + + 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(); + + protected: + + std::vector<point_t> vp_; + + }; // end of class oln::pset_vec<point_t> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename point_t> + pset_vec<point_t>::pset_vec() + { + } + + template <typename point_t> + pset_vec<point_t>::pset_vec(const pset_vec<point_t>& rhs) + { + 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_; + return *this; + } + + template <typename point_t> + unsigned pset_vec<point_t>::impl_npoints() const + { + return vp_.size(); + } + + template <typename point_t> + bool pset_vec<point_t>::impl_is_valid() const + { + 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_; + } + +# endif + +} // end of namespace oln + + +# include <oln/core/gen/piter_on_std_based_pset.hh> + + +#endif // ! OLN_CORE_GEN_PSET_VEC_HH Index: oln/core/gen/pset_.hh =================================================================== --- oln/core/gen/pset_.hh (revision 0) +++ oln/core/gen/pset_.hh (revision 0) @@ -0,0 +1,170 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_PSET_HH +# define OLN_CORE_GEN_PSET_HH + +# include <set> + +# include <oln/core/point_set_entry.hh> +# include <oln/core/abstract/point.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; + + + // Super type declaration. + template <typename point_t> + struct set_super_type< pset_<point_t> > + { + typedef pset_<point_t> self_t; + typedef point_set_entry<self_t> 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_know_size_type; + typedef mlc::false_ is_connected_type; + }; + + + /// 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; + + 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_; + + }; // end of class oln::pset_<point_t> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename point_t> + pset_<point_t>::pset_() + { + } + + template <typename point_t> + pset_<point_t>::pset_(const pset_<point_t>& rhs) + { + sp_ = rhs.sp_; + } + + template <typename point_t> + pset_<point_t>& pset_<point_t>::operator=(const pset_<point_t>& rhs) + { + sp_ = rhs.sp_; + 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/Makefile.am =================================================================== --- oln/Makefile.am (revision 696) +++ oln/Makefile.am (working copy) @@ -128,9 +128,14 @@ core/gen/fwd_qiter_win.hh \ core/gen/fwd_viter_lut.hh \ core/gen/piter_isubset.hh \ + core/gen/piter_isubset.hh \ + core/gen/pset_.hh \ + core/gen/pset_list.hh \ + core/gen/pset_vec.hh \ core/gen/grid.hh \ core/gen/mapimage.hh \ core/gen/neighb.hh \ + core/gen/piter_on_std_based_pset.hh \ core/gen/pw_value.hh \ core/gen/topo_add_isubset.hh \ core/gen/topo_add_nbh.hh \
participants (1)
-
Thierry GERAUD