BWAPI
|
00001 // Copyright (c) 2005 Stanford University (USA). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation; version 2.1 of the License. 00007 // See the file LICENSE.LGPL distributed with CGAL. 00008 // 00009 // Licensees holding a valid commercial license may use this file in 00010 // accordance with the commercial license agreement provided with the software. 00011 // 00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 // 00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kinetic_data_structures/include/CGAL/Polynomial/internal/Alternation_counter.h $ 00016 // $Id: Alternation_counter.h 28567 2006-02-16 14:30:13Z lsaboret $ 00017 // 00018 // 00019 // Author(s) : Daniel Russel <drussel@alumni.princeton.edu> 00020 00021 #ifndef CGAL_ALTERNATION_COUNTER_H 00022 #define CGAL_ALTERNATION_COUNTER_H 00023 00024 #include <CGAL/Polynomial/basic.h> 00025 00026 CGAL_POLYNOMIAL_BEGIN_NAMESPACE 00027 00032 00033 00036 template <class NT> 00037 class Alternation_counter 00038 { 00039 public: 00040 Alternation_counter():num_alternations_(0), 00041 last_sign_(EXTENDED_ZERO), count_uncertain_(false), 00042 parity_uncertain_(false), 00043 last_was_uncertain_(false) {} 00045 void push_back(const NT &i) { 00046 Extended_sign sn= extended_sign(i); 00047 00048 if (sn == EXTENDED_ZERO) { 00049 00050 } 00051 else if (sn==EXTENDED_UNKNOWN) { 00052 if (last_was_uncertain_) { 00053 count_uncertain_=true; 00054 parity_uncertain_=true; 00055 } else last_was_uncertain_=true; 00056 } 00057 else { 00058 if (sn==EXTENDED_NEGATIVE 00059 && last_sign_ == EXTENDED_POSITIVE) { 00060 ++num_alternations_; 00061 } else if (sn==EXTENDED_POSITIVE 00062 && last_sign_==EXTENDED_NEGATIVE) { 00063 ++num_alternations_; 00064 } 00065 else { 00066 if (last_was_uncertain_) { 00067 count_uncertain_=true; 00068 } 00069 // parity is still good 00070 } 00071 last_sign_=sn; 00072 last_was_uncertain_=false; 00073 } 00074 } 00075 00077 00080 std::size_t number_of_alternations() const 00081 { 00082 return num_alternations_; 00083 } 00085 bool is_uncertain() const 00086 { 00087 return count_uncertain_ || last_was_uncertain_; 00088 } 00090 bool parity_uncertain() const 00091 { 00092 return parity_uncertain_; 00093 } 00094 protected: 00095 std::size_t num_alternations_; 00096 00097 Extended_sign last_sign_; 00098 00099 bool count_uncertain_; 00100 bool parity_uncertain_; 00101 bool last_was_uncertain_; 00102 00103 }; 00104 00105 CGAL_POLYNOMIAL_END_NAMESPACE; 00106 #endif