https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 22 +++++++++
oln/core/abstract/size.hh | 3 -
oln/core/any/dpoint.hh | 6 +-
oln/core/any/grid.hh | 3 -
oln/core/any/point.hh | 28 ++++++++++--
oln/core/pw/abstract/binary_function.hh | 8 +++
oln/core/pw/apply.hh | 74 ++++++++++++++++++++++++++++++--
oln/makefile.src | 3 -
tests/pw/tests/apply-binary | 20 ++++++++
9 files changed, 152 insertions(+), 15 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add binary apply on point-wise functions.
* oln/core/pw/apply.hh (apply2): New class.
(p_apply): New helper for binary point-wise apply.
* tests/pw/tests/apply-binary: New test.
* oln/core/abstract/size.hh (oln_size_type_from_2): Adjust macro
to new Metalic logic system.
* oln/core/pw/abstract/binary_function.hh
(binary_function_helper < any_size, any_size >): New
specialization.
* oln/core/any/point.hh (impl_plus, impl_minus, impl_nth):
Implement (as dummies).
* oln/core/any/grid.hh (any_coord): Define this type.
* oln/core/any/dpoint.hh: Aesthetic changes.
* oln/makefile.src (OLN_DEP): Remove
core/abstract/regular_niter.hh, core/3d/fwd_niter3d.hh and
core/3d/fwd_qiter3d.hh.
2005-04-14 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/pw/tests/apply-binary
--- olena/tests/pw/tests/apply-binary (revision 0)
+++ olena/tests/pw/tests/apply-binary (revision 0)
@@ -0,0 +1,20 @@
+ // -*- C++ -*-
+#include <iostream>
+
+#include <cmath>
+#include <oln/core/pw/apply.hh>
+#include <oln/core/pw/literal.hh>
+#include <oln/core/any/point.hh>
+
+using namespace oln;
+
+bool check()
+{
+ any_point p;
+
+ pw::literal<int> pv1 (p_lit(1));
+ pw::literal<int> pv2 (p_lit(2));
+
+ int res = p_apply(mlc::make_binary_fun(std::plus<int>()), pv1, pv2)(p);
+ return not (res == 3);
+}
Index: olena/oln/core/abstract/size.hh
--- olena/oln/core/abstract/size.hh (revision 151)
+++ olena/oln/core/abstract/size.hh (working copy)
@@ -41,7 +41,8 @@
-# define oln_size_type_from_2(S1, S2) typename mlc::if_< typename mlc::eq< S2,
oln::any_size >::ret, S1, S2 >::ret
+# define oln_size_type_from_2(S1, S2) \
+typename mlc::if_< mlc::eq< S2, oln::any_size >, S1, S2 >::ret
Index: olena/oln/core/pw/abstract/binary_function.hh
--- olena/oln/core/pw/abstract/binary_function.hh (revision 151)
+++ olena/oln/core/pw/abstract/binary_function.hh (working copy)
@@ -100,6 +100,14 @@
}
};
+ template <>
+ struct binary_function_helper < any_size, any_size > {
+ template <typename L, typename R>
+ static const L& select(const L& l, R) {
+ return l;
+ }
+ };
+
} // end of namespace oln::pw::abstract::internal
Index: olena/oln/core/pw/apply.hh
--- olena/oln/core/pw/apply.hh (revision 151)
+++ olena/oln/core/pw/apply.hh (working copy)
@@ -30,6 +30,7 @@
# include <mlc/fun.hh>
# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/pw/abstract/binary_function.hh>
# include <oln/core/pw/macros.hh>
@@ -41,8 +42,7 @@
// fwd decl
namespace pw {
- template <typename F, typename T>
- struct apply;
+ template <typename F, typename T> struct apply;
}
// super type
@@ -110,18 +110,86 @@
} // end of namespace oln::pw
+
+ /*---------.
+ | Binary. |
+ `---------*/
+
+ // fwd decl
+ namespace pw {
+ template <typename F, typename T1, typename T2> struct apply2;
+ }
+
+ // super type
+ template <typename F, typename T1, typename T2>
+ struct set_super_type < pw::apply2<F, T1, T2> >
+ {
+ typedef pw::abstract::binary_function<T1, T2, pw::apply2<F, T1, T2> >
ret;
+ };
+
+ // props
+ template <typename F, typename T1, typename T2>
+ struct set_props < category::pw, pw::apply2<F, T1, T2> >
+ {
+ typedef typename F::result_type value_type;
+ };
+
+ namespace pw {
+
+ template <typename F, typename T1, typename T2>
+ struct apply2 :
+ public abstract::binary_function <T1, T2, apply2<F, T1, T2> >
+ {
+ typedef apply2<F, T1, T2> self_type;
+
+ typedef oln_pw_type_of(self_type, point) point_type;
+ typedef oln_pw_type_of(self_type, value) value_type;
+ typedef oln_pw_type_of(self_type, size) size_type;
+
+ typedef
+ abstract::binary_function <T1, T2, apply2<F, T1, T2> > super_type;
+
+ F f_;
+
+ apply2(const mlc::abstract::binary_function<F>& f,
+ const abstract::function<T1>& left,
+ const abstract::function<T2>& right) :
+ super_type(left, right),
+ f_(f.exact())
+ {
+ }
+
+ const value_type impl_get(const point_type& p) const
+ {
+ return f_(this->left(p), this->right(p));
+ }
+ };
+
+ } // end of namespace oln::pw
+
} // end of namespace oln
/// apply function on pwf
template <typename F, typename T>
-oln::pw::apply<F, T> p_apply (const mlc::abstract::unary_function<F>& f,
+oln::pw::apply<F, T>
+p_apply (const mlc::abstract::unary_function<F>& f,
const oln::pw::abstract::function<T>& x)
{
oln::pw::apply<F, T> tmp(f, x);
return tmp;
}
+template <typename F, typename T1, typename T2>
+oln::pw::apply2<F, T1, T2>
+p_apply (const mlc::abstract::binary_function<F>& f,
+ const oln::pw::abstract::function<T1>& x,
+ const oln::pw::abstract::function<T2>& y)
+{
+ oln::pw::apply2<F, T1, T2> tmp(f, x, y);
+ return tmp;
+}
+
#endif // ! OLENA_CORE_PW_APPLY_HH
Index: olena/oln/core/any/grid.hh
--- olena/oln/core/any/grid.hh (revision 151)
+++ olena/oln/core/any/grid.hh (working copy)
@@ -39,7 +39,8 @@
struct any_point;
struct any_dpoint;
struct any_size;
- struct any_coord;
+ // Dummy coord type.
+ struct any_coord {};
// super type
template <>
Index: olena/oln/core/any/point.hh
--- olena/oln/core/any/point.hh (revision 151)
+++ olena/oln/core/any/point.hh (working copy)
@@ -63,7 +63,7 @@
bool impl_fwd_less(const any_point& rhs) const
{
- precondition(0);
+ precondition(false);
return false;
}
@@ -72,7 +72,11 @@
return this->exact().impl_eq(rhs.exact());
}
- const any_point impl_plus(const any_dpoint& rhs) const;
+ const any_point impl_plus(const any_dpoint& rhs) const
+ {
+ precondition(false);
+ return any_point();
+ }
template <typename D>
const any_point impl_plus(const abstract::dpoint<D>& rhs) const
@@ -85,9 +89,18 @@
template <typename P>
const any_dpoint impl_minus(const abstract::point<P>& rhs) const;
- const any_coord impl_nth(unsigned i) const;
+ const any_coord impl_nth(unsigned i) const
+ {
+ precondition(false);
+ return any_coord();
+ }
- any_coord& impl_nth(unsigned i);
+ any_coord& impl_nth(unsigned i)
+ {
+ static any_coord dummy = any_coord();
+ precondition(false);
+ return dummy;
+ }
};
@@ -116,9 +129,16 @@
namespace oln {
+ const any_dpoint any_point::impl_minus(const any_point& rhs) const
+ {
+ precondition(false);
+ return any_dpoint();
+ }
+
template <typename P>
const any_dpoint any_point::impl_minus(const abstract::point<P>& rhs) const
{
+ precondition(false);
return any_dpoint();
}
Index: olena/oln/core/any/dpoint.hh
--- olena/oln/core/any/dpoint.hh (revision 151)
+++ olena/oln/core/any/dpoint.hh (working copy)
@@ -69,7 +69,7 @@
bool impl_fwd_less(const any_dpoint& rhs) const
{
- precondition(0);
+ precondition(false);
return false;
}
@@ -80,14 +80,14 @@
const coord_t impl_nth(unsigned i) const
{
- precondition(0);
+ precondition(false);
return 0;
}
coord_t& impl_nth(unsigned i)
{
static coord_t dummy = coord_t();
- precondition(0);
+ precondition(false);
return dummy;
}
Index: olena/oln/makefile.src
--- olena/oln/makefile.src (revision 151)
+++ olena/oln/makefile.src (working copy)
@@ -47,9 +47,7 @@
core/3d/array3d.hh \
core/3d/bkd_piter3d.hh \
core/3d/dpoint3d.hh \
- core/3d/fwd_niter3d.hh \
core/3d/fwd_piter3d.hh \
- core/3d/fwd_qiter3d.hh \
core/3d/image3d.hh \
core/3d/neighborhood3d.hh \
core/3d/niter3d.hh \
@@ -80,7 +78,6 @@
core/abstract/piter.hh \
core/abstract/point.hh \
core/abstract/qiter.hh \
- core/abstract/regular_niter.hh \
core/abstract/size.hh \
core/abstract/window.hh \
\