https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 18 +++++
oln/core/pw/abstract/unary_function.hh | 108 +++++++++++++++++++++++++++++++++
oln/core/pw/apply.hh | 45 ++++---------
oln/makefile.src | 1
4 files changed, 141 insertions(+), 31 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add unary point-wise function (PWF).
Use it to simplify unary apply on PWF.
* oln/core/pw/abstract/unary_function.hh: New file.
* oln/core/pw/apply.hh: Use it to rewrite pw::apply.
(apply): Inherit from pw::abstract::unary_function.
Rename as ...
(apply1): ...this.
(apply1::input_): Remove attribute.
(apply1::apply1): Adjust ctor.
(apply1::impl_get): Adjust method.
(apply1::impl_size, apply1::impl_hold, apply1::impl_hold_large):
Remove methods.
* oln/makefile.src (OLN_DEP): Add
core/pw/abstract/unary_function.hh.
Index: olena/oln/core/pw/abstract/unary_function.hh
--- olena/oln/core/pw/abstract/unary_function.hh (revision 0)
+++ olena/oln/core/pw/abstract/unary_function.hh (revision 0)
@@ -0,0 +1,108 @@
+// 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_ABSTRACT_UNARY_FUNCTION_HH
+# define OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH
+
+# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/abstract/size.hh>
+
+
+
+namespace oln {
+
+
+ // fwd decl
+ namespace pw {
+ namespace abstract {
+ template <typename T, typename E> struct unary_function;
+ }
+ }
+
+ // super type
+ template <typename T, typename E>
+ struct set_super_type < pw::abstract::unary_function<T, E> > { typedef
pw::abstract::function<E> ret; };
+
+ // props
+ template <typename T, typename E>
+ struct set_props < category::pw, pw::abstract::unary_function<T, E> >
+ {
+ typedef oln_pw_type_of(T, point) point_type;
+ typedef oln_pw_type_of(T, size) size_type;
+ };
+
+
+ namespace pw {
+
+ namespace abstract {
+
+ template <typename T, typename E>
+ struct unary_function : public function<E>
+ {
+ typedef T input_type;
+
+ T input;
+
+ unary_function(const abstract::function<T>& input) :
+ input(input.exact())
+ {
+ }
+
+ typedef oln_pw_type_of(E, point) point_type;
+ typedef oln_pw_type_of(E, size) size_type;
+
+ const size_type& impl_size() const
+ {
+ return input.size();
+ }
+
+ 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);
+ }
+
+ protected:
+ unary_function() {}
+
+ };
+
+
+ } // end of namespace oln::pw::abstract
+
+ } // end of namespace oln::pw
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH
Index: olena/oln/core/pw/apply.hh
--- olena/oln/core/pw/apply.hh (revision 154)
+++ olena/oln/core/pw/apply.hh (working copy)
@@ -29,7 +29,7 @@
# define OLENA_CORE_PW_APPLY_HH
# include <mlc/fun.hh>
-# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/pw/abstract/unary_function.hh>
# include <oln/core/pw/abstract/binary_function.hh>
# include <oln/core/pw/macros.hh>
@@ -42,19 +42,19 @@
// fwd decl
namespace pw {
- template <typename F, typename T> struct apply;
+ template <typename F, typename T> struct apply1;
}
// super type
template <typename F, typename T>
- struct set_super_type < pw::apply<F, T> >
+ struct set_super_type < pw::apply1<F, T> >
{
- typedef pw::abstract::function< pw::apply<F, T> > ret;
+ typedef pw::abstract::unary_function< T, pw::apply1<F, T> > ret;
};
// props
template <typename F, typename T>
- struct set_props < category::pw, pw::apply<F, T> >
+ struct set_props < category::pw, pw::apply1<F, T> >
{
typedef oln_pw_type_of(T, point) point_type;
typedef typename F::result_type value_type;
@@ -65,45 +65,28 @@
namespace pw {
template <typename F, typename T>
- struct apply : public abstract::function < apply<F, T> >
+ struct apply1 : public abstract::unary_function < T, apply1<F, T> >
{
- typedef apply<F, T> self_type;
+ typedef apply1<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;
+ typedef abstract::unary_function<T, self_type> super_type;
F f_;
- T input_;
- apply(const mlc::abstract::unary_function<F>& f,
+ apply1(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
+ super_type(input),
+ f_(f.exact())
{
- 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);
+ return f_(this->input(p));
}
};
@@ -173,11 +156,11 @@
/// apply function on pwf
template <typename F, typename T>
-oln::pw::apply<F, T>
+oln::pw::apply1<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);
+ oln::pw::apply1<F, T> tmp(f, x);
return tmp;
}
Index: olena/oln/makefile.src
--- olena/oln/makefile.src (revision 154)
+++ olena/oln/makefile.src (working copy)
@@ -109,6 +109,7 @@
\
core/pw/abstract/binary_function.hh \
core/pw/abstract/function.hh \
+ core/pw/abstract/unary_function.hh \
core/pw/apply.hh \
core/pw/all.hh \
core/pw/cmp.hh \