1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
|
// Copyright (c) 2005-2007
// Utrecht University (The Netherlands),
// ETH Zurich (Switzerland),
// INRIA Sophia-Antipolis (France),
// Max-Planck-Institute Saarbruecken (Germany),
// and Tel-Aviv University (Israel). All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Number_types/include/CGAL/Number_type_checker.h $
// $Id: include/CGAL/Number_type_checker.h 08b27d3db14 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Sylvain Pion, Michael Hemmer
#ifndef CGAL_NUMBER_TYPE_CHECKER_H
#define CGAL_NUMBER_TYPE_CHECKER_H
#include <CGAL/number_type_basic.h>
#include <sstream>
// A number type class, parameterized by 2 number types NT1 and NT2.
// It runs all operations on parallel over NT1 and NT2.
// It is also parameterized by a comparator which compares the values
// of NT1 and NT2 after all arithmetic operations.
// #define CGAL_NT_CHECK_DEBUG(s) std::cerr << s << std::endl
#define CGAL_NT_CHECK_DEBUG(s)
namespace CGAL {
namespace internal {
// std::equal_to<T> sticks things to one type, so I define my own.
struct Equal_to
{
template < typename NT1, typename NT2 >
bool operator()(const NT1& a, const NT2& b) const
{ return a == b; }
};
} // namespace internal
template < typename NT1, typename NT2, typename Cmp = internal::Equal_to >
class Number_type_checker
{
NT1 _n1;
NT2 _n2;
Cmp cmp;
public:
typedef Number_type_checker<NT1, NT2, Cmp> Self;
Number_type_checker() {}
Number_type_checker(int i)
: _n1(i), _n2(i) { CGAL_assertion(is_valid()); }
Number_type_checker(double d)
: _n1(d), _n2(d) { CGAL_assertion(is_valid()); }
Number_type_checker(const NT1 &n1, const NT2 &n2)
: _n1(n1), _n2(n2) { CGAL_assertion(is_valid()); }
// The following need to be dependent on NT1 != {NT2,int,double} ...
//Number_type_checker(const NT1 &n1) : _n1(n1), _n2(n1) {}
//Number_type_checker(const NT2 &n2) : _n1(n2), _n2(n2) {}
Self& operator+=(const Self &a)
{ n1() += a.n1(); n2() += a.n2(); CGAL_assertion(is_valid()); return *this; }
Self& operator-=(const Self &a)
{ n1() -= a.n1(); n2() -= a.n2(); CGAL_assertion(is_valid()); return *this; }
Self& operator*=(const Self &a)
{ n1() *= a.n1(); n2() *= a.n2(); CGAL_assertion(is_valid()); return *this; }
Self& operator/=(const Self &a)
{ n1() /= a.n1(); n2() /= a.n2(); CGAL_assertion(is_valid()); return *this; }
// Accessors and setters.
const NT1& n1() const { return _n1; }
const NT2& n2() const { return _n2; }
NT1& n1() { return _n1; }
NT2& n2() { return _n2; }
// Validity checking.
bool is_valid() const
{
CGAL_NT_CHECK_DEBUG("Checking...");
bool b = cmp(_n1, _n2);
if (!b)
{
CGAL_NT_CHECK_DEBUG("Different values :");
CGAL_NT_CHECK_DEBUG("n1 = " << _n1);
CGAL_NT_CHECK_DEBUG("n2 = " << _n2);
}
return b;
}
};
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator+(const Number_type_checker<NT1, NT2, Cmp> &a)
{
CGAL_NT_CHECK_DEBUG("operator+");
return Number_type_checker<NT1, NT2, Cmp>(+ a.n1(), + a.n2() );
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator+(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator+");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() + b.n1(), a.n2() + b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator+(int a, const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator+");
return Number_type_checker<NT1, NT2, Cmp>(a + b.n1(), a + b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator+(const Number_type_checker<NT1, NT2, Cmp> &a, int b)
{
CGAL_NT_CHECK_DEBUG("operator+");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() + b, a.n2() + b);
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator-(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator-");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() - b.n1(), a.n2() - b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator-(int a, const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator-");
return Number_type_checker<NT1, NT2, Cmp>(a - b.n1(), a - b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator-(const Number_type_checker<NT1, NT2, Cmp> &a, int b)
{
CGAL_NT_CHECK_DEBUG("operator-");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() - b, a.n2() - b);
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator-(const Number_type_checker<NT1, NT2, Cmp> &a)
{
CGAL_NT_CHECK_DEBUG("unary operator-");
return Number_type_checker<NT1, NT2, Cmp>(-a.n1(), -a.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator*(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator*");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() * b.n1(), a.n2() * b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator*(int a, const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator*");
return Number_type_checker<NT1, NT2, Cmp>(a * b.n1(), a * b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator*(const Number_type_checker<NT1, NT2, Cmp> &a, int b)
{
CGAL_NT_CHECK_DEBUG("operator*");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() * b, a.n2() * b);
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator/(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator/");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() / b.n1(), a.n2() / b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator/(int a, const Number_type_checker<NT1, NT2, Cmp> &b)
{
CGAL_NT_CHECK_DEBUG("operator/");
return Number_type_checker<NT1, NT2, Cmp>(a / b.n1(), a / b.n2());
}
template < typename NT1, typename NT2, typename Cmp >
Number_type_checker<NT1, NT2, Cmp>
operator/(const Number_type_checker<NT1, NT2, Cmp> &a, int b)
{
CGAL_NT_CHECK_DEBUG("operator/");
return Number_type_checker<NT1, NT2, Cmp>(a.n1() / b, a.n2() / b);
}
// arithmetic operators end
// compare operators begin
template < typename NT1, typename NT2, typename Cmp >
bool
operator==(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = a.n1() == b.n1();
CGAL_assertion(b1 == ( a.n2() == b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator!=(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = a.n1() != b.n1();
CGAL_assertion(b1 == ( a.n2() != b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator<(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = a.n1() < b.n1();
CGAL_assertion(b1 == ( a.n2() < b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator>(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = a.n1() > b.n1();
CGAL_assertion(b1 == ( a.n2() > b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator<=(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = a.n1() <= b.n1();
CGAL_assertion(b1 == ( a.n2() <= b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator>=(const Number_type_checker<NT1, NT2, Cmp> &a,
const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = a.n1() >= b.n1();
CGAL_assertion(b1 == ( a.n2() >= b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator==(const Number_type_checker<NT1, NT2, Cmp> &a, int i)
{
bool b1 = a.n1() == i;
CGAL_assertion(b1 == ( a.n2() == i ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator!=(const Number_type_checker<NT1, NT2, Cmp> &a, int i)
{
bool b1 = a.n1() != i;
CGAL_assertion(b1 == ( a.n2() != i ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator<(const Number_type_checker<NT1, NT2, Cmp> &a, int i)
{
bool b1 = a.n1() < i;
CGAL_assertion(b1 == ( a.n2() < i ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator>(const Number_type_checker<NT1, NT2, Cmp> &a, int i)
{
bool b1 = a.n1() > i;
CGAL_assertion(b1 == ( a.n2() > i ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator<=(const Number_type_checker<NT1, NT2, Cmp> &a, int i)
{
bool b1 = a.n1() <= i;
CGAL_assertion(b1 == ( a.n2() <= i ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator>=(const Number_type_checker<NT1, NT2, Cmp> &a, int i)
{
bool b1 = a.n1() >= i;
CGAL_assertion(b1 == ( a.n2() >= i ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator==(int i, const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = i == b.n1();
CGAL_assertion(b1 == ( i == b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator!=(int i, const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = i != b.n1();
CGAL_assertion(b1 == ( i != b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator<(int i, const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = i < b.n1();
CGAL_assertion(b1 == ( i < b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator>(int i, const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = i > b.n1();
CGAL_assertion(b1 == ( i > b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator<=(int i, const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = i <= b.n1();
CGAL_assertion(b1 == ( i <= b.n2() ) );
return b1;
}
template < typename NT1, typename NT2, typename Cmp >
bool
operator>=(int i, const Number_type_checker<NT1, NT2, Cmp> &b)
{
bool b1 = i >= b.n1();
CGAL_assertion(b1 == ( i >= b.n2() ) );
return b1;
}
// compare operators end
// Functors Is_valid
template < typename NT1, typename NT2, typename Cmp >
class Is_valid< Number_type_checker<NT1, NT2, Cmp> >
: public CGAL::cpp98::unary_function< Number_type_checker<NT1, NT2, Cmp> , bool > {
public :
bool operator()(const Number_type_checker<NT1, NT2, Cmp>& a ) const {
bool b1 = is_valid(a.n1());
CGAL_assertion(b1 == is_valid(a.n2()) );
// Should we also call a.is_valid() ?
return b1;
}
};
namespace NTC_INTERN{
// -----------------------------
// fwd
template < typename Number_type_checker, typename Algebraic_category>
class NTC_AST_base
:public Algebraic_structure_traits_base< Number_type_checker , Null_tag>{
};
template < typename NT1, typename NT2, typename Cmp >
class NTC_AST_base
< Number_type_checker<NT1, NT2, Cmp> , Integral_domain_without_division_tag>
:public Algebraic_structure_traits_base<Number_type_checker<NT1, NT2, Cmp>,
Integral_domain_without_division_tag>
{
private:
typedef Algebraic_structure_traits<NT1> AST1;
typedef Algebraic_structure_traits<NT2> AST2;
typedef Number_type_checker<NT1, NT2, Cmp> Type;
public:
//CGAL::Algebraic_structure_traits<>::Simplify
class Simplify
: public CGAL::cpp98::unary_function< Type& , void > {
public:
void operator()( Type& a) const {
typename AST1::Simplify()(a.n1());
typename AST2::Simplify()(a.n2());
CGAL_assertion(a.is_valid());
}
};
//CGAL::Algebraic_structure_traits< >::Is_zero
class Is_zero
: public CGAL::cpp98::unary_function< Type, bool > {
public:
bool operator()(const Type& a ) const {
bool b1 = typename AST1::Is_zero()(a.n1());
CGAL_assertion(b1 == typename AST2::Is_zero()(a.n2()) );
CGAL_assertion(a.is_valid());
return b1;
}
};
// CGAL::Algebraic_structure_traits< >::Is_one
class Is_one
: public CGAL::cpp98::unary_function< Type, bool > {
public:
bool operator()(const Type& a) const {
bool b1 = typename AST1::Is_one()(a.n1());
CGAL_assertion(b1 == typename AST2::Is_one()(a.n2()) );
CGAL_assertion(a.is_valid());
return b1;
}
};
// CGAL::Algebraic_structure_traits< >::Square
class Square
: public CGAL::cpp98::unary_function< Type , Type > {
public:
Type operator()(const Type& a) const {
return Type(
typename AST1::Square()(a.n1()),
typename AST2::Square()(a.n2()));
}
};
// CGAL::Algebraic_structure_traits< >::Unit_part
class Unit_part
: public CGAL::cpp98::unary_function< Type , Type > {
public:
Type operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("AST::Unit_part");
return Type(
typename AST1::Unit_part()(a.n1()),
typename AST2::Unit_part()(a.n2()));
}
};
};
template < typename NT1, typename NT2, typename Cmp >
class NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Integral_domain_tag >
:public NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Integral_domain_without_division_tag >
{
private:
typedef Algebraic_structure_traits<NT1> AST1;
typedef Algebraic_structure_traits<NT2> AST2;
typedef Number_type_checker<NT1, NT2, Cmp> Type;
public:
// CGAL::Algebraic_structure_traits< >::Integral_division
class Integral_division
: public CGAL::cpp98::binary_function< Type, Type, Type > {
public:
Type operator()( const Type& a, const Type& b) const {
CGAL_NT_CHECK_DEBUG("AST::Integral_division");
return Type(
typename AST1::Integral_division()(a.n1(),b.n1()),
typename AST2::Integral_division()(a.n2(),b.n2()));
}
};
class Divides
: public CGAL::cpp98::binary_function< Type, Type, bool > {
public:
bool operator()( const Type& a, const Type& b) const {
CGAL_NT_CHECK_DEBUG("AST::Divides");
bool result = typename AST1::Divides()(a.n1(),b.n1());
CGAL_assertion(result == typename AST2::Divides()(a.n2(),b.n2()));
return result;
}
bool operator()( const Type& a, const Type& b, Type& q) const {
CGAL_NT_CHECK_DEBUG("AST::Divides");
NT1 q1;
bool result1 = typename AST1::Divides()(a.n1(),b.n1(),q1);
NT2 q2;
CGAL_assertion_code( bool result2 = ) // needed for CGAL_assert only
typename AST2::Divides()(a.n2(),b.n2(),q2);
q = Type(q1,q2);
CGAL_assertion(result1 == result2);
return result1;
}
CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT(Type,bool)
};
};
template < typename NT1, typename NT2, typename Cmp >
class NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Unique_factorization_domain_tag >
:public NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Integral_domain_tag >
{
private:
typedef Algebraic_structure_traits<NT1> AST1;
typedef Algebraic_structure_traits<NT2> AST2;
typedef Number_type_checker<NT1, NT2, Cmp> Type;
public:
// CGAL::Algebraic_structure_traits< >::Gcd
class Gcd
: public CGAL::cpp98::binary_function< Type,
Type,
Type > {
public:
Type operator()(
const Type& a,
const Type& b) const {
CGAL_NT_CHECK_DEBUG("AST::Gcd");
return Type(
typename AST1::Gcd()(a.n1(),b.n1()),
typename AST2::Gcd()(a.n2(),b.n2()));
}
};
};
template < typename NT1, typename NT2, typename Cmp >
class NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Euclidean_ring_tag >
:public NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Unique_factorization_domain_tag >
{
private:
typedef Algebraic_structure_traits<NT1> AST1;
typedef Algebraic_structure_traits<NT2> AST2;
typedef Number_type_checker<NT1, NT2, Cmp> Type;
public:
// CGAL::Algebraic_structure_traits< >::Div
class Div
: public CGAL::cpp98::binary_function< Type,
Type,
Type > {
public:
Type operator()(
const Type& a,
const Type& b) const {
CGAL_NT_CHECK_DEBUG("AST::Div");
return Type(
typename AST1::Div()(a.n1(),b.n1()),
typename AST2::Div()(a.n2(),b.n2()));
}
};
// CGAL::Algebraic_structure_traits< >::Mod
class Mod
: public CGAL::cpp98::binary_function< Type,
Type,
Type > {
public:
Type operator()(
const Type& a,
const Type& b) const {
CGAL_NT_CHECK_DEBUG("AST::Mod");
return Type(
typename AST1::Mod()(a.n1(),b.n1()),
typename AST2::Mod()(a.n2(),b.n2()));
}
};
// CGAL::Algebraic_structure_traits< >::Div_mod
class Div_mod {
public:
typedef Type first_argument_type;
typedef Type second_argument_type;
typedef Type& third_argument_type;
typedef Type& fourth_argument_type;
typedef void result_type;
void operator()(
const Type& a,
const Type& b,
Type& q,
Type& r) const {
CGAL_NT_CHECK_DEBUG("AST::Div_mod");
NT1 q1,r1;
NT2 q2,r2;
typename AST1::Div_mod()(a.n1(),b.n1(),q1,r1);
typename AST2::Div_mod()(a.n2(),b.n2(),q2,r2);
q = Type(q1,q2);
r = Type(r1,r2);
}
};
};
template < typename NT1, typename NT2, typename Cmp >
class NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Field_tag >
:public NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Integral_domain_tag >
{
private:
typedef Algebraic_structure_traits<NT1> AST1;
typedef Algebraic_structure_traits<NT2> AST2;
typedef Number_type_checker<NT1, NT2, Cmp> Type;
public:
class Inverse
: public CGAL::cpp98::unary_function< Type, Type > {
public:
Type operator()( const Type& a ) const {
NT1 r1 = typename AST1::Inverse()(a.n1());
NT2 r2 = typename AST2::Inverse()(a.n2());
return Type(r1,r2);
}
};
};
template < typename NT1, typename NT2, typename Cmp >
class NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Field_with_sqrt_tag >
:public NTC_AST_base
< Number_type_checker< NT1, NT2, Cmp> , Field_tag >
{
private:
typedef Algebraic_structure_traits<NT1> AST1;
typedef Algebraic_structure_traits<NT2> AST2;
typedef Number_type_checker<NT1, NT2, Cmp> Type;
public:
// CGAL::Algebraic_structure_traits< >::Sqrt
class Sqrt
: public CGAL::cpp98::unary_function< Type , Type > {
public:
Type operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("AST::Sqrt");
return Type(
typename AST1::Sqrt()(a.n1()),
typename AST2::Sqrt()(a.n2()));
}
};
};
} // namespace NTC_INTERN
template < typename NT1, typename NT2, typename Cmp >
class Algebraic_structure_traits <Number_type_checker<NT1, NT2, Cmp> >
:public NTC_INTERN::NTC_AST_base< Number_type_checker< NT1, NT2, Cmp> ,
typename Algebraic_structure_traits<NT1>::Algebraic_category >
{
typedef Algebraic_structure_traits<NT1> AST1;
public:
typedef Number_type_checker< NT1, NT2, Cmp> Type;
typedef typename AST1::Algebraic_category Algebraic_category;
typedef typename AST1::Is_exact Is_exact;
};
namespace NTC_INTERN{
template < typename Number_type_checker, typename Is_real_embeddable >
class NTC_RET_base;
template < typename NT >
class NTC_RET_base<NT,Tag_false> : public Real_embeddable_traits<NT>
{};
template < typename NT1, typename NT2, typename Cmp >
class NTC_RET_base
< Number_type_checker<NT1, NT2, Cmp> , Tag_true>
:public INTERN_RET::Real_embeddable_traits_base< Number_type_checker< NT1, NT2, Cmp > , CGAL::Tag_true >
{
private:
typedef Real_embeddable_traits<NT1> RET1;
typedef Real_embeddable_traits<NT2> RET2;
typedef Number_type_checker<NT1, NT2, Cmp> Type;
public:
// CGAL::Real_embeddable_traits< >::Abs
class Abs
: public CGAL::cpp98::unary_function< Type , Type > {
public:
Type operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::Abs");
return Type(
typename RET1::Abs()(a.n1()),
typename RET2::Abs()(a.n2()));
}
};
// CGAL::Real_embeddable_traits< >::Sign
class Sgn
: public CGAL::cpp98::unary_function< Type , ::CGAL::Sign > {
public:
::CGAL::Sign operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::Sign");
::CGAL::Sign r1 = typename RET1::Sgn()(a.n1());
CGAL_assertion( r1 == typename RET2::Sgn()(a.n2()) );
return r1;
}
};
// CGAL::Real_embeddable_traits< >::Is_finite
class Is_finite
: public CGAL::cpp98::unary_function< Type , bool > {
public:
bool operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::Is_finite");
bool r1 = typename RET1::Is_finite()(a.n1());
CGAL_assertion( r1 == typename RET2::Is_finite()(a.n2()) );
return r1;
}
};
// CGAL::Real_embeddable_traits< >::Is_positive
class Is_positive
: public CGAL::cpp98::unary_function< Type , bool > {
public:
bool operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::Is_positive");
bool r1 = typename RET1::Is_positive()(a.n1());
CGAL_assertion( r1 == typename RET2::Is_positive()(a.n2()) );
return r1;
}
};
// CGAL::Real_embeddable_traits< >::Is_negative
class Is_negative
: public CGAL::cpp98::unary_function< Type , bool > {
public:
bool operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::Is_negative");
bool r1 = typename RET1::Is_negative()(a.n1());
CGAL_assertion( r1 == typename RET2::Is_negative()(a.n2()) );
return r1;
}
};
// CGAL::Real_embeddable_traits< >::Is_zero
class Is_zero
: public CGAL::cpp98::unary_function< Type , bool > {
public:
bool operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::Is_zero");
bool r1 = typename RET1::Is_zero()(a.n1());
CGAL_assertion( r1 == typename RET2::Is_zero()(a.n2()) );
return r1;
}
};
// CGAL::Real_embeddable_traits< >::Compare
class Compare
: public CGAL::cpp98::binary_function< Type , Type, Comparison_result > {
public:
Comparison_result operator()(const Type& a, const Type& b) const {
CGAL_NT_CHECK_DEBUG("RET::Compare");
Comparison_result r1 = typename RET1::Compare()(a.n1(),b.n1());
CGAL_assertion( r1 == typename RET2::Compare()(a.n2(),b.n2()) );
return r1;
}
};
// CGAL::Real_embeddable_traits< >::To_double
class To_double
: public CGAL::cpp98::unary_function< Type , double > {
public:
double operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::To_double");
double r1 = typename RET1::To_double()(a.n1());
CGAL_assertion( r1 == typename RET2::To_double()(a.n2()) );
return r1;
}
};
// CGAL::Real_embeddable_traits< >::To_interval
class To_interval
: public CGAL::cpp98::unary_function< Type , std::pair<double, double> > {
public:
std::pair<double, double> operator()(const Type& a) const {
CGAL_NT_CHECK_DEBUG("RET::To_interval");
std::pair<double, double> r1 = typename RET1::To_interval()(a.n1());
CGAL_assertion( r1 == typename RET2::To_interval()(a.n2()) );
return r1;
}
};
};
} // namespace NTC_INTERN
template < typename NT1, typename NT2, typename Cmp >
class Real_embeddable_traits
< Number_type_checker<NT1, NT2, Cmp> >
:public NTC_INTERN::NTC_RET_base< Number_type_checker< NT1, NT2, Cmp > ,
typename Real_embeddable_traits<NT1>::Is_real_embeddable >
{
typedef Real_embeddable_traits<NT1> RET1;
public:
typedef Number_type_checker< NT1, NT2, Cmp > Type;
typedef typename RET1::Is_real_embeddable Is_real_embeddable;
};
template < typename NT1, typename NT2, typename Cmp >
struct Coercion_traits< Number_type_checker<NT1,NT2,Cmp>,
Number_type_checker<NT1,NT2,Cmp> >{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_true Are_implicit_interoperable;
typedef Number_type_checker<NT1,NT2,Cmp> Type;
struct Cast{
typedef Type result_type;
Type operator()(const Type& x) const { return x;}
};
};
template < typename NT1, typename NT2, typename Cmp >
struct Coercion_traits< Number_type_checker<NT1,NT2,Cmp>, int >{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_true Are_implicit_interoperable;
typedef Number_type_checker<NT1,NT2,Cmp> Type;
struct Cast{
typedef Type result_type;
Type operator()(const Type& x) const { return x;}
Type operator()(int x) const { return Type(x);}
};
};
template < typename NT1, typename NT2, typename Cmp >
struct Coercion_traits< int , Number_type_checker<NT1,NT2,Cmp> >
:public Coercion_traits< Number_type_checker<NT1,NT2,Cmp> , int >{};
namespace NTC_INTERN {
template < typename NT_checker, typename Tag = Tag_false >
struct Coercion_traits_double{
typedef Tag_false Are_explicit_interoperable;
typedef Tag_false Are_implicit_interoperable;
typedef Null_tag Type;
};
template < typename NT1, typename NT2, typename Cmp>
struct Coercion_traits_double< Number_type_checker<NT1,NT2,Cmp> ,
Tag_true >{
typedef Tag_true Are_explicit_interoperable;
typedef Tag_true Are_implicit_interoperable;
typedef Number_type_checker<NT1,NT2,Cmp> Type;
struct Cast{
typedef Type result_type;
Type operator()(const Type& x) const { return x;}
Type operator()(const double& x) const {
return Type(x);
}
};
};
} // namespace NTC_INTERN
template < typename NT1, typename NT2, typename Cmp >
struct Coercion_traits< Number_type_checker<NT1,NT2,Cmp>, double >
:public NTC_INTERN::Coercion_traits_double< Number_type_checker<NT1,NT2,Cmp>,
typename Coercion_traits<NT1,double>::Are_implicit_interoperable >
{};
template < typename NT1, typename NT2, typename Cmp >
struct Coercion_traits< double , Number_type_checker<NT1,NT2,Cmp> >
:public Coercion_traits< Number_type_checker<NT1,NT2,Cmp>, double > {};
// What to do with the IO ?
// - either pick one as the main, and convert to the second.
// - output/input pairs, and read both (=> problems with FP values).
template < typename NT1, typename NT2, typename Cmp >
std::ostream &
operator<< (std::ostream & os, const Number_type_checker<NT1, NT2, Cmp> &b)
{
return os << b.n1();
}
template < typename NT1, typename NT2, typename Cmp >
std::istream &
operator>> (std::istream & is, Number_type_checker<NT1, NT2, Cmp> &b)
{
is >> b.n1();
std::stringstream ss;
ss << b.n1();
ss >> b.n2();
return is;
}
} //namespace CGAL
#endif // CGAL_NUMBER_TYPE_CHECKER_H
|