APRONXX 0.9.15
/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
23inline tcons0::tcons0(ap_tcons0_t& l) : l(l)
24{}
25
26inline tcons0::tcons0(ap_constyp_t constyp)
27{
28 l = ap_tcons0_make(constyp, NULL, NULL);
29}
30
31inline 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
38inline 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
44inline tcons0::tcons0(const tcons0& x)
45{
46 l = ap_tcons0_copy(const_cast<ap_tcons0_t*>(&x.l));
47}
48
49inline tcons0::tcons0(unsat x)
50{
51 l = ap_tcons0_make_unsat();
52}
53
54inline 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
65inline 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
72inline 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
81inline tcons0::~tcons0()
82{
83 ap_tcons0_clear(const_cast<ap_tcons0_t*>(&l));
84}
85
86
87/* 'Intelligent' constructors */
88/* ========================== */
89
90inline 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
97inline 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
104inline 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
111inline 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
118inline 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
125inline 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
136inline 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
145inline tcons0& tcons0::operator= (unsat x)
146{
147 ap_tcons0_clear(&l);
148 l = ap_tcons0_make_unsat();
149 return *this;
150}
151
152inline 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
163inline 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
169inline 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
175inline 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
187inline ap_constyp_t& tcons0::get_constyp()
188{
189 return l.constyp;
190}
191
192inline const ap_constyp_t& tcons0::get_constyp() const
193{
194 return l.constyp;
195}
196
197inline bool tcons0::has_modulo() const
198{
199 return l.scalar!=NULL;
200}
201
202inline bool tcons0::has_texpr() const
203{
204 return l.texpr0!=NULL;
205}
206
207inline 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
213inline 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
219inline 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
225inline 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
232inline 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
238inline 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
249inline 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
262inline 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
271inline bool tcons0::is_interval_cst() const
272{
273 return ap_tcons0_is_interval_cst(const_cast<ap_tcons0_t*>(&l));
274}
275
276inline bool tcons0::is_interval_linear() const
277{
278 return ap_tcons0_is_interval_linear(const_cast<ap_tcons0_t*>(&l));
279}
280
281inline bool tcons0::is_interval_polynomial() const
282{
283 return ap_tcons0_is_interval_polynomial(const_cast<ap_tcons0_t*>(&l));
284}
285
286inline bool tcons0::is_interval_polyfrac() const
287{
288 return ap_tcons0_is_interval_polyfrac(const_cast<ap_tcons0_t*>(&l));
289}
290
291inline 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
301inline const ap_tcons0_t* tcons0::get_ap_tcons0_t() const
302{
303 return &l;
304}
305
306inline 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
320inline tcons0_array::tcons0_array(size_t size)
321 : a(ap_tcons0_array_make(size))
322{
323}
324
325inline 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
332inline 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
339inline 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
346inline 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
356inline 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
362inline 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
373inline tcons0_array::~tcons0_array()
374{
375 ap_tcons0_array_clear(&a);
376}
377
378
379/* assignment */
380/* ========== */
381
382inline 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
392inline 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
402inline 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
412inline 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
426inline void tcons0_array::resize(size_t size)
427{
428 ap_tcons0_array_resize(&a, size);
429}
430
431inline 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
436inline 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
441inline 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
450inline size_t tcons0_array::size() const
451{
452 return a.size;
453}
454
455inline tcons0* tcons0_array::contents()
456{
457 return reinterpret_cast<tcons0*>(a.p);
458}
459
460inline const tcons0* tcons0_array::contents() const
461{
462 return reinterpret_cast<tcons0*>(a.p);
463}
464
465inline tcons0& tcons0_array::operator[](size_t i)
466{
467 return reinterpret_cast<tcons0&>(a.p[i]);
468}
469
470inline const tcons0& tcons0_array::operator[](size_t i) const
471{
472 return reinterpret_cast<tcons0&>(a.p[i]);
473}
474
475inline 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
481inline 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
491inline 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
504inline 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
513inline 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
522inline 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
530inline const ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t() const
531{
532 return &a;
533}
534
535inline ap_tcons0_array_t* tcons0_array::get_ap_tcons0_array_t()
536{
537 return &a;
538}
tcons0 operator!=(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_tcons0_inline.hh:125
tcons0 operator>(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_tcons0_inline.hh:104
tcons0 operator<=(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_tcons0_inline.hh:97
tcons0 operator>=(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_tcons0_inline.hh:90
tcons0 operator<(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_tcons0_inline.hh:111
tcons0 operator==(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_tcons0_inline.hh:118
std::ostream & operator<<(std::ostream &os, const tcons0 &s)
Definition apxx_tcons0_inline.hh:249
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_inline.hh:771