APRONXX  0.9.12
/home/mine/apron/apronxx/apxx_tcons0_inline.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * apxx_tcons0_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 /* tcons0 */
21 /* ================================= */
22 
23 inline tcons0::tcons0(ap_tcons0_t& l) : l(l)
24 {}
25 
26 inline tcons0::tcons0(ap_constyp_t constyp)
27 {
28  l = ap_tcons0_make(constyp, NULL, NULL);
29 }
30 
31 inline tcons0::tcons0(ap_constyp_t constyp, const texpr0::builder& t, const scalar& modulo)
32 {
33  ap_texpr0_t* lt = ap_texpr0_copy(const_cast<ap_texpr0_t*>(t.get_ap_texpr0_t()));
34  ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(modulo.get_ap_scalar_t()));
35  l = ap_tcons0_make(constyp, lt, mmodulo);
36 }
37 
38 inline tcons0::tcons0(ap_constyp_t constyp, const texpr0::builder& t)
39 {
40  ap_texpr0_t* lt = ap_texpr0_copy(const_cast<ap_texpr0_t*>(t.get_ap_texpr0_t()));
41  l = ap_tcons0_make(constyp, lt, NULL);
42 }
43 
44 inline tcons0::tcons0(const tcons0& x)
45 {
46  l = ap_tcons0_copy(const_cast<ap_tcons0_t*>(&x.l));
47 }
48 
49 inline tcons0::tcons0(unsat x)
50 {
51  l = ap_tcons0_make_unsat();
52 }
53 
54 inline tcons0::tcons0(const tcons0& x, const dimchange& d, bool add)
55 {
56  if (!x.l.texpr0) throw std::invalid_argument("apron::tcons0::tcons0(const tcons0&, const dimchange&, bool) empty expression");
57  if (add)
58  l = ap_tcons0_add_dimensions(const_cast<ap_tcons0_t*>(&x.l),
59  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
60  else
61  l = ap_tcons0_remove_dimensions(const_cast<ap_tcons0_t*>(&x.l),
62  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
63 }
64 
65 inline tcons0::tcons0(const tcons0& x, const dimperm& d)
66 {
67  if (!x.l.texpr0) throw std::invalid_argument("apron::tcons0::tcons0(const tcons0&, const dimperm&) empty expression");
68  l = ap_tcons0_permute_dimensions(const_cast<ap_tcons0_t*>(&x.l),
69  const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
70 }
71 
72 inline tcons0::tcons0(const lincons0& x)
73 {
74  l = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x.get_ap_lincons0_t()));
75 }
76 
77 
78 /* destructor */
79 /* ========== */
80 
81 inline tcons0::~tcons0()
82 {
83  ap_tcons0_clear(const_cast<ap_tcons0_t*>(&l));
84 }
85 
86 
87 /* 'Intelligent' constructors */
88 /* ========================== */
89 
90 inline tcons0 operator>=(const texpr0::builder& a, const texpr0::builder& b)
91 {
92  if (b.is_zero()) return tcons0(AP_CONS_SUPEQ,a);
93  else if (a.is_zero()) return tcons0(AP_CONS_SUPEQ,-b);
94  else return tcons0(AP_CONS_SUPEQ,a-b);
95 }
96 
97 inline tcons0 operator<=(const texpr0::builder& a, const texpr0::builder& b)
98 {
99  if (b.is_zero()) return tcons0(AP_CONS_SUPEQ,-a);
100  else if (a.is_zero()) return tcons0(AP_CONS_SUPEQ,b);
101  else return tcons0(AP_CONS_SUPEQ,b-a);
102 }
103 
104 inline tcons0 operator> (const texpr0::builder& a, const texpr0::builder& b)
105 {
106  if (b.is_zero()) return tcons0(AP_CONS_SUP,a);
107  else if (a.is_zero()) return tcons0(AP_CONS_SUP,-b);
108  else return tcons0(AP_CONS_SUP,a-b);
109 }
110 
111 inline tcons0 operator< (const texpr0::builder& a, const texpr0::builder& b)
112 {
113  if (b.is_zero()) return tcons0(AP_CONS_SUP,-a);
114  else if (a.is_zero()) return tcons0(AP_CONS_SUP,b);
115  else return tcons0(AP_CONS_SUP,b-a);
116 }
117 
118 inline tcons0 operator==(const texpr0::builder& a, const texpr0::builder& b)
119 {
120  if (b.is_zero()) return tcons0(AP_CONS_EQ,a);
121  else if (a.is_zero()) return tcons0(AP_CONS_EQ,b);
122  else return tcons0(AP_CONS_EQ,a-b);
123 }
124 
125 inline tcons0 operator!=(const texpr0::builder& a, const texpr0::builder& b)
126 {
127  if (b.is_zero()) return tcons0(AP_CONS_DISEQ,a);
128  else if (a.is_zero()) return tcons0(AP_CONS_DISEQ,b);
129  else return tcons0(AP_CONS_DISEQ,a-b);
130 }
131 
132 
133 /* assignment */
134 /* ========== */
135 
136 inline tcons0& tcons0::operator= (const tcons0& x)
137 {
138  if (&x!=this) {
139  ap_tcons0_clear(&l);
140  l = ap_tcons0_copy(const_cast<ap_tcons0_t*>(&x.l));
141  }
142  return *this;
143 }
144 
145 inline tcons0& tcons0::operator= (unsat x)
146 {
147  ap_tcons0_clear(&l);
148  l = ap_tcons0_make_unsat();
149  return *this;
150 }
151 
152 inline tcons0& tcons0::operator= (const lincons0& x)
153 {
154  ap_tcons0_clear(&l);
155  l = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x.get_ap_lincons0_t()));
156  return *this;
157 }
158 
159 
160 /* dimension operations */
161 /* ==================== */
162 
163 inline void tcons0::add_dimensions(const dimchange& d)
164 {
165  if (!l.texpr0) throw std::invalid_argument("apron::tcons0::add_dimensions(const dimchange&) empty expression");
166  ap_tcons0_add_dimensions_with(&l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
167 }
168 
169 inline void tcons0::remove_dimensions(const dimchange& d)
170 {
171  if (!l.texpr0) throw std::invalid_argument("apron::tcons0::remove_dimensions(const dimchange&) empty expression");
172  ap_tcons0_remove_dimensions_with(&l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
173 }
174 
175 inline void tcons0::permute_dimensions(const dimperm& d)
176 {
177  if (!l.texpr0) throw std::invalid_argument("apron::tcons0::permute_dimensions(dimperm&) empty expression");
178  ap_tcons0_permute_dimensions_with(&l, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
179 }
180 
181 
182 /* access */
183 /* ====== */
184 
185 /* get */
186 
187 inline ap_constyp_t& tcons0::get_constyp()
188 {
189  return l.constyp;
190 }
191 
192 inline const ap_constyp_t& tcons0::get_constyp() const
193 {
194  return l.constyp;
195 }
196 
197 inline bool tcons0::has_modulo() const
198 {
199  return l.scalar!=NULL;
200 }
201 
202 inline bool tcons0::has_texpr() const
203 {
204  return l.texpr0!=NULL;
205 }
206 
207 inline scalar& tcons0::get_modulo()
208 {
209  if (!l.scalar) throw std::invalid_argument("apron::tcons0::get_modulo() empty scalar");
210  return reinterpret_cast<scalar&>(*l.scalar);
211 }
212 
213 inline const scalar& tcons0::get_modulo() const
214 {
215  if (!l.scalar) throw std::invalid_argument("apron::tcons0::get_modulo() empty scalar");
216  return reinterpret_cast<scalar&>(*l.scalar);
217 }
218 
219 inline void tcons0::set_modulo(const scalar& c)
220 {
221  if (!l.scalar) l.scalar = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(c.get_ap_scalar_t()));
222  else ap_scalar_set(l.scalar, const_cast<ap_scalar_t*>(c.get_ap_scalar_t()));
223 }
224 
225 inline texpr0::const_iterator tcons0::get_texpr() const
226 {
227  if (!l.texpr0)
228  throw std::invalid_argument("apron::tcons0::get_texpr() empty expression");
229  return l.texpr0;
230 }
231 
232 inline texpr0::iterator tcons0::get_texpr()
233 {
234  if (!l.texpr0) throw std::invalid_argument("apron::tcons0::get_texpr() empty expression");
235  return l.texpr0;
236 }
237 
238 inline void tcons0::set_texpr(const texpr0::builder& c)
239 {
240  ap_texpr0_t* cc = ap_texpr0_copy(const_cast<ap_texpr0_t*>(c.get_ap_texpr0_t()));
241  if (l.texpr0) ap_texpr0_free(l.texpr0);
242  l.texpr0 = cc;
243 }
244 
245 
246 /* print */
247 /* ===== */
248 
249 inline std::ostream& operator<< (std::ostream& os, const tcons0& s)
250 {
251  os << s.get_texpr();
252  switch (s.get_constyp()) {
253  case AP_CONS_EQ: return os << " = 0";
254  case AP_CONS_SUPEQ: return os << " >= 0";
255  case AP_CONS_SUP: return os << " > 0";
256  case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo();
257  case AP_CONS_DISEQ: return os << " != 0";
258  default: throw std::invalid_argument("apron::operator<<(ostream&, const tcons0&) invalid constraint type");
259  }
260 }
261 
262 inline void tcons0::print(char** name_of_dim, FILE* stream) const
263 {
264  ap_tcons0_fprint(stream, const_cast<ap_tcons0_t*>(&l), name_of_dim);
265 }
266 
267 
268 /* tests */
269 /* ===== */
270 
271 inline bool tcons0::is_interval_cst() const
272 {
273  return ap_tcons0_is_interval_cst(const_cast<ap_tcons0_t*>(&l));
274 }
275 
276 inline bool tcons0::is_interval_linear() const
277 {
278  return ap_tcons0_is_interval_linear(const_cast<ap_tcons0_t*>(&l));
279 }
280 
281 inline bool tcons0::is_interval_polynomial() const
282 {
283  return ap_tcons0_is_interval_polynomial(const_cast<ap_tcons0_t*>(&l));
284 }
285 
286 inline bool tcons0::is_interval_polyfrac() const
287 {
288  return ap_tcons0_is_interval_polyfrac(const_cast<ap_tcons0_t*>(&l));
289 }
290 
291 inline bool tcons0::is_scalar() const
292 {
293  return ap_tcons0_is_scalar(const_cast<ap_tcons0_t*>(&l));
294 }
295 
296 
297 
298 /* C-level compatibility */
299 /* ===================== */
300 
301 inline const ap_tcons0_t* tcons0::get_ap_tcons0_t() const
302 {
303  return &l;
304 }
305 
306 inline ap_tcons0_t* tcons0::get_ap_tcons0_t()
307 {
308  return &l;
309 }
310 
311 
312 /* ================================= */
313 /* tcons0_array */
314 /* ================================= */
315 
316 
317 /* constructors */
318 /* ============ */
319 
320 inline tcons0_array::tcons0_array(size_t size)
321  : a(ap_tcons0_array_make(size))
322 {
323 }
324 
325 inline tcons0_array::tcons0_array(const tcons0_array& x)
326  : a(ap_tcons0_array_make(x.a.size))
327 {
328  for (size_t i=0; i<a.size; i++)
329  a.p[i] = ap_tcons0_copy(&x.a.p[i]);
330 }
331 
332 inline tcons0_array::tcons0_array(size_t size, const tcons0 x[])
333  : a(ap_tcons0_array_make(size))
334 {
335  for (size_t i=0; i<size; i++)
336  a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
337 }
338 
339 inline tcons0_array::tcons0_array(const std::vector<tcons0>& x)
340  : a(ap_tcons0_array_make(x.size()))
341 {
342  for (size_t i=0; i<a.size; i++)
343  a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
344 }
345 
346 inline tcons0_array::tcons0_array(const tcons0_array& x, const dimchange& d, bool add)
347 {
348  if (add)
349  a = ap_tcons0_array_add_dimensions(const_cast<ap_tcons0_array_t*>(&x.a),
350  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
351  else
352  a = ap_tcons0_array_remove_dimensions(const_cast<ap_tcons0_array_t*>(&x.a),
353  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
354 }
355 
356 inline tcons0_array::tcons0_array(const tcons0_array& x, const dimperm& d)
357 {
358  a = ap_tcons0_array_permute_dimensions(const_cast<ap_tcons0_array_t*>(&x.a),
359  const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
360 }
361 
362 inline tcons0_array::tcons0_array(const lincons0_array& x)
363  : a(ap_tcons0_array_make(x.size()))
364 {
365  for (size_t i=0; i<a.size; i++)
366  a.p[i] = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
367 }
368 
369 
370 /* destructor */
371 /* ========== */
372 
373 inline tcons0_array::~tcons0_array()
374 {
375  ap_tcons0_array_clear(&a);
376 }
377 
378 
379 /* assignment */
380 /* ========== */
381 
382 inline tcons0_array& tcons0_array::operator= (const tcons0_array& x)
383 {
384  if (&x!=this) {
385  ap_tcons0_array_clear(&a);
386  a = ap_tcons0_array_make(x.a.size);
387  for (size_t i=0; i<a.size; i++) a.p[i] = ap_tcons0_copy(&x.a.p[i]);
388  }
389  return *this;
390 }
391 
392 inline tcons0_array& tcons0_array::operator= (const tcons0 x[])
393 {
394  size_t size = a.size;
395  ap_tcons0_array_clear(&a);
396  a = ap_tcons0_array_make(size);
397  for (size_t i=0; i<size; i++)
398  a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
399  return *this;
400 }
401 
402 inline tcons0_array& tcons0_array::operator= (const std::vector<tcons0>& x)
403 {
404  size_t size = x.size();
405  ap_tcons0_array_clear(&a);
406  a = ap_tcons0_array_make(size);
407  for (size_t i=0; i<size; i++)
408  a.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>(x[i].get_ap_tcons0_t()));
409  return *this;
410 }
411 
412 inline tcons0_array& tcons0_array::operator= (const lincons0_array& x)
413 {
414  size_t size = x.size();
415  ap_tcons0_array_clear(&a);
416  a = ap_tcons0_array_make(size);
417  for (size_t i=0; i<size; i++)
418  a.p[i] = ap_tcons0_from_lincons0(const_cast<ap_lincons0_t*>(x[i].get_ap_lincons0_t()));
419  return *this;
420 }
421 
422 
423 /* dimension operations */
424 /* ==================== */
425 
426 inline void tcons0_array::resize(size_t size)
427 {
428  ap_tcons0_array_resize(&a, size);
429 }
430 
431 inline void tcons0_array::add_dimensions(const dimchange& d)
432 {
433  ap_tcons0_array_add_dimensions_with(&a, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
434 }
435 
436 inline void tcons0_array::remove_dimensions(const dimchange& d)
437 {
438  ap_tcons0_array_remove_dimensions_with(&a, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
439 }
440 
441 inline void tcons0_array::permute_dimensions(const dimperm& d)
442 {
443  ap_tcons0_array_permute_dimensions_with(&a, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
444 }
445 
446 
447 /* access */
448 /* ====== */
449 
450 inline size_t tcons0_array::size() const
451 {
452  return a.size;
453 }
454 
455 inline tcons0* tcons0_array::contents()
456 {
457  return reinterpret_cast<tcons0*>(a.p);
458 }
459 
460 inline const tcons0* tcons0_array::contents() const
461 {
462  return reinterpret_cast<tcons0*>(a.p);
463 }
464 
465 inline tcons0& tcons0_array::operator[](size_t i)
466 {
467  return reinterpret_cast<tcons0&>(a.p[i]);
468 }
469 
470 inline const tcons0& tcons0_array::operator[](size_t i) const
471 {
472  return reinterpret_cast<tcons0&>(a.p[i]);
473 }
474 
475 inline tcons0& tcons0_array::get(size_t i)
476 {
477  if (i >= a.size) throw std::out_of_range("apron::tcons0_array::get()");
478  return reinterpret_cast<tcons0&>(a.p[i]);
479 }
480 
481 inline const tcons0& tcons0_array::get(size_t i) const
482 {
483  if (i >= a.size) throw std::out_of_range("apron::tcons0_array::get()");
484  return reinterpret_cast<tcons0&>(a.p[i]);
485 }
486 
487 
488 /* conversion */
489 /* ========== */
490 
491 inline tcons0_array::operator std::vector<tcons0>() const
492 {
493  size_t sz = size();
494  std::vector<tcons0> v = std::vector<tcons0>(sz);
495  for (size_t i=0;i<sz;i++)
496  v[i] = (*this)[i];
497  return v;
498 }
499 
500 
501 /* print */
502 /* ===== */
503 
504 inline std::ostream& operator<< (std::ostream& os, const tcons0_array& s)
505 {
506  size_t size = s.size();
507  os << "{ ";
508  for (size_t i=0;i<size;i++)
509  os << s[i] << "; ";
510  return os << "}";
511 }
512 
513 inline void tcons0_array::print(char** name_of_dim, FILE* stream) const
514 {
515  ap_tcons0_array_fprint(stream, const_cast<ap_tcons0_array_t*>(&a), name_of_dim);
516 }
517 
518 
519 /* tests */
520 /* ===== */
521 
522 inline bool tcons0_array::is_interval_linear() const
523 {
524  return ap_tcons0_array_is_interval_linear(const_cast<ap_tcons0_array_t*>(&a));
525 }
526 
527 /* C-level compatibility */
528 /* ===================== */
529 
530 inline const ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t() const
531 {
532  return &a;
533 }
534 
535 inline ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t()
536 {
537  return &a;
538 }
void permute_dimensions(const dimperm &d)
Applies a permutation to the underlying expression tree.
Definition: apxx_tcons0.hh:176
void remove_dimensions(const dimchange &d)
Removes dimensions to the underlying expression tree.
Definition: apxx_tcons0.hh:170
std::ostream & operator<<(std::ostream &os, const tcons0 &s)
Definition: apxx_tcons0_inline.hh:249
~tcons0()
Frees the constraint, including the embedded expression tree and optional modulo scalar.
Definition: apxx_tcons0.hh:82
void set_modulo(const scalar &c)
Sets the extra scalar modulo to c (copied).
Definition: apxx_tcons0.hh:220
abstract0 & remove_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d)
Definition: apxx_abstract0_inline.hh:1049
bool has_texpr() const
Whether the constraint contains a valid expression tree.
Definition: apxx_tcons0.hh:203
tcons0_array(ap_tcons0_array_t &a)
Internal use only. Performs a shallow copy and takes ownership of the contents.
Definition: apxx_tcons0.hh:357
texpr0::iterator get_texpr()
Returns an iterator to the root of the underlying expression tree.
Definition: apxx_tcons0.hh:233
texpr0::builder add(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:772
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition: apxx_abstract0.hh:293
bool is_interval_polyfrac() const
Whether the expression is a polynomial fraction and there is no rounding.
Definition: apxx_tcons0.hh:287
bool is_interval_linear() const
Whether the expression is linear and there is no rounding.
Definition: apxx_tcons0.hh:277
bool is_interval_polynomial() const
Whether the expression is polynomial and there is no rounding.
Definition: apxx_tcons0.hh:282
bool is_scalar() const
Whether all occurring constants are scalar.
Definition: apxx_tcons0.hh:292
abstract0 & add_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d, bool project=false)
Definition: apxx_abstract0_inline.hh:1037
bool is_interval_cst() const
Whether the expression is constant (i.e., has no dimension leaves).
Definition: apxx_tcons0.hh:272
bool operator==(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:410
tcons0(ap_tcons0_t &l)
Internal use only. Performs a shallow copy and takes ownership of the contents.
Definition: apxx_tcons0.hh:24
ap_constyp_t & get_constyp()
Returns a (modifiable) reference to the constraint type.
Definition: apxx_tcons0.hh:188
void set_texpr(const texpr0::builder &c)
Sets the underlying expression tree to c (copied).
Definition: apxx_tcons0.hh:239
bool operator>(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:434
tcons0 & operator=(const tcons0 &x)
(Deep) copy.
Definition: apxx_tcons0.hh:137
abstract0 & permute_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimperm &d)
Definition: apxx_abstract0_inline.hh:1060
bool operator>=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:429
bool operator!=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:417
void add_dimensions(const dimchange &d)
Adds dimensions to the underlying expression tree.
Definition: apxx_tcons0.hh:164
const ap_tcons0_t * get_ap_tcons0_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition: apxx_tcons0.hh:302
ap_tcons0_t l
Structure managed by APRON.
Definition: apxx_tcons0.hh:51
scalar & get_modulo()
Returns a (modifiable) reference to the extra scalar.
Definition: apxx_tcons0.hh:208
bool operator<=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:422
void print(char **name_of_dim=NULL, FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_tcons0.hh:263
bool has_modulo() const
Returns whether the constraint has a valid extra scalar (used in modulo constraints).
Definition: apxx_tcons0.hh:198
bool operator<(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:439