proto-1.0 111: Cleaning mlc.

2005-04-05 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Cleaning. * mlc/types.hh: Rewrite and split into... * mlc/bool.hh: Likewise. * mlc/if.hh: ... this new file. * mlc/switch.hh: ... this new file. * mlc/value.hh: ... this new file. * mlc/cmp.hh: Rewrite and arithmetics move to... * mlc/arith.hh: ... this new file. * mlc/math.hh: Update. * mlc/properties.hh: Likewise. * mlc/makefile.src: Likewise. * mlc/is_a.hh: Likewise. * mlc/contract.hh: Likewise. * mlc/array/1d.hh: Likewise. * mlc/array/2d.hh: Likewise. * mlc/array/3d.hh: Likewise. * mlc/array/1d.hxx: Likewise. * mlc/array/2d.hxx: Likewise. * mlc/array/3d.hxx: Likewise. Index: mlc/math.hh =================================================================== --- mlc/math.hh (revision 110) +++ mlc/math.hh (working copy) @@ -64,17 +64,14 @@ internal::find_pow2sup< N, typename internal::is_pow2<N>::ret >::value }; - private: - typedef typename is_true<N < 32>::ensure_type precondition_type; + ~pow2sup() { mlc::value<bool, (N < 32)>::ensure(); } }; // Various tests on N (actually, we tests only oddness.) template<unsigned N> - class utest { - public: - typedef typename is_true<N/2 == (N+1)/2>::ensure_type is_odd_type; - static void ensure_odd() { is_odd_type::is_true(); } + struct utest { + static void ensure_odd() { mlc::value<bool, (N/2 == (N+1)/2)>::ensure(); } }; } // end of namespace mlc Index: mlc/bool.hh =================================================================== --- mlc/bool.hh (revision 110) +++ mlc/bool.hh (working copy) @@ -28,129 +28,36 @@ #ifndef METALIC_BOOL_HH # define METALIC_BOOL_HH +# include <mlc/value.hh> + namespace mlc { - struct false_type; - - struct true_type { - static void is_true() {} - typedef false_type not_type; - typedef void is_true_type; - }; - - struct false_type { - static void is_false() {} - typedef true_type not_type; - typedef void is_false_type; - }; - - - - /*----. - | if_ | - `----*/ - - template <bool Cond, class if_true_type, class if_false_type> - struct if_ { - typedef if_true_type ret; - }; - - template<class if_true_type, class if_false_type> - struct if_<false, if_true_type, if_false_type> + /// Specialization of mlc::value for T = bool and v = true; it provides ::ensure(). + template <> + struct value <bool, true> { - typedef if_false_type ret; - typedef false_type ensure_type; + static void ensure() {} + static const bool ret = true; + private: + value(); }; - /*--------. - | switch_ | - `--------*/ - struct invalid {}; + /// Typedefs of true_type and false_type. + typedef value<bool, true> true_type; + typedef value<bool, false> false_type; - template<unsigned Cond, class Ret, class Cases = invalid> - struct case_ {}; - template<unsigned Cond, class Cases, class Default = invalid> - struct switch_; - - template<unsigned Cond, unsigned Compare, class Ret, class Default> - struct switch_<Cond, case_<Compare, Ret>, Default > + /// Class is_true<b> (provided for bkd compability). + template <bool b> + struct is_true : public value<bool, b> { - typedef typename if_< (Cond == Compare), Ret, Default >::ret ret; }; - template<unsigned Cond, - unsigned Compare, - class Ret, - class Cases, - class Default> - struct switch_<Cond, case_<Compare, Ret, Cases>, Default > - { - typedef typename - if_< (Cond == Compare), - Ret, - typename switch_<Cond, Cases, Default>::ret>::ret ret; - }; - template<bool Cond, class Ret, class Cases = invalid> - struct bool_case_ {}; - - template<class Cases, class Default = invalid> - struct bool_switch_; - - template<bool Cond, class Ret, class Default> - struct bool_switch_<bool_case_<Cond, Ret>, Default > - { - typedef typename if_< Cond, Ret, Default >::ret ret; - }; - - template<bool Cond,class Ret, class Cases, class Default> - struct bool_switch_<bool_case_<Cond, Ret, Cases>, Default > - { - typedef typename - if_< Cond, - Ret, - typename bool_switch_<Cases, Default>::ret >::ret ret; - }; - - /*-----. - | misc | - `-----*/ - - template<bool> struct is_true; - template<> struct is_true<true> - { - static void ensure() {}; - typedef true_type ensure_type; - }; - - template<bool> struct is_false; - template<> struct is_false<false> { static void ensure() {}; }; - - // FIXME: find a good name for this struct. - - // base class for meta-types returning Boolean values - - template<bool> struct returns_bool_; - - template<> - struct returns_bool_<true> : public true_type - { - typedef void ensure_type; - static const bool ret = true; - static void ensure() {} - }; - - template<> - struct returns_bool_<false> : public false_type - { - static const bool ret = false; - }; - } // end of namespace mlc Index: mlc/properties.hh =================================================================== --- mlc/properties.hh (revision 110) +++ mlc/properties.hh (working copy) @@ -31,38 +31,11 @@ # include <iostream> # include <typeinfo> -# include <mlc/types.hh> -# include <mlc/bool.hh> +# include <mlc/if.hh> # include <mlc/cmp.hh> -// FIXME: temporary routines; equivalent to the ones of mlc/bool.hh and mlc/cmp.hh -// FIXME: modify mlc/* so that "types" are prefered to "values"... -namespace mlc -{ - namespace internal - { - template <class C, class T, class F> struct my_if; - template <class T, class F> struct my_if <mlc::true_type, T, F> { typedef T ret; }; - template <class T, class F> struct my_if <mlc::false_type, T, F> { typedef F ret; }; - - template <class T1, class T2> struct my_eq { typedef mlc::false_type ret; }; - template <class T> struct my_eq <T, T> { typedef mlc::true_type ret; }; - - } -} - -// FIXME: temporary macros (Cf. above) - -# define mlc_internal_if(C,T,F) \ -typename mlc::internal::my_if<C,T,F>::ret - -# define mlc_internal_eq(T1,T2) \ -typename mlc::internal::my_eq<T1,T2>::ret - - - /// macro to equip a namespace for properties: # define mlc_equip_namespace_for_properties() \ @@ -158,7 +131,7 @@ struct get_prop < CATEGORY, type, target::TARGET > \ { \ typedef get_prop_helper<CATEGORY, type, target::TARGET, \ - mlc_internal_eq(type, mlc::no_type), \ + mlc_eq(type, mlc::no_type), \ typename get_props<CATEGORY, type>::user_defined_ \ > helper_type; \ typedef typename helper_type::ret ret; \ @@ -172,7 +145,7 @@ typename get_super_type<type>::ret, \ target::TARGET>::ret super_prop_type; \ \ - typedef mlc_internal_if( mlc_internal_eq(prop_type, mlc::unknown_type), \ + typedef mlc_if( mlc_eq(prop_type, mlc::unknown_type), \ super_prop_type, \ prop_type ) ret; \ }; \ @@ -204,17 +177,17 @@ /// macros to declare a property: # define mlc_decl_prop_with_default(CATEGORY, NAME, DEFAULT) \ - typedef mlc_internal_if(mlc_internal_eq(type, mlc::default_type), \ + typedef mlc_if(mlc_eq(type, mlc::default_type), \ DEFAULT, \ - mlc_internal_if(mlc_internal_eq(type, mlc::no_type), \ + mlc_if(mlc_eq(type, mlc::no_type), \ mlc::unknown_type, \ mlc_internal_retrieve_prop(CATEGORY, type, NAME)) \ ) NAME # define mlc_decl_prop(CATEGORY, NAME) \ - typedef mlc_internal_if(mlc_internal_eq(type, mlc::default_type), \ + typedef mlc_if(mlc_eq(type, mlc::default_type), \ mlc::undefined_type, \ - mlc_internal_if(mlc_internal_eq(type, mlc::no_type), \ + mlc_if(mlc_eq(type, mlc::no_type), \ mlc::unknown_type, \ mlc_internal_retrieve_prop(CATEGORY, type, NAME)) \ ) NAME @@ -228,9 +201,9 @@ TYPE, \ NAMESPACE::target::TARGET##_type>::ret -# define mlc_type_of_(NAMESPACE, TYPE, TARGET) \ +# define mlc_type_of_(NAMESPACE, TYPE, TARGET) \ NAMESPACE::get_type_of<typename NAMESPACE::internal::get_category<TYPE>::ret, \ - TYPE, \ + TYPE, \ NAMESPACE::target::TARGET##_type>::ret Index: mlc/if.hh =================================================================== --- mlc/if.hh (revision 0) +++ mlc/if.hh (revision 0) @@ -0,0 +1,61 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 METALIC_IF_HH +# define METALIC_IF_HH + +# include <mlc/bool.hh> + + +/// Macro mlc_if. +# define mlc_if(Cond, Then, Else) typename mlc::if_<(Cond), (Then), (Else)>::ret + + +namespace mlc +{ + + template <typename cond_type, typename then_type, typename else_type> + struct if_; + + template <typename then_type, typename else_type> + struct if_ <true_type, then_type, else_type> + { + typedef then_type ret; + }; + + template <typename then_type, typename else_type> + struct if_ <false_type, then_type, else_type> + { + typedef else_type ret; + }; + + +} // end of namespace mlc + + + +#endif // ! METALIC_IF_HH Index: mlc/switch.hh =================================================================== --- mlc/switch.hh (revision 0) +++ mlc/switch.hh (revision 0) @@ -0,0 +1,92 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 METALIC_SWITCH_HH +# define METALIC_SWITCH_HH + +# include <mlc/bool.hh> +# include <mlc/if.hh> + + +namespace mlc +{ + + + // FIXME: not yet cleaned. + + struct invalid {}; + + template<unsigned Cond, class Ret, class Cases = invalid> + struct case_ {}; + + template<unsigned Cond, class Cases, class Default = invalid> + struct switch_; + + template<unsigned Cond, unsigned Compare, class Ret, class Default> + struct switch_<Cond, case_<Compare, Ret>, Default > + { + typedef typename if_< value<bool,(Cond == Compare)>, Ret, Default >::ret ret; + }; + + template<unsigned Cond, + unsigned Compare, + class Ret, + class Cases, + class Default> + struct switch_<Cond, case_<Compare, Ret, Cases>, Default > + { + typedef typename + if_< value<bool, bool(Cond == Compare)>, + Ret, + typename switch_<Cond, Cases, Default>::ret>::ret ret; + }; + + template<bool Cond, class Ret, class Cases = invalid> + struct bool_case_ {}; + + template<class Cases, class Default = invalid> + struct bool_switch_; + + template<bool Cond, class Ret, class Default> + struct bool_switch_<bool_case_<Cond, Ret>, Default > + { + typedef typename if_< value<bool,Cond>, Ret, Default >::ret ret; + }; + + template<bool Cond,class Ret, class Cases, class Default> + struct bool_switch_<bool_case_<Cond, Ret, Cases>, Default > + { + typedef typename + if_< value<bool, Cond>, + Ret, + typename bool_switch_<Cases, Default>::ret >::ret ret; + }; + +} // end of namespace mlc + + +#endif // ! METALIC_SWITCH_HH Index: mlc/types.hh =================================================================== --- mlc/types.hh (revision 110) +++ mlc/types.hh (working copy) @@ -28,7 +28,10 @@ #ifndef METALIC_TYPES_HH # define METALIC_TYPES_HH +# include <mlc/value.hh> + + /*! \namespace mlc ** \brief mlc namespace. */ Index: mlc/makefile.src =================================================================== --- mlc/makefile.src (revision 110) +++ mlc/makefile.src (working copy) @@ -5,6 +5,7 @@ MLC_DEP = \ any.hh \ + arith.hh \ array/1d.hh \ array/1d.hxx \ array/2d.hh \ @@ -19,10 +20,12 @@ cmp.hh \ config/system.hh \ contract.hh \ + if.hh \ is_a.hh \ math.hh \ properties.hh \ + switch.hh \ tracked_ptr.hh \ traits.hh \ - types.hh - + types.hh \ + value.hh Index: mlc/arith.hh =================================================================== --- mlc/arith.hh (revision 0) +++ mlc/arith.hh (revision 0) @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 METALIC_ARITH_HH +# define METALIC_ARITH_HH + +# include <mlc/bool.hh> + + + +namespace mlc +{ + + template <typename T> + struct on + { + template <T i, T j> struct eq : public value <bool, (i == j)> {}; + template <T i, T j> struct neq : public value <bool, (i != j)> {}; + + template <T i, T j> struct less : public value <bool, (i < j)> {}; + template <T i, T j> struct leq : public value <bool, (i <= j)> {}; + + template <T i, T j> struct greater : public value <bool, (i > j)> {}; + template <T i, T j> struct geq : public value <bool, (i >= j)> {}; + + template <T i, T j> struct min : public value<T, (i < j ? i : j)> {}; + template <T i, T j> struct max : public value<T, (i > j ? i : j)> {}; + + template <T i, T j, T N> struct maxN : public value<T, (i > j ? + (i > N ? N : i) : + (j > N ? N : j))> {}; + template <T i, T N> struct saturateN : public value<T, (i > N ? N : i)> {}; + }; + + +} // end of namespace mlc + + +#endif // ! METALIC_ARITH_HH Index: mlc/is_a.hh =================================================================== --- mlc/is_a.hh (revision 110) +++ mlc/is_a.hh (working copy) @@ -122,7 +122,7 @@ template<class T, class U> struct check - : public mlc::returns_bool_<( is_a__check_result_ )> + : public value<bool,( is_a__check_result_ )> { }; }; @@ -145,7 +145,7 @@ template<class T, template<class> class U> struct check - : public mlc::returns_bool_<( is_a__check_result_ )> + : public value<bool,( is_a__check_result_ )> { }; }; @@ -168,7 +168,7 @@ template<class T, template<class,class> class U> struct check - : public mlc::returns_bool_<( is_a__check_result_ )> + : public value<bool,( is_a__check_result_ )> {}; }; Index: mlc/value.hh =================================================================== --- mlc/value.hh (revision 0) +++ mlc/value.hh (revision 0) @@ -0,0 +1,51 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 METALIC_VALUE_HH +# define METALIC_VALUE_HH + + +/*! \namespace mlc +** \brief mlc namespace. +*/ +namespace mlc { + + + /// Class that defines a mlc value as a type (for instance mlc::value<int,3>). + template <typename T, T v> + struct value + { + static const T ret = v; + private: + value(); + }; + + +} // end of namespace mlc + + +#endif // ! METALIC_VALUE_HH Index: mlc/contract.hh =================================================================== --- mlc/contract.hh (revision 110) +++ mlc/contract.hh (working copy) @@ -34,10 +34,10 @@ // FIXME: a lot of code has been removed here // for simplification purpose only -# define assertion(expr) assert(expr) -# define invariant(expr) assert(expr) -# define precondition(expr) assert(expr) -# define postcondition(expr) assert(expr) +# define assertion(expr) assert(expr) +# define invariant(expr) assert(expr) +# define precondition(expr) assert(expr) +# define postcondition(expr) assert(expr) #endif // ! METALIC_CONTRACT_HH Index: mlc/cmp.hh =================================================================== --- mlc/cmp.hh (revision 110) +++ mlc/cmp.hh (working copy) @@ -28,104 +28,47 @@ #ifndef METALIC_CMP_HH # define METALIC_CMP_HH - # include <mlc/bool.hh> -namespace mlc -{ +/// Macro mlc_eq. +# define mlc_eq(T1, T2) typename mlc::eq<T1, T2>::ret - namespace type { - /*-----------------. - | Type comparisons | - `-----------------*/ +namespace mlc +{ - template <typename T, typename U> - struct eq : returns_bool_<false> {}; + /// Equality test between a couple of types. - template <typename T> - struct eq<T, T> : returns_bool_<true> {}; - - } // end of namespace type - - /*-------------------. - | Values comparisons | - `-------------------*/ - - // These struct are quite handy since constructions like - // is_true<a < b>::ensure() cannot be parsed. - - template<int i, int j> - struct less - { - enum { ret = (i < j) }; - static void ensure() { is_true<ret>::ensure(); }; - }; - - template<int i, int j> - struct lesseq - { - enum { ret = (i <= j) }; - static void ensure() { is_true<ret>::ensure(); }; - }; - - template<int i, int j> + template <typename T1, typename T2> struct eq { - enum { ret = (i == j) }; - static void ensure() { is_true<ret>::ensure(); }; + typedef false_type ret; }; - template<int i, int j> - struct neq + template <typename T> + struct eq <T, T> { - enum { ret = (i != j) }; - static void ensure() { is_true<ret>::ensure(); }; + typedef true_type ret; }; - template<int i, int j> - struct greater - { - enum { ret = (i > j) }; - static void ensure() { is_true<ret>::ensure(); }; - }; - template<int i, int j> - struct greatereq - { - enum { ret = (i >= j) }; - static void ensure() { is_true<ret>::ensure(); }; - }; + /// Inequality test between a couple of types. - template<int i, int j> - struct min + template <typename T1, typename T2> + struct neq { - enum { ret = (i < j ? i : j) }; + typedef true_type ret; }; - template<int i, int j> - struct max + template <typename T> + struct neq <T, T> { - enum { ret = (i > j ? i : j) }; + typedef false_type ret; }; - template<int i, int j, int N> - struct maxN - { - enum { ret = (i > j ? - (i > N ? N : i) : - (j > N ? N : j)) }; - }; - template<int i, int N> - struct saturateN - { - enum { ret = (i > N ? N : i) }; - }; - - } // end of namespace mlc Index: mlc/array/1d.hh =================================================================== --- mlc/array/1d.hh (revision 110) +++ mlc/array/1d.hh (working copy) @@ -29,7 +29,7 @@ # define METALIC_ARRAY_1D_HH # include <mlc/contract.hh> -# include <mlc/cmp.hh> +# include <mlc/arith.hh> # include <mlc/array/objs.hh> # include <ntg/basics.hh> # include <iostream> @@ -59,8 +59,8 @@ array1d(T* ptr) { - less<0, Info_::card>::ensure(); - less< Info_::card, internal::max_card_ >::ensure(); + on<unsigned>::less<0, Info_::card>::ensure(); + on<unsigned>::less< Info_::card, internal::max_card_ >::ensure(); for (unsigned i = 0; i < Info_::card; ++i) buffer_[i] = *ptr++; } @@ -230,14 +230,14 @@ template<unsigned i> T get_at_() const { - lesseq<i, Info_::card>::ensure(); + on<unsigned>::leq<i, Info_::card>::ensure(); return *(buffer_ + i); } template<int i> T get_() const { - lesseq<-Info_::center, i>::ensure(); - lesseq<i, Info_::card - Info_::center - 1>::ensure(); + on<int>::leq<-Info_::center, i>::ensure(); + on<int>::leq<i, Info_::card - Info_::center - 1>::ensure(); return *(buffer_ + Info_::center + i); } Index: mlc/array/2d.hh =================================================================== --- mlc/array/2d.hh (revision 110) +++ mlc/array/2d.hh (working copy) @@ -30,7 +30,7 @@ # include <mlc/array/objs.hh> # include <mlc/contract.hh> -# include <mlc/cmp.hh> +# include <mlc/arith.hh> # include <ntg/basics.hh> # include <iostream> @@ -58,9 +58,9 @@ array2d(T* ptr) { - less< 0, Info_::nrows >::ensure(); - less< 0, Info_::ncols >::ensure(); - less< Info_::card, internal::max_card_ >::ensure(); + on<unsigned>::less< 0, Info_::nrows >::ensure(); + on<unsigned>::less< 0, Info_::ncols >::ensure(); + on<unsigned>::less< Info_::card, internal::max_card_ >::ensure(); for (unsigned i = 0; i < Info_::card; ++i) buffer_[i] = *ptr++; } @@ -256,16 +256,16 @@ template<unsigned i> T get_at_() const { - lesseq<i, Info_::card>::ensure(); + on<unsigned>::leq<i, Info_::card>::ensure(); return *(buffer_ + i); } template<int nrow, int ncol> T get_() const { - lesseq< -Info_::center_row, nrow >::ensure(); - lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure(); - lesseq< -Info_::center_col, ncol >::ensure(); - lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure(); + on<int>::leq< -Info_::center_row, nrow >::ensure(); + on<int>::leq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure(); + on<int>::leq< -Info_::center_col, ncol >::ensure(); + on<int>::leq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure(); return *(buffer_ + Info_::center + (nrow * Info_::ncols) + ncol); } Index: mlc/array/3d.hh =================================================================== --- mlc/array/3d.hh (revision 110) +++ mlc/array/3d.hh (working copy) @@ -30,7 +30,7 @@ # include <mlc/array/objs.hh> # include <mlc/contract.hh> -# include <mlc/cmp.hh> +# include <mlc/arith.hh> # include <ntg/basics.hh> # include <iostream> @@ -60,10 +60,10 @@ array3d(T* ptr) { - less< 0, Info_::nplanes >::ensure(); - less< 0, Info_::nrows >::ensure(); - less< 0, Info_::ncols >::ensure(); - less< Info_::card, internal::max_card_ >::ensure(); + on<unsigned>::less< 0, Info_::nplanes >::ensure(); + on<unsigned>::less< 0, Info_::nrows >::ensure(); + on<unsigned>::less< 0, Info_::ncols >::ensure(); + on<unsigned>::less< Info_::card, internal::max_card_ >::ensure(); for (unsigned i = 0; i < Info_::card; ++i) buffer_[i] = *ptr++; } @@ -259,18 +259,18 @@ template<unsigned i> T get_at_() const { - lesseq<i, Info_::card>::ensure(); + on<int>::leq<i, Info_::card>::ensure(); return *(buffer_ + i); } template<int nplane, int nrow, int ncol> T get_() const { - lesseq< -Info_::center_plane, nplane >::ensure(); - lesseq< nplane, Info::nplanes - Info_::center_plane - 1 >::ensure(); - lesseq< -Info_::center_row, nrow >::ensure(); - lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure(); - lesseq< -Info_::center_col, ncol >::ensure(); - lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure(); + on<int>::leq< -Info_::center_plane, nplane >::ensure(); + on<int>::leq< nplane, Info::nplanes - Info_::center_plane - 1 >::ensure(); + on<int>::leq< -Info_::center_row, nrow >::ensure(); + on<int>::leq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure(); + on<int>::leq< -Info_::center_col, ncol >::ensure(); + on<int>::leq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure(); return *(buffer_ + Info_::center + (nplane * Info::nrows * Info::ncols) + (nrow * Info::ncols) + ncol); } Index: mlc/array/1d.hxx =================================================================== --- mlc/array/1d.hxx (revision 110) +++ mlc/array/1d.hxx (working copy) @@ -146,7 +146,7 @@ next_elt_t_ operator,(T val) { - is_true<Info::card == unknown_>::ensure(); + value<bool, (Info::card == unknown_)>::ensure(); *ptr = val; return next_elt_t_(ptr + 1, arr); } @@ -156,7 +156,7 @@ eat_center_t_ operator,(x_<T> val) { - is_true<Info::center == unknown_>::ensure(); + value<bool, (Info::center == unknown_)>::ensure(); *ptr = val.ue; // FIXME : give a *name* to this variable !! return eat_center_t_(ptr+1, arr); } @@ -166,7 +166,7 @@ eat_center_t_ operator,(x_<void>) { - is_true<Info::center == unknown_>::ensure(); + value<bool, (Info::center == unknown_)>::ensure(); *ptr = T(0); return eat_center_t_(ptr+1, arr); } @@ -177,7 +177,7 @@ array1d_t_ operator,(end_type) { // array is well-formed : - is_true<Info::well_formed>::ensure(); + value<bool, Info::well_formed>::ensure(); // centering is automatic or user-defined : // (commented out to allow automatic centering on even sized arrays) // mlc::logical_or< mlc::eq< Info::i % 2, 1 >::ret, mlc::neq< Info::center, unknown_ >::ret >::ensure(); Index: mlc/array/2d.hxx =================================================================== --- mlc/array/2d.hxx (revision 110) +++ mlc/array/2d.hxx (working copy) @@ -170,7 +170,7 @@ next_elt_t_ operator,(T val) { - is_true<Info::nrows == unknown_>::ensure(); + value<bool, (Info::nrows == unknown_)>::ensure(); *ptr = val; return next_elt_t_(ptr + 1, arr); } @@ -180,7 +180,7 @@ eat_center_t_ operator,(x_<T> val) { - is_true<Info::center == unknown_>::ensure(); + value<bool, (Info::center == unknown_)>::ensure(); *ptr = val.ue; // FIXME : give a *name* to this variable !! return eat_center_t_(ptr + 1, arr); } @@ -190,7 +190,7 @@ eat_center_t_ operator,(x_<void>) { - is_true<Info::center == unknown_>::ensure(); + value<bool, (Info::center == unknown_)>::ensure(); *ptr = T(0); return eat_center_t_(ptr + 1, arr); } @@ -200,8 +200,8 @@ eat_lbrk_t_ operator,(lbrk_) { - is_true<Info::ncols == unknown_>::ensure(); - is_true<Info::ncols != 0>::ensure(); + value<bool, (Info::ncols == unknown_)>::ensure(); + value<bool, (Info::ncols != 0)>::ensure(); return eat_lbrk_t_(ptr, arr); } @@ -213,19 +213,19 @@ enum { nrows = Info::i / Info::ncols }; // array is well-formed : - is_true<Info::well_formed == true>::ensure(); + value<bool, (Info::well_formed == true)>::ensure(); // centering is automatic or user-defined : - is_true<Info::ncols != unknown_>::ensure(); + value<bool, (Info::ncols != unknown_)>::ensure(); // both nrows and ncols must be odd // or the center must be user-defined - is_true< + value<bool, ( ((Info::ncols % 2 == 1) && (nrows % 2 == 1)) || (Info::center != unknown_) - >::ensure(); + )>::ensure(); return array2d_t_(arr->ptr); } Index: mlc/array/3d.hxx =================================================================== --- mlc/array/3d.hxx (revision 110) +++ mlc/array/3d.hxx (working copy) @@ -174,7 +174,7 @@ next_elt_t_ operator,(T val) { - is_true<Info::nplanes == unknown_>::ensure(); + value<bool, (Info::nplanes == unknown_)>::ensure(); *ptr = val; return next_elt_t_(ptr + 1, arr); } @@ -184,7 +184,7 @@ eat_center_t_ operator,(x_<T> val) { - is_true<Info::center == unknown_>::ensure(); + value<bool, (Info::center == unknown_)>::ensure(); *ptr = val.ue; // FIXME : give a *name* to this variable !! return eat_center_t_(ptr + 1, arr); } @@ -194,7 +194,7 @@ eat_center_t_ operator,(x_<void>) { - is_true<Info::center == unknown_>::ensure(); + value<bool, (Info::center == unknown_)>::ensure(); *ptr = T(0); return eat_center_t_(ptr + 1, arr); } @@ -204,7 +204,7 @@ eat_lbrk_t_ operator,(lbrk_) { - is_true<Info::ncols == unknown_>::ensure(); + value<bool, (Info::ncols == unknown_)>::ensure(); return eat_lbrk_t_(ptr, arr); } @@ -212,7 +212,7 @@ // elt, pbrk eat_pbrk_t_ operator,(pbrk_) { - is_true<Info::nplanes == unknown_>::ensure(); + value<bool, (Info::nplanes == unknown_)>::ensure(); return eat_pbrk_t_(ptr, arr); } @@ -223,19 +223,19 @@ enum { nplanes = (Info::i / (Info::ncols * Info::nrows)) }; // array is well-formed : - is_true<Info::well_formed>::ensure(); + value<bool, (Info::well_formed)>::ensure(); // centering is automatic or user-defined : - is_true<Info::ncols != unknown_>::ensure(); - is_true<Info::nrows != unknown_>::ensure(); + value<bool, (Info::ncols != unknown_)>::ensure(); + value<bool, (Info::nrows != unknown_)>::ensure(); // all of nplanes, nrows and ncols are odd // or the center is user-defined - is_true< + value<bool, ( (Info::ncols % 2 == 1 && Info::nrows % 2 == 1 && nplanes % 2 == 1) || (Info::center != unknown_) - >::ensure(); + )>::ensure(); return array3d_t_(arr->ptr); }
participants (1)
-
Thierry GERAUD