
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Add opt::value routine. * mln/core/image/flat_image.hh: Update specific method ands typedefs. * mln/core/concept/image.hh: Remove check of a deprecated spe method. * mln/opt/at.hh: Add documentation. * mln/opt/value.hh: New, opt::value routine. * mln/value/sign.hh: Update documentation. * tests/core/image/flat_image.cc: Update tests. * tests/opt/value.cc: New tests. mln/core/concept/image.hh | 3 mln/core/image/flat_image.hh | 30 ++------- mln/opt/at.hh | 18 ++++- mln/opt/value.hh | 124 +++++++++++++++++++++++++++++++++++++++++ mln/value/sign.hh | 2 tests/core/image/flat_image.cc | 2 tests/opt/value.cc | 52 +++++++++++++++++ 7 files changed, 201 insertions(+), 30 deletions(-) Index: mln/core/image/flat_image.hh --- mln/core/image/flat_image.hh (revision 3149) +++ mln/core/image/flat_image.hh (working copy) @@ -117,7 +117,7 @@ typedef const T& rvalue; /// Return type of read-write access. - typedef const T& lvalue; + typedef T& lvalue; /// Constructor without argument. @@ -140,13 +140,12 @@ const T& operator()(const mln_psite(S)& p) const; /// Read-write access to the image value located at point \p p. - const T& operator()(const mln_psite(S)& p); + T& operator()(const mln_psite(S)& p); - /// Change the image value. - void change_value(const T& old_val, const T& new_val); - const T& val() const; - T& val(); + /// Specific methods. + const T& value_() const; + T& value_(); }; @@ -238,7 +237,7 @@ template <typename T, typename S> inline - const T& + T& flat_image<T,S>::operator()(const mln_psite(S)&) { mln_precondition(this->is_valid()); @@ -247,21 +246,8 @@ template <typename T, typename S> inline - void - flat_image<T,S>::change_value(const T& old_val, const T& new_val) - { - mln_precondition(this->is_valid()); - mln_precondition(old_val == this->data_->val_); - this->data_->val_ = new_val; - - /// Avoid warning when NDEBUG is set - (void) old_val; - } - - template <typename T, typename S> - inline const T& - flat_image<T,S>::val() const + flat_image<T,S>::value_() const { mln_precondition(this->is_valid()); return this->data_->val_; @@ -270,7 +256,7 @@ template <typename T, typename S> inline T& - flat_image<T,S>::val() + flat_image<T,S>::value_() { mln_precondition(this->is_valid()); return this->data_->val_; Index: mln/core/concept/image.hh --- mln/core/concept/image.hh (revision 3149) +++ mln/core/concept/image.hh (working copy) @@ -148,9 +148,6 @@ { static void run() { - void (E::*m)(const typename E::value& old_val, - const typename E::value& new_val) = & E::change_value; - m = 0; } }; Index: mln/opt/at.hh --- mln/opt/at.hh (revision 3149) +++ mln/opt/at.hh (working copy) @@ -31,7 +31,7 @@ /// \file mln/opt/at.hh /// -/// FIXME +/// Define the optional routine at. # include <mln/core/concept/image.hh> # include <mln/trait/images.hh> @@ -48,26 +48,38 @@ { /// One dimension + /// Read-only access to the \p ima value located at (\p ind). template <typename I> mln_rvalue(I) at(const Image<I>& ima, def::coord ind); + /// Read-write access to the \p ima value located at (\p ind). template <typename I> mln_lvalue(I) at(Image<I>& ima, def::coord ind); /// Two dimensions + /// Read-only access to the \p ima value located at (\p row, \p col). template <typename I> mln_rvalue(I) at(const Image<I>& ima, def::coord row, def::coord col); + /// Read-write access to the \p ima value located at (\p row, \p col). template <typename I> mln_lvalue(I) at(Image<I>& ima, def::coord row, def::coord col); /// Three dimensions + /// Read-only access to the \p ima value located at + /// (\p sli, \p row, \p col). template <typename I> - mln_rvalue(I) at(const Image<I>& ima, def::coord sli, def::coord row, def::coord col); + mln_rvalue(I) at(const Image<I>& ima, + def::coord sli, def::coord row, def::coord col); + + + /// Read-write access to the \p ima value located at + /// (\p sli, \p row, \p col). template <typename I> - mln_lvalue(I) at(Image<I>& ima, def::coord sli, def::coord row, def::coord col); + mln_lvalue(I) at(Image<I>& ima, + def::coord sli, def::coord row, def::coord col); # ifndef MLN_INCLUDE_ONLY Index: mln/opt/value.hh --- mln/opt/value.hh (revision 0) +++ mln/opt/value.hh (revision 0) @@ -0,0 +1,124 @@ +// 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_OPT_VALUE_HH +# define MLN_OPT_VALUE_HH + +/// \file mln/opt/value.hh +/// +/// Define the opt::value routine. + +# include <mln/core/concept/image.hh> +# include <mln/trait/images.hh> + +namespace mln +{ + + namespace opt + { + + template <typename I> + inline + mln_rvalue(I) value(const Image<I>& ima); + + template <typename I> + inline + mln_lvalue(I) value(Image<I>& ima); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename I> + inline + mln_rvalue(I) value_impl(trait::image::category::domain_morpher, + const Image<I>& ima) + { + return value(*exact(ima).delegatee_()); + } + + template <typename I> + inline + mln_rvalue(I) value_impl(trait::image::category::any, + const Image<I>& ima) + { + mlc_is(mln_trait_image_value_storage(I), + trait::image::value_storage::singleton)::check(); + return exact(ima).value_(); + } + + + + + template <typename I> + inline + mln_lvalue(I) value_impl(trait::image::category::domain_morpher, + Image<I>& ima) + { + return value(*exact(ima).delegatee_()); + } + + template <typename I> + inline + mln_lvalue(I) value_impl(trait::image::category::any, + Image<I>& ima) + { + mlc_is(mln_trait_image_value_storage(I), + trait::image::value_storage::singleton)::check(); + return exact(ima).value_(); + } + } + + + template <typename I> + inline + mln_rvalue(I) value(const Image<I>& ima) + { + return impl::value_impl(mln_trait_image_category(I)(), ima); + } + + template <typename I> + inline + mln_lvalue(I) value(Image<I>& ima) + { + return impl::value_impl(mln_trait_image_category(I)(), ima); + } + + + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::opt + +} // end of namespace mln + + +#endif // ! MLN_OPT_VALUE_HH Index: mln/value/sign.hh --- mln/value/sign.hh (revision 3149) +++ mln/value/sign.hh (working copy) @@ -52,7 +52,7 @@ class sign : public internal::Integer<sign> { public: - /// FIXME is these typedefs correct? + /// FIXME Are these typedefs correct? /// Define the encoding type typedef int enc; Index: tests/core/image/flat_image.cc --- tests/core/image/flat_image.cc (revision 3149) +++ tests/core/image/flat_image.cc (working copy) @@ -51,7 +51,7 @@ { val = 9; - test.val() = 9; + test.value_() = 9; mln_piter_(I) p(test.domain()); for_all(p) mln_assertion(test(p) == val); Index: tests/opt/value.cc --- tests/opt/value.cc (revision 0) +++ tests/opt/value.cc (revision 0) @@ -0,0 +1,52 @@ +// 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/opt/at.cc +/// +/// Tests on mln::opt::at. + +#include <mln/opt/value.hh> +#include <mln/core/image/flat_image.hh> +#include <mln/core/alias/box2d.hh> + +#include <mln/trace/all.hh> + + +int main() +{ + using namespace mln; + + short val = 6; + typedef flat_image<short, box2d> I; + I ima(val, box2d(3, 4)); + + opt::value(ima) = 51; + mln_precondition(opt::value(ima) == 51); + + +}