proto-1.0 84: Add windows iterator

Index: ChangeLog from Simon Odou <simon@lrde.epita.fr> * tests/core/tests/fwd_witer2d: New. Test for forward window iterator in 2d. * oln/makefile.src: Add new headers. * oln/core/abstract/struct_elt.hh: Fix a bad prototype. * oln/core/abstract/neighborhood.hh: Likewise. * oln/core/abstract/witer.hh: New. Add window iterator. * oln/core/2d/window2d.hh: Add `fwd_witer' property.. * oln/core/properties.hh: Likewise. * oln/basics2d.hh: Add new headers. oln/basics2d.hh | 1 oln/core/2d/window2d.hh | 2 oln/core/abstract/neighborhood.hh | 2 oln/core/abstract/struct_elt.hh | 5 + oln/core/abstract/witer.hh | 142 ++++++++++++++++++++++++++++++++++++++ oln/core/properties.hh | 3 oln/makefile.src | 2 tests/core/tests/fwd_witer2d | 25 ++++++ 8 files changed, 180 insertions(+), 2 deletions(-) Index: tests/core/tests/fwd_witer2d --- tests/core/tests/fwd_witer2d (revision 0) +++ tests/core/tests/fwd_witer2d (revision 0) @@ -0,0 +1,25 @@ +#include <oln/core/2d/fwd_witer2d.hh> +#include <oln/core/abstract/piter.hh> + +#include <ntg/all.hh> + +#include <cassert> + +using namespace oln; +using namespace ntg; + +template <typename E> +bool foo(const E& w) +{ + oln_type_of(E, fwd_witer) i(w); + unsigned cpt = 0; + for_all(i) + ++cpt; + return not (cpt == w.card()); +} + +int main() +{ + window2d w = win_c8p(); + return foo(w); +} Index: oln/makefile.src --- oln/makefile.src (revision 83) +++ oln/makefile.src (working copy) @@ -25,6 +25,7 @@ core/2d/point2d.hh \ core/2d/size2d.hh \ core/2d/neighborhood2d.hh \ + core/2d/fwd_witer2d.hh \ core/2d/window2d.hh \ core/3d/array3d.hh \ core/3d/fwd_piter3d.hh \ @@ -44,6 +45,7 @@ core/abstract/internal/image_impl.hh \ core/abstract/op.hh \ core/abstract/piter.hh \ + core/abstract/witer.hh \ core/abstract/point.hh \ core/abstract/size.hh \ core/abstract/neighborhood.hh \ Index: oln/core/abstract/struct_elt.hh --- oln/core/abstract/struct_elt.hh (revision 83) +++ oln/core/abstract/struct_elt.hh (working copy) @@ -60,12 +60,14 @@ mlc_decl_prop(category::struct_elt, dpoint_type); mlc_decl_prop(category::struct_elt, size_type); + mlc_decl_prop(category::struct_elt, fwd_witer_type); static void echo(std::ostream& ostr) { ostr << "props_of( category::struct_elt, " << typeid(type).name() << ") = {" << " size_type = " << typeid(size_type).name() << "," << std::endl + << " fwd_witer_type = " << typeid(fwd_witer_type).name() << "," << std::endl << " dpoint_type = " << typeid(dpoint_type).name() << " }" << std::endl; } @@ -73,6 +75,7 @@ mlc_register_prop(category::struct_elt, dpoint_type); mlc_register_prop(category::struct_elt, size_type); + mlc_register_prop(category::struct_elt, fwd_witer_type); namespace abstract { @@ -100,7 +103,7 @@ } bool - has(const abstract::dpoint<dpoint_type>& dp) const + has(const dpoint_type& dp) const { return this->exact().impl_has(dp.exact()); } Index: oln/core/abstract/witer.hh --- oln/core/abstract/witer.hh (revision 0) +++ oln/core/abstract/witer.hh (revision 0) @@ -0,0 +1,142 @@ +// Copyright (C) 2001, 2003, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_ABSTRACT_WITER_HH +# define OLENA_CORE_ABSTRACT_WITER_HH + +# include <mlc/any.hh> +# include <mlc/types.hh> + +# include <oln/core/properties.hh> + +# include <string> + +namespace oln { + + // fwd decl + namespace abstract { + template <typename E> struct witer; + } + + // category + template <typename E> + struct set_category< abstract::witer<E> > { typedef category::witer ret; }; + + /// properties of any type in category::witer + // + template <typename type> + struct props_of < category::witer, type > + { + typedef mlc::true_type user_defined_; + + mlc_decl_prop(category::witer, se_type); + + static void echo(std::ostream& ostr) + { + ostr << "props_of( category::witer, " + << typeid(type).name() << ") = {" + << " se_type = " << typeid(se_type).name() + << " }" << std::endl; + } + }; + + mlc_register_prop(category::witer, se_type); + + namespace abstract { + + template <typename E> + struct witer : public mlc::any__best_speed<E> + { + + typedef witer<E> self_type; + + typedef oln_type_of(E, se) se_type; + typedef oln_type_of(se_type, dpoint) dpoint_type; + + void start() + { + this->exact().impl_start(); + } + + void next() + { + precondition(this->is_valid()); + this->exact().impl_next(); + } + + bool is_valid() const + { + return this->exact().impl_is_valid(); + } + + operator dpoint_type() const + { + precondition(this->is_valid()); + return this->se_[pos_]; + } + + void invalidate() + { + this->exact().impl_invalidate(); + postcondition(! this->is_valid()); + } + + protected: + + void impl_start() + { + pos_ = 0; + } + + void impl_next() + { + ++pos_; + } + + bool impl_is_valid() const + { + return pos_ != se_.card(); + } + + void impl_invalidate() + { + pos_ = se_.card(); + } + + witer(const se_type& se) + : se_(se), pos_(0) + {} + + const se_type& se_; + unsigned pos_; + }; + + } // abstract + +} // oln + +#endif // OLENA_CORE_ABSTRACT_WITER_HH Index: oln/core/abstract/neighborhood.hh --- oln/core/abstract/neighborhood.hh (revision 83) +++ oln/core/abstract/neighborhood.hh (working copy) @@ -100,7 +100,7 @@ } bool - has(const abstract::dpoint<dpoint_type>& dp) const + has(const dpoint_type& dp) const { return this->exact().impl_has(dp.exact()); } Index: oln/core/2d/window2d.hh --- oln/core/2d/window2d.hh (revision 83) +++ oln/core/2d/window2d.hh (working copy) @@ -36,6 +36,7 @@ namespace oln { class window2d; // forward declaration + class fwd_witer2d; // category template <> @@ -54,6 +55,7 @@ { typedef dpoint2d dpoint_type; typedef size2d size_type; + typedef fwd_witer2d fwd_witer_type; }; class window2d : public abstract::struct_elt<window2d> Index: oln/core/properties.hh --- oln/core/properties.hh (revision 83) +++ oln/core/properties.hh (working copy) @@ -46,6 +46,7 @@ struct point; struct size; struct piter; + struct witer; struct niter; // FIXME: ... } @@ -60,9 +61,11 @@ struct dpoint_type; struct fwd_piter_type; struct bkd_piter_type; + struct fwd_witer_type; struct iter_type; struct delegated_type; struct size_type; + struct se_type; struct image_constness_type; struct image_dimension_type; Index: oln/basics2d.hh --- oln/basics2d.hh (revision 83) +++ oln/basics2d.hh (working copy) @@ -35,6 +35,7 @@ # include <oln/core/2d/size2d.hh> # include <oln/core/2d/point2d.hh> # include <oln/core/2d/image2d.hh> +# include <oln/core/2d/fwd_witer2d.hh> # include <oln/core/2d/window2d.hh> # include <oln/core/2d/neighborhood2d.hh>
participants (1)
-
Simon Odou