1391: Add traits for comparison and logical operators.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add traits for comparison and logical operators. * mln/trait/op/leq.hh: New. * mln/trait/op/greater.hh: New. * mln/trait/op/not.hh: New. * mln/trait/op/and.hh: New. * mln/trait/op/less.hh: New. * mln/trait/op/xor.hh: New. * mln/trait/op/geq.hh: New. * mln/trait/op/or.hh: New. * mln/trait/op/all.hh: Update. * mln/trait/op/times.hh, * mln/trait/op/div.hh, * mln/trait/op/plus.hh, * mln/trait/op/neq.hh, * mln/trait/op/minus.hh, * mln/trait/op/postdec.hh, * mln/trait/op/predec.hh, * mln/trait/op/eq.hh, * mln/trait/op/uplus.hh, * mln/trait/op/postinc.hh, * mln/trait/op/mod.hh, * mln/trait/op/uminus.hh, * mln/trait/op/preinc.hh: Add file doc. Remove obsolete fwd decl. * mln/core/ops.hh: New trait defs for new ops. * mln/core/concept/point_set.hh (Point_Set<void>): New category. * mln/core/concept/point_site.hh: Fix doc. * mln/value/ops.hh: Remove dead code. (opertor<): New overload for the couples "scalar_ and Literal". * mln/value/gray.hh (enc, interop): Change from long to int. * mln/value/concept/built_in.hh: Remove dead code. (super): Fix to be compliant with solve. * mln/value/builtin/integers.hh: Update. * mln/value/concept/integer.hh: Fix doc. * mln/value/builtin/ops.hh: New traits for op::uminus and op::uplus. Remove unary trait for builtin. New traits for comparison and logical ops. * mln/value/builtin/promotions.hh: Update. * tests/value_scalar.cc: Augment. * tests/value_builtin.cc: New. mln/core/concept/point_set.hh | 19 ++++++ mln/core/concept/point_site.hh | 3 - mln/core/ops.hh | 52 ++++++++++++++--- mln/trait/op/all.hh | 11 +++ mln/trait/op/and.hh | 65 +++++++++++++++++++++ mln/trait/op/div.hh | 5 + mln/trait/op/eq.hh | 5 + mln/trait/op/geq.hh | 65 +++++++++++++++++++++ mln/trait/op/greater.hh | 65 +++++++++++++++++++++ mln/trait/op/leq.hh | 65 +++++++++++++++++++++ mln/trait/op/less.hh | 65 +++++++++++++++++++++ mln/trait/op/minus.hh | 7 -- mln/trait/op/mod.hh | 5 + mln/trait/op/neq.hh | 5 + mln/trait/op/not.hh | 65 +++++++++++++++++++++ mln/trait/op/or.hh | 65 +++++++++++++++++++++ mln/trait/op/plus.hh | 7 -- mln/trait/op/postdec.hh | 9 +-- mln/trait/op/postinc.hh | 9 +-- mln/trait/op/predec.hh | 9 +-- mln/trait/op/preinc.hh | 9 +-- mln/trait/op/times.hh | 7 -- mln/trait/op/uminus.hh | 10 --- mln/trait/op/uplus.hh | 9 +-- mln/trait/op/xor.hh | 65 +++++++++++++++++++++ mln/value/builtin/integers.hh | 16 ++--- mln/value/builtin/ops.hh | 66 ++++++++++++++++++---- mln/value/builtin/promotions.hh | 47 --------------- mln/value/concept/built_in.hh | 14 ---- mln/value/concept/integer.hh | 20 ++---- mln/value/gray.hh | 4 - mln/value/ops.hh | 49 ++++++++-------- tests/value_builtin.cc | 120 ++++++++++++++++++++++++++++++++++++++++ tests/value_scalar.cc | 49 +++++++++++++++- 34 files changed, 912 insertions(+), 174 deletions(-) Index: tests/value_scalar.cc --- tests/value_scalar.cc (revision 1390) +++ tests/value_scalar.cc (working copy) @@ -31,7 +31,9 @@ */ #include <iostream> + #include <mln/value/scalar.hh> +#include <mln/value/int_u8.hh> template <typename T> @@ -40,12 +42,53 @@ std::cout << mln::value::scalar(t) << std::endl; } +namespace mln +{ + namespace trait + { +// template <typename O1, typename O2> +// struct set_binary_< op::less, Object,O1, Object,O2 > { typedef bool ret; }; + +// template < typename Vl, typename Vr > +// struct set_binary_< op::less, mln::value::Scalar, Vl, mln::value::Scalar, Vr > +// { +// typedef double ret; +// }; + +// template <typename B, typename O> +// struct set_binary_< op::less, +// mln::value::Integer, B, +// mln::value::Scalar, O > +// { +// typedef bool ret; +// }; + + } +} + int main() { using namespace mln; - int i = 51; - foo(i); - foo( value::scalar(i) ); +// int i = 51; +// foo(i); +// foo( value::scalar(i) ); + + + { + bool b; + value::int_u8 i, j; + + b = 1 > value::scalar(j); + + b = value::scalar(j) < value::scalar(j); + +// mln_trait_op_less_(value::scalar_< value::int_u8 >, value::scalar_< value::int_u8 >) tmp; +// void* v = tmp; + +// mln_trait_op_less_(int, value::scalar_< value::int_u8 >) tmp; +// void* v = tmp; + } + } Index: tests/value_builtin.cc --- tests/value_builtin.cc (revision 0) +++ tests/value_builtin.cc (revision 0) @@ -0,0 +1,120 @@ +// Copyright (C) 2007 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_builtin.cc + * + * \brief Tests on mln::trait::op with a builtin. + */ + +#include <iostream> + +#include <mln/value/scalar.hh> +#include <mln/value/int_u8.hh> + + +namespace mln +{ + namespace trait + { + + namespace op + { + + template <typename T> + struct test; + + template <typename L, typename R> + struct test_2; + + } + + // unary + + template < typename S > + struct set_unary_< op::test, mln::value::Scalar, S > + { + typedef double ret; + }; + +// template <typename I> +// struct set_unary_< op::test, +// mln::value::Integer, I > +// { +// typedef float ret; +// }; + +// template <typename I> +// struct set_unary_< op::test, +// mln::value::Built_In, I > +// { +// typedef bool ret; +// }; + + + // binary + + template < typename S1, typename S2 > + struct set_binary_< op::test_2, + mln::value::Scalar, S1, + mln::value::Scalar, S2 > + { + typedef double ret; + }; + +// template < typename I, typename S > +// struct set_binary_< op::test_2, +// mln::value::Integer, I, +// mln::value::Scalar, S > +// { +// typedef float ret; +// }; + +// template < typename B, typename S > +// struct set_binary_< op::test_2, +// mln::value::Built_In, B, +// mln::value::Scalar, S > +// { +// typedef bool ret; +// }; + + } +} + + +int main() +{ + using namespace mln; + + { + mln::trait::solve_binary< trait::op::test_2, int, value::scalar_< value::int_u8 > >::ret tmp; + double& d = tmp; + } + { + mln::trait::solve_unary< trait::op::test, int >::ret tmp; + double& d = tmp; + } +} Index: mln/trait/op/leq.hh --- mln/trait/op/leq.hh (revision 0) +++ mln/trait/op/leq.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_LEQ_HH +# define MLN_TRAIT_OP_LEQ_HH + +/*! \file mln/trait/op/leq.hh + * + * \brief Declaration of the "binary less-or-equal" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_leq(L, R) typename mln::trait::op::leq< L , R >::ret +# define mln_trait_op_leq_(L, R) mln::trait::op::leq< L , R >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename L, typename R> + struct leq : public solve_binary<leq, L, R> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_LEQ_HH Index: mln/trait/op/times.hh --- mln/trait/op/times.hh (revision 1390) +++ mln/trait/op/times.hh (working copy) @@ -28,14 +28,11 @@ #ifndef MLN_TRAIT_OP_TIMES_HH # define MLN_TRAIT_OP_TIMES_HH -/*! - * \file mln/trait/op/times.hh - * - * \brief FIXME +/*! \file mln/trait/op/times.hh * + * \brief Declaration of the "binary multiplication" operator trait. */ - # include <mln/trait/promote.hh> Index: mln/trait/op/div.hh --- mln/trait/op/div.hh (revision 1390) +++ mln/trait/op/div.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_DIV_HH # define MLN_TRAIT_OP_DIV_HH +/*! \file mln/trait/op/div.hh + * + * \brief Declaration of the "binary division" operator trait. + */ + # include <mln/trait/promote.hh> Index: mln/trait/op/plus.hh --- mln/trait/op/plus.hh (revision 1390) +++ mln/trait/op/plus.hh (working copy) @@ -28,14 +28,11 @@ #ifndef MLN_TRAIT_OP_PLUS_HH # define MLN_TRAIT_OP_PLUS_HH -/*! - * \file mln/trait/op/plus.hh - * - * \brief FIXME +/*! \file mln/trait/op/plus.hh * + * \brief Declaration of the "binary plus" operator trait. */ - # include <mln/trait/promote.hh> Index: mln/trait/op/neq.hh --- mln/trait/op/neq.hh (revision 1390) +++ mln/trait/op/neq.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_NEQ_HH # define MLN_TRAIT_OP_NEQ_HH +/*! \file mln/trait/op/neq.hh + * + * \brief Declaration of the "binary un-equality" operator trait. + */ + # include <mln/trait/solve.hh> Index: mln/trait/op/greater.hh --- mln/trait/op/greater.hh (revision 0) +++ mln/trait/op/greater.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_GREATER_HH +# define MLN_TRAIT_OP_GREATER_HH + +/*! \file mln/trait/op/greater.hh + * + * \brief Declaration of the "binary greater" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_greater(L, R) typename mln::trait::op::greater< L , R >::ret +# define mln_trait_op_greater_(L, R) mln::trait::op::greater< L , R >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename L, typename R> + struct greater : public solve_binary<greater, L, R> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_GREATER_HH Index: mln/trait/op/minus.hh --- mln/trait/op/minus.hh (revision 1390) +++ mln/trait/op/minus.hh (working copy) @@ -28,14 +28,11 @@ #ifndef MLN_TRAIT_OP_MINUS_HH # define MLN_TRAIT_OP_MINUS_HH -/*! - * \file mln/trait/op/minus.hh - * - * \brief FIXME +/*! \file mln/trait/op/minus.hh * + * \brief Declaration of the "binary minus" operator trait. */ - # include <mln/trait/promote.hh> Index: mln/trait/op/not.hh --- mln/trait/op/not.hh (revision 0) +++ mln/trait/op/not.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_NOT_HH +# define MLN_TRAIT_OP_NOT_HH + +/*! \file mln/trait/op/not.hh + * + * \brief Declaration of the "unary negation" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_not(T) typename mln::trait::op::not_< T >::ret +# define mln_trait_op_not_(T) mln::trait::op::not_< T >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename T> + struct not_ : public solve_unary<not_, T> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_NOT_HH Index: mln/trait/op/postdec.hh --- mln/trait/op/postdec.hh (revision 1390) +++ mln/trait/op/postdec.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_POSTDEC_HH # define MLN_TRAIT_OP_POSTDEC_HH +/*! \file mln/trait/op/postdec.hh + * + * \brief Declaration of the "unary post-decrementation" operator trait. + */ + # include <mln/trait/solve.hh> @@ -39,10 +44,6 @@ namespace mln { - // Fwd decl. - template <typename E> struct Object; - - namespace trait { Index: mln/trait/op/predec.hh --- mln/trait/op/predec.hh (revision 1390) +++ mln/trait/op/predec.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_PREDEC_HH # define MLN_TRAIT_OP_PREDEC_HH +/*! \file mln/trait/op/predec.hh + * + * \brief Declaration of the "unary pre-decrementation" operator trait. + */ + # include <mln/trait/solve.hh> @@ -39,10 +44,6 @@ namespace mln { - // Fwd decl. - template <typename E> struct Object; - - namespace trait { Index: mln/trait/op/and.hh --- mln/trait/op/and.hh (revision 0) +++ mln/trait/op/and.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_AND_HH +# define MLN_TRAIT_OP_AND_HH + +/*! \file mln/trait/op/and.hh + * + * \brief Declaration of the "binary and" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_and(L, R) typename mln::trait::op::and_< L , R >::ret +# define mln_trait_op_and_(L, R) mln::trait::op::and_< L , R >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename L, typename R> + struct and_ : public solve_binary<and_, L, R> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_AND_HH Index: mln/trait/op/eq.hh --- mln/trait/op/eq.hh (revision 1390) +++ mln/trait/op/eq.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_EQ_HH # define MLN_TRAIT_OP_EQ_HH +/*! \file mln/trait/op/eq.hh + * + * \brief Declaration of the "binary equality" operator trait. + */ + # include <mln/trait/solve.hh> Index: mln/trait/op/less.hh --- mln/trait/op/less.hh (revision 0) +++ mln/trait/op/less.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_LESS_HH +# define MLN_TRAIT_OP_LESS_HH + +/*! \file mln/trait/op/less.hh + * + * \brief Declaration of the "binary less" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_less(L, R) typename mln::trait::op::less< L , R >::ret +# define mln_trait_op_less_(L, R) mln::trait::op::less< L , R >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename L, typename R> + struct less : public solve_binary<less, L, R> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_LESS_HH Index: mln/trait/op/all.hh --- mln/trait/op/all.hh (revision 1390) +++ mln/trait/op/all.hh (working copy) @@ -65,7 +65,16 @@ # include <mln/trait/op/eq.hh> # include <mln/trait/op/neq.hh> -// FIXME: eq, less, ... + and, xor, ... +# include <mln/trait/op/less.hh> +# include <mln/trait/op/leq.hh> +# include <mln/trait/op/geq.hh> +# include <mln/trait/op/greater.hh> + +# include <mln/trait/op/and.hh> +# include <mln/trait/op/or.hh> +# include <mln/trait/op/xor.hh> + +# include <mln/trait/op/not.hh> #endif // ! MLN_TRAIT_OP_ALL_HH Index: mln/trait/op/uplus.hh --- mln/trait/op/uplus.hh (revision 1390) +++ mln/trait/op/uplus.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_UPLUS_HH # define MLN_TRAIT_OP_UPLUS_HH +/*! \file mln/trait/op/uplus.hh + * + * \brief Declaration of the "unary plus" operator trait. + */ + # include <mln/trait/solve.hh> @@ -39,10 +44,6 @@ namespace mln { - // Fwd decl. - template <typename E> struct Object; - - namespace trait { Index: mln/trait/op/xor.hh --- mln/trait/op/xor.hh (revision 0) +++ mln/trait/op/xor.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_XOR_HH +# define MLN_TRAIT_OP_XOR_HH + +/*! \file mln/trait/op/xor.hh + * + * \brief Declaration of the "binary xor" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_xor(L, R) typename mln::trait::op::xor_< L , R >::ret +# define mln_trait_op_xor_(L, R) mln::trait::op::xor_< L , R >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename L, typename R> + struct xor_ : public solve_binary<xor_, L, R> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_XOR_HH Index: mln/trait/op/geq.hh --- mln/trait/op/geq.hh (revision 0) +++ mln/trait/op/geq.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_GEQ_HH +# define MLN_TRAIT_OP_GEQ_HH + +/*! \file mln/trait/op/geq.hh + * + * \brief Declaration of the "binary greater-or-equal" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_geq(L, R) typename mln::trait::op::geq< L , R >::ret +# define mln_trait_op_geq_(L, R) mln::trait::op::geq< L , R >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename L, typename R> + struct geq : public solve_binary<geq, L, R> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_GEQ_HH Index: mln/trait/op/postinc.hh --- mln/trait/op/postinc.hh (revision 1390) +++ mln/trait/op/postinc.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_POSTINC_HH # define MLN_TRAIT_OP_POSTINC_HH +/*! \file mln/trait/op/postinc.hh + * + * \brief Declaration of the "unary post-incrementation" operator trait. + */ + # include <mln/trait/solve.hh> @@ -39,10 +44,6 @@ namespace mln { - // Fwd decl. - template <typename E> struct Object; - - namespace trait { Index: mln/trait/op/mod.hh --- mln/trait/op/mod.hh (revision 1390) +++ mln/trait/op/mod.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_MOD_HH # define MLN_TRAIT_OP_MOD_HH +/*! \file mln/trait/op/mod.hh + * + * \brief Declaration of the "binary modulus" operator trait. + */ + # include <mln/trait/promote.hh> Index: mln/trait/op/uminus.hh --- mln/trait/op/uminus.hh (revision 1390) +++ mln/trait/op/uminus.hh (working copy) @@ -28,11 +28,9 @@ #ifndef MLN_TRAIT_OP_UMINUS_HH # define MLN_TRAIT_OP_UMINUS_HH -/*! - * \file mln/trait/op/uminus.hh - * - * \brief FIXME +/*! \file mln/trait/op/uminus.hh * + * \brief Declaration of the "unary minus" operator trait. */ # include <mln/trait/solve.hh> @@ -46,10 +44,6 @@ namespace mln { - // Fwd decl. - template <typename E> struct Object; - - namespace trait { Index: mln/trait/op/preinc.hh --- mln/trait/op/preinc.hh (revision 1390) +++ mln/trait/op/preinc.hh (working copy) @@ -28,6 +28,11 @@ #ifndef MLN_TRAIT_OP_PREINC_HH # define MLN_TRAIT_OP_PREINC_HH +/*! \file mln/trait/op/predec.hh + * + * \brief Declaration of the "unary pre-decrementation" operator trait. + */ + # include <mln/trait/solve.hh> @@ -39,10 +44,6 @@ namespace mln { - // Fwd decl. - template <typename E> struct Object; - - namespace trait { Index: mln/trait/op/or.hh --- mln/trait/op/or.hh (revision 0) +++ mln/trait/op/or.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2006 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_TRAIT_OP_OR_HH +# define MLN_TRAIT_OP_OR_HH + +/*! \file mln/trait/op/or.hh + * + * \brief Declaration of the "binary or" operator trait. + */ + +# include <mln/trait/solve.hh> + + +# define mln_trait_op_or(L, R) typename mln::trait::op::or_< L , R >::ret +# define mln_trait_op_or_(L, R) mln::trait::op::or_< L , R >::ret + + + +namespace mln +{ + + namespace trait + { + + namespace op + { + + template <typename L, typename R> + struct or_ : public solve_binary<or_, L, R> + { + }; + + } // end of namespace mln::trait::op + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_TRAIT_OP_OR_HH Index: mln/core/ops.hh --- mln/core/ops.hh (revision 1390) +++ mln/core/ops.hh (working copy) @@ -86,7 +86,37 @@ struct set_binary_< op::eq, Object,O1, Object,O2 > { typedef bool ret; }; template <typename O1, typename O2> - struct set_binary_< op::neq, Object,O1, Object,O2 > { typedef bool ret; }; + struct set_binary_< op::neq, Object,O1, Object,O2 > + { + // O1 != O2 --> ! (O1 = O2) + typedef mln_trait_op_eq(O1, O2) B_; + typedef mln_trait_op_not(B_) ret; + }; + + template <typename O1, typename O2> + struct set_binary_< op::less, Object,O1, Object,O2 > { typedef bool ret; }; + + template <typename O1, typename O2> + struct set_binary_< op::leq, Object,O1, Object,O2 > + { + // O1 <= O2 --> ! (O2 < 01) + typedef mln_trait_op_less(O2, O1) B_; + typedef mln_trait_op_not(B_) ret; + }; + + template <typename O1, typename O2> + struct set_binary_< op::geq, Object,O1, Object,O2 > + { + // O1 >= O2 --> O2 <= O1 + typedef mln_trait_op_leq(O2, O1) ret; + }; + + template <typename O1, typename O2> + struct set_binary_< op::greater, Object,O1, Object,O2 > + { + // O1 > O2 --> O2 < O1 + typedef mln_trait_op_less(O2, O1) ret; + }; // FIXME: Same for the other definitions below... @@ -151,7 +181,8 @@ * in milena when applying on a couple of mln::Object. */ template <typename O1, typename O2> - bool operator>(const Object<O1>& lhs, const Object<O2>& rhs); + mln_trait_op_greater(O1, O2) + operator>(const Object<O1>& lhs, const Object<O2>& rhs); /*! \brief General definition of the "greater than or equal to" @@ -165,7 +196,8 @@ * in milena when applying on a couple of mln::Object. */ template <typename O1, typename O2> - bool operator>=(const Object<O1>& lhs, const Object<O2>& rhs); + mln_trait_op_geq(O1, O2) + operator>=(const Object<O1>& lhs, const Object<O2>& rhs); /*! \brief Default definition of the "less than or equal to" @@ -179,7 +211,8 @@ * operator has to be re-defined. */ template <typename O1, typename O2> - bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs); + mln_trait_op_leq(O1, O2) + operator<=(const Object<O1>& lhs, const Object<O2>& rhs); /* \brief Default definition of the post-incrementation operator. @@ -423,7 +456,7 @@ return exact(rhs); } - // Not equal to. + // Comparisons. template <typename O1, typename O2> mln_trait_op_neq(O1, O2) @@ -433,19 +466,22 @@ } template <typename O1, typename O2> - bool operator>(const Object<O1>& lhs, const Object<O2>& rhs) + mln_trait_op_greater(O1, O2) + operator>(const Object<O1>& lhs, const Object<O2>& rhs) { return exact(rhs) < exact(lhs); } template <typename O1, typename O2> - bool operator>=(const Object<O1>& lhs, const Object<O2>& rhs) + mln_trait_op_geq(O1, O2) + operator>=(const Object<O1>& lhs, const Object<O2>& rhs) { return exact(rhs) <= exact(lhs); } template <typename O1, typename O2> - bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs) + mln_trait_op_leq(O1, O2) + operator<=(const Object<O1>& lhs, const Object<O2>& rhs) { // if partial ordering, this operator should be re-defined! return ! (exact(rhs) < exact(lhs)); Index: mln/core/concept/point_set.hh --- mln/core/concept/point_set.hh (revision 1390) +++ mln/core/concept/point_set.hh (working copy) @@ -32,8 +32,10 @@ * * \brief Definition of the concept of mln::Point_Set. * - * \todo Think about adding an 'insert' method (not os easy because of + * \todo Think about adding an 'insert' method (not so easy because of * pset_if...) + * + * \todo Move out the ops. */ # include <mln/core/concept/point.hh> @@ -43,6 +45,18 @@ namespace mln { + // Fwd decl. + template <typename E> struct Point_Set; + + + /// Point_Set category flag type. + template <> + struct Point_Set<void> + { + typedef Object<void> super; + }; + + /*! \brief Base class for implementation classes of point sets. * * \see mln::doc::Point_Set for a complete documentation of this @@ -225,4 +239,7 @@ } // end of namespace mln +# include <mln/core/ops.hh> + + #endif // ! MLN_CORE_CONCEPT_POINT_SET_HH Index: mln/core/concept/point_site.hh --- mln/core/concept/point_site.hh (revision 1390) +++ mln/core/concept/point_site.hh (working copy) @@ -44,7 +44,8 @@ // Fwd decl. template <typename E> struct Point; - // Point_Site category flag type. + + /// Point_Site category flag type. template <> struct Point<void> { Index: mln/value/ops.hh --- mln/value/ops.hh (revision 1390) +++ mln/value/ops.hh (working copy) @@ -301,8 +301,8 @@ return value::equiv(lhs) % value::equiv(rhs); } - // ... + // Operator =. template <typename Sl, typename Sr> mln_trait_op_eq(Sl, Sr) @@ -311,33 +311,10 @@ return value::equiv(lhs) = value::equiv(rhs); } - - // FIXME: Uncomment when less and leq are handled. - -// template <typename Sl, typename Sr> -// mln_trait_op_less(Sl, Sr) -// operator < (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs) -// { -// return value::equiv(lhs) < value::equiv(rhs); -// } - -// template <typename Sl, typename Sr> -// mln_trait_op_leq(Sl, Sr) -// operator <= (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs) -// { -// return value::equiv(lhs) <= value::equiv(rhs); -// } - - // ... - - - - template <typename O, typename L> mln_trait_op_eq(O, O) operator=(const value::scalar_<O>& lhs, const Literal<L>& rhs) { - // mlc_converts_to(L, O)::check(); return exact(lhs) = mln_value_equiv(O)(exact(rhs)); } @@ -345,11 +322,33 @@ mln_trait_op_eq(O, O) operator=(const Literal<L>& lhs, const value::scalar_<O>& rhs) { - // mlc_converts_to(L, O)::check(); return mln_value_equiv(O)(exact(lhs)) = exact(rhs); } + // Operator <. + + template <typename Sl, typename Sr> + mln_trait_op_less(Sl, Sr) + operator < (const value::scalar_<Sl>& lhs, const value::scalar_<Sr>& rhs) + { + return value::equiv(lhs) < value::equiv(rhs); + } + + template <typename O, typename L> + mln_trait_op_less(O, O) + operator < (const value::scalar_<O>& lhs, const Literal<L>& rhs) + { + return exact(lhs) < mln_value_equiv(O)(exact(rhs)); + } + + template <typename L, typename O> + mln_trait_op_less(O, O) + operator < (const Literal<L>& lhs, const value::scalar_<O>& rhs) + { + return mln_value_equiv(O)(exact(lhs)) < exact(rhs); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/value/gray.hh --- mln/value/gray.hh (revision 1390) +++ mln/value/gray.hh (working copy) @@ -72,10 +72,10 @@ public: /// Encoding associated type. - typedef long enc; + typedef int enc; /// Equivalent associated type. - typedef long equiv; + typedef int equiv; /// Constructor without argument. gray(); Index: mln/value/concept/built_in.hh --- mln/value/concept/built_in.hh (revision 1390) +++ mln/value/concept/built_in.hh (working copy) @@ -39,17 +39,6 @@ namespace mln { - // Fwd decl. - namespace value { template <typename E> struct Built_In; } - - - namespace trait - { - // FIXME... - - } // end of namespace mln::trait - - namespace value { @@ -58,8 +47,7 @@ struct Built_In<void> // No inheritance here since this category is special (on the side). { // Every builtin belongs to a sub-category of Value but we do not know which one. - // FIXME HERE FIRST: was void* below - typedef Unknown<void> super; + typedef void* super; }; } // end of namespace mln::value Index: mln/value/concept/integer.hh --- mln/value/concept/integer.hh (revision 1390) +++ mln/value/concept/integer.hh (working copy) @@ -31,6 +31,8 @@ /*! \file mln/value/concept/integer.hh * * \brief Define a generic class for integer values. + * + * \todo Similar files needs to be cleaned-up. */ # include <mln/value/concept/scalar.hh> @@ -39,28 +41,22 @@ namespace mln { - // Fwd decl. - namespace value { template <typename E> struct Integer; } - - - namespace trait + namespace value { - // FIXME... - - } // end of namespace mln::trait + // Fwd decl. + template <typename E> struct Integer; - namespace value - { - - // Category flag type. + /// Category flag type. template <> struct Integer<void> { typedef Scalar<void> super; }; + + /// Concept of integer. template <typename E> struct Integer : public Scalar<E> { Index: mln/value/builtin/ops.hh --- mln/value/builtin/ops.hh (revision 1390) +++ mln/value/builtin/ops.hh (working copy) @@ -318,6 +318,41 @@ namespace trait { + // Unary traits. + + template< typename B > + struct set_unary_< op::uplus, + mln::value::Built_In, B > + { + typedef B ret; + }; + + template<> + struct set_precise_unary_< op::not_, bool > + { + typedef bool ret; + }; + + template<> struct set_precise_unary_< op::uminus, signed char > { typedef signed char ret; }; + template<> struct set_precise_unary_< op::uminus, unsigned char > { typedef int ret; }; + template<> struct set_precise_unary_< op::uminus, signed short > { typedef signed short ret; }; + template<> struct set_precise_unary_< op::uminus, unsigned short > { typedef int ret; }; + template<> struct set_precise_unary_< op::uminus, signed int > { typedef signed int ret; }; + + // Disabled cause no correct result can be obtained + // e.g., (- unsigned int) is an (unsigned int)! + template<> struct set_precise_unary_< op::uminus, unsigned int > {}; + template<> struct set_precise_unary_< op::uminus, signed long > {}; + template<> struct set_precise_unary_< op::uminus, unsigned long > {}; + template<> struct set_precise_unary_< op::uminus, bool > {}; + + template<> struct set_precise_unary_< op::uminus, float > { typedef float ret; }; + template<> struct set_precise_unary_< op::uminus, double > { typedef double ret; }; + + + // FIXME: Is that all? + + // A couple of builtins => promotion... mln_internal_set_builtin_trait_is_promotion_(op::plus); @@ -326,23 +361,28 @@ mln_internal_set_builtin_trait_is_promotion_(op::div); mln_internal_set_builtin_trait_is_promotion_(op::mod); - // ...or for comparisons => bool. + // For comparisons (such as "less-than"), we get bool. mln_internal_set_builtin_trait_is_bool_(op::eq); mln_internal_set_builtin_trait_is_bool_(op::neq); - // FIXME: ... - // FIXME: What about +=, etc. + mln_internal_set_builtin_trait_is_bool_(op::less); + mln_internal_set_builtin_trait_is_bool_(op::leq); + mln_internal_set_builtin_trait_is_bool_(op::geq); + mln_internal_set_builtin_trait_is_bool_(op::greater); + + mln_internal_set_builtin_trait_is_bool_(op::and_); + mln_internal_set_builtin_trait_is_bool_(op::or_); + mln_internal_set_builtin_trait_is_bool_(op::xor_); + // FIXME: We want to disable some ops; for instance "bool + int" and "int and int"... + + + + + // FIXME: What about +=, etc. - template< template <class> class Name, - typename B > - struct set_unary_< Name, - mln::value::Built_In, B > - { - typedef B ret; // FIXME: Wrong because some types are unsigned! - }; // Operators "Object OP Built_In" => "Object OP scalar_" @@ -377,6 +417,12 @@ typedef mln_trait_op_mod(O, mln::value::scalar_<B>) ret; }; + template <typename O, typename B> + struct set_binary_< op::less, mln::Object, O, mln::value::Built_In, B > + { + typedef mln_trait_op_less(O, mln::value::scalar_<B>) ret; + }; + // 'Op+' is commutative so "o + b" => "o + scalar(b)". Index: mln/value/builtin/promotions.hh --- mln/value/builtin/promotions.hh (revision 1390) +++ mln/value/builtin/promotions.hh (working copy) @@ -68,28 +68,6 @@ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n -# define mln_internal_set_uminus_bi_(Builtin, Result) \ - \ - template<> \ - struct set_precise_unary_< op::uminus, Builtin > \ - { \ - typedef Result ret; \ - }; \ - \ - struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n - - -# define mln_internal_set_uplus_bi_(Builtin) \ - \ - template<> \ - struct set_precise_unary_< op::uplus, Builtin > \ - { \ - typedef Builtin ret; \ - }; \ - \ - struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n - - namespace mln { @@ -171,31 +149,6 @@ mln_internal_set_promotion_auto_( float, double); - - // Builtin unary traits. - - mln_internal_set_uplus_bi_(unsigned char ); - mln_internal_set_uplus_bi_( signed char ); - mln_internal_set_uplus_bi_(unsigned short); - mln_internal_set_uplus_bi_( signed short); - mln_internal_set_uplus_bi_(unsigned int ); - mln_internal_set_uplus_bi_( signed int ); - mln_internal_set_uplus_bi_(unsigned long ); - mln_internal_set_uplus_bi_( signed long ); - mln_internal_set_uplus_bi_( float ); - mln_internal_set_uplus_bi_( double ); - - mln_internal_set_uminus_bi_(unsigned char, unsigned char); - mln_internal_set_uminus_bi_( signed char, signed char); - mln_internal_set_uminus_bi_(unsigned short, unsigned short); - mln_internal_set_uminus_bi_( signed short, signed short); - mln_internal_set_uminus_bi_(unsigned int, unsigned int); - mln_internal_set_uminus_bi_( signed int, signed int); - mln_internal_set_uminus_bi_(unsigned long, unsigned long); - mln_internal_set_uminus_bi_( signed long, signed long); - mln_internal_set_uminus_bi_( float, float); - mln_internal_set_uminus_bi_( double, double); - } // end of namespace mln::trait } // end of namespace mln Index: mln/value/builtin/integers.hh --- mln/value/builtin/integers.hh (revision 1390) +++ mln/value/builtin/integers.hh (working copy) @@ -45,14 +45,14 @@ namespace mln { - template <> struct category< unsigned char > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; - template <> struct category< signed char > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; - template <> struct category< unsigned short > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; - template <> struct category< signed short > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; - template <> struct category< unsigned int > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; - template <> struct category< signed int > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; - template <> struct category< unsigned long > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; - template <> struct category< signed long > { typedef value::Built_In<void*> ret; typedef value::Integer<void> super; }; + template <> struct category< unsigned char > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; + template <> struct category< signed char > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; + template <> struct category< unsigned short > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; + template <> struct category< signed short > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; + template <> struct category< unsigned int > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; + template <> struct category< signed int > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; + template <> struct category< unsigned long > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; + template <> struct category< signed long > { typedef value::Built_In<void> ret; typedef value::Integer<void> super; }; namespace trait
participants (1)
-
Thierry Geraud