https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0/olena
ChangeLog | 13 +++++
oln/core/any/grid.hh | 71 +++++++++++++++++++++++++++
oln/core/any/point.hh | 12 ++++
oln/core/pw/apply.hh | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++
oln/makefile.src | 2
tests/pw/Makefile.am | 5 +
tests/pw/tests/apply | 18 +++++++
7 files changed, 247 insertions(+), 1 deletion(-)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add apply on point-wise functions.
* oln/core/pw/apply.hh: New file.
* tests/pw/Makefile.am: New file.
* tests/pw/tests/apply: New test.
* oln/core/any/grid.hh: New file.
* oln/core/any/point.hh: Conform to abstract::point constraints.
* oln/makefile.src (OLN_DEP): Add core/any/grid.hh and
core/pw/apply.hh.
2005-04-13 Roland Levillain <roland(a)lrde.epita.fr>
Property changes on: tests/pw
___________________________________________________________________
Name: svn:ignore
+ Makefile.in
Makefile
Index: tests/pw/tests/apply
--- tests/pw/tests/apply (revision 0)
+++ tests/pw/tests/apply (revision 0)
@@ -0,0 +1,18 @@
+ // -*- 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(42));
+
+ int res = p_apply(mlc::make_unary_fun(std::negate<int>()), pv1)(p);
+ return !(res == -42);
+}
Index: tests/pw/Makefile.am
--- tests/pw/Makefile.am (revision 0)
+++ tests/pw/Makefile.am (revision 0)
@@ -0,0 +1,5 @@
+include ../check/Makefile.runtests
+include ../check/Makefile.check
+
+
+check-local: check-runtests
Index: oln/core/pw/apply.hh
--- oln/core/pw/apply.hh (revision 0)
+++ oln/core/pw/apply.hh (revision 0)
@@ -0,0 +1,127 @@
+// Copyright (C) 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_PW_APPLY_HH
+# define OLENA_CORE_PW_APPLY_HH
+
+# include <mlc/fun.hh>
+# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/pw/macros.hh>
+
+
+namespace oln {
+
+ /*--------.
+ | Unary. |
+ `--------*/
+
+ // fwd decl
+ namespace pw {
+ template <typename F, typename T>
+ struct apply;
+ }
+
+ // super type
+ template <typename F, typename T>
+ struct set_super_type < pw::apply<F, T> >
+ {
+ typedef pw::abstract::function< pw::apply<F, T> > ret;
+ };
+
+ // props
+ template <typename F, typename T>
+ struct set_props < category::pw, pw::apply<F, T> >
+ {
+ typedef oln_pw_type_of(T, point) point_type;
+ typedef typename F::result_type value_type;
+ typedef oln_pw_type_of(T, size) size_type;
+ };
+
+
+ namespace pw {
+
+ template <typename F, typename T>
+ struct apply : public abstract::function < apply<F, T> >
+ {
+ typedef apply<F, T> 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::function<self_type> super_type;
+
+ F f_;
+ T input_;
+
+ apply(const mlc::abstract::unary_function<F>& f,
+ const abstract::function<T>& input) :
+ super_type(),
+ f_(f.exact()),
+ input_(input.exact())
+ {
+ }
+
+ const size_type& impl_size() const
+ {
+ return input_.size();
+ }
+
+ const value_type impl_get(const point_type& p) const
+ {
+ return f_(input_(p));
+ }
+
+ bool impl_hold(const point_type& p) const
+ {
+ return input_.hold(p);
+ }
+
+ bool impl_hold_large(const point_type& p) const
+ {
+ return input_.hold_large(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,
+ const oln::pw::abstract::function<T>& x)
+{
+ oln::pw::apply<F, T> tmp(f, x);
+ return tmp;
+}
+
+
+#endif // ! OLENA_CORE_PW_APPLY_HH
Index: oln/core/any/grid.hh
--- oln/core/any/grid.hh (revision 0)
+++ oln/core/any/grid.hh (revision 0)
@@ -0,0 +1,71 @@
+// Copyright (C) 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_ANY_GRID_HH
+# define OLENA_CORE_ANY_GRID_HH
+
+# include <mlc/value.hh>
+# include <oln/core/abstract/grid.hh>
+
+
+namespace oln {
+
+ // fwd decls
+ struct any_grid;
+ struct any_point;
+ struct any_dpoint;
+ struct any_coord;
+
+ // super type
+ template <>
+ struct set_super_type < any_grid >
+ {
+ typedef abstract::grid< any_grid > ret;
+ };
+
+ // props
+ template <>
+ struct set_props < category::grid, any_grid >
+ {
+ typedef any_point point_type;
+ typedef any_dpoint dpoint_type;
+ typedef any_coord coord_type;
+ typedef mlc::value<unsigned,0> dimvalue_type;
+ };
+
+ struct any_grid : public abstract::grid< any_grid >
+ {
+ protected:
+ any_grid()
+ {}
+ };
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_ANY_GRID_HH
Index: oln/core/any/point.hh
--- oln/core/any/point.hh (revision 138)
+++ oln/core/any/point.hh (working copy)
@@ -31,6 +31,7 @@
# include <iostream>
# include <oln/core/abstract/point.hh>
# include <oln/core/abstract/dpoint.hh>
+# include <oln/core/any/grid.hh>
namespace oln {
@@ -38,32 +39,41 @@
// fwd decls
struct any_point;
struct any_dpoint;
+ struct any_grid;
// props
template <>
struct set_props < category::point, any_point >
{
typedef any_dpoint dpoint_type;
+ typedef any_grid grid_type;
+ typedef any_coord coord_type;
};
struct any_point : public abstract::point < any_point >
{
-
bool impl_eq(const exact_type& rhs) const
{
return this->exact().impl_eq(rhs.exact());
}
+ const any_point impl_plus(const any_dpoint& rhs) const;
+
template <typename D>
const any_point impl_plus(const abstract::dpoint<D>& rhs) const
{
return any_point();
}
+ const any_dpoint impl_minus(const any_point& rhs) const;
+
template <typename P>
const any_dpoint impl_minus(const abstract::point<P>& rhs) const;
+ const any_coord impl_nth(unsigned i) const;
+
+ any_coord& impl_nth(unsigned i);
};
Index: oln/makefile.src
--- oln/makefile.src (revision 138)
+++ oln/makefile.src (working copy)
@@ -77,6 +77,7 @@
\
core/any/all.hh \
core/any/dpoint.hh \
+ core/any/grid.hh \
core/any/point.hh \
core/any/size.hh \
\
@@ -96,6 +97,7 @@
\
core/pw/abstract/binary_function.hh \
core/pw/abstract/function.hh \
+ core/pw/apply.hh \
core/pw/all.hh \
core/pw/cmp.hh \
core/pw/div.hh \