|
PPL
0.12.1
|
00001 /* Linear_Form class implementation: inline functions. 00002 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 00003 Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com) 00004 00005 This file is part of the Parma Polyhedra Library (PPL). 00006 00007 The PPL is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 The PPL is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software Foundation, 00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 00020 00021 For the most up-to-date information see the Parma Polyhedra Library 00022 site: http://bugseng.com/products/ppl/ . */ 00023 00024 #ifndef PPL_Linear_Form_inlines_hh 00025 #define PPL_Linear_Form_inlines_hh 1 00026 00027 #include "Variable.defs.hh" 00028 #include <iostream> 00029 #include <stdexcept> 00030 00031 namespace Parma_Polyhedra_Library { 00032 00033 template <typename C> 00034 inline dimension_type 00035 Linear_Form<C>::max_space_dimension() { 00036 return vec_type().max_size() - 1; 00037 } 00038 00039 template <typename C> 00040 inline 00041 Linear_Form<C>::Linear_Form() 00042 : vec(1, zero) { 00043 vec.reserve(compute_capacity(1, vec_type().max_size())); 00044 } 00045 00046 template <typename C> 00047 inline 00048 Linear_Form<C>::Linear_Form(dimension_type sz, bool) 00049 : vec(sz, zero) { 00050 vec.reserve(compute_capacity(sz, vec_type().max_size())); 00051 } 00052 00053 template <typename C> 00054 inline 00055 Linear_Form<C>::Linear_Form(const Linear_Form& f) 00056 : vec(f.vec) { 00057 } 00058 00059 template <typename C> 00060 inline 00061 Linear_Form<C>::~Linear_Form() { 00062 } 00063 00064 template <typename C> 00065 inline dimension_type 00066 Linear_Form<C>::size() const { 00067 return vec.size(); 00068 } 00069 00070 template <typename C> 00071 inline void 00072 Linear_Form<C>::extend(dimension_type sz) { 00073 assert(sz > size()); 00074 vec.reserve(compute_capacity(sz, vec_type().max_size())); 00075 vec.resize(sz, zero); 00076 } 00077 00078 template <typename C> 00079 inline 00080 Linear_Form<C>::Linear_Form(const C& n) 00081 : vec(1, n) { 00082 vec.reserve(compute_capacity(1, vec_type().max_size())); 00083 } 00084 00085 template <typename C> 00086 inline dimension_type 00087 Linear_Form<C>::space_dimension() const { 00088 return size() - 1; 00089 } 00090 00091 template <typename C> 00092 inline const C& 00093 Linear_Form<C>::coefficient(Variable v) const { 00094 if (v.space_dimension() > space_dimension()) 00095 return zero; 00096 return vec[v.id()+1]; 00097 } 00098 00099 template <typename C> 00100 inline C& 00101 Linear_Form<C>::operator[](dimension_type i) { 00102 assert(i < size()); 00103 return vec[i]; 00104 } 00105 00106 template <typename C> 00107 inline const C& 00108 Linear_Form<C>::operator[](dimension_type i) const { 00109 assert(i < size()); 00110 return vec[i]; 00111 } 00112 00113 template <typename C> 00114 inline const C& 00115 Linear_Form<C>::inhomogeneous_term() const { 00116 return vec[0]; 00117 } 00118 00119 template <typename C> 00120 inline memory_size_type 00121 Linear_Form<C>::total_memory_in_bytes() const { 00122 return sizeof(*this) + external_memory_in_bytes(); 00123 } 00124 00126 template <typename C> 00127 inline Linear_Form<C> 00128 operator+(const Linear_Form<C>& f) { 00129 return f; 00130 } 00131 00133 template <typename C> 00134 inline Linear_Form<C> 00135 operator+(const Linear_Form<C>& f, const C& n) { 00136 return n + f; 00137 } 00138 00140 template <typename C> 00141 inline Linear_Form<C> 00142 operator+(const Linear_Form<C>& f, const Variable v) { 00143 return v + f; 00144 } 00145 00147 template <typename C> 00148 inline Linear_Form<C> 00149 operator-(const Linear_Form<C>& f, const C& n) { 00150 return -n + f; 00151 } 00152 00154 template <typename C> 00155 inline Linear_Form<C> 00156 operator-(const Variable v, const Variable w) { 00157 return Linear_Form<C>(v, w); 00158 } 00159 00161 template <typename C> 00162 inline Linear_Form<C> 00163 operator*(const Linear_Form<C>& f, const C& n) { 00164 return n * f; 00165 } 00166 00168 template <typename C> 00169 inline Linear_Form<C>& 00170 operator+=(Linear_Form<C>& f, const C& n) { 00171 f[0] += n; 00172 return f; 00173 } 00174 00176 template <typename C> 00177 inline Linear_Form<C>& 00178 operator-=(Linear_Form<C>& f, const C& n) { 00179 f[0] -= n; 00180 return f; 00181 } 00182 00184 template <typename C> 00185 inline bool 00186 operator!=(const Linear_Form<C>& x, const Linear_Form<C>& y) { 00187 return !(x == y); 00188 } 00189 00190 template <typename C> 00191 inline void 00192 Linear_Form<C>::m_swap(Linear_Form& y) { 00193 using std::swap; 00194 swap(vec, y.vec); 00195 } 00196 00197 template <typename C> 00198 inline void 00199 Linear_Form<C>::ascii_dump(std::ostream& s) const { 00200 using namespace IO_Operators; 00201 dimension_type space_dim = space_dimension(); 00202 s << space_dim << "\n"; 00203 for (dimension_type i = 0; i <= space_dim; ++i) { 00204 const char separator = ' '; 00205 s << vec[i] << separator; 00206 } 00207 s << "\n"; 00208 } 00209 00210 template <typename C> 00211 inline bool 00212 Linear_Form<C>::ascii_load(std::istream& s) { 00213 using namespace IO_Operators; 00214 dimension_type new_dim; 00215 if (!(s >> new_dim)) 00216 return false; 00217 00218 vec.resize(new_dim + 1, zero); 00219 for (dimension_type i = 0; i <= new_dim; ++i) { 00220 if (!(s >> vec[i])) 00221 return false; 00222 } 00223 00224 PPL_ASSERT(OK()); 00225 return true; 00226 } 00227 00228 // Floating point analysis related methods. 00229 template <typename C> 00230 inline bool 00231 Linear_Form<C>::overflows() const { 00232 if (!inhomogeneous_term().is_bounded()) 00233 return true; 00234 00235 for (dimension_type i = space_dimension(); i-- > 0; ) { 00236 if (!coefficient(Variable(i)).is_bounded()) 00237 return true; 00238 } 00239 00240 return false; 00241 } 00242 00244 template <typename C> 00245 inline void 00246 swap(Linear_Form<C>& x, Linear_Form<C>& y) { 00247 x.m_swap(y); 00248 } 00249 00250 } // namespace Parma_Polyhedra_Library 00251 00252 #endif // !defined(PPL_Linear_Form_inlines_hh)