proto-1.0 194: Add method call to image

Index: ChangeLog from Nicolas Widynski <nicolas.widynski@lrde.epita.fr> * olena/oln/core/abstract/image_constness.hh: Add call to readwrite_image and read_only_image. * olena/oln/core/abstract/image_with_data.hh: Dispatch impl_call. * olena/oln/core/2d/array2d.hh: Real impl_call. Same thing must be done in 1d and 3d. * olena/oln/core/box.hh: Add call to box. * olena/oln/core/gen/internal/value_box.hh: Add call to value_box. 2d/array2d.hh | 12 +++++++++++ abstract/image_constness.hh | 47 ++++++++++++++++++++++++++++++++++++++++++++ abstract/image_with_data.hh | 18 ++++++++++++++++ box.hh | 30 +++++++++++++++++++++++++++- gen/internal/value_box.hh | 30 ++++++++++++++++++++++------ 5 files changed, 130 insertions(+), 7 deletions(-) Index: olena/oln/core/abstract/image_constness.hh --- olena/oln/core/abstract/image_constness.hh (revision 193) +++ olena/oln/core/abstract/image_constness.hh (working copy) @@ -66,6 +66,11 @@ struct readonly_image : public virtual image<E>, public internal::get_image_impl < readonly_image<E>, E > { + template <typename R, typename T> + R call(const oln_type_of(E, point)& p, + R (T::*method)() const) const; + + protected: /*! \brief Constructor (protected, empty). @@ -74,7 +79,35 @@ }; + namespace internal { + template <typename E> + struct set_image_impl < readonly_image<E>, E> : public virtual image_impl<E> + { + /// typedefs + typedef typename image_impl<E>::D D; + typedef oln_type_of(D, point) point_type; + typedef oln_type_of(D, value) value_type; + + template <typename R, typename T> + R impl_call(const oln_type_of(E, point)& p, + R (T::*method)() const) const + { + return this->delegate().call(p, method); + } + + + // extra code; default is 'do nothing': + + void impl_set_ante(const point_type&, const value_type&) {} + void impl_set_post(const point_type&, const value_type&) {} + }; + + } // end of namespace oln::abstract::internal + + + + /*! \class abstract::readonly_image<E> ** ** Class of images whose data are mutable (both readable and writable). @@ -125,6 +158,11 @@ // return *this; // } + template <typename T, typename A, typename V> + void call(const point_type& p, + void (T::*method)(A), + V arg); + protected: /*! \brief Constructor (protected, empty). @@ -155,6 +193,15 @@ this->exact().impl_set_post(p, v); } + template <typename T, typename A, typename V> + void impl_call(const point_type& p, + void (T::*method)(A), + V arg) + { + this->delegate().impl_call(p, method, arg); + } + + // extra code; default is 'do nothing': void impl_set_ante(const point_type&, const value_type&) {} Index: olena/oln/core/abstract/image_with_data.hh --- olena/oln/core/abstract/image_with_data.hh (revision 193) +++ olena/oln/core/abstract/image_with_data.hh (working copy) @@ -151,6 +151,24 @@ } + template <typename R, typename T> + R impl_call(const point_type& p, + R (T::*method)() const) const + { + return (this->data_->get(p).*method)(); + //this->data_->call(p, method); + } + + template <typename T, typename A, typename V> + void impl_call(const point_type& p, + void (T::*method)(A), + V arg) + { + // std::cout << "yes!" << std::endl; + this->data_->call(p, method, arg); + } + + /*! \brief Implement abstract::readwrite_image<E>::set(p, v) so ** write the value \a v at \a p in the current image. */ Index: olena/oln/core/2d/array2d.hh --- olena/oln/core/2d/array2d.hh (revision 193) +++ olena/oln/core/2d/array2d.hh (working copy) @@ -213,6 +213,18 @@ array_[p.row()][p.col()] = v; } + // FIXME: should be impl_ here; and call should be defined in storage_type + template <typename T2, typename A, typename V> + void call(const point2d& p, + void (T2::*method)(A), + V arg) + { + T& value = array_[p.row()][p.col()]; + (value.*method)(arg); + } + + + void impl_set_data(const T& v) { invariant_(); Index: olena/oln/core/box.hh --- olena/oln/core/box.hh (revision 193) +++ olena/oln/core/box.hh (working copy) @@ -267,7 +267,7 @@ } - /// Implementation of abstract::image<E>::get(p). + /// Implementation of abstract::image<E>::get(p) const. template <typename E> const oln_type_of(E, value) @@ -279,7 +279,35 @@ return this->exact().impl_get(p); } + /// Implementation of abstract::image<E>::call(p, method) const. + template <typename E> + template <typename R, typename T> + R + readonly_image<E>::call(const oln_type_of(E, point)& p, + R (T::*method)() const) const + { +# ifdef OLNTRACE + inc_ncalls("call", *this); +# endif // ! OLNTRACE + return this->exact().impl_call(p, method); + } + + /// Implementation of abstract::readwrite_image<E>::call(p, method, value). + template <typename E> + template <typename T, typename A, typename V> + void + readwrite_image<E>::call(const oln_type_of(E, point)& p, + void (T::*method)(A), + V arg) + { +# ifdef OLNTRACE + inc_ncalls("call", *this); +# endif // ! OLNTRACE + this->exact().impl_call(p, method, arg); + } + + /// Implementation of abstract::readwrite_image<E>::set(p, v). template <typename E> Index: olena/oln/core/gen/internal/value_box.hh --- olena/oln/core/gen/internal/value_box.hh (revision 193) +++ olena/oln/core/gen/internal/value_box.hh (working copy) @@ -157,12 +157,12 @@ ** FIXME:... */ - template <typename A, typename V> - value_box& set(void (I::*method)(A), const V& value) - { - ima_->set(p_, method, value); - return *this; - } +// template <typename A, typename V> +// value_box& set(void (I::*method)(A), const V& value) +// { +// ima_->set(p_, method, value); +// return *this; +// } @@ -201,7 +201,19 @@ return ima_->get(p_); } + template <typename R, typename T> + R call(R (T::*method)() const) const + { + return ima_->call(p_, method); + } + template <typename T, typename A, typename V> + void call(void (T::*method)(A), + V arg) + { + ima_->call(p_, method, arg); + } + /// Cpy ctor. value_box(const value_box& rhs) : @@ -340,7 +352,13 @@ // IDEA: provide op-> + template <typename R, typename T> + R call(R (T::*method)() const) const + { + return ima_->call(p_, method); + } + /// Cpy ctor. value_box(const value_box& rhs) :

Nicolas Widynski <nicolas.widynski@lrde.epita.fr> writes:
Index: ChangeLog from Nicolas Widynski <nicolas.widynski@lrde.epita.fr>
* olena/oln/core/abstract/image_constness.hh: Add call to readwrite_image and read_only_image. * olena/oln/core/abstract/image_with_data.hh: Dispatch impl_call. * olena/oln/core/2d/array2d.hh: Real impl_call. Same thing must be done in 1d and 3d. * olena/oln/core/box.hh: Add call to box. * olena/oln/core/gen/internal/value_box.hh: Add call to value_box.
You should quote things coming from the code to disambuigate the title of your news and the ChangeLog. Nice patch anyway. -- Michael Cadilhac, a.k.a. Micha * + - - --. | -Epita 2007 - Ing 1 - CSI- @ r '@' ***** O `@ | | ,)´ (. ********* `(. | `-- - - ******************************************'

Le 23-05-2005, Nicolas Widynski <nicolas.widynski@lrde.epita.fr> a écrit :
Index: ChangeLog from Nicolas Widynski <nicolas.widynski@lrde.epita.fr>
* olena/oln/core/abstract/image_constness.hh: Add call to readwrite_image and read_only_image. * olena/oln/core/abstract/image_with_data.hh: Dispatch impl_call. * olena/oln/core/2d/array2d.hh: Real impl_call. Same thing must be done in 1d and 3d. * olena/oln/core/box.hh: Add call to box. * olena/oln/core/gen/internal/value_box.hh: Add call to value_box.
You did not write your changes in the right place (ChangeLog instead of olena/ChangeLog)
participants (3)
-
Micha
-
Nicolas Widynski
-
Simon Odou