https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Add the sign value type (subset of the int value type). * tests/core/image/flat_image.cc: Update the test. * tests/value/sign.cc: New test. * tests/value/Makefile.am: Add the new test in the Makefile. * mln/value/sign.hh: New sign value type. * mln/value/super_value.hh: Update the super_value trait. * mln/make/box2d.hh: Fix a conversion warning. mln/make/box2d.hh | 4 mln/value/sign.hh | 229 +++++++++++++++++++++++++++++++++++++++++ mln/value/super_value.hh | 16 ++ tests/core/image/flat_image.cc | 9 + tests/value/Makefile.am | 2 tests/value/sign.cc | 51 +++++++++ 6 files changed, 302 insertions(+), 9 deletions(-) Index: tests/core/image/flat_image.cc --- tests/core/image/flat_image.cc (revision 2204) +++ tests/core/image/flat_image.cc (working copy) @@ -32,18 +32,21 @@ #include <mln/core/image/flat_image.hh> #include <mln/core/alias/box2d.hh> +#include <mln/value/sign.hh> int main() { - { using namespace mln; + { flat_image<short, box2d> test; - std::cout << test.values_eligible() << std::endl; std::cout << test.values_space() << std::endl; - // flat_image<short, box2d>::t_eligible_value_set::fwd_viter viter(test.values_eligible()); + } + { + flat_image<value::sign, box2d> test; + std::cout << test.values_eligible() << std::endl; } } Index: tests/value/sign.cc --- tests/value/sign.cc (revision 0) +++ tests/value/sign.cc (revision 0) @@ -0,0 +1,51 @@ +// 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/value/sign.cc + * + * \brief Tests on mln::value::sign. + */ + +#include <cassert> +#include <mln/value/sign.hh> + + +int main() +{ + using namespace mln; + using value::sign; + + { + sign s; + s = -1; + s = 0; + s = 1; + assert(sign::zero == 0); + assert(sign::one == 1); + assert(s != 3); + } +} Index: tests/value/Makefile.am --- tests/value/Makefile.am (revision 2204) +++ tests/value/Makefile.am (working copy) @@ -27,6 +27,7 @@ rgb8 \ scalar \ set \ + sign \ stack # FIXME: Enable when make check_full works. @@ -51,6 +52,7 @@ rgb8_SOURCES = rgb8.cc scalar_SOURCES = scalar.cc set_SOURCES = set.cc +sign_SOURCES = sign.cc stack_SOURCES = stack.cc # FIXME: Enable when make check_full works. Index: mln/value/sign.hh --- mln/value/sign.hh (revision 0) +++ mln/value/sign.hh (revision 0) @@ -0,0 +1,229 @@ +// 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. + +#ifndef MLN_VALUE_SIGN_HH +# define MLN_VALUE_SIGN_HH + +/*! \file mln/value/sign.hh + * + * \brief Definition of the mln::value::sign class. + */ + +# include <mln/value/internal/integer.hh> +# include <mln/trait/value_.hh> +# include <mln/literal/zero.hh> +# include <mln/literal/one.hh> +# include <mln/debug/format.hh> + +namespace mln +{ + namespace value + { + + + /*! + ** \brief The sign class represents the value type + ** composed by the set (-1, 0, 1) + ** sign value type is a subset of the int value type. + */ + class sign : public internal::Integer<sign> + { + public: + /// FIXME is these typedefs correct? + + /// Define the encoding type + typedef int enc; + + /// Define the equivalent type + typedef int equiv; + + + /// Constructor without argument. + sign(); + + /// Constructor from an integer. + sign(int i); + + /// \{ Constructors/assignments with literals. + sign(const mln::literal::zero_t&); + sign& operator=(const mln::literal::zero_t&); + sign(const mln::literal::one_t&); + sign& operator=(const mln::literal::one_t&); + /// \} + + /// Conversion to an integer. + operator int() const; + + /// Return the value associated to the sign object + int val_() const; + + /// Assignment from an integer. + sign& operator=(int i); + + + + /// Zero value. + static const sign zero; + + /// Unit value. + static const sign one; + + protected: + + /// The value + int v_; + }; + + /*! \brief Print an signed integer \p i into the output stream \p ostr. + * + * \param[in,out] ostr An output stream. + * \param[in] i An sign value + * + * \return The modified output stream \p ostr. + */ + std::ostream& operator<<(std::ostream& ostr, const sign& i); + + /// Comparaison operator + bool operator==(sign lhs, sign rhs); + +# ifndef MLN_INCLUDE_ONLY + + inline + sign::sign() + { + } + + inline + sign::operator int() const + { + return this->v_; + } + + inline + int + sign::val_() const + { + return this->v_; + } + + inline + sign::sign(int i) + { + mln_precondition(i >= -1); + mln_precondition(i <= 1); + this->v_ = i; + } + + inline + sign& + sign::operator=(int i) + { + mln_precondition(i >= -1); + mln_precondition(i <= 1); + this->v_ = i; + return *this; + } + + inline + sign::sign(const mln::literal::zero_t&) + { + this->v_ = 0; + } + + inline + sign& + sign::operator=(const mln::literal::zero_t&) + { + this->v_ = 0; + return *this; + } + + inline + sign::sign(const mln::literal::one_t&) + { + this->v_ = 1; + } + + inline + sign& + sign::operator=(const mln::literal::one_t&) + { + this->v_ = 1; + return *this; + } + + const sign sign::zero = 0; + + const sign sign::one = 1; + + inline + std::ostream& operator<<(std::ostream& ostr, const sign& i) + { + return ostr << debug::format(i.val_()); + } + + inline + bool operator==(sign lhs, sign rhs) + { + return lhs.val_() == rhs.val_(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace value + + + namespace trait + { + + template <> + struct value_<mln::value::sign> + { + + enum { + nbits = 2, + card = 3 + }; + + typedef trait::value::nature::integer nature; + typedef trait::value::kind::gray kind; + typedef trait::value::quant::low quant; + + static mln::value::sign min() { return -1; } + static mln::value::sign max() { return 1; } + static mln::value::sign epsilon() { return 0; } + + typedef int sum; + }; + + } // end of namespace trait + + +} // end of namespace mln + + +#endif // ! MLN_VALUE_SIGN_HH Index: mln/value/super_value.hh --- mln/value/super_value.hh (revision 2204) +++ mln/value/super_value.hh (working copy) @@ -33,6 +33,8 @@ * \brief Definition of the mln::super_value trait. */ +# include <mln/value/sign.hh> + namespace mln { @@ -49,11 +51,17 @@ typedef T ret; }; - /// Specialization - /// + /// Specializations: + + /// Sign type is a subset of the short value type. + template <> + struct super_value<sign> + { + typedef int ret; + }; - } + } // end of namespace value -} +} // end of namespace mln #endif // !MLN_VALUE_SUPER_VALUE_HH Index: mln/make/box2d.hh --- mln/make/box2d.hh (revision 2204) +++ mln/make/box2d.hh (working copy) @@ -79,8 +79,8 @@ { mln_precondition(nrows != 0 && ncols != 0); mln::box2d tmp(make::point2d(0, 0), - make::point2d(nrows - 1, - ncols - 1)); + make::point2d(def::coord (nrows - 1), + def::coord (ncols - 1))); return tmp; }