APRONXX  0.9.12
/home/mine/apron/apronxx/apxx_lincons0_inline.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * apxx_lincons0_inline.hh
3  *
4  * APRON Library / C++ inline functions
5  *
6  * DO NOT INCLUDE THIS FILE DIRECTLY
7  *
8  * Copyright (C) Antoine Mine' 2007
9  *
10  */
11 /* This file is part of the APRON Library, released under LGPL license
12  with an exception allowing the redistribution of statically linked
13  executables.
14 
15  Please read the COPYING file packaged in the distribution.
16 */
17 
18 
19 /* ================================= */
20 /* lincons0 */
21 /* ================================= */
22 
23 inline lincons0::lincons0(ap_lincons0_t l) : l(l) {}
24 
25 inline lincons0::lincons0(ap_constyp_t constyp)
26 {
27  ap_linexpr0_t* llin = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0);
28  l = ap_lincons0_make(constyp, llin, NULL);
29 }
30 
31 inline lincons0::lincons0(ap_constyp_t constyp, const linexpr0& lin, const scalar& modulo)
32 {
33  ap_linexpr0_t* llin = ap_linexpr0_copy(const_cast<ap_linexpr0_t*>(lin.get_ap_linexpr0_t()));
34  ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(modulo.get_ap_scalar_t()));
35  l = ap_lincons0_make(constyp, llin, mmodulo);
36 }
37 
38 inline lincons0::lincons0(ap_constyp_t constyp, const linexpr0& lin)
39 {
40  ap_linexpr0_t* llin = ap_linexpr0_copy(const_cast<ap_linexpr0_t*>(lin.get_ap_linexpr0_t()));
41  l = ap_lincons0_make(constyp, llin, NULL);
42 }
43 
44 inline lincons0::lincons0(const lincons0& x)
45 {
46  l = ap_lincons0_copy(const_cast<ap_lincons0_t*>(&x.l));
47 }
48 
49 inline lincons0::lincons0(unsat x)
50 {
51  l = ap_lincons0_make_unsat();
52 }
53 
54 inline lincons0::lincons0(const lincons0& x, const dimchange& d)
55 {
56  if (!x.l.linexpr0) throw std::invalid_argument("apron::lincons0::lincons0(const dimchange&) empty expression");
57  l = ap_lincons0_add_dimensions(const_cast<ap_lincons0_t*>(&x.l),
58  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
59 }
60 
61 inline lincons0::lincons0(const lincons0& x, const dimperm& d)
62 {
63  if (!x.l.linexpr0) throw std::invalid_argument("apron::lincons0::lincons0(const dimperm&) empty expression");
64  l = ap_lincons0_permute_dimensions(const_cast<ap_lincons0_t*>(&x.l),
65  const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
66 }
67 
68 
69 /* destructor */
70 /* ========== */
71 
72 inline lincons0::~lincons0()
73 {
74  ap_lincons0_clear(&l);
75 }
76 
77 
78 /* assignment */
79 /* ========== */
80 
81 inline lincons0& lincons0::operator= (const lincons0& x)
82 {
83  if (&x!=this) {
84  ap_lincons0_clear(&l);
85  l = ap_lincons0_copy(const_cast<ap_lincons0_t*>(&x.l));
86  }
87  return *this;
88 }
89 
90 inline lincons0& lincons0::operator= (unsat x)
91 {
92  ap_lincons0_clear(&l);
93  l = ap_lincons0_make_unsat();
94  return *this;
95 }
96 
97 
98 /* dimension operations */
99 /* ==================== */
100 
101 inline void lincons0::resize(size_t size)
102 {
103  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::resize(size_t) empty expression");
104  ap_linexpr0_realloc(l.linexpr0, size);
105 }
106 
107 
108 inline void lincons0::add_dimensions(const dimchange& d)
109 {
110  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::add_dimensions(const dimchange&) empty expression");
111  ap_lincons0_add_dimensions_with(&l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
112 }
113 
114 inline void lincons0::permute_dimensions(const dimperm& d)
115 {
116  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::permute_dimensions(const dimperm&) empty expression");
117  ap_lincons0_permute_dimensions_with(&l, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
118 }
119 
120 
121 /* access */
122 /* ====== */
123 
124 /* size */
125 
126 inline size_t lincons0::size() const
127 {
128  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::size() empty expression");
129  return ap_linexpr0_size(const_cast<ap_linexpr0_t*>(l.linexpr0));
130 }
131 
132 
133 /* get */
134 
135 inline ap_constyp_t& lincons0::get_constyp()
136 {
137  return l.constyp;
138 }
139 
140 inline const ap_constyp_t& lincons0::get_constyp() const
141 {
142  return l.constyp;
143 }
144 
145 inline bool lincons0::has_modulo() const
146 {
147  return l.scalar!=NULL;
148 }
149 
150 inline bool lincons0::has_linexpr() const
151 {
152  return l.linexpr0!=NULL;
153 }
154 
155 inline scalar& lincons0::get_modulo()
156 {
157  if (!l.scalar) throw std::invalid_argument("apron::lincons0::get_modulo() empty scalar");
158  return reinterpret_cast<scalar&>(*l.scalar);
159 }
160 
161 inline const scalar& lincons0::get_modulo() const
162 {
163  if (!l.scalar) throw std::invalid_argument("apron::lincons0::get_modulo() empty scalar");
164  return reinterpret_cast<scalar&>(*l.scalar);
165 }
166 
167 inline void lincons0::set_modulo(const scalar& c)
168 {
169  if (!l.scalar) l.scalar = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(c.get_ap_scalar_t()));
170  else ap_scalar_set(l.scalar, const_cast<ap_scalar_t*>(c.get_ap_scalar_t()));
171 }
172 
173 inline linexpr0& lincons0::get_linexpr()
174 {
175  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::get_linexpr() empty expression");
176  return reinterpret_cast<linexpr0&>(*l.linexpr0);
177 }
178 
179 inline const linexpr0& lincons0::get_linexpr() const
180 {
181  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::get_linexpr() empty expression");
182  return reinterpret_cast<linexpr0&>(*l.linexpr0);
183 }
184 
185 inline void lincons0::set_linexpr(const linexpr0& c)
186 {
187  if (l.linexpr0) ap_linexpr0_free(l.linexpr0);
188  l.linexpr0 = ap_linexpr0_copy(const_cast<ap_linexpr0_t*>(c.get_ap_linexpr0_t()));
189 }
190 
191 inline coeff& lincons0::get_cst()
192 { return get_linexpr().get_cst(); }
193 
194 inline const coeff& lincons0::get_cst() const
195 { return get_linexpr().get_cst(); }
196 
197 inline coeff& lincons0::operator[](ap_dim_t dim)
198 { return get_linexpr()[dim]; }
199 
200 inline const coeff& lincons0::operator[](ap_dim_t dim) const
201 { return get_linexpr()[dim]; }
202 
203 
204 /* print */
205 /* ===== */
206 
207 inline std::ostream& operator<< (std::ostream& os, const lincons0& s)
208 {
209  os << s.get_linexpr();
210  switch (s.get_constyp()) {
211  case AP_CONS_EQ: return os << " = 0";
212  case AP_CONS_SUPEQ: return os << " >= 0";
213  case AP_CONS_SUP: return os << " > 0";
214  case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo();
215  case AP_CONS_DISEQ: return os << " != 0";
216  default: throw std::invalid_argument("apron::operator<<(ostream&, const lincons0&) unknown constraint type");
217  }
218 }
219 
220 inline void lincons0::print(char** name_of_dim, FILE* stream) const
221 {
222  ap_lincons0_fprint(stream, const_cast<ap_lincons0_t*>(&l), name_of_dim);
223 }
224 
225 
226 /* tests */
227 /* ===== */
228 
229 inline bool lincons0::is_unsat() const
230 {
231  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::is_unsat() empty expression");
232  return ap_lincons0_is_unsat(const_cast<ap_lincons0_t*>(&l));
233 }
234 
235 inline bool lincons0::is_linear() const
236 {
237  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::is_linear() empty expression");
238  return ap_linexpr0_is_linear(l.linexpr0);
239 }
240 
241 inline bool lincons0::is_quasilinear() const
242 {
243  if (!l.linexpr0) throw std::invalid_argument("apron::lincons0::is_quasilinear() empty expression");
244  return ap_linexpr0_is_quasilinear(l.linexpr0);
245 }
246 
247 
248 
249 /* C-level compatibility */
250 /* ===================== */
251 
252 inline const ap_lincons0_t* lincons0::get_ap_lincons0_t() const
253 {
254  return &l;
255 }
256 
257 inline ap_lincons0_t* lincons0::get_ap_lincons0_t()
258 {
259  return &l;
260 }
261 
262 
263 /* ================================= */
264 /* lincons0_array */
265 /* ================================= */
266 
267 
268 /* constructors */
269 /* ============ */
270 
271 inline lincons0_array::lincons0_array(size_t size)
272  : a(ap_lincons0_array_make(size))
273 {
274 }
275 
276 inline lincons0_array::lincons0_array(const lincons0_array& x)
277  : a(ap_lincons0_array_make(x.a.size))
278 {
279  for (size_t i=0; i<a.size; i++)
280  a.p[i] = ap_lincons0_copy(&x.a.p[i]);
281 }
282 
283 inline lincons0_array::lincons0_array(size_t size, const lincons0 x[])
284  : a(ap_lincons0_array_make(size))
285 {
286  for (size_t i=0; i<size; i++)
287  a.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
288 }
289 
290 inline lincons0_array::lincons0_array(const std::vector<lincons0>& x)
291  : a(ap_lincons0_array_make(x.size()))
292 {
293  for (size_t i=0; i<a.size; i++)
294  a.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
295 }
296 
297 inline lincons0_array::lincons0_array(const lincons0_array& x, const dimchange& d)
298 {
299  a = ap_lincons0_array_add_dimensions(const_cast<ap_lincons0_array_t*>(&x.a),
300  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
301 }
302 
303 inline lincons0_array::lincons0_array(const lincons0_array& x, const dimperm& d)
304 {
305  a = ap_lincons0_array_permute_dimensions(const_cast<ap_lincons0_array_t*>(&x.a),
306  const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
307 }
308 
309 
310 /* destructor */
311 /* ========== */
312 
313 inline lincons0_array::~lincons0_array()
314 {
315  ap_lincons0_array_clear(&a);
316 }
317 
318 
319 /* assignment */
320 /* ========== */
321 
322 inline lincons0_array& lincons0_array::operator= (const lincons0_array& x)
323 {
324  if (&x!=this) {
325  ap_lincons0_array_clear(&a);
326  a = ap_lincons0_array_make(x.a.size);
327  for (size_t i=0; i<a.size; i++) a.p[i] = ap_lincons0_copy(&x.a.p[i]);
328  }
329  return *this;
330 }
331 
332 inline lincons0_array& lincons0_array::operator= (const lincons0 x[])
333 {
334  size_t size = a.size;
335  ap_lincons0_array_clear(&a);
336  a = ap_lincons0_array_make(size);
337  for (size_t i=0; i<size; i++)
338  a.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
339  return *this;
340 }
341 
342 inline lincons0_array& lincons0_array::operator= (const std::vector<lincons0>& x)
343 {
344  size_t size = x.size();
345  ap_lincons0_array_clear(&a);
346  a = ap_lincons0_array_make(size);
347  for (size_t i=0; i<size; i++)
348  a.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
349  return *this;
350 }
351 
352 
353 /* dimension operations */
354 /* ==================== */
355 
356 inline void lincons0_array::resize(size_t size)
357 {
358  ap_lincons0_array_resize(&a, size);
359 }
360 
361 inline void lincons0_array::add_dimensions(const dimchange& d)
362 {
363  ap_lincons0_array_add_dimensions_with(&a, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
364 }
365 
366 inline void lincons0_array::permute_dimensions(const dimperm& d)
367 {
368  ap_lincons0_array_permute_dimensions_with(&a, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
369 }
370 
371 
372 /* access */
373 /* ====== */
374 
375 inline size_t lincons0_array::size() const
376 {
377  return a.size;
378 }
379 
380 inline lincons0* lincons0_array::contents()
381 {
382  return reinterpret_cast<lincons0*>(a.p);
383 }
384 
385 inline const lincons0* lincons0_array::contents() const
386 {
387  return reinterpret_cast<lincons0*>(a.p);
388 }
389 
390 inline lincons0& lincons0_array::operator[](size_t i)
391 {
392  return reinterpret_cast<lincons0&>(a.p[i]);
393 }
394 
395 inline const lincons0& lincons0_array::operator[](size_t i) const
396 {
397  return reinterpret_cast<lincons0&>(a.p[i]);
398 }
399 
400 inline lincons0& lincons0_array::get(size_t i)
401 {
402  if (i >= a.size) throw std::out_of_range("apron::lincons0_array::get(size_t)");
403  return reinterpret_cast<lincons0&>(a.p[i]);
404 }
405 
406 inline const lincons0& lincons0_array::get(size_t i) const
407 {
408  if (i >= a.size) throw std::out_of_range("apron::lincons0_array::get(size_t)");
409  return reinterpret_cast<lincons0&>(a.p[i]);
410 }
411 
412 
413 /* conversion */
414 /* ========== */
415 
416 inline lincons0_array::operator std::vector<lincons0>() const
417 {
418  size_t sz = size();
419  std::vector<lincons0> v = std::vector<lincons0>(sz);
420  for (size_t i=0;i<sz;i++)
421  v[i] = (*this)[i];
422  return v;
423 }
424 
425 
426 /* print */
427 /* ===== */
428 
429 inline std::ostream& operator<< (std::ostream& os, const lincons0_array& s)
430 {
431  size_t sz = s.size();
432  os << "{ ";
433  for (size_t i=0;i<sz;i++)
434  os << s[i] << "; ";
435  return os << "}";
436 }
437 
438 inline void lincons0_array::print(char** name_of_dim, FILE* stream) const
439 {
440  ap_lincons0_array_fprint(stream, const_cast<ap_lincons0_array_t*>(&a), name_of_dim);
441 }
442 
443 
444 /* tests */
445 /* ===== */
446 
447 inline bool lincons0_array::is_linear() const
448 {
449  return ap_lincons0_array_is_linear(const_cast<ap_lincons0_array_t*>(&a));
450 }
451 
452 inline bool lincons0_array::is_quasilinear() const
453 {
454  return ap_lincons0_array_is_quasilinear(const_cast<ap_lincons0_array_t*>(&a));
455 }
456 
457 
458 
459 /* C-level compatibility */
460 /* ===================== */
461 
462 inline const ap_lincons0_array_t* lincons0_array::get_ap_lincons0_array_t() const
463 {
464  return &a;
465 }
466 
467 inline ap_lincons0_array_t* lincons0_array::get_ap_lincons0_array_t()
468 {
469  return &a;
470 }
size_t size() const
Returns the size of the underlying linear expression.
Definition: apxx_lincons0.hh:127
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition: apxx_linexpr0.hh:179
lincons0(ap_lincons0_t l)
Internal use only. Performs a shallow copy and takes ownership of the contents.
Definition: apxx_lincons0.hh:24
void set_linexpr(const linexpr0 &c)
Sets the underlying linear expression to c (copied).
Definition: apxx_lincons0.hh:186
void set_modulo(const scalar &c)
Sets the auxiliary scalar modulo to c (copied).
Definition: apxx_lincons0.hh:168
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition: apxx_abstract0.hh:293
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition: apxx_lincons0.hh:192
lincons0_array(ap_lincons0_array_t &a)
Internal use only. Performs a shallow copy and takes ownership of the contents.
Definition: apxx_lincons0.hh:348
const ap_lincons0_t * get_ap_lincons0_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition: apxx_lincons0.hh:253
ap_lincons0_t l
Structure managed by APRON.
Definition: apxx_lincons0.hh:47
scalar & get_modulo()
Returns a (modifiable) reference to the auxiliary scalar.
Definition: apxx_lincons0.hh:156
abstract0 & add_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d, bool project=false)
Definition: apxx_abstract0_inline.hh:1037
void print(char **name_of_dim=NULL, FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_lincons0.hh:221
bool is_linear() const
Whether the underlying linear expression has only scalar coefficients.
Definition: apxx_lincons0.hh:236
~lincons0()
Frees the constraint, including the embedded linear expression and optional modulo scalar.
Definition: apxx_lincons0.hh:73
abstract0 & permute_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimperm &d)
Definition: apxx_abstract0_inline.hh:1060
bool is_quasilinear() const
Whether the underlying linear expression has only scalar coefficients, except maybe for the constant ...
Definition: apxx_lincons0.hh:242
void add_dimensions(const dimchange &d)
Changes the dimension of the underlying linear expression.
Definition: apxx_lincons0.hh:109
linexpr0 & get_linexpr()
Returns a (modifiable) reference to the underlying linear expression.
Definition: apxx_lincons0.hh:174
lincons0 & operator=(const lincons0 &x)
(Deep) copy.
Definition: apxx_lincons0.hh:82
void resize(size_t size)
Resizes the underlying linear expression.
Definition: apxx_lincons0.hh:102
coeff & operator[](ap_dim_t dim)
Returns a (modifiable) reference to the coefficient corresponding to the given dimension.
Definition: apxx_lincons0.hh:198
bool is_unsat() const
Whether the constraint is unsatisfiable.
Definition: apxx_lincons0.hh:230
std::ostream & operator<<(std::ostream &os, const lincons0 &s)
Definition: apxx_lincons0_inline.hh:207
bool has_modulo() const
Whether the constraint has a valid auxiliary scalar (used in modulo constraints).
Definition: apxx_lincons0.hh:146
void permute_dimensions(const dimperm &d)
Applies a permutation to the underlying linear expression.
Definition: apxx_lincons0.hh:115
bool has_linexpr() const
Whether the constraint has a valid linear expression.
Definition: apxx_lincons0.hh:151
ap_constyp_t & get_constyp()
Returns a (modifiable) reference to the constraint type.
Definition: apxx_lincons0.hh:136