Index: integre/ChangeLog from Nicolas Burrus burrus_n@lrde.epita.fr
Make typetraits and optraits reproduce more accurately the value hierarchy.
* ntg/real/int_s.hh: Fix traits inheritance. * ntg/real/int_u.hh: Likewise. * ntg/real/optraits_builtin_int.hh: Likewise. * ntg/real/typetraits_builtin_int.hh: Likewise. * ntg/real/builtin_float.hh: Likewise. * ntg/real/range.hh: Likewise. * ntg/real/cycle.hh: Likewise. * ntg/vect/vec.hh: Likewise. * ntg/enum/bin.hh: Likewise.
* ntg/real/real_value.hh: Define typetraits. * ntg/vect/vect_value.hh: Likewise. * ntg/enum/enum_value.hh: Likewise. * ntg/real/optraits_real.hh: Rename optraits_xxx as optraits<xxx_value>. * ntg/core/value.hh: Define typetraits<value> and optraits<value>.
* ntg/core/internal/traits.hh: Remove useless optraits_xxx definitions.
Index: integre/ntg/real/int_s.hh --- integre/ntg/real/int_s.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/24_int_s.hh 1.16.1.17 640) +++ integre/ntg/real/int_s.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/24_int_s.hh 1.16.1.18 640) @@ -67,6 +67,7 @@
template <unsigned nbits, class behavior> struct typetraits<int_s<nbits, behavior> > + : public typetraits<sint_value<int_s<nbits, behavior> > > { typedef int_s<nbits, behavior> self; typedef signed_integer abstract_type; @@ -213,10 +214,11 @@
template <unsigned nbits, class behavior> struct optraits<int_s<nbits, behavior> > : - public optraits_int_s<int_s<nbits, behavior> > + public optraits<sint_value<int_s<nbits, behavior> > > { public: typedef int_s<nbits, behavior> self; + typedef optraits<sint_value<int_s<nbits, behavior> > > super;
private: typedef typename typetraits<self>::base_type base_type_; @@ -250,17 +252,17 @@
// int_sN == int_u32; int_u32 == int_sN
- template <class B2> + template <unsigned mbits, class B1, class B2> static bool - cmp_eq(const self& lhs, const int_u<32, B2>& rhs) + cmp_eq(const int_s<mbits, B1>& lhs, const int_u<32, B2>& rhs) { if (lhs.val() < 0) return false;
return static_cast<int_u<32, B2> >(lhs).val() == rhs.val(); } - template <class B1> - static bool cmp_eq(const int_u<32, B1>& lhs, const self& rhs) + template <unsigned mbits, class B1, class B2> + static bool cmp_eq(const int_u<32, B1>& lhs, const int_s<mbits, B2>& rhs) { return cmp_eq(rhs, lhs); }
// <T1> == <T2> @@ -268,7 +270,7 @@ template <class T1, class T2> static bool cmp_eq(const T1& lhs, const T2& rhs) - { return optraits_scalar<self>::cmp_eq(lhs, rhs); } + { return super::cmp_eq(lhs, rhs); }
// // cmp_lt @@ -276,17 +278,17 @@
// int_sN < int_u32; int_u32 < int_sN
- template <class B2> + template <unsigned mbits, class B1, class B2> static bool - cmp_lt(const self& lhs, const int_u<32, B2>& rhs) + cmp_lt(const int_s<mbits, B1>& lhs, const int_u<32, B2>& rhs) { if (lhs.val() < 0) return true;
return static_cast<int_u<32, B2> >(lhs).val() < rhs.val(); } - template <class B1> - static bool cmp_lt(const int_u<32, B1>& lhs, const self& rhs) + template <unsigned mbits, class B1, class B2> + static bool cmp_lt(const int_u<32, B1>& lhs, const int_s<mbits, B2>& rhs) { if (rhs.val() < 0) return false; @@ -299,7 +301,7 @@ template <class T1, class T2> static bool cmp_lt(const T1& lhs, const T2& rhs) - { return optraits_scalar<self>::cmp_lt(lhs, rhs); } + { return super::cmp_lt(lhs, rhs); }
// debug static std::string name() { Index: integre/ntg/real/int_u.hh --- integre/ntg/real/int_u.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/23_int_u.hh 1.19.1.17 640) +++ integre/ntg/real/int_u.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/23_int_u.hh 1.19.1.18 640) @@ -63,6 +63,7 @@
template <unsigned nbits, class behavior> struct typetraits<int_u<nbits, behavior> > + : public typetraits<uint_value<int_u<nbits, behavior> > > { typedef int_u<nbits, behavior> self; typedef unsigned_integer abstract_type; @@ -213,7 +214,7 @@
template <unsigned nbits, class behavior> struct optraits<int_u<nbits, behavior> > : - public optraits_int_u<int_u<nbits, behavior> > + public optraits<uint_value<int_u<nbits, behavior> > > { private: typedef int_u<nbits, behavior> self; Index: integre/ntg/real/optraits_builtin_int.hh --- integre/ntg/real/optraits_builtin_int.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/18_optraits_b 1.6.1.9 640) +++ integre/ntg/real/optraits_builtin_int.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/18_optraits_b 1.6.1.10 640) @@ -47,7 +47,7 @@
# define OPTRAITS_BUILTIN_INT_U(Name, Max) \ template <> \ - struct optraits<Name> : public optraits_int_u<Name> \ + struct optraits<Name> : public optraits<uint_value<Name> > \ { \ static Name max() { return Max; } \ static std::string name() { return std::string(#Name); } \ @@ -55,7 +55,7 @@
# define OPTRAITS_BUILTIN_INT_S(Name, Min, Max) \ template <> \ - struct optraits<Name> : public optraits_int_s<Name> \ + struct optraits<Name> : public optraits<sint_value<Name> > \ { \ static Name min() { return Min; } \ static Name max() { return Max; } \ Index: integre/ntg/real/optraits_real.hh --- integre/ntg/real/optraits_real.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/12_optraits_s 1.11.1.9 640) +++ integre/ntg/real/optraits_real.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/12_optraits_s 1.11.1.10 640) @@ -39,7 +39,6 @@ // --
# include <ntg/core/internal/global_ops_traits.hh> -# include <ntg/core/type_traits.hh> # include <ntg/core/macros.hh>
// macros definitions @@ -49,16 +48,16 @@
namespace internal {
- /*----------------. - | optraits_scalar | - `----------------*/ + /*---------------------. + | optraits<real_value> | + `---------------------*/
//! Implement common operators for scalars - template <class Self> - class optraits_scalar : public optraits_top<Self> + template <class E> + class optraits<real_value<E> > : public optraits<value<E> > { private: - typedef typename typetraits<Self>::storage_type storage_type_; + typedef typename typetraits<E>::storage_type storage_type_;
public: static storage_type_ zero () { return 0; } @@ -86,60 +85,61 @@ CMP_SCALAR_OPERATOR(cmp_lt, <) };
- /*---------------. - | optraits_float | - `---------------*/
- template <class Self> - class optraits_float : public optraits_scalar<Self> + /*----------------------. + | optraits<float_value> | + `----------------------*/ + + template <class E> + class optraits<float_value<E> > : public optraits<real_value<E> > { public: // This is the standard size for float on std::ostream. static unsigned max_print_width () { return 11U; } };
- /*-------------. - | optraits_int | - `-------------*/ + /*--------------------. + | optraits<int_value> | + `--------------------*/
- template <class Self> - class optraits_int : public optraits_scalar<Self> + template <class E> + class optraits<int_value<E> > : public optraits<real_value<E> > { - typedef typename typetraits<Self>::storage_type storage_type_; + typedef typename typetraits<E>::storage_type storage_type_;
public: - static storage_type_ inf () { return optraits<Self>::min(); } - static storage_type_ sup () { return optraits<Self>::max(); } + static storage_type_ inf () { return optraits<E>::min(); } + static storage_type_ sup () { return optraits<E>::max(); }
static unsigned max_print_width () { - return (unsigned) log10(double(optraits<Self>::max())) + 1; + return (unsigned) log10(double(optraits<E>::max())) + 1; }
ASSIGN_INT_OPERATOR(mod_equal, %) ARITH_INT_OPERATOR(mod, %=) };
- /*---------------. - | optraits_int_u | - `---------------*/ + /*---------------------. + | optraits<uint_value> | + `---------------------*/
- template <class Self> - class optraits_int_u : public optraits_int<Self> + template <class E> + class optraits<uint_value<E> > : public optraits<int_value<E> > { private: - typedef typename typetraits<Self>::storage_type storage_type_; + typedef typename typetraits<E>::storage_type storage_type_;
public: static storage_type_ min () { return 0; } };
- /*---------------. - | optraits_int_s | - `---------------*/ + /*---------------------. + | optraits<sint_value> | + `---------------------*/
- template <class Self> - class optraits_int_s : public optraits_int<Self> + template <class E> + class optraits<sint_value<E> > : public optraits<int_value<E> > {};
} // end of internal Index: integre/ntg/core/value.hh --- integre/ntg/core/value.hh Tue, 13 May 2003 21:32:45 +0200 burrus_n (oln/g/8_rec_value. 1.8.1.8 640) +++ integre/ntg/core/value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/8_rec_value. 1.8.1.9 640) @@ -103,6 +103,18 @@ storage_type val_; };
+ namespace internal { + + template <class E> + struct typetraits<value<E> > + {}; + + template <class E> + struct optraits<value<E> > + {}; + + } + } // end of ntg.
#endif // !NTG_CORE_VALUE_HH Index: integre/ntg/real/typetraits_builtin_int.hh --- integre/ntg/real/typetraits_builtin_int.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/g/3_typetraits 1.7.1.12 640) +++ integre/ntg/real/typetraits_builtin_int.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/g/3_typetraits 1.7.1.13 640) @@ -36,9 +36,9 @@ | macros | `-------*/
-# define TYPETRAITS_BUILTIN_INT(Name) \ +# define TYPETRAITS_BUILTIN_INT(Name, Value) \ template<> \ - struct typetraits<Name> \ + struct typetraits<Name> : public typetraits<Value<Name> > \ { \ typedef Name self; \ typedef builtin::to_ntg<Name>::ret ntg_type; \ @@ -152,18 +152,18 @@
namespace internal {
- TYPETRAITS_BUILTIN_INT(unsigned long) - TYPETRAITS_BUILTIN_INT( signed long) + TYPETRAITS_BUILTIN_INT(unsigned long, uint_value) + TYPETRAITS_BUILTIN_INT(signed long, sint_value)
- TYPETRAITS_BUILTIN_INT(unsigned int) - TYPETRAITS_BUILTIN_INT( signed int) + TYPETRAITS_BUILTIN_INT(unsigned int, uint_value) + TYPETRAITS_BUILTIN_INT(signed int, sint_value)
- TYPETRAITS_BUILTIN_INT(unsigned short) - TYPETRAITS_BUILTIN_INT( signed short) + TYPETRAITS_BUILTIN_INT(unsigned short, uint_value) + TYPETRAITS_BUILTIN_INT(signed short, sint_value)
- TYPETRAITS_BUILTIN_INT(unsigned char) - TYPETRAITS_BUILTIN_INT( signed char) - TYPETRAITS_BUILTIN_INT( char) + TYPETRAITS_BUILTIN_INT(unsigned char, uint_value) + TYPETRAITS_BUILTIN_INT(signed char, sint_value) + TYPETRAITS_BUILTIN_INT(char, sint_value)
} // end of internal.
Index: integre/ntg/real/real_value.hh --- integre/ntg/real/real_value.hh Sun, 04 May 2003 21:38:39 +0200 burrus_n (oln/s/15_real_value 1.2 640) +++ integre/ntg/real/real_value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/15_real_value 1.3 640) @@ -28,42 +28,30 @@ #ifndef NTG_REAL_REAL_VALUE_HH # define NTG_REAL_REAL_VALUE_HH
+# include <ntg/core/type_traits.hh> # include <ntg/core/value.hh>
+# define declare_real_value_type__(Type, Parent) \ + template <class E> \ + class Type : public Parent<E> \ + {}; \ + \ + namespace internal { \ + \ + template <class E> \ + struct typetraits<Type<E> > : public typetraits<Parent<E> > \ + {}; \ + \ + } + namespace ntg {
- /*-----------. - | real_value | - `-----------*/ - - template <class E> - class real_value : public value<E> - {}; - - /*----------. - | int_value | - `----------*/ - - template <class E> - class int_value : public real_value<E> - {}; - - template <class E> - class uint_value : public int_value<E> - {}; - - template <class E> - class sint_value : public int_value<E> - {}; - - /*------------. - | float_value | - `------------*/ - - template <class E> - class float_value : public real_value<E> - {}; + declare_real_value_type__(real_value, value) + declare_real_value_type__(float_value, real_value) + declare_real_value_type__(int_value, real_value) + declare_real_value_type__(uint_value, int_value) + declare_real_value_type__(sint_value, int_value)
} // end of ntg.
Index: integre/ntg/core/internal/traits.hh --- integre/ntg/core/internal/traits.hh Sun, 03 Aug 2003 21:08:04 +0200 burrus_n (oln/s/16_traits.hh 1.4 640) +++ integre/ntg/core/internal/traits.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/16_traits.hh 1.5 640) @@ -62,21 +62,6 @@ | optraits | `---------*/
- // top of hierarchy - template <class T> - struct optraits_top - {}; - - // enumerated types - template <class T> - class optraits_enum : public optraits_top<T> - {}; - - // vectorial types - template <class T> - class optraits_vector : public optraits_top<T> - {}; - //! Associates functions to types. /* It should be specialized for every types. Index: integre/ntg/vect/vect_value.hh --- integre/ntg/vect/vect_value.hh Sun, 27 Jul 2003 19:14:42 +0200 burrus_n (oln/s/22_vect_value 1.2 640) +++ integre/ntg/vect/vect_value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/22_vect_value 1.3 640) @@ -51,6 +51,18 @@ static unsigned size() { return nb_comp; } };
+ namespace internal { + + template <class E> + class typetraits<vect_value<E> > : public typetraits<value<E> > + {}; + + template <class E> + class optraits<vect_value<E> > : public optraits<value<E> > + {}; + + } + }
#endif // !NTG_VECT_VECT_VALUE_HH Index: integre/ntg/enum/enum_value.hh --- integre/ntg/enum/enum_value.hh Sun, 04 May 2003 16:11:37 +0200 burrus_n (oln/s/23_enum_value 1.1 640) +++ integre/ntg/enum/enum_value.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/23_enum_value 1.2 640) @@ -29,6 +29,7 @@ # define NTG_ENUM_ENUM_VALUE_HH
# include <ntg/core/value.hh> +# include <ntg/core/type_traits.hh>
namespace ntg { @@ -41,6 +42,18 @@ class enum_value : public value<E> {};
+ namespace internal { + + template <class E> + class typetraits<enum_value<E> > : public typetraits<value<E> > + {}; + + template <class E> + class optraits<enum_value<E> > : public optraits<value<E> > + {}; + + } + }
#endif // !NTG_ENUM_ENUM_VALUE_HH Index: integre/ntg/real/builtin_float.hh --- integre/ntg/real/builtin_float.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/s/47_builtin_fl 1.3 640) +++ integre/ntg/real/builtin_float.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/s/47_builtin_fl 1.4 640) @@ -47,7 +47,7 @@ `------------------*/
template <> - struct typetraits<float> + struct typetraits<float> : public typetraits<float_value<float> > { typedef float self; typedef decimal abstract_type; @@ -76,7 +76,7 @@ `-------------------*/
template <> - struct typetraits<double> + struct typetraits<double> : public typetraits<float_value<double> > { typedef double self; typedef decimal abstract_type; @@ -105,7 +105,7 @@ `----------------*/
template <> - struct optraits<float> : public optraits_float<float> + struct optraits<float> : public optraits<float_value<float> > { private: typedef float self; @@ -251,7 +251,7 @@ `-----------------*/
template <> - struct optraits<double> : public optraits_float<double> + struct optraits<double> : public optraits<float_value<double> > { private: // shortcuts Index: integre/ntg/real/range.hh --- integre/ntg/real/range.hh Wed, 26 Nov 2003 16:45:27 +0100 burrus_n (oln/t/16_range.hh 1.4 640) +++ integre/ntg/real/range.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/16_range.hh 1.5 640) @@ -46,7 +46,7 @@ `------------------*/
template <class T, class interval, class behavior> - struct typetraits<range<T, interval, behavior> > + struct typetraits<range<T, interval, behavior> > : public typetraits<T> { typedef range<T, interval, behavior> self; typedef ntgi_abstract_type(T) abstract_type; Index: integre/ntg/real/cycle.hh --- integre/ntg/real/cycle.hh Mon, 21 Jul 2003 17:51:12 +0200 burrus_n (oln/t/17_cycle.hh 1.2 640) +++ integre/ntg/real/cycle.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/17_cycle.hh 1.3 640) @@ -46,7 +46,7 @@ `------------------*/
template <class T, class interval> - struct typetraits<cycle<T, interval> > + struct typetraits<cycle<T, interval> > : public typetraits<T> { typedef cycle<T, interval> self; typedef typename typetraits<T>::abstract_type abstract_type; Index: integre/ntg/vect/vec.hh --- integre/ntg/vect/vec.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/t/18_vec.hh 1.7 640) +++ integre/ntg/vect/vec.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/18_vec.hh 1.8 640) @@ -89,7 +89,7 @@ `----------------*/
template <unsigned N, class T, class Self> - struct typetraits<vec<N, T, Self> > + struct typetraits<vec<N, T, Self> > : public typetraits<vect_value<vec<N, T, Self> > > { enum { nb_comp = N };
@@ -186,7 +186,7 @@ `--------------*/
template <unsigned N, class T, class E> - class optraits<vec<N, T, E> > : public optraits_vector<vec<N, T, E> > + class optraits<vec<N, T, E> > : public optraits<vect_value<vec<N, T, E> > > { typedef vec<N, T, E> self; typedef ntgi_storage_type(self) storage_type_; Index: integre/ntg/enum/bin.hh --- integre/ntg/enum/bin.hh Mon, 10 Nov 2003 11:19:49 +0100 burrus_n (oln/t/21_bin.hh 1.5 640) +++ integre/ntg/enum/bin.hh Thu, 27 Nov 2003 11:17:00 +0100 burrus_n (oln/t/21_bin.hh 1.6 640) @@ -49,7 +49,7 @@ `----------------*/
template <> - struct typetraits<bin> + struct typetraits<bin> : typetraits<enum_value<bin> > { typedef binary abstract_type; typedef bin self; @@ -133,7 +133,7 @@ `--------------*/
template <> - struct optraits<bin> : public optraits_enum<bin> + struct optraits<bin> : public optraits<enum_value<bin> > { private: typedef typetraits<bin>::storage_type storage_type_;