APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_tcons1_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_tcons1_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/* ================================= */
21/* tcons1 */
22/* ================================= */
23
24
25/* constructors */
26/* ============ */
27
28inline tcons1::tcons1(ap_tcons1_t l) : l(l)
29{}
30
31inline tcons1::tcons1(const environment& env, ap_constyp_t constyp)
32{
33 l.tcons0 = ap_tcons0_make(constyp, NULL, NULL);
34 l.env = ap_environment_copy(const_cast<ap_environment_t*>(env.get_ap_environment_t()));
35}
36
37inline tcons1::tcons1(ap_constyp_t constyp, const texpr1::builder& t)
38{
39 ap_texpr1_t* x = ap_texpr1_copy(const_cast<ap_texpr1_t*>(t.get_ap_texpr1_t()));
40 l = ap_tcons1_make(constyp, x, NULL);
41 free(x);
42}
43
44inline tcons1::tcons1(ap_constyp_t constyp, const texpr1::builder& t, const scalar& modulo)
45{
46 ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(modulo.get_ap_scalar_t()));
47 ap_texpr1_t* x = ap_texpr1_copy(const_cast<ap_texpr1_t*>(t.get_ap_texpr1_t()));
48 l = ap_tcons1_make(constyp, x, mmodulo);
49 free(x);
50}
51
52inline tcons1::tcons1(const tcons1& x)
53 : l(ap_tcons1_copy(const_cast<ap_tcons1_t*>(&x.l)))
54{}
55
56inline tcons1::tcons1(const tcons1& x, const environment& e)
57{
58 if (!x.l.tcons0.texpr0)
59 throw std::invalid_argument("apron::tcons1::tcons1(const tcons1&, const enviroment&) empty expression");
60 bool r =
61 ap_tcons1_extend_environment(&l,
62 const_cast<ap_tcons1_t*>(&x.l),
63 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
64 if (r)
65 throw std::invalid_argument("apron::tcons1::tcons1(const tcons1&, const enviroment&) not a super-environment");
66}
67
68inline tcons1::tcons1(const environment& e, unsat x)
69{
70 l.tcons0 = ap_tcons0_make_unsat();
71 l.env = ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t()));
72}
73
74inline tcons1::tcons1(const lincons1& x)
75 : l(ap_tcons1_from_lincons1(const_cast<ap_lincons1_t*>(x.get_ap_lincons1_t())))
76{}
77
78
79/* destructor */
80/* ========== */
81
82inline tcons1::~tcons1()
83{
84 ap_tcons1_clear(&l);
85}
86
87
88/* 'Intelligent' constructors */
89/* ========================== */
90
91inline tcons1 operator>=(const texpr1::builder& a, const texpr1::builder& b)
92{
93 if (b.is_zero()) return tcons1(AP_CONS_SUPEQ,a);
94 else if (a.is_zero()) return tcons1(AP_CONS_SUPEQ,-b);
95 else return tcons1(AP_CONS_SUPEQ,a-b);
96}
97
98inline tcons1 operator<=(const texpr1::builder& a, const texpr1::builder& b)
99{
100 if (b.is_zero()) return tcons1(AP_CONS_SUPEQ,-a);
101 else if (a.is_zero()) return tcons1(AP_CONS_SUPEQ,b);
102 else return tcons1(AP_CONS_SUPEQ,b-a);
103}
104
105inline tcons1 operator> (const texpr1::builder& a, const texpr1::builder& b)
106{
107 if (b.is_zero()) return tcons1(AP_CONS_SUP,a);
108 else if (a.is_zero()) return tcons1(AP_CONS_SUP,-b);
109 else return tcons1(AP_CONS_SUP,a-b);
110}
111
112inline tcons1 operator< (const texpr1::builder& a, const texpr1::builder& b)
113{
114 if (b.is_zero()) return tcons1(AP_CONS_SUP,-a);
115 else if (a.is_zero()) return tcons1(AP_CONS_SUP,b);
116 else return tcons1(AP_CONS_SUP,b-a);
117}
118
119inline tcons1 operator==(const texpr1::builder& a, const texpr1::builder& b)
120{
121 if (b.is_zero()) return tcons1(AP_CONS_EQ,a);
122 else if (a.is_zero()) return tcons1(AP_CONS_EQ,b);
123 else return tcons1(AP_CONS_EQ,a-b);
124}
125
126inline tcons1 operator!=(const texpr1::builder& a, const texpr1::builder& b)
127{
128 if (b.is_zero()) return tcons1(AP_CONS_DISEQ,a);
129 else if (a.is_zero()) return tcons1(AP_CONS_DISEQ,b);
130 else return tcons1(AP_CONS_DISEQ,a-b);
131}
132
133
134/* assignment */
135/* ========== */
136
137inline tcons1& tcons1::operator= (const tcons1& x)
138{
139 if (&x!=this) {
140 ap_tcons1_clear(&l);
141 l = ap_tcons1_copy(const_cast<ap_tcons1_t*>(&x.l));
142 }
143 return *this;
144}
145
146inline tcons1& tcons1::operator= (unsat x)
147{
148 ap_tcons0_clear(&l.tcons0);
149 l.tcons0 = ap_tcons0_make_unsat();
150 return *this;
151}
152
153inline tcons1& tcons1::operator= (const lincons1& x)
154{
155 ap_tcons1_clear(&l);
156 l = ap_tcons1_from_lincons1(const_cast<ap_lincons1_t*>(x.get_ap_lincons1_t()));
157 return *this;
158}
159
160inline void tcons1::set_modulo(const scalar& c)
161{
162 get_tcons0().set_modulo(c);
163}
164
165inline void tcons1::set_texpr(const texpr1::builder& c)
166{
167 ap_texpr1_t* cc = ap_texpr1_copy(const_cast<ap_texpr1_t*>(c.get_ap_texpr1_t()));
168 if (l.tcons0.texpr0) ap_texpr0_free(l.tcons0.texpr0);
169 ap_environment_free(l.env);
170 l.tcons0.texpr0 = cc->texpr0;
171 l.env = cc->env;
172 free(cc);
173}
174
175
176/* dimension operations */
177/* ==================== */
178
179inline void tcons1::extend_environment(const environment& e)
180{
181 bool r =
182 ap_tcons1_extend_environment_with(&l,
183 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
184 if (r)
185 throw std::invalid_argument("apron::tcons1::extend_environment(const environment&) not a super-environment");
186}
187
188
189/* access */
190/* ====== */
191
192inline environment tcons1::get_environment() const
193{
194 return ap_environment_copy(l.env);
195}
196
197inline const tcons0& tcons1::get_tcons0() const
198{
199 return reinterpret_cast<const tcons0&>(l.tcons0);
200}
201
202inline tcons0& tcons1::get_tcons0()
203{
204 return reinterpret_cast<tcons0&>(l.tcons0);
205}
206
207inline ap_constyp_t& tcons1::get_constyp()
208{
209 return get_tcons0().get_constyp();
210}
211
212inline const ap_constyp_t& tcons1::get_constyp() const
213{
214 return get_tcons0().get_constyp();
215}
216
217inline bool tcons1::has_modulo() const
218{
219 return get_tcons0().has_modulo();
220}
221
222inline bool tcons1::has_texpr() const
223{
224 return get_tcons0().has_texpr();
225}
226
227inline scalar& tcons1::get_modulo()
228{
229 if (!get_tcons0().has_modulo()) throw std::invalid_argument("apron::tcons1::get_modulo() empty scalar");
230 return get_tcons0().get_modulo();
231}
232
233inline const scalar& tcons1::get_modulo() const
234{
235 if (!get_tcons0().has_modulo()) throw std::invalid_argument("apron::tcons1::get_modulo() empty scalar");
236 return get_tcons0().get_modulo();
237}
238
239inline texpr1::iterator tcons1::get_texpr()
240{
241 if (!l.tcons0.texpr0) throw std::invalid_argument("apron::tcons1::get_texpr() empty expression");
242 return texpr1::iterator(l.tcons0.texpr0,l.env);
243}
244
245inline texpr1::const_iterator tcons1::get_texpr() const
246{
247 if (!l.tcons0.texpr0) throw std::invalid_argument("apron::tcons1::get_texpr() empty expression");
248 return texpr1::const_iterator(l.tcons0.texpr0,l.env);
249}
250
251
252
253/* print */
254/* ===== */
255
256inline std::ostream& operator<< (std::ostream& os, const tcons1& s)
257{
258 os << s.get_texpr();
259 switch (s.get_constyp()) {
260 case AP_CONS_EQ: return os << " = 0";
261 case AP_CONS_SUPEQ: return os << " >= 0";
262 case AP_CONS_SUP: return os << " > 0";
263 case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo();
264 case AP_CONS_DISEQ: return os << " != 0";
265 default: throw std::invalid_argument("apron::operator<<(ostream&, const tcons1&) invalid constraint type");
266 }
267}
268
269inline void tcons1::print(FILE* stream) const
270{
271 ap_tcons1_fprint(stream, const_cast<ap_tcons1_t*>(&l));
272}
273
274
275/* tests */
276/* ===== */
277
278inline bool tcons1::is_interval_cst() const
279{
280 return get_texpr().is_interval_cst();
281}
282
283inline bool tcons1::is_interval_linear() const
284{
285 return get_texpr().is_interval_linear();
286}
287
288inline bool tcons1::is_interval_polynomial() const
289{
290 return get_texpr().is_interval_polynomial();
291}
292
293inline bool tcons1::is_interval_polyfrac() const
294{
295 return get_texpr().is_interval_polyfrac();
296}
297
298inline bool tcons1::is_scalar() const
299{
300 return get_texpr().is_scalar();
301}
302
303
304/* C-level compatibility */
305/* ===================== */
306
307inline const ap_tcons1_t* tcons1::get_ap_tcons1_t() const
308{
309 return &l;
310}
311
312inline ap_tcons1_t* tcons1::get_ap_tcons1_t()
313{
314 return &l;
315}
316
317
318
319
320
321/* ================================= */
322/* tcons1_array */
323/* ================================= */
324
325
326
327/* constructors */
328/* ============ */
329
330inline tcons1_array::tcons1_array(ap_tcons1_array_t& a) : a(a)
331{}
332
333inline tcons1_array::tcons1_array(const environment& e, const tcons0_array& x)
334{
335 size_t sz = x.size();
336 a = ap_tcons1_array_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), sz);
337 for (size_t i=0; i<sz; i++)
338 a.tcons0_array.p[i] = ap_tcons0_copy(&x.a.p[i]);
339}
340
341inline tcons1_array::tcons1_array(const environment& e, size_t size)
342{
343 a = ap_tcons1_array_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), size);
344}
345
346inline tcons1_array::tcons1_array(const tcons1_array& x)
347{
348 size_t sz = x.size();
349 a = ap_tcons1_array_make(x.get_environment().get_ap_environment_t(), sz);
350 for (size_t i=0; i<sz; i++)
351 a.tcons0_array.p[i] = ap_tcons0_copy(&x.a.tcons0_array.p[i]);
352}
353
354inline tcons1_array::tcons1_array(const tcons1_array& x, const environment& e)
355{
356 bool r =
357 ap_tcons1_array_extend_environment(&a,
358 const_cast<ap_tcons1_array_t*>(&x.a),
359 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
360 if (r) throw std::invalid_argument("apron::tcons1_array::tcons1_array(const tcons1_array, const environment&) not a super-environment");
361}
362
363inline tcons1_array::tcons1_array(size_t sz, const tcons1 x[])
364{
365 if (sz<1) throw std::invalid_argument("apron::tcons1_array::tcons1_array(size_t, const tcons1) null size");
366 a = ap_tcons1_array_make(x[0].get_environment().get_ap_environment_t(), sz);
367 for (size_t i=0; i<sz; i++)
368 a.tcons0_array.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>
369 (x[i].get_tcons0().get_ap_tcons0_t()));
370}
371
372inline tcons1_array::tcons1_array(const std::vector<tcons1>& x)
373{
374 size_t sz = x.size();
375 if (sz<1) throw std::invalid_argument("apron::tcons1_array::tcons1_array(const vector<tcons1>&) null size");
376 a = ap_tcons1_array_make(x[0].get_environment().get_ap_environment_t(), sz);
377 for (size_t i=0; i<sz; i++)
378 a.tcons0_array.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>
379 (x[i].get_tcons0().get_ap_tcons0_t()));
380}
381
382
383/* destructor */
384/* ========== */
385
386inline tcons1_array::~tcons1_array()
387{
388 ap_tcons1_array_clear(&a);
389}
390
391
392/* assignment */
393/* ========== */
394
395inline tcons1_array& tcons1_array::operator= (const tcons1_array& x)
396{
397 if (this!=&x) {
398 size_t sz = x.size();
399 ap_tcons1_array_clear(&a);
400 a = ap_tcons1_array_make(x.get_environment().get_ap_environment_t(), sz);
401 for (size_t i=0; i<sz; i++)
402 a.tcons0_array.p[i] = ap_tcons0_copy(&x.a.tcons0_array.p[i]);
403 }
404 return *this;
405}
406
407inline tcons1_array& tcons1_array::operator= (const tcons1 x[])
408{
409 size_t sz = size();
410 for (size_t i=0; i<sz; i++) {
411 ap_tcons0_clear(&a.tcons0_array.p[i]);
412 a.tcons0_array.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>
413 (x[i].get_tcons0().get_ap_tcons0_t()));
414 }
415 return *this;
416}
417
418inline tcons1_array& tcons1_array::operator= (const std::vector<tcons1>& x)
419{
420 size_t size = x.size();
421 if (size<1) {
422 ap_tcons1_array_t aa = ap_tcons1_array_make(a.env,0);
423 ap_tcons1_array_clear(&a);
424 a = aa;
425 return *this;
426 }
427 ap_tcons1_array_clear(&a);
428 a = ap_tcons1_array_make(x[0].get_environment().get_ap_environment_t(), size);
429 for (size_t i=0; i<size; i++)
430 a.tcons0_array.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>
431 (x[i].get_tcons0().get_ap_tcons0_t()));
432 return *this;
433}
434
435
436/* dimension operations */
437/* ==================== */
438
439inline void tcons1_array::resize(size_t size)
440{
441 ap_tcons0_array_resize(&a.tcons0_array, size);
442}
443
444inline void tcons1_array::extend_environment(const environment& e)
445{
446 bool r =
447 ap_tcons1_array_extend_environment_with(&a,
448 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
449 if (r) throw std::invalid_argument("apron::tcons1_array::extend_environment(const environment&) not a super-environment");
450}
451
452
453/* access */
454/* ====== */
455
456inline size_t tcons1_array::size() const
457{
458 return ap_tcons1_array_size(const_cast<ap_tcons1_array_t*>(&a));
459}
460
461inline environment tcons1_array::get_environment() const
462{
463 return (ap_environment_copy(ap_tcons1_array_envref(const_cast<ap_tcons1_array_t*>(&a))));
464}
465
466inline const tcons0_array& tcons1_array::get_tcons0_array() const
467{
468 return reinterpret_cast<tcons0_array&>(const_cast<ap_tcons0_array_t&>(a.tcons0_array));
469}
470
471inline tcons0_array& tcons1_array::get_tcons0_array()
472{
473 return reinterpret_cast<tcons0_array&>(a.tcons0_array);
474}
475
476inline tcons1 tcons1_array::get(size_t i) const
477{
478 if (i>=size()) throw std::out_of_range("apron::tcons1_array::get(size_t)");
479 ap_tcons1_t c = ap_tcons1_array_get(const_cast<ap_tcons1_array_t*>(&a),i);
480 ap_tcons1_t cc = ap_tcons1_copy(&c);
481 return tcons1(cc);
482}
483
484inline void tcons1_array::set(size_t i, const tcons1& x)
485{
486 if (i>=size()) throw std::out_of_range("apron::tcons1_array::set(size_t, const tcons1&)");
487 ap_tcons0_clear(&a.tcons0_array.p[i]);
488 a.tcons0_array.p[i] = ap_tcons0_copy(const_cast<ap_tcons0_t*>
489 (x.get_tcons0().get_ap_tcons0_t()));
490}
491
492
493/* conversion */
494/* ========== */
495
496inline tcons1_array::operator std::vector<tcons1>() const
497{
498 size_t sz = size();
499 tcons1 dummy(get_environment(),unsat());
500 std::vector<tcons1> v(sz,dummy);
501 for (size_t i=0;i<sz;i++) {
502 ap_tcons1_t c = ap_tcons1_array_get(const_cast<ap_tcons1_array_t*>(&a),i);
503 v[i] = ap_tcons1_copy(&c);
504 }
505 return v;
506}
507
508
509/* print */
510/* ===== */
511
512inline std::ostream& operator<< (std::ostream& os, const tcons1_array& s)
513{
514 size_t sz = s.size();
515 os << "{ ";
516 for (size_t i=0;i<sz;i++)
517 os << s.get(i) << "; ";
518 return os << "}";
519}
520
521inline void tcons1_array:: print(FILE* stream) const
522{
523 ap_tcons1_array_fprint(stream, const_cast<ap_tcons1_array_t*>(&a));
524}
525
526
527/* C-level compatibility */
528/* ===================== */
529
530inline const ap_tcons1_array_t* tcons1_array::get_ap_tcons1_array_t() const
531{
532 return &a;
533}
534
535inline ap_tcons1_array_t* tcons1_array::get_ap_tcons1_array_t()
536{
537 return &a;
538}
539
tcons1 operator!=(const texpr1::builder &a, const texpr1::builder &b)
Definition apxx_tcons1_inline.hh:126
tcons1 operator>(const texpr1::builder &a, const texpr1::builder &b)
Definition apxx_tcons1_inline.hh:105
tcons1 operator>=(const texpr1::builder &a, const texpr1::builder &b)
Definition apxx_tcons1_inline.hh:91
std::ostream & operator<<(std::ostream &os, const tcons1 &s)
Definition apxx_tcons1_inline.hh:256
tcons1 operator<(const texpr1::builder &a, const texpr1::builder &b)
Definition apxx_tcons1_inline.hh:112
tcons1 operator<=(const texpr1::builder &a, const texpr1::builder &b)
Definition apxx_tcons1_inline.hh:98
tcons1 operator==(const texpr1::builder &a, const texpr1::builder &b)
Definition apxx_tcons1_inline.hh:119