APRONXX  0.9.12
/home/mine/apron/apronxx/apxx_texpr1_inline.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * apxx_texpr1_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 inline void texpr1::init_from(ap_environment_t* e, ap_texpr0_t* x)
19 {
20  l.env = e;
21  l.texpr0 = x;
22 }
23 
24 inline void texpr1::init_from(ap_texpr1_t* x)
25 {
26  l = *x;
27  free(x);
28 }
29 
30 inline texpr1::texpr1(ap_texpr1_t* x)
31 {
32  init_from(x);
33 }
34 
35 inline texpr1::texpr1(const texpr1& x)
36 {
37  init_from(ap_texpr1_copy(const_cast<ap_texpr1_t*>(&x.l)));
38 }
39 
40 inline texpr1::texpr1(const builder& x)
41 {
42  init_from(ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t())));
43 }
44 
45 inline texpr1::texpr1(const const_iterator& x)
46 {
47  init_from(ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t())));
48 }
49 
50 inline texpr1::texpr1(const environment& e, const var& v)
51 {
52  ap_texpr1_t* ll =
53  ap_texpr1_var(const_cast<ap_environment_t*>(e.get_ap_environment_t()), v.get_ap_var_t());
54  if (!ll) throw(std::invalid_argument("apron::texpr1::texpr1(const environment&, const var&) variable not in environment"));
55  init_from(ll);
56 }
57 
58 inline texpr1::texpr1(const environment& e, const texpr0& x)
59 {
60  init_from(ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t())),
61  ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t())));
62 }
63 
64 inline texpr1::texpr1(const environment& e, const texpr0::const_iterator& x)
65 {
66  init_from(ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t())),
67  ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t())));
68 }
69 
70 inline texpr1::texpr1(const environment& e, const texpr0::builder& c)
71 {
72  init_from(ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t())),
73  ap_texpr0_copy(const_cast<ap_texpr0_t*>(c.get_ap_texpr0_t())));
74 }
75 
76 
77 inline texpr1::texpr1(const linexpr1& l)
78 {
79  init_from(ap_texpr1_from_linexpr1(const_cast<ap_linexpr1_t*>(l.get_ap_linexpr1_t())));
80 }
81 
82 inline texpr1::texpr1(const texpr1& x, const environment& e)
83 {
84  ap_texpr1_t* ll =
85  ap_texpr1_extend_environment(const_cast<ap_texpr1_t*>(&x.l),
86  const_cast<ap_environment_t*>(e.get_ap_environment_t()));
87  if (!ll)
88  throw std::invalid_argument("apron::texpr1::texpr1(const texpr1&, const environment&) not a super-environment");
89  init_from(ll);
90 }
91 
92 inline texpr1::texpr1(const texpr1& x, const var& src, const texpr1& dst)
93 {
94  ap_texpr1_t* ll =
95  ap_texpr1_substitute(const_cast<ap_texpr1_t*>(&x.l),
96  const_cast<ap_var_t>(src.get_ap_var_t()),
97  const_cast<ap_texpr1_t*>(&dst.l));
98  if (!ll)
99  throw std::invalid_argument("apron::texpr1::texpr1(const texpr1&, const var&, const texpr1&)");
100  init_from(ll);
101 }
102 
103 
104 /* destructor */
105 /* ========== */
106 
107 inline texpr1::~texpr1()
108 {
109  ap_environment_free(l.env);
110  ap_texpr0_free(l.texpr0);
111 }
112 
113 
114 /* assignment */
115 /* ========== */
116 
117 inline texpr1& texpr1::operator=(const texpr1& x)
118 {
119  ap_texpr1_t* c = ap_texpr1_copy(const_cast<ap_texpr1_t*>(&x.l));
120  ap_environment_free(l.env);
121  ap_texpr0_free(l.texpr0);
122  init_from(c);
123  return *this;
124 }
125 
126 inline texpr1& texpr1::operator=(const builder& x)
127 {
128  ap_texpr1_t* c = ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
129  ap_environment_free(l.env);
130  ap_texpr0_free(l.texpr0);
131  init_from(c);
132  return *this;
133 }
134 
135 inline texpr1& texpr1::operator=(const const_iterator& x)
136 {
137  ap_texpr1_t* c = ap_texpr1_copy(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
138  ap_environment_free(l.env);
139  ap_texpr0_free(l.texpr0);
140  init_from(c);
141  return *this;
142 }
143 
144 inline texpr1& texpr1::operator= (const linexpr1& x)
145 {
146  ap_environment_free(l.env);
147  ap_texpr0_free(l.texpr0);
148  init_from(ap_texpr1_from_linexpr1(const_cast<ap_linexpr1_t*>(x.get_ap_linexpr1_t())));
149  return *this;
150 }
151 
152 
153 
154 /* print */
155 /* ===== */
156 
157 extern void apxx_texpr0_env_ostream(std::ostream& os, ap_environment_t* env, ap_texpr0_t* a);
158 
159 inline std::ostream& operator<< (std::ostream& os, const texpr1& s)
160 {
161  return os << s.root();
162 }
163 
164 inline void texpr1::print(FILE* stream) const
165 {
166  root().print(stream);
167 }
168 
169 
170 
171 /* dimension operations */
172 /* ==================== */
173 
174 inline void texpr1::extend_environment(const environment& e)
175 {
176  bool r =
177  ap_texpr1_extend_environment_with(&l,
178  const_cast<ap_environment_t*>(e.get_ap_environment_t()));
179  if (r)
180  throw std::invalid_argument("apron::texpr1::extend_environment(const environment&) not a super-environment");
181 }
182 
183 
184 /* access */
185 /* ====== */
186 
187 inline environment texpr1::get_environment() const
188 {
189  return root().get_environment();
190 }
191 
192 inline texpr0::const_iterator texpr1::get_texpr0() const
193 {
194  return root().get_texpr0();
195 }
196 
197 inline texpr0::iterator texpr1::get_texpr0()
198 {
199  return root().get_texpr0();
200 }
201 
202 inline bool texpr1::equal(const texpr1& x) const
203 {
204  return root().equal(x);
205 }
206 
207 inline size_t texpr1::depth() const
208 {
209  return root().depth();
210 }
211 
212 inline bool texpr1::is_zero() const
213 {
214  return root().is_zero();
215 }
216 
217 inline size_t texpr1::size() const
218 {
219  return root().size();
220 }
221 
222 inline bool texpr1::has_var(const var& v) const
223 {
224  return root().has_var(v);
225 }
226 
227 inline bool texpr1::is_interval_cst() const
228 {
229  return root().is_interval_cst();
230 }
231 
232 inline bool texpr1::is_interval_linear() const
233 {
234  return root().is_interval_linear();
235 }
236 
237 inline bool texpr1::is_interval_polynomial() const
238 {
239  return root().is_interval_polynomial();
240 }
241 
242 inline bool texpr1::is_interval_polyfrac() const
243 {
244  return root().is_interval_polyfrac();
245 }
246 
247 inline bool texpr1::is_scalar() const
248 {
249  return root().is_scalar();
250 }
251 
252 
253 /* operations */
254 /* ========== */
255 
256 inline void texpr1::substitute(const var& src, const texpr1& dst)
257 {
258  bool r =
259  ap_texpr1_substitute_with(const_cast<ap_texpr1_t*>(&l),
260  const_cast<ap_var_t>(src.get_ap_var_t()),
261  const_cast<ap_texpr1_t*>(&dst.l));
262  if (r)
263  throw std::invalid_argument("apron::texpr1::substitute(const var&, const texpr1&)");
264 }
265 
266 
267 /* C-level compatibility */
268 /* ===================== */
269 
270 
271 inline ap_texpr1_t* texpr1::get_ap_texpr1_t()
272 {
273  return &l;
274 }
275 
276 inline const ap_texpr1_t* texpr1::get_ap_texpr1_t() const
277 {
278  return &l;
279 }
280 
281 
282 
283 
284 
285 
286 /* ========= */
287 /* iterators */
288 /* ========= */
289 
290 
291 
292 /* constructors */
293 /* ============ */
294 
295 inline texpr1::const_iterator texpr1::root() const
296 {
297  return const_iterator(const_cast<ap_texpr1_t*>(&l));
298 }
299 
300 inline texpr1::const_iterator::const_iterator(ap_texpr0_t* ll, ap_environment_t* ee)
301 {
302  l.texpr0 = ll;
303  l.env = ee;
304 }
305 
306 inline texpr1::const_iterator::const_iterator(ap_texpr1_t* l)
307  : l(*l)
308 {}
309 
310 inline texpr1::const_iterator::const_iterator(const texpr1& e)
311  : l(*e.get_ap_texpr1_t())
312 {}
313 
314 inline texpr1::const_iterator::const_iterator(const const_iterator& i)
315  : l(i.l)
316 {}
317 
318 
319 /* access */
320 /* ====== */
321 
322 inline environment texpr1::const_iterator::get_environment() const
323 {
324  return ap_environment_copy(l.env);
325 }
326 
327 inline texpr0::const_iterator texpr1::const_iterator::get_texpr0() const
328 {
329  return l.texpr0;
330 }
331 
332 inline ap_texpr_discr_t texpr1::const_iterator::get_discr() const
333 {
334  return l.texpr0->discr;
335 }
336 
337 inline const coeff& texpr1::const_iterator::get_coeff() const
338 {
339  if (l.texpr0->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr1::const_iterator::get_coeff()"));
340  return reinterpret_cast<coeff&>(l.texpr0->val.cst);
341 }
342 
343 inline const var& texpr1::const_iterator::get_var() const
344 {
345  if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::const_iterator::get_var()"));
346  return *reinterpret_cast<var*>(&l.env->var_of_dim[l.texpr0->val.dim]);
347 }
348 
349 inline ap_dim_t texpr1::const_iterator::get_dim() const
350 {
351  if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::const_iterator::get_dim()"));
352  return l.texpr0->val.dim;
353 }
354 
355 inline ap_texpr_op_t texpr1::const_iterator::get_op() const
356 {
357  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_op()"));
358  return l.texpr0->val.node->op;
359 }
360 
361 inline ap_texpr_rtype_t texpr1::const_iterator::get_rtype() const
362 {
363  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_type()"));
364  return l.texpr0->val.node->type;
365 }
366 
367 inline ap_texpr_rdir_t texpr1::const_iterator::get_rdir() const
368 {
369  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::get_dir()"));
370  return l.texpr0->val.node->dir;
371 }
372 
373 
374 /* traversal */
375 /* ========= */
376 
377 inline texpr1::const_iterator& texpr1::const_iterator::operator=(const const_iterator& i)
378 {
379  l = i.l;
380  return *this;
381 }
382 
383 inline texpr1::const_iterator texpr1::const_iterator::child() const
384 {
385  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::child()"));
386  if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::const_iterator::child()"));
387  return const_iterator(l.texpr0->val.node->exprA, l.env);
388 }
389 
390 inline texpr1::const_iterator texpr1::const_iterator::left() const
391 {
392  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::left()"));
393  if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::const_iterator::left()"));
394  return const_iterator(l.texpr0->val.node->exprA, l.env);
395 }
396 
397 inline texpr1::const_iterator texpr1::const_iterator::right() const
398 {
399  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::const_iterator::right()"));
400  if (!l.texpr0->val.node->exprB) throw(std::out_of_range("apron::texpr1::const_iterator::right()"));
401  return const_iterator(l.texpr0->val.node->exprB, l.env);
402 }
403 
404 
405 
406 
407 /* print */
408 /* ===== */
409 
410 inline std::ostream& operator<< (std::ostream& os, const texpr1::const_iterator& s)
411 {
412  ap_texpr1_t* x = const_cast<ap_texpr1_t*>(s.get_ap_texpr1_t());
413  apxx_texpr0_env_ostream(os, x->env, x->texpr0);
414  return os;
415 }
416 
417 inline void texpr1::const_iterator::print(FILE* stream) const
418 {
419  ap_texpr1_fprint(stream, const_cast<ap_texpr1_t*>(&l));
420 }
421 
422 
423 /* tests, size */
424 /* =========== */
425 
426 inline bool texpr1::const_iterator::equal(const texpr1& x) const
427 {
428  return ap_texpr1_equal(const_cast<ap_texpr1_t*>(&l),
429  const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
430 }
431 
432 inline size_t texpr1::const_iterator::depth() const
433 {
434  return ap_texpr0_depth(const_cast<ap_texpr0_t*>(l.texpr0));
435 }
436 
437 inline bool texpr1::const_iterator::is_zero() const
438 {
439  return l.texpr0->discr==AP_TEXPR_CST && ap_coeff_zero(&const_cast<ap_texpr0_t*>(l.texpr0)->val.cst);
440 }
441 
442 inline size_t texpr1::const_iterator::size() const
443 {
444  return ap_texpr0_size(const_cast<ap_texpr0_t*>(l.texpr0));
445 }
446 
447 inline bool texpr1::const_iterator::has_var(const var& v) const
448 {
449  return ap_texpr1_has_var(const_cast<ap_texpr1_t*>(&l),
450  const_cast<ap_var_t>(v.get_ap_var_t()));
451 }
452 
453 inline bool texpr1::const_iterator::is_interval_cst() const
454 {
455  return ap_texpr1_is_interval_cst(const_cast<ap_texpr1_t*>(&l));
456 }
457 
458 inline bool texpr1::const_iterator::is_interval_linear() const
459 {
460  return ap_texpr1_is_interval_linear(const_cast<ap_texpr1_t*>(&l));
461 }
462 
463 inline bool texpr1::const_iterator::is_interval_polynomial() const
464 {
465  return ap_texpr1_is_interval_polynomial(const_cast<ap_texpr1_t*>(&l));
466 }
467 
468 inline bool texpr1::const_iterator::is_interval_polyfrac() const
469 {
470  return ap_texpr1_is_interval_polyfrac(const_cast<ap_texpr1_t*>(&l));
471 }
472 
473 inline bool texpr1::const_iterator::is_scalar() const
474 {
475  return ap_texpr1_is_scalar(const_cast<ap_texpr1_t*>(&l));
476 }
477 
478 
479 /* C-level compatibility */
480 /* ===================== */
481 
482 inline ap_texpr1_t* texpr1::const_iterator::get_ap_texpr1_t()
483 {
484  return &l;
485 }
486 
487 inline const ap_texpr1_t* texpr1::const_iterator::get_ap_texpr1_t() const
488 {
489  return &l;
490 }
491 
492 
493 /* constructors */
494 /* ============ */
495 
496 inline texpr1::iterator texpr1::root()
497 {
498  return iterator(&l);
499 }
500 
501 inline texpr1::iterator::iterator(ap_texpr0_t* l, ap_environment_t* e)
502  : texpr1::const_iterator(l,e)
503 {}
504 
505 inline texpr1::iterator::iterator(ap_texpr1_t* l)
506  : texpr1::const_iterator(l)
507 {}
508 
509 
510 inline texpr1::iterator::iterator(texpr1& e)
511  : texpr1::const_iterator(e.get_ap_texpr1_t())
512 {}
513 
514 inline texpr1::iterator::iterator(const iterator& i)
515  : texpr1::const_iterator(i)
516 {}
517 
518 
519 
520 /* substitution */
521 /* ============ */
522 
523 inline texpr1::iterator& texpr1::iterator::operator= (const builder& c)
524 {
525  ap_texpr0_t* cc = ap_texpr0_copy(c.get_ap_texpr1_t()->texpr0);
526  ap_texpr0_clear(l.texpr0);
527  *l.texpr0 = *cc;
528  free(cc);
529  return *this;
530 }
531 
532 
533 /* access */
534 /* ====== */
535 
536 inline texpr0::iterator texpr1::iterator::get_texpr0() const
537 {
538  return l.texpr0;
539 }
540 
541 
542 inline coeff& texpr1::iterator::get_coeff() const
543 {
544  if (l.texpr0->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr1::iterator::get_coeff()"));
545  return reinterpret_cast<coeff&>(l.texpr0->val.cst);
546 }
547 
548 inline void texpr1::iterator::set_var(const var& v) const
549 {
550  if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::iterator::set_var(const var&)"));
551  ap_dim_t d = ap_environment_dim_of_var(l.env, v.get_ap_var_t());
552  if (d==AP_DIM_MAX) throw(std::invalid_argument("apron::texpr1::iterator::set_var(const var&) variable not in environment"));
553  l.texpr0->val.dim = d;
554 }
555 
556 inline ap_dim_t& texpr1::iterator::get_dim() const
557 {
558  if (l.texpr0->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr1::iterator::get_dim()"));
559  return l.texpr0->val.dim;
560 }
561 
562 inline ap_texpr_op_t& texpr1::iterator::get_op() const
563 {
564  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_op()"));
565  return l.texpr0->val.node->op;
566 }
567 
568 inline ap_texpr_rtype_t& texpr1::iterator::get_rtype() const
569 {
570  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_type()"));
571  return l.texpr0->val.node->type;
572 }
573 
574 inline ap_texpr_rdir_t& texpr1::iterator::get_rdir() const
575 {
576  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::get_dir()"));
577  return l.texpr0->val.node->dir;
578 }
579 
580 
581 /* traversal */
582 /* ========= */
583 
584 inline texpr1::iterator& texpr1::iterator::operator=(const iterator& i)
585 {
586  l = i.l;
587  return *this;
588 }
589 
590 inline texpr1::iterator texpr1::iterator::child() const
591 {
592  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::child()"));
593  if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::iterator::child()"));
594  return iterator(l.texpr0->val.node->exprA, l.env);
595 }
596 
597 inline texpr1::iterator texpr1::iterator::left() const
598 {
599  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::left()"));
600  if (!l.texpr0->val.node->exprA) throw(std::out_of_range("apron::texpr1::iterator::left()"));
601  return iterator(l.texpr0->val.node->exprA, l.env);
602 }
603 
604 inline texpr1::iterator texpr1::iterator::right() const
605 {
606  if (l.texpr0->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr1::iterator::right()"));
607  if (!l.texpr0->val.node->exprB) throw(std::out_of_range("apron::texpr1::iterator::right()"));
608  return iterator(l.texpr0->val.node->exprB, l.env);
609 }
610 
611 
612 /* C-level compatibility */
613 /* ===================== */
614 
615 inline ap_texpr1_t* texpr1::iterator::get_ap_texpr1_t()
616 {
617  return &l;
618 }
619 
620 inline const ap_texpr1_t* texpr1::iterator::get_ap_texpr1_t() const
621 {
622  return &l;
623 }
624 
625 
626 /* ================================= */
627 /* builder */
628 /* ================================= */
629 
630 inline void texpr1::builder::init_from(ap_texpr1_t* x)
631 {
632  l.env = x->env;
633  switch (x->texpr0->discr) {
634  case AP_TEXPR_DIM: l.texpr0 = ap_texpr0_dim(x->texpr0->val.dim); break;
635  case AP_TEXPR_CST: l.texpr0 = ap_texpr0_cst(const_cast<ap_coeff_t*>(&x->texpr0->val.cst)); break;
636  case AP_TEXPR_NODE:
637  l.texpr0 = ap_texpr0_node(x->texpr0->val.node->op,
638  x->texpr0->val.node->type, x->texpr0->val.node->dir,
639  x->texpr0->val.node->exprA, x->texpr0->val.node->exprB);
640  break;
641  default: throw std::invalid_argument("apron::texpr1::builder::init_from(ap_texpr1_t*) invalid discriminant");
642  }
643 }
644 
645 inline void texpr1::builder::init_from(ap_environment_t* e, ap_texpr0_t* x)
646 {
647  ap_texpr1_t ll;
648  ll.texpr0 = x;
649  ll.env = e;
650  init_from(&ll);
651 }
652 
653 inline texpr1::builder::builder(ap_texpr1_t* x)
654 {
655  init_from(x);
656 }
657 
658 inline texpr1::builder::builder(const builder& x)
659 {
660  init_from(const_cast<ap_texpr1_t*>(&x.l));
661 }
662 
663 inline texpr1::builder::builder(const const_iterator& x)
664 {
665  init_from(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
666 }
667 
668 inline texpr1::builder::builder(const texpr1& x)
669 {
670  init_from(const_cast<ap_texpr1_t*>(x.get_ap_texpr1_t()));
671 }
672 
673 inline texpr1::builder::builder(const environment& e, const texpr0::builder& b)
674 {
675  init_from(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
676  const_cast<ap_texpr0_t*>(b.get_ap_texpr0_t()));
677 }
678 
679 inline texpr1::builder::builder(const environment& e, const texpr0::const_iterator& b)
680 {
681  init_from(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
682  const_cast<ap_texpr0_t*>(b.get_ap_texpr0_t()));
683 }
684 
685 inline texpr1::builder::builder(const environment& e, const texpr0& b)
686 {
687  init_from(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
688  const_cast<ap_texpr0_t*>(b.get_ap_texpr0_t()));
689 }
690 
691 inline texpr1::builder::builder(const environment& e, const coeff& x)
692 {
693  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
694  l.texpr0 = ap_texpr0_cst(const_cast<ap_coeff_t*>(x.get_ap_coeff_t()));
695 }
696 
697 inline texpr1::builder::builder(const environment& e, const scalar& x)
698 {
699  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
700  l.texpr0 = ap_texpr0_cst_scalar(const_cast<ap_scalar_t*>(x.get_ap_scalar_t()));
701 }
702 
703 inline texpr1::builder::builder(const environment& e, const mpq_class& x)
704 {
705  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
706  l.texpr0 = ap_texpr0_cst_scalar_mpq(const_cast<mpq_class&>(x).get_mpq_t());
707 }
708 
709 inline texpr1::builder::builder(const environment& e, mpfr_t x)
710 {
711  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
712  l.texpr0 = ap_texpr0_cst_scalar_mpfr(x);
713 }
714 
715 inline texpr1::builder::builder(const environment& e, int x)
716 {
717  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
718  l.texpr0 = ap_texpr0_cst_scalar_int(x);
719 }
720 
721 inline texpr1::builder::builder(const environment& e, long x)
722 {
723  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
724  l.texpr0 = ap_texpr0_cst_scalar_int(x);
725 }
726 
727 inline texpr1::builder::builder(const environment& e, double x)
728 {
729  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
730  l.texpr0 = ap_texpr0_cst_scalar_double(x);
731 }
732 
733 inline texpr1::builder::builder(const environment& e, const frac& x)
734 {
735  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
736  l.texpr0 = ap_texpr0_cst_scalar_frac(x.num, x.den);
737 }
738 
739 inline texpr1::builder::builder(const environment& e, const interval& x)
740 {
741  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
742  l.texpr0 = ap_texpr0_cst_interval(const_cast<ap_interval_t*>(x.get_ap_interval_t()));
743 }
744 
745 inline texpr1::builder::builder(const environment& e, const scalar& inf, const scalar& sup)
746 {
747  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
748  l.texpr0 = ap_texpr0_cst_interval_scalar(const_cast<ap_scalar_t*>(inf.get_ap_scalar_t()),
749  const_cast<ap_scalar_t*>(sup.get_ap_scalar_t()));
750 }
751 
752 inline texpr1::builder::builder(const environment& e, const mpq_class& inf, const mpq_class& sup)
753 {
754  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
755  l.texpr0 = ap_texpr0_cst_interval_mpq(const_cast<mpq_class&>(inf).get_mpq_t(),
756  const_cast<mpq_class&>(sup).get_mpq_t());
757 }
758 
759 inline texpr1::builder::builder(const environment& e, mpfr_t inf, mpfr_t sup)
760 {
761  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
762  l.texpr0 = ap_texpr0_cst_interval_mpfr(inf,sup);
763 }
764 
765 inline texpr1::builder::builder(const environment& e, int inf, int sup)
766 {
767  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
768  l.texpr0 = ap_texpr0_cst_interval_int(inf, sup);
769 }
770 
771 inline texpr1::builder::builder(const environment& e, long inf, long sup)
772 {
773  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
774  l.texpr0 = ap_texpr0_cst_interval_int(inf, sup);
775 }
776 
777 inline texpr1::builder::builder(const environment& e, double inf, double sup)
778 {
779  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
780  l.texpr0 = ap_texpr0_cst_interval_double(inf, sup);
781 }
782 
783 inline texpr1::builder::builder(const environment& e, const frac& inf, const frac& sup)
784 {
785  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
786  l.texpr0 = ap_texpr0_cst_interval_frac(inf.num, inf.den, sup.num, sup.den);
787 }
788 
789 inline texpr1::builder::builder(const environment& e, top t)
790 {
791  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
792  l.texpr0 = ap_texpr0_cst_interval_top();
793 }
794 
795 inline texpr1::builder::builder(const environment& e, const var& v)
796 {
797  l.env = const_cast<ap_environment_t*>(e.get_ap_environment_t());
798  ap_dim_t d = ap_environment_dim_of_var(l.env, v.get_ap_var_t());
799  if (d==AP_DIM_MAX)
800  throw std::invalid_argument("texpr1::builder::builder(const environment&, const var&) variable not in environment");
801  l.texpr0 = ap_texpr0_dim(d);
802 }
803 
804 inline texpr1::builder::builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir)
805 {
806  if (!ap_texpr_is_unop(op))
807  throw std::invalid_argument("apron::texpr1::builder::builder(ap_texpr_op_t, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a unary operator");
808  l.env = argA.l.env;
809  l.texpr0 = ap_texpr0_unop(op,
810  const_cast<ap_texpr0_t*>(argA.l.texpr0),
811  rtype, rdir);
812 }
813 
814 inline texpr1::builder::builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir)
815 {
816  if (!ap_texpr_is_binop(op))
817  throw std::invalid_argument("apron::texpr1::builder::builder(ap_texpr_op_t, const builder&, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a binary operator");
818  l.env = argA.l.env;
819  l.texpr0 = ap_texpr0_binop(op,
820  const_cast<ap_texpr0_t*>(argA.l.texpr0),
821  const_cast<ap_texpr0_t*>(argB.l.texpr0),
822  rtype, rdir);
823 }
824 
825 
826 /* 'intelligent' constructors */
827 
828 inline texpr1::builder unary(ap_texpr_op_t op, const texpr1::builder& a,
829  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
830  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
831 {
832  return texpr1::builder(op, a, rtype, rdir);
833 }
834 
835 inline texpr1::builder binary(ap_texpr_op_t op, const texpr1::builder& a, const texpr1::builder& b,
836  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
837  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
838 {
839  return texpr1::builder(op, a, b, rtype, rdir);
840 }
841 
842 
843 inline texpr1::builder add(const texpr1::builder& a, const texpr1::builder& b,
844  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
845  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
846 {
847  return texpr1::builder(AP_TEXPR_ADD, a, b, rtype, rdir);
848 }
849 
850 inline texpr1::builder sub(const texpr1::builder& a, const texpr1::builder& b,
851  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
852  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
853 {
854  return texpr1::builder(AP_TEXPR_SUB, a, b, rtype, rdir);
855 }
856 
857 inline texpr1::builder mul(const texpr1::builder& a, const texpr1::builder& b,
858  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
859  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
860 {
861  return texpr1::builder(AP_TEXPR_MUL, a, b, rtype, rdir);
862 }
863 
864 inline texpr1::builder div(const texpr1::builder& a, const texpr1::builder& b,
865  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
866  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
867 {
868  return texpr1::builder(AP_TEXPR_DIV, a, b, rtype, rdir);
869 }
870 
871 inline texpr1::builder mod(const texpr1::builder& a, const texpr1::builder& b,
872  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
873  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
874 {
875  return texpr1::builder(AP_TEXPR_MOD, a, b, rtype, rdir);
876 }
877 
878 inline texpr1::builder pow(const texpr1::builder& a, const texpr1::builder& b,
879  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
880  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
881 {
882  return texpr1::builder(AP_TEXPR_POW, a, b, rtype, rdir);
883 }
884 
885 inline texpr1::builder neg(const texpr1::builder& a,
886  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
887  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
888 {
889  return texpr1::builder(AP_TEXPR_NEG, a, rtype, rdir);
890 }
891 
892 inline texpr1::builder cast(const texpr1::builder& a, ap_texpr_rtype_t rtype,
893  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
894 {
895  return texpr1::builder(AP_TEXPR_CAST, a, rtype, rdir);
896 }
897 
898 inline texpr1::builder floor(const texpr1::builder& a)
899 {
900  return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_DOWN);
901 }
902 
903 inline texpr1::builder ceil(const texpr1::builder& a)
904 {
905  return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_UP);
906 }
907 
908 inline texpr1::builder trunc(const texpr1::builder& a)
909 {
910  return texpr1::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_ZERO);
911 }
912 
913 inline texpr1::builder sqrt(const texpr1::builder& a,
914  ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
915  ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
916 {
917  return texpr1::builder(AP_TEXPR_SQRT, a, rtype, rdir);
918 }
919 
920 inline texpr1::builder operator+(const texpr1::builder& a)
921 {
922  return a;
923 }
924 
925 inline texpr1::builder operator-(const texpr1::builder& a)
926 {
927  return neg(a);
928 }
929 
930 inline texpr1::builder operator+(const texpr1::builder& a, const texpr1::builder& b)
931 {
932  return add(a,b);
933 }
934 
935 inline texpr1::builder operator-(const texpr1::builder& a, const texpr1::builder& b)
936 {
937  return sub(a,b);
938 }
939 
940 inline texpr1::builder operator*(const texpr1::builder& a, const texpr1::builder& b)
941 {
942  return mul(a,b);
943 }
944 
945 inline texpr1::builder operator/(const texpr1::builder& a, const texpr1::builder& b)
946 {
947  return div(a,b);
948 }
949 
950 inline texpr1::builder operator%(const texpr1::builder& a, const texpr1::builder& b)
951 {
952  return mod(a,b);
953 }
954 
955 inline texpr1::builder operator^(const texpr1::builder& a, const texpr1::builder& b)
956 {
957  return pow(a,b);
958 }
959 
960 
961 /* tests */
962 /* ===== */
963 
964 inline bool texpr1::builder::is_zero() const
965 {
966  return l.texpr0->discr==AP_TEXPR_CST && ap_coeff_zero(const_cast<ap_coeff_t*>(&l.texpr0->val.cst));
967 }
968 
969 
970 /* destructor */
971 /* ========== */
972 
973 inline texpr1::builder::~builder()
974 {
975  switch(l.texpr0->discr){
976  case AP_TEXPR_CST: ap_coeff_clear(&l.texpr0->val.cst); break;
977  case AP_TEXPR_DIM: break;
978  case AP_TEXPR_NODE: free(l.texpr0->val.node); break;
979  default: assert(false);
980  }
981  free(l.texpr0);
982 }
983 
984 
985 /* C-level compatibility */
986 /* ===================== */
987 
988 inline ap_texpr1_t* texpr1::builder::get_ap_texpr1_t()
989 {
990  return &l;
991 }
992 
993 inline const ap_texpr1_t* texpr1::builder::get_ap_texpr1_t() const
994 {
995  return &l;
996 }
texpr1::builder div(const texpr1::builder &a, const texpr1::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:864
texpr1::builder operator-(const texpr1::builder &a)
Definition: apxx_texpr1_inline.hh:925
texpr1::builder pow(const texpr1::builder &a, const texpr1::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:878
texpr1::builder unary(ap_texpr_op_t op, const texpr1::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:828
texpr1::builder operator *(const texpr1::builder &a, const texpr1::builder &b)
Definition: apxx_texpr1_inline.hh:940
bool equal(const linexpr0 &x, const linexpr0 &y)
Definition: apxx_linexpr0_inline.hh:293
texpr1::builder ceil(const texpr1::builder &a)
Definition: apxx_texpr1_inline.hh:903
texpr1::builder neg(const texpr1::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:885
texpr1::builder mul(const texpr1::builder &a, const texpr1::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:857
texpr1::builder add(const texpr1::builder &a, const texpr1::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:843
texpr1::builder floor(const texpr1::builder &a)
Definition: apxx_texpr1_inline.hh:898
std::ostream & operator<<(std::ostream &os, const texpr1 &s)
Definition: apxx_texpr1_inline.hh:159
texpr1::builder operator%(const texpr1::builder &a, const texpr1::builder &b)
Definition: apxx_texpr1_inline.hh:950
texpr1::builder sub(const texpr1::builder &a, const texpr1::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:850
texpr1::builder operator^(const texpr1::builder &a, const texpr1::builder &b)
Definition: apxx_texpr1_inline.hh:955
texpr1::builder operator/(const texpr1::builder &a, const texpr1::builder &b)
Definition: apxx_texpr1_inline.hh:945
abstract0 & substitute(manager &m, abstract0 &dst, const abstract0 &src, ap_dim_t dim, const linexpr0 &l, const abstract0 &inter=abstract0::null)
Definition: apxx_abstract0.hh:860
texpr1::builder binary(ap_texpr_op_t op, const texpr1::builder &a, const texpr1::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:835
void apxx_texpr0_env_ostream(std::ostream &os, ap_environment_t *env, ap_texpr0_t *a)
texpr1::builder mod(const texpr1::builder &a, const texpr1::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:871
texpr1::builder operator+(const texpr1::builder &a)
Definition: apxx_texpr1_inline.hh:920
texpr1::builder cast(const texpr1::builder &a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:892
texpr1::builder sqrt(const texpr1::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr1_inline.hh:913
texpr1::builder trunc(const texpr1::builder &a)
Definition: apxx_texpr1_inline.hh:908