
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add a label wrapper in fun::l2l. * mln/fun/l2l/wrap.hh: New. * mln/fun/l2l/all.hh: Update. * tests/fun/l2l: New directory. * tests/fun/Makefile.am: Update. * tests/fun/l2l/wrap.cc: New. * tests/fun/l2l/Makefile.am: New. mln/fun/l2l/all.hh | 4 +- mln/fun/l2l/wrap.hh | 87 ++++++++++++++++++++++++++++++++++++++++++++++ tests/fun/Makefile.am | 2 - tests/fun/l2l/Makefile.am | 10 +++++ tests/fun/l2l/wrap.cc | 58 ++++++++++++++++++++++++++++++ 5 files changed, 159 insertions(+), 2 deletions(-) Index: mln/fun/l2l/all.hh --- mln/fun/l2l/all.hh (revision 3366) +++ mln/fun/l2l/all.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009 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 @@ -49,6 +50,7 @@ # include <mln/fun/l2l/relabel.hh> +# include <mln/fun/l2l/wrap.hh> Index: mln/fun/l2l/wrap.hh --- mln/fun/l2l/wrap.hh (revision 0) +++ mln/fun/l2l/wrap.hh (revision 0) @@ -0,0 +1,87 @@ +// Copyright (C) 2009 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_L2L_WRAP_HH +# define MLN_FUN_L2L_WRAP_HH + +/// \file mln/fun/l2l/wrap.hh +/// +/// Function to wrap labels such as 0 -> 0 and [1, lmax] maps to [1, +/// Lmax] (using modulus). +/// +/// \todo Prefer not to cast towards 'unsigned long'; use a procedure +/// such as enc(l) that can work on 'unsigned', 'int_u8', 'label<n>', and +/// also other label types. + +# include <mln/core/concept/function.hh> + + +namespace mln +{ + + namespace fun + { + + namespace l2l + { + + template <typename L> + struct wrap : public Function_l2l< wrap<L> > + { + public: + + typedef L result; + + template <typename L_> + L operator()(const L_& l_) const; + + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename L> + template <typename L_> + inline + L + wrap<L>::operator()(const L_& l_) const + { + mlc_converts_to(L_, unsigned long)::check(); + unsigned long l = static_cast<unsigned long>(l_); + return l == 0ul ? L(0ul) : L(1 + (l - 1) % 255); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::l2l + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_L2L_WRAP_HH Index: tests/fun/Makefile.am --- tests/fun/Makefile.am (revision 3366) +++ tests/fun/Makefile.am (working copy) @@ -2,4 +2,4 @@ include $(top_srcdir)/milena/tests/tests.mk -SUBDIRS = i2v p2b p2p p2v v2v vv2v x2x +SUBDIRS = i2v p2b l2l p2p p2v v2v vv2v x2x Index: tests/fun/l2l/Makefile.am --- tests/fun/l2l/Makefile.am (revision 0) +++ tests/fun/l2l/Makefile.am (revision 0) @@ -0,0 +1,10 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + wrap + +wrap_SOURCES = wrap.cc + +TESTS = $(check_PROGRAMS) Index: tests/fun/l2l/wrap.cc --- tests/fun/l2l/wrap.cc (revision 0) +++ tests/fun/l2l/wrap.cc (revision 0) @@ -0,0 +1,58 @@ +// Copyright (C) 2009 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/fun/l2l/wrap.cc +/// +/// Test on mln::fun::l2l::wrap. + +#include <mln/fun/l2l/wrap.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/label_16.hh> + + +int main() +{ + using namespace mln; + + fun::l2l::wrap<value::int_u8> f; + + value::label_16 + l0 = 0, + l1 = 1, + l255 = 255, + l256 = 256, + l510 = 510, + l511 = 511; + + mln_assertion( f(l0) == 0 ); + mln_assertion( f(l1) == 1 ); + mln_assertion( f(l255) == 255 ); + mln_assertion( f(l256) == 1 ); + mln_assertion( f(l510) == 255 ); + mln_assertion( f(l511) == 1 ); +}