proto-1.0 60: Import integre in proto-1.0

Index: ChangeLog from Damien Thivolle <damien@lrde.epita.fr> * tests/utils: New. * tests/utils/tests: New. * tests/utils/tests/debug1: New. * tests/utils/Makefile.am: New. * tests/types: New. * tests/types/tests: New. * tests/types/tests/range3b: New. * tests/types/tests/range3c: New. * tests/types/tests/range3d: New. * tests/types/tests/int_s1: New. * tests/types/tests/int_s2: New. * tests/types/tests/range1: New. * tests/types/tests/range2: New. * tests/types/tests/range3: New. * tests/types/tests/range4: New. * tests/types/tests/int4b: New. * tests/types/tests/bin1: New. * tests/types/tests/bin2: New. * tests/types/tests/bin3: New. * tests/types/tests/sizes: New. * tests/types/tests/unsafe1: New. * tests/types/tests/unsafe2: New. * tests/types/tests/int_u5c: New. * tests/types/tests/float_r1: New. * tests/types/tests/float_r2: New. * tests/types/tests/int1b: New. * tests/types/tests/comp1: New. * tests/types/tests/comp2: New. * tests/types/tests/comp3: New. * tests/types/tests/conv1: New. * tests/types/tests/conv2: New. * tests/types/tests/builtin1: New. * tests/types/tests/float_c1: New. * tests/types/tests/vec1: New. * tests/types/tests/char1: New. * tests/types/tests/vec2: New. * tests/types/tests/op1: New. * tests/types/tests/int_u1: New. * tests/types/tests/vec3: New. * tests/types/tests/int_s2b: New. * tests/types/tests/op2: New. * tests/types/tests/vec4: New. * tests/types/tests/int_u2a: New. * tests/types/tests/vec5: New. * tests/types/tests/int_u2b: New. * tests/types/tests/int_u4: New. * tests/types/tests/vec6: New. * tests/types/tests/int_u2c: New. * tests/types/tests/vec7: New. * tests/types/tests/int_u2d: New. * tests/types/tests/int_u6: New. * tests/types/tests/optrait1a: New. * tests/types/tests/int_u7: New. * tests/types/tests/int_u2e: New. * tests/types/tests/optrait1b: New. * tests/types/tests/int_u8: New. * tests/types/tests/int_u2f: New. * tests/types/tests/int1: New. * tests/types/tests/int2: New. * tests/types/tests/int3: New. * tests/types/tests/int4: New. * tests/types/tests/int5: New. * tests/types/tests/int6: New. * tests/types/tests/range2b: New. * tests/types/tests/int7: New. * tests/types/tests/int6b: New. * tests/types/tests/int6c: New. * tests/types/tests/int6d: New. * tests/types/tests/float1: New. * tests/types/tests/cplx1: New. * tests/types/tests/float2: New. * tests/types/tests/cplx2: New. * tests/types/tests/cplx3: New. * tests/types/tests/cplx4: New. * tests/types/tests/cplx5: New. * tests/types/tests/ntg_compare_nb_comp: New. * tests/types/tests/cplx6: New. * tests/types/tests/int_sc1: New. * tests/types/tests/int_sc2: New. * tests/types/tests/int_u3a: New. * tests/types/tests/int_sc3: New. * tests/types/tests/int_u3b: New. * tests/types/tests/int_sc4: New. * tests/types/tests/int_sc5: New. * tests/types/tests/optrait3: New. * tests/types/tests/optrait2a: New. * tests/types/tests/optrait2b: New. * tests/types/runtests: New. * tests/types/Makefile.am: New. * ntg/real/builtin_properties.hh: New. * ntg/real/builtin_float.hh: New. * ntg/real/range.hh: New. * ntg/real/integer.hh: Remove. * ntg/real/behavior.hh: New. * ntg/real/cycle.hh: New. * ntg/real/optraits_builtin_int.hh: New. * ntg/real/int_u8.hh: Remove. * ntg/real/optraits_real.hh: New. * ntg/real/typetraits_builtin_int.hh: New. * ntg/real/optraits_real_defs.hh: New. * ntg/real/int_s.hh: New. * ntg/real/int_u.hh: New. * ntg/real/real_value.hh: New. * ntg/real/builtin_int.hh: New. * ntg/core/abstract_hierarchy.hh: New. * ntg/core/predecls.hh: New. * ntg/core/type.hh: New. * ntg/core/props.hh: Remove. * ntg/core/macros.hh: Import former macros from integre. * ntg/core/interval.hh: New. * ntg/core/pred_succ.hh: New. * ntg/core/type_traits.hh: New. * ntg/core/math.hh: New. * ntg/core/cats.hh: Remove. * ntg/core/value.hh: New. * ntg/core/contract.hh: New. * ntg/core/internal: New. * ntg/core/internal/global_ops.hh: New. * ntg/core/internal/global_ops_defs.hh: New. * ntg/core/internal/macros.hh: New. * ntg/core/internal/traits.hh: New. * ntg/core/internal/global_ops_traits.hh: New. * ntg/int.hh: New. * ntg/range.hh: New. * ntg/cycle.hh: New. * ntg/utils: New. * ntg/utils/debug.hh: New. * ntg/utils/cast.hh: New. * ntg/vect: New. * ntg/vect/cplx.hh: New. * ntg/vect/cplx_representation.hh: New. * ntg/vect/vect_value.hh: New. * ntg/vect/vec.hh: New. * ntg/basics.hh: New. * ntg/makefile.src: Add new files. * ntg/float.hh: New. * ntg/enum/builtin_bool.hh: New. * ntg/enum/enum.hh: Remove. * ntg/enum/bin.hh: Import from integre. * ntg/enum/enum_value.hh: New. * ntg/cplx.hh: New. * ntg/all.hh: Import from integre. * ntg/bin.hh: New. * ntg/Makefile.am: Import from integre. * ntg/vec.hh: New. * ntg/color.hh: New. * ntg/color/rgb_8.hh: Remove. * ntg/color/yiq.hh: New. * ntg/color/hsi.hh: New. * ntg/color/yuv.hh: New. * ntg/color/hsl.hh: New. * ntg/color/nrgb.hh: New. * ntg/color/rgb.hh: New. * ntg/color/xyz.hh: New. * ntg/color/color.hh: Import from integre. * ntg/color/hsv.hh: New. ntg/Makefile.am | 58 ++ ntg/all.hh | 26 + ntg/basics.hh | 61 +++ ntg/bin.hh | 37 + ntg/color.hh | 44 ++ ntg/color/color.hh | 311 +++++++++++++-- ntg/color/hsi.hh | 63 +++ ntg/color/hsl.hh | 54 ++ ntg/color/hsv.hh | 55 ++ ntg/color/nrgb.hh | 130 ++++++ ntg/color/rgb.hh | 58 ++ ntg/color/rgb_8.hh | 153 ------- ntg/color/xyz.hh | 54 ++ ntg/color/yiq.hh | 64 +++ ntg/color/yuv.hh | 63 +++ ntg/core/abstract_hierarchy.hh | 84 ++++ ntg/core/cats.hh | 77 --- ntg/core/contract.hh | 57 ++ ntg/core/internal/global_ops.hh | 243 ++++++++++++ ntg/core/internal/global_ops_defs.hh | 274 +++++++++++++ ntg/core/internal/global_ops_traits.hh | 213 ++++++++++ ntg/core/internal/macros.hh | 87 ++++ ntg/core/internal/traits.hh | 82 ++++ ntg/core/interval.hh | 118 +++++ ntg/core/macros.hh | 189 +++++++++ ntg/core/math.hh | 82 ++++ ntg/core/pred_succ.hh | 95 ++++ ntg/core/predecls.hh | 134 ++++++ ntg/core/props.hh | 77 --- ntg/core/type.hh | 139 +++++++ ntg/core/type_traits.hh | 66 +++ ntg/core/value.hh | 122 ++++++ ntg/cplx.hh | 37 + ntg/cycle.hh | 37 + ntg/enum/bin.hh | 259 ++++++++++--- ntg/enum/builtin_bool.hh | 87 ++++ ntg/enum/enum.hh | 97 ---- ntg/enum/enum_value.hh | 59 ++ ntg/float.hh | 38 + ntg/int.hh | 42 ++ ntg/makefile.src | 60 ++- ntg/range.hh | 37 + ntg/real/behavior.hh | 462 +++++++++++++++++++++++ ntg/real/builtin_float.hh | 427 +++++++++++++++++++++ ntg/real/builtin_int.hh | 38 + ntg/real/builtin_properties.hh | 162 ++++++++ ntg/real/cycle.hh | 187 +++++++++ ntg/real/int_s.hh | 580 +++++++++++++++++++++++++++++ ntg/real/int_u.hh | 412 ++++++++++++++++++++ ntg/real/int_u8.hh | 131 ------ ntg/real/integer.hh | 94 ---- ntg/real/optraits_builtin_int.hh | 92 ++++ ntg/real/optraits_real.hh | 148 +++++++ ntg/real/optraits_real_defs.hh | 213 ++++++++++ ntg/real/range.hh | 197 +++++++++ ntg/real/real_value.hh | 58 ++ ntg/real/typetraits_builtin_int.hh | 173 ++++++++ ntg/utils/cast.hh | 236 +++++++++++ ntg/utils/debug.hh | 94 ++++ ntg/vec.hh | 35 + ntg/vect/cplx.hh | 655 +++++++++++++++++++++++++++++++++ ntg/vect/cplx_representation.hh | 43 ++ ntg/vect/vec.hh | 443 ++++++++++++++++++++++ ntg/vect/vect_value.hh | 68 +++ tests/types/Makefile.am | 16 tests/types/runtests | 126 ++++++ tests/types/tests/bin1 | 30 + tests/types/tests/bin2 | 37 + tests/types/tests/bin3 | 37 + tests/types/tests/builtin1 | 31 + tests/types/tests/char1 | 33 + tests/types/tests/comp1 | 31 + tests/types/tests/comp2 | 31 + tests/types/tests/comp3 | 31 + tests/types/tests/conv1 | 31 + tests/types/tests/conv2 | 31 + tests/types/tests/cplx1 | 37 + tests/types/tests/cplx2 | 45 ++ tests/types/tests/cplx3 | 44 ++ tests/types/tests/cplx4 | 39 + tests/types/tests/cplx5 | 38 + tests/types/tests/cplx6 | 34 + tests/types/tests/float1 | 30 + tests/types/tests/float2 | 33 + tests/types/tests/float_c1 | 31 + tests/types/tests/float_r1 | 31 + tests/types/tests/float_r2 | 31 + tests/types/tests/int1 | 31 + tests/types/tests/int1b | 30 + tests/types/tests/int2 | 31 + tests/types/tests/int3 | 31 + tests/types/tests/int4 | 30 + tests/types/tests/int4b | 30 + tests/types/tests/int5 | 30 + tests/types/tests/int6 | 31 + tests/types/tests/int6b | 30 + tests/types/tests/int6c | 31 + tests/types/tests/int6d | 32 + tests/types/tests/int7 | 30 + tests/types/tests/int_s1 | 32 + tests/types/tests/int_s2 | 32 + tests/types/tests/int_s2b | 32 + tests/types/tests/int_sc1 | 35 + tests/types/tests/int_sc2 | 33 + tests/types/tests/int_sc3 | 32 + tests/types/tests/int_sc4 | 33 + tests/types/tests/int_sc5 | 30 + tests/types/tests/int_u1 | 30 + tests/types/tests/int_u2a | 30 + tests/types/tests/int_u2b | 30 + tests/types/tests/int_u2c | 30 + tests/types/tests/int_u2d | 31 + tests/types/tests/int_u2e | 31 + tests/types/tests/int_u2f | 32 + tests/types/tests/int_u3a | 31 + tests/types/tests/int_u3b | 31 + tests/types/tests/int_u4 | 30 + tests/types/tests/int_u5c | 31 + tests/types/tests/int_u6 | 32 + tests/types/tests/int_u7 | 31 + tests/types/tests/int_u8 | 37 + tests/types/tests/ntg_compare_nb_comp | 42 ++ tests/types/tests/op1 | 40 ++ tests/types/tests/op2 | 31 + tests/types/tests/optrait1a | 52 ++ tests/types/tests/optrait1b | 52 ++ tests/types/tests/optrait2a | 30 + tests/types/tests/optrait2b | 30 + tests/types/tests/optrait3 | 36 + tests/types/tests/range1 | 65 +++ tests/types/tests/range2 | 30 + tests/types/tests/range2b | 30 + tests/types/tests/range3 | 30 + tests/types/tests/range3b | 30 + tests/types/tests/range3c | 31 + tests/types/tests/range3d | 31 + tests/types/tests/range4 | 31 + tests/types/tests/sizes | 34 + tests/types/tests/unsafe1 | 31 + tests/types/tests/unsafe2 | 30 + tests/types/tests/vec1 | 33 + tests/types/tests/vec2 | 34 + tests/types/tests/vec3 | 36 + tests/types/tests/vec4 | 36 + tests/types/tests/vec5 | 34 + tests/types/tests/vec6 | 36 + tests/types/tests/vec7 | 34 + tests/utils/Makefile.am | 3 tests/utils/tests/debug1 | 41 ++ 149 files changed, 11214 insertions(+), 751 deletions(-) Index: tests/utils/tests/debug1 --- tests/utils/tests/debug1 (revision 0) +++ tests/utils/tests/debug1 (revision 0) @@ -0,0 +1,41 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +// #define NTG_DEBUG + +#include <ntg/int.hh> + +using namespace ntg; + +ntg_debug_define_vars(true) + +int main() +{ + int_u32 u = 65537U * 65535U; + u = u - 1; // ABORT +} Index: tests/utils/Makefile.am --- tests/utils/Makefile.am (revision 0) +++ tests/utils/Makefile.am (revision 0) @@ -0,0 +1,3 @@ +## Process this file with Automake to produce Makefile.in -*- Makefile -*- + +include ../check/Makefile.runtests Index: tests/types/tests/range3b --- tests/types/tests/range3b (revision 0) +++ tests/types/tests/range3b (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +range<int_u8, bounded_u<10, 13>, saturate> u = 20; +return u != 13; Index: tests/types/tests/range3c --- tests/types/tests/range3c (revision 0) +++ tests/types/tests/range3c (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +range<int_u8, bounded_u<10, 13>, saturate> u = 11; +u += u; +return u != 13; Index: tests/types/tests/range3d --- tests/types/tests/range3d (revision 0) +++ tests/types/tests/range3d (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +range<int_u8, bounded_u<10, 13>, saturate> u = 2; +u += 10; +return u != 13; Index: tests/types/tests/int_s1 --- tests/types/tests/int_s1 (revision 0) +++ tests/types/tests/int_s1 (revision 0) @@ -0,0 +1,32 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_s8 s1 = 10; +int_s16 s2 = -20; +int_s8 s3 = s1 + s2; +return s3 != -10; Index: tests/types/tests/int_s2 --- tests/types/tests/int_s2 (revision 0) +++ tests/types/tests/int_s2 (revision 0) @@ -0,0 +1,32 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_s8 s1 = 10; +int_s16 s2 = -200; +int_s8 s3 = s1 + s2; // ABORT +(void) s3; Index: tests/types/tests/range1 --- tests/types/tests/range1 (revision 0) +++ tests/types/tests/range1 (revision 0) @@ -0,0 +1,65 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef range<int_u8, bounded_u<10, 13>, strict> t1; +typedef range<int, bounded_u<5, 72>, strict> t2; +typedef range<float_s, bounded_s<-15, 28>, strict> t3; + +t1 u = 10; +t2 v = 32U; +t3 w = -5.8; + +u = 11; +u = 12; +u = 13; + +ntg_is_a_(t1, unsigned_integer)::ensure(); +mlc_is_a_(t1, uint_value)::ensure(); + +ntg_is_a_(t2, signed_integer)::ensure(); +mlc_is_a_(t2, sint_value)::ensure(); + +ntg_is_a_(t3, decimal)::ensure(); +mlc_is_a_(t3, float_value)::ensure(); + +u + u; +u + 5; +5 + u; +u + int_u16(5); +int_u16(5) + u; + +u * v; +v * 5U; +u / v; + +u + w + v; +u + w * v; + +w + 5; + +return (u + v * w) != -172.6f; Index: tests/types/tests/range2 --- tests/types/tests/range2 (revision 0) +++ tests/types/tests/range2 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +range<int_u8, bounded_u<10, 13>, strict> u = 14; // ABORT +(void) u; Index: tests/types/tests/range3 --- tests/types/tests/range3 (revision 0) +++ tests/types/tests/range3 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +range<int_u8, bounded_u<10, 13>, saturate> u = 9; +return u != 10; Index: tests/types/tests/range4 --- tests/types/tests/range4 (revision 0) +++ tests/types/tests/range4 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +range<int_u8, bounded_u<2, 5> > r1 = 3; +range<int_u16, bounded_u<2, 5> > r2 = 4; +return (r1 + r2) != 7; Index: tests/types/tests/int4b --- tests/types/tests/int4b (revision 0) +++ tests/types/tests/int4b (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7> i = 130; // ABORT +(void) i; Index: tests/types/tests/bin1 --- tests/types/tests/bin1 (revision 0) +++ tests/types/tests/bin1 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +bin b1 = 1; +return !(b1 == true); Index: tests/types/tests/bin2 --- tests/types/tests/bin2 (revision 0) +++ tests/types/tests/bin2 (revision 0) @@ -0,0 +1,37 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +bin b1 = 1; +bin b2 = 0; + +return (min(b1, b2) != bin(0)) + || (min(b1, b1) != bin(1)) + || (min(b2, b2) != bin(0)) + || (max(b1, b2) != bin(1)) + || (max(b1, b1) != bin(1)) + || (max(b2, b2) != bin(0)); Index: tests/types/tests/bin3 --- tests/types/tests/bin3 (revision 0) +++ tests/types/tests/bin3 (revision 0) @@ -0,0 +1,37 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +bin b1 = 1; +bin b2 = 0; + +return ((b1 | b2) != (b1 || b2)) + || ((b1 | b1) != (b1 || b1)) + || ((b2 | b2) != (b2 || b2)) + || ((b1 & b2) != (b1 && b2)) + || ((b1 & b1) != (b1 && b1)) + || ((b2 & b2) != (b1 && b2)); Index: tests/types/tests/sizes --- tests/types/tests/sizes (revision 0) +++ tests/types/tests/sizes (revision 0) @@ -0,0 +1,34 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +// FIXME: add more exhaustive tests based on C_for_* instead of hard coded +// types + +return (sizeof(int_u8) != sizeof(unsigned char)) + || (sizeof(int_u16) != sizeof(unsigned short)) + || (sizeof(range<int_u8, bounded_u<0, 5>, strict>) != sizeof(unsigned char)); Index: tests/types/tests/unsafe1 --- tests/types/tests/unsafe1 (revision 0) +++ tests/types/tests/unsafe1 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<8, unsafe> u = 200; +u += 56; +return u != 0; Index: tests/types/tests/unsafe2 --- tests/types/tests/unsafe2 (revision 0) +++ tests/types/tests/unsafe2 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7, unsafe> u = 140; +(void) u; Index: tests/types/tests/int_u5c --- tests/types/tests/int_u5c (revision 0) +++ tests/types/tests/int_u5c (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32s i(4294967295U); +i = i + int_u32s(1); +return i != 4294967295U; Index: tests/types/tests/float_r1 --- tests/types/tests/float_r1 (revision 0) +++ tests/types/tests/float_r1 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef range<float_s, bounded_s<10, 30>, strict> sr; +sr f = 23.0; +return f <= 22.999 || f >= 23.001; Index: tests/types/tests/float_r2 --- tests/types/tests/float_r2 (revision 0) +++ tests/types/tests/float_r2 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef range<float_s, bounded_s<10, 20>, strict> sr; +sr f = 23.0; // ABORT +(void) f; Index: tests/types/tests/int1b --- tests/types/tests/int1b (revision 0) +++ tests/types/tests/int1b (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7,saturate> i = 130; +return i != 127; Index: tests/types/tests/comp1 --- tests/types/tests/comp1 (revision 0) +++ tests/types/tests/comp1 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_s8 s = -127; +int_u16 u = 65535; +return s >= u || !(s < u); Index: tests/types/tests/comp2 --- tests/types/tests/comp2 (revision 0) +++ tests/types/tests/comp2 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_s16 s = -32768; +int_u32 u = 4294967295U; +return s >= u || !(s < u); Index: tests/types/tests/comp3 --- tests/types/tests/comp3 (revision 0) +++ tests/types/tests/comp3 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_s32 s = -2147483647-1; +int_u32 u = 4294967295U; +return s >= u || !(s < u); Index: tests/types/tests/conv1 --- tests/types/tests/conv1 (revision 0) +++ tests/types/tests/conv1 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +float_s s = 255.8; +int_u8 u = s; // XFAIL: need discussion about float to int conversion +return u != 255; Index: tests/types/tests/conv2 --- tests/types/tests/conv2 (revision 0) +++ tests/types/tests/conv2 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +float_s s = -128.8; +int_s8 u = s; // XFAIL:need discussion about float to int conversion +return u != -128; Index: tests/types/tests/builtin1 --- tests/types/tests/builtin1 (revision 0) +++ tests/types/tests/builtin1 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 i = 11; +unsigned long l = 12; +return l < i; Index: tests/types/tests/float_c1 --- tests/types/tests/float_c1 (revision 0) +++ tests/types/tests/float_c1 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef cycle< float_s, bounded_s< 0, 360 > > sc; +sc f = -400.0; // f == 320.0 +return f <= 319.999 || f >= 320.001; Index: tests/types/tests/vec1 --- tests/types/tests/vec1 (revision 0) +++ tests/types/tests/vec1 (revision 0) @@ -0,0 +1,33 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<3, int> foo; +foo[0] = 5; +foo[1] = 7; +foo[2] = 13; +return foo[0] + foo[1] + foo[2] != 25; Index: tests/types/tests/char1 --- tests/types/tests/char1 (revision 0) +++ tests/types/tests/char1 (revision 0) @@ -0,0 +1,33 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int a = ntg_max_val(char); +a = ntg_max_val(signed char); +a = ntg_max_val(unsigned char); + +return !a; Index: tests/types/tests/vec2 --- tests/types/tests/vec2 (revision 0) +++ tests/types/tests/vec2 (revision 0) @@ -0,0 +1,34 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<3, int> v1; +v1[0] = 5; +v1[1] = 7; +v1[2] = 13; +vec<3, int> v2 = v1; +return v2 != v1; Index: tests/types/tests/op1 --- tests/types/tests/op1 (revision 0) +++ tests/types/tests/op1 (revision 0) @@ -0,0 +1,40 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 a = 2; +int_u8 b = a * a * a * a * a * a * a; // 128 +int_u16 c = b * a; // 256 +int_u16 d = c * b; // 32768 +int_u32 e = d * a; // 65536 +int_u32 f = (e + 1U) * int_u32(e - 1); // 4294967295 +return a != 2 + || b != 128 + || c != 256 + || d != 32768 + || e != 65536 + || f != 4294967295U; Index: tests/types/tests/int_u1 --- tests/types/tests/int_u1 (revision 0) +++ tests/types/tests/int_u1 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 65537U * 65535U; +return u != 4294967295U; Index: tests/types/tests/vec3 --- tests/types/tests/vec3 (revision 0) +++ tests/types/tests/vec3 (revision 0) @@ -0,0 +1,36 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<3, int> v1; +v1[0] = 5; +v1[1] = 7; +v1[2] = 13; +vec<3, int> v2 = v1; +v2 += v2; +v1 *= 2; +return v2 != v1; Index: tests/types/tests/int_s2b --- tests/types/tests/int_s2b (revision 0) +++ tests/types/tests/int_s2b (revision 0) @@ -0,0 +1,32 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_s8 s1 = 10; +int_s16 s2 = -200; +int_s8 s3 = s1 - s2; // ABORT +(void) s3; Index: tests/types/tests/op2 --- tests/types/tests/op2 (revision 0) +++ tests/types/tests/op2 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 a = 65536; +int_u32 b = (a + 1U) * int_u32(a - 1); +return b != 4294967295U; Index: tests/types/tests/vec4 --- tests/types/tests/vec4 (revision 0) +++ tests/types/tests/vec4 (revision 0) @@ -0,0 +1,36 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<3, int_u16> v1; +v1[0] = 5; +v1[1] = 7; +v1[2] = 13; +vec<3, int_u32> v2 = v1; +v2 = v2 + v2; +v1 = v1 * int_u8(2); +return v2 != v1; Index: tests/types/tests/int_u2a --- tests/types/tests/int_u2a (revision 0) +++ tests/types/tests/int_u2a (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 4; +u -= 5; // ABORT Index: tests/types/tests/vec5 --- tests/types/tests/vec5 (revision 0) +++ tests/types/tests/vec5 (revision 0) @@ -0,0 +1,34 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<1, int_u16> v1; +v1[0] = 20; +vec<1, int_u32> v2 = v1; +v2 = v2; +v1 = 2 * v1 / 2; +return v2 != v1; Index: tests/types/tests/int_u2b --- tests/types/tests/int_u2b (revision 0) +++ tests/types/tests/int_u2b (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 4; +u += -5; // ABORT Index: tests/types/tests/int_u4 --- tests/types/tests/int_u4 (revision 0) +++ tests/types/tests/int_u4 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 65537U * 65535U; +u = u - 1; // ABORT Index: tests/types/tests/vec6 --- tests/types/tests/vec6 (revision 0) +++ tests/types/tests/vec6 (revision 0) @@ -0,0 +1,36 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<2, int_s<9> > v1; +v1[0] = 5; +v1[1] = -7; +v1 %= int_u8(3); +vec<2, int_s<9> > v2; +v2[0] = 2; +v2[1] = -1; +return v2 != v1; Index: tests/types/tests/int_u2c --- tests/types/tests/int_u2c (revision 0) +++ tests/types/tests/int_u2c (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 0; +--u; // ABORT Index: tests/types/tests/vec7 --- tests/types/tests/vec7 (revision 0) +++ tests/types/tests/vec7 (revision 0) @@ -0,0 +1,34 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<3, int_u16> v1; +v1[0] = 5; +v1[1] = 7; +v1[2] = 13; +int_u16 v2 = v1 * v1; +return v2 != 5 * 5 + 7 * 7 + 13 * 13; Index: tests/types/tests/int_u2d --- tests/types/tests/int_u2d (revision 0) +++ tests/types/tests/int_u2d (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 0; +u--; // ABORT +std::cout << u << std::endl; Index: tests/types/tests/int_u6 --- tests/types/tests/int_u6 (revision 0) +++ tests/types/tests/int_u6 (revision 0) @@ -0,0 +1,32 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 a = 5; +int_s8 b = -a; + +return a != -b; Index: tests/types/tests/optrait1a --- tests/types/tests/optrait1a (revision 0) +++ tests/types/tests/optrait1a (revision 0) @@ -0,0 +1,52 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u1 = ntg_max_val(int_u32); +int_u16 u2 = ntg_max_val(int_u16); +int_u8 u3 = ntg_max_val(int_u8); +int_s32 s1 = ntg_max_val(int_s32); +int_s16 s2 = ntg_max_val(int_s16); +int_s8 s3 = ntg_max_val(int_s8); +int_u32 u4 = ntg_min_val(int_u32); +int_u16 u5 = ntg_min_val(int_u16); +int_u8 u6 = ntg_min_val(int_u8); +int_s32 s4 = ntg_min_val(int_s32); +int_s16 s5 = ntg_min_val(int_s16); +int_s8 s6 = ntg_min_val(int_s8); +return u1 != 4294967295U + || u2 != 65535U + || u3 != 255 + || s1 != 2147483647 + || s2 != 32767 + || s3 != 127 + || u4 != 0 + || u5 != 0 + || u6 != 0 + || s4 != -2147483647-1 + || s5 != -32768 + || s6 != -128; Index: tests/types/tests/int_u7 --- tests/types/tests/int_u7 (revision 0) +++ tests/types/tests/int_u7 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u16 a = 12; +char c = 3; +return a < c; Index: tests/types/tests/int_u2e --- tests/types/tests/int_u2e (revision 0) +++ tests/types/tests/int_u2e (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 65536; +u *= 65537; // ABORT +std::cout << u << std::endl; Index: tests/types/tests/optrait1b --- tests/types/tests/optrait1b (revision 0) +++ tests/types/tests/optrait1b (revision 0) @@ -0,0 +1,52 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u1 = ntg_max_val(int_u32); +int_u16 u2 = ntg_max_val(int_u16); +int_u8 u3 = ntg_max_val(int_u8); +int_s32 s1 = ntg_max_val(int_s32); +int_s16 s2 = ntg_max_val(int_s16); +int_s8 s3 = ntg_max_val(int_s8); +int_u32 u4 = ntg_min_val(int_u32); +int_u16 u5 = ntg_min_val(int_u16); +int_u8 u6 = ntg_min_val(int_u8); +int_s32 s4 = ntg_min_val(int_s32); +int_s16 s5 = ntg_min_val(int_s16); +int_s8 s6 = ntg_min_val(int_s8); +return u1 != ntg_sup_val(int_u32) + || u2 != ntg_sup_val(int_u16) + || u3 != ntg_sup_val(int_u8) + || s1 != ntg_sup_val(int_s32) + || s2 != ntg_sup_val(int_s16) + || s3 != ntg_sup_val(int_s8) + || u4 != ntg_inf_val(int_u32) + || u5 != ntg_inf_val(int_u16) + || u6 != ntg_inf_val(int_u8) + || s4 != ntg_inf_val(int_s32) + || s5 != ntg_inf_val(int_s16) + || s6 != ntg_inf_val(int_s8); Index: tests/types/tests/int_u8 --- tests/types/tests/int_u8 (revision 0) +++ tests/types/tests/int_u8 (revision 0) @@ -0,0 +1,37 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 u1 = (unsigned char) 56; +int_u8 u2 = (unsigned char) 153; +int_u32 u = 0U; + +for (unsigned i = 0; i < 5000000; ++i) + for (unsigned j = 0; j < 10; ++j) + u = u1 * u2 + int_u8u(i % 50); + +return u != 8617; Index: tests/types/tests/int_u2f --- tests/types/tests/int_u2f (revision 0) +++ tests/types/tests/int_u2f (revision 0) @@ -0,0 +1,32 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u16s a = 65535; +a *= 65538U; +std::cout << a << std::endl; +return a != 65535; Index: tests/types/tests/int1 --- tests/types/tests/int1 (revision 0) +++ tests/types/tests/int1 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7,saturate> i = 130; +int_u<7,saturate> j = 127; +return i != j; Index: tests/types/tests/int2 --- tests/types/tests/int2 (revision 0) +++ tests/types/tests/int2 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7,saturate> i = 130; +i += 10; +return i != 127; Index: tests/types/tests/int3 --- tests/types/tests/int3 (revision 0) +++ tests/types/tests/int3 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7,saturate> i = 130; +i -= 10; +return i != 117; Index: tests/types/tests/int4 --- tests/types/tests/int4 (revision 0) +++ tests/types/tests/int4 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7, strict> i = 130; // ABORT +(void) i; Index: tests/types/tests/int5 --- tests/types/tests/int5 (revision 0) +++ tests/types/tests/int5 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u<7, strict> i = 120; +i += 10; // ABORT Index: tests/types/tests/int6 --- tests/types/tests/int6 (revision 0) +++ tests/types/tests/int6 (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 u8 = 250; +int_u<7, strict> u7 = 6; +u8 += u7; // ABORT Index: tests/types/tests/range2b --- tests/types/tests/range2b (revision 0) +++ tests/types/tests/range2b (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +range<int_u8, bounded_u<10, 13> > u = 14; // ABORT +(void) u; Index: tests/types/tests/int7 --- tests/types/tests/int7 (revision 0) +++ tests/types/tests/int7 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 4294967295U; +return u != 4294967295U; Index: tests/types/tests/int6b --- tests/types/tests/int6b (revision 0) +++ tests/types/tests/int6b (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 u8 = 250; +u8 += 6; // ABORT Index: tests/types/tests/int6c --- tests/types/tests/int6c (revision 0) +++ tests/types/tests/int6c (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 u8 = 250; +int_u<9, strict> u9 = 6; +u8 += u9; // ABORT Index: tests/types/tests/int6d --- tests/types/tests/int6d (revision 0) +++ tests/types/tests/int6d (revision 0) @@ -0,0 +1,32 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u8 u8 = 250; +int_u<9, strict> u9 = 6; +u9 += u8; +return u9 != 256; Index: tests/types/tests/float1 --- tests/types/tests/float1 (revision 0) +++ tests/types/tests/float1 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +float_s pi = M_PI; +return sin(pi) == 0.0; Index: tests/types/tests/cplx1 --- tests/types/tests/cplx1 (revision 0) +++ tests/types/tests/cplx1 (revision 0) @@ -0,0 +1,37 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +cplx<rect, int> rect1(42, 51); +cplx<polar, float> polar1(rect1); +vec<2, int_u8> v1(rect1); +cplx<rect, float_s> rect2(v1); + +polar1 = rect2; +rect1 += 69; + +std::cout << rect1 << " | " << polar1 << " | " << rect2 << std::endl; Index: tests/types/tests/float2 --- tests/types/tests/float2 (revision 0) +++ tests/types/tests/float2 (revision 0) @@ -0,0 +1,33 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +float_s f = 0.25; +int_u8 a = 2; +f *= a; // f == 0.5 +f += a; // f == 2.5 +return f != 2.5; Index: tests/types/tests/cplx2 --- tests/types/tests/cplx2 (revision 0) +++ tests/types/tests/cplx2 (revision 0) @@ -0,0 +1,45 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +cplx<rect, float_d> rect1(4, 5); +cplx<rect, float_d> rect2(rect1); +cplx<polar, int> polar1(rect1); +cplx<polar, int> polar2(polar1); + + +rect1 += rect1; +rect1 *= rect1; +rect1 -= rect2; +rect1 /= rect2; + +polar1 += polar1; +polar1 *= polar1; +polar1 -= polar2; +polar1 /= polar2; + +std::cout << rect1 << " | " << polar1.to_rect() << std::endl; Index: tests/types/tests/cplx3 --- tests/types/tests/cplx3 (revision 0) +++ tests/types/tests/cplx3 (revision 0) @@ -0,0 +1,44 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +cplx<rect, float> rect1(4, 5); +cplx<rect, float> rect2(rect1); +cplx<polar, float_s> polar1(rect1); +cplx<polar, float_s> polar2(polar1); + +rect1 += polar2; +rect1 *= polar2; +rect1 -= polar2; +rect1 /= polar2; + +polar1 += rect2; +polar1 *= rect2; +polar1 -= rect2; +polar1 /= rect2; + +std::cout << rect1 << " | " << polar1.to_rect() << std::endl; Index: tests/types/tests/cplx4 --- tests/types/tests/cplx4 (revision 0) +++ tests/types/tests/cplx4 (revision 0) @@ -0,0 +1,39 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<2, int_u16> v; +v[0] = 51; +v[1] = 69; +cplx<rect, int_u16> rect1(v); +cplx<rect, float_s> rect2(rect1[0], rect1[1]); +cplx<polar, double> polar1(rect1); +cplx<polar, double> polar2(rect2); +rect1 = 3 + polar1 + 2; +polar1 = 2 * (rect1 + 3 * polar1 / rect2.conj()) / 3; + +std::cout << rect1 << " | " << polar1.to_rect() << std::endl; Index: tests/types/tests/cplx5 --- tests/types/tests/cplx5 (revision 0) +++ tests/types/tests/cplx5 (revision 0) @@ -0,0 +1,38 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +vec<2, int_s16> v; +v[0] = 51; +v[1] = 69; +vec<2, int_s16> v2; +v2[0] = 0; +v2[1] = 0; +cplx<rect, int_u16> rect1(42, 42); +void(rect1 + rect1); +return 0; // FIXME +//return ((rect1 + v) != (v + rect1)) || ((v - rect1) + (rect1 - v) == v2); Index: tests/types/tests/ntg_compare_nb_comp --- tests/types/tests/ntg_compare_nb_comp (revision 0) +++ tests/types/tests/ntg_compare_nb_comp (revision 0) @@ -0,0 +1,42 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +bool should_just_compile; +should_just_compile = ntg_if_vectorial_nb_comp_(int); + +bool fail = false; +fail = fail || ntg_if_vectorial_nb_comp_(ntg::rgb_8) != 3; +typedef ntg::vec<3, bool> vec3; +typedef ntg::vec<4, bool> vec4; +fail = fail || ntg_if_vectorial_nb_comp_(vec3) != 3; +fail = fail || ntg_if_vectorial_nb_comp_(vec4) != 4; +fail = fail || ntg_compare_nb_comp_(int, ntg::rgb_8)::ret != 0; +fail = fail || ntg_compare_nb_comp_(int, float)::ret != 1; +fail = fail || ntg_compare_nb_comp_(vec3, ntg::rgb_8)::ret != 1; +fail = fail || ntg_compare_nb_comp_(vec4, ntg::rgb_8)::ret != 0; +return fail; Index: tests/types/tests/cplx6 --- tests/types/tests/cplx6 (revision 0) +++ tests/types/tests/cplx6 (revision 0) @@ -0,0 +1,34 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +cplx<rect, float_d> rect1(42, 51); +cplx<rect, float_d> rect2(rect1); +cplx<polar, float_d> polar1(rect1); +cplx<polar, float_d> polar2(polar1); + +return !(rect1 == rect2 && polar1 == polar2); Index: tests/types/tests/int_sc1 --- tests/types/tests/int_sc1 (revision 0) +++ tests/types/tests/int_sc1 (revision 0) @@ -0,0 +1,35 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef cycle<int_s8, bounded_s<-128, +128> > int_s8c; +int_s8c a = 300; // a == 44 +int_s8c b = 10; +b -= 20; // b == -10 +int_s8c c = b; +c -= 290; // c == -44 +return a != 44 || b != -10 || c != -a || c + a != 0; Index: tests/types/tests/int_sc2 --- tests/types/tests/int_sc2 (revision 0) +++ tests/types/tests/int_sc2 (revision 0) @@ -0,0 +1,33 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef cycle<int_s8, bounded_s<-3, +12> > type; +type a = 14; // a = -1 +type b = a * 2; // b = -2 +type c = b * 2; // c = 11 +return a != -1 || b != -2 || c != 11; Index: tests/types/tests/int_u3a --- tests/types/tests/int_u3a (revision 0) +++ tests/types/tests/int_u3a (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 65537U * 65535U; +u--; +return u != 4294967294U; Index: tests/types/tests/int_sc3 --- tests/types/tests/int_sc3 (revision 0) +++ tests/types/tests/int_sc3 (revision 0) @@ -0,0 +1,32 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef cycle<int_s8, bounded_s<-128, +127> > int_s8c; +int_s8c a = 255; // a == 0 +int_s8c b = 256; // b == 1 +return a != 0 || b != 1; Index: tests/types/tests/int_u3b --- tests/types/tests/int_u3b (revision 0) +++ tests/types/tests/int_u3b (revision 0) @@ -0,0 +1,31 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +int_u32 u = 65537U * 65535U; +--u; +return u != 4294967294U; Index: tests/types/tests/int_sc4 --- tests/types/tests/int_sc4 (revision 0) +++ tests/types/tests/int_sc4 (revision 0) @@ -0,0 +1,33 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +typedef cycle<int_u32, bounded_u<0, 65536U * 65536U - 10> > int_u32c; +int_u32c a = 65536; // a == 65536 +a *= 65537; // a == 65446 // XFAIL: don't know how to calculate + // modulus when an overflow occurs +return a != 65546; Index: tests/types/tests/int_sc5 --- tests/types/tests/int_sc5 (revision 0) +++ tests/types/tests/int_sc5 (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +cycle<int_u8, bounded_u<0,5> > c1 = 1U; +return !c1; Index: tests/types/tests/optrait3 --- tests/types/tests/optrait3 (revision 0) +++ tests/types/tests/optrait3 (revision 0) @@ -0,0 +1,36 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +float_s s1 = ntg_sup_val(float_s); +float_d d1 = ntg_sup_val(float_d); +float_s s2 = ntg_inf_val(float_s); +float_d d2 = ntg_inf_val(float_d); +return s1 != NTG_FLOAT_INFINITY + || d1 != NTG_DOUBLE_INFINITY + || s2 != - NTG_FLOAT_INFINITY + || d2 != - NTG_DOUBLE_INFINITY; Index: tests/types/tests/optrait2a --- tests/types/tests/optrait2a (revision 0) +++ tests/types/tests/optrait2a (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +float_s s = ntg_max_val(float_s); // COMPFAIL +(void) s; Index: tests/types/tests/optrait2b --- tests/types/tests/optrait2b (revision 0) +++ tests/types/tests/optrait2b (revision 0) @@ -0,0 +1,30 @@ +// -*- c++ -*- +// Copyright (C) 2004 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. + +float_d s = ntg_min_val(float_d); // COMPFAIL +(void) s; Index: tests/types/runtests --- tests/types/runtests (revision 0) +++ tests/types/runtests (revision 0) @@ -0,0 +1,126 @@ +#!/bin/sh + +if test "x$VERBOSE" != x; then + verb='echo' + quiet='' +else + verb=':' + quiet='-q' +fi + +exec 6>&2 +. ../check/defs +exec 2>&6 + +failures=0 + +indir=${SRCDIR-.}/tests +rundir=runs +test -d $rundir || mkdir $rundir + +if test "$# = 0 -a ${TESTS+set}"; then + set $TESTS +fi + +# If no tests were given on the command line, get the list from $indir. +if test $# = 0; then + set dummy $indir/* + shift +fi + +for test; do + if test -d $test; then continue; fi + echo $test | grep '~$' && continue; + # We want only the basename of $test. + test=`basename "$test"` + fail=0 + dir=$rundir/$test + input=$indir/$test + test -f $input || { + echo "FAIL: $test (does not exist)" >&2 + failures=`expr $failures + 1` + continue; } + rm -rf $dir + mkdir $dir + # Build the source code to compile. + src=$dir/$test.cc + cat >$src <<'EOF' +#include <ntg/all.hh> +using namespace ntg; +int main() { +EOF + cat $input >>$src + echo '}' >>$src + # Build the compile script (using such a script make it easier + # to debug failures); + cat >$dir/try <<EOF +exec 6>&2 +if test "x\$1" = "x-q"; then + exec 2>$dir/cxx.errors +else + echo $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS $dir/$test.cc +fi +$CXX $CPPFLAGS $CXXFLAGS $LDFLAGS "$dir/$test.cc" -o "$dir/test$EXEEXT" || exit 50 + +if test "x\$1" = "x-q"; then + exec 2>$dir/run.errors +else + echo $dir/test$EXEEXT +fi +$dir/test$EXEEXT +estatus=\$? + +exec 2>&6 +echo \$estatus > $dir/exit.status +exit \$estatus +EOF + chmod +x $dir/try + + # Do we expect a failure? + expected=ok + grep '//.*ABORT' $input >/dev/null && expected=abort + grep '//.*COMPFAIL' $input >/dev/null && expected=compfail + + # Do we know the test fails ? + xfail=no + grep '//.*XFAIL' $input >/dev/null && xfail=yes + + # Run the test. + $verb ========== Running $test... >&2 + ($SHELL $dir/try "$quiet" "$dir") + estatus=$? + + msg=""; + case $expected:$estatus in + ok:0 | compfail:50 | abort:134) + if test ! x"$KEEP_RUNS" = x"1"; then + rm -rf "$dir"; + fi + msg="(ok)" ;; + *:50) msg="(doesn't compile)" ;; + *:134) msg="(aborts at run-time)" ;; + compfail:*) msg="(compiles!)" ;; + abort:*) msg="(doesn't abort!)" ;; + ok:*) msg="(exits with \$?=$estatus)" ;; + *) ;; + esac + if test x"$msg" != x"(ok)"; then + if test "$xfail" = "no"; then + echo "FAIL: $test $msg" >&2 + failures=`expr $failures + 1` + else + echo "XFAIL: $test $msg" >&2 + fi + else + echo "PASS: $test" >&2 + fi +done + +echo ========================================>&2 +if test $failures = 0; then + echo No failures. >&2 + exit 0 +else + echo $failures failures. >&2 + exit 1 +fi Property changes on: tests/types/runtests ___________________________________________________________________ Name: svn:executable + * Index: tests/types/Makefile.am --- tests/types/Makefile.am (revision 0) +++ tests/types/Makefile.am (revision 0) @@ -0,0 +1,16 @@ +## Process this file with Automake to produce Makefile.in -*- Makefile -*- + +EXTRA_DIST = tests runtests + +CLEANFILES = test.core + +check-local: + TOP_SRCDIR=$(top_srcdir) SRCDIR=$(srcdir) \ + TOP_BUILDDIR=$(top_builddir) \ + LDFLAGS="$(LDFLAGS)" \ + CPPFLAGS="$(CPPFLAGS) $(DEFS) -I$(top_builddir)" \ + CXXFLAGS="$(CXXFLAGS) $(CXXFLAGS_OPTIMIZE) $(CXXFLAGS_STRICT_ERRORS)" \ + $(SHELL) $(srcdir)/runtests + +distclean-local: + rm -rf runs Index: ntg/real/builtin_properties.hh --- ntg/real/builtin_properties.hh (revision 0) +++ ntg/real/builtin_properties.hh (revision 0) @@ -0,0 +1,162 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_REAL_BUILTIN_PROPERTIES_HH +# define NTG_REAL_BUILTIN_PROPERTIES_HH + +# include <mlc/math.hh> + +# include <limits.h> +# include <float.h> + +namespace ntg +{ + + /*-------------------. + | C_for_ntg integers | + `-------------------*/ + + template<unsigned nbits> + struct C_for_int_u + { + enum { + mbits = mlc::pow2sup<nbits>::value + }; + typedef typename C_for_int_u<mbits>::type type; + static type max() { + return type((type(1) << nbits) - type(1)); + } + }; + + template<unsigned nbits> + struct C_for_int_s + { + enum { mbits = mlc::pow2sup<nbits>::value }; + typedef typename C_for_int_s<mbits>::type type; + static type min() { + return type(- max() - type(1)); + } + static type max() { + return type((type(1) << (nbits-1)) - type(1)); + } + }; + + template<> + struct C_for_int_u<8> + { + typedef unsigned char type; + static type max() { return UCHAR_MAX; } + }; + + + template<> + struct C_for_int_s<8> + { + typedef signed char type; + static type min() { return CHAR_MIN; } + static type max() { return CHAR_MAX; } + }; + + template<> + struct C_for_int_u<16> + { + typedef unsigned short type; + static type max() { return USHRT_MAX; } + }; + + template<> + struct C_for_int_s<16> + { + typedef signed short type; + static type min() { return SHRT_MIN; } + static type max() { return SHRT_MAX; } + }; + + template<> + struct C_for_int_u<32> + { + typedef unsigned int type; + static type max() { return UINT_MAX; } + }; + + template<> + struct C_for_int_s<32> + { + typedef signed int type; + static type min() { return INT_MIN; } + static type max() { return INT_MAX; } + }; + + // TODO: add 64 bits integers support is they are available. + + /*----------------. + | C_for_ntg float | + `----------------*/ + + // FIXME: this code is not used anywhere, maybe it should be + // removed. + + struct C_for_float_s + { + typedef float type; + static type min() { return FLT_MIN; } + static type max() { return FLT_MAX; } + }; + + struct C_for_float_d + { + typedef double type; + static type min() { return DBL_MIN; } + static type max() { return DBL_MAX; } + }; + + // IEEE : Take a look at epsilon for some conditional (FIXME) + + // FLT_RADIX 2 + // FLT_MANT_DIG 24 + // FLT_DIG 6 + // FLT_MIN_EXP -125 + // FLT_MIN_10_EXP -37 + // FLT_MAX_EXP 128 + // FLT_MAX_10_EXP +38 + // FLT_MIN 1.17549435E-38F + // FLT_MAX 3.40282347E+38F + // FLT_EPSILON 1.19209290E-07F + + // DBL_MANT_DIG 53 + // DBL_DIG 15 + // DBL_MIN_EXP -1021 + // DBL_MIN_10_EXP -307 + // DBL_MAX_EXP 1024 + // DBL_MAX_10_EXP 308 + // DBL_MAX 1.7976931348623157E+308 + // DBL_MIN 2.2250738585072014E-308 + // DBL_EPSILON 2.2204460492503131E-016 + +} // end of ntg. + +#endif // !NTG_REAL_BUILTIN_PROPERTIES_HH Index: ntg/real/builtin_float.hh --- ntg/real/builtin_float.hh (revision 0) +++ ntg/real/builtin_float.hh (revision 0) @@ -0,0 +1,427 @@ +// Copyright (C) 2002, 2003 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 NTG_REAL_BUILTIN_FLOAT_HH +# define NTG_REAL_BUILTIN_FLOAT_HH + +# include <ntg/config/system.hh> +# include <ntg/real/behavior.hh> +# include <ntg/core/internal/global_ops_traits.hh> +# include <ntg/core/internal/traits.hh> +# include <ntg/real/builtin_properties.hh> +# include <ntg/real/optraits_real.hh> +# include <ntg/core/predecls.hh> + +# include <mlc/cmp.hh> + +namespace ntg { + + namespace internal { + + /*------------------. + | typetraits<float> | + `------------------*/ + + template <> + struct typetraits<float> : public typetraits<float_value<float> > + { + typedef float self; + typedef decimal abstract_type; + typedef self ntg_type; + + ntg_build_value_type(float_value<E>); + + typedef optraits<self> optraits_type; + typedef unsafe::get<self> behavior_type; + typedef unsafe abstract_behavior_type; + + typedef self base_type; + typedef self storage_type; + typedef self signed_type; + typedef self unsigned_type; + typedef self cumul_type; + typedef self largest_type; + typedef self signed_largest_type; + typedef self signed_cumul_type; + typedef self unsigned_largest_type; + typedef self unsigned_cumul_type; + typedef self integer_type; + }; + + /*-------------------. + | typetraits<double> | + `-------------------*/ + + template <> + struct typetraits<double> : public typetraits<float_value<double> > + { + typedef double self; + typedef decimal abstract_type; + typedef self ntg_type; + + ntg_build_value_type(float_value<E>); + + typedef optraits<self> optraits_type; + typedef unsafe::get<self> behavior_type; + typedef unsafe abstract_behavior_type; + + typedef self base_type; + typedef self storage_type; + typedef self signed_type; + typedef self unsigned_type; + typedef self cumul_type; + typedef self largest_type; + typedef self signed_largest_type; + typedef self signed_cumul_type; + typedef self unsigned_largest_type; + typedef self unsigned_cumul_type; + typedef self integer_type; + }; + + /*----------------. + | optraits<float> | + `----------------*/ + + template <> + struct optraits<float> : public optraits<float_value<float> > + { + private: + typedef float self; + typedef typetraits<self>::storage_type storage_type_; + + public: + // Don't define min() and max() for float and double. + // This is error-prone because max()-1 == max(). + // Furthermore max()-min() can't be computed. + static storage_type_ sup() { return NTG_FLOAT_INFINITY; } + static storage_type_ inf() { return - sup (); } + static std::string name() { return "float"; } + }; + + /*--------------------------. + | operator traits for float | + `--------------------------*/ + + struct all_float_traits + { + enum { commutative = true }; + typedef float ret; + typedef float impl; + }; + + // + // plus + // + + template <unsigned nbits, class B> + struct operator_traits<operator_plus, float, int_u<nbits, B> > + : all_float_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_plus, float, int_s<nbits, B> > + : all_float_traits {}; + + // We need this because ntg_cast(float) gives float. + // So when using cycle<float,..> + float, it searches + // operator_traits<operator_plus, float,float> + template <> + struct operator_traits<operator_plus, float, float> + : all_float_traits {}; + + // + // minus + // + + template <unsigned nbits, class B> + struct operator_traits<operator_minus, float, int_u<nbits, B> > + : all_float_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_minus, float, int_s<nbits, B> > + : all_float_traits {}; + + template <> + struct operator_traits<operator_minus, float, float> + : all_float_traits {}; + + // + // times + // + + template <unsigned nbits, class B> + struct operator_traits<operator_times, float, int_u<nbits, B> > + : all_float_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_times, float, int_s<nbits, B> > + : all_float_traits {}; + + template <> + struct operator_traits<operator_times, float, float> + : all_float_traits {}; + + // + // div + // + + template <unsigned nbits, class B> + struct operator_traits<operator_div, float, int_u<nbits, B> > + : all_float_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_div, float, int_s<nbits, B> > + : all_float_traits {}; + + template <> + struct operator_traits<operator_div, float, float> + : all_float_traits {}; + + // + // min + // + + template <unsigned nbits, class B> + struct operator_traits<operator_min, float, int_u<nbits, B> > + : all_float_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_min, float, int_s<nbits, B> > + : all_float_traits {}; + + template <> + struct operator_traits<operator_min, float, float> + : all_float_traits {}; + + // + // max + // + + template <unsigned nbits, class B> + struct operator_traits<operator_max, float, int_u<nbits, B> > + : all_float_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_max, float, int_s<nbits, B> > + : all_float_traits {}; + + template <> + struct operator_traits<operator_max, float, float> + : all_float_traits {}; + + // + // Comparison + // + + template <unsigned nbits, class B> + struct operator_traits<operator_cmp, float, int_u<nbits, B> > + : all_float_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_cmp, float, int_s<nbits, B> > + : all_float_traits {}; + + template <> + struct operator_traits<operator_cmp, float, float> + : all_float_traits {}; + + /*-----------------. + | optraits<double> | + `-----------------*/ + + template <> + struct optraits<double> : public optraits<float_value<double> > + { + private: + // shortcuts + typedef double self; + typedef typetraits<self>::storage_type storage_type_; + + public: + // Don't define min() and max() for float and double. + // This is error-prone because max()-1 == max(). + // Furthermore max()-min() can't be computed. + static storage_type_ sup() { return NTG_DOUBLE_INFINITY; } + static storage_type_ inf() { return - sup (); } + static std::string name() { return "double"; } + }; + + /*---------------------------. + | operator traits for double | + `---------------------------*/ + + struct all_double_traits + { + enum { commutative = true }; + typedef double ret; + typedef double impl; + }; + + // + // plus + // + + template <unsigned nbits, class B> + struct operator_traits<operator_plus, double, int_u<nbits, B> > + : all_double_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_plus, double, int_s<nbits, B> > + : all_double_traits {}; + + template <> + struct operator_traits<operator_plus, double, double> + : all_double_traits {}; + + template <> + struct operator_traits<operator_plus, double, float> + : all_double_traits {}; + + // + // minus + // + + template <unsigned nbits, class B> + struct operator_traits<operator_minus, double, int_u<nbits, B> > + : all_double_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_minus, double, int_s<nbits, B> > + : all_double_traits {}; + + template <> + struct operator_traits<operator_minus, double, double> + : all_double_traits {}; + + template <> + struct operator_traits<operator_minus, double, float> + : all_double_traits {}; + + // + // times + // + + template <unsigned nbits, class B> + struct operator_traits<operator_times, double, int_u<nbits, B> > + : all_double_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_times, double, int_s<nbits, B> > + : all_double_traits {}; + + template <> + struct operator_traits<operator_times, double, double> + : all_double_traits {}; + + template <> + struct operator_traits<operator_times, double, float> + : all_double_traits {}; + + // + // div + // + + template <unsigned nbits, class B> + struct operator_traits<operator_div, double, int_u<nbits, B> > + : all_double_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_div, double, int_s<nbits, B> > + : all_double_traits {}; + + template <> + struct operator_traits<operator_div, double, double> + : all_double_traits {}; + + template <> + struct operator_traits<operator_div, double, float> + : all_double_traits {}; + + // + // min + // + + template <unsigned nbits, class B> + struct operator_traits<operator_min, double, int_u<nbits, B> > + : all_double_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_min, double, int_s<nbits, B> > + : all_double_traits {}; + + template <> + struct operator_traits<operator_min, double, double> + : all_double_traits {}; + + template <> + struct operator_traits<operator_min, double, float> + : all_double_traits {}; + + // + // max + // + + template <unsigned nbits, class B> + struct operator_traits<operator_max, double, int_u<nbits, B> > + : all_double_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_max, double, int_s<nbits, B> > + : all_double_traits {}; + + template <> + struct operator_traits<operator_max, double, double> + : all_double_traits {}; + + template <> + struct operator_traits<operator_max, double, float> + : all_double_traits {}; + + // + // Comparison + // + + template <unsigned nbits, class B> + struct operator_traits<operator_cmp, double, int_u<nbits, B> > + : all_double_traits {}; + + template <unsigned nbits, class B> + struct operator_traits<operator_cmp, double, int_s<nbits, B> > + : all_double_traits {}; + + template <> + struct operator_traits<operator_cmp, double, double> + : all_double_traits {}; + + template <> + struct operator_traits<operator_cmp, double, float> + : all_double_traits {}; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_REAL_BUILTIN_FLOAT_HH Index: ntg/real/range.hh --- ntg/real/range.hh (revision 0) +++ ntg/real/range.hh (revision 0) @@ -0,0 +1,197 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_REAL_RANGE_HH +# define NTG_REAL_RANGE_HH + +# include <mlc/is_a.hh> + +# include <ntg/basics.hh> +# include <ntg/core/internal/macros.hh> +# include <ntg/real/optraits_real.hh> + +# include <string> +# include <sstream> + +namespace ntg { + + namespace internal { + + /*------------------. + | typetraits<range> | + `------------------*/ + + template <class T, class interval, class behavior> + struct typetraits<range<T, interval, behavior> > : public typetraits<T> + { + typedef range<T, interval, behavior> self; + typedef ntgi_abstract_type(T) abstract_type; + typedef self ntg_type; + typedef optraits<self> optraits_type; + typedef typename behavior::template get<self> behavior_type; + typedef behavior abstract_behavior_type; + + typedef ntgi_base_type(T) base_type; + typedef T storage_type; + typedef ntgi_signed_type(T) signed_type; + typedef ntgi_unsigned_type(T) unsigned_type; + typedef ntgi_cumul_type(T) cumul_type; + typedef ntgi_largest_type(T) largest_type; + typedef ntgi_signed_largest_type(T) signed_largest_type; + typedef ntgi_signed_cumul_type(T) signed_cumul_type; + typedef ntgi_unsigned_largest_type(T) unsigned_largest_type; + typedef ntgi_unsigned_cumul_type(T) unsigned_cumul_type; + typedef ntgi_integer_type(T) integer_type; + }; + + } // end of internal. + + /*-----------------------------. + | range<T, Interval, Behavior> | + `-----------------------------*/ + + //! Restrict the interval of a type. + /* + Range is a decorator. Thanks to the build_value_type helper in + typetraits, it can insert into a precise place of the hierarchy, + depending on T. + */ + template <class T, class interval, class behavior> + class range : + public type_traits<T>::template build_value_type<range<T, interval, behavior> >::ret + { + public: + typedef range<T, interval, behavior> self; + + private: + typedef ntgi_optraits_type(self) optraits_type; + typedef ntg_base_type(self) base_type; + typedef ntg_storage_type(base_type) base_storage_type; + + public: + range () { this->val_ = 0; } + + template <class U> + range (const U& u) + { + ntg_is_a(U, real)::ensure(); + this->val_ = optraits_type::check(u); + } + template <class U> + self& + operator=(const U& u) + { + this->val_ = optraits_type::check(u); + return *this; + } + + template <class U> + operator U() const { return this->val_; } + }; + + template<class T, class interval, class behavior> + inline std::ostream& + operator<<(std::ostream& stream, const range<T, interval, behavior>& rhs) + { + // Cast useful for range<unsigned char, ...> + stream << (ntg_largest_type(T))(rhs.val()); + return stream; + } + + namespace internal { + + /*----------------. + | optraits<range> | + `----------------*/ + + template<class T, class interval, class behavior> + struct optraits<range<T, interval, behavior> > : public optraits<T> + { + public: + typedef range<T, interval, behavior> self; + + private: + typedef typename typetraits<self>::storage_type storage_type_; + typedef typename behavior::template get<self> behavior_type_; + typedef typename interval::storage_type interval_type_; + + public: + template <class P> + static storage_type_ check(const P& rhs) + { return behavior_type_::check(rhs); } + + static interval_type_ min() + { return interval::min(); } + + static interval_type_ max() + { return interval::max(); } + + static interval_type_ inf() + { return interval::inf(); } + + static interval_type_ sup() + { return interval::sup(); } + + static std::string + name() + { + std::ostringstream out; + out << "range<" << optraits<T>::name() << ", " << interval::name() + << ", " << behavior::name() << ">"<< std::ends; + return out.str(); + } + }; + + /*----------------. + | operator traits | + `----------------*/ + + // Inherit operator traits from the base type. + template <class Op, class T, class I, class B, class U> + struct operator_traits<Op, range<T, I, B>, U> + : public deduce_from_traits<Op, T, U>::deduced_traits + {}; + + // Inherit operator traits from the base type. + template <class Op, class T, class I, class B, class U> + struct operator_traits<Op, U, range<T, I, B> > + : public deduce_from_traits<Op, U, T>::deduced_traits + {}; + + // Inherit operator traits from the base type. + template <class Op, + class T1, class I1, class B1, + class T2, class I2, class B2> + struct operator_traits<Op, range<T1, I1, B1>, range<T2, I2, B2> > + : public deduce_from_traits<Op, T1, T2>::deduced_traits + {}; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_REAL_RANGE_HH Index: ntg/real/integer.hh --- ntg/real/integer.hh (revision 59) +++ ntg/real/integer.hh (working copy) @@ -1,94 +0,0 @@ -// 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 INTEGRE_REAL_INTEGER_HH -# define INTEGRE_REAL_INTEGER_HH - -# include <mlc/any.hh> -# include <mlc/types.hh> - -# include <ntg/core/cats.hh> -# include <ntg/core/props.hh> - -namespace ntg { - - template <typename E> struct integer; - - template <typename E> - struct category_type< integer<E> > { typedef cat::integer ret; }; - - template <> - struct default_props < cat::integer > - { - enum { max_val = 0 }; - typedef mlc::no_type io_type; - - protected: - default_props() {} - }; - - template <typename E> - struct integer : public mlc::any__best_memory<E> - { - typedef E exact_type; - - template <typename V> - exact_type& operator=(const V& rhs) - { - return this->exact().impl_assign(rhs); - } - - bool operator==(int rhs) const - { - return this->exact().impl_eq(rhs); - } - - template <typename I> - bool operator==(const integer<I>& rhs) const - { - return this->exact().impl_eq(rhs.exact()); - } - - template <typename V> - bool operator!=(const V& rhs) const - { - return ! this->operator==(rhs); - } - - template <typename V> - exact_type& operator+(const V& rhs) const - { - return this->exact().impl_add(rhs); - } - - protected : - integer() {} - }; - -} - -#endif // ! INTEGRE_REAL_INTEGER_HH Index: ntg/real/behavior.hh --- ntg/real/behavior.hh (revision 0) +++ ntg/real/behavior.hh (revision 0) @@ -0,0 +1,462 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_REAL_BEHAVIOUR_HH +# define NTG_REAL_BEHAVIOUR_HH + +/* + Behaviors for real datatypes int_u, int_s, etc ... + + <WARNING> Don't forget that behaviors are checked on assignements + and contruction of types, and use comparison, so create only vars + with unsafe behaviors in comparison operators implementation. +*/ + +# include <mlc/bool.hh> +# include <mlc/contract.hh> +# include <mlc/is_a.hh> + +# include <ntg/core/contract.hh> +# include <ntg/core/macros.hh> +# include <ntg/core/type_traits.hh> +# include <ntg/core/value.hh> +# include <ntg/core/internal/macros.hh> +# include <ntg/real/optraits_real.hh> +# include <ntg/real/real_value.hh> +# include <ntg/utils/debug.hh> +# include <ntg/utils/cast.hh> + +# include <string> +# include <sstream> + +// FIXME: there is maybe simpler a way to write that, but we want it +// to be compatible with icc, so the behaviors must stay classes, not +// meta classes. +// FIXME: are these considerations still accurate? + +namespace ntg +{ + + /* + Behaviors work by callbacks. When an operator has some side effect + to apply, it calls the corresponding behavior functions to wrap + the new value to be assigned. + + Example in the constructor of int_u taking an unsigned in parameter: + real_data_value = behavior_type<get<int_u> >::check(value_to_assign); + */ + + /*-------. + | unsafe | + `-------*/ + //! No check performed. + /*! + Same behavior as the underlying builtin type. + */ + struct unsafe + { + template <class T> + struct get + { + typedef ntgi_storage_type(T) storage_type; + + template <class T1, class T2> + static T + check_plus (T1 lhs, T2 rhs) + { return lhs + rhs; } + + template <class T1, class T2> + static T + check_minus (T1 lhs, T2 rhs) + { return lhs - rhs; } + + template <class T1, class T2> + static T + check_times (T1 lhs, T2 rhs) + { return lhs * rhs; } + + template <class T1, class T2> + static T + check_div (T1 lhs, T2 rhs) + { return lhs / rhs; } + + template <class P> + static storage_type + check (const P& p) + { return storage_type(p); } + }; + + static std::string + name() + { return "unsafe"; } + }; + + /*------. + | force | + `------*/ + //! Force the value to be assigned without checks. + /*! + Quite similar to unsafe, but even if the destination type has a + strict behavior, by using cast::force we ensure that no check will + be performed. + + Example: + + int_u<8, strict> a; + a = force::get<int_u<8, strict> >::check_plus(5, 6); + + => no check + + This construction is useful when we want to use code from a + particular behavior to a type defined with another behavior. + */ + struct force + { + template <class T> + struct get + { + typedef ntgi_storage_type(T) storage_type; + + template <class T1, class T2> + static T + check_plus (T1 lhs, T2 rhs) + { return cast::force<T>(lhs + rhs); } + + template <class T1, class T2> + static T + check_minus (T1 lhs, T2 rhs) + { return cast::force<T>(lhs - rhs); } + + template <class T1, class T2> + static T + check_times (T1 lhs, T2 rhs) + { return cast::force<T>(lhs * rhs); } + + template <class T1, class T2> + static T + check_div (T1 lhs, T2 rhs) + { return cast::force<T>(lhs / rhs); } + + template <class P> + static storage_type + check (const P& p) + { return cast::force<T>(p); } + }; + + static std::string + name() + { return "force"; } + }; + + /*-------. + | strict | + `-------*/ + //! Strict checking, abort in there is a problem. + struct strict + { + template <class T> + struct get + { + typedef ntgi_storage_type(T) storage_type; + + // FIXME: These checks are not always useful. We can determine + // in advance the types which can raise overflow + // (eg. int_u<32>), the tests should be performed only in those + // cases! + + // FIXME: check that conditions lead to empty code when + // -DNDEBUG is defined does not have any runtime cost. + + template <class T1, class T2> + static T + check_plus (T1 lhs, T2 rhs) + { + T ret = lhs + rhs; + if (rhs > 0) + ntg_assert(ntg_cast(ret) > lhs); + else + ntg_assert(ntg_cast(ret) <= lhs); + return ret; + } + + template <class T1, class T2> + static T + check_minus (T1 lhs, T2 rhs) + { + T ret = lhs - rhs; + if (rhs > 0) + ntg_assert(ntg_cast(ret) < lhs); + else + ntg_assert(ntg_cast(ret) >= lhs); + return ret; + } + + // FIXME: this check is very slow! Find another solution. + template <class T1, class T2> + static T + check_times (T1 lhs, T2 rhs) + { + T ret = lhs * rhs; + if (rhs != 0) + ntg_assert((ret / rhs) == lhs); + return ret; + } + + template <class T1, class T2> + static T + check_div (T1 lhs, T2 rhs) + { return lhs / rhs; } + + template <class P> + static storage_type + check (const P& p) + { + ntg_assert(ntg_cast(p) <= ntg_max_val(T)); + ntg_assert(ntg_cast(p) >= ntg_min_val(T)); + + return static_cast<storage_type>(p); + } + }; + + static std::string + name() + { return "strict"; } + }; + + /*---------. + | saturate | + `---------*/ + //! Bound values to the nearest limit when an overflow occurs. + struct saturate + { + template <class T> + struct get + { + typedef ntgi_storage_type(T) storage_type; + + template <class T1, class T2> + static T + check_plus (T1 lhs, T2 rhs) + { + T ret = lhs + rhs; + if (rhs > 0) + { + if (ntg_cast(ret) <= lhs) + ret = ntg_max_val(T); + } + else if (ntg_cast(ret) > lhs) + ret = ntg_min_val(T); + return ret; + } + + template <class T1, class T2> + static T + check_minus (T1 lhs, T2 rhs) + { + T ret = lhs - rhs; + if (rhs > 0) + { + if (ntg_cast(ret) > lhs) + ret = ntg_min_val(T); + } + else if (rhs != 0 && ntg_cast(ret) <= lhs) + ret = ntg_max_val(T); + return ret; + } + + // FIXME: this check is very slow ! find another solution ... + template <class T1, class T2> + static T + check_times (T1 lhs, T2 rhs) + { + T ret = lhs * rhs; + if ((ret / rhs) != lhs) + { + // if lhs and rhs signs are equal, we wanted to grow + if ((lhs > 0 && rhs > 0) || (-lhs > 0 && -rhs > 0)) + ret = ntg_max_val(T); + else + ret = ntg_min_val(T); + } + return ret; + } + + template <class T1, class T2> + static T + check_div (T1 lhs, T2 rhs) + { return lhs / rhs; } + + template <class P> + static storage_type + check (const P& p) + { + if (ntg_cast(p) > ntg_max_val(T)) + return ntg_max_val(T); + + if (ntg_cast(p) < ntg_min_val(T)) + return ntg_min_val(T); + + return static_cast<storage_type>(p); + } + }; + + static std::string + name() + { return "saturate"; } + }; + + /*---------------. + | cycle_behavior | + `---------------*/ + //! Apply a modulus when an overflow occurs. + /*! + This behavior is not really useful, but implement cycle<> + internal calculus. You should note that a range<int_u, ..., + cycle_behavior> is different than cycle<int_u, ...>. Refer to the + documentation for more details. + */ + struct cycle_behavior + { + template <class T> + struct get + { + typedef ntgi_storage_type(T) storage_type; + + // FIXME: calculate real values! + + template <class T1, class T2> + static T check_plus (T1 lhs, T2 rhs) + { return lhs + rhs; } + + template <class T1, class T2> + static T check_minus (T1 lhs, T2 rhs) + { return lhs - rhs; } + + template <class T1, class T2> + static T check_times (T1 lhs, T2 rhs) + { return lhs * rhs; } + + template <class T1, class T2> + static T check_div (T1 lhs, T2 rhs) + { return lhs / rhs; } + + // float modulus + struct cycle_fmod + { + static double + exec(double lhs, double rhs) + { return fmod(lhs, rhs); } + }; + + // integer modulus + struct cycle_mod + { + template <class T1, class T2> + static T1 + exec(const T1& lhs, const T2& rhs) + { return lhs % rhs; } + }; + + // FIXME: optimize! + template <class P> + static storage_type + check (const P& rhs) + { + typedef typename mlc::if_<ntg_is_a(P, decimal)::ret, + cycle_fmod, + cycle_mod>::ret cycle_op; + + ntg_type(P) tmp = cycle_op::exec(std::abs(ntg_signed_cast(rhs)), + ntg_max_val(T) - ntg_min_val(T)); + + if (to_ntg(rhs) < 0) + tmp = -tmp; + + if (tmp < ntg_min_val(T)) + return ntg_max_val(T) - ntg_min_val(T) + tmp; + else if (tmp >= ntg_max_val(T)) + return ntg_min_val(T) - ntg_max_val(T) + tmp; + + return tmp; + } + }; + + static std::string + name() { return "cycle_behavior"; } + }; + + namespace internal { + + /*-------------------. + | deduce_op_behavior | + `-------------------*/ + + //! Determine the resulting behavior of an operator return type. + /*! + The algorithm is quite simple and arbitrary, is the two + behaviors are identicals, then use it for the return type. Else + use a strict behavior. + */ + template <class B1, class B2> + struct deduce_op_behavior + { typedef strict ret; }; + + template <class B> + struct deduce_op_behavior<B, B> + { typedef B ret; }; + + /*----------------. + | ret_behavior_if | + `----------------*/ + + //! Determine the behavior to use depending on check requirements. + /*! + If need_check is true, the returned behavior will be the same as + the previously determined return type (generally safe). + + In some cases, no check is required, thus type used to perform + the calculus does not need to be safe. The force behavior is + returned in such cases. + */ + + template <bool need_check, class Ret> + struct ret_behavior_if + { + typedef typename typetraits<Ret>::abstract_behavior_type ret; + }; + + template <class Ret> + struct ret_behavior_if<false, Ret> + { + typedef ntg::force ret; + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_REAL_BEHAVIOUR_HH Index: ntg/real/cycle.hh --- ntg/real/cycle.hh (revision 0) +++ ntg/real/cycle.hh (revision 0) @@ -0,0 +1,187 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_REAL_CYCLE_HH +# define NTG_REAL_CYCLE_HH + +# include <ntg/basics.hh> +# include <ntg/core/internal/macros.hh> +# include <ntg/core/interval.hh> + +# include <mlc/is_a.hh> + +# include <string> +# include <sstream> + +namespace ntg { + + namespace internal { + + /*------------------. + | typetraits<cycle> | + `------------------*/ + + template <class T, class interval> + struct typetraits<cycle<T, interval> > : public typetraits<T> + { + typedef cycle<T, interval> self; + typedef typename typetraits<T>::abstract_type abstract_type; + typedef self ntg_type; + typedef optraits<self> optraits_type; + typedef cycle_behavior::get<self> behavior_type; + typedef cycle_behavior abstract_behavior_type; + + typedef typename typetraits<T>::base_type base_type; + typedef T storage_type; + typedef typename typetraits<T>::signed_type signed_type; + typedef typename typetraits<T>::unsigned_type unsigned_type; + typedef self cumul_type; + typedef self largest_type; + typedef self signed_largest_type; + typedef self signed_cumul_type; + typedef self unsigned_largest_type; + typedef self unsigned_cumul_type; + typedef typename typetraits<T>::integer_type integer_type; + }; + + } // end of internal. + + /*-------------------. + | cycle<T, interval> | + `-------------------*/ + + template <class T, + class interval> + class cycle : + public type_traits<T>::template build_value_type<cycle<T, interval> >::ret + { + public: + typedef cycle<T, interval> self; + + private: + typedef ntgi_optraits_type(self) optraits_type; + typedef ntg_base_type(self) base_type; + typedef ntgi_storage_type(base_type) base_storage_type; + + public: + cycle () { this->val_ = 0; } + + template <class U> + cycle (const U& u) + { + ntg_is_a(U, real)::ensure(); + this->val_ = optraits_type::check(u); + } + template <class U> + self& + operator=(const U& u) + { + this->val_ = optraits_type::check(u); + return *this; + } + + operator base_storage_type() const { return this->val_; } + }; + + template<class T, class interval> + inline std::ostream& + operator<<(std::ostream& stream, const cycle<T, interval>& rhs) + { + // FIXME: cast needed for cycle<unsigned char, ...>. + stream << (ntg_largest_type(T))(rhs.val()); + return stream; + } + + namespace internal { + + /*----------------. + | optraits<cycle> | + `----------------*/ + + template<class T, + class interval> + struct optraits<cycle<T, interval> > : public optraits<T> + { + public: + typedef cycle<T, interval> self; + + private: + typedef typename typetraits<self>::storage_type storage_type_; + typedef typename interval::storage_type interval_type_; + typedef typename typetraits<self>::behavior_type behavior_type_; + + public: + static interval_type_ min() + { return interval::min(); } + + static interval_type_ max() + { return interval::max(); } + + static interval_type_ inf() + { return interval::inf(); } + + static interval_type_ sup() + { return interval::sup(); } + + template <class P> + static storage_type_ + check(const P& rhs) + { return behavior_type_::check(rhs); } + + static std::string + name() + { + std::ostringstream out; + out << "cycle<" << optraits<T>::name() << ", " + << interval::name() << ">"<< std::ends; + return out.str(); + } + }; + + // Inherit operator traits from the base type. + template <class Op, class T, class I, class U> + struct operator_traits<Op, cycle<T, I>, U> + : public deduce_from_traits<Op, T, U>::deduced_traits + {}; + + // Inherit operator traits from the base type. + template <class Op, class T, class I, class U> + struct operator_traits<Op, U, cycle<T, I> > + : public deduce_from_traits<Op, U, T>::deduced_traits + {}; + + // Inherit operator traits from the base type. + template <class Op, class T1, class I1, class T2, class I2> + struct operator_traits<Op, cycle<T1, I1>, cycle<T2, I2> > + : public deduce_from_traits<Op, T1, T2>::deduced_traits + {}; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_REAL_CYCLE_HH Index: ntg/real/optraits_builtin_int.hh --- ntg/real/optraits_builtin_int.hh (revision 0) +++ ntg/real/optraits_builtin_int.hh (revision 0) @@ -0,0 +1,92 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_REAL_OPTRAITS_BUILTIN_INT_HH +# define NTG_REAL_OPTRAITS_BUILTIN_INT_HH + +/* + optraits for integer builtin types +*/ + +# include <ntg/config/system.hh> +# include <ntg/real/optraits_real.hh> +# include <ntg/real/typetraits_builtin_int.hh> + +// FIXME: this should be included by system.hh. +# include <limits.h> + +# include <string> + +/*-------. +| macros | +`-------*/ + +# define OPTRAITS_BUILTIN_INT_U(Name, Max) \ + template <> \ + struct optraits<Name > : public optraits<uint_value<Name > > \ + { \ + static Name max() { return Max; } \ + static std::string name() { return std::string(#Name); } \ + } + +# define OPTRAITS_BUILTIN_INT_S(Name, Min, Max) \ + template <> \ + struct optraits<Name > : public optraits<sint_value<Name > > \ + { \ + static Name min() { return Min; } \ + static Name max() { return Max; } \ + static std::string name() { return std::string(#Name); } \ + } + +namespace ntg { + + namespace internal { + + /* + dev note : optraits<builtins> arithmetic operators are only + called when there is an operator_xxx_traits defined, else + builtin are converted into oln type. + */ + + OPTRAITS_BUILTIN_INT_U(unsigned long, ULONG_MAX); + OPTRAITS_BUILTIN_INT_U(unsigned int, UINT_MAX); + OPTRAITS_BUILTIN_INT_U(unsigned short, USHRT_MAX); + OPTRAITS_BUILTIN_INT_U(unsigned char, UCHAR_MAX); + + OPTRAITS_BUILTIN_INT_S(signed long, LONG_MIN, LONG_MAX); + OPTRAITS_BUILTIN_INT_S(signed int, INT_MIN, INT_MAX); + OPTRAITS_BUILTIN_INT_S(signed short, SHRT_MIN, SHRT_MAX); + // char is not the same as signed char. + OPTRAITS_BUILTIN_INT_S(signed char, CHAR_MIN, CHAR_MAX); + // FIXME: whether char is signed or not is implementation defined. + OPTRAITS_BUILTIN_INT_S(char, CHAR_MIN, CHAR_MAX); + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_REAL_OPTRAITS_BUILTIN_INT_HH Index: ntg/real/int_u8.hh --- ntg/real/int_u8.hh (revision 59) +++ ntg/real/int_u8.hh (working copy) @@ -1,131 +0,0 @@ -// 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 INTEGRE_REAL_INT_U8_HH -# define INTEGRE_REAL_INT_U8_HH - -# include <mlc/traits.hh> - -# include <ntg/core/cats.hh> -# include <ntg/core/props.hh> -# include <ntg/real/integer.hh> - -namespace ntg { - - struct int_u8; - - template <> - struct category_type< int_u8 > { typedef cat::integer ret; }; - - template <> - struct props<cat::integer, int_u8> : public default_props<cat::integer> - { - enum { max_val = 255 }; - typedef char io_type; - }; - - - struct int_u8: public integer<int_u8> - { - int_u8() : - value_(0) - { - } - - int_u8(unsigned char value) : - value_(value) - { - } - - int_u8(const int_u8& rhs) : - value_(rhs) - { - } - - int_u8& impl_assign(const int_u8& rhs) - { - this->value_ = rhs; - return *this; - } - - int_u8& impl_assign(const unsigned char& rhs) - { - this->value_ = rhs; - return *this; - } - - operator unsigned char() const - { - return value_; - } - -// template <typename V> -// bool impl_eq(const V& rhs) const -// { -// return this->value_ == rhs; -// } - - bool impl_eq(int rhs) const - { - return this->value_ == rhs; - } - - bool impl_eq(const int_u8& rhs) const - { - return this->value_ == (unsigned char)rhs; - } - - template <typename V> - int_u8 impl_add(const V& rhs) const - { - int_u8 tmp(this->value_ + rhs); - return tmp; - } - - private: - - unsigned char value_; - }; - - -} // end of namespace ntg - - - -namespace mlc { - - template <> - struct traits < ntg::int_u8 > - { - typedef unsigned char encoding_type; - }; - -} // end of namespace mlc - - - -#endif // ! INTEGRE_REAL_INT_U8_HH Index: ntg/real/optraits_real.hh --- ntg/real/optraits_real.hh (revision 0) +++ ntg/real/optraits_real.hh (revision 0) @@ -0,0 +1,148 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_OPTRAITS_REAL_HH_ +# define NTG_OPTRAITS_REAL_HH_ + +# include <cmath> + +# include <mlc/is_a.hh> + +# include <ntg/real/real_value.hh> +# include <ntg/core/type_traits.hh> +# include <ntg/core/abstract_hierarchy.hh> + +// -- + +# include <ntg/core/internal/global_ops_traits.hh> +# include <ntg/core/macros.hh> + +// macros definitions +# include <ntg/real/optraits_real_defs.hh> + +namespace ntg { + + namespace internal { + + /*---------------------. + | optraits<real_value> | + `---------------------*/ + + //! Implement common operators for scalars + template <class E> + class optraits<real_value<E> > : public optraits<value<E> > + { + private: + typedef typename typetraits<E>::storage_type storage_type_; + + public: + static storage_type_ zero () { return 0; } + static storage_type_ unit () { return 1; } + static storage_type_ default_val() { return zero(); } + + // + // dev note : the aim of these default operators is to check the kind + // of operands (value or not), and then call the good function. + // + // ASSIGN_SCALAR_OPERATOR includes default check_xxx_equal functions + // + + ASSIGN_SCALAR_OPERATOR(plus) + ASSIGN_SCALAR_OPERATOR(minus) + ASSIGN_SCALAR_OPERATOR(times) + ASSIGN_SCALAR_OPERATOR(div) + + ARITH_SCALAR_OPERATOR(plus) + ARITH_SCALAR_OPERATOR(minus) + ARITH_SCALAR_OPERATOR(times) + ARITH_SCALAR_OPERATOR(div) + + CMP_SCALAR_OPERATOR(cmp_eq, ==) + CMP_SCALAR_OPERATOR(cmp_lt, <) + }; + + /*----------------------. + | 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_value> | + `--------------------*/ + + template <class E> + class optraits<int_value<E> > : public optraits<real_value<E> > + { + typedef typename typetraits<E>::storage_type storage_type_; + + public: + 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<E>::max())) + 1; + } + + ASSIGN_INT_OPERATOR(mod_equal, %) + ARITH_INT_OPERATOR(mod, %=) + }; + + /*---------------------. + | optraits<uint_value> | + `---------------------*/ + + template <class E> + class optraits<uint_value<E> > : public optraits<int_value<E> > + { + private: + typedef typename typetraits<E>::storage_type storage_type_; + + public: + static storage_type_ min () { return 0; } + }; + + /*---------------------. + | optraits<sint_value> | + `---------------------*/ + + template <class E> + class optraits<sint_value<E> > : public optraits<int_value<E> > + {}; + + } // end of internal + +} // end of ntg + +#endif // ndef NTG_OPTRAITS_REAL_HH_ Index: ntg/real/typetraits_builtin_int.hh --- ntg/real/typetraits_builtin_int.hh (revision 0) +++ ntg/real/typetraits_builtin_int.hh (revision 0) @@ -0,0 +1,173 @@ +// Copyright (C) 2002, 2003, 2004 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 NTG_REAL_TYPETRAITS_BUILTIN_INT_HH +# define NTG_REAL_TYPETRAITS_BUILTIN_INT_HH + +# include <ntg/real/behavior.hh> +# include <ntg/core/predecls.hh> +# include <ntg/core/type_traits.hh> + +/*-------. +| macros | +`-------*/ + +# define TYPETRAITS_BUILTIN_INT(Name, Value) \ + template<> \ + struct typetraits<Name> : public typetraits<Value<Name > > \ + { \ + typedef Name self; \ + typedef builtin::to_ntg<Name >::ret ntg_type; \ + typedef builtin::abstract_trait<Name >::ret abstract_type; \ + template <class E> \ + struct build_value_type \ + { \ + typedef typename builtin::value_type<Name, E >::ret ret; \ + }; \ + \ + typedef optraits<self> optraits; \ + typedef unsafe::get<self> behavior_type; \ + typedef unsafe abstract_behavior_type; \ + \ + typedef self base_type; \ + typedef self storage_type; \ + typedef builtin::signed_trait<Name >::ret signed_type; \ + typedef builtin::unsigned_trait<Name >::ret unsigned_type; \ + typedef builtin::cumul_trait<Name >::ret cumul_type; \ + typedef builtin::largest_trait<Name >::ret largest_type; \ + typedef builtin::signed_largest_trait<Name >::ret signed_largest_type; \ + typedef builtin::signed_cumul_trait<Name >::ret signed_cumul_type; \ + typedef builtin::unsigned_largest_trait<Name >::ret unsigned_largest_type; \ + typedef builtin::unsigned_cumul_trait<Name >::ret unsigned_cumul_type; \ + typedef self integer_type; \ + }; + +namespace ntg { + + namespace builtin { + + template <class T> + struct abstract_trait { typedef unsigned_integer ret; }; + template <> struct abstract_trait<signed long> { typedef signed_integer ret; }; + template <> struct abstract_trait<signed int> { typedef signed_integer ret; }; + template <> struct abstract_trait<signed short> { typedef signed_integer ret; }; + template <> struct abstract_trait<signed char> { typedef signed_integer ret; }; + template <> struct abstract_trait< char> { typedef signed_integer ret; }; + + template <class T> + struct signed_trait { typedef T ret; }; + template <> struct signed_trait<unsigned long> { typedef signed long ret; }; + template <> struct signed_trait<unsigned int> { typedef signed int ret; }; + template <> struct signed_trait<unsigned short> { typedef signed int ret; }; + template <> struct signed_trait<unsigned char> { typedef signed short ret; }; + + template <class T> + struct unsigned_trait { typedef T ret; }; + template <> struct unsigned_trait<signed long> { typedef unsigned long ret; }; + template <> struct unsigned_trait<signed int> { typedef unsigned int ret; }; + template <> struct unsigned_trait<signed short> { typedef unsigned short ret; }; + template <> struct unsigned_trait<signed char> { typedef unsigned char ret; }; + template <> struct unsigned_trait< char> { typedef unsigned char ret; }; + + template <class T> + struct cumul_trait { typedef T ret; }; + template <> struct cumul_trait<unsigned short> { typedef unsigned int ret; }; + template <> struct cumul_trait< signed short> { typedef signed int ret; }; + template <> struct cumul_trait<unsigned char> { typedef unsigned short ret; }; + template <> struct cumul_trait< signed char> { typedef signed short ret; }; + template <> struct cumul_trait< char> { typedef signed short ret; }; + + template <class T> + struct largest_trait { typedef T ret; }; + template <> struct largest_trait<unsigned short> { typedef unsigned int ret; }; + template <> struct largest_trait< signed short> { typedef signed int ret; }; + template <> struct largest_trait<unsigned char> { typedef unsigned int ret; }; + template <> struct largest_trait< signed char> { typedef signed int ret; }; + template <> struct largest_trait< char> { typedef signed int ret; }; + + template <class T> + struct signed_largest_trait { typedef signed int ret; }; + template <> struct signed_largest_trait<unsigned long> { typedef signed long ret; }; + + template <class T> + struct signed_cumul_trait { typedef signed int ret; }; + template <> struct signed_cumul_trait<unsigned long> { typedef signed long ret; }; + template <> struct signed_cumul_trait<unsigned char> { typedef signed short ret; }; + template <> struct signed_cumul_trait< signed char> { typedef signed short ret; }; + template <> struct signed_cumul_trait< char> { typedef signed short ret; }; + + template <class T> + struct unsigned_largest_trait { typedef unsigned int ret; }; + template <> struct unsigned_largest_trait< signed long> { typedef unsigned long ret; }; + + template <class T> + struct unsigned_cumul_trait { typedef unsigned int ret; }; + template <> struct unsigned_cumul_trait<signed long> { typedef unsigned long ret; }; + template <> struct unsigned_cumul_trait<unsigned char> { typedef unsigned short ret; }; + template <> struct unsigned_cumul_trait< signed char> { typedef unsigned short ret; }; + template <> struct unsigned_cumul_trait< char> { typedef unsigned short ret; }; + + template<class T> struct to_ntg { typedef T ret; }; + template<> struct to_ntg<unsigned char> { typedef int_u8u ret; }; + template<> struct to_ntg< signed char> { typedef int_s8u ret; }; + template<> struct to_ntg< char> { typedef int_s8u ret; }; + template<> struct to_ntg<unsigned short> { typedef int_u16u ret; }; + template<> struct to_ntg< signed short> { typedef int_s16u ret; }; + template<> struct to_ntg<unsigned int> { typedef int_u32u ret; }; + template<> struct to_ntg< signed int> { typedef int_s32u ret; }; + template<> struct to_ntg<unsigned long> { typedef int_u32u ret; }; + template<> struct to_ntg< signed long> { typedef int_s32u ret; }; + + template <class T, class E> struct value_type { typedef uint_value<E> ret; }; + template <class E> struct value_type<signed long, E> { typedef sint_value<E> ret; }; + template <class E> struct value_type<signed int, E> { typedef sint_value<E> ret; }; + template <class E> struct value_type<signed short, E> { typedef sint_value<E> ret; }; + template <class E> struct value_type<signed char, E> { typedef sint_value<E> ret; }; + template <class E> struct value_type< char, E> { typedef sint_value<E> ret; }; + + } // end of builtin. + + namespace internal { + + TYPETRAITS_BUILTIN_INT(unsigned long, uint_value) + TYPETRAITS_BUILTIN_INT(signed long, sint_value) + + TYPETRAITS_BUILTIN_INT(unsigned int, uint_value) + TYPETRAITS_BUILTIN_INT(signed int, sint_value) + + TYPETRAITS_BUILTIN_INT(unsigned short, uint_value) + TYPETRAITS_BUILTIN_INT(signed short, sint_value) + + TYPETRAITS_BUILTIN_INT(unsigned char, uint_value) + TYPETRAITS_BUILTIN_INT(signed char, sint_value) + TYPETRAITS_BUILTIN_INT(char, sint_value) + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_REAL_TYPETRAITS_BUILTIN_INT_HH Index: ntg/real/optraits_real_defs.hh --- ntg/real/optraits_real_defs.hh (revision 0) +++ ntg/real/optraits_real_defs.hh (revision 0) @@ -0,0 +1,213 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_OPTRAITS_REAL_DEFS_HH +# define NTG_OPTRAITS_REAL_DEFS_HH + +// +// macros used in optraits_real definition +// +///////////////////////////////////////////// + +# define ASSIGN_SCALAR_OPERATOR(Name) \ + template <class T1, class T2> inline \ + static T1& Name##_equal(T1& lhs, const T2& rhs) \ + { \ + ntg_is_a(T1, ntg::real)::ensure(); \ + ntg_is_a(T2, ntg::real)::ensure(); \ + \ + return Name##_equal_impl<T1,T2>(lhs, rhs); \ + } \ + \ + template <class T1, class T2> inline \ + static T1& \ + Name##_equal_impl(ntg::real_value<T1>& lhs, \ + const ntg::real_value<T2>& rhs) \ + { \ + typedef typename typetraits<T1>::behavior_type behavior_type; \ + lhs.exact() = behavior_type::check_##Name(lhs.exact().val(), \ + rhs.exact().val()); \ + return lhs.exact(); \ + } \ + \ + template <class T1, class T2> inline \ + static T1& \ + Name##_equal_impl(ntg::real_value<T1>& lhs, \ + const ntg::any_const_class<T2> rhs) \ + { \ + typedef typename typetraits<T1>::behavior_type behavior_type; \ + lhs.exact() = behavior_type::check_##Name(lhs.exact().val(), \ + rhs.exact()); \ + return lhs.exact(); \ + } \ + \ + template <class T1, class T2> inline \ + static T1& \ + Name##_equal_impl(ntg::any_class<T1> lhs, \ + const ntg::real_value<T2>& rhs) \ + { \ + typedef typename typetraits<T1>::behavior_type behavior_type; \ + lhs.exact() = behavior_type::check_##Name(lhs.exact(), \ + rhs.exact().val()); \ + return lhs.exact(); \ + } + +# define ARITH_SCALAR_OPERATOR(Name) \ + template <class T1, class T2> inline \ + static ntg_return_type(Name, T1, T2) \ + Name(const T1& lhs, const T2& rhs) \ + { \ + ntg_is_a(T1, ntg::real)::ensure(); \ + ntg_is_a(T2, ntg::real)::ensure(); \ + \ + return Name##_impl<T1,T2>(lhs, rhs); \ + } \ + \ + template <class T1, class T2> inline \ + static ntg_return_type(Name, T1, T2) \ + Name##_impl(const ntg::real_value<T1>& lhs, \ + const ntg::real_value<T2>& rhs) \ + { \ + typedef ntg_return_type(Name, T1, T2) return_type; \ + typedef typename \ + typetraits<E>::abstract_behavior_type::template get<return_type> \ + behavior_type; \ + return_type tmp; \ + tmp = behavior_type::check_##Name(lhs.exact().val(), \ + rhs.exact().val()); \ + return tmp; \ + } \ + \ + template <class T1, class T2> inline \ + static ntg_return_type(Name, T1, T2) \ + Name##_impl(const ntg::real_value<T1>& lhs, \ + const ntg::any_const_class<T2>& rhs) \ + { \ + typedef ntg_return_type(Name, T1, T2) return_type; \ + typedef typename \ + typetraits<E>::abstract_behavior_type::template get<return_type> \ + behavior_type; \ + return_type tmp; \ + tmp = behavior_type::check_##Name(lhs.exact().val(), \ + rhs.exact()); \ + return tmp; \ + } \ + \ + template <class T1, class T2> inline \ + static ntg_return_type(Name, T1, T2) \ + Name##_impl(const ntg::any_const_class<T1>& lhs, \ + const ntg::real_value<T2>& rhs) \ + { \ + typedef ntg_return_type(Name, T1, T2) return_type; \ + typedef typename \ + typetraits<E>::abstract_behavior_type::template get<return_type> \ + behavior_type; \ + return_type tmp; \ + tmp = behavior_type::check_##Name(lhs.exact(), \ + rhs.exact().val()); \ + return tmp; \ + } + +# define CMP_SCALAR_OPERATOR(Name, Op) \ + template <class T1, class T2> inline \ + static bool Name (const T1& lhs, const T2& rhs) \ + { \ + ntg_is_a(T1, ntg::real)::ensure(); \ + ntg_is_a(T2, ntg::real)::ensure(); \ + \ + typedef ntg_return_type(cmp, T1, T2) tmp_type; \ + \ + return Name##_impl<tmp_type>(static_cast<tmp_type>(lhs), \ + static_cast<tmp_type>(rhs)); \ + } \ + \ + template <class T> inline \ + static bool \ + Name##_impl(const ntg::real_value<T>& lhs, \ + const ntg::real_value<T>& rhs) \ + { return lhs.exact().val() Op rhs.exact().val(); } \ + \ + template <class T> inline \ + static bool \ + Name##_impl(const ntg::any_const_class<T> lhs, \ + const ntg::any_const_class<T> rhs) \ + { return lhs.exact() Op rhs.exact(); } + + +// +// Macros for optraits_int +// +//////////////////////////// + +# define ASSIGN_INT_OPERATOR(Name, Op) \ + template <class T1, class T2> inline \ + static T1& Name(T1& lhs, const T2& rhs) \ + { \ + ntg_is_a(T1, ntg::integer)::ensure(); \ + ntg_is_a(T2, ntg::integer)::ensure(); \ + \ + return Name##_impl<T1,T2>(lhs, rhs); \ + } \ + \ + template <class T1, class T2> inline \ + static T1& Name##_impl(int_value<T1>& lhs, const int_value<T2>& rhs) \ + { \ + lhs.exact() = lhs.exact().val() Op rhs.exact().val(); \ + return lhs.exact(); \ + } \ + \ + template <class T1, class T2> inline \ + static T1& Name##_impl(int_value<T1>& lhs, \ + const ntg::any_const_class<T2>& rhs) \ + { \ + lhs.exact() = lhs.exact().val() Op rhs.exact(); \ + return lhs.exact(); \ + } \ + \ + template <class T1, class T2> inline \ + static T1& Name##_impl(ntg::any_class<T1>& lhs, \ + const int_value<T2>& rhs) \ + { \ + lhs.exact() = lhs.exact() Op rhs.exact().val(); \ + return lhs.exact(); \ + } + +# define ARITH_INT_OPERATOR(Name, Op) \ + template <class T1, class T2> inline \ + static ntg_return_type(Name, T1, T2) \ + Name(const T1& lhs, const T2& rhs) \ + { \ + ntg_is_a(T1, integer)::ensure(); \ + ntg_is_a(T2, integer)::ensure(); \ + \ + typedef ntg_return_type(Name, T1, T2) return_type; \ + return_type result(lhs); \ + result Op rhs; \ + return result; \ + } + +#endif // ndef NTG_OPTRAITS_REAL_DEFS_HH Index: ntg/real/int_s.hh --- ntg/real/int_s.hh (revision 0) +++ ntg/real/int_s.hh (revision 0) @@ -0,0 +1,580 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_CORE_INT_S_HH +# define NTG_CORE_INT_S_HH + +# include <ntg/basics.hh> +# include <ntg/real/optraits_real.hh> +# include <ntg/real/real_value.hh> +# include <ntg/bin.hh> +# include <ntg/real/int_u.hh> + +# include <mlc/bool.hh> +# include <mlc/cmp.hh> +# include <mlc/is_a.hh> + +# include <string> +# include <sstream> + +/*-------. +| macros | +`-------*/ + +// FIXME: add bits number comparison to avoid useless checks. + +# define INT_S_CTOR_FROM_UNSIGNED_BUILTIN(Builtin) \ +int_s (const Builtin rhs) \ +{ \ + if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size < nbits) \ + this->val_ = rhs; \ + else \ + this->val_ = optraits_type::check(rhs); \ +} \ +self& operator=(const Builtin rhs) \ +{ \ + if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size < nbits) \ + this->val_ = rhs; \ + else \ + this->val_ = optraits_type::check(rhs); \ + return *this; \ +} + +# define INT_S_CTOR_FROM_SIGNED_BUILTIN(Builtin) \ +int_s (const Builtin rhs) \ +{ \ + if ((unsigned)internal::typetraits<ntg_type(Builtin)>::size <= nbits) \ + this->val_ = rhs; \ + else \ + this->val_ = optraits_type::check(rhs); \ +} \ +self& operator=(const Builtin rhs) \ +{ \ + if ((unsigned)internal::typetraits<ntg_type(Builtin)>::size <= nbits) \ + this->val_ = rhs; \ + else \ + this->val_ = optraits_type::check(rhs); \ + return *this; \ +} + + +namespace ntg { + + namespace internal { + + /*------------------. + | typetraits<int_s> | + `------------------*/ + + template <unsigned nbits, typename 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; + typedef self ntg_type; + + ntg_build_value_type(sint_value<E>); + + typedef optraits<self> optraits_type; + typedef behavior abstract_behavior_type; + typedef typename behavior::template get<self> behavior_type; + + typedef self base_type; + typedef typename C_for_int_s<nbits>::type storage_type; + typedef self signed_type; + typedef int_u<nbits-1, behavior> unsigned_type; + // FIXME: calculate it more precisely + typedef int_s<32, behavior> cumul_type; + typedef int_s<32, behavior> largest_type; + typedef int_s<32, behavior> signed_largest_type; + typedef int_s<32, behavior> signed_cumul_type; + typedef int_u<32, behavior> unsigned_largest_type; + typedef int_u<32, behavior> unsigned_cumul_type; + typedef signed int integer_type; + + // Particular properties + enum { size = nbits }; + }; + + } // end of internal. + + /*-----------------------. + | int_s<nbits, behavior> | + `-----------------------*/ + + template <unsigned nbits, class behavior> + class int_s : public sint_value<int_s<nbits, behavior> > + { + typedef int_s<nbits, behavior> self; + typedef ntgi_storage_type(self) storage_type; + typedef ntgi_optraits_type(self) optraits_type; + + public: + + int_s () { this->val_ = 0; } + + // We define ctor for each builtin to avoid implicit builtin + // promotion. + + INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned long); + INT_S_CTOR_FROM_SIGNED_BUILTIN(signed long); + + INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned int); + INT_S_CTOR_FROM_SIGNED_BUILTIN(signed int); + + INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned short); + INT_S_CTOR_FROM_SIGNED_BUILTIN(signed short); + + INT_S_CTOR_FROM_UNSIGNED_BUILTIN(unsigned char); + INT_S_CTOR_FROM_SIGNED_BUILTIN(signed char); + INT_S_CTOR_FROM_SIGNED_BUILTIN(char); + + template <unsigned mbits, class B2> + int_s (const int_s<mbits, B2>& rhs) + { + if (mbits <= nbits) + this->val_ = rhs.val(); + else + this->val_ = optraits_type::check(rhs.val()); + } + template <unsigned mbits, class B2> + self& + operator=(const int_s<mbits, B2>& rhs) + { + if (mbits <= nbits) + this->val_ = rhs.val(); + else + this->val_ = optraits_type::check(rhs.val()); + return *this; + } + + template <class T> + int_s (const real_value<T>& rhs) + { + this->val_ = optraits_type::check(rhs.val()); + } + template <class T> + self& + operator=(const real_value<T>& rhs) + { + this->val_ = optraits_type::check(rhs.val()); + return *this; + } + + // FIXME: do we really want float to int conversions ? + + int_s (const float_s rhs) + { + this->val_ = optraits_type::check(roundf(rhs)); + } + self& operator=(const float_s rhs) + { + this->val_ = optraits_type::check(roundf(rhs)); + return *this; + } + + int_s (const float_d rhs) + { + this->val_ = optraits_type::check(round(rhs)); + } + self& operator=(const float_d rhs) + { + this->val_ = optraits_type::check(round(rhs)); + return *this; + } + + // bin is allowed since it has defined values 0 or 1. + int_s (bin b) + { + this->val_ = b.val(); + } + self& operator=(bin b) + { + this->val_ = b.val(); + return *this; + } + + operator storage_type () const { return this->val_; } + + private: + // We want to prevent this + int_s(bool); + }; + + template<unsigned nbits, class behavior> + inline std::ostream& + operator<<(std::ostream& stream, const int_s<nbits, behavior>& rhs) + { + stream << signed(rhs.val()); + return stream; + } + + namespace internal + { + + /*----------------. + | optraits<int_s> | + `----------------*/ + + template <unsigned nbits, class behavior> + struct optraits<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_; + typedef typename typetraits<self>::storage_type storage_type_; + typedef typename behavior::template get<self> behavior_type_; + + public: + template <class P> + static storage_type_ + check(const P& rhs) + { return behavior_type_::check(rhs); } + + static storage_type_ max() + { return C_for_int_s<nbits>::max(); } + + static storage_type_ min() + { return C_for_int_s<nbits>::min(); } + + // + // Comparison operators + // + ///////////////////////// + + // As int_x32 cannot grow, there is a problem with comparisons when a + // int_u32 is present, as we cannot convert it to a signed type safely. + // + + // + // cmp_eq + // + + // int_sN == int_u32; int_u32 == int_sN + + template <unsigned mbits, class B1, class B2> + static bool + 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 <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> + + template <class T1, class T2> + static bool + cmp_eq(const T1& lhs, const T2& rhs) + { return super::cmp_eq(lhs, rhs); } + + // + // cmp_lt + // + + // int_sN < int_u32; int_u32 < int_sN + + template <unsigned mbits, class B1, class B2> + static bool + 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 <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; + + return lhs.val() < static_cast<int_u<32, B1> >(rhs.val()); + } + + // <T1> < <T2> + + template <class T1, class T2> + static bool + cmp_lt(const T1& lhs, const T2& rhs) + { return super::cmp_lt(lhs, rhs); } + + // debug + static std::string name() { + std::ostringstream out; + out << "int_s<" << int(nbits) << ", " << behavior::name() << ">" + << std::ends; + return out.str(); + } + }; + + + /*----------------. + | operator traits | + `----------------*/ + + // + // plus + // + + // int_s + int_s + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_plus, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = true, + need_check = ((unsigned) mlc::max<nbits, mbits>::ret >= 32) }; + typedef int_s<(unsigned)mlc::maxN<nbits + 1,mbits + 1, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + + // int_s + int_u ; int_u + int_s + + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_plus, int_s<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true, + need_check = ((mbits >= 31) || (nbits >= 32)) }; + typedef int_s<(unsigned)mlc::maxN<nbits + 1,mbits + 2, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + + // + // minus + // + + // int_s - int_s + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_minus, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = true, + need_check = ((mbits >= 31) || (nbits >= 31)) }; + typedef int_s<(unsigned)mlc::maxN<nbits + 1, mbits + 1, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + // int_s - int_u ; int_u - int_s + + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_minus, int_s<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true, + need_check = ((mbits >= 31) || (nbits >= 32)) }; + typedef int_s<(unsigned)mlc::maxN<nbits + 1, mbits + 2, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + + // + // times + // + + // int_s * int_s + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_times, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = true, + need_check = (mbits + nbits > 32) }; + typedef int_s<(unsigned)mlc::saturateN<nbits + mbits, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + + // int_s * int_u ; int_u * int_s + + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_times, int_s<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true, + need_check = (nbits + mbits + 1 > 32)}; + typedef int_s<(unsigned)mlc::saturateN<nbits + mbits+1, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + // + // div + // + + // int_s / int_s + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_div, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = true }; + typedef int_s<nbits, typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, force> impl; + }; + + // int_s / int_u ; int_u / int_s + + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_div, int_s<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = false, + need_check = (mbits >= 32) }; + typedef int_s<nbits, typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_div, int_u<mbits, B2>, int_s<nbits, B1> > + { + enum { commutative = false, + need_check = (mbits >= 32) }; + typedef int_s<mlc::saturateN<mbits + 1, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + // + // mod + // + + // int_s % int_s + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_mod, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = false }; + typedef int_s<mbits, typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, force> impl; + }; + + // int_s % int_u ; int_u % int_s + + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_mod, int_s<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = false, + need_check = (mbits >= 32) }; + typedef int_s<(unsigned)mlc::saturateN<mbits + 1, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + // FIXME: don't know what to do with this operator, so the + // implementation is disabled. In classical C++, (a % b) with b < 0 + // returns a whatever b is. + +#if 0 + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_mod, int_u<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = false }; + typedef int_u<mbits, typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, B1> impl; + }; +#endif + + // + // Min + // + + // min(int_s, int_s) + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_min, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = true }; + typedef int_s<(unsigned) mlc::min<nbits, mbits>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, force> impl; + }; + + // + // Max + // + + // max(int_s, int_s) + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_max, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = true }; + typedef int_s<(unsigned) mlc::max<nbits, mbits>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_s<nbits, force> impl; + }; + + // + // Comparison operator + // + + // int_s compared with int_s + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_cmp, int_s<nbits, B1>, int_s<mbits, B2> > + { + enum { commutative = true }; + typedef int_s<(unsigned)mlc::maxN<nbits,mbits,32>::ret, unsafe> ret; + typedef int_s<nbits, force> impl; + }; + + + // int_s CMP int_u ; int_u CMP int_s + + template <unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_cmp, int_s<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true }; + typedef int_s<(unsigned)mlc::maxN<nbits,mbits+1, 32>::ret, unsafe> ret; + typedef int_s<nbits, force> impl; + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_CORE_INT_S_HH Index: ntg/real/int_u.hh --- ntg/real/int_u.hh (revision 0) +++ ntg/real/int_u.hh (revision 0) @@ -0,0 +1,412 @@ +// Copyright (C) 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 NTG_REAL_INT_U_HH +# define NTG_REAL_INT_U_HH + +# include <ntg/basics.hh> +# include <ntg/real/optraits_real.hh> +# include <ntg/real/real_value.hh> +# include <ntg/bin.hh> + +# include <mlc/bool.hh> +# include <mlc/cmp.hh> +# include <mlc/is_a.hh> + +# include <string> +# include <sstream> + +/*-------. +| macros | +`-------*/ + +# define INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(Builtin) \ +int_u (const Builtin rhs) \ +{ \ + if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size <= nbits) \ + this->val_ = rhs; \ + else \ + this->val_ = optraits_type::check(rhs); \ +} \ +self& operator=(const Builtin rhs) \ +{ \ + if ((unsigned) internal::typetraits<ntg_type(Builtin)>::size <= nbits) \ + this->val_ = rhs; \ + else \ + this->val_ = optraits_type::check(rhs); \ + return *this; \ +} + +# define INT_U_CTOR_FROM_BUILTIN_INT(Builtin) \ +int_u (const Builtin rhs) \ +{ \ + this->val_ = optraits_type::check(rhs); \ +} \ +self& operator=(const Builtin rhs) \ +{ \ + this->val_ = optraits_type::check(rhs); \ + return *this; \ +} + + +namespace ntg { + + namespace internal { + + /*------------------. + | typetraits<int_u> | + `------------------*/ + + template <unsigned nbits, typename 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; + typedef self ntg_type; + + ntg_build_value_type(uint_value<E>); + + typedef optraits<self> optraits_type; + typedef behavior abstract_behavior_type; + typedef typename behavior::template get<self> behavior_type; + + typedef self base_type; + typedef typename C_for_int_u<nbits>::type storage_type; + typedef int_s<mlc::saturateN<nbits+1, 32>::ret, + behavior> signed_type; + typedef self unsigned_type; + // FIXME: calculate it more precisely + typedef int_u<32, behavior> cumul_type; + typedef int_u<32, behavior> largest_type; + typedef int_s<32, behavior> signed_largest_type; + typedef int_s<32, behavior> signed_cumul_type; + typedef int_u<32, behavior> unsigned_largest_type; + typedef int_u<32, behavior> unsigned_cumul_type; + typedef unsigned int integer_type; + typedef int_u<nbits, unsafe> unsafe_type; + + // Particular properties + enum { size = nbits }; + }; + + } // end of internal. + + /*-----------------------. + | int_u<nbits, behavior> | + `-----------------------*/ + + template <unsigned nbits, class behavior> + class int_u : public uint_value<int_u<nbits, behavior> > + { + typedef int_u<nbits, behavior> self; + typedef ntgi_storage_type(self) storage_type; + // dev note : should be directly optraits<self_t>, but with g++ this + // breaks inheritance in optraits herarchy ... + typedef ntgi_optraits_type(self) optraits_type; + + public: + int_u () { this->val_ = 0; } + + // We define ctor for each builtin to avoid implicit builtin + // promotion. + + // FIXME: dynamic checks are not necessary for all builtin types! + + INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned long); + INT_U_CTOR_FROM_BUILTIN_INT(signed long); + + INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned int); + INT_U_CTOR_FROM_BUILTIN_INT(signed int); + + INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned short); + INT_U_CTOR_FROM_BUILTIN_INT(signed short); + + INT_U_CTOR_FROM_UNSIGNED_BUILTIN_INT(unsigned char); + INT_U_CTOR_FROM_BUILTIN_INT(signed char); + INT_U_CTOR_FROM_BUILTIN_INT(char); + + int_u (const float_s rhs) + { + this->val_ = optraits_type::check(roundf(rhs)); + } + self& + operator=(const float rhs) + { + this->val_ = optraits_type::check(roundf(rhs)); + return *this; + } + + int_u (const float_d rhs) + { + this->val_ = optraits_type::check(round(rhs)); + } + self& + operator=(const double rhs) + { + this->val_ = optraits_type::check(round(rhs)); + return *this; + } + + template <unsigned mbits, class B2> + int_u (const int_u<mbits, B2>& rhs) + { + if (mbits <= nbits) + this->val_ = rhs.val(); + else + this->val_ = optraits_type::check(rhs.val()); + } + template <unsigned mbits, class B2> + self& + operator=(const int_u<mbits, B2>& rhs) + { + if (mbits <= nbits) + this->val_ = rhs.val(); + else + this->val_ = optraits_type::check(rhs.val()); + return *this; + } + + template <class T> + int_u (const real_value<T>& rhs) + { + this->val_ = optraits_type::check(rhs.val()); + } + template <class T> + self& + operator=(const real_value<T>& rhs) + { + this->val_ = optraits_type::check(rhs.val()); + return *this; + } + + // bin is allowed since it has defined values 0 or 1. + int_u (bin b) + { + this->val_ = b.val(); + } + self& + operator=(bin b) + { + this->val_ = b.val(); + return *this; + } + + operator storage_type () const { return this->val_; } + + private: + // We want to prevent this + int_u(bool); + }; + + template<unsigned nbits, class behavior> + inline std::ostream& + operator<<(std::ostream& stream, const int_u<nbits, behavior>& rhs) + { + stream << unsigned(rhs.val()); + return stream; + } + + namespace internal + { + + /*----------------. + | optraits<int_u> | + `----------------*/ + + template <unsigned nbits, class behavior> + struct optraits<int_u<nbits, behavior> > : + public optraits<uint_value<int_u<nbits, behavior> > > + { + private: + typedef int_u<nbits, behavior> self; + typedef typename typetraits<self>::storage_type storage_type_; + typedef typename behavior::template get<self> behavior_type_; + + public: + template <class P> + static storage_type_ check(const P& rhs) + { return behavior_type_::check(rhs); } + + static storage_type_ max() + { return C_for_int_u<nbits>::max(); } + + static std::string + name() + { + std::ostringstream out; + out << "int_u<" << int(nbits) << ", " << behavior::name() << ">" + << std::ends; + return out.str(); + } + }; + + /*----------------. + | operator traits | + `----------------*/ + + // + // plus + // + + // int_u + int_u + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_plus, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true, + need_check = ((unsigned) mlc::max<nbits, mbits>::ret >= 32) }; + typedef int_u<(unsigned) mlc::maxN<nbits + 1, mbits + 1, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + // + // minus + // + + // int_u - int_u + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_minus, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true, + need_check = ((unsigned) mlc::max<nbits, mbits>::ret >= 32) }; + typedef int_s<(unsigned) mlc::maxN<nbits+1, mbits+1, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + // int_u32 - int_u : we do not convert result to int_s because we + // want to access (UINT_MAX - 1). + + template<class B1, unsigned mbits, class B2> + struct operator_traits<operator_minus, int_u<32, B1>, int_u<mbits, B2> > + { + enum { commutative = true }; + typedef int_u<32, typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<32, force> impl; + }; + + // + // times + // + + // int_u * int_u + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_times, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true, need_check = (nbits + mbits > 32) }; + typedef int_u<(unsigned) mlc::saturateN<nbits + mbits, 32>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<nbits, + typename ret_behavior_if<need_check, ret>::ret> impl; + }; + + // + // div + // + + // int_u / int_u + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_div, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true }; + typedef int_u<nbits, typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<nbits, force> impl; + }; + + // + // modulo + // + + // int_u % int_u + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_mod, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = false }; + typedef int_u<mbits, typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<nbits, force> impl; + }; + + // + // Min + // + + // min(int_u, int_u) + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_min, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true }; + typedef int_u<(unsigned) mlc::min<nbits, mbits>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<nbits, force> impl; + }; + + + // + // Max + // + + // max(int_u, int_u) + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_max, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true }; + typedef int_u<(unsigned) mlc::max<nbits, mbits>::ret, + typename deduce_op_behavior<B1, B2>::ret> ret; + typedef int_u<nbits, force> impl; + }; + + + // + // Comparison + // + + // int_u CMP int_u + + template<unsigned nbits, class B1, unsigned mbits, class B2> + struct operator_traits<operator_cmp, int_u<nbits, B1>, int_u<mbits, B2> > + { + enum { commutative = true }; + // FIXME: why unsafe? I think there is a reason. + typedef int_u<(unsigned) mlc::maxN<nbits, mbits, 32>::ret, unsafe> ret; + typedef int_u<nbits, force> impl; + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_REAL_INT_U_HH Index: ntg/real/real_value.hh --- ntg/real/real_value.hh (revision 0) +++ ntg/real/real_value.hh (revision 0) @@ -0,0 +1,58 @@ +// Copyright (C) 2001, 2002, 2003, 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 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 +{ + + 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. + +#endif // !NTG_REAL_REAL_VALUE_HH Index: ntg/real/builtin_int.hh --- ntg/real/builtin_int.hh (revision 0) +++ ntg/real/builtin_int.hh (revision 0) @@ -0,0 +1,38 @@ +// Copyright (C) 2002, 2003 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 NTG_CORE_BUILTIN_INT_HH +# define NTG_CORE_BUILTIN_INT_HH + +/* + Proxy header for integer builtin types. +*/ + +# include <ntg/real/typetraits_builtin_int.hh> +# include <ntg/real/optraits_builtin_int.hh> + +#endif // !NTG_CORE_BUILTIN_INT_HH Index: ntg/core/abstract_hierarchy.hh --- ntg/core/abstract_hierarchy.hh (revision 0) +++ ntg/core/abstract_hierarchy.hh (revision 0) @@ -0,0 +1,84 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CORE_ABSTRACT_HIERARCHY_HH +# define NTG_CORE_ABSTRACT_HIERARCHY_HH + +namespace ntg +{ + + /* + Abstract hierarchy is useful to easily check the properties of + each types. type_traits<T>::abstract_type gives the abstract type + associated to T. The macro ntg_is_a(T, abstract_type) is a simple + way to ensure a given type has good properties. + + Examples: + + ntg_is_a(int, integer)::ensure(); + mlc_is_a(type_traits<int_u8>::abstract_type, unsigned_integer)::ensure(); + */ + + //! Top of the hierarchy. + class data_type {}; + + // Single valued data types + class non_vectorial {}; + + /*------. + | reals | + `------*/ + + class real : public non_vectorial {}; + + // int, unsigned, int_u, int_s, etc. + class integer : public real {}; + class unsigned_integer : public integer {}; + class signed_integer : public integer {}; + + // float_s, float_d, etc. + class decimal : public real {}; + + /*-----------. + | enumerated | + `-----------*/ + + class enumerated : public non_vectorial {}; + + // bin, bool, etc. + class binary : public enumerated {}; + + /*----------. + | vectorial | + `----------*/ + + // vec, cplx, etc. + class vectorial : public data_type {}; + +} // end of ntg. + +#endif // !NTG_CORE_ABSTRACT_HIERARCHY_HH Index: ntg/core/predecls.hh --- ntg/core/predecls.hh (revision 0) +++ ntg/core/predecls.hh (revision 0) @@ -0,0 +1,134 @@ +// Copyright (C) 2001, 2002, 2003, 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 NTG_CORE_PREDECLS_HH +# define NTG_CORE_PREDECLS_HH + +# include <ntg/core/type.hh> +# include <ntg/vect/cplx_representation.hh> + +/* + Forward declarations of every available types. +*/ + +namespace ntg +{ + + /*----------. + | behaviors | + `----------*/ + + class unsafe; + class strict; + class saturate; + + /*----------. + | intervals | + `----------*/ + + template <class T, T i_min, T i_max> class bounded; + template <unsigned i_min, unsigned i_max> class bounded_u; + template <signed i_min, signed i_max> class bounded_s; + + /*------. + | reals | + `------*/ + + template <unsigned nbits, class behavior = strict> class int_u; + template <unsigned nbits, class behavior = strict> class int_s; + template <class T, class interval, class behavior = strict> class range; + template <class T, class interval> class cycle; + + typedef float float_s; + typedef double float_d; + + /*-----------. + | enumerated | + `-----------*/ + + class bin; + + /*----------. + | vectorial | + `----------*/ + + template <unsigned N, class T, class Self = ntg::final> class vec; + + template <cplx_representation R, class T> class cplx; + + /*-------. + | colors | + `-------*/ + + // This helps swig to parse to file. +#ifndef SWIG + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct color; +#else + struct color; +#endif + + template<int lval, int uval> + struct interval; + + /*--------------------. + | shortcuts for int_u | + `--------------------*/ + + typedef int_u<8, strict> int_u8; + typedef int_u<8, unsafe> int_u8u; + typedef int_u<8, saturate> int_u8s; + + typedef int_u<16, strict> int_u16; + typedef int_u<16, unsafe> int_u16u; + typedef int_u<16, saturate> int_u16s; + + typedef int_u<32, strict> int_u32; + typedef int_u<32, unsafe> int_u32u; + typedef int_u<32, saturate> int_u32s; + + /*--------------------. + | shortcuts for int_s | + `--------------------*/ + + typedef int_s<8, strict> int_s8; + typedef int_s<8, unsafe> int_s8u; + typedef int_s<8, saturate> int_s8s; + + typedef int_s<16, strict> int_s16; + typedef int_s<16, unsafe> int_s16u; + typedef int_s<16, saturate> int_s16s; + + typedef int_s<32, strict> int_s32; + typedef int_s<32, unsafe> int_s32u; + typedef int_s<32, saturate> int_s32s; + +} // end of ntg. + +#endif // !NTG_CORE_PREDECLS_HH Index: ntg/core/type.hh --- ntg/core/type.hh (revision 0) +++ ntg/core/type.hh (revision 0) @@ -0,0 +1,139 @@ +// Copyright (C) 2001, 2002, 2003, 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 NTG_CORE_TYPE_HH +# define NTG_CORE_TYPE_HH + +# include <string> + +/* + Utility classes. +*/ + +namespace ntg +{ + + // FIXME: see comments in ntg/core/value.hh about this duplicate of + // metalic's code. + + /*-------. + | any<E> | + `-------*/ + + //! Top of static hierarchy. + template <class E> + class any + { + public: + typedef E exact_type; + + E& exact() { return static_cast<E&>(*this); } + const E& exact() const { return static_cast<const E&>(*this); } + }; + + /*------------------. + | any_(const_)class | + `------------------*/ + + /* + Classes used to disambiguate overloading. They can store an + instance of any object and restore it later. + */ + + template <class T> + class any_class + { + public: + any_class(T& t) : _target(t) {} + + T& exact() { return _target; } + + private: + T& _target; + }; + + template <class T> + class any_const_class + { + public: + any_const_class(const T& t) : _target(t) {} + + const T& exact() const { return _target; } + + private: + const T& _target; + }; + + /*-------------. + | Useful types | + `-------------*/ + + struct undefined {}; + + class final + { + public: + static std::string name() { return "final"; } + protected: + final() {} + }; + + class top + { + public: + static std::string name() { return ""; } + protected: + top() {} + }; + + + /*---------. + | exact_vt | + `---------*/ + + // + // exact virtual type traits + // (inheritance determination) + // + // If Exact is mlc::final return T else return Exact + + template<class T, class Exact> + struct exact_vt + { + typedef Exact ret; + }; + + template<class Exact> + struct exact_vt<Exact,final> + { + typedef Exact ret; + }; + + +} // end of ntg. + +#endif // !NTG_CORE_TYPE_HH Index: ntg/core/props.hh --- ntg/core/props.hh (revision 59) +++ ntg/core/props.hh (working copy) @@ -1,77 +0,0 @@ -// 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 INTEGRE_CORE_PROPS_HH -# define INTEGRE_CORE_PROPS_HH - -# include <mlc/types.hh> - -# include <ntg/core/cats.hh> - -/*! \namespace ntg -** \brief ntg namespace. -*/ -namespace ntg { - - - /*! \class default_props - ** - ** \brief Class that defines properties by default, so properties are - ** undefined. // FIXME: this doc should be modified... - ** - ** Practically all typedefs of default_props are thus set to - ** mlc::undefined_type. - ** - ** When props<E> is specialized, the programmer should derive that - ** specialization from another props<E'> or from default_props. - ** That ensures that an undefined property is set to mlc::undefined_type. - ** - ** \see props<E> - */ - template < typename category > - struct default_props; - - - /*! \class props<E> - ** - ** Declaration of the trait class for properties. - ** Parameter E is the targeted type. FIXME: rewrite doc. - */ - template <typename category, typename type> - struct props : public default_props <category> - {}; - - template <typename category, typename type> - struct props <category, const type> : public props <category, type> - {}; - - - -} // end of namespace ntg - - -#endif // ndef INTEGRE_CORE_PROPS_HH Index: ntg/core/macros.hh --- ntg/core/macros.hh (revision 59) +++ ntg/core/macros.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004 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 @@ -25,15 +25,188 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef INTEGRE_CORE_MACROS_HH -# define INTEGRE_CORE_MACROS_HH +#ifndef NTG_CORE_MACROS_HH +# define NTG_CORE_MACROS_HH -# define ntg_max_val(T) ntg::props<ntg_category_type(T),T>::max_val +/*------. +| casts | +`------*/ -# define ntg_depth(T) ntg::props<ntg_category_type(T),T>::depth +# define ntg_type(T) typename ntg::type_traits< T >::ntg_type +# define ntg_type_(T) typename ntg::type_traits< T >::ntg_type -# define ntg_comp_type(T) typename ntg::props<ntg_category_type(T),T>::comp_type +# define ntg_cast(Val) ntg::to_ntg(Val) +# define ntg_signed_cast(Val) ntg::to_signed_ntg(Val) -# define ntg_io_type(T) typename ntg::props<ntg_category_type(T),T>::io_type +/*--------------. +| type checking | +`--------------*/ -#endif // ! INTEGRE_CORE_MACROS_HH +# define ntg_is_a(T, U) mlc_is_a(typename ntg::type_traits< T >::abstract_type, U) +# define ntg_is_a_(T, U) mlc_is_a_(ntg::type_traits< T >::abstract_type, U) + +/*----------------. +| types accessors | +`----------------*/ + +# define ntg_abstract_type(T) typename ntg::type_traits< T >::abstract_type +# define ntg_abstract_type_(T) ntg::type_traits< T >::abstract_type + +# define ntg_storage_type(T) typename ntg::type_traits< T >::storage_type +# define ntg_storage_type_(T) ntg::type_traits< T >::storage_type + +# define ntg_base_type(T) typename ntg::type_traits< T >::base_type +# define ntg_base_type_(T) ntg::type_traits< T >::base_type + +# define ntg_signed_type(T) typename ntg::type_traits< T >::signed_type +# define ntg_signed_type_(T) ntg::type_traits< T >::signed_type + +# define ntg_unsigned_type(T) typename ntg::type_traits< T >::unsigned_type +# define ntg_unsigned_type_(T) ntg::type_traits< T >::unsigned_type + +# define ntg_integer_type(T) typename ntg::type_traits< T >::integer_type +# define ntg_integer_type_(T) ntg::type_traits< T >::integer_type + +# define ntg_cumul_type(T) typename ntg::type_traits< T >::cumul_type +# define ntg_cumul_type_(T) ntg::type_traits< T >::cumul_type + +# define ntg_signed_cumul_type(T) \ + typename ntg::type_traits< T >::signed_cumul_type +# define ntg_signed_cumul_type_(T) ntg::type_traits< T >::signed_cumul_type + +# define ntg_unsigned_cumul_type(T) \ + typename ntg::type_traits< T >::unsigned_cumul_type +# define ntg_unsigned_cumul_type_(T) ntg::type_traits< T >::unsigned_cumul_type + +# define ntg_largest_type(T) typename ntg::type_traits< T >::largest_type +# define ntg_largest_type_(T) ntg::type_traits< T >::largest_type + +# define ntg_signed_largest_type(T) \ + typename ntg::type_traits< T >::signed_largest_type +# define ntg_signed_largest_type_(T) ntg::type_traits< T >::signed_largest_type + +# define ntg_unsigned_largest_type(T) \ + typename ntg::type_traits< T >::unsigned_largest_type +# define ntg_unsigned_largest_type_(T) \ + ntg::type_traits< T >::unsigned_largest_type + +# define ntg_comp_type(T) \ + typename ntg::type_traits< T >::comp_type +# define ntg_comp_type_(T) \ + ntg::type_traits< T >::comp_type + +# define ntg_unsafe_type(T) typename ntg::type_traits< T >::unsafe_type +# define ntg_unsafe_type_(T) ntg::type_traits< T >::unsafe_type + +/*-----------------. +| values accessors | +`-----------------*/ + +# define ntg_zero_val(T) ntg::type_traits< T >::zero() + +# define ntg_unit_val(T) ntg::type_traits< T >::unit() + +# define ntg_max_val(T) ntg::type_traits< T >::max() + +# define ntg_min_val(T) ntg::type_traits< T >::min() + +# define ntg_sup_val(T) ntg::type_traits< T >::sup() + +# define ntg_inf_val(T) ntg::type_traits< T >::inf() + +# define ntg_inf_val(T) ntg::type_traits< T >::inf() + +# define ntg_sup_val(T) ntg::type_traits< T >::sup() + +# define ntg_max_print_width(T) ntg::type_traits< T >::max_print_width() + +# define ntg_nb_comp(T) ntg::type_traits< T >::nb_comp + +/*--------------------------. +| operator traits accessors | +`--------------------------*/ + +# define ntg_return_type(Op, T1, T2) \ + typename ntg::internal::deduce_from_traits<ntg::internal::operator_##Op , T1, T2 >::ret +# define ntg_return_type_(Op, T1, T2) \ + ntg::internal::deduce_from_traits<ntg::internal::operator_##Op, T1, T2 >::ret + +# define ntg_deduced_traits_type(Op, T1, T2) \ + typename ntg::internal::deduce_from_traits<ntg::internal::operator_##Op, T1, T2 > +# define ntg_deduced_traits_type_(Op, T1, T2) \ + ntg::internal::deduce_from_traits<ntg::internal::operator_##Op, T1, T2 > + +# define ntg_impl_type(Op, T1, T2) \ + typename ntg::internal::deduce_from_traits<ntg::internal::operator_##Op, T1, T2 >::impl +# define ntg_impl_type_(Op, T1, T2) \ + ntg::internal::deduce_from_traits<ntg::internal::operator_##Op, T1, T2 >::impl + +/*----------. +| utilities | +`----------*/ + +# define ntg_name(T) ntg::type_traits< T >::name() + +// FIXME: reimplement when variadic macros will be allowed. +# define ntg_build_value_type(Type) \ + template <class E> \ + struct build_value_type \ + { \ + typedef Type ret; \ + } + +// FIXME: reimplement when variadic macros will be allowed. +# define ntg_get_value_type(T, E) ntg::type_traits< T >::build_value_type<E > + + +/* ----. +| Misc | +`-----*/ +#define ntg_nbits(T) ntg::internal::typetraits< T >::size + + +/*! Return the number of components of T if T is vectorial. +** +** If T is non vectorial, the value returned should not be considered. +*/ +#define ntg_if_vectorial_nb_comp(T) \ + ntg::type_traits<typename mlc::if_<ntg_is_a(T, ntg::vectorial)::ret, \ + T, \ + ntg::vec<42, bool> >::ret>::nb_comp + +/*! Same as \a ntg_if_vectorial_nb_comp but without 'typename' +** +** \see ntg_if_vectorial_nb_comp +*/ +#define ntg_if_vectorial_nb_comp_(T) \ + ntg::type_traits<mlc::if_<ntg_is_a_(T, ntg::vectorial)::ret, \ + T, \ + ntg::vec<42, bool> >::ret>::nb_comp + +/*! Compare the number of components. +** +** - If \a A and \a B are non_vectorial, then +** \a {ntg_compare_nb_comp(A, B)::ret = true} +** - If \a A and \a B are vectorial, then +** \a {ntg_compare_nb_comp(A, B)::ret = (ntg_nb_comp(A) = ntg_nb_comp(B))} +** - Otherwise, it returns false +*/ +#define ntg_compare_nb_comp(A, B) \ + mlc::if_< \ + ntg_is_a(A, ntg::non_vectorial)::ret, \ + ntg_is_a(B, ntg::non_vectorial), \ + mlc::eq<ntg_if_vectorial_nb_comp(A), \ + ntg_if_vectorial_nb_comp(B) > >::ret + +/*! Same as \a ntg_compare_nb_comp but without 'typename' +** +** \see ntg_compare_nb_comp +*/ +#define ntg_compare_nb_comp_(A, B) \ + mlc::if_< \ + ntg_is_a_(A, ntg::non_vectorial)::ret, \ + ntg_is_a_(B, ntg::non_vectorial), \ + mlc::eq<ntg_if_vectorial_nb_comp_(A), \ + ntg_if_vectorial_nb_comp_(B) > >::ret + +#endif // !NTG_CORE_MACROS_HH Index: ntg/core/interval.hh --- ntg/core/interval.hh (revision 0) +++ ntg/core/interval.hh (revision 0) @@ -0,0 +1,118 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CORE_INTERVAL_HH +# define NTG_CORE_INTERVAL_HH + +# include <ntg/config/system.hh> +# include <ntg/core/macros.hh> +# include <ntg/core/type_traits.hh> + +# include <string> +# include <sstream> + +/* + Classes to define intervals. The problem with static intervals is + that you cannot specify it easily: + + template <T lower, T upper> + struct foo {} + + What do you specify for T ? If you use unsigned, you cannot handle + negative values, if you use signed, you won't be able to use the max + of an unsigned. That's why you have to specify the type of the + bounds. Interval is an handy way to do this. + + Note: it is not possible to define float intervals, as floats cannot + be template parameters. +*/ + +namespace ntg +{ + + /*-------------------------. + | bounded<T, i_min, i_max> | + `-------------------------*/ + + template <class T, T i_min, T i_max> + class bounded + { + public: + typedef T storage_type; + + static T min() { return i_min; } + static T max() { return i_max; } + static T inf() { return i_min; } + static T sup() { return i_max; } + + static std::string + name() + { + std::ostringstream out; + out << "bounded<" << ntg_name(T) << ", " << i_min + << ", " << i_max << ">"<< std::ends; + return out.str(); + } + }; + + /*------------------------. + | bounded_u<i_min, i_max> | + `------------------------*/ + + template <unsigned i_min, unsigned i_max> + class bounded_u : public bounded<unsigned, i_min, i_max> + { + public: + static std::string + name() + { + std::ostringstream out; + out << "bounded_u<" << i_min << ", " << i_max << ">"<< std::ends; + return out.str(); + } + }; + + /*------------------------. + | bounded_s<i_min, i_max> | + `------------------------*/ + + template <signed i_min, signed i_max> + class bounded_s : public bounded<signed, i_min, i_max> + { + public: + static std::string + name() + { + std::ostringstream out; + out << "bounded_s<" << i_min << ", " << i_max << ">"<< std::ends; + return out.str(); + } + }; + +} // end of ntg. + +#endif // !NTG_CORE_INTERVAL_HH Index: ntg/core/pred_succ.hh --- ntg/core/pred_succ.hh (revision 0) +++ ntg/core/pred_succ.hh (revision 0) @@ -0,0 +1,95 @@ +// Copyright (C) 2004 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 NTG_CORE_PRED_SUCC_HH +# define NTG_CORE_PRED_SUCC_HH + + +#include <mlc/is_a.hh> +#include <ntg/real/int_u.hh> +#include <ntg/core/macros.hh> + +namespace ntg { + + namespace internal { + //! Return a type which supports inc and dec. + template <typename T> + struct with_arith + { + typedef typename ntg_is_a(T, non_vectorial)::ensure_type non_v; + + typedef int_u<1> bool_with_arith; + typedef T non_vectorial_with_arith; + + typedef typename mlc::if_<ntg_is_a(T, ntg::binary)::ret, + id_<bool_with_arith>, + id_<non_vectorial_with_arith> >::ret::ret ret; + }; + } + + /*! Return the successor of \a t. + ** + ** \note The goal is to iterate on types such as ntg::bin. + */ + template <typename T> + T + succ(const T &t) + { + return T(typename internal::with_arith<T>::ret(t) + 1); + } + + /*! Return the predecessor of \a t. + ** + ** \note The goal is to iterate on types such as ntg::bin. + */ + template <typename T> + T + pred(const T&t) + { + return T(typename internal::with_arith<T>::ret(t) - 1); + } + + namespace internal { + /*! Default less. + ** + ** Specialization of this class provides a less functor even for + ** types that do not support the operator "<". + */ + template <typename T> + struct default_less + { + typedef T arg_type; + bool operator()(const T& l, + const T& r) const + { + return l < r; + } + }; + } +} + +#endif Index: ntg/core/type_traits.hh --- ntg/core/type_traits.hh (revision 0) +++ ntg/core/type_traits.hh (revision 0) @@ -0,0 +1,66 @@ +// Copyright (C) 2001, 2002, 2003, 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 NTG_CORE_TYPE_TRAITS_HH +# define NTG_CORE_TYPE_TRAITS_HH + +# include <ntg/core/internal/traits.hh> + +namespace ntg +{ + + /*------------. + | type_traits | + `------------*/ + + //! Associates properties and methods to types. + /*! + type_traits gives a variable set of properties, depending on + the type considered. For example, type_traits<int_u8> can give + larger_type, max(), ... + + It refers to the exact type, this means type_traits<any<int_u8> > + will give the same results than type_traits<int_u8>. + + Traits can be defined for builtin values, so that type_traits<int> + works, this is the main advantage on T::xxx approach to define + properties. + */ + + // FIXME: should inherit from *traits<mlc_exact_type(T)> instead of + // optraits<T> directly. This makes things like + // type_traits<int_value<int_u<..> > >::max() possible. + + template <class T> + class type_traits : + public internal::optraits<T>, + public internal::typetraits<T> + {}; + +} // end of ntg. + +#endif // ndef NTG_CORE_TYPE_TRAITS_HH Index: ntg/core/math.hh --- ntg/core/math.hh (revision 0) +++ ntg/core/math.hh (revision 0) @@ -0,0 +1,82 @@ +// Copyright (C) 2001, 2002, 2003, 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 NTG_CORE_MATH_HH +# define NTG_CORE_MATH_HH + +# include <mlc/bool.hh> + +namespace mlc +{ + + namespace internal + { + + // Helper structs for pow2sup below. + + template<unsigned N> struct is_pow2 { typedef false_type ret; }; + template<> struct is_pow2<8> { typedef true_type ret; }; + template<> struct is_pow2<16> { typedef true_type ret; }; + template<> struct is_pow2<32> { typedef true_type ret; }; + template<> struct is_pow2<64> { typedef true_type ret; }; + + template<unsigned N, class> struct find_pow2sup; + template<unsigned N> struct find_pow2sup<N,true_type> { + enum { value = N }; + }; + template<unsigned N> struct find_pow2sup<N,false_type> { + enum { value = find_pow2sup< N+1, + typename is_pow2<N+1>::ret >::value }; + }; + + } // end of internal + + // Smaller power of 2 greater than N. + + template<unsigned N> + struct pow2sup { + enum { + value = + internal::find_pow2sup< N, + typename internal::is_pow2<N>::ret >::value + }; + private: + typedef typename is_true<N < 32>::ensure_type precondition_type; + }; + + // 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(); } + }; + +} // end of namespace mlc + +#endif // METALIC_MATH_HH Index: ntg/core/cats.hh --- ntg/core/cats.hh (revision 59) +++ ntg/core/cats.hh (working copy) @@ -1,77 +0,0 @@ -// 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 INTEGRE_CORE_CATS_HH -# define INTEGRE_CORE_CATS_HH - -# include <mlc/types.hh> - - -/*! \macro FIXME:doc -*/ - -# define ntg_category_type(T) typename ntg::category_type<T>::ret - - - -/*! \namespace ntg -** \brief ntg namespace. -*/ -namespace ntg { - - - /*! \class category_type<T> - ** - ** FIXME: doc - ** - */ - template <typename T> - struct category_type - { - typedef mlc::undefined_type ret; - }; - - - /*! \namespace ntg::cat - ** \brief ntg::cat namespace. - */ - namespace cat { - - struct color; - struct enum_value; - struct integer; - // FIXME:... - - } // end of namespace ntg::cat - - -} // end of namespace ntg - - - - -#endif // ! INTEGRE_CORE_CATS_HH Index: ntg/core/value.hh --- ntg/core/value.hh (revision 0) +++ ntg/core/value.hh (revision 0) @@ -0,0 +1,122 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CORE_VALUE_HH +# define NTG_CORE_VALUE_HH + +# include <ntg/core/macros.hh> +# include <ntg/core/type.hh> +# include <ntg/core/type_traits.hh> + +namespace ntg { + + namespace internal { + + /*---------. + | any_ntg_ | + `---------*/ + + // FIXME: it is not possible to inherit from mlc::any, because it + // gives all subtypes an implicit access to the mlc + // namespace. This is problematic since min or max for example are + // defined in mlc and ntg::internal namespaces, and it creates + // conflicts with g++ (3.2, 3.3, 3.4). + + //! Bridge to internal for ntg type hierarchy. + /*! + This class is a bridge with the internal namespace. Indeed, + global operators (such as <T,U> operator+(T, U)) are defined in + the internal namespace to allow a "using namespace ntg" + directive without breaking external classes interactions. + + However, ntg types need to see those operators. This is done by + inheriting from internal::any_ntg_, thanks to Koenig lookup. + + See comments in <ntg/config/system.hh>. + */ + template <class E> + class any_ntg_ : public ntg::any<E> + {}; + + } // end of internal. + + /*--------. + | any_ntg | + `--------*/ + + //! Top of the ntg types hierarchy. + /*! + Just an abstraction. + */ + template <class E> + class any_ntg : public internal::any_ntg_<E> + {}; + + /*------. + | value | + `------*/ + + //! Concrete value storage class. + /*! + This class actually store the real value (usually a builtin). The + value type is determined from the exact type. + + For example, int_u8::val() returns an "unsigned char". + */ + template <class E> + class value : public any_ntg<E> + { + // note: here it is not possible to use ntg::type_traits, + // because of recursive instanciation problems. + typedef typename internal::typetraits<E>::storage_type storage_type; + + public: + // Hooks + storage_type& val() { return val_; } + const storage_type& val() const { return val_; } + + protected: + storage_type val_; + }; + + namespace internal { + + template <class E> + struct typetraits<value<E> > + { + typedef E unsafe_type; + }; + + template <class E> + struct optraits<value<E> > + {}; + + } + +} // end of ntg. + +#endif // !NTG_CORE_VALUE_HH Index: ntg/core/contract.hh --- ntg/core/contract.hh (revision 0) +++ ntg/core/contract.hh (revision 0) @@ -0,0 +1,57 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CORE_CONTRACT_HH +# define NTG_CORE_CONTRACT_HH + +# include <mlc/contract.hh> + +/* + Custom version of assert, which can print a context string if + NTG_DEBUG is defined. The context string should be filled by + operators. +*/ + +# ifdef NDEBUG +# define ntg_assert(expr) (static_cast<void>(0)) +# else +// FIXME: repair NTG_DEBUG +# if 0 // ifdef NTG_DEBUG +# define ntg_assert(expr) \ + if (!(expr)) \ + { \ + if (!ntg::debug_context.empty()) \ + std::cerr << "In context: " << ntg::debug_context \ + << std::endl; \ + assertion(expr); \ + } +# else + # define ntg_assert(expr) assertion(expr) +# endif +# endif + +#endif // !NTG_CORE_CONTRACT_HH Index: ntg/core/internal/global_ops.hh --- ntg/core/internal/global_ops.hh (revision 0) +++ ntg/core/internal/global_ops.hh (revision 0) @@ -0,0 +1,243 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_CORE_INTERNAL_GLOBAL_OPS_HH +# define NTG_CORE_INTERNAL_GLOBAL_OPS_HH + +/* + This header defines global operators (arithmetic, logical, and + comparison). They are examined when at least one ntg type is + involved. They are required to have a precise dispatch, you can + check the documentation for more details. +*/ + +# include <mlc/contract.hh> +# include <mlc/is_a.hh> + +# include <ntg/real/builtin_float.hh> +# include <ntg/real/optraits_builtin_int.hh> +# include <ntg/core/internal/global_ops_traits.hh> +# include <ntg/core/macros.hh> +# include <ntg/core/value.hh> +# include <ntg/utils/debug.hh> + +// macros defs +# include <ntg/core/internal/global_ops_defs.hh> + +// min and max +# include <algorithm> + +namespace ntg +{ + + /* + Global operators are defined in the internal namespace to avoid + any possible clash, even when "using namespace ntg" directive is + used. + */ + + namespace internal + { + + /*------------------------. + | Arithmetic assignements | + `------------------------*/ + + GLOBAL_ASSIGN_OP(operator+=, plus_equal) + GLOBAL_ASSIGN_OP_BUILTIN_INT(operator+=, plus_equal) + GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator+=, plus_equal) + + GLOBAL_ASSIGN_OP(operator-=, minus_equal) + GLOBAL_ASSIGN_OP_BUILTIN_INT(operator-=, minus_equal) + GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator-=, minus_equal) + + GLOBAL_ASSIGN_OP(operator*=, times_equal) + GLOBAL_ASSIGN_OP_BUILTIN_INT(operator*=, times_equal) + GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator*=, times_equal) + + GLOBAL_ASSIGN_OP(operator/=, div_equal) + GLOBAL_ASSIGN_OP_BUILTIN_INT(operator/=, div_equal) + GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator/=, div_equal) + + GLOBAL_ASSIGN_OP(operator%=, mod_equal) + GLOBAL_ASSIGN_OP_BUILTIN_INT(operator%=, mod_equal) + + /*---------------------. + | Logical assignements | + `---------------------*/ + + // FIXME: implement |=, &= and ^= in optraits<bool>. + + GLOBAL_ASSIGN_OP(operator|=, logical_or_equal) + // GLOBAL_ASSIGN_OP_BUILTIN_BOOL(operator|=, logical_or_equal) + + GLOBAL_ASSIGN_OP(operator&=, logical_and_equal) + // GLOBAL_ASSIGN_OP_BUILTIN_BOOL(operator&=, logical_and_equal) + + GLOBAL_ASSIGN_OP(operator^=, logical_xor_equal) + // GLOBAL_ASSIGN_OP_BUILTIN_BOOL(operator^=, logical_xor_equal) + + /*----------------------. + | Arithmetic operations | + `----------------------*/ + + GLOBAL_ARITH_OP(operator+, plus) + GLOBAL_ARITH_OP(operator-, minus) + GLOBAL_ARITH_OP(operator*, times) + GLOBAL_ARITH_OP(operator/, div) + GLOBAL_ARITH_OP(operator%, mod) + + /*------------------. + | Logical operators | + `------------------*/ + + GLOBAL_LOGICAL_OP(operator|, logical_or) + GLOBAL_LOGICAL_OP(operator&, logical_and) + GLOBAL_LOGICAL_OP(operator^, logical_xor) + + /*---------------------. + | Comparison operators | + `---------------------*/ + + GLOBAL_CMP_OP(operator==, cmp_eq) + + template <class T1, class T2> inline + bool + operator!=(const T1& lhs, const T2& rhs) + { return !(lhs == rhs); } + + // >, >= and <= operators are defined using <. They are not + // implicitely defined so we have to do so by hand. + + GLOBAL_CMP_OP(operator<, cmp_lt) + + template <class T1, class T2> inline + bool + operator>(const T1& lhs, const T2& rhs) + { return rhs < lhs; } + + template <class T1, class T2> inline + bool + operator>=(const T1& lhs, const T2& rhs) + { return !(lhs < rhs); } + + template <class T1, class T2> inline + bool + operator<=(const T1& lhs, const T2& rhs) + { return !(rhs < lhs); } + + /*-----------------------------. + | Arithmetical unary operators | + `-----------------------------*/ + + // plus + + template <class T> inline + const T& + operator+(const T& val) + { + return val; + } + + template<class T> inline + const T& + operator++(T& val) + { + val += ntg_unit_val(T); + return val; + } + + template<class T> inline + T + operator++(T& val, int) + { + T tmp(val); + val += ntg_unit_val(T); + return tmp; + } + + // minus + + template <class T> inline + const ntg_signed_type(T) + operator-(const T& val) + { + typedef ntg_signed_type(T) signed_type; + return static_cast<signed_type>(ntg_zero_val(T)) - val; + } + + template<class T> inline + const T& operator--(T& val) + { + val -= ntg_unit_val(T); + return val; + } + + template<class T> inline + T operator--(T& val, int) + { + T tmp(val); + val -= ntg_unit_val(T); + return tmp; + } + + /*------------------. + | Min/Max operators | + `------------------*/ + + /* + These operators are slighly different from standard library ones + since they can operate on values of 2 different types. + */ + + template <class T1, class T2> inline + ntg_return_type(min, T1, T2) + min (const T1& lhs, const T2& rhs) + { + typedef ntg_return_type(max, T1, T2) result_type; + return (lhs < rhs) ? result_type(lhs) : result_type(rhs); + } + + template <class T1, class T2> inline + ntg_return_type(max, T1, T2) + max (const T1& lhs, const T2& rhs) + { + typedef ntg_return_type(max, T1, T2) result_type; + return (lhs > rhs) ? result_type(lhs) : result_type(rhs); + } + + } // end of internal. + + // FIXME: those are needed to handle max and min between two builtin + // types. Maybe std::min and std::max should be extended to work + // with builtin types? + using internal::min; + using internal::max; + +} // end of ntg. + +#endif // ndef NTG_CORE_INTERNAL_GLOBAL_OPS_HH Index: ntg/core/internal/global_ops_defs.hh --- ntg/core/internal/global_ops_defs.hh (revision 0) +++ ntg/core/internal/global_ops_defs.hh (revision 0) @@ -0,0 +1,274 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CORE_INTERNAL_GLOBAL_OPS_DEFS_HH +# define NTG_CORE_INTERNAL_GLOBAL_OPS_DEFS_HH + +/* + Global operators macros, used to factorize global operators + definitions. +*/ + +/* + For every operator, we need a specialization for every builtin type + to avoid overloading problems. So here are the defined operators: + + operatorX(ntg_type, T2) (1) + operatorX(builtin1, T2) (2) + operatorX(builtin2, T2) + ... + + This handles all cases without ambiguity: + + ntg_type X ntg_type ==> (1) + ntg_type X builtin ==> (1) + builtin1 X ntg_type ==> (2) +*/ + +/*-------------. +| ASSIGNEMENTS | +`-------------*/ + +/*---------------------------------. +| Global assignements for builtins | +`---------------------------------*/ + +# define GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, Builtin) \ +template <class T2> inline \ +Builtin& \ +Op(Builtin& lhs, const value<T2>& rhs) \ +{ return optraits<Builtin>::Name(lhs, rhs.exact()); } + +/*-----------------------------------------------. +| Global assignements for ntg_types and builtins | +`------------------------------------------------*/ + +# define GLOBAL_ASSIGN_OP_BUILTIN_INT(Op, Name) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed long) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned long) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed int) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned int) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed short) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned short) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, char) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed char) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned char) + +# define GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(Op, Name) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, float) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, double) + +# define GLOBAL_ASSIGN_OP_BUILTIN_BOOL(Op, Name) \ +GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, bool) + +# define GLOBAL_ASSIGN_OP(Op, Name) \ +template <class T1, class T2> inline \ +T1& \ +Op(value<T1>& lhs, const T2& rhs) \ +{ return optraits<T1>::Name(lhs.exact(), rhs); } + +/*---------------------. +| ARITHMETIC OPERATORS | +`---------------------*/ + +/*-----------------------------------------. +| Global arithmetic operators for builtins | +`-----------------------------------------*/ + +# define GLOBAL_ARITH_OP_BUILTIN(Op, Name, Builtin) \ +template <class T2> inline \ +ntg_return_type(Name, Builtin, T2) \ +Op(Builtin lhs, const value<T2>& rhs) \ +{ \ + typedef ntg_deduced_traits_type(Name, Builtin, T2) deduced_type; \ + \ + typedef typename deduced_type::impl impl; \ + typedef typename deduced_type::lhs_type lhs_type; \ + typedef typename deduced_type::rhs_type rhs_type; \ + \ + return optraits<impl>::Name(static_cast<lhs_type>(lhs), \ + static_cast<rhs_type>(rhs.exact())); \ +} + +/*------------------------------------------------------------. +| Global arithmetic operators for both ntg_types and builtins | +`------------------------------------------------------------*/ + +# define GLOBAL_ARITH_OP(Op, Name) \ +template <class T1, class T2> inline \ +ntg_return_type(Name, T1, T2) \ +Op(const value<T1>& lhs, const T2& rhs) \ +{ \ + /* \ + This code is an example of debugging information, disabled until \ + a good way to handle debug is found. \ + */ \ + \ + /* \ + if (ntg_is_debug_active) \ + { \ + std::ostringstream s; \ + s << typename_of<ntg_return_type(Name, T1, T2)>() << " " \ + << #Op << "(" << typename_of<T1>() << " lhs, " \ + << typename_of<T2>() << " rhs)" << std::endl \ + << "\twith lhs = " << lhs.exact() << " and rhs = " << rhs; \ + ntg_debug_context_set(s.str()); \ + } \ + */ \ + \ + typedef ntg_deduced_traits_type(Name, T1, T2) deduced_type; \ + \ + typedef typename deduced_type::impl impl; \ + typedef typename deduced_type::lhs_type lhs_type; \ + typedef typename deduced_type::rhs_type rhs_type; \ + \ + return optraits<impl>::Name(static_cast<lhs_type>(lhs.exact()), \ + static_cast<rhs_type>(rhs)); \ +} \ + \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed long) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned long) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed int) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned int) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed short) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned short) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed char) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned char) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, char) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, float) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, double) \ +GLOBAL_ARITH_OP_BUILTIN(Op, Name, bool) + +/*------------------. +| LOGICAL OPERATORS | +`------------------*/ + +/*--------------------------------------. +| Global logical operators for builtins | +`--------------------------------------*/ + +# define GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, Builtin) \ +template <class T2> inline \ +ntg_return_type(logical, Builtin, T2) \ +Op(const Builtin& lhs, const value<T2>& rhs) \ +{ \ + typedef ntg_deduced_traits_type(logical, Builtin, T2) deduced_type; \ + \ + typedef typename deduced_type::impl impl; \ + typedef typename deduced_type::lhs_type lhs_type; \ + typedef typename deduced_type::rhs_type rhs_type; \ + \ + return optraits<impl>::Name(static_cast<lhs_type>(lhs), \ + static_cast<rhs_type>(rhs.exact())); \ +} + +/*----------------------------------------------------. +| Global logical operators for ntg_types and builtins | +`----------------------------------------------------*/ + +# define GLOBAL_LOGICAL_OP(Op, Name) \ +template <class T1, class T2> inline \ +ntg_return_type(logical, T1, T2) \ +Op(const value<T1>& lhs, const T2& rhs) \ +{ \ + typedef ntg_deduced_traits_type(logical, T1, T2) deduced_type; \ + \ + typedef typename deduced_type::impl impl; \ + typedef typename deduced_type::lhs_type lhs_type; \ + typedef typename deduced_type::rhs_type rhs_type; \ + \ + return optraits<impl>::Name(static_cast<lhs_type>(lhs.exact()), \ + static_cast<rhs_type>(rhs)); \ +} \ + \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed long) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned long) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed int) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned int) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed short) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned short) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed char) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned char) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, float) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, double) \ +GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, bool) + +/*---------------------. +| COMPARISON OPERATORS | +`---------------------*/ + +/*-----------------------------------------. +| Global comparison operators for builtins | +`-----------------------------------------*/ + +# define GLOBAL_CMP_OP_BUILTIN(Op, Name, Builtin) \ +template <class T2> inline \ +bool \ +Op(const Builtin& lhs, const value<T2>& rhs) \ +{ \ + typedef ntg_deduced_traits_type(cmp, Builtin, T2) deduced_type; \ + \ + typedef typename deduced_type::impl impl; \ + typedef typename deduced_type::lhs_type lhs_type; \ + typedef typename deduced_type::rhs_type rhs_type; \ + \ + return optraits<impl>::Name(static_cast<lhs_type>(lhs), \ + static_cast<rhs_type>(rhs.exact())); \ +} + +/*------------------------------------------------------------. +| Global comparison operators for both ntg_types and builtins | +`------------------------------------------------------------*/ + +# define GLOBAL_CMP_OP(Op, Name) \ +template <class T1, class T2> inline \ +bool \ +Op(const value<T1>& lhs, const T2& rhs) \ +{ \ + typedef ntg_deduced_traits_type(cmp, T1, T2) deduced_type; \ + \ + typedef typename deduced_type::impl impl; \ + typedef typename deduced_type::lhs_type lhs_type; \ + typedef typename deduced_type::rhs_type rhs_type; \ + \ + return optraits<impl>::Name(static_cast<lhs_type>(lhs.exact()), \ + static_cast<rhs_type>(rhs)); \ +} \ + \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, signed long) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned long) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, signed int) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned int) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, signed short) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned short) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, signed char) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned char) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, float) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, double) \ +GLOBAL_CMP_OP_BUILTIN(Op, Name, bool) + +#endif // !NTG_CORE_INTERNAL_GLOBAL_OPS_DEFS_HH Index: ntg/core/internal/macros.hh --- ntg/core/internal/macros.hh (revision 0) +++ ntg/core/internal/macros.hh (revision 0) @@ -0,0 +1,87 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_CORE_INTERNAL_MACROS_HH +# define NTG_CORE_INTERNAL_MACROS_HH + +/* + All internal macros starts have an ntgi prefix. +*/ + +/*----------------. +| types accessors | +`----------------*/ + +/* + In come internal code, it is not always possible to use + type_traits<T>, especially within the code of the T class itself. + That's why ntgi_* macros exists. +*/ + +# define ntgi_storage_type(T) \ +typename ntg::internal::typetraits< T >::storage_type + +# define ntgi_abstract_type(T) \ +typename ntg::internal::typetraits< T >::abstract_type + +# define ntgi_optraits_type(T) \ +typename ntg::internal::typetraits< T >::optraits_type + +# define ntgi_behavior_type(T) \ +typename ntg::internal::typetraits< T >::behavior_type + +# define ntgi_base_type(T) \ +typename ntg::internal::typetraits< T >::base_type + +# define ntgi_signed_type(T) \ +typename ntg::internal::typetraits< T >::signed_type + +# define ntgi_unsigned_type(T) \ +typename ntg::internal::typetraits< T >::unsigned_type + +# define ntgi_cumul_type(T) \ +typename ntg::internal::typetraits< T >::cumul_type + +# define ntgi_largest_type(T) \ +typename ntg::internal::typetraits< T >::largest_type + +# define ntgi_signed_largest_type(T) \ +typename ntg::internal::typetraits< T >::signed_largest_type + +# define ntgi_signed_cumul_type(T) \ +typename ntg::internal::typetraits< T >::signed_cumul_type + +# define ntgi_unsigned_largest_type(T) \ +typename ntg::internal::typetraits< T >::unsigned_largest_type + +# define ntgi_unsigned_cumul_type(T) \ +typename ntg::internal::typetraits< T >::unsigned_cumul_type + +# define ntgi_integer_type(T) \ +typename ntg::internal::typetraits< T >::integer_type + +#endif // !NTG_CORE_INTERNAL_MACROS_HH Index: ntg/core/internal/traits.hh --- ntg/core/internal/traits.hh (revision 0) +++ ntg/core/internal/traits.hh (revision 0) @@ -0,0 +1,82 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_CORE_INTERNAL_TRAITS_HH +# define NTG_CORE_INTERNAL_TRAITS_HH + +/* + Traits used internally, encapsulated in type_traits for external + use. +*/ + +# include <ntg/core/abstract_hierarchy.hh> +# include <string> +namespace ntg { + + namespace internal { + + /*-----------. + | typetraits | + `-----------*/ + + //! Associates types to types. + /*! + Specialize it for every types. + + Please note that typetraits only associates types, and not + methods. This is necessary to handle mutual instantiation + problems, as optraits usually needs typetraits to be + instantiated. + */ + template <class T> + struct typetraits + { + typedef data_type abstract_type; + }; + + /*---------. + | optraits | + `---------*/ + + //! Associates functions to types. + /* + It should be specialized for every types. + */ + template <class T> + struct optraits + { + static std::string name() + { + return "unknown_data_type"; + } + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_CORE_INTERNAL_TRAITS_HH Index: ntg/core/internal/global_ops_traits.hh --- ntg/core/internal/global_ops_traits.hh (revision 0) +++ ntg/core/internal/global_ops_traits.hh (revision 0) @@ -0,0 +1,213 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CORE_INTERNAL_GLOBAL_OPS_TRAITS_HH +# define NTG_CORE_INTERNAL_GLOBAL_OPS_TRAITS_HH + +/* + Tools to determine return type of operators given the parameters + types. For each type, one has to specialize the traits + operator_xxx, and then use deduce_from_traits<operator_xxx, T1, T2> + as return type for operatorxxx(T1, T2) functions. +*/ + +# include <ntg/core/macros.hh> +# include <ntg/core/type_traits.hh> + +# include <mlc/bool.hh> + +namespace ntg { + + namespace internal { + + /*-----------. + | Meta tools | + `-----------*/ + + struct undefined_traits {}; + + template <class T> + struct meta_undefined_traits + { + typedef undefined_traits ret; + typedef undefined_traits lhs_type; + typedef undefined_traits rhs_type; + typedef undefined_traits traits_lhs_type; + typedef undefined_traits traits_rhs_type; + }; + + template <class T> + struct is_defined { enum { ret = true }; }; + template <> + struct is_defined<undefined_traits> { enum { ret = false }; }; + + /* + get_order, get_order_inv + + These structs are used to inverse input types (if the operator + is commutative) and to specify whether input types should be + converted into another type (eg. the corresponding ntg_type). + */ + + template <class T1, class T2> + struct get_order + { + typedef T1 traits_lhs_type; + typedef T2 traits_rhs_type; + + typedef T1 lhs_type; + typedef T2 rhs_type; + }; + + template <class T1, class T2> + struct get_order_inv + { + typedef T2 traits_lhs_type; + typedef T1 traits_rhs_type; + + typedef T1 lhs_type; + typedef T2 rhs_type; + }; + + /*---------------------------. + | Operator traits definition | + `---------------------------*/ + //! Give return type for operators, depending on the input types. + /*! + operator_traits traits should not be used directly. Instead one + should use deduce_from_traits, see comments below for more + details. + + These traits defines 3 properties: + + * commutative (enum): Tells whether the operator is commutative + or not. + + * ret (typedef): Specifies the return type. + + * impl (typedef): Specifies the type which implement the + operator, that is, the type T such as optraits<T>::operatorX + is the good implementation. + + To specify the concerned operator, one empty class represent + each operator. For example, to specify the traits associated + to the + operator with T1 and T2 as arguments: + + template <class T1, class T2> + struct operator_traits<operator_plus, T1, T2> + { + ... + } + */ + + template <class Op, class T, class U> + struct operator_traits + { + enum { commutative = false }; + typedef undefined_traits ret; + typedef undefined_traits impl; + }; + + struct operator_plus {}; + struct operator_minus {}; + struct operator_times {}; + struct operator_div {}; + struct operator_mod {}; + struct operator_logical {}; + struct operator_cmp {}; + struct operator_min {}; + struct operator_max {}; + + /*-----------------------------------. + | deduce_from_traits<operator, T, U> | + `-----------------------------------*/ + //! Find the good operator_traits, following a simple algorithm. + /*! + deduce_from_traits should generally be used instead of + operator_traits. Indeed, it has a handy algorithm to find return + types: + + 1) Convert T1 and T2 to ntg types. + 2) Check if traits<T1, T2> is defined. + 3) Else, check if traits<T2, T1> is defined + AND traits<T2, T1>::commutative is true. + + deduce_from_traits defines several types: + + - lhs_type and rhs_type: The types into which the first and + second paramaters should be converted before called the + implementation. + + - ret: The return type. + + - impl: The implementation type. + + - deduced_traits: A pointer to the good operator_traits<> + specialization. This can be useful sometimes. + */ + + template <class Op, class T, class U> + struct deduce_from_traits + { + private: + typedef ntg_type(T) T1; + typedef ntg_type(U) T2; + + typedef typename operator_traits<Op, T1, T2>::ret traits; + typedef typename operator_traits<Op, T2, T1>::ret rev_traits; + + enum { can_invert = (operator_traits<Op, T2, T1>::commutative + && is_defined<rev_traits>::ret) }; + + typedef typename + mlc::if_<is_defined<traits>::ret, + get_order<T1, T2>, typename + mlc::if_<can_invert, + get_order_inv<T1, T2>, + meta_undefined_traits<undefined_traits> + >::ret + >::ret deduced_type; + + typedef typename deduced_type::traits_lhs_type traits_lhs_type; + typedef typename deduced_type::traits_rhs_type traits_rhs_type; + + public: + typedef operator_traits<Op, + traits_lhs_type, + traits_rhs_type> deduced_traits; + + typedef typename deduced_type::lhs_type lhs_type; + typedef typename deduced_type::rhs_type rhs_type; + typedef typename deduced_traits::ret ret; + typedef typename deduced_traits::impl impl; + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_CORE_INTERNAL_GLOBAL_OPS_TRAITS_HH Index: ntg/int.hh --- ntg/int.hh (revision 0) +++ ntg/int.hh (revision 0) @@ -0,0 +1,42 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_INT_HH +# define NTG_INT_HH + +/* + Proxy header for integer types (int_u and int_s). +*/ + +// Note: these two types are included together as it is quite +// impossible to use only int_u. For example, doing int_u + 1 needs +// int_s as 1 is a signed int builtin type. + +# include <ntg/real/int_u.hh> +# include <ntg/real/int_s.hh> + +#endif // !NTG_INT_HH Index: ntg/range.hh --- ntg/range.hh (revision 0) +++ ntg/range.hh (revision 0) @@ -0,0 +1,37 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_RANGE_HH +# define NTG_RANGE_HH + +/* + Proxy header for range. +*/ + +# include <ntg/real/range.hh> + +#endif // !NTG_RANGE_HH Index: ntg/cycle.hh --- ntg/cycle.hh (revision 0) +++ ntg/cycle.hh (revision 0) @@ -0,0 +1,37 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CYCLE_HH +# define NTG_CYCLE_HH + +/* + Proxy header for cycle. +*/ + +# include <ntg/real/cycle.hh> + +#endif // !NTG_CYCLE_HH Index: ntg/utils/debug.hh --- ntg/utils/debug.hh (revision 0) +++ ntg/utils/debug.hh (revision 0) @@ -0,0 +1,94 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_UTILS_DEBUG_HH +# define NTG_UTILS_DEBUG_HH + +# include <ntg/core/macros.hh> +# include <ntg/core/type_traits.hh> + +# include <string> + +namespace ntg +{ + + /*---------------------. + | typename_of_var(obj) | + `---------------------*/ + + template<class T> inline + std::string + typename_of_var(const T&) + { return ntg_name(T); } + + /*-----------------. + | typename_of<T>() | + `-----------------*/ + + /* + This function is handy then there are commas in the type + expression. Else ntg_name(T) is shorter. + */ + + template<class T> inline + std::string + typename_of() + { return ntg_name(T); } + + /* + Debug context. The idea is to keep a context string to simplify + debugging when an assert fails somewhere in a hidden operator. As + this can be slow, a dynamic boolean specifies wheter the context + has to be maintained or not. + */ + +#ifdef NTG_DEBUG + extern bool debug_active; + extern std::string debug_context; +#endif + +} + +# ifdef NTG_DEBUG +# define ntg_debug_define_vars(State) \ + bool ntg::debug_active = State; \ + std::string ntg::debug_context; +# define ntg_debug_activate() ntg::debug_active = true +# define ntg_debug_desactivate() ntg::debug_active = false +# define ntg_is_debug_active (ntg::debug_active == true) +# define ntg_debug_context_set(Context) ntg::debug_context = Context +# define ntg_debug_context_clear(Context) ntg::debug_context.clear() +# else +# define ntg_debug_define_vars(State) +# define ntg_debug_activate() +# define ntg_debug_desactivate() +# define ntg_is_debug_active false +# define ntg_debug_context_set(Context) +# define ntg_debug_context_clear(Context) +# endif + +#endif // !NTG_UTILS_DEBUG_HH Index: ntg/utils/cast.hh --- ntg/utils/cast.hh (revision 0) +++ ntg/utils/cast.hh (revision 0) @@ -0,0 +1,236 @@ +// Copyright (C) 2001, 2002, 2003, 2004 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 NTG_UTILS_CAST_HH +# define NTG_UTILS_CAST_HH + +# include <ntg/config/system.hh> +# include <ntg/core/macros.hh> +# include <ntg/core/predecls.hh> +# include <ntg/core/type_traits.hh> +# include <ntg/real/real_value.hh> + +// FIXME: this file is completely broken, taking float_value as +// parameter does not make sense. + +/*-------. +| macros | +`-------*/ + +# define TO_NTG_CAST(Dest) \ + template<class T> \ + inline ntg_##Dest##_type(T) to_##Dest##_ntg(T val) \ + { \ + return static_cast<ntg_##Dest##_type(T)>(val); \ + } + +namespace ntg { + + /*---------. + | to_ntg() | + `---------*/ + + template<class T> + inline ntg_type(T) to_ntg(T val) + { + return static_cast<ntg_type(T)>(val); + } + + TO_NTG_CAST(signed) + + namespace cast { + + // FIXME: force does not seem to have any reason to live. + + /*------. + | force | + `------*/ + + // a cast is performed instead of a constructor (unsafe one) call + // because this last one may not be available with the good + // signature. + template<class Tdest, class Tsrc> inline + const Tdest + force(const Tsrc& val) + { + return ntg_unsafe_type(Tdest)(val); + } + + /*------. + | bound | + `------*/ + + // Like cast::force, but with saturation. + template<class Tdest, class Tsrc> inline + const Tdest + bound(const Tsrc& val) + { + if (ntg_sup_val(Tsrc) > ntg_sup_val(Tdest)) + if (val > Tsrc(Tdest(ntg_sup_val(Tdest)))) + return ntg_sup_val(Tdest); + if (ntg_inf_val(Tsrc) < ntg_inf_val(Tdest)) + if (val < Tsrc(Tdest(ntg_inf_val(Tdest)))) + return ntg_inf_val(Tdest); + return val; + } + + /*------. + | round | + `------*/ + + namespace internal { + template<class Tdest, class Tsrc> + struct _round { + // By default we don't define any function. + // This cast does only work on float input. + }; + + template<class Tdest, class Tsrc> + struct _round<Tdest, float_value<Tsrc> > + { + static const Tdest + doit(const float_value<Tsrc>& val) + { + // FIXME: this code seems out of date. + +#if 1 + // KLUDGE: Cast the rounded value to Tdest::value_t before + // returning it as Tdest. Otherwise g++-3.* complains there + // is no Tdest constructor taking a float argument. + return (ntg_storage_type(Tdest)) round(val.exact()); +#endif + // return round(val.exact()); + } + }; + + template<class Tdest> + struct _round<Tdest, float_s > + { + static const Tdest + doit(const float_s& val) + { + // FIXME: this code seems out of date. +#if 1 + // KLUDGE: Cast the rounded value to Tdest::value_t before + // returning it as Tdest. Otherwise g++-3.* complains there + // is no Tdest constructor taking a float argument. + return (ntg_storage_type(Tdest)) roundf(val); +#endif + // return roundf(val); + } + }; + + template<class Tdest> + struct _round<Tdest, double> + { + static const Tdest + doit(const float_d& val) + { + // FIXME: this code seems out of date. +#if 0 + // KLUDGE: Cast the rounded value to Tdest::value_t before + // returning it as Tdest. Otherwise g++-3.0 complains there + // is no Tdest constructor taking a float argument. + return (ntg_storage_type(Tdest)) round(val); +#endif + return round(val); + } + }; + + template<class Tdest, class Tsrc> + struct _round<float_value<Tdest>, float_value<Tsrc> > + { + static const Tdest + doit(const float_value<Tsrc>& val) + { + return val.exact(); + } + }; + + template<class Tsrc> + struct _round<float_s, float_value<Tsrc> > + { + static float_s + doit(const float_value<Tsrc>& val) + { + return val.exact(); + } + }; + + template<class Tsrc> + struct _round<float_d, float_value<Tsrc> > + { + static float_d + doit(const float_value<Tsrc>& val) + { + return val.exact(); + } + }; + + template<> + struct _round<float_s, float_d> + { + static float + doit(const double& val) + { + return val; + } + }; + + template<> + struct _round<float_d, float_s> + { + static float_d + doit(const float& val) + { + return val; + } + }; + } // end of internal. + + template<class Tdest, class Tsrc> inline + const Tdest round(const Tsrc& val) + { + return internal::_round<Tdest, Tsrc>::doit(val); + } + + /* Like cast::round, but with saturation. */ + template<class Tdest, class Tsrc> inline + const Tdest rbound(const Tsrc& val) + { + if (val > Tsrc(Tdest(ntg_max_val(Tdest)))) + return ntg_max_val(Tdest); + if (val < Tsrc(Tdest(ntg_min_val(Tdest)))) + return ntg_min_val(Tdest); + return cast::round<Tdest>(val); + } + + } // end of cast. + +} // end of ntg. + +#endif // NTG_UTILS_CAST_HH Index: ntg/vect/cplx.hh --- ntg/vect/cplx.hh (revision 0) +++ ntg/vect/cplx.hh (revision 0) @@ -0,0 +1,655 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_VECT_CPLX_HH +# define NTG_VECT_CPLX_HH + +# include <ntg/basics.hh> +# include <ntg/vect/cplx_representation.hh> +# include <ntg/vect/vec.hh> + +# include <mlc/cmp.hh> +# include <mlc/is_a.hh> + +/*------------------------------. +| Assignements operators macros | +`------------------------------*/ + +# define ASSIGN_CPLX_SCALAR_OPERATOR_SINGLE(Rep, Name, Op) \ +template <class T1, class T2> inline \ +static cplx<Rep, T1>& \ +Name(cplx<Rep, T1>& lhs, const T2& rhs) \ +{ \ + ntg_is_a(T2, real)::ensure(); \ + lhs.first() Op rhs; \ + return lhs; \ +} + +# define ASSIGN_CPLX_SCALAR_OPERATOR_BOTH(Rep, Name, Op) \ +template <class T1, class T2> inline \ +static cplx<Rep, T1>& \ +Name(cplx<Rep, T1>& lhs, const T2& rhs) \ +{ \ + ntg_is_a(T2, real)::ensure(); \ + lhs.first() Op rhs; \ + lhs.second() Op rhs; \ + return lhs; \ +} + +# define ASSIGN_CPLX_POLAR_SCALAR_OPERATOR(Name, Op) \ +template <class T1, class T2> inline \ +static cplx<polar, T1>& \ +Name(cplx<polar, T1>& lhs, const T2& rhs) \ +{ \ + ntg_is_a(T2, real)::ensure(); \ + cplx<rect, float_d> tmp(lhs); \ + tmp.real() Op rhs; \ + lhs = tmp; \ + return lhs; \ +} + +# define ASSIGN_CPLX_RECT_CPLX_OPERATOR_MULT(Name, Op1, Op2) \ +template <class T1, cplx_representation R2, class T2> inline \ +static cplx<rect, T1>& \ +Name(cplx<rect, T1>& lhs, const cplx<R2, T2>& rhs) \ +{ \ + cplx<polar, float_d> tmp(lhs); \ + tmp.magn() Op1 (float_d)rhs.magn(); \ + tmp.angle() Op2 (float_d)rhs.angle(); \ + lhs = tmp; \ + return lhs; \ +} + +# define ASSIGN_CPLX_RECT_CPLX_OPERATOR_ADD(Name, Op1, Op2) \ +template <cplx_representation R, class T1, class T2> inline \ +static cplx<rect, T1>& \ +Name(cplx<rect, T1>& lhs, const cplx<R, T2>& rhs) \ +{ \ + lhs.first() Op1 rhs.real(); \ + lhs.second() Op2 rhs.imag(); \ + return lhs; \ +} + +# define ASSIGN_CPLX_POLAR_CPLX_OPERATOR_MULT(Name, Op1, Op2) \ +template <cplx_representation R, class T1, class T2> inline \ +static cplx<polar, T1>& \ +Name(cplx<polar, T1>& lhs, const cplx<R, T2>& rhs) \ +{ \ + lhs.magn() Op1 rhs.magn(); \ + lhs.angle() Op2 rhs.angle(); \ + return lhs; \ +} + +# define ASSIGN_CPLX_POLAR_CPLX_OPERATOR_ADD(Name, Op) \ +template <cplx_representation R, class T1, class T2> inline \ +static cplx<polar, T1>& \ +Name(cplx<polar, T1>& lhs, const cplx<R, T2>& rhs) \ +{ \ + cplx<rect, float_d> tmp(lhs); \ + tmp.real() Op (float_d)rhs.real(); \ + tmp.imag() Op (float_d)rhs.imag(); \ + lhs = tmp; \ + return lhs; \ +} + +# define ASSIGN_CPLX_VECTOR_OPERATOR(Rep, Name, Op) \ +template <class T1, class T2> inline \ +static cplx<Rep, T1>& \ +Name(cplx<Rep, T1>& lhs, const vec<2, T2>& rhs) \ +{ \ + lhs.first() Op rhs[0]; \ + lhs.second() Op rhs[1]; \ + return lhs; \ +} + +/*-----------------------------. +| Arithemetic operators macros | +`-----------------------------*/ + +# define ARITH_CPLX_CPLX_OPERATOR(Rep1, Rep2, Name, Op) \ +template <class T1, class T2> \ +inline static \ +cplx<Rep1, ntg_return_type(Name, T1, T2)> \ +Name(const cplx<Rep1, T1>& lhs, const cplx<Rep2, T2>& rhs) \ +{ \ + typedef cplx<Rep1, ntg_return_type(Name, T1, T2)> return_type; \ + return_type result(lhs); \ + result Op rhs; \ + return result; \ +} + +# define ARITH_CPLX_SCALAR_OPERATOR(Rep, Name, Op) \ +template <class T1, class T2> \ +inline static \ +cplx<Rep, ntg_return_type(Name, T1, T2)> \ +Name(const cplx<Rep, T1>& lhs, const T2& rhs) \ +{ \ + ntg_is_a(T2, real)::ensure(); \ + typedef cplx<Rep, ntg_return_type(Name, T1, T2)> return_type; \ + return_type result(lhs); \ + result Op rhs; \ + return result; \ +} + +# define ARITH_CPLX_SCALAR_OPERATOR_COMMUTE(Rep, Name, Op) \ +template <class T1, class T2> \ +inline static \ +cplx<Rep, ntg_return_type(Name, T1, T2)> \ +Name(const T1& lhs, const cplx<Rep, T2>& rhs) \ +{ \ + return Name(rhs, lhs); \ +} + +# define ARITH_CPLX_VECTOR_OPERATOR(Rep, Name, Op) \ +template <class T1, class T2> \ +inline static \ +cplx<Rep, ntg_return_type(Name, T1, T2)> \ +Name(const cplx<Rep, T1>& lhs, const vec<2, T2>& rhs) \ +{ \ + typedef cplx<Rep, ntg_return_type(Name, T1, T2)> return_type; \ + return_type result(lhs); \ + result Op rhs; \ + return result; \ +} + +# define ARITH_CPLX_VECTOR_OPERATOR_COMMUTE_PLUS(Rep, Name, Op) \ +template <class T1, class T2> \ +inline static \ +cplx<Rep, ntg_return_type(Name, T1, T2)> \ +Name(const vec<2, T1>& lhs, const cplx<Rep, T2>& rhs) \ +{ \ + return Name(rhs, lhs); \ +} + +# define ARITH_CPLX_VECTOR_OPERATOR_COMMUTE_MINUS(Rep, Name, Op) \ +template <class T1, class T2> \ +inline static \ +cplx<Rep, ntg_return_type(Name, T1, T2)> \ +Name(const vec<2, T1>& lhs, const cplx<Rep, T2>& rhs) \ +{ \ + return Name(rhs, lhs).invert(); \ +} + +namespace ntg { + + namespace internal { + + /*----------------------. + | typetraits<cplx<R, T> | + `----------------------*/ + + // FIXME: why cplx<polar> does not inherit from vec<2, ...> ? + + template <cplx_representation R, class T> + struct typetraits<cplx<R, T> > : + public typetraits<vec<2, T, cplx<R, T> > > + { + typedef cplx<R, T> self; + typedef self ntg_type; + typedef optraits<self> optraits_type; + }; + + } // end of internal. + + /*-----------. + | cplx<R, T> | + `-----------*/ + + //! No default implementation. + template <cplx_representation R, class T> + class cplx; + + /*--------------. + | cplx<rect, T> | + `--------------*/ + + template <class T> + class cplx<rect, T> : public vec<2, T, cplx<rect, T> > + { + public: + + cplx(const T& re = 0, const T& im = 0) + { + this->val_[0] = re; + this->val_[1] = im; + } + + cplx<rect, T>& + operator=(const T& r) + { + this->val_[0] = r; + this->val_[1] = 0; + return *this; + } + + template<cplx_representation R, class T2> + cplx(const cplx<R, T2>& rhs) + { + this->val_[0] = (T)rhs.real(); + this->val_[1] = (T)rhs.imag(); + } + + template<cplx_representation R, class T2> + cplx<rect, T>& + operator=(const cplx<R, T2>& rhs) + { + this->val_[0] = (T)rhs.real(); + this->val_[1] = (T)rhs.imag(); + return *this; + } + + template<class T2> + cplx(const vec<2, T2>& rhs) + { + this->val_[0] = (T)rhs[0]; + this->val_[1] = (T)rhs[1]; + } + + template<class T2> + cplx<rect, T>& + operator=(const vec<2, T2>& rhs) + { + this->val_[0] = (T)rhs[0]; + this->val_[1] = (T)rhs[1]; + return *this; + } + + ~cplx() + { + ntg_is_a(T, ntg::real)::ensure(); + } + + // accessors + + const T real() const { return this->val_[0]; } + T& real() { return this->val_[0]; } + + const T imag() const { return this->val_[1]; } + T& imag() { return this->val_[1]; } + + const T first() const { return this->val_[0]; } + T& first() { return this->val_[0]; } + + const T second() const { return this->val_[1]; } + T& second() { return this->val_[1]; } + + // methods + + const float_d + magn() const + { + return sqrt(this->val_[0] * this->val_[0] + this->val_[1] * this->val_[1]); + } + + const float_d + angle() const + { + return atan2(this->val_[1], this->val_[0]); + } + + const cplx<rect, T> + conj() const + { + return cplx<rect, T>(this->val_[0], -this->val_[1]); + } + + const cplx<rect, T> + invert() const + { + return cplx<rect, T>(-this->val_[0], -this->val_[1]); + } + + const cplx<polar, float_d> + to_polar() const + { + return cplx<polar, float_d>(magn(), angle()); + } + + }; + + /*---------------. + | cplx<polar, T> | + `---------------*/ + + template <class T> + class cplx<polar, T> : public vect_value<cplx<polar, T> > + { + public: + + cplx(const T& ma = 0, const T& an = 0) + { + ntg_assert(ma >= 0); + this->val_[0] = ma; + this->val_[1] = an; + } + + cplx<polar, T>& operator=(const T& r) + { + this->val_[0] = r; + this->val_[1] = 0; + return *this; + } + + template<cplx_representation R, class T2> + cplx(const cplx<R, T2>& rhs) + { + this->val_[0] = (T)rhs.magn(); + this->val_[1] = (T)rhs.angle(); + } + + template<cplx_representation R, class T2> + cplx<polar, T>& operator=(const cplx<R, T2>& rhs) + { + this->val_[0] = (T)rhs.magn(); + this->val_[1] = (T)rhs.angle(); + return *this; + } + + ~cplx() + { + ntg_is_a(T, ntg::real)::ensure(); + } + + // accessors + + const T magn() const { return this->val_[0]; } + T& magn() { return this->val_[0]; } + + const T angle() const { return this->val_[1]; } + T& angle() { return this->val_[1]; } + + const T first() const { return this->val_[0]; } + T& first() { return this->val_[0]; } + + const T second() const { return this->val_[1]; } + T& second() { return this->val_[1]; } + + // methods + + const float_d + real() const + { + return this->val_[0] * cos(this->val_[1]); + } + + const float_d + imag() const + { + return this->val_[0] * sin(this->val_[1]); + } + + const cplx<polar, T> + conj() const + { + return cplx<polar, T>(this->val_[0], -this->val_[1]); + } + + const cplx<rect, T> + invert() const + { + return cplx<rect, T>(this->val_[0], this->val_[1] + M_PI); + } + + const cplx<rect, float_d> + to_rect() const + { + return cplx<rect, float_d>(real(), imag()); + } + + }; + + template<class T> + inline std::ostream& + operator<<(std::ostream& ostr, const cplx<rect, T>& rhs) + { + // Using an ostringstream is necessary to pretty print. + std::ostringstream str; + str << rhs.real() << " + " << rhs.imag() << "i"; + return ostr << str.str(); + } + + template<class T> + inline std::ostream& + operator<<(std::ostream& ostr, const cplx<polar, T>& rhs) + { + // Using an ostringstream is necessary to pretty print. + std::ostringstream str; + str << rhs.magn() << " * exp(" << rhs.angle() << "i)"; + return ostr << str.str(); + } + + namespace internal + { + + /*-------------------------. + | optraits<cplx<rect, T> > | + `-------------------------*/ + + template <class T> + class optraits<cplx<rect, T> > : public optraits<vec<2, T> > + { + typedef cplx<rect, T> self; + typedef typename typetraits<self>::storage_type storage_type_; + + public: + static self zero () { return self(); } + static self unit () { return self(1); } + + static unsigned max_print_width() + { + return 2 * ntg_max_print_width(T) + 4; + } + + static std::string + name() + { + std::ostringstream out; + out << "cplx<rect, " << optraits<T>::name() << ">" << std::ends; + return out.str(); + } + + ASSIGN_CPLX_SCALAR_OPERATOR_SINGLE(rect, plus_equal, +=) + ASSIGN_CPLX_SCALAR_OPERATOR_SINGLE(rect, minus_equal, -=) + ASSIGN_CPLX_SCALAR_OPERATOR_BOTH(rect, times_equal, *=) + ASSIGN_CPLX_SCALAR_OPERATOR_BOTH(rect, div_equal, /=) + + ASSIGN_CPLX_RECT_CPLX_OPERATOR_ADD(plus_equal, +=, +=) + ASSIGN_CPLX_RECT_CPLX_OPERATOR_ADD(minus_equal, -=, -=) + ASSIGN_CPLX_RECT_CPLX_OPERATOR_MULT(times_equal, *=, +=) + ASSIGN_CPLX_RECT_CPLX_OPERATOR_MULT(div_equal, /=, -=) + + ASSIGN_CPLX_VECTOR_OPERATOR(rect, plus_equal, +=) + ASSIGN_CPLX_VECTOR_OPERATOR(rect, minus_equal, -=) + + ARITH_CPLX_SCALAR_OPERATOR(rect, plus, +=) + ARITH_CPLX_SCALAR_OPERATOR_COMMUTE(rect, plus, +=) + ARITH_CPLX_SCALAR_OPERATOR(rect, minus, -=) + ARITH_CPLX_SCALAR_OPERATOR(rect, times, *=) + ARITH_CPLX_SCALAR_OPERATOR_COMMUTE(rect, times, *=) + ARITH_CPLX_SCALAR_OPERATOR(rect, div, /=) + + ARITH_CPLX_CPLX_OPERATOR(rect, rect, plus, +=) + ARITH_CPLX_CPLX_OPERATOR(rect, rect, minus, -=) + ARITH_CPLX_CPLX_OPERATOR(rect, rect, times, *=) + ARITH_CPLX_CPLX_OPERATOR(rect, rect, div, /=) + + ARITH_CPLX_CPLX_OPERATOR(rect, polar, plus, +=) + ARITH_CPLX_CPLX_OPERATOR(rect, polar, minus, -=) + ARITH_CPLX_CPLX_OPERATOR(rect, polar, times, *=) + ARITH_CPLX_CPLX_OPERATOR(rect, polar, div, /=) + + ARITH_CPLX_VECTOR_OPERATOR(rect, plus, +=) + ARITH_CPLX_VECTOR_OPERATOR_COMMUTE_PLUS(rect, plus, +=) + ARITH_CPLX_VECTOR_OPERATOR(rect, minus, -=) + ARITH_CPLX_VECTOR_OPERATOR_COMMUTE_MINUS(rect, minus, -=) + + template <class T1, cplx_representation R2, class T2> + inline static bool + cmp_eq (const cplx<rect, T1>& lhs, const cplx<R2, T2>& rhs) + { + if (lhs.real() != rhs.real() || lhs.imag() != rhs.imag()) + return false; + return true; + } + + }; + + /*--------------------------. + | optraits<cplx<polar, T> > | + `--------------------------*/ + + template <class T> + class optraits<cplx<polar, T> > + { + typedef cplx<polar, T> self; + typedef ntgi_storage_type(self) storage_type_; + + public: + static self zero () { return self(); } + + static self unit () { return self(1); } + + static unsigned max_print_width() + { + return 2 * ntg_max_print_width(T) + 4; + } + + static std::string + name() + { + std::ostringstream out; + out << "cplx<polar, " << optraits<T>::name() << ">" << std::ends; + return out.str(); + } + + ASSIGN_CPLX_POLAR_SCALAR_OPERATOR(plus_equal, +=) + ASSIGN_CPLX_POLAR_SCALAR_OPERATOR(minus_equal, -=) + ASSIGN_CPLX_SCALAR_OPERATOR_SINGLE(polar, times_equal, *=) + ASSIGN_CPLX_SCALAR_OPERATOR_SINGLE(polar, div_equal, /=) + + ASSIGN_CPLX_POLAR_CPLX_OPERATOR_ADD(plus_equal, +=) + ASSIGN_CPLX_POLAR_CPLX_OPERATOR_ADD(minus_equal, -=) + ASSIGN_CPLX_POLAR_CPLX_OPERATOR_MULT(times_equal, *=, +=) + ASSIGN_CPLX_POLAR_CPLX_OPERATOR_MULT(div_equal, /=, -=) + + ARITH_CPLX_SCALAR_OPERATOR(polar, plus, +=) + ARITH_CPLX_SCALAR_OPERATOR_COMMUTE(polar, plus, +=) + ARITH_CPLX_SCALAR_OPERATOR(polar, minus, -=) + ARITH_CPLX_SCALAR_OPERATOR(polar, times, *=) + ARITH_CPLX_SCALAR_OPERATOR_COMMUTE(polar, times, *=) + ARITH_CPLX_SCALAR_OPERATOR(polar, div, /=) + + ARITH_CPLX_CPLX_OPERATOR(polar, polar, plus, +=) + ARITH_CPLX_CPLX_OPERATOR(polar, polar, minus, -=) + ARITH_CPLX_CPLX_OPERATOR(polar, polar, times, *=) + ARITH_CPLX_CPLX_OPERATOR(polar, polar, div, /=) + + ARITH_CPLX_CPLX_OPERATOR(polar, rect, plus, +=) + ARITH_CPLX_CPLX_OPERATOR(polar, rect, minus, -=) + ARITH_CPLX_CPLX_OPERATOR(polar, rect, times, *=) + ARITH_CPLX_CPLX_OPERATOR(polar, rect, div, /=) + + template <class T1, cplx_representation R2, class T2> + inline static bool + cmp_eq (const cplx<polar, T1>& lhs, const cplx<R2, T2>& rhs) + { + if (lhs.magn() != rhs.magn() || lhs.angle() != rhs.angle()) + return false; + return true; + } + + }; + + /*-----------------------. + | operator traits macros | + `-----------------------*/ + + // FIXME: I think there should be an easy way to simplify this. + // -- nes + +# define CPLX_SCALAR_OPERATORS_TRAITS(Name, CommuteBool) \ + template <cplx_representation R1, class T1, class T2> \ + struct operator_traits<operator_##Name, cplx<R1, T1>, T2> \ + { \ + enum { commutative = CommuteBool }; \ + typedef cplx<R1, ntg_return_type(Name, T1, T2)> ret; \ + typedef cplx<R1, T1> impl; \ + } + +# define CPLX_CPLX_OPERATORS_TRAITS(Name, CommuteBool) \ + template <cplx_representation R1, \ + class T1, \ + cplx_representation R2, class T2> \ + struct operator_traits<operator_##Name, \ + cplx<R1, T1>, cplx<R2, T2> > \ + { \ + enum { commutative = CommuteBool }; \ + typedef cplx<R1, ntg_return_type(Name, T1, T2)> ret; \ + typedef cplx<R1, T1> impl; \ + } + +# define CPLX_VECTOR_OPERATORS_TRAITS(Rep, Name, CommuteBool) \ + template <class T1, class T2> \ + struct operator_traits<operator_##Name, \ + cplx<Rep, T1>, vec<2, T2> > \ + { \ + enum { commutative = CommuteBool }; \ + typedef cplx<Rep, ntg_return_type(Name, T1, T2)> ret; \ + typedef cplx<Rep, T1> impl; \ + } + + /*----------------. + | operator traits | + `----------------*/ + + CPLX_SCALAR_OPERATORS_TRAITS(plus, true); + CPLX_SCALAR_OPERATORS_TRAITS(minus, true); + CPLX_SCALAR_OPERATORS_TRAITS(times, true); + CPLX_SCALAR_OPERATORS_TRAITS(div, true); + + CPLX_CPLX_OPERATORS_TRAITS(plus, true); + CPLX_CPLX_OPERATORS_TRAITS(minus, true); + CPLX_CPLX_OPERATORS_TRAITS(times, true); + CPLX_CPLX_OPERATORS_TRAITS(div, true); + + CPLX_VECTOR_OPERATORS_TRAITS(rect, plus, true); + CPLX_VECTOR_OPERATORS_TRAITS(rect, minus, true); + + template<cplx_representation R1, class T1, + cplx_representation R2, class T2> + struct operator_traits<operator_cmp, cplx<R1, T1>, cplx<R2, T2> > + { + enum { commutative = true }; + typedef cplx<R1, ntg_return_type(cmp, T1, T2)> ret; + typedef cplx<R1, T1> impl; + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_VECT_CPLX_HH Index: ntg/vect/cplx_representation.hh --- ntg/vect/cplx_representation.hh (revision 0) +++ ntg/vect/cplx_representation.hh (revision 0) @@ -0,0 +1,43 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_VECT_CPLX_REPRESENTATION_HH +# define NTG_VECT_CPLX_REPRESENTATION_HH + +namespace ntg +{ + + // Different representations of cplx : + typedef enum + { + rect, + polar + } cplx_representation; + +} // end of ntg. + +#endif // !NTG_VECT_CPLX_REPRESENTATION_HH Index: ntg/vect/vect_value.hh --- ntg/vect/vect_value.hh (revision 0) +++ ntg/vect/vect_value.hh (revision 0) @@ -0,0 +1,68 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_VECT_VECT_VALUE_HH +# define NTG_VECT_VECT_VALUE_HH + +# include <ntg/core/value.hh> + +namespace ntg +{ + + /*-----------. + | vect_value | + `-----------*/ + + template <class E> + class vect_value : public value<E> + { + typedef typename internal::typetraits<E>::comp_type comp_type; + enum { nb_comp = internal::typetraits<E>::nb_comp }; + + public: + // accessor + comp_type& operator[](unsigned i) { return this->val_[i]; } + comp_type operator[](unsigned i) const { return this->val_[i]; } + + 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: ntg/vect/vec.hh --- ntg/vect/vec.hh (revision 0) +++ ntg/vect/vec.hh (revision 0) @@ -0,0 +1,443 @@ +// Copyright (C) 2001, 2002, 2003, 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 NTG_VECT_VEC_HH +# define NTG_VECT_VEC_HH + +# include <ntg/basics.hh> +# include <ntg/core/internal/macros.hh> +# include <ntg/vect/vect_value.hh> + +# include <mlc/array/all.hh> + +/*--------------------. +| assignements macros | +`--------------------*/ + +# define ASSIGN_VECTOR_VECTOR_OPERATOR(Name, Op) \ +template <class T1, class T2> inline \ +static T1& \ +Name(T1& lhs, const T2& rhs) \ +{ \ + ntg_is_a(T1, ntg::vectorial)::ensure(); \ + ntg_is_a(T2, ntg::vectorial)::ensure(); \ + precondition(lhs.size() == rhs.size()); \ + unsigned s = lhs.size(); \ + for (unsigned i = 0; i < s; ++i) \ + lhs[i] Op rhs[i]; \ + return lhs; \ +} + +# define ASSIGN_VECTOR_SCALAR_OPERATOR(Name, Op) \ +template <class T1, class T2> inline \ +static T1& \ +Name(T1& lhs, const T2& rhs) \ +{ \ + ntg_is_a(T1, ntg::vectorial)::ensure(); \ + ntg_is_a(T2, ntg::real)::ensure(); \ + unsigned s = lhs.size(); \ + for (unsigned i = 0; i < s; ++i) \ + lhs[i] Op rhs; \ + return lhs; \ +} + +# define ARITH_VECTOR_VECTOR_OPERATOR(Name, Op) \ +template <class T1, class T2> \ +inline static \ +ntg_return_type(Name,T1, T2) \ +Name(const T1& lhs, const T2& rhs) \ +{ \ + ntg_is_a(T1, ntg::vectorial)::ensure(); \ + ntg_is_a(T2, ntg::vectorial)::ensure(); \ + typedef ntg_return_type(Name,T1, T2) return_type; \ + return_type result(lhs); \ + result Op rhs; \ + return result; \ +} + +namespace ntg { + + namespace internal { + + /*----------------. + | typetraits<vec> | + `----------------*/ + + template <unsigned N, class T, class Self> + struct typetraits<vec<N, T, Self> > : public typetraits<vect_value<vec<N, T, Self> > > + { + enum { nb_comp = N }; + + typedef vec<N, T, Self> self; + typedef vectorial abstract_type; + typedef self ntg_type; + typedef optraits<self> optraits_type; + + ntg_build_value_type(vect_value<E>); + + // FIXME: document comp_type + typedef T comp_type; + typedef self base_type; + typedef T storage_type[N]; + typedef typename typetraits<T>::cumul_type cumul_type[N]; + + static const self &sup() + { + static self tmp = mkSup(); + + return tmp; + }; + + protected: + static self mkSup() + { + self tmp; + + for (unsigned i = 0; i < N; ++i) + tmp[i] = ntg_sup_val(T); + return tmp; + }; + }; + + } // end of internal. + + /*----------. + | vec<N, T> | + `----------*/ + + template <unsigned N, class T, class E> + class vec : + public vect_value<typename ntg::exact_vt<vec<N, T, ntg::final>, E>::ret> + { + public : + + vec() + { + _fill (ntg_zero_val(T)); + } + + /* A vector can be built from a 1xM array. */ + template<int ncols, class T2> + vec(const mlc::array2d< mlc::array2d_info<1, ncols>, T2>& arr) + { + mlc::is_true< ncols == N >::ensure(); + for (unsigned i = 0; i < N; ++i) + this->val_[i] = arr[i]; + } + + template<class U, class E2> + vec(const vec<N, U, E2>& v) + { + for (unsigned i = 0; i < N; ++i) + this->val_[i] = v[i]; + } + + template<class U, class E2> + vec<N, T>& operator=(const vec<N, U, E2>& v) + { + for (unsigned i = 0; i < N; ++i) + this->val_[i] = v[i]; + return *this; + } + + static const vec<N,T> zero() { return vec(); } + // There is no unit() for vec<>. + + ~vec() {} + + protected: + vec& _fill(T t) + { + for (unsigned i = 0; i < N; ++i) + this->val_[i] = t; + return *this; + } + }; + + template<unsigned N,class T> inline + std::ostream& + operator<<(std::ostream& ostr, const vec<N,T>& rhs) + { + // dev note: we use an ostringstream to make only one output + // on the ostream. This allows calling procedures to consider + // data type printing as atomic, thus ostr.width(...) can + // work. + std::ostringstream str; + str << "["; + for (unsigned i = 0; i < N; ++i) + str << rhs[i] << ((i < N-1) ? "," : "]"); + ostr << str.str(); + return ostr; + } + + namespace internal + { + + /*--------------. + | optraits<vec> | + `--------------*/ + + template <unsigned N, class T, class 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_; + + public: + static self zero () + { + // A vectorial type MUST return a zero initialized value. + return self(); + } + + static unsigned max_print_width () + { + return (N * ntg_max_print_width(T)) + (N - 1) + 2; + } + + static std::string + name() { + std::ostringstream out; + out << "vec<" << N << ", " << ntg_name(T) << ">"<< std::ends; + return out.str(); + } + + // No unit() for vector. + // static storage_type_ unit (); + + ASSIGN_VECTOR_VECTOR_OPERATOR(plus_equal, +=) + ASSIGN_VECTOR_VECTOR_OPERATOR(minus_equal, -=) + ASSIGN_VECTOR_SCALAR_OPERATOR(times_equal, *=) + ASSIGN_VECTOR_SCALAR_OPERATOR(div_equal, /=) + ASSIGN_VECTOR_SCALAR_OPERATOR(mod_equal, %=) + + ARITH_VECTOR_VECTOR_OPERATOR(plus, +=) + ARITH_VECTOR_VECTOR_OPERATOR(minus, -=) + + // division + + template <class T1, class T2> + inline static + ntg_return_type(div, T1, T2) + div(const T1& lhs, const T2& rhs) + { + ntg_is_a(T1, ntg::vectorial)::ensure(); + ntg_is_a(T2, ntg::real)::ensure(); + typedef ntg_return_type(div, T1, T2) return_type; + return_type result(lhs); + result /= rhs; + return result; + } + + // modulo + + template <class T1, class T2> + inline static + ntg_return_type(mod, T1, T2) + mod(const T1& lhs, const T2& rhs) + { + ntg_is_a(T1, ntg::vectorial)::ensure(); + ntg_is_a(T2, ntg::real)::ensure(); + typedef ntg_return_type(mod, T1, T2) return_type; + return_type result(lhs); + result %= rhs; + return result; + } + + // multiplication + + // dot-product + template <unsigned M, class T1, class T2> + inline static typename + internal::deduce_from_traits<internal::operator_times, + vec<M, T1>, + vec<M, T2> >::ret + times(const vec<M, T1>& lhs, const vec<M, T2>& rhs) + { + typedef vec<M, T1> vec1; + typedef vec<M, T2> vec2; + ntg_is_a(vec1, ntg::vectorial)::ensure(); + ntg_is_a(vec2, ntg::vectorial)::ensure(); + typedef typename + internal::deduce_from_traits<internal::operator_times, + vec<M, T1>, vec<M, T2> >::ret return_type; + precondition(lhs.size() == rhs.size()); + + return_type result = optraits<return_type>::zero(); + unsigned s = lhs.size(); + for (unsigned i = 0; i < s; ++i) + result += lhs[i] * rhs[i]; + + return result; + } + + // vector * scalar + template <class T1, class T2> + inline static + ntg_return_type(times, T1, T2) + times(const vect_value<T1>& lhs, const T2& rhs) + { + ntg_is_a(T1, ntg::vectorial)::ensure(); + ntg_is_a(T2, ntg::real)::ensure(); + typedef ntg_return_type(times, T1, T2) return_type; + return_type result(lhs.exact()); + result *= rhs; + return result; + } + + // scalar * vector + template <class T1, class T2> + inline static + ntg_return_type(times, T1, T2) + times(const T1& lhs, const vect_value<T2>& rhs) + { + return times(rhs, lhs); + } + + + template <class T1, class T2> + inline static bool + cmp_eq (const T1& lhs, const T2& rhs) + { + ntg_is_a(T1, ntg::vectorial)::ensure(); + ntg_is_a(T2, ntg::vectorial)::ensure(); + ntg_assert(lhs.size() == rhs.size()); + + typedef ntg_return_type(cmp, T1, T2) tmp_type; + + unsigned s = lhs.size(); + for (unsigned i = 0; i < s; ++i) + if (lhs[i] != rhs[i]) + return false; + return true; + } + }; + + /*----------------. + | operator traits | + `----------------*/ + + // + // plus + // + + // vec + vec + + template<unsigned N, class T1, class T2, class S1, class S2> + struct operator_traits<operator_plus, vec<N, T1, S1>, vec<N, T2, S2> > + { + enum { commutative = true }; + typedef vec<N, ntg_return_type(plus, T1, T2)> ret; + typedef vec<N, T1> impl; + }; + + // + // minus + // + + // vec - vec + + template<unsigned N, class T1, class T2> + struct operator_traits<operator_minus, vec<N, T1>, vec<N, T2> > + { + enum { commutative = true }; + typedef vec<N, ntg_return_type(minus, T1, T2)> ret; + typedef vec<N, T1> impl; + }; + + // + // times + // + + // vec * s; s * vec + + template<unsigned N, class T1, class T2> + struct operator_traits<operator_times, vec<N, T1>, T2> + { + enum { commutative = true }; + typedef vec<N, ntg_return_type(times, T1, T2)> ret; + typedef vec<N, T1> impl; + }; + + // vec * vec + + template<unsigned N, class T1, class T2> + struct operator_traits<operator_times, vec<N, T1>, vec<N, T2> > + { + enum { commutative = true }; + typedef ntg_return_type(times,T1,T2) t; + typedef typename typetraits<t>::cumul_type ret; + typedef vec<N, T1> impl; + }; + + // + // div + // + + // vec / s + + template<unsigned N, class T1, class T2> + struct operator_traits<operator_div, vec<N, T1>, T2> + { + enum { commutative = false }; + typedef vec<N, ntg_return_type(div, T1, T2)> ret; + typedef vec<N, T1> impl; + }; + + // + // mod + // + + // vec % s + + template<unsigned N, class T1, class T2> + struct operator_traits<operator_mod, vec<N, T1>, T2> + { + enum { commutative = false }; + typedef vec<N, ntg_return_type(mod, T1, T2)> ret; + typedef vec<N, T1> impl; + }; + + // + // Comparison operator + // + + // vec compared with vec + + template<unsigned N, class T1, class T2, class S1, class S2> + struct operator_traits<operator_cmp, vec<N, T1, S1>, vec<N, T2, S2> > + { + enum { commutative = true }; + typedef vec<N, ntg_return_type(cmp, T1, T2)> ret; + typedef vec<N, T1> impl; + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_VECT_VEC_HH Index: ntg/basics.hh --- ntg/basics.hh (revision 0) +++ ntg/basics.hh (revision 0) @@ -0,0 +1,61 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_BASICS_HH +# define NTG_BASICS_HH + +/* + Basic header that regroup basic common headers every file + will certainely need. +*/ + +# include <ntg/config/system.hh> + +# include <ntg/core/predecls.hh> + +# include <ntg/core/abstract_hierarchy.hh> +# include <ntg/real/behavior.hh> +# include <ntg/core/contract.hh> +# include <ntg/core/interval.hh> +# include <ntg/real/builtin_properties.hh> +# include <ntg/core/type.hh> +# include <ntg/core/value.hh> + +/* + These headers are included as builtins may be used anywhere, without + having previously included the corresponding integre headers. +*/ +# include <ntg/enum/builtin_bool.hh> +# include <ntg/real/builtin_int.hh> +# include <ntg/real/builtin_float.hh> + +# include <ntg/core/internal/global_ops.hh> +# include <ntg/core/macros.hh> + +# include <ntg/utils/cast.hh> + +#endif // !NTG_BASICS_HH Index: ntg/makefile.src --- ntg/makefile.src (revision 59) +++ ntg/makefile.src (working copy) @@ -4,14 +4,60 @@ ## NTG_DEP = \ - color/rgb_8.hh \ + all.hh \ + basics.hh \ + bin.hh \ + color.hh \ color/color.hh \ + color/hsi.hh \ + color/hsl.hh \ + color/hsv.hh \ + color/nrgb.hh \ + color/rgb.hh \ + color/xyz.hh \ + color/yiq.hh \ + color/yuv.hh \ + config/math.hh \ config/system.hh \ - config/math.hh \ - core/cats.hh \ + core/abstract_hierarchy.hh \ + real/behavior.hh \ + core/contract.hh \ + core/internal/global_ops.hh \ + core/internal/global_ops_defs.hh \ + core/internal/global_ops_traits.hh \ + core/internal/macros.hh \ + core/internal/traits.hh \ + core/interval.hh \ core/macros.hh \ - core/props.hh \ + core/pred_succ.hh \ + core/predecls.hh \ + core/type.hh \ + core/type_traits.hh \ + core/value.hh \ + cplx.hh \ + cycle.hh \ enum/bin.hh \ - enum/enum.hh \ - real/int_u8.hh \ - real/integer.hh + enum/builtin_bool.hh \ + enum/enum_value.hh \ + float.hh \ + int.hh \ + range.hh \ + real/builtin_int.hh \ + real/builtin_float.hh \ + real/builtin_properties.hh \ + real/cycle.hh \ + real/int_s.hh \ + real/int_u.hh \ + real/optraits_builtin_int.hh \ + real/optraits_real.hh \ + real/optraits_real_defs.hh \ + real/range.hh \ + real/real_value.hh \ + real/typetraits_builtin_int.hh \ + utils/cast.hh \ + utils/debug.hh \ + vec.hh \ + vect/cplx.hh \ + vect/cplx_representation.hh \ + vect/vec.hh \ + vect/vect_value.hh Index: ntg/float.hh --- ntg/float.hh (revision 0) +++ ntg/float.hh (revision 0) @@ -0,0 +1,38 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_FLOAT_HH +# define NTG_FLOAT_HH + +/* + Proxy header for float types (float_s and float_d). +*/ + +# include <ntg/basics.hh> +# include <ntg/real/builtin_float.hh> + +#endif // !NTG_FLOAT_HH Index: ntg/enum/builtin_bool.hh --- ntg/enum/builtin_bool.hh (revision 0) +++ ntg/enum/builtin_bool.hh (revision 0) @@ -0,0 +1,87 @@ +// Copyright (C) 2002, 2003 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 NTG_ENUM_BUILTIN_BOOL_HH +# define NTG_ENUM_BUILTIN_BOOL_HH + +# include <ntg/core/abstract_hierarchy.hh> +# include <ntg/real/behavior.hh> +# include <ntg/core/predecls.hh> +# include <ntg/core/type_traits.hh> + +namespace ntg { + + namespace internal { + + /*-----------------. + | typetraits<bool> | + `-----------------*/ + + template <> + struct typetraits<bool> + { + typedef bool self; + typedef binary abstract_type; + typedef bin ntg_type; + typedef optraits<self> optraits_type; + typedef unsafe::get<self> behavior_type; + + typedef self base_type; + typedef self storage_type; + typedef self cumul_type; + typedef self largest_type; + typedef self signed_largest_type; + typedef self signed_cumul_type; + typedef self unsigned_largest_type; + typedef self unsigned_cumul_type; + typedef unsigned int integer_type; + }; + + /*---------------. + | optraits<bool> | + `---------------*/ + + template<> + struct optraits<bool> + { + static bool min() { return 0; } + static bool max() { return 1; } + static bool zero() { return 0; } + static bool unit() { return 1; } + static bool inf() { return min(); } + static bool sup() { return max(); } + + static unsigned max_print_width () { return 1U; } + + static std::string name() { return "bool"; } + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_ENUM_BUILTIN_BOOL_HH Index: ntg/enum/enum.hh --- ntg/enum/enum.hh (revision 59) +++ ntg/enum/enum.hh (working copy) @@ -1,97 +0,0 @@ -// 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 INTEGRE_ENUM_ENUM_HH -# define INTEGRE_ENUM_ENUM_HH - -# include <mlc/any.hh> - -# include <ntg/core/cats.hh> -# include <ntg/core/props.hh> - -namespace ntg { - - template <typename E> struct enum_value; - - template <typename E> - struct category_type< enum_value<E> > { typedef cat::enum_value ret; }; - - template <> - struct default_props < cat::enum_value > - { - enum { max_val = 0 }; - enum { depth = 1 }; - typedef mlc::no_type io_type; - - protected: - default_props() {} - }; - - template <typename E> - struct enum_value : public mlc::any__best_memory<E> - { - typedef E exact_type; - - bool operator==(int rhs) const - { - return this->exact().impl_eq(rhs); - } - - template <typename I> - bool operator==(const enum_value<I>& rhs) const - { - return this->exact().impl_eq(rhs.exact()); - } - - template <typename V> - bool operator!=(const V& rhs) const - { - return ! this->operator==(rhs); - } - - template <typename V> - exact_type& operator=(const V& rhs) - { - return this->exact().impl_assign(rhs); - } - - template <typename V> - exact_type& operator+(const V& rhs) const - { - return this->exact().impl_add(rhs); - } - - protected: - enum_value() {} - }; - -} // end of namespace ntg - - - - -#endif // ! INTEGRE_ENUM_ENUM_HH Index: ntg/enum/bin.hh --- ntg/enum/bin.hh (revision 59) +++ ntg/enum/bin.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004 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 @@ -25,98 +25,243 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef INTEGRE_ENUM_BIN_HH -# define INTEGRE_ENUM_BIN_HH +#ifndef NTG_ENUM_BIN_HH +# define NTG_ENUM_BIN_HH -# include <mlc/traits.hh> +/* + Binary type. Possible values are 0 and 1 (not true and false). +*/ -# include <ntg/core/props.hh> -# include <ntg/core/cats.hh> -# include <ntg/enum/enum.hh> +# include <ntg/basics.hh> +# include <ntg/enum/enum_value.hh> +# include <ntg/core/internal/global_ops.hh> +# include <mlc/contract.hh> + +# include <string> + namespace ntg { - struct bin; + namespace internal { - template <> - struct category_type< bin > { typedef cat::enum_value ret; }; + /*----------------. + | typetraits<bin> | + `----------------*/ + template <> + struct typetraits<bin> : typetraits<enum_value<bin> > + { + typedef binary abstract_type; + typedef bin self; + typedef self ntg_type; - template <> - struct props<cat::enum_value, bin> : public default_props<cat::enum_value> - { - enum { max_val = 1 }; - typedef unsigned char io_type; - }; + ntg_build_value_type(enum_value<E>); - struct bin : public enum_value<bin> + typedef optraits<self> optraits_type; + + typedef self base_type; + typedef bool storage_type; + typedef bin signed_type; + typedef bin unsigned_type; + typedef bin cumul_type; + typedef bin largest_type; + typedef bin signed_largest_type; + typedef bin signed_cumul_type; + typedef bin unsigned_largest_type; + typedef bin unsigned_cumul_type; + typedef unsigned int integer_type; + + // Particular properties + enum { size = 1 }; + }; + + } // end of internal. + + /*----. + | bin | + `----*/ + + class bin : public enum_value<bin> { - bin() : - value_(0) - { - } + public: + bin () + { this->val_ = 0; } - bin(unsigned char value) : - value_(value) - { - } + // FIXME: create a template constructor and check into it if T + // is a real or whatever ? - bin(const bin& rhs) : - value_(rhs) + bin (unsigned char val) { + ntg_assert(val < 2); + this->val_ = val; } - template <typename V> - bin& impl_assign(const V& rhs) + bin& + operator=(unsigned char val) { - this->value_ = (int)rhs % 2; + ntg_assert(val < 2); + this->val_ = val; return *this; } - operator unsigned char() const + template <class T> + bin (const real_value<T>& val) { - return value_; + ntg_assert(val < 2); + this->val_ = val.val(); } - - bool impl_eq(const unsigned char& rhs) const + template <class T> + bin& + operator=(const real_value<T>& val) { - return this->value_ == rhs; + ntg_assert(val < 2); + this->val_ = val.val(); + return *this; } - template <typename V> - bool impl_eq(const V& rhs) const - { - return this->value_ == (unsigned char)rhs; - } + operator unsigned char() const { return this->val_; } + }; + inline std::ostream& + operator<<(std::ostream& stream, const bin& rhs) + { + stream << (unsigned int) rhs.val(); + return stream; + } - template <typename V> - bin impl_add(const V& rhs) const + namespace internal { + + /*--------------. + | optraits<bin> | + `--------------*/ + + template <> + struct optraits<bin> : public optraits<enum_value<bin> > { - bin tmp((this->value_ + rhs) % 2); - return tmp; - } + private: + typedef typetraits<bin>::storage_type storage_type_; - private: + public: + static storage_type_ zero() { return 0; } + static storage_type_ unit() { return 1; } + static storage_type_ min() { return 0; } + static storage_type_ max() { return 1; } + static storage_type_ inf() { return min(); } + static storage_type_ sup() { return max(); } + static unsigned max_print_width () { return 1U; } - unsigned char value_; - }; + // logical assignement operators + static bin& + logical_or_equal(bin& lhs, const bin& rhs) + { + lhs = lhs.val() | rhs.val(); + return lhs; + } -} // end of namespace ntg + static bin& + logical_and_equal(bin& lhs, const bin& rhs) + { + lhs = lhs.val() & rhs.val(); + return lhs; + } + static bin& + logical_xor_equal(bin& lhs, const bin& rhs) + { + lhs = lhs.val() ^ rhs.val(); + return lhs; + } + // logical binary ops -namespace mlc { + static bin + logical_or(const bin& lhs, const bin& rhs) + { + bin tmp(lhs); + tmp |= rhs; + return tmp; + } - template <> - struct traits < ntg::bin > - { - typedef unsigned char encoding_type; - }; + static bin + logical_and(const bin& lhs, const bin& rhs) + { + bin tmp(lhs); + tmp &= rhs; + return tmp; + } -} // end of namespace mlc + static bin + logical_xor(const bin& lhs, const bin& rhs) + { + bin tmp(lhs); + tmp ^= rhs; + return tmp; + } + // comparisons + static bool + cmp_lt(const bin& lhs, const bin& rhs) + { + return lhs.val() < rhs.val(); + } -#endif // ! INTEGRE_ENUM_BIN_HH + static bool + cmp_eq(const bin& lhs, const bin& rhs) + { + return lhs.val() == rhs.val(); + } + + static std::string name() { return "bin"; } + }; + + /*-----------------. + | operators traits | + `-----------------*/ + + // Logical operators + + template <class T> + struct operator_traits<operator_logical, bin, T> + { + enum { commutative = true }; + typedef bin ret; + typedef bin impl; + }; + + // Comparison operators + + template <> + struct operator_traits<operator_cmp, bin, bin> + { + enum { commutative = true }; + typedef bin ret; + typedef bin impl; + }; + + // Max + + template <> + struct operator_traits<operator_max, bin, bin> + { + enum { commutative = true }; + typedef bin ret; + typedef bin impl; + }; + + // Min + + template <> + struct operator_traits<operator_min, bin, bin> + { + enum { commutative = true }; + typedef bin ret; + typedef bin impl; + }; + + } // end of internal. + +} // end of ntg. + +#endif // !NTG_ENUM_BIN_HH Index: ntg/enum/enum_value.hh --- ntg/enum/enum_value.hh (revision 0) +++ ntg/enum/enum_value.hh (revision 0) @@ -0,0 +1,59 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_ENUM_ENUM_VALUE_HH +# define NTG_ENUM_ENUM_VALUE_HH + +# include <ntg/core/value.hh> +# include <ntg/core/type_traits.hh> + +namespace ntg +{ + + /*-----------. + | enum_value | + `-----------*/ + + template <class E> + 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: ntg/cplx.hh --- ntg/cplx.hh (revision 0) +++ ntg/cplx.hh (revision 0) @@ -0,0 +1,37 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_CPLX_HH +# define NTG_CPLX_HH + +/* + Proxy header for cplx type. +*/ + +# include <ntg/vect/cplx.hh> + +#endif // !NTG_CPLX_HH Index: ntg/all.hh --- ntg/all.hh (revision 59) +++ ntg/all.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2003 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 @@ -28,9 +28,23 @@ #ifndef NTG_ALL_HH # define NTG_ALL_HH -# include <ntg/core/macros.hh> -# include <ntg/color/rgb_8.hh> -# include <ntg/real/int_u8.hh> -# include <ntg/enum/bin.hh> +/* + Include all Integre's features. +*/ -#endif // ! NTG_ALL_HH +# include <ntg/basics.hh> + +# include <ntg/bin.hh> + +# include <ntg/int.hh> +# include <ntg/cycle.hh> +# include <ntg/range.hh> + +# include <ntg/vec.hh> +# include <ntg/cplx.hh> + +# include <ntg/color.hh> + +# include <ntg/utils/cast.hh> + +#endif // !NTG_ALL_HH Index: ntg/bin.hh --- ntg/bin.hh (revision 0) +++ ntg/bin.hh (revision 0) @@ -0,0 +1,37 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_BIN_HH +# define NTG_BIN_HH + +/* + Proxy header for bin type. +*/ + +# include <ntg/enum/bin.hh> + +#endif // !NTG_BIN_HH Index: ntg/Makefile.am --- ntg/Makefile.am (revision 59) +++ ntg/Makefile.am (working copy) @@ -5,3 +5,61 @@ include $(srcdir)/makefile.src ntgdir = $(includedir)/ntg +nobase_ntg_HEADERS = \ + all.hh \ + basics.hh \ + bin.hh \ + color.hh \ + color/color.hh \ + color/hsi.hh \ + color/hsl.hh \ + color/hsv.hh \ + color/nrgb.hh \ + color/rgb.hh \ + color/xyz.hh \ + color/yiq.hh \ + color/yuv.hh \ + config/math.hh \ + config/system.hh \ + core/abstract_hierarchy.hh \ + real/behavior.hh \ + core/contract.hh \ + core/internal/global_ops.hh \ + core/internal/global_ops_defs.hh \ + core/internal/global_ops_traits.hh \ + core/internal/macros.hh \ + core/internal/traits.hh \ + core/interval.hh \ + core/macros.hh \ + core/pred_succ.hh \ + core/predecls.hh \ + core/type.hh \ + core/type_traits.hh \ + core/value.hh \ + cplx.hh \ + cycle.hh \ + enum/bin.hh \ + enum/builtin_bool.hh \ + enum/enum_value.hh \ + float.hh \ + int.hh \ + range.hh \ + real/builtin_int.hh \ + real/builtin_float.hh \ + real/builtin_properties.hh \ + real/cycle.hh \ + real/int_s.hh \ + real/int_u.hh \ + real/optraits_builtin_int.hh \ + real/optraits_real.hh \ + real/optraits_real_defs.hh \ + real/range.hh \ + real/real_value.hh \ + real/typetraits_builtin_int.hh \ + utils/cast.hh \ + utils/debug.hh \ + vec.hh \ + vect/cplx.hh \ + vect/cplx_representation.hh \ + vect/vec.hh \ + vect/vect_value.hh Index: ntg/vec.hh --- ntg/vec.hh (revision 0) +++ ntg/vec.hh (revision 0) @@ -0,0 +1,35 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_VEC_HH +# define NTG_VEC_HH + +// Proxy header for vec type. + +# include <ntg/vect/vec.hh> + +#endif // !NTG_VEC_HH Index: ntg/color.hh --- ntg/color.hh (revision 0) +++ ntg/color.hh (revision 0) @@ -0,0 +1,44 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_HH +# define NTG_COLOR_HH + +/* + Proxy header for color types. +*/ + +# include <ntg/color/rgb.hh> +# include <ntg/color/nrgb.hh> +# include <ntg/color/hsi.hh> +# include <ntg/color/hsl.hh> +# include <ntg/color/hsv.hh> +# include <ntg/color/xyz.hh> +# include <ntg/color/yiq.hh> +# include <ntg/color/yuv.hh> + +#endif // !NTG_COLOR_HH Index: ntg/color/rgb_8.hh --- ntg/color/rgb_8.hh (revision 59) +++ ntg/color/rgb_8.hh (working copy) @@ -1,153 +0,0 @@ -// 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 INTEGRE_COLOR_RGB_8_HH -# define INTEGRE_COLOR_RGB_8_HH - -# include <mlc/traits.hh> - -# include <ntg/core/props.hh> -# include <ntg/color/color.hh> - -namespace ntg { - - struct rgb_8; - - template <> - struct category_type< rgb_8 > { typedef cat::color ret; }; - - - template <> - struct props<cat::color, rgb_8> : default_props<cat::color> - { - enum { max_val = 255 }; - enum { depth = 3 }; - - typedef char io_type; - typedef unsigned char comp_type; - }; - - enum { - rgb_red = 0, - rgb_green = 1, - rgb_blue = 2 - }; - - - struct rgb_8: public color <rgb_8> - { - rgb_8() - { - this->value_[rgb_red] = 0; - this->value_[rgb_green] = 0; - this->value_[rgb_blue] = 0; - } - - rgb_8(const unsigned char init[3]) - { - for (unsigned i = 0; i < 3; i++) - value_[i] = init[i]; - } - - rgb_8(unsigned char red, - unsigned char green, - unsigned char blue) - { - this->value_[rgb_red] = red; - this->value_[rgb_green] = green; - this->value_[rgb_blue] = blue; - } - - rgb_8(const rgb_8& rhs) - { - this->value_[rgb_red] = rhs[rgb_red]; - this->value_[rgb_green] = rhs[rgb_green]; - this->value_[rgb_blue] = rhs[rgb_blue]; - } - - rgb_8& impl_assign(const rgb_8& rhs) - { - this->value_[rgb_red] = rhs[rgb_red]; - this->value_[rgb_green] = rhs[rgb_green]; - this->value_[rgb_blue] = rhs[rgb_blue]; - return *this; - } - - bool impl_eq(const rgb_8& rhs) const - { - return this->value_[rgb_red] == rhs[rgb_red] && - this->value_[rgb_green] == rhs[rgb_green] && - this->value_[rgb_blue] == rhs[rgb_blue]; - } - - unsigned char& impl_op_sqbr(unsigned int i) - { - assert(i < 3); - return value_[i]; - } - - const unsigned char impl_op_sqbr(unsigned int i) const - { - assert(i < 3); - return value_[i]; - } - - private: - - unsigned char value_[3]; - }; - - -} // end of namespace ntg - - -# include <ostream> - -std::ostream& operator<<(std::ostream& ostr, const ntg::rgb_8& to_print) -{ - ostr << "(" << unsigned(to_print[0]) - << "," << unsigned(to_print[1]) - << "," << unsigned(to_print[2]) - << ")"; - return ostr; -} - - - -namespace mlc { - - template <> - struct traits < ntg::rgb_8 > - { - typedef ntg::rgb_8 encoding_type; - }; - -} // end of namespace mlc - - - -#endif // ! NTG_COLOR_RGB_8_HH Index: ntg/color/yiq.hh --- ntg/color/yiq.hh (revision 0) +++ ntg/color/yiq.hh (revision 0) @@ -0,0 +1,64 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_YIQ_HH +# define NTG_COLOR_YIQ_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum yiq_comp + { + yiq_Y = 0, + yiq_I = 1, + yiq_Q = 2 + }; + + template<unsigned icomp> struct yiq_traits; + template<> struct yiq_traits<yiq_Y> : public interval<0,1> {}; + + template<> struct yiq_traits<yiq_I> + { + static float lower_bound() { return -.4192; } + static float upper_bound() { return .5346; } + }; + + template<> struct yiq_traits<yiq_Q> + { + static float lower_bound() { return -.6783; } + static float upper_bound() { return .6527; } + }; + + typedef color<3,8,yiq_traits> yiq_8; + typedef color<3,16,yiq_traits> yiq_16; + typedef color<3,32,yiq_traits> yiq_32; + +} // end of ntg. + +#endif // !NTG_COLOR_YIQ_HH Index: ntg/color/hsi.hh --- ntg/color/hsi.hh (revision 0) +++ ntg/color/hsi.hh (revision 0) @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_HSI_HH +# define NTG_COLOR_HSI_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum hsi_comp + { + hsi_H = 0, + hsi_S = 1, + hsi_I = 2 + }; + + template<unsigned icomp> struct hsi_traits; + template<> struct hsi_traits<hsi_H> : public interval<0,360> {}; + template<> struct hsi_traits<hsi_S> + { + static float lower_bound() { return 0.; } + static float upper_bound() { return 0.816497; } //2 / sqrt(6) + }; + + template<> struct hsi_traits<hsi_I> + { + static float lower_bound() { return 0.; } + static float upper_bound() { return 1.7320508; } //sqrt(3) + }; + + typedef color<3,8,hsi_traits> hsi_8; + typedef color<3,16,hsi_traits> hsi_16; + typedef color<3,32,hsi_traits> hsi_32; + +} // end of ntg. + +#endif // !NTG_COLOR_HSI_HH Index: ntg/color/yuv.hh --- ntg/color/yuv.hh (revision 0) +++ ntg/color/yuv.hh (revision 0) @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_YUV_HH +# define NTG_COLOR_YUV_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum yuv_comp + { + yuv_Y = 0, + yuv_U = 1, + yuv_V = 2 + }; + + template<unsigned icomp> struct yuv_traits; + template<> struct yuv_traits<yuv_Y> : public interval<0,1> {}; + template<> struct yuv_traits<yuv_U> + { + static float lower_bound() { return -0.517; } + static float upper_bound() { return 0.437; } + }; + + template<> struct yuv_traits<yuv_V> + { + static float lower_bound() { return -0.576; } + static float upper_bound() { return 0.654; } + }; + + typedef color<3,8,yuv_traits> yuv_8; + typedef color<3,16,yuv_traits> yuv_16; + typedef color<3,32,yuv_traits> yuv_32; + +} // end of ntg. + +#endif // !NTG_COLOR_YUV_HH Index: ntg/color/hsl.hh --- ntg/color/hsl.hh (revision 0) +++ ntg/color/hsl.hh (revision 0) @@ -0,0 +1,54 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_HSL_HH +# define NTG_COLOR_HSL_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum hsl_comp + { + hsl_H = 0, + hsl_S = 1, + hsl_L = 2 + }; + + template<unsigned icomp> struct hsl_traits; + template<> struct hsl_traits<hsl_H> : public interval<0,360> {}; + template<> struct hsl_traits<hsl_S> : public interval<0,1> {}; + template<> struct hsl_traits<hsl_L> : public interval<0,1> {}; + + typedef color<3,8,hsl_traits> hsl_8; + typedef color<3,16,hsl_traits> hsl_16; + typedef color<3,32,hsl_traits> hsl_32; + +} // end of ntg + +#endif // !NTG_COLOR_HSL_HH Index: ntg/color/nrgb.hh --- ntg/color/nrgb.hh (revision 0) +++ ntg/color/nrgb.hh (revision 0) @@ -0,0 +1,130 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_NRGB_HH +# define NTG_NRGB_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + /*! + NTSC RGB format. + */ + + enum nrgb_comp + { + nrgb_R = 0, + nrgb_G = 1, + nrgb_B = 2 + }; + + template<unsigned icomp> struct nrgb_traits; + template<> + struct nrgb_traits<nrgb_R> + { + static float lower_bound() { return 0;} + static float upper_bound() { return 1.0885004;} + }; + + + template<> + struct nrgb_traits<nrgb_G> + { + static float lower_bound() { return -0.3321984;} + static float upper_bound() { return 1.3189264;} + }; + + + template<> + struct nrgb_traits<nrgb_B> + { + static float lower_bound() { return -0.0688480;} + static float upper_bound() { return 0.904727;} + }; + + + typedef color<3,8,nrgb_traits> nrgb_8; + typedef color<3,16,nrgb_traits> nrgb_16; + typedef color<3,32,nrgb_traits> nrgb_32; + + // FIXME: not thread safe ! +# define DEFINE_COLOR(Type, Name, V1, V2, V3) \ + inline const Type& Name() { \ + static const Type tmp(V1, V2, V3); \ + return tmp; \ + } + + namespace nrgb_8_color + { + + DEFINE_COLOR(nrgb_8, white, 255, 255, 255) + DEFINE_COLOR(nrgb_8, gray, 128, 128, 128) + DEFINE_COLOR(nrgb_8, black, 0, 0, 0) + DEFINE_COLOR(nrgb_8, red, 255, 0, 0) + DEFINE_COLOR(nrgb_8, green, 0, 255, 0) + DEFINE_COLOR(nrgb_8, blue, 0, 0, 255) + DEFINE_COLOR(nrgb_8, yellow,255, 255, 0) + DEFINE_COLOR(nrgb_8, cyan, 0, 255, 255) + DEFINE_COLOR(nrgb_8, pink, 255, 0, 255) + + } // end of nrgb_8_color + + namespace nrgb_16_color + { + + DEFINE_COLOR(nrgb_16, white, 255, 255, 255) + DEFINE_COLOR(nrgb_16, gray, 128, 128, 128) + DEFINE_COLOR(nrgb_16, black, 0, 0, 0) + DEFINE_COLOR(nrgb_16, red, 255, 0, 0) + DEFINE_COLOR(nrgb_16, green, 0, 255, 0) + DEFINE_COLOR(nrgb_16, blue, 0, 0, 255) + DEFINE_COLOR(nrgb_16, yellow,255, 255, 0) + DEFINE_COLOR(nrgb_16, cyan, 0, 255, 255) + DEFINE_COLOR(nrgb_16, pink, 255, 0, 255) + + } // end of nrgb_16_color + + namespace nrgb_32_color + { + + DEFINE_COLOR(nrgb_32, white, 255, 255, 255) + DEFINE_COLOR(nrgb_32, gray, 128, 128, 128) + DEFINE_COLOR(nrgb_32, black, 0, 0, 0) + DEFINE_COLOR(nrgb_32, red, 255, 0, 0) + DEFINE_COLOR(nrgb_32, green, 0, 255, 0) + DEFINE_COLOR(nrgb_32, blue, 0, 0, 255) + DEFINE_COLOR(nrgb_32, yellow,255, 255, 0) + DEFINE_COLOR(nrgb_32, cyan, 0, 255, 255) + DEFINE_COLOR(nrgb_32, pink, 255, 0, 255) + + } // end of nrgb_32_color. + +} // end of ntg. + +#endif // !NTG_COLOR_NRGB_HH Index: ntg/color/rgb.hh --- ntg/color/rgb.hh (revision 0) +++ ntg/color/rgb.hh (revision 0) @@ -0,0 +1,58 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_RGB_HH +# define NTG_COLOR_RGB_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + /*! + CIE RGB format. + */ + + enum rgb_comp + { + rgb_R = 0, + rgb_G = 1, + rgb_B = 2 + }; + + template<unsigned icomp> struct rgb_traits; + template<> struct rgb_traits<rgb_R> : public interval<0,1> {}; + template<> struct rgb_traits<rgb_G> : public interval<0,1> {}; + template<> struct rgb_traits<rgb_B> : public interval<0,1> {}; + + typedef color<3,8,rgb_traits> rgb_8; + typedef color<3,16,rgb_traits> rgb_16; + typedef color<3,32,rgb_traits> rgb_32; + +} // end of ntg. + +#endif // !NTG_COLOR_RGB_HH Index: ntg/color/xyz.hh --- ntg/color/xyz.hh (revision 0) +++ ntg/color/xyz.hh (revision 0) @@ -0,0 +1,54 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_XYZ_HH +# define NTG_COLOR_XYZ_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum xyz_comp + { + xyz_X = 0, + xyz_Y = 1, + xyz_Z = 2 + }; + + template<unsigned icomp> struct xyz_traits; + template<> struct xyz_traits<xyz_X> : public interval<0,1> {}; + template<> struct xyz_traits<xyz_Y> : public interval<0,1> {}; + template<> struct xyz_traits<xyz_Z> : public interval<0,1> {}; + + typedef color<3,8,xyz_traits> xyz_8; + typedef color<3,16,xyz_traits> xyz_16; + typedef color<3,32,xyz_traits> xyz_32; + +} // end of ntg. + +#endif // !NTG_COLOR_XYZ_HH Index: ntg/color/color.hh --- ntg/color/color.hh (revision 59) +++ ntg/color/color.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2005 EPITA Research and Development Laboratory +// 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 @@ -25,75 +25,298 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef INTEGRE_COLOR_COLOR_HH -# define INTEGRE_COLOR_COLOR_HH +#ifndef NTG_COLOR_COLOR_HH +# define NTG_COLOR_COLOR_HH -# include <mlc/any.hh> -# include <mlc/types.hh> +/* + Header for generic color type, from which real color types are defined. +*/ -# include <ntg/core/cats.hh> -# include <ntg/core/props.hh> +# include <ntg/basics.hh> +# include <ntg/int.hh> +# include <ntg/vect/vec.hh> +# include <ntg/core/pred_succ.hh> +# include <mlc/cmp.hh> + +# include <iostream> +# include <sstream> +# include <string> + namespace ntg { - template <typename E> - struct color; + namespace internal { - template <typename E> - struct category_type< color<E> > { typedef cat::color ret; }; + /*------------------. + | typetraits<color> | + `------------------*/ + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct typetraits<color<ncomps, qbits, color_system> > + { + enum { nb_comp = ncomps }; - template <> - struct default_props < cat::color > - { - enum { max_val = 0 }; - enum { depth = 0 }; - typedef mlc::undefined_type comp_type; - typedef mlc::undefined_type io_type; + typedef color<ncomps, qbits, color_system> self; + typedef self ntg_type; + typedef vectorial abstract_type; + typedef int_u<qbits> comp_type; + typedef self base_type; + typedef vec<ncomps, int_u<qbits> > storage_type; + }; + /*-------------------------. + | Helper structs for float | + `-------------------------*/ - protected: - default_props() {} - }; + /*! + Helper struct to convert vec<N,T> to vec<N,float>, + taking color_system into account. + */ + template <unsigned n, + unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _to_float + { + typedef int_u<qbits> T; + typedef vec<ncomps, T> in_type; + typedef vec<ncomps, float> out_type; - template <typename E> - struct color : public mlc::any__best_memory<E> - { - typedef E exact_type; - typedef typename props<cat::color, E>::comp_type comp_type; + static void + doit (const in_type& in, out_type& out) + { + float in_range = float(ntg_max_val(T)) - float(ntg_min_val(T)); + float out_range = float(color_system<n>::upper_bound()) + - float(color_system<n>::lower_bound()); + out[n] = ((float(in[n]) - float(ntg_min_val(T))) + * out_range / in_range + + float(color_system<n>::lower_bound())); - E& operator=(const exact_type& rhs) + // process next componant recursively: + _to_float<n + 1, ncomps, qbits, color_system>::doit(in, out); + } + }; + + // Stop recursion when n == ncomps. + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _to_float<ncomps, ncomps, qbits, color_system> { - return this->exact.impl_assign(rhs); - } + typedef vec<ncomps, int_u<qbits> > in_type; + typedef vec<ncomps, float> out_type; - template <typename I> - bool operator==(const color<I>& rhs) const + static void + doit (const in_type&, out_type&) + {} + }; + + /*! + Helper struct to convert vec<N,float> to vec<N,T>, + taking color_system into account. + */ + template <unsigned n, + unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _from_float { - return this->exact().impl_eq(rhs.exact()); - } + typedef int_u<qbits> T; + typedef vec<ncomps, float> in_type; + typedef vec<ncomps, T> out_type; - template <typename V> - bool operator!=(const V& rhs) const + static void + doit (const in_type& in, out_type& out) + { + float out_range = float(optraits<T>::max()) + - float(optraits<T>::min()); + float in_range = float(color_system<n>::upper_bound()) + - float(color_system<n>::lower_bound()); + + out[n] = cast::rbound<int_u<qbits> > + ((in[n] - float(color_system<n>::lower_bound())) + * out_range / in_range + + float(color_system<n>::lower_bound())); + + // process next componant recursively: + _from_float<n + 1, ncomps, qbits, color_system>::doit(in, out); + } + }; + + // stop recursion when n == ncomps. + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _from_float<ncomps, ncomps, qbits, color_system> { - return ! this->operator==(rhs); + typedef vec<ncomps, float> in_type; + typedef vec<ncomps, int_u<qbits> > out_type; + + static void + doit (const in_type&, out_type&) + {} + }; + + } // end of internal. + + /*-----------------------------------. + | color<ncomps, qbits, color_system> | + `-----------------------------------*/ + + //! Generic type for color. + /*! + Specific color types (such as rgb, xyz, etc.) are defined by + specifying ncomps, qbits and a color_system trait. + + ncomps: number of components. + qbits: number of bits of each unsigned integer component. + color_system: traits defining the intervals of each component. + + Colors are implemented and seen as a vector of components. + */ + + + template <typename E> + struct color_value: public vect_value<E> + {}; + + namespace internal { + + template <class E> + struct typetraits<color_value<E> > : public typetraits<vect_value<E> > + {}; + + } + + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct color : public color_value<color<ncomps, qbits, color_system> > + { + typedef int_u<qbits> comp_type; + typedef vec<ncomps, comp_type> vec_type; + typedef vec<ncomps, float> float_vec_type; + + color() {}; + color(const vec_type& vec) { this->val_ = vec; }; + color(const float_vec_type& vec) + { + internal::_from_float<0,ncomps,qbits,color_system>::doit(vec,this->val_); } - comp_type& operator [](const unsigned int &i) + color(const comp_type& c1, const comp_type& c2, const comp_type& c3) { - return this->exact().impl_op_sqbr(i); + mlc::is_true<ncomps == 3>::ensure(); + this->val_[0] = c1; + this->val_[1] = c2; + this->val_[2] = c3; } - const comp_type operator [](const unsigned int &i) const + vec_type& as_vec() { return this->val_; } + const vec_type& as_vec() const { return this->val_; } + + float_vec_type + to_float() const { - return this->exact().impl_op_sqbr(i); + float_vec_type tmp; + internal::_to_float<0,ncomps,qbits,color_system>::doit(this->val_, tmp); + return tmp; } - protected: - color() {} + bool + operator==(const color& r) const + { return this->val_ == r.val_; } }; -} // end of namespace ntg + /*! + Helper function to complete color_system (by inheritance). + */ + template<int lval, int uval> + struct interval + { + static int lower_bound() { return lval; } + static int upper_bound() { return uval; } + }; + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + inline std::ostream& + operator<<(std::ostream& o, + const color<ncomps, qbits, color_system>& r) + { + o << r.as_vec(); + return o; + } -#endif // ! INTEGRE_COLOR_COLOR_HH + namespace internal + { + + /*----------------. + | optraits<color> | + `----------------*/ + + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct optraits<color<ncomps, qbits, color_system> > + { + private: + typedef color<ncomps, qbits, color_system> self; + typedef typename typetraits<self>::storage_type storage_type; + + public: + static unsigned max_print_width () + { + return ntg_max_print_width(storage_type); + } + + static std::string + name() + { + std::ostringstream out; + // FIXME: Output color_system somehow. + out << "color<" << ncomps << "," << qbits << ",...>" << std::ends; + return out.str(); + } + }; + + + template <typename T> struct default_less; + + /*! The specialized version of default_less for colors. + ** + ** \warning This class is only provided to build classes + ** that need a less class, it does not correspond to + ** the reality. \n + ** Example of a std::set of RGB colors: + ** \verbatim + ** std::set<ntg:rgb_8, + ** ntg::internal::default_less<ntg::rgb8> > s; + ** s.insert(ntg::rgb_8(10, 16, 64)); + ** \endverbatim + */ + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct default_less< ntg::color<ncomps, qbits, color_system> > + { + typedef ntg::color<ncomps, qbits, color_system> arg_type; + bool operator()(const arg_type& l, + const arg_type& r) const + { + for (unsigned i = 0; i < ntg_nb_comp(arg_type); ++i) + if (l[i] < r[i]) + return true; + else if (l[i] > r[i]) + return false; + return false; + } + }; + } // end of internal. + +} // end of ntg. + +#endif // !NTG_COLOR_COLOR_HH Index: ntg/color/hsv.hh --- ntg/color/hsv.hh (revision 0) +++ ntg/color/hsv.hh (revision 0) @@ -0,0 +1,55 @@ +// Copyright (C) 2001, 2002, 2003 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 NTG_COLOR_HSV_HH +# define NTG_COLOR_HSV_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum hsv_comp + { + hsv_H = 0, + hsv_S = 1, + hsv_V = 2 + }; + + template<unsigned icomp> struct hsv_traits; + template<> struct hsv_traits<hsv_H> : public interval<0,360> {}; + template<> struct hsv_traits<hsv_S> : public interval<0,1> {}; + template<> struct hsv_traits<hsv_V> : public interval<0,1> {}; + + + typedef color<3,8,hsv_traits> hsv_8; + typedef color<3,16,hsv_traits> hsv_16; + typedef color<3,32,hsv_traits> hsv_32; + +} // end of ntg. + +#endif // !NTG_COLOR_HSV_HH
participants (1)
-
Damien Thivolle