cleanup-2008 2870: Add set compute with an accumulator.
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add set compute with an accumulator. * tests/set/compute.cc: New. * tests/set/Makefile.am: Update. * tests/set/diff.cc: Upgrade doc style. Fix clumsy include. * mln/set/compute.hh: New. * mln/set/all.hh: Update. mln/set/all.hh | 11 +++- mln/set/compute.hh | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/set/Makefile.am | 2 tests/set/compute.cc | 44 +++++++++++++++++++ tests/set/diff.cc | 10 ++-- 5 files changed, 170 insertions(+), 9 deletions(-) Index: tests/set/compute.cc --- tests/set/compute.cc (revision 0) +++ tests/set/compute.cc (revision 0) @@ -0,0 +1,44 @@ +// 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. + +/// \file tests/set/compute.cc +/// +/// Tests on mln::set::compute. + +#include <mln/core/site_set/p_set.hh> +#include <mln/core/alias/point2d.hh> +#include <mln/accu/count.hh> +#include <mln/set/compute.hh> + + +int main() +{ + using namespace mln; + + p_set<point2d> s; + mln_assertion(set::compute(accu::meta::count(), s) == 0); +} Index: tests/set/Makefile.am --- tests/set/Makefile.am (revision 2869) +++ tests/set/Makefile.am (working copy) @@ -3,12 +3,14 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ + compute \ diff \ inter \ is_subset_of \ sym_diff \ uni +compute_SOURCES = compute.cc diff_SOURCES = diff.cc inter_SOURCES = inter.cc is_subset_of_SOURCES = is_subset_of.cc Index: tests/set/diff.cc --- tests/set/diff.cc (revision 2869) +++ tests/set/diff.cc (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 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 @@ -25,13 +26,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/set/diff.cc - * - * \brief Tests on mln::set::diff. - */ +/// \file tests/set/diff.cc +/// +/// Tests on mln::set::diff. #include <mln/core/site_set/p_set.hh> -#include <mln/core/alias/dpoint2d.hh> +#include <mln/core/alias/point2d.hh> #include <mln/set/diff.hh> Index: mln/set/all.hh --- mln/set/all.hh (revision 2869) +++ mln/set/all.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 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 @@ -28,10 +29,9 @@ #ifndef MLN_SET_ALL_HH # define MLN_SET_ALL_HH -/*! \file mln/set/all.hh - * - * \brief File that includes all set-related routines. - */ +/// \file mln/set/all.hh +/// +/// File that includes all set-related routines. namespace mln @@ -42,6 +42,8 @@ } + +# include <mln/set/compute.hh> # include <mln/set/diff.hh> # include <mln/set/inter.hh> # include <mln/set/get.hh> @@ -50,4 +52,5 @@ # include <mln/set/sym_diff.hh> # include <mln/set/uni.hh> + #endif // ! MLN_SET_ALL_HH Index: mln/set/compute.hh --- mln/set/compute.hh (revision 0) +++ mln/set/compute.hh (revision 0) @@ -0,0 +1,112 @@ +// 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_SET_COMPUTE_HH +# define MLN_SET_COMPUTE_HH + +/// \file mln/set/compute.hh +/// +/// Compute an accumulator on a site set. + +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/core/concept/site_set.hh> + + +namespace mln +{ + + namespace set + { + + /*! Compute an accumulator onto the sites of a site set. + * + * \param[in] a An accumulator. + * \param[in] s A site set. + * \return The accumulator result. + */ + template <typename A, typename S> + mln_result(A) + compute(const Accumulator<A>& a, const Site_Set<S>& s); + + + /*! Compute an accumulator onto the sites of a site set. + * + * \param[in] a A meta-accumulator. + * \param[in] s A site set. + * \return The accumulator result. + */ + template <typename A, typename S> + mln_accu_with(A, mln_site(S))::result + compute(const Meta_Accumulator<A>& a, const Site_Set<S>& s); + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A, typename S> + inline + mln_result(A) + compute(const Accumulator<A>& a_, const Site_Set<S>& s_) + { + trace::entering("set::compute"); + + A a = exact(a_); + const S& s = exact(s_); + + mln_piter(S) p(s); + for_all(p) + a.take(p); + + trace::exiting("set::compute"); + return a.to_result(); + } + + template <typename A, typename S> + mln_accu_with(A, mln_site(S))::result + compute(const Meta_Accumulator<A>& a_, const Site_Set<S>& s_) + { + trace::entering("set::compute"); + + mln_accu_with(A, mln_site(S)) a = accu::unmeta(exact(a_), mln_site(S)()); + const S& s = exact(s_); + + mln_piter(S) p(s); + for_all(p) + a.take(p); + + trace::exiting("set::compute"); + return a.to_result(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::set + +} // end of namespace mln + + +#endif // ! MLN_SET_COMPUTE_HH
participants (1)
-
Thierry Geraud