APRONXX 0.9.14
/builddir/build/BUILD/apron-0.9.15-build/apron-0.9.15/apronxx/apxx_lincons1_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_lincons1_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/* lincons1 */
21/* ================================= */
22
23
24/* constructors */
25/* ============ */
26
27inline lincons1::lincons1(ap_lincons1_t p) : l(p)
28{}
29
30inline lincons1::lincons1(const environment& e, const lincons0& x)
31{
32 l = ap_lincons1_of_lincons0(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
33 ap_lincons0_copy(const_cast<ap_lincons0_t*>(x.get_ap_lincons0_t())));
34}
35
36inline lincons1::lincons1(const environment& e, ap_constyp_t constyp)
37{
38 ap_linexpr1_t llin =
39 ap_linexpr1_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), AP_LINEXPR_SPARSE, 0);
40 l = ap_lincons1_make(constyp, &llin, NULL);
41}
42
43inline lincons1::lincons1(ap_constyp_t constyp, const linexpr1& lin)
44{
45 ap_linexpr1_t llin = ap_linexpr1_copy(const_cast<ap_linexpr1_t*>(lin.get_ap_linexpr1_t()));
46 l = ap_lincons1_make(constyp, &llin, NULL);
47}
48
49inline lincons1::lincons1(ap_constyp_t constyp, const linexpr1& lin, const scalar& modulo)
50{
51 ap_linexpr1_t llin = ap_linexpr1_copy(const_cast<ap_linexpr1_t*>(lin.get_ap_linexpr1_t()));
52 ap_scalar_t* mmodulo = ap_scalar_alloc_set(const_cast<ap_scalar_t*>(modulo.get_ap_scalar_t()));
53 l = ap_lincons1_make(constyp, &llin, mmodulo);
54}
55
57{
58 l = ap_lincons1_make_unsat(const_cast<ap_environment_t*>(e.get_ap_environment_t()));
59}
60
62{
63 l = ap_lincons1_copy(const_cast<ap_lincons1_t*>(&x.l));
64}
65
66inline lincons1::lincons1(const lincons1& x, const environment& e)
67{
68 if (!x.has_linexpr())
69 throw std::invalid_argument("apron::lincons1::lincons1(const lincons1&, const environment&) empty expression");
70 bool r =
71 ap_lincons1_extend_environment(&l,
72 const_cast<ap_lincons1_t*>(&x.l),
73 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
74 if (r) throw std::invalid_argument("apron::lincons1::lincons1(const lincons1&, const environment&) not a super-environment");
75}
76
77
78/* destructor */
79/* ========== */
80
82{
83 ap_lincons1_clear(&l);
84}
85
86
87/* assignment */
88/* ========== */
89
91{
92 ap_lincons1_t ll = ap_lincons1_copy(const_cast<ap_lincons1_t*>(&x.l));
93 ap_lincons1_clear(&l);
94 l = ll;
95 return *this;
96}
97
99{
100 ap_lincons1_t ll = ap_lincons1_make_unsat(ap_lincons1_envref(&l));
101 ap_lincons1_clear(&l);
102 l = ll;
103 return *this;
104}
105
106inline void lincons1::set_modulo(const scalar& c)
107{
109}
110
111inline void lincons1::set_linexpr(const linexpr1& c)
112{
114}
115
116
117/* dimension operations */
118/* ==================== */
119
121{
122 if (!has_linexpr())
123 throw std::invalid_argument("apron::lincons1::extend_environment(const environment&) empty expression");
124 bool r =
125 ap_lincons1_extend_environment_with(&l,
126 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
127 if (r) throw std::invalid_argument("apron::lincons1::extend_environment(const environment&) not a super-environment");
128
129}
130
131
132/* access */
133/* ====== */
134
136{
137 return (ap_environment_copy(ap_lincons1_envref(const_cast<ap_lincons1_t*>(&l))));
138}
139
140inline const lincons0& lincons1::get_lincons0() const
141{
142 return reinterpret_cast<lincons0&>(*ap_lincons1_lincons0ref(const_cast<ap_lincons1_t*>(&l)));
143}
144
146{
147 return reinterpret_cast<lincons0&>(*ap_lincons1_lincons0ref(&l));
148}
149
150inline size_t lincons1::size() const
151{
152 return get_lincons0().size();
153}
154
155inline ap_constyp_t& lincons1::get_constyp()
156{
157 return get_lincons0().get_constyp();
158}
159
160inline const ap_constyp_t& lincons1::get_constyp() const
161{
162 return get_lincons0().get_constyp();
163}
164
165inline bool lincons1::has_modulo() const
166{
167 return get_lincons0().has_modulo();
168}
169
170inline bool lincons1::has_linexpr() const
171{
172 return get_lincons0().has_linexpr();
173}
174
176{
177 if (!has_modulo())
178 throw std::invalid_argument("apron::lincons1::get_modulo() empty scalar");
179 return get_lincons0().get_modulo();
180}
181
182inline const scalar& lincons1::get_modulo() const
183{
184 if (!has_modulo())
185 throw std::invalid_argument("apron::lincons1::get_modulo() empty scalar");
186 return get_lincons0().get_modulo();
187}
188
190{
191 if (!has_linexpr())
192 throw std::invalid_argument("apron::lincons1::get_linexpr() empty expression");
194 return linexpr1(get_environment(),ll);
195}
196
198{
199 if (!has_linexpr())
200 throw std::invalid_argument("apron::lincons1::get_cst() empty expression");
201 return reinterpret_cast<coeff&>(*ap_lincons1_cstref(&l));
202}
203
204inline const coeff& lincons1::get_cst() const
205{
206 if (!has_linexpr())
207 throw std::invalid_argument("apron::lincons1::get_cst() empty expression");
208 return reinterpret_cast<coeff&>(*ap_lincons1_cstref(const_cast<ap_lincons1_t*>(&l)));
209}
210
211inline coeff& lincons1::operator[](const var& var)
212{
213 if (!has_linexpr())
214 throw std::invalid_argument("apron::lincons1::operator[](const var&) empty expression");
215 ap_coeff_t* x = ap_lincons1_coeffref(&l,
216 const_cast<ap_var_t>(var.get_ap_var_t()));
217 if (!x)
218 throw std::invalid_argument("apron::lincons1::operator[](const var&) variable not in environment");
219 return reinterpret_cast<coeff&>(*x);
220}
221
222inline const coeff& lincons1::operator[](const var& var) const
223{
224 if (!has_linexpr())
225 throw std::invalid_argument("apron::lincons1::operator[](const var&) empty expression");
226 ap_coeff_t* x = ap_lincons1_coeffref(const_cast<ap_lincons1_t*>(&l),
227 const_cast<ap_var_t>(var.get_ap_var_t()));
228 if (!x)
229 throw std::invalid_argument("apron::lincons1::operator[](const var&) variable not in environment");
230 return reinterpret_cast<coeff&>(*x);
231}
232
233
234/* print */
235/* ===== */
236
237inline std::ostream& operator<< (std::ostream& os, const lincons1& s)
238{
239 os << s.get_linexpr();
240 switch (s.get_constyp()) {
241 case AP_CONS_EQ: return os << " = 0";
242 case AP_CONS_SUPEQ: return os << " >= 0";
243 case AP_CONS_SUP: return os << " > 0";
244 case AP_CONS_EQMOD: return os << " = 0 mod " << s.get_modulo();
245 case AP_CONS_DISEQ: return os << " != 0";
246 default: throw std::invalid_argument("apron::operator<<(ostream&, const lincons1&) invalid constraint type");
247 }
248}
249
250inline void lincons1::print(FILE* stream) const
251{
252 ap_lincons1_fprint(stream, const_cast<ap_lincons1_t*>(&l));
253}
254
255
256/* tests */
257/* ===== */
258
259inline bool lincons1::is_unsat() const
260{
261 return ap_lincons1_is_unsat(const_cast<ap_lincons1_t*>(&l));
262}
263
264inline bool lincons1::is_linear() const
265{
266 return get_lincons0().is_linear();
267}
268
269inline bool lincons1::is_quasilinear() const
270{
271 return get_lincons0().is_quasilinear();
272}
273
274
275/* C-level compatibility */
276/* ===================== */
277
278inline const ap_lincons1_t* lincons1::get_ap_lincons1_t() const
279{
280 return &l;
281}
282
283inline ap_lincons1_t* lincons1::get_ap_lincons1_t()
284{
285 return &l;
286}
287
288
289
290
291/* ================================= */
292/* lincons1_array */
293/* ================================= */
294
295
296
297/* constructors */
298/* ============ */
299
300inline lincons1_array::lincons1_array(ap_lincons1_array_t& a) : a(a)
301{}
302
304{
305 size_t sz = x.size();
306 a = ap_lincons1_array_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), sz);
307 for (size_t i=0; i<sz; i++)
308 a.lincons0_array.p[i] = ap_lincons0_copy(&x.a.p[i]);
309}
310
311inline lincons1_array::lincons1_array(const environment& e, size_t size)
312{
313 a = ap_lincons1_array_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), size);
314}
315
317{
318 size_t sz = x.size();
319 a = ap_lincons1_array_make(x.get_environment().get_ap_environment_t(), sz);
320 for (size_t i=0; i<sz; i++)
321 a.lincons0_array.p[i] = ap_lincons0_copy(&x.a.lincons0_array.p[i]);
322}
323
325{
326 bool r =
327 ap_lincons1_array_extend_environment(&a,
328 const_cast<ap_lincons1_array_t*>(&x.a),
329 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
330 if (r) throw std::invalid_argument("apron::lincons1_array::lincons1_array(const lincons1_array, const environment&) not a super-environment");
331}
332
333inline lincons1_array::lincons1_array(size_t sz, const lincons1 x[])
334{
335 if (sz<1) throw std::invalid_argument("apron::lincons1_array::lincons1_array(size_t, const lincons1) null size");
336 a = ap_lincons1_array_make(x[0].get_environment().get_ap_environment_t(), sz);
337 for (size_t i=0; i<sz; i++)
338 a.lincons0_array.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>
339 (x[i].get_lincons0().get_ap_lincons0_t()));
340}
341
342inline lincons1_array::lincons1_array(const std::vector<lincons1>& x)
343{
344 size_t sz = x.size();
345 if (sz<1) throw std::invalid_argument("apron::lincons1_array::lincons1_array(const vector<lincons1>&) null size");
346 a = ap_lincons1_array_make(x[0].get_environment().get_ap_environment_t(), sz);
347 for (size_t i=0; i<sz; i++)
348 a.lincons0_array.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>
349 (x[i].get_lincons0().get_ap_lincons0_t()));
350}
351
352
353/* destructor */
354/* ========== */
355
357{
358 ap_lincons1_array_clear(&a);
359}
360
361
362/* assignment */
363/* ========== */
364
366{
367 if (this!=&x) {
368 size_t sz = x.size();
369 ap_lincons1_array_clear(&a);
370 a = ap_lincons1_array_make(x.get_environment().get_ap_environment_t(), sz);
371 for (size_t i=0; i<sz; i++)
372 a.lincons0_array.p[i] = ap_lincons0_copy(&x.a.lincons0_array.p[i]);
373 }
374 return *this;
375}
376
378{
379 size_t sz = size();
380 for (size_t i=0; i<sz; i++) {
381 ap_lincons0_clear(&a.lincons0_array.p[i]);
382 a.lincons0_array.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>
383 (x[i].get_lincons0().get_ap_lincons0_t()));
384 }
385 return *this;
386}
387
388inline lincons1_array& lincons1_array::operator= (const std::vector<lincons1>& x)
389{
390 size_t size = x.size();
391 if (size<1) {
392 ap_lincons1_array_t aa = ap_lincons1_array_make(a.env,0);
393 ap_lincons1_array_clear(&a);
394 a = aa;
395 return *this;
396 }
397 ap_lincons1_array_clear(&a);
398 a = ap_lincons1_array_make(x[0].get_environment().get_ap_environment_t(), size);
399 for (size_t i=0; i<size; i++)
400 a.lincons0_array.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>
401 (x[i].get_lincons0().get_ap_lincons0_t()));
402 return *this;
403}
404
405
406/* dimension operations */
407/* ==================== */
408
409inline void lincons1_array::resize(size_t size)
410{
411 ap_lincons0_array_resize(&a.lincons0_array, size);
412}
413
415{
416 bool r =
417 ap_lincons1_array_extend_environment_with(&a,
418 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
419 if (r) throw std::invalid_argument("apron::lincons1_array::extend_environment(const environment&) not a super-environment");
420}
421
422
423/* access */
424/* ====== */
425
426inline size_t lincons1_array::size() const
427{
428 return ap_lincons1_array_size(const_cast<ap_lincons1_array_t*>(&a));
429}
430
432{
433 return (ap_environment_copy(ap_lincons1_array_envref(const_cast<ap_lincons1_array_t*>(&a))));
434}
435
437{
438 return reinterpret_cast<lincons0_array&>(const_cast<ap_lincons0_array_t&>(a.lincons0_array));
439}
440
442{
443 return reinterpret_cast<lincons0_array&>(a.lincons0_array);
444}
445
446inline lincons1 lincons1_array::get(size_t i) const
447{
448 if (i>=size()) throw std::out_of_range("apron::lincons1_array::get(size_t)");
449 ap_lincons1_t c = ap_lincons1_array_get(const_cast<ap_lincons1_array_t*>(&a),i);
450 return lincons1(ap_lincons1_copy(&c));
451}
452
453inline void lincons1_array::set(size_t i, const lincons1& x)
454{
455 if (i>=size()) throw std::out_of_range("apron::lincons1_array::set(size_t, const lincons1&)");
456 ap_lincons0_clear(&a.lincons0_array.p[i]);
457 a.lincons0_array.p[i] = ap_lincons0_copy(const_cast<ap_lincons0_t*>
459}
460
461
462/* conversion */
463/* ========== */
464
465inline lincons1_array::operator std::vector<lincons1>() const
466{
467 size_t sz = size();
468 lincons1 dummy(get_environment(),unsat());
469 std::vector<lincons1> v(sz,dummy);
470 for (size_t i=0;i<sz;i++) {
471 ap_lincons1_t c = ap_lincons1_array_get(const_cast<ap_lincons1_array_t*>(&a),i);
472 v[i] = ap_lincons1_copy(&c);
473 }
474 return v;
475}
476
477
478/* print */
479/* ===== */
480
481inline std::ostream& operator<< (std::ostream& os, const lincons1_array& s)
482{
483 size_t sz = s.size();
484 os << "{ ";
485 for (size_t i=0;i<sz;i++)
486 os << s.get(i) << "; ";
487 return os << "}";
488}
489
490inline void lincons1_array:: print(FILE* stream) const
491{
492 ap_lincons1_array_fprint(stream, const_cast<ap_lincons1_array_t*>(&a));
493}
494
495
496/* C-level compatibility */
497/* ===================== */
498
499inline const ap_lincons1_array_t* lincons1_array::get_ap_lincons1_array_t() const
500{
501 return &a;
502}
503
504inline ap_lincons1_array_t* lincons1_array::get_ap_lincons1_array_t()
505{
506 return &a;
507}
508
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition apxx_abstract0_inline.hh:292
Coefficient (ap_coeff_t wrapper).
Definition apxx_coeff.hh:36
Level 1 environment (ap_environment_t wrapper).
Definition apxx_environment.hh:51
const ap_environment_t * get_ap_environment_t() const
Returns a pointer to the internal APRON object pointed by *this.
Definition apxx_environment_inline.hh:425
Array of linear constraints (ap_lincons0_array_t wrapper).
Definition apxx_lincons0.hh:341
size_t size() const
Returns the size of the array.
Definition apxx_lincons0_inline.hh:375
ap_lincons0_array_t a
Structure managed by APRON.
Definition apxx_lincons0.hh:345
Level 0 linear constraint (ap_lincons0_t wrapper).
Definition apxx_lincons0.hh:43
bool has_modulo() const
Whether the constraint has a valid auxiliary scalar (used in modulo constraints).
Definition apxx_lincons0_inline.hh:145
bool has_linexpr() const
Whether the constraint has a valid linear expression.
Definition apxx_lincons0_inline.hh:150
void set_linexpr(const linexpr0 &c)
Sets the underlying linear expression to c (copied).
Definition apxx_lincons0_inline.hh:185
bool is_quasilinear() const
Whether the underlying linear expression has only scalar coefficients, except maybe for the constant ...
Definition apxx_lincons0_inline.hh:241
bool is_linear() const
Whether the underlying linear expression has only scalar coefficients.
Definition apxx_lincons0_inline.hh:235
const ap_lincons0_t * get_ap_lincons0_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_lincons0_inline.hh:252
scalar & get_modulo()
Returns a (modifiable) reference to the auxiliary scalar.
Definition apxx_lincons0_inline.hh:155
void set_modulo(const scalar &c)
Sets the auxiliary scalar modulo to c (copied).
Definition apxx_lincons0_inline.hh:167
ap_constyp_t & get_constyp()
Returns a (modifiable) reference to the constraint type.
Definition apxx_lincons0_inline.hh:135
size_t size() const
Returns the size of the underlying linear expression.
Definition apxx_lincons0_inline.hh:126
linexpr0 & get_linexpr()
Returns a (modifiable) reference to the underlying linear expression.
Definition apxx_lincons0_inline.hh:173
Array of linear constraints (ap_lincons1_array_t wrapper).
Definition apxx_lincons1.hh:331
void set(size_t i, const lincons1 &x)
Changes the constraint at index i.
Definition apxx_lincons1_inline.hh:453
const lincons0_array & get_lincons0_array() const
Returns a reference to the underlying lincons0_array.
Definition apxx_lincons1_inline.hh:436
void extend_environment(const environment &e)
Extends the environment of all expressions in array.
Definition apxx_lincons1_inline.hh:414
ap_lincons1_array_t a
Structure managed by APRON.
Definition apxx_lincons1.hh:335
void resize(size_t size)
Resizes the array.
Definition apxx_lincons1_inline.hh:409
const ap_lincons1_array_t * get_ap_lincons1_array_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_lincons1_inline.hh:499
lincons1_array(ap_lincons1_array_t &a)
Internal use only. Shallow copy (no copy of lincons0_array or environment).
Definition apxx_lincons1_inline.hh:300
environment get_environment() const
Returns the environment shared by all constraints (with incremented reference count).
Definition apxx_lincons1_inline.hh:431
~lincons1_array()
Frees the space used by the array and all its constraints, and decrements the reference count of the ...
Definition apxx_lincons1_inline.hh:356
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_lincons1_inline.hh:490
lincons1_array & operator=(const lincons1_array &x)
(Deep) copy.
Definition apxx_lincons1_inline.hh:365
size_t size() const
Returns the size of the array.
Definition apxx_lincons1_inline.hh:426
lincons1 get(size_t i) const
Returns a copy of the constraint at index i.
Definition apxx_lincons1_inline.hh:446
Level 1 linear constraint (ap_lincons1_t wrapper).
Definition apxx_lincons1.hh:40
void set_linexpr(const linexpr1 &c)
Sets the underlying linear expression to c (copied).
Definition apxx_lincons1_inline.hh:111
const ap_lincons1_t * get_ap_lincons1_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_lincons1_inline.hh:278
bool is_linear() const
Whether the underlying linear expression has only scalar coefficients.
Definition apxx_lincons1_inline.hh:264
size_t size() const
Returns the size of the underlying linear expression.
Definition apxx_lincons1_inline.hh:150
bool has_modulo() const
Whether the constraint has a valid auxiliary scalar (used in modulo constraints).
Definition apxx_lincons1_inline.hh:165
environment get_environment() const
Returns the environment of the constraint (with incremented reference count).
Definition apxx_lincons1_inline.hh:135
void set_modulo(const scalar &c)
Sets the auxiliary scalar modulo to c (copied).
Definition apxx_lincons1_inline.hh:106
void extend_environment(const environment &e)
Extends the environment of the expression.
Definition apxx_lincons1_inline.hh:120
lincons1 & operator=(const lincons1 &x)
Makes a (deep) copy.
Definition apxx_lincons1_inline.hh:90
coeff & operator[](const var &v)
Returns a (modifiable) reference to the coefficient corresponding to the given variable name.
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_lincons1_inline.hh:250
ap_lincons1_t l
Structure managed by APRON.
Definition apxx_lincons1.hh:44
bool is_quasilinear() const
Whether the underlying linear expression has only scalar coefficients, except maybe for the constant ...
Definition apxx_lincons1_inline.hh:269
ap_constyp_t & get_constyp()
Returns a (modifiable) reference to the constraint type.
Definition apxx_lincons1_inline.hh:155
lincons1(ap_lincons1_t p)
Internal use only. Shallow copy (no copy of lincons0 or environment).
Definition apxx_lincons1_inline.hh:27
const lincons0 & get_lincons0() const
Returns a reference to the underlying lincons0.
Definition apxx_lincons1_inline.hh:140
linexpr1 get_linexpr() const
Returns a copy of the underlying linear expression.
Definition apxx_lincons1_inline.hh:189
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition apxx_lincons1_inline.hh:197
scalar & get_modulo()
Returns a (modifiable) reference to the auxiliary scalar.
Definition apxx_lincons1_inline.hh:175
bool has_linexpr() const
Whether the constraint has a valid linear expression.
Definition apxx_lincons1_inline.hh:170
~lincons1()
Frees all space for the expression and coefficients, and decrements the reference count of the enviro...
Definition apxx_lincons1_inline.hh:81
bool is_unsat() const
Whether the constraint is unsatisfiable.
Definition apxx_lincons1_inline.hh:259
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition apxx_linexpr0.hh:44
Level 1 linear expression (ap_linexpr1_t wrapper).
Definition apxx_linexpr1.hh:39
const linexpr0 & get_linexpr0() const
Returns a reference to the underlying linexpr0.
Definition apxx_linexpr1_inline.hh:102
const ap_linexpr1_t * get_ap_linexpr1_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_linexpr1_inline.hh:321
Scalar (ap_scalar_t wrapper).
Definition apxx_scalar.hh:89
const ap_scalar_t * get_ap_scalar_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_scalar_inline.hh:449
Variable name (ap_var_t wrapper).
Definition apxx_var.hh:39
const ap_var_t & get_ap_var_t() const
Returns a reference to the APRON object wrapped (no copy).
Definition apxx_var_inline.hh:156
Unsatisfiable constraint, to simplify initialisations and assignments.
Definition apxx_lincons0.hh:28