https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add functors max and min.
* mln/core/concept/function.hh (mln::Function_vv2v): New.
* mln/fun/vv2v/max.hh, mln/fun/vv2v/min.hh: New.
* tests/fun/vv2v/max.cc, tests/fun/vv2v/min.cc: New tests.
* tests/fun/vv2v/Makefile.am: New.
* tests/fun/Makefile.am (SUBDIRS): Add i2v, p2b, p2v and vv2v.
* tests/norm/common.hh: Adjust coding style.
mln/core/concept/function.hh | 77 +++++++++++++++++++++++++++++++++++--------
mln/fun/vv2v/max.hh | 77 +++++++++++++++++++++++++++++++++++++++++++
mln/fun/vv2v/min.hh | 77 +++++++++++++++++++++++++++++++++++++++++++
tests/fun/Makefile.am | 2 -
tests/fun/vv2v/Makefile.am | 12 ++++++
tests/fun/vv2v/max.cc | 53 +++++++++++++++++++++++++++++
tests/fun/vv2v/min.cc | 53 +++++++++++++++++++++++++++++
tests/norm/common.hh | 0
8 files changed, 336 insertions(+), 15 deletions(-)
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1707)
+++ mln/core/concept/function.hh (working copy)
@@ -39,9 +39,7 @@
namespace mln
{
- /// \{
- /// Fwd decls.
-
+ // Fwd decls.
template <typename E> struct Function;
template <typename E> struct Function_v2v;
template <typename E> struct Function_i2v;
@@ -50,11 +48,11 @@
template <typename E> struct Function_p2b;
template <typename E> struct Function_p2p;
template <typename E> struct Function_x2x;
- /// \}
+ template <typename E> struct Function_vv2v;
- // Function category flag type.
+ /// Function category flag type.
template <>
struct Function<void>
{
@@ -81,7 +79,9 @@
};
- // Value -> Value.
+ /*-----------------.
+ | Value -> Value. |
+ `-----------------*/
template <>
struct Function_v2v<void> { typedef Function<void> super; };
@@ -102,12 +102,13 @@
};
- // Index -> Value.
+ /*-----------------.
+ | Index -> Value. |
+ `-----------------*/
template <>
struct Function_i2v<void> { typedef Function_v2v<void> super; };
-
/*!
* \brief Base class for implementation of function-objects from
* index to value.
@@ -124,7 +125,9 @@
};
- // Point -> Value.
+ /*-----------------.
+ | Point -> Value. |
+ `-----------------*/
template <>
struct Function_p2v<void> { typedef Function_v2v<void> super; };
@@ -145,7 +148,9 @@
};
- // Value -> bool.
+ /*----------------.
+ | Value -> bool. |
+ `----------------*/
template <>
struct Function_v2b<void> { typedef Function_v2v<void> super; };
@@ -167,7 +172,9 @@
};
- // Point -> bool.
+ /*----------------.
+ | Point -> bool. |
+ `----------------*/
template <>
struct Function_p2b<void> { typedef Function_p2v<void> super; }; // FIXME
@@ -190,7 +197,9 @@
};
- // Point -> Point.
+ /*-----------------.
+ | Point -> Point. |
+ `-----------------*/
template <>
struct Function_p2p<void> { typedef Function_p2v<void> super; }; // FIXME
@@ -211,7 +220,9 @@
};
- // Vector -> Vector.
+ /*-------------------.
+ | Vector -> Vector. |
+ `-------------------*/
template <>
struct Function_x2x<void> { typedef Function_v2v<void> super; }; // FIXME
@@ -231,7 +242,10 @@
Function_x2x(const Function_x2x&);
};
- // Vector <-> Vector.
+
+ /*--------------------.
+ | Vector <-> Vector. |
+ `--------------------*/
/*!
* \brief Base class for implementation of bijective function-objects from
@@ -251,6 +265,28 @@
};
+ /*------------------------.
+ | Value, Value -> Value. |
+ `------------------------*/
+
+ template <>
+ struct Function_vv2v<void> { typedef Function<void> super; };
+
+ /*!
+ * \brief Base class for implementation of function-objects from
+ * a couple of values to a value.
+ *
+ * The parameter \a E is the exact type.
+ */
+ template <typename E>
+ struct Function_vv2v : public Function<E>
+ {
+ typedef Function_vv2v<void> category;
+ protected:
+ Function_vv2v();
+ Function_vv2v(const Function_vv2v&);
+ };
+
# ifndef MLN_INCLUDE_ONLY
@@ -370,6 +406,19 @@
m = 0;
}
+ template <typename E>
+ inline
+ Function_vv2v<E>::Function_vv2v()
+ {
+ }
+
+ template <typename E>
+ inline
+ Function_vv2v<E>::Function_vv2v(const Function_vv2v<E>& rhs)
+ : Function<E>(rhs)
+ {
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/fun/vv2v/min.hh
--- mln/fun/vv2v/min.hh (revision 0)
+++ mln/fun/vv2v/min.hh (revision 0)
@@ -0,0 +1,77 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_FUN_VV2V_MIN_HH
+# define MLN_FUN_VV2V_MIN_HH
+
+/// \file mln/fun/vv2v/min.hh
+/// \brief computing the minimum of two values using a functor.
+
+# include <mln/core/concept/function.hh>
+# include <mln/math/min.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace vv2v
+ {
+
+ // FIXME: Doc.
+
+ /// \brief A functor computing the minimum of two values.
+ template <typename V>
+ struct min : public Function_vv2v< min<V> >
+ {
+ typedef V result;
+ V operator()(const V& v1, const V& v2) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ V
+ min<V>::operator()(const V& v1, const V& v2) const
+ {
+ return mln::math::min(v1, v2);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::vv2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VV2V_MIN_HH
Index: mln/fun/vv2v/max.hh
--- mln/fun/vv2v/max.hh (revision 0)
+++ mln/fun/vv2v/max.hh (revision 0)
@@ -0,0 +1,77 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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 MLN_FUN_VV2V_MAX_HH
+# define MLN_FUN_VV2V_MAX_HH
+
+/// \file mln/fun/vv2v/max.hh
+/// \brief Computing the maximum of two values using a functor.
+
+# include <mln/core/concept/function.hh>
+# include <mln/math/max.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace vv2v
+ {
+
+ // FIXME: Doc.
+
+ /// \brief A functor computing the maximum of two values.
+ template <typename V>
+ struct max : public Function_vv2v< max<V> >
+ {
+ typedef V result;
+ V operator()(const V& v1, const V& v2) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ V
+ max<V>::operator()(const V& v1, const V& v2) const
+ {
+ return mln::math::max(v1, v2);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::vv2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VV2V_MAX_HH
Index: tests/fun/vv2v/min.cc
--- tests/fun/vv2v/min.cc (revision 0)
+++ tests/fun/vv2v/min.cc (revision 0)
@@ -0,0 +1,53 @@
+// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/// \file tests/fun/vv2v/min.cc
+/// \brief Test the min functor.
+
+#include <cassert>
+
+#include <mln/metal/vec.hh>
+#include <mln/fun/vv2v/min.hh>
+
+int main()
+{
+ // Scalars.
+ mln::fun::vv2v::min<int> min_int;
+ assert (min_int(42, 51) == 42);
+
+ // FIXME: We don't have vectors-with-an-order (yet), so this won't
+ // work.
+#if 0
+ // Vectors.
+ typedef mln::metal::vec<3, int> vec_t;
+ mln::fun::vv2v::min<vec_t> min_vec_t;
+ vec_t t, u;
+ t.set (1, -2, 3);
+ u.set (5, 1, 0);
+ assert (min_vec_t(t, u) == t);
+#endif
+}
Index: tests/fun/vv2v/max.cc
--- tests/fun/vv2v/max.cc (revision 0)
+++ tests/fun/vv2v/max.cc (revision 0)
@@ -0,0 +1,53 @@
+// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/// \file tests/fun/vv2v/max.cc
+/// \brief Test the max functor.
+
+#include <cassert>
+
+#include <mln/metal/vec.hh>
+#include <mln/fun/vv2v/max.hh>
+
+int main()
+{
+ // Scalars.
+ mln::fun::vv2v::max<int> max_int;
+ assert (max_int(42, 51) == 51);
+
+ // FIXME: We don't have vectors-with-an-order (yet), so this won't
+ // work.
+#if 0
+ // Vectors.
+ typedef mln::metal::vec<3, int> vec_t;
+ mln::fun::vv2v::max<vec_t> max_vec_t;
+ vec_t t, u;
+ t.set (1, -2, 3);
+ u.set (5, 1, 0);
+ assert (max_vec_t(t, u) == u);
+#endif
+}
Index: tests/fun/vv2v/Makefile.am
--- tests/fun/vv2v/Makefile.am (revision 0)
+++ tests/fun/vv2v/Makefile.am (revision 0)
@@ -0,0 +1,12 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ max \
+ min
+
+max_SOURCES = max.cc
+min_SOURCES = min.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/fun/Makefile.am
--- tests/fun/Makefile.am (revision 1707)
+++ tests/fun/Makefile.am (working copy)
@@ -2,4 +2,4 @@
include $(top_srcdir)/milena/tests/tests.mk
-SUBDIRS = v2v x2x
+SUBDIRS = i2v p2b p2v v2v vv2v x2x
Index: tests/norm/common.hh