BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Polynomial/Polynomial.h
Go to the documentation of this file.
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/Polynomial.h $
00016 // $Id: Polynomial.h 31053 2006-05-07 04:25:55Z drussel $
00017 // 
00018 //
00019 // Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>
00020 
00021 #ifndef CGAL_POLYNOMIAL_POLYNOMIAL_H_
00022 #define CGAL_POLYNOMIAL_POLYNOMIAL_H_
00023 #include <CGAL/Polynomial/basic.h>
00024 
00025 #include <CGAL/Polynomial/internal/interval_arithmetic.h>
00026 #include <CGAL/Polynomial/internal/Polynomial_impl.h>
00027 //#include <utility>
00028 #include <sstream>
00029 
00030 CGAL_POLYNOMIAL_BEGIN_NAMESPACE
00031 
00033 
00038 template <class NTT>
00039 class Polynomial: public internal::Polynomial_impl<Polynomial<NTT>, NTT>
00040 {
00041     typedef Polynomial<NTT> This;
00042     typedef internal::Polynomial_impl<This, NTT>  Parent;
00043 
00044 // friend class internal::Polynomial_impl<This, NTT>; // NOT SO CLEAN
00045 
00046 #ifdef CGAL_POLYNOMIAL_STRING
00047     typedef std::string Approximation;
00048     void generate_approximation() const
00049     {
00050         std::ostringstream s;
00051         this->write(s);
00052         approximation_= s.str();
00053 //return s.str();
00054     }
00055 #endif
00056 
00057     void approximate() const
00058     {
00059 #ifdef CGAL_POLYNOMIAL_STRING
00060         generate_approximation();
00061 #endif
00062     }
00063     public:
00064 
00065 // hack to try to fix pgCC
00066 //using typename Parent::iterator;
00067         typedef typename Parent::iterator iterator;
00068 
00069 //================
00070 // CONSTRUCTORS
00071 //================
00072 
00074         Polynomial() {
00075 #ifdef CGAL_POLYNOMIAL_STRING
00076             approximation_="Not initialized.";
00077 #endif
00078         }
00079 
00081         Polynomial(const NTT& c): Parent(c) {
00082 #ifdef CGAL_POLYNOMIAL_STRING
00083             approximate();
00084 #endif
00085             strip_leading_zeros();
00086         }
00087 
00089         template<typename Iterator>
00090             Polynomial(Iterator first, Iterator beyond)
00091         : Parent(first,beyond) {
00092 #ifdef CGAL_POLYNOMIAL_STRING
00093             approximate();
00094 #endif
00095             strip_leading_zeros();
00096         }
00097 
00098         Polynomial(const Parent &p): Parent(p) {
00099 #ifdef CGAL_POLYNOMIAL_STRING
00100             approximate();
00101 #endif
00102             strip_leading_zeros();
00103         }
00104 
00105     protected:
00106 
00107         void strip_leading_zeros() {
00108             if ( this->is_zero() ) { return; }
00109 
00110             do {
00111                 Sign s = CGAL::sign( this->coefs_[this->degree()] );
00112                 if ( s == ZERO ) {
00113                     CGAL_Polynomial_assertion( this->coefs_.size() > 0 );
00114                     this->coefs_.resize(this->coefs_.size() - 1);
00115                 }
00116                 else {
00117                     break;
00118                 }
00119             } while ( !this->is_zero() );
00120         }
00121 
00122     public:
00123         void finalize() {
00124             strip_leading_zeros();
00125         }
00126 
00127     private:
00128 #ifdef CGAL_POLYNOMIAL_STRING
00129 
00131         mutable Approximation approximation_;
00132 #endif
00133 };
00134 
00135 CGAL_POLYNOMIAL_END_NAMESPACE
00136 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines