Damien Thivolle <damien(a)lrde.epita.fr> writes:
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* ChangeLog: New.
* oln/makefile.src: Adds file dependencies.
* oln/core/abstract/iter.hh: New.
* oln/core/abstract/size.hh: Adapts to coding style.
* oln/core/2d/iter2d.hh: New.
core/2d/iter2d.hh | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++
core/abstract/iter.hh | 72 ++++++++++++++++++++++++++++++++++++
core/abstract/size.hh | 2 -
makefile.src | 3 +
4 files changed, 174 insertions(+), 2 deletions(-)
Index: ChangeLog
Index: oln/makefile.src
--- oln/makefile.src (revision 4)
+++ oln/makefile.src (working copy)
@@ -6,6 +6,7 @@
OLN_DEP = \
core/2d/array2d.hh \
core/2d/image2d.hh \
+ core/2d/iter2d.hh \
core/2d/point2d.hh \
core/2d/size2d.hh \
core/abstract/data_storage.hh \
@@ -14,6 +15,7 @@
core/abstract/image_with_data.hh \
core/abstract/images.hh \
core/abstract/internal/image_impl.hh \
+ core/abstract/iter.hh \
core/abstract/point.hh \
core/abstract/size.hh \
core/cats.hh \
@@ -22,4 +24,3 @@
core/props.hh \
core/tags.hh \
core/value_box.hh
-
Index: oln/core/abstract/iter.hh
--- oln/core/abstract/iter.hh (revision 0)
+++ oln/core/abstract/iter.hh (revision 0)
@@ -0,0 +1,72 @@
+#ifndef PROTO_OLN_CORE_ABSTRACT_ITER_HH
+# define PROTO_OLN_CORE_ABSTRACT_ITER_HH
+
+# include <mlc/any.hh>
+
+# include <oln/core/abstract/point.hh>
+# include <oln/core/abstract/size.hh>
+
+namespace oln {
+
+ namespace abstract {
+
+ template <typename E>
+ struct iter : mlc::any__best_memory<E>
+ {
+
+ void
+ operator++()
+ {
+ this->exact().next_impl();
+ }
+
+ void
+ begin()
+ {
+ this->exact().begin_impl();
+ }
+
+ bool
+ end()
+ {
+ return this->exact().end_impl();
+ }
+
+
+ template <typename P>
+ bool
+ operator!=(const point<P> &p) const
+ {
+ return this->exact().noteq_impl(p.exact());
+ }
+
+ template <typename P>
+ bool
+ operator==(const point<P> &p) const
+ {
+ return this->exact().eq_impl(p.exact());
+ }
+
+ template <typename P>
+ operator point<P>() const
+ {
+ return this->exact().to_point();
+ }
+
+ template <typename S>
+ void operator() (const size<S> &s)
+ {
+ this->exact().op_par_impl(s.exact());
+ }
+
+ protected:
+
+ iter()
+ {}
+
+ };
+ }
+}
+
+
+#endif // ndef PROTO_OLN_CORE_ABSTRACT_ITER_HH
Index: oln/core/abstract/size.hh
--- oln/core/abstract/size.hh (revision 4)
+++ oln/core/abstract/size.hh (working copy)
@@ -1,7 +1,7 @@
#ifndef PROTO_OLN_CORE_ABSTRACT_SIZE_HH
# define PROTO_OLN_CORE_ABSTRACT_SIZE_HH
-#include <mlc/any.hh>
+# include <mlc/any.hh>
namespace oln {
Index: oln/core/2d/iter2d.hh
--- oln/core/2d/iter2d.hh (revision 0)
+++ oln/core/2d/iter2d.hh (revision 0)
@@ -0,0 +1,99 @@
+#ifndef PROTO_OLN_CORE_2D_ITER2D_HH
+# define PROTO_OLN_CORE_2D_ITER2D_HH
+
+# include <mlc/contract.hh>
+# include <mlc/objs.hh>
+
+# include <oln/core/abstract/iter.hh>
+# include <oln/core/2d/point2d.hh>
+# include <oln/core/2d/size2d.hh>
+# include <oln/core/props.hh>
+
+
+namespace oln {
+
+ struct iter2d;
+
+ struct iter2d : abstract::iter<iter2d>
+ {
+
+ typedef abstract::iter<iter2d> super_type;
+
+ friend class abstract::iter<iter2d>;
+
+ iter2d() : super_type(), nrows_(0), ncols_(0)
+ {}
+
+ iter2d(const size2d& size) :
+ super_type(),
+ nrows_(size.nrows()),
+ ncols_(size.ncols())
+ {}
+
+
+ protected:
+
+ coord_t nrows_;
+ coord_t ncols_;
+ point2d p_;
+
+ point2d
+ to_point() const
+ {
+ precondition(!end_impl());
+ invariant(this->p_.row() >= 0 &&
+ (this->p_.row() < nrows_ || this->p_.row() == nrows_) &&
+ this->p_.col() >= 0 &&
+ this->p_.col() < ncols_);
+ return this->p_;
+ }
+
+
+ void op_par_impl(const size2d& size)
+ {
+ ncols_ = size.ncols();
+ nrows_ = size.nrows();
+ }
+
+ void
+ next_impl()
+ {
+ this->p_.col()++;
+ if (this->p_.col() != this->ncols_)
+ return;
+ this->p_.col() = 0;
+ this->p_.row()++;
+ }
+
+ void
+ begin_impl()
+ {
+ this->p_.row() = 0;
+ this->p_.col() = 0;
+ }
+
+ bool
+ end_impl() const
+ {
+ return this->p_.row() == this->nrows_;
+ }
+
+
+ bool
+ noteq_impl(const point2d &p) const
+ {
+ return p_ != p.exact();
+ }
+
+ bool
+ eq_impl(const point2d &p) const
+ {
+ return p_ == p.exact();
+ }
+
+
+ };
+}
+
+
+#endif // ndef PROTO_OLN_CORE_ABSTRACT_ITER_HH
^^^^^^^^^^^^^
Encore un peu rouillé :)
--
Damien Thivolle
damien(a)lrde.epita.fr