
Index: ChangeLog from Damien Thivolle <damien@lrde.epita.fr> * tests/core/tests/piter2d: Add a test for backward 2d iterators. * oln/makefile.src: Add new file. * oln/core/2d/image2d.hh: Include bkd_piter2d.hh. * oln/core/2d/bkd_piter2d.hh: New. bkd_piter2d implementation. * oln/core/properties.hh: Add bkd_piter_type property. oln/core/2d/bkd_piter2d.hh | 117 +++++++++++++++++++++++++++++++++++++++++++++ oln/core/2d/image2d.hh | 2 oln/core/properties.hh | 3 - oln/makefile.src | 1 tests/core/tests/piter2d | 23 ++++++-- 5 files changed, 140 insertions(+), 6 deletions(-) Index: tests/core/tests/piter2d --- tests/core/tests/piter2d (revision 78) +++ tests/core/tests/piter2d (working copy) @@ -14,16 +14,29 @@ { oln::image2d<int> ima(10, 10); int cpt = 0; - - oln::fwd_piter2d it(ima.size()); - for_all (it) + + oln::fwd_piter2d fwd_it(ima.size()); + for_all (fwd_it) { - ima[it] = 0; + ima[fwd_it] = 0; cpt++; } if (cpt != 100) return true; - + + + cpt = 0; + oln::bkd_piter2d bkd_it(ima.size()); + for_all (bkd_it) + { + ima[bkd_it] = 0; + cpt++; + } + + if (cpt != 100) + return true; + + return false; } Index: oln/makefile.src --- oln/makefile.src (revision 78) +++ oln/makefile.src (working copy) @@ -18,6 +18,7 @@ core/1d/point1d.hh \ core/1d/size1d.hh \ core/2d/array2d.hh \ + core/2d/bkd_piter2d.hh \ core/2d/dpoint2d.hh \ core/2d/fwd_piter2d.hh \ core/2d/image2d.hh \ Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 78) +++ oln/core/2d/image2d.hh (working copy) @@ -34,6 +34,7 @@ # include <oln/core/abstract/image_with_data.hh> # include <oln/core/2d/array2d.hh> # include <oln/core/2d/fwd_piter2d.hh> +# include <oln/core/2d/bkd_piter2d.hh> /*! \namespace oln @@ -80,6 +81,7 @@ typedef fwd_piter2d piter_type; typedef fwd_piter2d fwd_piter_type; + typedef bkd_piter2d bkd_piter_type; // please note that value_storage_type means data_type // since image2d is an image_with_data Index: oln/core/2d/bkd_piter2d.hh --- oln/core/2d/bkd_piter2d.hh (revision 0) +++ oln/core/2d/bkd_piter2d.hh (revision 0) @@ -0,0 +1,117 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 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_2D_BKD_PITER2D_HH +# define OLENA_CORE_2D_BKD_PITER2D_HH + +# include <mlc/contract.hh> + +# include <oln/core/abstract/piter.hh> +# include <oln/core/2d/point2d.hh> +# include <oln/core/2d/size2d.hh> + + +namespace oln { + + // fwd decl + struct bkd_piter2d; + + // category + template <> + struct set_category<bkd_piter2d> { typedef category::piter ret; }; + + + // props + template <> + struct set_props < category::piter, bkd_piter2d > : public props_of<category::piter> + { + typedef point2d point_type; + typedef size2d size_type; + }; + + + + struct bkd_piter2d : public abstract::piter< bkd_piter2d > + { + + typedef abstract::piter<bkd_piter2d> super_type; + + bkd_piter2d(const size2d& size) : + super_type(size) + { + this->exact_ptr = this; + this->invalidate(); + } + +# if defined __GNUC__ && __GNUC__ >= 3 + friend class abstract::piter< bkd_piter2d >; + protected: +# endif + + void impl_start() + { + this->p_.row() = this->s_.nrows() - 1; + this->p_.col() = this->s_.ncols() - 1; + postcondition(this->p_.row().is_defined() && + this->p_.col().is_defined()); + } + + bool impl_is_valid() const + { + precondition(this->p_.row().is_defined() && + this->p_.col().is_defined()); + return this->p_.row() >= 0; + } + + void impl_next() + { + precondition(this->p_.row().is_defined() && + this->p_.col().is_defined()); + precondition(this->p_.row() >= 0 && this->p_.row() < this->s_.nrows() && + this->p_.col() >= 0 && this->p_.col() < this->s_.ncols()); + --this->p_.col(); + if (this->p_.col() >= 0) + return; + this->p_.col() = this->s_.ncols() - 1; + --this->p_.row(); + postcondition(this->p_.row().is_defined() && + this->p_.col().is_defined()); + } + + void impl_invalidate() + { + this->p_.row() = -1; + this->p_.col() = -1; + postcondition(this->p_.row().is_defined() && + this->p_.col().is_defined()); + } + + }; +} + + +#endif // ! OLENA_CORE_2D_BKD_PITER2D_HH Index: oln/core/properties.hh --- oln/core/properties.hh (revision 78) +++ oln/core/properties.hh (working copy) @@ -36,7 +36,7 @@ */ namespace oln { - + namespace category { struct data_storage; @@ -59,6 +59,7 @@ struct point_type; struct dpoint_type; struct fwd_piter_type; + struct bkd_piter_type; struct iter_type; struct delegated_type; struct size_type;