886: Add the type of 'point set such as f : point -> bool.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add the type of 'point set such as f : point -> bool. * oln/core/concept/functions.hh: Rename as... * oln/core/concept/function.hh: ...this. * oln/core/gen/piter_isubset.hh: Rename as... * oln/core/internal/piter_adaptor.hh: ...this. * oln/core/gen/fun.hh: New. * oln/core/internal/op_pset_such_as_fp2b.hh: New. * oln/core/concept/value.hh (Boolean): New. * oln/core/2d/grid2d.hh (grid2d_rec): Rename as... (grid2d): ...this. (grid2d): Rename as... (grid2d_rec): ...this. * oln/core/2d/point2d.hh: Cosmetic change. * oln/core/equipment.hh (adapted): New. * oln/core/gen/op.hh (category_of_): Move to... * oln/core/internal/category_of.hh: ...this new file. * oln/core/internal/point_base.hh: Add commentary. * oln/core/internal/dpoint_base.hh (vtypes): Add category. * oln/core/internal/point_set_base.hh (operator|): New. (include): Update. * oln/core/internal/op_image_plus_nbh.hh: Cosmetic change. * oln/core/internal/special_op.hh (include): Remove image_base.hh. 2d/grid2d.hh | 10 - 2d/point2d.hh | 2 concept/function.hh | 30 ++- concept/value.hh | 18 + equipment.hh | 4 gen/fun.hh | 120 ++++++++++++ gen/op.hh | 22 -- gen/pset_such_as.hh | 380 +++++++++++++++++++++++++++++++++++++++ internal/category_of.hh | 124 ++++++++++++ internal/dpoint_base.hh | 4 internal/op_image_plus_nbh.hh | 2 internal/op_pset_such_as_fp2b.hh | 336 ++++++++++++++++++++++++++++++++++ internal/piter_adaptor.hh | 147 +++++---------- internal/point_base.hh | 10 - internal/point_set_base.hh | 35 +++ internal/special_op.hh | 2 16 files changed, 1119 insertions(+), 127 deletions(-) Index: oln/core/concept/function.hh --- oln/core/concept/function.hh (revision 877) +++ oln/core/concept/function.hh (working copy) @@ -25,15 +25,18 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_CONCEPT_FUNCTIONS_HH -# define OLN_CORE_CONCEPT_FUNCTIONS_HH +#ifndef OLN_CORE_CONCEPT_FUNCTION_HH +# define OLN_CORE_CONCEPT_FUNCTION_HH # include <oln/core/equipment.hh> + + namespace oln { + /* // Fwd decl. @@ -46,6 +49,10 @@ */ template <typename Exact> + struct Function; + + + template <typename Exact> struct Function : public Any<Exact> { protected: @@ -63,6 +70,16 @@ }; + // Point -> bool. + + template <typename Exact> + struct Function_p2b : public Function<Exact> + { + protected: + Function_p2b(); + }; + + // Value -> Value. template <typename Exact> @@ -73,7 +90,7 @@ }; - // Neighborhood -> Value. + // Values -> Value. template <typename Exact> struct Accumulator : public Function<Exact> @@ -137,6 +154,11 @@ } template <typename Exact> + Function_p2b<Exact>::Function_p2b() + { + } + + template <typename Exact> Function_p2v<Exact>::Function_p2v() { } @@ -170,4 +192,4 @@ } // end of namespace oln -#endif // ! OLN_CORE_CONCEPT_FUNCTIONS_HH +#endif // ! OLN_CORE_CONCEPT_FUNCTION_HH Index: oln/core/concept/value.hh --- oln/core/concept/value.hh (revision 885) +++ oln/core/concept/value.hh (working copy) @@ -44,14 +44,32 @@ Value(); }; + /// Concept-class "Boolean". + + template <typename Exact> + struct Boolean : public Value<Exact> + { + protected: + Boolean(); + }; + # ifndef OLN_INCLUDE_ONLY + // Value. + template <typename Exact> Value<Exact>::Value() { } + // Boolean. + + template <typename Exact> + Boolean<Exact>::Boolean() + { + } + # endif } // end of namespace oln Index: oln/core/2d/grid2d.hh --- oln/core/2d/grid2d.hh (revision 885) +++ oln/core/2d/grid2d.hh (working copy) @@ -53,7 +53,7 @@ /// Fwd decls. template <typename Exact> struct Grid_2D; - struct grid2d_rec; + struct grid2d; struct grid2d_hex; struct grid2d_tri; @@ -83,9 +83,9 @@ /// Super types. template<> - struct super_trait_< grid2d_rec > + struct super_trait_< grid2d > { - typedef Grid_2D< grid2d_rec > ret; + typedef Grid_2D< grid2d > ret; }; template<> @@ -107,10 +107,10 @@ /// Rectangular grid struct. - struct grid2d_rec : public Grid_2D< grid2d_rec > + struct grid2d : public Grid_2D< grid2d > {}; - typedef grid2d_rec grid2d; // for short + typedef grid2d grid2d_rec; // more explicit /// Hexagonal grid struct. Index: oln/core/2d/point2d.hh --- oln/core/2d/point2d.hh (revision 885) +++ oln/core/2d/point2d.hh (working copy) @@ -93,7 +93,7 @@ this->col() = dat->second.value; } -# endif +# endif // OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 885) +++ oln/core/equipment.hh (working copy) @@ -49,6 +49,10 @@ # include <stc/scoop-alt.inc> # endif + // a + + stc_decl_associated_type( adapted ); + // b stc_decl_associated_type( bkd_niter ); stc_decl_associated_type( bkd_piter ); Index: oln/core/gen/fun.hh --- oln/core/gen/fun.hh (revision 0) +++ oln/core/gen/fun.hh (revision 0) @@ -0,0 +1,120 @@ +// 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_GEN_FUN_HH +# define OLN_CORE_GEN_FUN_HH + +# include <oln/core/internal/category_of.hh> +# include <oln/core/concept/function.hh> +# include <oln/core/concept/point.hh> +# include <oln/core/concept/value.hh> + + + +// FIXME: Add "fun" to names below. +# define oln_arg_of_(T) typename oln::internal::argument_of_< T >::ret +# define oln_res_of_(T) typename oln::internal::result_of_< T >::ret + + + +namespace oln +{ + + + namespace internal + { + + // result_of_ + + template <typename F> + struct result_of_ + { + typedef typename F::result ret; + }; + + template <typename R, typename A> + struct result_of_< R (*)(A) > + { + typedef R ret; + }; + + + // argument_of_ + + template <typename F> + struct argument_of_ + { + typedef typename F::argument ret; + }; + + template <typename R, typename A> + struct argument_of_< R (*)(A) > + { + typedef A ret; + }; + + + } // end of namespace oln::internal + + + + // Fwd decl. + template <typename F> struct fun_p2b_; + + // Category. + namespace internal + { + template <typename F> + struct set_category_of_< fun_p2b_<F> > + { + typedef stc::is< Function_p2b > ret; + }; + } + + // Class. + template <typename F> + struct fun_p2b_ : public Function_p2b< fun_p2b_<F> > + { + typedef oln_arg_of_(F) argument; + typedef oln_res_of_(F) result; + + fun_p2b_(F f) : f_(f) {} + + result operator()(argument arg) const + { + return this->f_(arg); + } + + private: + F f_; + }; + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_FUN_HH Index: oln/core/gen/op.hh --- oln/core/gen/op.hh (revision 885) +++ oln/core/gen/op.hh (working copy) @@ -29,6 +29,9 @@ # define OLN_CORE_GEN_OP_HH # include <oln/core/internal/special_op.hh> +# include <oln/core/internal/category_of.hh> +# include <oln/core/concept/function.hh> +# include <oln/core/concept/value.hh> @@ -78,28 +81,10 @@ - -# define oln_category_of_(Type) typename oln::internal::category_of_<Type>::ret - - namespace oln { - namespace internal - { - template <typename T> - struct category_of_ - { - typedef stc_type(T, category) ret; - }; - - // ... - - } // end of namespace oln::internal - - - /// \{ /// Operator Names. @@ -111,6 +96,7 @@ + // Fwd decl. template <typename L, typename OpName, typename R> class op_; Index: oln/core/gen/pset_such_as.hh --- oln/core/gen/pset_such_as.hh (revision 0) +++ oln/core/gen/pset_such_as.hh (revision 0) @@ -0,0 +1,380 @@ +// 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_INTERNAL_POINT_SET_STD_BASED_HH +# define OLN_CORE_INTERNAL_POINT_SET_STD_BASED_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 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 type. + template <typename Exact> + struct super_trait_< internal::point_set_std_based_<Exact> > + { + typedef internal::point_set_base_<Exact> ret; + }; + + + /// 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; + }; + + + namespace internal + { + + /// Base class for point sets defined over std containers. + + template <typename Exact> + struct point_set_std_based_ : public point_set_base_<Exact> + { + typedef point_set_base_<Exact> super; + public: + + stc_using(point); + stc_using(box); + + unsigned impl_npoints() const; + bool impl_has(const point& p) const; + const box& impl_bbox() const; + + stc_typename(std_container); + const std_container& con() const; + + 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 << "}"; + return 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 + { + return this->con_; + } + +# endif + + } // end of namespace oln::internal + + + + + // -------------------- iterators on classes deriving from internal::point_set_std_based_<Exact> + + + + // Super types. + + template <typename C> + struct super_trait_< pset_std_based_fwd_piter_<C> > + { + 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. + + template <typename C> + struct vtypes< pset_std_based_fwd_piter_<C> > + { + 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>. + + template <typename C> + 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>. + + 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: + + 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; + point impl_to_point() const; + const point* impl_point_adr() const; + + private: + + const C& con_; + typename C::const_reverse_iterator it_; + + }; // end of class pset_std_based_bkd_piter_<C> + + + +# ifndef OLN_INCLUDE_ONLY + + + + // -------------------- pset_std_based_fwd_piter_<C> + + + template <typename C> + 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->it_ = this->con_.end(); + } + + template <typename C> + void pset_std_based_fwd_piter_<C>::impl_start() + { + this->it_ = this->con_.begin(); + } + + template <typename C> + void pset_std_based_fwd_piter_<C>::impl_next() + { + ++this->it_; + } + + template <typename C> + void pset_std_based_fwd_piter_<C>::impl_invalidate() + { + this->it_ = this->con_.end(); + } + + template <typename C> + bool pset_std_based_fwd_piter_<C>::impl_is_valid() const + { + return this->it_ != this->con_.end(); + } + + template <typename C> + typename pset_std_based_fwd_piter_<C>::point + pset_std_based_fwd_piter_<C>::impl_to_point() const + { + return *this->it_; + } + + template <typename C> + const typename pset_std_based_fwd_piter_<C>::point* + pset_std_based_fwd_piter_<C>::impl_point_adr() const + { + 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. + } + + + // -------------------- pset_std_based_bkd_piter_<C> + + + template <typename C> + 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->it_ = this->con_.rend(); + } + + template <typename C> + void pset_std_based_bkd_piter_<C>::impl_start() + { + this->it_ = this->con_.rbegin(); + } + + template <typename C> + void pset_std_based_bkd_piter_<C>::impl_next() + { + ++this->it_; + } + + template <typename C> + void pset_std_based_bkd_piter_<C>::impl_invalidate() + { + this->it_ = this->con_.rend(); + } + + template <typename C> + bool pset_std_based_bkd_piter_<C>::impl_is_valid() const + { + return this->it_ != this->con_.rend(); + } + + template <typename C> + typename pset_std_based_bkd_piter_<C>::point + pset_std_based_bkd_piter_<C>::impl_to_point() const + { + return *this->it_; + } + + template <typename C> + const typename pset_std_based_bkd_piter_<C>::point* + pset_std_based_bkd_piter_<C>::impl_point_adr() const + { + return &(*(this->it_)); + // FIXME: Read comments in pset_std_based_fwd_piter_<C>. + } + + +# endif + + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH Index: oln/core/internal/point_base.hh --- oln/core/internal/point_base.hh (revision 885) +++ oln/core/internal/point_base.hh (working copy) @@ -50,13 +50,15 @@ template <typename Exact> struct vtypes< internal::point_base_<Exact> > { - typedef stc::abstract grid; + typedef stc::abstract grid; // FIXME: Could be defined and final? + typedef stc::abstract coord; // FIXME: Likewise? + typedef stc::abstract dpoint; typedef stc_deferred(grid) grid__; - typedef stc::final<stc_type(grid__, dim)> dim; - typedef stc::abstract coord; - typedef stc::abstract dpoint; + // Final: + typedef stc::final<typename grid__::dim> dim; // FIXME: Propagate this kind of changes. + typedef stc::final< stc::is<Point> > category; }; Index: oln/core/internal/op_pset_such_as_fp2b.hh --- oln/core/internal/op_pset_such_as_fp2b.hh (revision 0) +++ oln/core/internal/op_pset_such_as_fp2b.hh (revision 0) @@ -0,0 +1,336 @@ +// 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_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH +# define OLN_CORE_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH + +# include <oln/core/concept/function.hh> +# include <oln/core/gen/op.hh> +# include <oln/core/internal/piter_adaptor.hh> +# include <oln/core/internal/point_set_base.hh> + + +namespace oln +{ + + +# define current \ + special_op_< stc::is<Point_Set>, S, such_as, stc::is<Function_p2b>, F > + + + /// Fwd decls. + namespace internal + { + template <typename S, typename F> class current; + } + template <typename S, typename F> class pset_such_as_fp2b_fwd_piter_; + template <typename S, typename F> class pset_such_as_fp2b_bkd_piter_; + + + + /// Super type. + template <typename S, typename F> + struct super_trait_< internal::current > + { + typedef internal::point_set_base_< op_<S, such_as, F> > ret; + }; + + + /// Virtual types. + template <typename S, typename F> + struct vtypes< internal::current > + { + typedef typename S::point point; + typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter; + typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter; + }; + + + namespace internal + { + + /// Implementation class the result of "Point_Set S | Function_p2b F". + + template <typename S, typename F> + class current + : + public internal::point_set_base_< op_<S, such_as, F> > + { + typedef internal::point_set_base_< op_<S, such_as, F> > super; + public: + + stc_using(point); + stc_using(box); + + unsigned impl_npoints() const; + bool impl_has(const point& p) const; + const box& impl_bbox() const; + + const S& adapted_() const; + F fun_() const; + + protected: + special_op_(); + special_op_(S& pset, F& f); + + S pset_; + F f_; + + // template <typename D> + // friend + // bool init_(internal::current* this_, const D& dat); + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename S, typename F> + current::special_op_() + { + } + + template <typename S, typename F> + current::special_op_(S& pset, F& f) + : pset_(pset), + f_(f) + { + } + + template <typename S, typename F> + unsigned + current::impl_npoints() const + { + return 0; // FIXME: Wrong!!! + } + + template <typename S, typename F> + bool + current::impl_has(const typename current::point& p) const + { + return this->pset_.has(p) and this->f_(p); + } + + template <typename S, typename F> + const typename current::box& + current::impl_bbox() const + { + return this->pset_.bbox(); + } + + template <typename S, typename F> + const S& + current::adapted_() const + { + return this->pset_; + } + + template <typename S, typename F> + F current::fun_() const + { + return this->f_; + } + +# endif + + } // end of namespace oln::internal + + +// // Fixme: Activate init + +// template <typename S, typename F, typename D> +// bool init_(internal::current* this_, const D& dat) +// { +// bool pset_ok = init(this_->pset_, with, dat); +// bool fun_ok = init(this_->f_, with, dat); +// postcondition(pset_ok); +// postcondition(fun_ok); +// return pset_ok and fun_ok; +// } + + +# undef current + + + + + + + +# define current pset_such_as_fp2b_fwd_piter_<S, F> + // ---------------------------------- + +# define super internal::piter_adaptor_< current > + + + // Super type. + template <typename S, typename F> + struct super_trait_< current > + { + typedef super ret; + }; + + + // Virtual types. + template <typename S, typename F> + struct vtypes< current > + { + typedef typename S::point point; + typedef typename S::fwd_piter adapted; + }; + + + // Class. + template <typename S, typename F> + class pset_such_as_fp2b_fwd_piter_ : public super + { + public: + + pset_such_as_fp2b_fwd_piter_(); + pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset); + + void impl_start(); + void impl_next(); + + private: + F f_; + + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename S, typename F> + current::pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset) + : super(exact(pset).adapted_()), + f_(exact(pset).fun_()) + { + } + + template <typename S, typename F> + void + current::impl_start() + { + this->p_.start(); + while (this->p_.is_valid() and not f_(this->p_)) + this->p_.next(); + } + + template <typename S, typename F> + void + current::impl_next() + { + do + this->p_.next(); + while (this->p_.is_valid() and not f_(this->p_)); + } + +# endif // OLN_INCLUDE_ONLY + +# undef super +# undef current + + + + + +# define current pset_such_as_fp2b_bkd_piter_<S, F> + // ---------------------------------- + +# define super internal::piter_adaptor_< current > + + + // Super type. + template <typename S, typename F> + struct super_trait_< current > + { + typedef super ret; + }; + + + // Virtual types. + template <typename S, typename F> + struct vtypes< current > + { + typedef typename S::point point; + typedef typename S::fwd_piter adapted; + }; + + + // Class. + template <typename S, typename F> + class pset_such_as_fp2b_bkd_piter_ : public super + { + public: + + pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset); + + void impl_start(); + void impl_next(); + + private: + F f_; + + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename S, typename F> + current::pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset) + : super(exact(pset).adapted_()), + f_(exact(pset).fun_()) + { + } + + template <typename S, typename F> + void + current::impl_start() + { + this->p_.start(); + while (this->p_.is_valid() and not f_(this->p_)) + this->p_.next(); + } + + template <typename S, typename F> + void + current::impl_next() + { + do + this->p_.next(); + while (this->p_.is_valid() and not f_(this->p_)); + } + +# endif // OLN_INCLUDE_ONLY + +# undef super +# undef current + + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH Index: oln/core/internal/dpoint_base.hh --- oln/core/internal/dpoint_base.hh (revision 885) +++ oln/core/internal/dpoint_base.hh (working copy) @@ -57,7 +57,9 @@ typedef stc::final<stc_type(grid__, dim)> dim; typedef stc::abstract coord; - typedef stc::abstract point; + typedef stc::abstract point; // FIXME: Just like in point_base.hh + + typedef stc::final< stc::is<Dpoint> > category; }; Index: oln/core/internal/piter_adaptor.hh --- oln/core/internal/piter_adaptor.hh (revision 879) +++ oln/core/internal/piter_adaptor.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,159 +25,124 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_GEN_PITER_ISUBSET_HH -# define OLN_CORE_GEN_PITER_ISUBSET_HH +#ifndef OLN_CORE_INTERNAL_PITER_ADAPTOR_HH +# define OLN_CORE_INTERNAL_PITER_ADAPTOR_HH -# include <oln/core/abstract/iterator_on_points.hh> -# include <oln/core/abstract/topology.hh> -# include <oln/core/gen/topo_add_isubset.hh> +# include <oln/core/concept/iterator_on_points.hh> namespace oln { - // Forward declaration. - template <typename piter_t, typename isubset_t> class piter_isubset_; + // Fwd decl. + namespace internal { template <typename Exact> class piter_adaptor_; } - // Super type declaration. - template <typename piter_t, typename isubset_t> - struct set_super_type< piter_isubset_<piter_t, isubset_t> > + // Super type. + template <typename Exact> + struct super_trait_< internal::piter_adaptor_<Exact> > { - typedef piter_isubset_<piter_t, isubset_t> self_t; - typedef abstract::iterator_on_points<self_t> ret; + typedef Iterator_on_Points<Exact> ret; }; - /// Virtual types associated to oln::piter_isubset_<piter_t, isubset_t>. - template <typename piter_t, typename isubset_t> - struct vtypes< piter_isubset_<piter_t, isubset_t> > + // Virtual types. + template <typename Exact> + struct vtypes< internal::piter_adaptor_<Exact> > { - typedef oln_vtype(piter_t, point) point_type; - typedef oln_vtype(piter_t, grid) grid_type; - - typedef topo_add_isubset<oln_vtype(piter_t, topo), isubset_t> topo_type; + typedef stc::abstract point; + typedef stc::abstract adapted; }; - - /// Abstract forward point iterator class. - template <typename piter_t, typename isubset_t> - class piter_isubset_ : public abstract::iterator_on_points< piter_isubset_<piter_t, isubset_t> > + namespace internal { - typedef piter_isubset_<piter_t, isubset_t> self_t; - typedef abstract::iterator_on_points<self_t> super_t; - typedef oln_vtype(self_t, topo) topo_t; - typedef oln_vtype(self_t, point) point_t; + // Base implementation class for types of iterator on points + // defined over other types of iterator on points. + template <typename Exact> + class piter_adaptor_ : public Iterator_on_Points<Exact> + { + typedef Iterator_on_Points<Exact> super; public: - template <typename T> - piter_isubset_(const abstract::topology<T>& topo); + stc_using(point); + stc_typename(adapted); - template <typename P, typename T> - piter_isubset_(const P& p, const abstract::topology<T>& topo); + piter_adaptor_(adapted p); + // Default impl is delegation. void impl_start(); - void impl_next(); - void impl_invalidate(); - bool impl_is_valid() const; - - point_t impl_to_point() const; - - const point_t* impl_point_adr() const; - - const topo_t topo() const; + point impl_to_point() const; + const point* impl_point_adr() const; protected: + adapted p_; - piter_t p_; - isubset_t isubset_; // Cpy. - - }; // end of class oln::piter_isubset_<point> + }; // end of class oln::internal::piter_adaptor_<Exact> # ifndef OLN_INCLUDE_ONLY - template <typename piter_t, typename isubset_t> - template <typename T> - piter_isubset_<piter_t, isubset_t>::piter_isubset_(const abstract::topology<T>& topo) - : p_(topo), - isubset_(topo.exact().subset()) - { - } - - template <typename piter_t, typename isubset_t> - template <typename P, typename T> - piter_isubset_<piter_t, isubset_t>::piter_isubset_(const P& p, const abstract::topology<T>& topo) - : p_(p, topo), - isubset_(topo.exact().subset()) + template <typename Exact> + piter_adaptor_<Exact>::piter_adaptor_(adapted p) + : p_(p) { } - template <typename piter_t, typename isubset_t> + template <typename Exact> void - piter_isubset_<piter_t, isubset_t>::impl_start() + piter_adaptor_<Exact>::impl_start() { - p_.start(); - while (p_.is_valid() and isubset_(p_) = false) - p_.next(); + this->p_.start(); } - template <typename piter_t, typename isubset_t> + template <typename Exact> void - piter_isubset_<piter_t, isubset_t>::impl_next() + piter_adaptor_<Exact>::impl_next() { - do - p_.next(); - while (p_.is_valid() and isubset_(p_) = false); + this->p_.next(); } - template <typename piter_t, typename isubset_t> + template <typename Exact> void - piter_isubset_<piter_t, isubset_t>::impl_invalidate() + piter_adaptor_<Exact>::impl_invalidate() { - p_.invalidate(); + this->p_.invalidate(); } - template <typename piter_t, typename isubset_t> + template <typename Exact> bool - piter_isubset_<piter_t, isubset_t>::impl_is_valid() const + piter_adaptor_<Exact>::impl_is_valid() const { - return p_.is_valid(); + return this->p_.is_valid(); } - template <typename piter_t, typename isubset_t> - typename piter_isubset_<piter_t, isubset_t>::point_t - piter_isubset_<piter_t, isubset_t>::impl_to_point() const + template <typename Exact> + typename piter_adaptor_<Exact>::point + piter_adaptor_<Exact>::impl_to_point() const { - return p_.to_point(); + return this->p_.to_point(); } - template <typename piter_t, typename isubset_t> - const typename piter_isubset_<piter_t, isubset_t>::point_t* - piter_isubset_<piter_t, isubset_t>::impl_point_adr() const + template <typename Exact> + const typename piter_adaptor_<Exact>::point* + piter_adaptor_<Exact>::impl_point_adr() const { - return p_.point_adr(); - } - - template <typename piter_t, typename isubset_t> - const typename piter_isubset_<piter_t, isubset_t>::topo_t - piter_isubset_<piter_t, isubset_t>::topo() const - { - topo_t tmp(p_.topo(), isubset_); - return tmp; + return this->p_.point_adr(); } # endif + } // end of namespace oln::internal + } // end of namespace oln -#endif // ! OLN_CORE_GEN_PITER_ISUBSET_HH +#endif // ! OLN_CORE_INTERNAL_PITER_ADAPTOR_HH Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 885) +++ oln/core/internal/point_set_base.hh (working copy) @@ -93,4 +93,39 @@ } // end of namespace oln + +/// \{ +/// FIXME: Bad! + +# include <oln/core/gen/fun.hh> +# include <oln/core/internal/op_pset_such_as_fp2b.hh> + +namespace oln +{ + + // Point_Set | Function. + + oln_decl_op_such_as(Point_Set, Function_p2b); + + + // Specialization. + + template <typename S, typename B, typename P> + op_<const S, such_as, const fun_p2b_<B (*)(P)> > + operator | (const Point_Set<S>& lhs, + B (*f)(P)) + { + typedef oln_strip_(P) P_; + mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg. + mlc::assert_equal_< P_, typename S::point >::check(); + op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f); + return tmp; + } + + +} // end of namespace oln + +/// \} + + #endif // ! OLN_CORE_INTERNAL_POINT_SET_BASE_HH Index: oln/core/internal/category_of.hh --- oln/core/internal/category_of.hh (revision 0) +++ oln/core/internal/category_of.hh (revision 0) @@ -0,0 +1,124 @@ +// 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 +// 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_INTERNAL_CATEGORY_OF_HH +# define OLN_CORE_INTERNAL_CATEGORY_OF_HH + + +# define oln_category_of_(Type) typename oln::internal::category_of_< Type >::ret +# define oln_strip_(Type) typename oln::internal::strip_< Type >::ret + + +namespace oln +{ + + // Fwd decls. + template <typename Exact> struct Boolean; + + + + namespace internal + { + + // Strip_ + + + template <typename T> + struct strip_ + { + typedef T ret; + }; + + template <typename T> + struct strip_< T* > + { + typedef typename strip_<T>::ret ret; + }; + + template <typename T> + struct strip_< T& > + { + typedef typename strip_<T>::ret ret; + }; + + template <typename T> + struct strip_< const T > + { + typedef typename strip_<T>::ret ret; + }; + + + + + // Category_of_ + + + template <typename T> + struct set_category_of_ + { + typedef stc_type(T, category) ret; + }; + + template <> + struct set_category_of_< bool > + { + typedef stc::is< Boolean > ret; + }; + + + template <typename T> + struct category_of_ + { + typedef typename strip_<T>::ret T_; + typedef typename set_category_of_<T_>::ret ret; + }; + + // ... + + + + + // only_if_ + + template < typename Ret, + typename Check_1, + typename Check_2 = void, + typename Check_3 = void, + typename Check_4 = void > + struct only_if_ + { + typedef Ret ret; + }; + + + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_CATEGORY_OF_HH Index: oln/core/internal/op_image_plus_nbh.hh --- oln/core/internal/op_image_plus_nbh.hh (revision 885) +++ oln/core/internal/op_image_plus_nbh.hh (working copy) @@ -82,7 +82,7 @@ /// Implementation class the result of "Image I + Neighborhood N". template <typename I, typename N> - class special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N > + class current : public internal::image_extension_< op_<I, plus, N> >, private mlc::assert_< mlc_is_not_a(I, Image_with_Nbh) > // FIXME: Add err msg. Index: oln/core/internal/special_op.hh --- oln/core/internal/special_op.hh (revision 885) +++ oln/core/internal/special_op.hh (working copy) @@ -28,8 +28,6 @@ #ifndef OLN_CORE_INTERNAL_SPECIAL_OP_HH # define OLN_CORE_INTERNAL_SPECIAL_OP_HH -# include <oln/core/internal/image_base.hh> - namespace oln {
participants (1)
-
Thierry Geraud