BWAPI
|
00001 // Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany). 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/Polynomial/include/CGAL/Exponent_vector.h $ 00016 // $Id: Exponent_vector.h 47915 2009-02-05 12:51:19Z eric $ 00017 // 00018 // 00019 // Author(s) : Michael Hemmer 00020 // 00021 // ============================================================================ 00022 00023 #ifndef CGAL_EXPONENT_VECTOR_H 00024 #define CGAL_EXPONENT_VECTOR_H 00025 00026 #include <deque> 00027 #include <iterator> 00028 #include <algorithm> 00029 #include <vector> 00030 #include <CGAL/assertions.h> 00031 00032 00033 CGAL_BEGIN_NAMESPACE 00034 00035 00036 class Exponent_vector : 00037 public boost::less_than_comparable1< Exponent_vector >, 00038 public boost::equality_comparable1< Exponent_vector > 00039 { 00040 std::vector<int> v; 00041 public: 00042 typedef Exponent_vector Self; 00043 00044 Exponent_vector(){}; 00045 00046 Exponent_vector(int e0): v(1) { 00047 v[0]=e0; 00048 }; 00049 Exponent_vector(int e0, int e1): v(2) { 00050 v[0]=e0; v[1]=e1; 00051 }; 00052 Exponent_vector(int e0, int e1, int e2): v(3) { 00053 v[0]=e0; v[1]=e1; v[2]=e2; 00054 }; 00055 Exponent_vector(int e0, int e1, int e2, int e3): v(4) { 00056 v[0]=e0; v[1]=e1; v[2]=e2; v[3]=e3; 00057 }; 00058 00059 Exponent_vector(const std::vector<int>& v_): v(v_){}; 00060 Exponent_vector(const Exponent_vector& ev): v(ev.v){}; 00061 00062 template <class InputIterator> 00063 Exponent_vector(InputIterator begin , InputIterator end) 00064 :v(begin,end){ 00065 typedef typename std::iterator_traits<InputIterator>::value_type value_type; 00066 BOOST_STATIC_ASSERT(( ::boost::is_same<value_type, int>::value)); 00067 } 00068 00069 00070 // mirror vector functions 00071 typedef std::vector<int>::value_type value_type; 00072 typedef std::vector<int>::pointer pointer; 00073 typedef std::vector<int>::const_pointer const_pointer; 00074 typedef std::vector<int>::reference reference; 00075 typedef std::vector<int>::const_reference const_reference; 00076 typedef std::vector<int>::size_type size_type; 00077 typedef std::vector<int>::difference_type difference_type; 00078 typedef std::vector<int>::iterator iterator; 00079 typedef std::vector<int>::const_iterator const_iterator; 00080 typedef std::vector<int>::reverse_iterator reverse_iterator; 00081 typedef std::vector<int>::const_reverse_iterator const_reverse_iterator; 00082 00083 iterator begin(){return v.begin();} 00084 iterator end(){return v.end();} 00085 const_iterator begin() const {return v.begin();} 00086 const_iterator end() const {return v.end();} 00087 reverse_iterator rbegin() {return v.rbegin();} 00088 reverse_iterator rend(){return v.rend();} 00089 const_reverse_iterator rbegin() const {return v.rbegin();} 00090 const_reverse_iterator rend() const {return v.rend();} 00091 size_type size() const {return v.size();} 00092 size_type max_size() const {return v.max_size();} 00093 size_type capacity() const {return v.capacity();} 00094 bool empty() const {return v.empty();} 00095 reference operator[](size_type n) { return v[n]; } 00096 const_reference operator[](size_type n) const {return v[n];} 00097 // vector& operator=(const vector&) 00098 00099 void reserve(size_t s){v.reserve(s);} 00100 reference front(){return v.front();} 00101 const_reference front() const {return v.front();} 00102 reference back() {return v.back();} 00103 const_reference back() const {return v.back();} 00104 void push_back(const int& x) { v.push_back(x);} 00105 void pop_back() {v.pop_back();} 00106 void swap(Self& ev) {v.swap(ev.v);} 00107 iterator insert(iterator pos, const int& x){return v.insert(pos,x);} 00108 00109 template <class InputIterator> 00110 void insert(iterator pos,InputIterator f, InputIterator l){ 00111 v.insert(pos,f,l); 00112 } 00113 void insert(iterator pos, size_type n, const int& x){ 00114 v.insert(pos,n,x); 00115 } 00116 iterator erase(iterator pos){return v.erase(pos);} 00117 iterator erase(iterator first, iterator last){return v.erase(first,last);} 00118 void clear(){v.clear();} 00119 void resize(size_type n, int t = 0){v.resize(n,t);} 00120 bool operator==(const Self& ev) const { return v == ev.v; } 00121 00122 // this is the actual change 00123 bool operator<( const Exponent_vector& ev ) const { 00124 CGAL_precondition(this->size() == ev.size()); 00125 const_reverse_iterator rit1(this->rbegin()); 00126 const_reverse_iterator rit2(ev.rbegin()); 00127 while(rit1!=this->rend()){ 00128 if(*rit1 < *rit2) return true; 00129 if(*rit1 > *rit2) return false; 00130 rit1++; rit2++; 00131 } 00132 CGAL_postcondition(rit1 == this->rend()); 00133 CGAL_postcondition(rit2 == ev.rend()); 00134 return false; 00135 } 00136 00137 void output_benchmark( std::ostream& os ) const { 00138 os << "( "; 00139 for( unsigned i = 0; i < size(); ++i ) { 00140 if( i != 0 ) 00141 os << ", "; 00142 os << v.at(i); 00143 } 00144 os << " )"; 00145 } 00146 }; 00147 00148 00149 inline bool is_valid(const Exponent_vector& ev) { 00150 Exponent_vector::const_iterator it; 00151 for(it = ev.begin(); it != ev.end();it++){ 00152 if (CGAL::is_negative(*it)) return false; 00153 } 00154 return true; 00155 } 00156 00157 inline std::ostream& operator << (std::ostream& os, const Exponent_vector& ev) { 00158 Exponent_vector::const_iterator it; 00159 os << "(" ; 00160 for(it = ev.begin(); it != ev.end();it++){ 00161 if (it == ev.begin()) { 00162 os << *it ; 00163 } 00164 else{ 00165 os <<"," << *it ; 00166 } 00167 } 00168 os << ")" ; 00169 return os; 00170 } 00171 00172 CGAL_END_NAMESPACE 00173 00174 namespace std{ 00175 template <> inline 00176 void swap(CGAL::Exponent_vector& ev1, CGAL::Exponent_vector& ev2){ 00177 ev1.swap(ev2); 00178 } 00179 00180 } 00181 00182 00183 #endif // CGAL_EXPONENT_VECTOR_H