PPL  1.2
Linear_Form_inlines.hh
Go to the documentation of this file.
1 /* Linear_Form class implementation: inline functions.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Linear_Form_inlines_hh
25 #define PPL_Linear_Form_inlines_hh 1
26 
27 #include "Variable_defs.hh"
28 #include <iostream>
29 #include <stdexcept>
30 
31 namespace Parma_Polyhedra_Library {
32 
33 template <typename C>
34 inline dimension_type
36  return vec_type().max_size() - 1;
37 }
38 
39 template <typename C>
40 inline
42  : vec(1, zero) {
43  vec.reserve(compute_capacity(1, vec_type().max_size()));
44 }
45 
46 template <typename C>
47 inline
49  : vec(sz, zero) {
50  vec.reserve(compute_capacity(sz, vec_type().max_size()));
51 }
52 
53 template <typename C>
54 inline
56  : vec(f.vec) {
57 }
58 
59 template <typename C>
60 inline
62 }
63 
64 template <typename C>
65 inline dimension_type
67  return vec.size();
68 }
69 
70 template <typename C>
71 inline void
73  assert(sz > size());
74  vec.reserve(compute_capacity(sz, vec_type().max_size()));
75  vec.resize(sz, zero);
76 }
77 
78 template <typename C>
79 inline
81  : vec(1, n) {
82  vec.reserve(compute_capacity(1, vec_type().max_size()));
83 }
84 
85 template <typename C>
86 inline dimension_type
88  return size() - 1;
89 }
90 
91 template <typename C>
92 inline const C&
94  if (v.space_dimension() > space_dimension()) {
95  return zero;
96  }
97  return vec[v.id()+1];
98 }
99 
100 template <typename C>
101 inline C&
103  assert(i < size());
104  return vec[i];
105 }
106 
107 template <typename C>
108 inline const C&
110  assert(i < size());
111  return vec[i];
112 }
113 
114 template <typename C>
115 inline const C&
117  return vec[0];
118 }
119 
120 template <typename C>
121 inline memory_size_type
123  return sizeof(*this) + external_memory_in_bytes();
124 }
125 
127 template <typename C>
128 inline Linear_Form<C>
130  return f;
131 }
132 
134 template <typename C>
135 inline Linear_Form<C>
136 operator+(const Linear_Form<C>& f, const C& n) {
137  return n + f;
138 }
139 
141 template <typename C>
142 inline Linear_Form<C>
143 operator+(const Linear_Form<C>& f, const Variable v) {
144  return v + f;
145 }
146 
148 template <typename C>
149 inline Linear_Form<C>
150 operator-(const Linear_Form<C>& f, const C& n) {
151  return -n + f;
152 }
153 
155 template <typename C>
156 inline Linear_Form<C>
157 operator-(const Variable v, const Variable w) {
158  return Linear_Form<C>(v, w);
159 }
160 
162 template <typename C>
163 inline Linear_Form<C>
164 operator*(const Linear_Form<C>& f, const C& n) {
165  return n * f;
166 }
167 
169 template <typename C>
170 inline Linear_Form<C>&
171 operator+=(Linear_Form<C>& f, const C& n) {
172  f[0] += n;
173  return f;
174 }
175 
177 template <typename C>
178 inline Linear_Form<C>&
179 operator-=(Linear_Form<C>& f, const C& n) {
180  f[0] -= n;
181  return f;
182 }
183 
185 template <typename C>
186 inline bool
188  return !(x == y);
189 }
190 
191 template <typename C>
192 inline void
194  using std::swap;
195  swap(vec, y.vec);
196 }
197 
198 template <typename C>
199 inline void
200 Linear_Form<C>::ascii_dump(std::ostream& s) const {
201  using namespace IO_Operators;
202  dimension_type space_dim = space_dimension();
203  s << space_dim << "\n";
204  for (dimension_type i = 0; i <= space_dim; ++i) {
205  const char separator = ' ';
206  s << vec[i] << separator;
207  }
208  s << "\n";
209 }
210 
211 template <typename C>
212 inline bool
213 Linear_Form<C>::ascii_load(std::istream& s) {
214  using namespace IO_Operators;
215  dimension_type new_dim;
216  if (!(s >> new_dim)) {
217  return false;
218  }
219 
220  vec.resize(new_dim + 1, zero);
221  for (dimension_type i = 0; i <= new_dim; ++i) {
222  if (!(s >> vec[i])) {
223  return false;
224  }
225  }
226 
227  PPL_ASSERT(OK());
228  return true;
229 }
230 
231 // Floating point analysis related methods.
232 template <typename C>
233 inline bool
235  if (!inhomogeneous_term().is_bounded()) {
236  return true;
237  }
238  for (dimension_type i = space_dimension(); i-- > 0; ) {
239  if (!coefficient(Variable(i)).is_bounded()) {
240  return true;
241  }
242  }
243 
244  return false;
245 }
246 
248 template <typename C>
249 inline void
251  x.m_swap(y);
252 }
253 
254 } // namespace Parma_Polyhedra_Library
255 
256 #endif // !defined(PPL_Linear_Form_inlines_hh)
void swap(Linear_Form< C > &x, Linear_Form< C > &y)
void swap(CO_Tree &x, CO_Tree &y)
C & operator[](dimension_type i)
Returns a reference to vec[i].
std::vector< C > vec_type
Type of the container vector.
size_t dimension_type
An unsigned integral type for representing space dimensions.
const C & coefficient(Variable v) const
Returns the coefficient of v in *this.
bool overflows() const
Verifies if the linear form overflows.
void ascii_dump() const
Writes to std::cerr an ASCII representation of *this.
Linear_Form< C > operator+(const Linear_Form< C > &f, const Variable v)
Linear_Form< C > operator*(const Linear_Form< C > &f, const C &n)
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
dimension_type id() const
Returns the index of the Cartesian axis associated to the variable.
A dimension of the vector space.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
void extend(dimension_type sz)
Extends the vector of *this to size sz.
Linear_Form< C > operator+(const Linear_Form< C > &f)
A linear form with interval coefficients.
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
Linear_Form< C > operator+(const Linear_Form< C > &f, const C &n)
vec_type vec
The container vector.
Linear_Form< C > operator-(const Linear_Form< C > &f, const C &n)
Linear_Form< C > & operator-=(Linear_Form< C > &f, const C &n)
bool operator!=(const Linear_Form< C > &x, const Linear_Form< C > &y)
Linear_Form< C > operator-(const Variable v, const Variable w)
The entire library is confined to this namespace.
Definition: version.hh:61
const C & inhomogeneous_term() const
Returns the inhomogeneous term of *this.
memory_size_type total_memory_in_bytes() const
Returns a lower bound to the total size in bytes of the memory occupied by *this. ...
Linear_Form()
Default constructor: returns a copy of Linear_Form::zero().
dimension_type size() const
Gives the number of generic coefficients currently in use.
Linear_Form< C > & operator+=(Linear_Form< C > &f, const C &n)
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
void m_swap(Linear_Form &y)
Swaps *this with y.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_Form can handle.