Index: ChangeLog
===================================================================
--- ChangeLog (revision 18)
+++ ChangeLog (working copy)
@@ -1,3 +1,15 @@
+2005-01-24 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
+
+ * oln/core/props.hh: Move image defaults into abstract/image.hh.
+ * oln/core/macros.hh: Add piter related macros.
+ * oln/core/abstract/image.hh: Add image defaults and piter typedefs.
+ * oln/core/abstract/iter.hh: Move to piter.hh.
+ * oln/core/abstract/piter.hh: Change interface.
+ * oln/core/2d/image2d.hh: Add piter typedefs in props.
+ * oln/core/2d/iter2d.hh: Move to fwd_piter2d.hh.
+ * oln/core/2d/fwd_piter2d.hh: Conform to new interface.
+ * oln/core/cats.hh: Add cat::piter.
+
2005-01-21 Simon Odou <simon(a)lrde.epita.fr>
* tests/core/tests/readonly_image: New.
Index: oln/core/props.hh
===================================================================
--- oln/core/props.hh (revision 18)
+++ oln/core/props.hh (working copy)
@@ -29,32 +29,6 @@
struct default_props;
- // FIXME: doc
- template <>
- struct default_props < cat::image >
- {
- typedef mlc::undefined_type delegated_type;
-
- typedef mlc::undefined_type size_type;
- typedef mlc::undefined_type point_type;
- typedef mlc::undefined_type value_type;
-
- typedef mlc::undefined_type value_storage_type;
- typedef mlc::undefined_type value_container_type;
-
- // FIXME: etc.
-
- template <typename T>
- struct ch_value_type
- {
- typedef mlc::undefined_type ret;
- };
-
- protected:
- default_props() {}
- };
-
-
/*! \class props<E>
**
** Declaration of the trait class for properties.
Index: oln/core/macros.hh
===================================================================
--- oln/core/macros.hh (revision 18)
+++ oln/core/macros.hh (working copy)
@@ -33,6 +33,9 @@
# define oln_value_storage_type(T) typename
oln::props<oln_category_type(T),T>::value_storage_type
# define oln_value_container_type(T) typename
oln::props<oln_category_type(T),T>::value_container_type
+# define oln_piter_type(T) typename
oln::props<oln_category_type(T),T>::piter_type
+# define oln_fwd_piter_type(T) typename
oln::props<oln_category_type(T),T>::fwd_piter_type
+
// binary macros
# define oln_ch_value_type(I,V) typename
oln::props<oln_category_type(I),I>::ch_value_type<V>::ret
Index: oln/core/abstract/image.hh
===================================================================
--- oln/core/abstract/image.hh (revision 18)
+++ oln/core/abstract/image.hh (working copy)
@@ -2,9 +2,12 @@
# define OLENA_CORE_ABSTRACT_IMAGE_HH
# include <oln/core/abstract/internal/image_impl.hh>
+# include <oln/core/cats.hh>
+# include <oln/core/props.hh>
# include <oln/core/macros.hh>
# include <oln/core/value_box.hh>
+
/*! \namespace oln
** \brief oln namespace.
*/
@@ -12,6 +15,36 @@
+ // FIXME: doc
+ template <>
+ struct default_props < cat::image >
+ {
+ typedef mlc::undefined_type delegated_type;
+
+ typedef mlc::undefined_type size_type;
+ typedef mlc::undefined_type point_type;
+ typedef mlc::undefined_type value_type;
+
+ typedef mlc::undefined_type piter_type;
+ typedef mlc::undefined_type fwd_piter_type;
+
+ typedef mlc::undefined_type value_storage_type;
+ typedef mlc::undefined_type value_container_type;
+
+ // FIXME: etc.
+
+ template <typename T>
+ struct ch_value_type
+ {
+ typedef mlc::undefined_type ret;
+ };
+
+ protected:
+ default_props() {}
+ };
+
+
+
/*! \namespace oln::abstract
** \brief oln::abstract namespace.
*/
Index: oln/core/abstract/iter.hh
===================================================================
--- oln/core/abstract/iter.hh (revision 18)
+++ oln/core/abstract/iter.hh (working copy)
@@ -1,72 +0,0 @@
-#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/piter.hh
===================================================================
--- oln/core/abstract/piter.hh (revision 18)
+++ oln/core/abstract/piter.hh (working copy)
@@ -1,72 +1,79 @@
-#ifndef PROTO_OLN_CORE_ABSTRACT_ITER_HH
-# define PROTO_OLN_CORE_ABSTRACT_ITER_HH
+#ifndef PROTO_OLN_CORE_ABSTRACT_PITER_HH
+# define PROTO_OLN_CORE_ABSTRACT_PITER_HH
# include <mlc/any.hh>
+# include <mlc/types.hh>
+# include <mlc/contract.hh>
# include <oln/core/abstract/point.hh>
-# include <oln/core/abstract/size.hh>
+# include <oln/core/cats.hh>
+# include <oln/core/props.hh>
+
namespace oln {
+
+ template <>
+ struct default_props < cat::piter >
+ {
+ typedef mlc::undefined_type point_type;
+ typedef mlc::undefined_type size_type;
+ };
+
+
namespace abstract {
template <typename E>
- struct iter : mlc::any__best_memory<E>
+ struct piter : public mlc::any__best_memory<E>
{
-
- void
- operator++()
+
+ void start()
{
- this->exact().next_impl();
+ this->exact().impl_start();
}
- void
- begin()
+ void next()
{
- this->exact().begin_impl();
+ precondition(this->is_ok());
+ this->exact().impl_next();
}
- bool
- end()
+ bool is_ok() const
{
- return this->exact().end_impl();
+ return this->exact().impl_is_ok();
}
-
- template <typename P>
- bool
- operator!=(const point<P> &p) const
+ operator point_type() const
{
- return this->exact().noteq_impl(p.exact());
+ precondition(this->is_ok());
+ return this->p_;
}
- template <typename P>
- bool
- operator==(const point<P> &p) const
+ void invalidate()
{
- return this->exact().eq_impl(p.exact());
+ this->exact().impl_invalidate();
+ postcondition(not this->is_ok());
}
- template <typename P>
- operator point<P>() const
- {
- return this->exact().to_point();
- }
+ protected:
- template <typename S>
- void operator() (const size<S> &s)
+ typedef piter<E> self_type;
+ typedef oln_point_type(self_type) point_type;
+ typedef oln_size_type(self_type) size_type;
+
+ piter(const size_type& s) :
+ s_(s),
+ p_()
{
- this->exact().op_par_impl(s.exact());
+ this->invalidate();
}
- protected:
+ const size_type s_;
+ point_type p_;
- iter()
- {}
-
};
}
}
-#endif // ndef PROTO_OLN_CORE_ABSTRACT_ITER_HH
+#endif // ndef PROTO_OLN_CORE_ABSTRACT_PITER_HH
Index: oln/core/2d/image2d.hh
===================================================================
--- oln/core/2d/image2d.hh (revision 18)
+++ oln/core/2d/image2d.hh (working copy)
@@ -37,6 +37,9 @@
typedef point2d point_type;
typedef T value_type;
+ typedef fwd_piter2d piter_type;
+ typedef fwd_piter2d fwd_piter_type;
+
// please note that value_storage_type means data_type
// since image2d is an image_with_data
typedef mlc_encoding_type(T) value_storage_type;
Index: oln/core/2d/iter2d.hh
===================================================================
--- oln/core/2d/iter2d.hh (revision 18)
+++ oln/core/2d/iter2d.hh (working copy)
@@ -1,98 +0,0 @@
-#ifndef PROTO_OLN_CORE_2D_ITER2D_HH
-# define PROTO_OLN_CORE_2D_ITER2D_HH
-
-# include <mlc/contract.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_2D_ITER2D_HH
Index: oln/core/2d/fwd_piter2d.hh
===================================================================
--- oln/core/2d/fwd_piter2d.hh (revision 18)
+++ oln/core/2d/fwd_piter2d.hh (working copy)
@@ -1,5 +1,5 @@
-#ifndef PROTO_OLN_CORE_2D_ITER2D_HH
-# define PROTO_OLN_CORE_2D_ITER2D_HH
+#ifndef PROTO_OLN_CORE_2D_FWD_ITER2D_HH
+# define PROTO_OLN_CORE_2D_FWD_ITER2D_HH
# include <mlc/contract.hh>
@@ -11,88 +11,55 @@
namespace oln {
- struct iter2d;
+ struct fwd_iter2d;
- struct iter2d : abstract::iter<iter2d>
+ template <>
+ struct props < cat::piter, fwd_iter2d >
{
+ typedef point2d point_type;
+ typedef size2d size_type;
+ };
- typedef abstract::iter<iter2d> super_type;
+ struct fwd_iter2d : public abstract::piter<fwd_iter2d>
+ {
- friend class abstract::iter<iter2d>;
+ typedef abstract::iter<fwd_iter2d> super_type;
- iter2d() : super_type(), nrows_(0), ncols_(0)
- {}
+ friend class abstract::iter<fwd_iter2d>;
- 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
+ fwd_iter2d(const size2d& size) :
+ super_type(size)
{
- 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)
+ void impl_start()
{
- 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
+ bool impl_is_ok() const
{
- return this->p_.row() == this->nrows_;
+ return this->p_.row() < this->s_.nrows();
}
-
- bool
- noteq_impl(const point2d &p) const
+ void impl_next() const
{
- return p_ != p.exact();
+ ++this->p_.col();
+ if (this->p_.col() != this->s_.ncols())
+ return;
+ this->p_.col() = 0;
+ ++this->p_.row();
}
- bool
- eq_impl(const point2d &p) const
+ void impl_invalidate()
{
- return p_ == p.exact();
+ this->p_.row() = this->s_.nrows();
+ this->p_.col() = this->s_.ncols();
}
-
};
}
-#endif // ndef PROTO_OLN_CORE_2D_ITER2D_HH
+#endif // ndef PROTO_OLN_CORE_2D_FWD_ITER2D_HH
Index: oln/core/cats.hh
===================================================================
--- oln/core/cats.hh (revision 18)
+++ oln/core/cats.hh (working copy)
@@ -35,9 +35,10 @@
namespace cat {
struct image;
+ struct data_storage;
+ struct piter;
struct point;
struct size;
- struct data_storage;
// FIXME:...
} // end of namespace oln::cat