974: Add materials for value types and builtins.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add materials for value types and builtins. * oln/core/internal/f_grid_coord_to_point.hh: New. * oln/core/internal/macros_ops.hh: New. * oln/core/internal/value_base.hh: New. * oln/morpho/thinning.hh: New. * oln/value/gray_level.hh: New. * oln/value/bool.hh: New. * oln/value/gray.hh: New. * oln/value/black.hh: New. * oln/value/mlc_extra.hh: New. * oln/core/2d/image2d_b.hh (fiter): Update. * oln/core/3d/image3d_b.hh: Likewise. * oln/core/equipment.hh (encoding, fiter, nbits): New. * oln/core/gen/extended_by.hh: Add mutable nbh version. * oln/core/gen/inplace.hh: New error type. * oln/core/gen/value.hh (unwrap): New. (make_value): New overload. * oln/core/gen/zero.hh: Replace operators by... (assignment_): New. * oln/core/concept/literal.hh (operator T): New. * oln/core/concept/dpoint.hh (operator%=): Fix and factor. * oln/core/internal/dpoint_base.hh (impl_op_mod_equal_): Remove. * oln/core/concept/value.hh (Boolean): Remove. * oln/core/concept/operators.hh: Handle builtins. * oln/morpho/elementary_gradient.hh (postcondition): Update. * oln/morpho/top_hat_black.hh, * oln/morpho/top_hat_white.hh, * oln/morpho/elementary_gradient_internal.hh, * oln/morpho/elementary_gradient_external.hh, * oln/morpho/gradient_internal.hh, * oln/morpho/gradient.hh, * oln/morpho/gradient_external.hh: Likewise. * oln/arith/plus.hh, * oln/arith/minus.hh, * oln/level/local_sup.hh, * oln/level/fill.hh, * oln/level/local_inf.hh, * oln/value/builtin_traits.hh, * oln/value/builtin.hh: Update. * oln/level/compare.hh: Update. arith/minus.hh | 2 arith/plus.hh | 2 core/2d/image2d_b.hh | 3 core/3d/image3d_b.hh | 3 core/concept/dpoint.hh | 9 core/concept/literal.hh | 13 + core/concept/operators.hh | 59 ++++ core/concept/value.hh | 22 - core/equipment.hh | 6 core/gen/extended_by.hh | 2 core/gen/inplace.hh | 7 core/gen/value.hh | 17 + core/gen/zero.hh | 33 -- core/internal/dpoint_base.hh | 14 - core/internal/f_grid_coord_to_point.hh | 111 ++++++++ core/internal/macros_ops.hh | 77 ++++++ core/internal/value_base.hh | 300 +++++++++++++++++++++++ level/compare.hh | 161 ++++++++---- level/fill.hh | 3 level/local_inf.hh | 6 level/local_sup.hh | 6 morpho/elementary_gradient.hh | 2 morpho/elementary_gradient_external.hh | 2 morpho/elementary_gradient_internal.hh | 2 morpho/gradient.hh | 2 morpho/gradient_external.hh | 2 morpho/gradient_internal.hh | 2 morpho/thinning.hh | 141 +++++++++++ morpho/top_hat_black.hh | 2 morpho/top_hat_white.hh | 2 value/black.hh | 91 +++++++ value/bool.hh | 55 ++++ value/builtin.hh | 61 +--- value/builtin_traits.hh | 64 ++--- value/gray.hh | 420 +++++++++++++++++++++++++++++++++ value/gray_level.hh | 360 ++++++++++++++++++++++++++++ value/mlc_extra.hh | 76 +++++ 37 files changed, 1913 insertions(+), 227 deletions(-) Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 973) +++ oln/core/2d/image2d_b.hh (working copy) @@ -89,8 +89,7 @@ typedef internal::plain_primitive_image_<current> super; typedef array2d_<T, int> array_t; public: - //FIXME (fast image concept??) - typedef typename vtypes< image2d_b<T> >::fiter fiter; + typedef stc_type(current, fiter) fiter; stc_using(data); image2d_b(); Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 973) +++ oln/core/equipment.hh (working copy) @@ -83,7 +83,12 @@ # define oln_dim(T) oln_typename_shortcut__(T, dim) # define oln_dpoint(T) oln_typename_shortcut__(T, dpoint) + // e + stc_decl_associated_type( encoding ); +# define oln_encoding(T) oln_typename_shortcut__(T, encoding) + // f + stc_decl_associated_type( fiter ); stc_decl_associated_type( fwd_niter ); stc_decl_associated_type( fwd_piter ); stc_decl_associated_type( fwd_qiter ); @@ -108,6 +113,7 @@ // n stc_decl_associated_type( n ); stc_decl_associated_type( nbh ); + stc_decl_associated_type( nbits ); stc_decl_associated_type( niter ); # define oln_niter(T) oln_typename_shortcut__(T, niter) Index: oln/core/3d/image3d_b.hh --- oln/core/3d/image3d_b.hh (revision 973) +++ oln/core/3d/image3d_b.hh (working copy) @@ -88,8 +88,7 @@ typedef internal::plain_primitive_image_<current> super; typedef array3d_<T, int> array_t; public: - //FIXME (fast image concept??) - typedef typename vtypes< image3d_b<T> >::fiter fiter; + typedef stc_type(current, fiter) fiter; stc_using(data); image3d_b(); Index: oln/core/gen/extended_by.hh --- oln/core/gen/extended_by.hh (revision 973) +++ oln/core/gen/extended_by.hh (working copy) @@ -46,11 +46,13 @@ { oln_decl_op_image_extended_by_const(Neighborhood); + oln_decl_op_image_extended_by_mutable(Neighborhood); # ifndef OLN_INCLUDE_ONLY oln_def_op_image_extended_by_const(Neighborhood); + oln_def_op_image_extended_by_mutable(Neighborhood); # endif // ! OLN_INCLUDE_ONLY Index: oln/core/gen/inplace.hh --- oln/core/gen/inplace.hh (revision 973) +++ oln/core/gen/inplace.hh (working copy) @@ -62,6 +62,13 @@ inplace(inplace_<I> ima); + namespace ERROR + { + + struct keyword_inplace_is_missing; + + } // end of namespace oln::ERROR + # ifndef OLN_INCLUDE_ONLY Index: oln/core/gen/value.hh --- oln/core/gen/value.hh (revision 973) +++ oln/core/gen/value.hh (working copy) @@ -79,6 +79,8 @@ template <typename U> operator value_<U>() const; + const T& unwrap() const; + private: T val_; }; @@ -146,14 +148,25 @@ } template <typename T> - value_<T> make_value(const T& val) + const T& + value_<T>::unwrap() const + { + return this->val_; + } + + // make_value + + template <typename T> + value_<T> + make_value(const T& val) { value_<T> tmp = val; return tmp; } template <typename T> - value_<T> make_value(const value_<T>& val) + value_<T> + make_value(const value_<T>& val) { return val; } Index: oln/core/gen/zero.hh --- oln/core/gen/zero.hh (revision 973) +++ oln/core/gen/zero.hh (working copy) @@ -34,17 +34,17 @@ namespace oln { - struct zero_t : public Literal< zero_t > - { + struct zero_t; - template <typename T> - operator T() const; - // builtins: - operator unsigned() const; - operator int() const; - operator float() const; - operator double() const; + void assignment_(int& i, const zero_t&) { i = 0; } + void assignment_(unsigned& u, const zero_t&) { u = 0u; } + void assignment_(float& f, const zero_t&) { f = 0.f; } + void assignment_(double& d, const zero_t&) { d = 0.; } + + + struct zero_t : public Literal< zero_t > + { } zero; @@ -62,21 +62,6 @@ # ifndef OLN_INCLUDE_ONLY template <typename T> - zero_t::operator T() const - { - mlc::assert_< mlc_is_a(T, Any) >::check(); // FIXME: Add err msg. - T tmp; - tmp.assign_(*this); - return tmp; - } - - zero_t::operator unsigned() const { return 0u; } - zero_t::operator int() const { return 0; } - zero_t::operator float() const { return 0.f; } - zero_t::operator double() const { return 0.; } - - - template <typename T> T operator - (const Any<T>& rhs) { Index: oln/core/concept/literal.hh --- oln/core/concept/literal.hh (revision 973) +++ oln/core/concept/literal.hh (working copy) @@ -40,6 +40,10 @@ struct Literal : public Any<Exact> { typedef Literal<void> category; + + template <typename T> + operator T() const; // NEW + protected: Literal(); }; @@ -64,6 +68,15 @@ { } + template <typename Exact> + template <typename T> + Literal<Exact>::operator T() const + { + T tmp; + assignment_(tmp, exact(*this)); + return tmp; + } + template <typename L, typename R> oln_minus_trait(R, R) operator - (const Literal<L>& lhs, const Any<R>& rhs) Index: oln/core/concept/dpoint.hh --- oln/core/concept/dpoint.hh (revision 973) +++ oln/core/concept/dpoint.hh (working copy) @@ -30,6 +30,7 @@ # define OLN_CORE_CONCEPT_DPOINT_HH # include <oln/core/concept/point.hh> +# include <xtd/vec.hh> @@ -192,7 +193,13 @@ template <typename D, typename D2> D& operator %= (Dpoint<D>& lhs, const Dpoint<D2>& rhs) { - exact(lhs).vec() %= exact(rhs).vec(); + // FIXME: Check that D::n = D2::n + for (unsigned i = 0; i < D::n; ++i) + { + exact(lhs)[i] %= exact(rhs)[i]; + if (exact(lhs)[i] < 0) + exact(lhs)[i] += exact(rhs)[i]; + } return exact(lhs); } Index: oln/core/concept/value.hh --- oln/core/concept/value.hh (revision 973) +++ oln/core/concept/value.hh (working copy) @@ -44,21 +44,6 @@ Value(); }; - /// Concept-class "Boolean". - - template <typename Exact> - struct Boolean : public Value<Exact> - { - protected: - Boolean(); - }; - - template <> - struct vtypes< bool > // FIXME: single_vtype? or move elsewhere? - { - typedef stc::is<Boolean> category; - }; - # ifndef OLN_INCLUDE_ONLY @@ -69,13 +54,6 @@ { } - // Boolean. - - template <typename Exact> - Boolean<Exact>::Boolean() - { - } - # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/operators.hh --- oln/core/concept/operators.hh (revision 973) +++ oln/core/concept/operators.hh (working copy) @@ -31,6 +31,7 @@ # include <oln/core/equipment.hh> # include <oln/core/gen/traits.hh> # include <oln/core/gen/value.hh> +# include <oln/core/internal/macros_ops.hh> namespace oln @@ -61,7 +62,7 @@ template <typename T> T - operator - (const Any<T>& lhs, const Any<T>& rhs); // Using "+=". + operator - (const Any<T>& lhs, const Any<T>& rhs); // Using "-=". template <typename T> T @@ -69,6 +70,13 @@ + // With builtin: + + oln_def_cmp_ops_with_builtin(int); + oln_def_cmp_ops_with_builtin(float); + oln_def_cmp_ops_with_builtin(double); + + namespace ERROR { @@ -120,6 +128,43 @@ + // FIXME: Just a try. + + // The result of "a builtin Op any type" is just like + // the commuted operation, that is, "any type Op a builtin". + // As a consequence, we never have to handle the case of a builtin + // being the lhs operand. + + template <typename T> + oln_plus_trait(T, int) + operator+ (int lhs, const Any<T>& rhs) + { + return exact(rhs) + lhs; + } + + template <typename T> + oln_times_trait(T, int) + operator* (int lhs, const Any<T>& rhs) + { + return exact(rhs) * lhs; + } + + template <typename T> + oln_times_trait(T, float) + operator* (float lhs, const Any<T>& rhs) + { + return exact(rhs) * lhs; + } + + template <typename T> + oln_times_trait(T, double) + operator* (double lhs, const Any<T>& rhs) + { + return exact(rhs) * lhs; + } + + // FIXME: end of "Just a try". + # ifndef OLN_INCLUDE_ONLY @@ -175,7 +220,7 @@ // Operator =. template <typename L, typename R> - void operator = (const Any<L>& lhs, const Any<R>& rhs) + void operator = (const Any<L>&, const Any<R>&) { mlc::abort_<L, typename ERROR::operator_< eq_id >::_is_missing_for_types_<L, R> @@ -184,7 +229,7 @@ // Operator <. template <typename L, typename R> - void operator < (const Any<L>& lhs, const Any<R>& rhs) + void operator < (const Any<L>&, const Any<R>&) { mlc::abort_<L, typename ERROR::operator_< less_id >::template _is_missing_for_types_<L, R> @@ -193,7 +238,7 @@ // Operator +=. template <typename L, typename R> - void operator += (const Any<L>& lhs, const Any<R>& rhs) + void operator += (const Any<L>&, const Any<R>&) { mlc::abort_<L, typename ERROR::operator_< plus_equal_id >::template _is_missing_for_types_<L, R> @@ -202,7 +247,7 @@ // Operator -=. template <typename L, typename R> - void operator -= (const Any<L>& lhs, const Any<R>& rhs) + void operator -= (const Any<L>&, const Any<R>&) { mlc::abort_<L, typename ERROR::operator_< minus_equal_id >::template _is_missing_for_types_<L, R> @@ -211,7 +256,7 @@ // Operator %=. template <typename L, typename R> - void operator %= (const Any<L>& lhs, const Any<R>& rhs) + void operator %= (const Any<L>&, const Any<R>&) { mlc::abort_<L, typename ERROR::operator_< modulus_equal_id >::template _is_missing_for_types_<L, R> @@ -220,7 +265,7 @@ // Operator -. template <typename T> - void operator - (const Any<T>& rhs) + void operator - (const Any<T>&) { mlc::abort_<T, typename ERROR::operator_< uminus_id >::template _is_missing_for_<T> Index: oln/core/internal/dpoint_base.hh --- oln/core/internal/dpoint_base.hh (revision 973) +++ oln/core/internal/dpoint_base.hh (working copy) @@ -85,8 +85,6 @@ coord operator[](unsigned i) const; coord& operator[](unsigned i); - Exact& impl_op_mod_equal_(const Exact& rhs); // FIXME: Remove HERE - typedef xtd::vec<n, coord> vec_t; const vec_t& vec() const; vec_t& vec(); @@ -118,18 +116,6 @@ } template <typename Exact> - Exact& dpoint_base_<Exact>::impl_op_mod_equal_(const Exact& rhs) - { - for (unsigned i = 0; i < n; ++i) - { - v_[i] %= rhs.v_[i]; - if (v_[i] < 0) - v_[i] += rhs.v_[i]; - } - return exact(*this); - } - - template <typename Exact> const typename dpoint_base_<Exact>::vec_t& dpoint_base_<Exact>::vec() const { Index: oln/core/internal/f_grid_coord_to_point.hh --- oln/core/internal/f_grid_coord_to_point.hh (revision 0) +++ oln/core/internal/f_grid_coord_to_point.hh (revision 0) @@ -0,0 +1,111 @@ +// 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. + +#ifndef OLN_CORE_INTERNAL_F_GRID_COORD_TO_POINT_HH +# define OLN_CORE_INTERNAL_F_GRID_COORD_TO_POINT_HH + +# include <oln/core/concept/grid.hh> + + +# define oln_f_grid_coord_to_point(G, C) \ +typename oln::internal::f_grid_coord_to_point_< G, C >::ret + + +namespace oln +{ + + /// \{ + /// Forward declarations. + + // Grid types. + + struct grid1d; + struct grid2d; // FIXME: hex, tri... + struct grid3d; + + // Point types. + + struct point1d; + struct point2d; + struct point3d; + template <typename G, typename C> class point; + + /// \} + + + + namespace internal + { + + template <typename G, typename C> + struct grid_coord_to_point__; + + + /// \{ + /// Definitions. + + template <typename G, typename C> + struct grid_coord_to_point__ + { + typedef oln::point<G, C> ret; + }; + + template <> + struct grid_coord_to_point__< grid1d, int > + { + typedef point1d ret; + }; + + template <> + struct grid_coord_to_point__< grid2d, int > + { + typedef point2d ret; + }; + + // FIXME: 2D hex/tri... + + template <> + struct grid_coord_to_point__< grid3d, int > + { + typedef point3d ret; + }; + + /// \} + + + template <typename G, typename C> + struct f_grid_coord_to_point_ : private mlc::assert_< mlc_is_a(G, Grid) >, + public grid_coord_to_point__< G, C > + { + }; + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_F_GRID_COORD_TO_POINT_HH Index: oln/core/internal/point_impl.hh Index: oln/core/internal/macros_ops.hh --- oln/core/internal/macros_ops.hh (revision 0) +++ oln/core/internal/macros_ops.hh (revision 0) @@ -0,0 +1,77 @@ +// 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. + +#ifndef OLN_CORE_INTERNAL_MACROS_OPS_HH +# define OLN_CORE_INTERNAL_MACROS_OPS_HH + + +# define oln_def_cmp_ops_with_builtin(Builtin) \ + \ + template <typename L> \ + bool operator = (const Any<L>& lhs, Builtin rhs) { return exact(lhs) = make_value(rhs); } \ + \ + template <typename L> \ + bool operator != (const Any<L>& lhs, Builtin rhs) { return not (exact(lhs) = make_value(rhs)); } \ + \ + \ + template <typename L> \ + bool operator = (Builtin lhs, const Any<L>& rhs) { return exact(rhs) = make_value(lhs); } \ + \ + template <typename L> \ + bool operator != (Builtin lhs, const Any<L>& rhs) { return not (exact(rhs) = make_value(lhs)); } \ + \ + \ + template <typename L> \ + bool operator < (const Any<L>& lhs, Builtin rhs) { return exact(lhs) < make_value(rhs); } \ + \ + template <typename L> \ + bool operator > (const Any<L>& lhs, Builtin rhs) { return exact(lhs) > make_value(rhs); } \ + \ + template <typename L> \ + bool operator <= (const Any<L>& lhs, Builtin rhs) { return exact(lhs) <= make_value(rhs); } \ + \ + template <typename L> \ + bool operator >= (const Any<L>& lhs, Builtin rhs) { return exact(lhs) >= make_value(rhs); } \ + \ + \ + template <typename L> \ + bool operator < (Builtin lhs, const Any<L>& rhs) { return exact(rhs) > make_value(lhs); } \ + \ + template <typename L> \ + bool operator > (Builtin lhs, const Any<L>& rhs) { return exact(rhs) < make_value(lhs); } \ + \ + template <typename L> \ + bool operator <= (Builtin lhs, const Any<L>& rhs) { return exact(rhs) >= make_value(lhs); } \ + \ + template <typename L> \ + bool operator >= (Builtin lhs, const Any<L>& rhs) { return exact(rhs) <= make_value(lhs); } \ + \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + +#endif // ! OLN_CORE_INTERNAL_MACROS_OPS_HH Index: oln/core/internal/value_base.hh --- oln/core/internal/value_base.hh (revision 0) +++ oln/core/internal/value_base.hh (revision 0) @@ -0,0 +1,300 @@ +// 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. + +#ifndef OLN_CORE_INTERNAL_VALUE_BASE_HH +# define OLN_CORE_INTERNAL_VALUE_BASE_HH + +# include <oln/core/concept/value.hh> + + +// FIXME: Rename this file as oln/value/internal/value_base.hh? + + +/* + * The base value classes mimics this image hierarchy: + * + * Image + * | + * | + * o -- + -- Gray_Level_Image + * | + * + -- Color_Image + * | + * + -- Label_Image + * | | + * | + -- Binary_Image + * | | + * | + -- String_Image + * | + * + -- Deformation_Field_Image + * | + * + -- Data_Image + */ + + +namespace oln +{ + + /// \{ + /// Fwd decls. + + namespace internal + { + template <typename Exact> class value_base_; + + template <typename Exact> class graylevel_value_; + template <typename Exact> class color_value_; + + template <typename Exact> class label_value_; + template <typename Exact> class boolean_value_; + template <typename Exact> class string_value_; + + template <typename Exact> class data_value_; + } + + /// \} + + + /// \{ + /// Super types. + + template <typename Exact> + struct super_trait_< internal::value_base_<Exact> > + { + typedef Value<Exact> ret; + }; + + template <typename Exact> + struct super_trait_< internal::graylevel_value_<Exact> > + { + typedef internal::value_base_<Exact> ret; + }; + + template <typename Exact> + struct super_trait_< internal::color_value_<Exact> > + { + typedef internal::value_base_<Exact> ret; + }; + + template <typename Exact> + struct super_trait_< internal::label_value_<Exact> > + { + typedef internal::value_base_<Exact> ret; + }; + + template <typename Exact> + struct super_trait_< internal::boolean_value_<Exact> > + { + typedef internal::label_value_<Exact> ret; + }; + + template <typename Exact> + struct super_trait_< internal::string_value_<Exact> > + { + typedef internal::label_value_<Exact> ret; + }; + + template <typename Exact> + struct super_trait_< internal::data_value_<Exact> > + { + typedef internal::value_base_<Exact> ret; + }; + + /// \} + + + /// \{ + /// Virtual types. + + template <typename Exact> + struct vtypes< internal::value_base_<Exact> > + { + typedef stc::abstract encoding; + + // Final: + typedef stc::final< stc::is<Value> > category; + }; + + template <typename Exact> + struct vtypes< internal::graylevel_value_<Exact> > + { + typedef stc::abstract nbits; + }; + + template <typename Exact> + struct vtypes< internal::color_value_<Exact> > + { + }; + + template <typename Exact> + struct vtypes< internal::label_value_<Exact> > + { + typedef stc::abstract nbits; + }; + + template <typename Exact> + struct vtypes< internal::boolean_value_<Exact> > + { + }; + + template <typename Exact> + struct vtypes< internal::string_value_<Exact> > + { + }; + + template <typename Exact> + struct vtypes< internal::data_value_<Exact> > + { + }; + + /// \} + + + + namespace internal + { + + /// Base implementation class for value classes. + + template <typename Exact> + class value_base_ : public Value<Exact> + { + public: + stc_typename(encoding); + + // FIXME: Contents? + protected: + value_base_(); + }; + + + template <typename Exact> + class graylevel_value_ : public value_base_<Exact> + { + public: + // FIXME: Contents? + protected: + graylevel_value_(); + }; + + + template <typename Exact> + class color_value_ : public value_base_<Exact> + { + public: + // FIXME: Contents? + protected: + color_value_(); + }; + + + template <typename Exact> + class label_value_ : public value_base_<Exact> + { + public: + // FIXME: Contents? + protected: + label_value_(); + }; + + + template <typename Exact> + class boolean_value_ : public label_value_<Exact> + { + public: + // FIXME: Contents? + protected: + boolean_value_(); + }; + + + template <typename Exact> + class string_value_ : public label_value_<Exact> + { + public: + // FIXME: Contents? + protected: + string_value_(); + }; + + + template <typename Exact> + class data_value_ : public value_base_<Exact> + { + public: + // FIXME: Contents? + protected: + data_value_(); + }; + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + value_base_<Exact>::value_base_() + { + } + + template <typename Exact> + graylevel_value_<Exact>::graylevel_value_() + { + } + + template <typename Exact> + color_value_<Exact>::color_value_() + { + } + + template <typename Exact> + label_value_<Exact>::label_value_() + { + } + + template <typename Exact> + boolean_value_<Exact>::boolean_value_() + { + } + + template <typename Exact> + string_value_<Exact>::string_value_() + { + } + + template <typename Exact> + data_value_<Exact>::data_value_() + { + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_VALUE_BASE_HH Index: oln/morpho/elementary_gradient.hh --- oln/morpho/elementary_gradient.hh (revision 973) +++ oln/morpho/elementary_gradient.hh (working copy) @@ -76,7 +76,7 @@ elementary_gradient(const Image_with_Nbh<I>& input) { oln_plain(I) output = impl::elementary_gradient_(exact(input)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/morpho/top_hat_black.hh --- oln/morpho/top_hat_black.hh (revision 973) +++ oln/morpho/top_hat_black.hh (working copy) @@ -75,7 +75,7 @@ top_hat_black(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::top_hat_black_(exact(input), exact(win)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/morpho/top_hat_white.hh --- oln/morpho/top_hat_white.hh (revision 973) +++ oln/morpho/top_hat_white.hh (working copy) @@ -74,7 +74,7 @@ top_hat_white(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::top_hat_white_(exact(input), exact(win)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/morpho/thinning.hh --- oln/morpho/thinning.hh (revision 0) +++ oln/morpho/thinning.hh (revision 0) @@ -0,0 +1,141 @@ +// 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. + +#ifndef OLN_MORPHO_THINNING_HH +# define OLN_MORPHO_THINNING_HH + +# include <oln/morpho/erosion.hh> +# include <oln/morpho/dilation.hh> +/* +# include <oln/core/gen/ternary_fun.hh> +# include <oln/core/level/ternary.hh> +# include <oln/arith/ternary.hh> +*/ + + +namespace oln +{ + + namespace morpho + { + + // Fwd decl. + + template <typename I, typename W1, typename W2> + oln_plain(I) + thinning(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I, typename W1, typename W2> + oln_plain(I) + thinning_on_function_(const Image<I>& f, + const Window<W1>& B1, const Window<W2>& B2) + { + oln_plain(I) + e = morpho::erosion(f, B1), + d = morpho::dilation(f, B2); + + /* + oln_plain_value(I, bool) t; + t = d < f and f = e; + return level::ternary(t, d, f); + */ + + /* + oln_plain(I) o; + prepare(o, with, f); + level::fill( inplace(o), + ternary_fun( pw_value(d) < pw_value(f) and pw_value(f) = pw_value(e), + pw_value(d), + pw_value(f) ) ); + return o; + */ + + oln_plain(I) o; + prepare(o, with, f); + oln_piter(I) p(f.points()); + for_all(p) + o(p) = ( d(p) < f(p) and f(p) = e(p) + ? d(p) + : f(p) ); + return o; + } + + // FIXME: Add a fast version. + + + // Impl facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + thinning_(const Image<I>& input, + const W1& B1, const W2& B2) + { + return thinning_on_function_(exact(input), B1, B2); + } + +// template <typename I, typename W1, typename W2> +// oln_plain(I) +// thinning_(const Binary_Image<I>& input, +// const W1& B1, const W2& B2) +// { +// return thinning_on_set_(exact(input), B1, B2); +// } + + + } // end of namespace oln::morpho::impl + + + // Facade. + + template <typename I, typename W1, typename W2> + oln_plain(I) + thinning(const Image<I>& input, + const Window<W1>& B1, const Window<W2>& B2) + { + precondition(B1.is_centered()); + oln_plain(I) output = impl::thinning_(exact(input), exact(B1), exact(B2)); + postcondition(output <= input); + return output; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::morpho + +} // end of namespace oln + + +#endif // ! OLN_MORPHO_THINNING_HH Index: oln/morpho/elementary_gradient_internal.hh --- oln/morpho/elementary_gradient_internal.hh (revision 973) +++ oln/morpho/elementary_gradient_internal.hh (working copy) @@ -74,7 +74,7 @@ elementary_gradient_internal(const Image_with_Nbh<I>& input) { oln_plain(I) output = impl::elementary_gradient_internal_(exact(input)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/morpho/elementary_gradient_external.hh --- oln/morpho/elementary_gradient_external.hh (revision 973) +++ oln/morpho/elementary_gradient_external.hh (working copy) @@ -74,7 +74,7 @@ elementary_gradient_external(const Image_with_Nbh<I>& input) { oln_plain(I) output = impl::elementary_gradient_external_(exact(input)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/morpho/gradient_internal.hh --- oln/morpho/gradient_internal.hh (revision 973) +++ oln/morpho/gradient_internal.hh (working copy) @@ -73,7 +73,7 @@ gradient_internal(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::gradient_internal_(exact(input), exact(win)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/morpho/gradient.hh --- oln/morpho/gradient.hh (revision 973) +++ oln/morpho/gradient.hh (working copy) @@ -74,7 +74,7 @@ gradient(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::gradient_(exact(input), exact(win)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/morpho/gradient_external.hh --- oln/morpho/gradient_external.hh (revision 973) +++ oln/morpho/gradient_external.hh (working copy) @@ -72,7 +72,7 @@ gradient_external(const Image<I>& input, const Window<W>& win) { oln_plain(I) output = impl::gradient_external_(exact(input), exact(win)); - postcondition(output >= zero); + postcondition(output >= oln_value(I)(zero)); return output; } Index: oln/arith/plus.hh --- oln/arith/plus.hh (revision 973) +++ oln/arith/plus.hh (working copy) @@ -94,7 +94,7 @@ precondition(lhs.points() = rhs.points()); oln_plain_value(I, V) output; prepare(output, with, lhs); - level::fill(output, + level::fill(inplace(output), value_cast<V>(pw_value(lhs) + pw_value(rhs))); return output; } Index: oln/arith/minus.hh --- oln/arith/minus.hh (revision 973) +++ oln/arith/minus.hh (working copy) @@ -90,7 +90,7 @@ precondition(lhs.points() = rhs.points()); oln_plain_value(I, V) output; prepare(output, with, lhs); - level::fill(output, + level::fill(inplace(output), value_cast<V>(pw_value(lhs) - pw_value(rhs))); return output; } Index: oln/level/local_sup.hh --- oln/level/local_sup.hh (revision 973) +++ oln/level/local_sup.hh (working copy) @@ -68,7 +68,7 @@ const oln_point(I)& p) { f.init_with(input(p)); - oln_niter(I) n(input, p); + oln_niter(I) n(p, input); for_all(n) if (n > p) f(input(n)); @@ -86,7 +86,7 @@ f.init_with(input(p)); if (f.value() = true) return true; - oln_niter(I) n(input, p); + oln_niter(I) n(p, input); for_all(n) if (n > p) { @@ -106,7 +106,7 @@ const oln_point(I)& p) { f.init_with(input(p)); - oln_niter(I) n(input, p); + oln_niter(I) n(p, input); for_all(n) if (n > p) { Index: oln/level/fill.hh --- oln/level/fill.hh (revision 973) +++ oln/level/fill.hh (working copy) @@ -153,7 +153,8 @@ template <typename I, typename T> void fill(const Image<I>&, const T&) { - mlc::abort_<I>::check(); // FIXME: Add err msg. + mlc::abort_< I, + ERROR::keyword_inplace_is_missing >::check(); } # endif // ! OLN_INCLUDE_ONLY Index: oln/level/compare.hh --- oln/level/compare.hh (revision 973) +++ oln/level/compare.hh (working copy) @@ -30,11 +30,11 @@ # include <oln/core/concept/image.hh> # include <oln/core/gen/pset_compare.hh> +# include <oln/core/gen/value.hh> // FIXME: Rename this file as "comparison.hh". - namespace oln { @@ -43,20 +43,29 @@ template <typename L, typename R> bool operator = (const Image<L>& lhs, const Image<R>& rhs); - template <typename I> - bool operator = (const Image<I>& lhs, const oln_value(I)& val); - template <typename L, typename R> bool operator < (const Image<L>& lhs, const Image<R>& rhs); - template <typename I> - bool operator < (const Image<I>& lhs, const oln_value(I)& val); - - template <typename L, typename R> + template <typename L, typename R> // required! bool operator <= (const Image<L>& lhs, const Image<R>& rhs); - template <typename I> - bool operator <= (const Image<I>& lhs, const oln_value(I)& val); + + // with a value: + + template <typename I, typename V> + bool operator = (const Image<I>& lhs, const value_<V>& val); + + template <typename I, typename V> + bool operator < (const Image<I>& lhs, const value_<V>& val); + + template <typename I, typename V> + bool operator <= (const Image<I>& lhs, const value_<V>& val); + + template <typename I, typename V> + bool operator > (const Image<I>& lhs, const value_<V>& val); + + template <typename I, typename V> + bool operator >= (const Image<I>& lhs, const value_<V>& val); // FIXME: is-it a good idea to have "ima = lit"? @@ -74,98 +83,109 @@ // Generic version. template <typename L, typename R> - bool op_eq_(const Image<L>& lhs, const Image<R>& rhs) + bool operator_equal_(const Image<L>& lhs, const Image<R>& rhs) { - precondition(lhs.points() = rhs.points()); oln_piter(L) p(lhs.points()); for_all(p) - if (lhs(p) != rhs(p)) + if (not (lhs(p) = rhs(p))) return false; return true; } - // Image I = Value V - // ---------------------- + // Image L < Image R + // --------------------- // Generic version. - template <typename I> - bool op_eq_(const Image<I>& lhs, const oln_value(I)& val) + template <typename L, typename R> + bool operator_less_(const Image<L>& lhs, const Image<R>& rhs) { - oln_piter(I) p(lhs.points()); + oln_piter(L) p(lhs.points()); for_all(p) - if (lhs(p) != val) + if (not (lhs(p) < rhs(p))) return false; return true; } - // Image L < Image R - // --------------------- + // Image L <= Image R + // ---------------------- // Generic version. template <typename L, typename R> - bool op_less_(const Image<L>& lhs, const Image<R>& rhs) + bool operator_less_or_equal_(const Image<L>& lhs, const Image<R>& rhs) { - precondition(lhs.points() = rhs.points()); oln_piter(L) p(lhs.points()); for_all(p) - if (lhs(p) >= rhs(p)) + if (not (lhs(p) <= rhs(p))) return false; return true; } - // Image I < Value V - // --------------------- + // Image I = Value V + // ---------------------- // Generic version. template <typename I> - bool op_less_(const Image<I>& lhs, const oln_value(I)& val) + bool operator_image_equal_to_value_(const Image<I>& lhs, + const oln_value(I)& val) { oln_piter(I) p(lhs.points()); for_all(p) - if (lhs(p) >= val) + if (not (lhs(p) = val)) return false; return true; } - // Image L <= Image R - // ---------------------- + // Image I cmp Value V + // ----------------------- - // Generic version. + // Generic versions. - template <typename L, typename R> - bool op_leq_(const Image<L>& lhs, const Image<R>& rhs) + template <typename I> + bool operator_image_less_than_value_(const Image<I>& lhs, const oln_value(I)& val) { - precondition(lhs.points() = rhs.points()); - oln_piter(L) p(lhs.points()); + oln_piter(I) p(lhs.points()); for_all(p) - if (lhs(p) > rhs(p)) + if (not (lhs(p) < val)) return false; return true; } - - // Image I <= Value V - // ---------------------- - - // Generic version. + template <typename I> + bool operator_image_less_or_equal_than_value_(const Image<I>& lhs, const oln_value(I)& val) + { + oln_piter(I) p(lhs.points()); + for_all(p) + if (not (lhs(p) <= val)) + return false; + return true; + } template <typename I> - bool op_leq_(const Image<I>& lhs, const oln_value(I)& val) + bool operator_image_greater_than_value_(const Image<I>& lhs, const oln_value(I)& val) { oln_piter(I) p(lhs.points()); for_all(p) - if (lhs(p) > val) + if (not (lhs(p) > val)) return false; return true; } + template <typename I> + bool operator_image_greater_or_equal_than_value_(const Image<I>& lhs, const oln_value(I)& val) + { + oln_piter(I) p(lhs.points()); + for_all(p) + if (not (lhs(p) >= val)) + return false; + return true; + } } // end of namespace oln::level::impl @@ -176,39 +196,62 @@ bool operator = (const Image<L>& lhs, const Image<R>& rhs) { assert_same_grid_<L, R>::check(); - return impl::op_eq_(exact(lhs), exact(rhs)); + precondition(lhs.points() = rhs.points()); + return impl::operator_equal_(exact(lhs), exact(rhs)); } - template <typename I> - bool operator = (const Image<I>& lhs, const oln_value(I)& val) + template <typename L, typename R> + bool operator < (const Image<L>& lhs, const Image<R>& rhs) { - return impl::op_eq_(exact(lhs), val); + assert_same_grid_<L, R>::check(); + precondition(lhs.points() = rhs.points()); + return impl::operator_less_(exact(lhs), exact(rhs)); } template <typename L, typename R> - bool operator < (const Image<L>& lhs, const Image<R>& rhs) + bool operator <= (const Image<L>& lhs, const Image<R>& rhs) { assert_same_grid_<L, R>::check(); - return impl::op_less_(exact(lhs), exact(rhs)); + precondition(lhs.points() = rhs.points()); + return impl::operator_less_or_equal_(exact(lhs), exact(rhs)); } - template <typename I> - bool operator < (const Image<I>& lhs, const oln_value(I)& val) + + // with a value: + + template <typename I, typename V> + bool operator = (const Image<I>& lhs, const value_<V>& val) { - return impl::op_less_(exact(lhs), val); + // FIXME: insert static assertion? + return impl::operator_image_equal_to_value_(exact(lhs), val.unwrap()); } - template <typename L, typename R> - bool operator <= (const Image<L>& lhs, const Image<R>& rhs) + template <typename I, typename V> + bool operator < (const Image<I>& lhs, const value_<V>& val) { - assert_same_grid_<L, R>::check(); - return impl::op_leq_(exact(lhs), exact(rhs)); + // FIXME: insert static assertion? + return impl::operator_image_less_than_value_(exact(lhs), val.unwrap()); } - template <typename I> - bool operator <= (const Image<I>& lhs, const oln_value(I)& val) + template <typename I, typename V> + bool operator <= (const Image<I>& lhs, const value_<V>& val) + { + // FIXME: insert static assertion? + return impl::operator_image_less_or_equal_than_value_(exact(lhs), val.unwrap()); + } + + template <typename I, typename V> + bool operator > (const Image<I>& lhs, const value_<V>& val) + { + // FIXME: insert static assertion? + return impl::operator_image_greater_than_value_(exact(lhs), val.unwrap()); + } + + template <typename I, typename V> + bool operator >= (const Image<I>& lhs, const value_<V>& val) { - return impl::op_leq_(exact(lhs), val); + // FIXME: insert static assertion? + return impl::operator_image_greater_or_equal_than_value_(exact(lhs), val.unwrap()); } # endif // ! OLN_INCLUDE_ONLY Index: oln/level/local_inf.hh --- oln/level/local_inf.hh (revision 973) +++ oln/level/local_inf.hh (working copy) @@ -68,7 +68,7 @@ const oln_point(I)& p) { f.init_with(input(p)); - oln_niter(I) n(input, p); + oln_niter(I) n(p, input); for_all(n) if (n < p) f(input(n)); @@ -86,7 +86,7 @@ f.init_with(input(p)); if (f.value() = true) return true; - oln_niter(I) n(input, p); + oln_niter(I) n(p, input); for_all(n) if (n < p) { @@ -106,7 +106,7 @@ const oln_point(I)& p) { f.init_with(input(p)); - oln_niter(I) n(input, p); + oln_niter(I) n(p, input); for_all(n) if (n < p) { Index: oln/value/gray_level.hh --- oln/value/gray_level.hh (revision 0) +++ oln/value/gray_level.hh (revision 0) @@ -0,0 +1,360 @@ +// Copyright (C) 2006, 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. + +#ifndef OLN_VALUE_GRAY_LEVEL_HH +# define OLN_VALUE_GRAY_LEVEL_HH + +# include <iostream> +# include <oln/core/concept/operators.hh> +# include <oln/core/internal/value_base.hh> +# include <mlc/int.hh> + + +// FIXME: Move! +# include <oln/value/mlc_extra.hh> + + +namespace oln +{ + + namespace value + { + + namespace internal + { + + template <typename T> T format(T t) { return t; } + unsigned format(unsigned char t) { return t; } + + + template <unsigned nbits> struct encoding_; + + template <> struct encoding_ <1> { typedef bool ret; }; + + template <> struct encoding_ <2> { typedef unsigned char ret; }; + template <> struct encoding_ <3> { typedef unsigned char ret; }; + template <> struct encoding_ <4> { typedef unsigned char ret; }; + template <> struct encoding_ <5> { typedef unsigned char ret; }; + template <> struct encoding_ <6> { typedef unsigned char ret; }; + template <> struct encoding_ <7> { typedef unsigned char ret; }; + template <> struct encoding_ <8> { typedef unsigned char ret; }; + + template <> struct encoding_ < 9> { typedef unsigned short ret; }; + template <> struct encoding_ <10> { typedef unsigned short ret; }; + template <> struct encoding_ <11> { typedef unsigned short ret; }; + template <> struct encoding_ <12> { typedef unsigned short ret; }; + template <> struct encoding_ <13> { typedef unsigned short ret; }; + template <> struct encoding_ <14> { typedef unsigned short ret; }; + template <> struct encoding_ <15> { typedef unsigned short ret; }; + template <> struct encoding_ <16> { typedef unsigned short ret; }; + + template <> struct encoding_ <32> { typedef unsigned long ret; }; + + } // end of oln::value::internal + + + // Fwd decls. + template <unsigned N> class gray_level; + class gray; + + + } // end of namespace oln::value + + + /// \{ + /// Aliases. + + typedef value::gray_level<8> gl8; + typedef value::gray_level<16> gl16; + typedef value::gray_level<32> gl32; + + /// \} + + +# define current gray_level<N> +# define super oln::internal::graylevel_value_< oln::value::current > + + // Super type. + + template <unsigned N> + struct super_trait_< value::current > + { + typedef super ret; + }; + + // Virtual types. + + template <unsigned N> + struct vtypes< value::current > + { + typedef typename value::internal::encoding_<N>::ret encoding; + typedef mlc::uint_<N> nbits; + }; + + + namespace value + { + + /// General gray-level class on n bits. + template <unsigned N> + class gray_level : public super + { + public: + stc_using(encoding); + + // Ctors. + gray_level(); + + // In oln/value/gray.hh: + gray_level(const gray& g); + gray_level<N>& operator=(const gray& val); + operator gray() const; + + // Access to encoding value. + const encoding& enc() const; + encoding& enc(); + + // Conversions. + operator float() const; + operator double() const; + + protected: + encoding val_; + }; + + + // Op<<. + template <unsigned N> + std::ostream& operator<<(std::ostream& ostr, const gray_level<N>& g); + + + template <unsigned N> + bool operator=(const gray_level<N>& lhs, const gray_level<N>& rhs); + + template <unsigned N, unsigned M> + bool operator=(const gray_level<N>& lhs, const gray_level<M>& rhs); + + + template <unsigned N> + bool operator<(const gray_level<N>& lhs, const gray_level<N>& rhs); + + template <unsigned N, unsigned M> + bool operator<(const gray_level<N>& lhs, const gray_level<M>& rhs); + + + // -> gray + + template <unsigned N, unsigned M> + gray operator+(const gray_level<N>& lhs, const gray_level<M>& rhs); + + template <unsigned N, unsigned M> + gray operator-(const gray_level<N>& lhs, const gray_level<M>& rhs); + + template <unsigned N> + gray operator*(int s, const gray_level<N>& rhs); + + template <unsigned N> + gray operator*(const gray_level<N>& lhs, int s); + + template <unsigned N> + gray operator/(const gray_level<N>& lhs, int s); + + + + +# ifndef OLN_INCLUDE_ONLY + + template <unsigned N> + current::gray_level() + { + } + + template <unsigned N> + const typename current::encoding& + current::enc() const + { + return this->val_; + } + + template <unsigned N> + typename current::encoding& + current::enc() + { + return this->val_; + } + + template <unsigned N> + current:: operator float() const + { + static const float coef_ + = 1.f / float(mlc::math::two_pow_<N>::value - 1.f); + return coef_ * this->val_; + } + + template <unsigned N> + current::operator double() const + { + static const double coef_ + = 1. / double(mlc::math::two_pow_<N>::value - 1.); + return coef_ * this->val_; + } + + template <unsigned N> + std::ostream& operator<<(std::ostream& ostr, const gray_level<N>& g) + { + return ostr << internal::format( g.enc() ) + << "[/" << N << ']'; + } + + + template <unsigned N> + bool operator=(const gray_level<N>& lhs, const gray_level<N>& rhs) + { + return lhs.enc() = rhs.enc(); + } + + template <unsigned N, unsigned M> + bool operator=(const gray_level<N>& lhs, const gray_level<M>& rhs) + { + return + mlc::math::two_pow_<M>::value * lhs.enc() + = mlc::math::two_pow_<N>::value * rhs.enc(); + // FIXME: return gray(lhs) = gray(rhs); + } + + + template <unsigned N> + bool operator<(const gray_level<N>& lhs, const gray_level<N>& rhs) + { + return lhs.enc() < rhs.enc(); + } + + template <unsigned N, unsigned M> + bool operator<(const gray_level<N>& lhs, const gray_level<M>& rhs) + { + return + mlc::math::two_pow_<M>::value * lhs.enc() + < mlc::math::two_pow_<N>::value * rhs.enc(); + // FIXME: return gray(lhs) < gray(rhs); + } + + /* + + template <unsigned N> + gray_level<N>::operator gray() const + { + gray tmp(N, this->val_); + return tmp; + } + + template <unsigned N, unsigned M> + gray operator+(const gray_level<N>& lhs, const gray_level<M>& rhs) + { + return gray(lhs) + gray(rhs); + } + + template <unsigned N, unsigned M> + gray operator-(const gray_level<N>& lhs, const gray_level<M>& rhs) + { + return gray(lhs) - gray(rhs); + } + + template <unsigned N> + gray operator*(int s, const gray_level<N>& rhs) + { + precondition(s >= 0); + gray tmp(N, s * rhs.enc()); + return tmp; + } + + template <unsigned N> + gray operator*(const gray_level<N>& lhs, int s) + { + precondition(s >= 0); + gray tmp(N, lhs.enc() * s); + return tmp; + } + + template <unsigned N> + gray operator/(const gray_level<N>& lhs, int s) + { + precondition(s > 0); + gray tmp(N, lhs.enc() / s); + return tmp; + } + + */ + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::value + +# undef super +# undef current + +} // end of namespace oln + + +/* + +namespace xtd +{ + + using oln::value::gray; + + template <> struct set_trait_<op_plus, gray, gray> { typedef gray ret; }; + template <> struct set_trait_<op_minus, gray, gray> { typedef gray ret; }; + template <> struct set_trait_<op_mult, int, gray> { typedef gray ret; }; + template <> struct set_trait_<op_mult, gray, int > { typedef gray ret; }; + template <> struct set_trait_<op_div, gray, int > { typedef gray ret; }; + + using oln::value::gray_level; + + template <unsigned N, unsigned M> + struct set_trait_< op_plus, gray_level<N>, gray_level<M> > { typedef gray ret; }; + + template <unsigned N, unsigned M> + struct set_trait_< op_minus, gray_level<N>, gray_level<M> > { typedef gray ret; }; + + template <unsigned N> + struct set_trait_< op_mult, int, gray_level<N> > { typedef gray ret; }; + + template <unsigned N> + struct set_trait_< op_mult, gray_level<N>, int > { typedef gray ret; }; + + template <unsigned N> + struct set_trait_< op_div, gray_level<N>, int > { typedef gray ret; }; + +} // end of namespace xtd + +*/ + + +# include <oln/value/gray.hh> + + +#endif // ! OLN_VALUE_GRAY_LEVEL_HH Index: oln/value/bool.hh --- oln/value/bool.hh (revision 0) +++ oln/value/bool.hh (revision 0) @@ -0,0 +1,55 @@ +// 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. + +#ifndef OLN_VALUE_BOOL_HH +# define OLN_VALUE_BOOL_HH + +# include <oln/core/internal/value_base.hh> + + +namespace oln +{ + + // Super type. + template<> + struct super_trait_< bool > + { + typedef internal::boolean_value_< bool > ret; + }; + + // Virtual types. + template <> + struct vtypes< bool > + { + typedef bool encoding; + // FIXME: ... + }; + +} // end of namespace oln + + +#endif // ! OLN_VALUE_BOOL_HH Index: oln/value/builtin_traits.hh --- oln/value/builtin_traits.hh (revision 973) +++ oln/value/builtin_traits.hh (working copy) @@ -32,45 +32,41 @@ # include <oln/core/gen/traits.hh> -namespace oln -{ - - template <typename Op> - struct set_trait_< Value, int, Op, Value, float > - { - typedef float ret; - }; +# define oln_decl_builtin_binary_trait(T1, T2, R) \ + \ + template <typename Op> \ + struct set_trait_< Value, T1, Op, Value, T2 > { typedef R ret; }; \ + \ + template <typename Op> \ + struct set_trait_< Value, T2, Op, Value, T1 > { typedef R ret; }; \ + \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n - template <typename Op> - struct set_trait_< Value, double, Op, Value, double > - { - typedef double ret; - }; - template <typename Op> - struct set_trait_< Value, int, Op, Value, double > - { - typedef double ret; - }; - - template <typename Op> - struct set_trait_< Value, float, Op, Value, int > +namespace oln { - typedef float ret; - }; + oln_decl_builtin_binary_trait(unsigned char, float, float); + oln_decl_builtin_binary_trait(unsigned short, float, float); + oln_decl_builtin_binary_trait(unsigned int, float, float); + oln_decl_builtin_binary_trait(unsigned long, float, float); + + oln_decl_builtin_binary_trait(signed char, float, float); + oln_decl_builtin_binary_trait(signed short, float, float); + oln_decl_builtin_binary_trait(signed int, float, float); + oln_decl_builtin_binary_trait(signed long, float, float); + + oln_decl_builtin_binary_trait(unsigned char, double, double); + oln_decl_builtin_binary_trait(unsigned short, double, double); + oln_decl_builtin_binary_trait(unsigned int, double, double); + oln_decl_builtin_binary_trait(unsigned long, double, double); + + oln_decl_builtin_binary_trait(signed char, double, double); + oln_decl_builtin_binary_trait(signed short, double, double); + oln_decl_builtin_binary_trait(signed int, double, double); + oln_decl_builtin_binary_trait(signed long, double, double); - template <typename Op> - struct set_trait_< Value, bool, Op, Value, bool > - { - typedef bool ret; - }; - - template <typename Op> - struct set_utrait_< Op, Boolean, bool > - { - typedef bool ret; - }; + oln_decl_builtin_binary_trait(float, double, double); // FIXME: To be continued... Index: oln/value/gray.hh --- oln/value/gray.hh (revision 0) +++ oln/value/gray.hh (revision 0) @@ -0,0 +1,420 @@ +// Copyright (C) 2006, 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. + +#ifndef OLN_VALUE_GRAY_HH +# define OLN_VALUE_GRAY_HH + +# include <iostream> +# include <oln/value/gray_level.hh> + + + +namespace oln +{ + + // Fwd decls. + namespace value + { + template <unsigned N> class gray_level; + class gray; + } + + // Super type. + + template <> + struct super_trait_< value::gray > + { + typedef oln::internal::graylevel_value_< value::gray > ret; + }; + + // Virtual types. + + template <> + struct vtypes< value::gray > + { + typedef unsigned long encoding; // FIXME: std::pair? + typedef mlc::uint_<0> nbits; // FIXME: means unknown? + }; + + + namespace value + { + + + /// General gray-level class where n bits is not know at compile-time. + /// This class is used for exchange between gray-level types purpose. + + class gray : public oln::internal::graylevel_value_< gray > + { + public: + + /// Ctor. + gray(); + + /// Ctor. + template <unsigned N> + gray(const gray_level<N>& val); + + /// Ctor. + gray(unsigned nbits, unsigned long val); + + /// Access to std type. + unsigned long value() const; + + unsigned nbits() const; + + void set_nbits(unsigned nbits); + + gray to_nbits(unsigned nbits) const; + + template <unsigned N> + operator gray_level<N>() const; + + protected: + unsigned nbits_; + unsigned long val_; + }; + + + std::ostream& operator<<(std::ostream& ostr, const gray& g); + + bool operator=(const gray& lhs, const gray& rhs); + bool operator<(const gray& lhs, const gray& rhs); + + gray operator+(const gray& lhs, const gray& rhs); + gray operator-(const gray& lhs, const gray& rhs); + + gray operator*(int s, const gray& rhs); + gray operator*(const gray& lhs, int s); + + gray operator/(const gray& lhs, int s); + + + + +# ifndef OLN_INCLUDE_ONLY + + template <unsigned N, unsigned M> + gray operator+(const gray_level<N>& lhs, const gray_level<M>& rhs) + { + return gray(lhs) + gray(rhs); + } + + template <unsigned N, unsigned M> + gray operator-(const gray_level<N>& lhs, const gray_level<M>& rhs) + { + return gray(lhs) - gray(rhs); + } + + template <unsigned N> + gray operator*(int s, const gray_level<N>& rhs) + { + precondition(s >= 0); + gray tmp(N, s * rhs.value()); + return tmp; + } + + template <unsigned N> + gray operator*(const gray_level<N>& lhs, int s) + { + precondition(s >= 0); + gray tmp(N, lhs.value() * s); + return tmp; + } + + template <unsigned N> + gray operator/(const gray_level<N>& lhs, int s) + { + precondition(s > 0); + gray tmp(N, lhs.value() / s); + return tmp; + } + + + + // Gray. + + gray::gray() + : nbits_(0) + { + } + + template <unsigned n> + gray::gray(const gray_level<n>& g) + : nbits_(n), + val_(g.value()) + { + } + + gray::gray(unsigned nbits, unsigned long val) + : nbits_(nbits), + val_(val) + { + } + + unsigned long gray::value() const + { + invariant(nbits_ != 0); + return val_; + } + + unsigned gray::nbits() const + { + return nbits_; + } + + namespace internal + { + + unsigned long two_pow_(unsigned n) + { + if (n = 0) + return 1; + else + return 2 * two_pow_(n - 1); + } + + unsigned long two_pow_n_minus_1(unsigned n) + { + return two_pow_(n) - 1; + } + + template <unsigned n_dest> + unsigned long convert(unsigned n_src, unsigned long val) + { + if (n_dest = n_src) + return val; + else + if (n_dest > n_src) + return val * two_pow_n_minus_1(n_dest) / two_pow_n_minus_1(n_src); + else + return val / two_pow_(n_src - n_dest); + } + + } // end of oln::value::internal + + + void gray::set_nbits(unsigned nbits) + { + precondition(nbits != 0); + invariant(nbits_ != 0); + if (nbits = nbits_) + return; + if (nbits > nbits_) + { + val_ *= internal::two_pow_n_minus_1(nbits); + val_ /= internal::two_pow_n_minus_1(nbits_); + } + else // nbits < nbits_ + { + val_ /= internal::two_pow_(nbits_ - nbits); + } + nbits_ = nbits; + } + + + gray gray::to_nbits(unsigned nbits) const + { + precondition(nbits != 0); + invariant(nbits_ != 0); + gray tmp(*this); + tmp.set_nbits(nbits); + return tmp; + } + + + template <unsigned n> + gray::operator gray_level<n>() const + { + precondition(nbits_ != 0); + gray_level<n> tmp(internal::convert<n>(nbits_, val_)); + assert(tmp.value() < internal::two_pow_(n)); + return tmp; + } + + // operators + + std::ostream& operator<<(std::ostream& ostr, const gray& g) + { + return ostr << g.value() << '/' << g.nbits() << "nbits"; + } + + bool operator=(const gray& lhs, const gray& rhs) + { + precondition(lhs.nbits() != 0 and rhs.nbits() != 0); + if (rhs.nbits() = lhs.nbits()) + return lhs.value() = rhs.value(); + if (lhs.nbits() > rhs.nbits()) + return lhs.value() = rhs.to_nbits(lhs.nbits()).value(); + else + return lhs.to_nbits(rhs.nbits()).value() = rhs.value(); + } + + bool operator<(const gray& lhs, const gray& rhs) + { + precondition(lhs.nbits() != 0 and rhs.nbits() != 0); + if (rhs.nbits() = lhs.nbits()) + return lhs.value() < rhs.value(); + if (lhs.nbits() > rhs.nbits()) + return lhs.value() < rhs.to_nbits(lhs.nbits()).value(); + else + return lhs.to_nbits(rhs.nbits()).value() < rhs.value(); + } + + gray operator+(const gray& lhs, const gray& rhs) + { + precondition(lhs.nbits() != 0 and rhs.nbits() != 0); + if (lhs.nbits() > rhs.nbits()) + { + gray tmp(lhs.nbits(), + lhs.value() + rhs.to_nbits(lhs.nbits()).value()); + return tmp; + } + else + { + gray tmp(rhs.nbits(), + lhs.to_nbits(rhs.nbits()).value() + rhs.value()); + return tmp; + } + } + + gray operator-(const gray& lhs, const gray& rhs) + { + precondition(lhs.nbits() != 0 and rhs.nbits() != 0); + if (lhs.nbits() > rhs.nbits()) + { + unsigned long l = rhs.to_nbits(lhs.nbits()).value(); + assert(lhs.value() >= l); + gray tmp(lhs.nbits(), + lhs.value() - l); + return tmp; + } + else + { + unsigned long l = lhs.to_nbits(rhs.nbits()).value(); + assert(l >= rhs.value()); + gray tmp(rhs.nbits(), + l - rhs.value()); + return tmp; + } + } + + gray operator*(int s, const gray& rhs) + { + precondition(s >= 0); + gray tmp(rhs.nbits(), rhs.value() * s); + return tmp; + } + + gray operator*(const gray& lhs, int s) + { + precondition(s >= 0); + gray tmp(lhs.nbits(), lhs.value() * s); + return tmp; + } + + gray operator/(const gray& lhs, int s) + { + precondition(s > 0); + gray tmp(lhs.nbits(), lhs.value() / s); + return tmp; + } + + template <unsigned N> + gray_level<N>& + gray_level<N>::operator=(const gray& g) + { + precondition(g.nbits() = N); + assert(g.value() < internal::two_pow_(N)); + this->val = g.value(); // FIXME: Add static_cast. + } + +# endif // ! OLN_INCLUDE_ONLY + + /* + + template <unsigned N, unsigned M> + bool operator=(const gray_level<N>& lhs, const gray_level<M>& rhs); + + template <unsigned N, unsigned M> + gray operator+(const gray_level<N>& lhs, const gray_level<M>& rhs); + + template <unsigned N, unsigned M> + gray operator-(const gray_level<N>& lhs, const gray_level<M>& rhs); + + template <unsigned N> + gray operator*(int s, const gray_level<N>& rhs); + + template <unsigned N> + gray operator*(const gray_level<N>& lhs, int s); + + template <unsigned N> + gray operator/(const gray_level<N>& lhs, int s); + + */ + + } // end of namespace oln::value + +} // end of namespace oln + + +/* + +namespace xtd +{ + + using oln::value::gray; + + template <> struct set_trait_<op_plus, gray, gray> { typedef gray ret; }; + template <> struct set_trait_<op_minus, gray, gray> { typedef gray ret; }; + template <> struct set_trait_<op_mult, int, gray> { typedef gray ret; }; + template <> struct set_trait_<op_mult, gray, int > { typedef gray ret; }; + template <> struct set_trait_<op_div, gray, int > { typedef gray ret; }; + + using oln::value::gray_level; + + template <unsigned nbits, unsigned M> + struct set_trait_< op_plus, gray_level<nbits>, gray_level<M> > { typedef gray ret; }; + + template <unsigned nbits, unsigned M> + struct set_trait_< op_minus, gray_level<nbits>, gray_level<M> > { typedef gray ret; }; + + template <unsigned nbits> + struct set_trait_< op_mult, int, gray_level<nbits> > { typedef gray ret; }; + + template <unsigned nbits> + struct set_trait_< op_mult, gray_level<nbits>, int > { typedef gray ret; }; + + template <unsigned nbits> + struct set_trait_< op_div, gray_level<nbits>, int > { typedef gray ret; }; + +} // end of namespace xtd + +*/ + + +#endif // ! OLN_VALUE_GRAY_HH Index: oln/value/builtin.hh --- oln/value/builtin.hh (revision 973) +++ oln/value/builtin.hh (working copy) @@ -28,84 +28,59 @@ #ifndef OLN_VALUE_BUILTIN_HH # define OLN_VALUE_BUILTIN_HH -# include <oln/core/concept/value.hh> +# include <oln/core/internal/value_base.hh> namespace oln { + // int - // Fwd decl. - namespace internal { template <typename Exact> struct builtin_base; } - - - // Virtual types. - template <typename Exact> - struct vtypes< internal::builtin_base<Exact> > + template <> + struct super_trait_< int > { - typedef stc::final< stc::is<Value> > category; + typedef internal::data_value_<int> ret; }; - - namespace internal - { - - // Base class for builtin types. - template <typename Exact> - struct builtin_base : public Value<Exact> + template <> + struct vtypes< int > { - protected: - builtin_base(); }; -# ifndef OLN_INCLUDE_ONLY - - template <typename Exact> - builtin_base<Exact>::builtin_base() - { - } - -# endif // ! OLN_INCLUDE_ONLY - - } // end of namespace oln::internal - - - - // unsigned, int, float, double,... + // float template <> - struct super_trait_< unsigned > + struct super_trait_< float > { - typedef internal::builtin_base<unsigned> ret; + typedef internal::data_value_<float> ret; }; template <> - struct super_trait_< int > + struct vtypes< float > { - typedef internal::builtin_base<int> ret; }; + + // double + template <> - struct super_trait_< float > + struct super_trait_< double > { - typedef internal::builtin_base<float> ret; + typedef internal::data_value_<double> ret; }; template <> - struct super_trait_< double > + struct vtypes< double > { - typedef internal::builtin_base<double> ret; }; - + // FIXME: To be continued... } // end of namespace oln -// FIXME: Bad? # include <oln/value/builtin_traits.hh> #endif // ! OLN_VALUE_BUILTIN_HH - Index: oln/value/black.hh --- oln/value/black.hh (revision 0) +++ oln/value/black.hh (revision 0) @@ -0,0 +1,91 @@ +// 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. + +#ifndef OLN_CORE_VALUE_ZERO_HH +# define OLN_CORE_VALUE_ZERO_HH + +# include <oln/core/concept/literal.hh> + + +namespace oln +{ + + struct black_t : public Literal< black_t > + { + + template <typename T> + operator T() const; + + // builtins: + operator unsigned() const; + operator int() const; + operator float() const; + operator double() const; + } + + black; + + + + // Default unary minus operator. + + template <typename T> + T + operator - (const Any<T>& rhs); // Use binary -. + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename T> + black_t::operator T() const + { + mlc::assert_< mlc_is_a(T, Any) >::check(); // FIXME: Add err msg. + T tmp; + tmp.assign_(*this); + return tmp; + } + + black_t::operator unsigned() const { return 0u; } + black_t::operator int() const { return 0; } + black_t::operator float() const { return 0.f; } + black_t::operator double() const { return 0.; } + + + template <typename T> + T + operator - (const Any<T>& rhs) + { + return black - exact(rhs); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_VALUE_BLACK_HH Index: oln/value/mlc_extra.hh --- oln/value/mlc_extra.hh (revision 0) +++ oln/value/mlc_extra.hh (revision 0) @@ -0,0 +1,76 @@ +// 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. + +#ifndef OLN_VALUE_MLC_EXTRA_HH +# define OLN_VALUE_MLC_EXTRA_HH + + + +namespace mlc +{ + namespace math + { + + template <int X, unsigned N> + struct pow_ + { + enum { value = X * pow_<X, N-1>::value }; + }; + + template <int X> + struct pow_< X, 0 > + { + enum { value = 1 }; + }; + + template <> + struct pow_< 0, 0 > + { + enum { value = 1 }; + }; + + template <unsigned N> + struct pow_< 0, N > + { + enum { value = 0 }; + }; + + + template <unsigned N> + struct two_pow_ : public pow_<2, N> + { + }; + + + } // end of namespace mlc::math + +} // end of namespace mlc + + + +#endif // ! OLN_VALUE_MLC_EXTRA_HH +
participants (1)
-
Thierry Geraud