From 0c34dc2525c21a8fabc1adb3b4b6c6fde4da4a57 Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Tue, 12 Aug 2008 11:23:34 +0000 Subject: [PATCH] - Refine CGAL_AND or CGAL_OR to make sure they work when the second argument is a bool. - Add CGAL_AND_3 and CGAL_OR_3 for 3-arguments boolean operations. --- STL_Extension/doc_tex/STL_Extension_ref/Uncertain.tex | 3 +++ STL_Extension/include/CGAL/Uncertain.h | 9 +++++++-- STL_Extension/test/STL_Extension/test_Uncertain.cpp | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/STL_Extension/doc_tex/STL_Extension_ref/Uncertain.tex b/STL_Extension/doc_tex/STL_Extension_ref/Uncertain.tex index 02c94f727c1..d4ccf828b60 100644 --- a/STL_Extension/doc_tex/STL_Extension_ref/Uncertain.tex +++ b/STL_Extension/doc_tex/STL_Extension_ref/Uncertain.tex @@ -320,6 +320,9 @@ Another option is : ... // Use res \end{ccExampleCode} + For convenience, the macros \ccc{CGAL_AND_3} and \ccc{CGAL_OR_3} are also + provided to support boolean operations with 3 arguments instead of 2. + %% +-----------------------------------+ \ccHeading{Overloaded operators and functions for \ccc{Uncertain} only} diff --git a/STL_Extension/include/CGAL/Uncertain.h b/STL_Extension/include/CGAL/Uncertain.h index a15b87df170..76ebf622af3 100644 --- a/STL_Extension/include/CGAL/Uncertain.h +++ b/STL_Extension/include/CGAL/Uncertain.h @@ -319,12 +319,17 @@ Uncertain operator&(Uncertain a, bool b) #else # define CGAL_AND(X, Y) \ ({ CGAL::Uncertain CGAL_TMP = (X); \ - CGAL::certainly_not(CGAL_TMP) ? CGAL::make_uncertain(false) : CGAL_TMP & (Y); }) + CGAL::certainly_not(CGAL_TMP) ? CGAL::make_uncertain(false) \ + : CGAL_TMP & CGAL::make_uncertain((Y)); }) # define CGAL_OR(X, Y) \ ({ CGAL::Uncertain CGAL_TMP = (X); \ - CGAL::certainly(CGAL_TMP) ? CGAL::make_uncertain(true) : CGAL_TMP | (Y); }) + CGAL::certainly(CGAL_TMP) ? CGAL::make_uncertain(true) \ + : CGAL_TMP | CGAL::make_uncertain((Y)); }) #endif +#define CGAL_AND_3(X, Y, Z) CGAL_AND(X, CGAL_AND(Y, Z)) +#define CGAL_OR_3(X, Y, Z) CGAL_OR(X, CGAL_OR(Y, Z)) + // Equality operators diff --git a/STL_Extension/test/STL_Extension/test_Uncertain.cpp b/STL_Extension/test/STL_Extension/test_Uncertain.cpp index 67856a45dae..8a214ba81ba 100644 --- a/STL_Extension/test/STL_Extension/test_Uncertain.cpp +++ b/STL_Extension/test/STL_Extension/test_Uncertain.cpp @@ -243,6 +243,9 @@ void test_bool() bool_assert(CGAL_AND(utrue, utrue)); bool_assert(!CGAL_AND(ufalse, ufalse)); + bool_assert(CGAL_AND_3(true, true, true)); + bool_assert(!CGAL_AND_3(true, false, true)); + bool_assert(CGAL_OR(true, false)); bool_assert(CGAL_OR(false, true)); bool_assert(CGAL_OR(true, true)); @@ -252,6 +255,9 @@ void test_bool() bool_assert(CGAL_OR(utrue, utrue)); bool_assert(!CGAL_OR(ufalse, ufalse)); + bool_assert(CGAL_OR_3(false, false, true)); + bool_assert(!CGAL_OR_3(false, false, false)); + try { bool_assert( CGAL_AND(utrue, utrue)); bool_assert(!CGAL_AND(ufalse, ufalse));