APRONXX 0.9.14
/builddir/build/BUILD/apron-0.9.15-build/apron-0.9.15/apronxx/apxx_interval_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_interval_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/* interval */
21/* ================================= */
22
23
24/* constructors */
25/* ============ */
26
27
28inline void interval::init()
29{
30 c.inf = ap_scalar_alloc();
31 c.sup = ap_scalar_alloc();
32}
33
34inline interval::interval(ap_interval_t* i)
35 : c(*i)
36{
37 free(i);
38}
39
41{
42 init();
43}
44
46{
47 init();
48 ap_interval_set(&c, const_cast<ap_interval_t*>(&x.c));
49}
50
51inline interval::interval(const scalar& inf, const scalar& sup)
52{
53 init();
54 ap_interval_set_scalar(&c,
55 const_cast<ap_scalar_t*>(inf.get_ap_scalar_t()),
56 const_cast<ap_scalar_t*>(sup.get_ap_scalar_t()));
57}
58
59inline interval::interval(int inf, int sup)
60{
61 init();
62 ap_interval_set_int(&c, inf, sup);
63}
64
65inline interval::interval(long inf, long sup)
66{
67 init();
68 ap_interval_set_int(&c, inf, sup);
69}
70
71inline interval::interval(double inf, double sup)
72{
73 init();
74 ap_interval_set_double(&c, inf, sup);
75}
76
77inline interval::interval(const frac& inf, const frac& sup)
78{
79 init();
80 ap_interval_set_frac(&c, inf.num, inf.den, sup.num, sup.den);
81}
82
83inline interval::interval(const mpq_class& inf, const mpq_class& sup)
84{
85 init();
86 ap_interval_set_mpq(&c,
87 const_cast<mpq_class&>(inf).get_mpq_t(),
88 const_cast<mpq_class&>(sup).get_mpq_t());
89}
90
91inline interval::interval(mpfr_t inf, mpfr_t sup)
92{
93 init();
94 ap_interval_set_mpfr(&c,inf,sup);
95}
96
98{
99 init();
100 ap_interval_set_top(&c);
101}
102
104{
105 init();
106 ap_interval_set_bottom(&c);
107}
108
109
110/* destructor */
111/* ========== */
112
114{
115 ap_scalar_free(c.inf);
116ap_scalar_free(c.sup);
117}
118
119
120/* assignments */
121/* =========== */
122
123/* = */
124
126{
127 ap_interval_set(&c, const_cast<ap_interval_t*>(&x.c));
128 return *this;
129}
130
132{
133 ap_interval_set_top(&c);
134 return *this;
135}
136
138{
139 ap_interval_set_bottom(&c);
140 return *this;
141}
142
143
144/* set */
145
147{
148 ap_interval_set(&c, const_cast<ap_interval_t*>(&x.c));
149 return *this;
150}
151
152inline interval& interval::set(const scalar& inf, const scalar& sup)
153{
154 ap_interval_set_scalar(&c,
155 const_cast<ap_scalar_t*>(inf.get_ap_scalar_t()),
156 const_cast<ap_scalar_t*>(sup.get_ap_scalar_t()));
157 return *this;
158}
159
160inline interval& interval::set(int inf, int sup)
161{
162 ap_interval_set_int(&c, inf, sup);
163 return *this;
164}
165
166inline interval& interval::set(long inf, long sup)
167{
168 ap_interval_set_int(&c, inf, sup);
169 return *this;
170}
171
172inline interval& interval::set(double inf, double sup)
173{
174 ap_interval_set_double(&c, inf, sup);
175 return *this;
176}
177
178inline interval& interval::set(const frac& inf, const frac& sup)
179{
180 ap_interval_set_frac(&c, inf.num, inf.den, sup.num, sup.den);
181 return *this;
182}
183
184inline interval& interval::set(const mpq_class& inf, const mpq_class& sup)
185{
186 ap_interval_set_mpq(&c,
187 const_cast<mpq_class&>(inf).get_mpq_t(),
188 const_cast<mpq_class&>(sup).get_mpq_t());
189 return *this;
190}
191
192inline interval& interval::set(mpfr_t inf, mpfr_t sup)
193{
194 ap_interval_set_mpfr(&c,inf,sup);
195 return *this;
196}
197
199{
200 ap_interval_set_top(&c);
201 return *this;
202}
203
205{
206 ap_interval_set_bottom(&c);
207 return *this;
208}
209
210
211/* swap */
212
213inline void swap(interval& a, interval &b)
214{
215 ap_interval_swap(&a.c, &b.c);
216}
217
218
219/* access */
220/* ====== */
221
223{
224 return reinterpret_cast<scalar&>(*c.inf);
225}
226
228{
229 return reinterpret_cast<scalar&>(*c.sup);
230}
231
232inline const scalar& interval::get_inf() const
233{
234 return reinterpret_cast<const scalar&>(*c.inf);
235}
236
237inline const scalar& interval::get_sup() const
238{
239 return reinterpret_cast<const scalar&>(*c.sup);
240}
241
242
243/* print */
244/* ===== */
245
246inline std::ostream& operator<< (std::ostream& os, const interval& s)
247{
248 return os << '[' << s.get_inf() << ',' << s.get_sup() << ']';
249}
250
251inline void interval::print(FILE* stream) const
252{
253 ap_interval_fprint(stream, const_cast<ap_interval_t*>(&c));
254}
255
256
257/* tests */
258/* ===== */
259
260inline bool interval::is_top() const
261{
262 return ap_interval_is_top(const_cast<ap_interval_t*>(&c));
263}
264
265inline bool interval::is_bottom() const
266{
267 return ap_interval_is_bottom(const_cast<ap_interval_t*>(&c));
268}
269
270inline bool operator<= (const interval&a, const interval &b)
271{
272 return ap_interval_is_leq(const_cast<ap_interval_t*>(&a.c),
273 const_cast<ap_interval_t*>(&b.c));
274}
275
276inline bool operator>= (const interval&a, const interval &b)
277{
278 return ap_interval_is_leq(const_cast<ap_interval_t*>(&b.c),
279 const_cast<ap_interval_t*>(&a.c));
280}
281
282inline bool operator< (const interval&a, const interval &b)
283{
284 return ap_interval_cmp(const_cast<ap_interval_t*>(&a.c),
285 const_cast<ap_interval_t*>(&b.c)) == -1;
286}
287
288inline bool operator> (const interval&a, const interval &b)
289{
290 return ap_interval_cmp(const_cast<ap_interval_t*>(&a.c),
291 const_cast<ap_interval_t*>(&b.c)) == 1;
292}
293
294inline bool operator== (const interval&a, const interval &b)
295{
296 return ap_interval_equal(const_cast<ap_interval_t*>(&a.c),
297 const_cast<ap_interval_t*>(&b.c));
298}
299
300inline bool operator!= (const interval&a, const interval &b)
301{
302 return !ap_interval_equal(const_cast<ap_interval_t*>(&a.c),
303 const_cast<ap_interval_t*>(&b.c));
304}
305
306inline interval::order cmp (const interval&a, const interval &b)
307{
308 return (interval::order)ap_interval_cmp(const_cast<ap_interval_t*>(&a.c),
309 const_cast<ap_interval_t*>(&b.c));
310}
311
312
313/* other operators */
314/* =============== */
315
316inline void interval::neg()
317{
318 ap_interval_neg(&c, &c);
319}
320
322{
323 interval r = *this;
324 r.neg();
325 return r;
326}
327
328inline long interval::hash() const
329{
330 return ap_interval_hash(const_cast<ap_interval_t*>(&c));
331}
332
333
334/* C-level compatibility */
335
336inline const ap_interval_t* interval::get_ap_interval_t() const
337{
338 return &c;
339}
340
341inline ap_interval_t* interval::get_ap_interval_t()
342{
343 return &c;
344}
345
346
347
348
349
350/* ================================= */
351/* interval_array */
352/* ================================= */
353
354
355inline interval_array::interval_array(size_t size, ap_interval_t** c)
356 : sz(size), c(c)
357{}
358
359
360/* constructors */
361/* ============ */
362
364 : sz(size), c(ap_interval_array_alloc(size))
365{}
366
368 : sz(x.sz), c(ap_interval_array_alloc(x.sz))
369{
370 for (size_t i=0;i<sz;i++)
371 ap_interval_set(c[i], x.c[i]);
372}
373
374inline interval_array::interval_array(const std::vector<interval>& x)
375 : sz(x.size()), c(ap_interval_array_alloc(x.size()))
376{
377 for (size_t i=0;i<sz;i++)
378 ap_interval_set(c[i], const_cast<ap_interval_t*>(x[i].get_ap_interval_t()));
379}
380
381inline interval_array::interval_array(size_t size, const interval x[])
382 : sz(size), c(ap_interval_array_alloc(size))
383{
384 for (size_t i=0;i<size;i++)
385 ap_interval_set(c[i], const_cast<ap_interval_t*>(x[i].get_ap_interval_t()));
386}
387
388
389
390/* destructor */
391/* ========== */
392
394{
395 ap_interval_array_free(c, sz);
396}
397
398
399/* assignment */
400/* ========== */
401
403{
404 if (&x!=this) {
405 if (sz != x.sz) {
406 ap_interval_array_free(c, sz);
407 sz = x.sz;
408 c = ap_interval_array_alloc(sz);
409 }
410 for (size_t i=0;i<sz;i++)
411 ap_interval_set(c[i], x.c[i]);
412 }
413 return *this;
414}
415
416inline interval_array& interval_array::operator= (const std::vector<interval>& x)
417{
418 if (sz != x.size()) {
419 ap_interval_array_free(c, sz);
420 sz = x.size();
421 c = ap_interval_array_alloc(sz);
422 }
423 for (size_t i=0;i<sz;i++)
424 ap_interval_set(c[i], const_cast<ap_interval_t*>(x[i].get_ap_interval_t()));
425 return *this;
426}
427
429{
430 for (size_t i=0;i<sz;i++)
431 ap_interval_set(c[i], const_cast<ap_interval_t*>(x[i].get_ap_interval_t()));
432 return *this;
433}
434
435
436/* conversion */
437/* ========== */
438
439inline interval_array::operator std::vector<interval>() const
440{
441 std::vector<interval> v = std::vector<interval>(sz);
442 for (size_t i=0;i<sz;i++)
443 ap_interval_set(v[i].get_ap_interval_t(), c[i]);
444 return v;
445}
446
447
448/* print */
449/* ===== */
450
451inline std::ostream& operator<< (std::ostream& os, const interval_array& s)
452{
453 os << "{ ";
454 for (size_t i=0;i<s.sz;i++)
455 os << s.get(i) << " ";
456 return os << "}";
457}
458
459inline void interval_array::print(FILE* stream) const
460{
461 fprintf(stream, "{ " );
462 for (size_t i=0;i<sz;i++) {
463 ap_interval_fprint(stream, const_cast<ap_interval_t*>(c[i]));
464 fprintf(stream, " ");
465 }
466 fprintf(stream,"}");
467}
468
469
470/* access */
471/* ====== */
472
473inline size_t interval_array::size() const
474{ return sz; }
475
477{ return reinterpret_cast<interval**>(c); }
478
480{
481 if (i >= sz) throw std::out_of_range("apron::interval_array::get(size_t)");
482 return reinterpret_cast<interval&>(*c[i]);
483}
484
485inline const interval& interval_array::get(size_t i) const
486{
487 if (i >= sz) throw std::out_of_range("apron::interval_array::get(size_t)");
488 return reinterpret_cast<interval&>(*c[i]);
489}
490
492{
493 return reinterpret_cast<interval&>(*c[i]);
494}
495
496inline const interval& interval_array::operator[](size_t i) const
497{
498 return reinterpret_cast<interval&>(*c[i]);
499}
500
501
502/* C API compatibility */
503/* =================== */
504
505inline const ap_interval_t * const * interval_array::get_ap_interval_t_array() const
506{
507 return c;
508}
509
511{
512 return c;
513}
514
bool operator==(const abstract0 &x, const abstract0 &y)
Definition apxx_abstract0_inline.hh:409
bool operator<=(const abstract0 &x, const abstract0 &y)
Definition apxx_abstract0_inline.hh:421
bool operator>(const abstract0 &x, const abstract0 &y)
Definition apxx_abstract0_inline.hh:433
bool operator<(const abstract0 &x, const abstract0 &y)
Definition apxx_abstract0_inline.hh:438
bool operator>=(const abstract0 &x, const abstract0 &y)
Definition apxx_abstract0_inline.hh:428
bool operator!=(const abstract0 &x, const abstract0 &y)
Definition apxx_abstract0_inline.hh:416
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition apxx_abstract0_inline.hh:292
int cmp(const coeff &a, const coeff &b)
Definition apxx_coeff_inline.hh:414
void swap(coeff &a, coeff &b)
Definition apxx_coeff_inline.hh:381
array of interval(s).
Definition apxx_interval.hh:302
interval_array(size_t size, ap_interval_t **c)
Internal use only. Reference an array created with ap_interval_array_alloc.
Definition apxx_interval_inline.hh:355
size_t sz
Array size.
Definition apxx_interval.hh:306
interval ** contents()
Returns a pointer to the start of the array of elements used internally.
Definition apxx_interval_inline.hh:476
ap_interval_t ** c
Array of pointers to intervals.
Definition apxx_interval.hh:307
const ap_interval_t *const * get_ap_interval_t_array() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_interval_inline.hh:505
interval_array & operator=(const interval_array &x)
Copies an interval array into *this.
Definition apxx_interval_inline.hh:402
size_t size() const
Returns the array size.
Definition apxx_interval_inline.hh:473
interval & get(size_t i)
Definition apxx_interval_inline.hh:479
~interval_array()
Frees the space occupied by the array and all its elements.
Definition apxx_interval_inline.hh:393
interval & operator[](size_t i)
Returns a (modifiable) reference to an element, no bound checking.
Definition apxx_interval_inline.hh:491
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_interval_inline.hh:459
Interval (ap_interval_t wrapper).
Definition apxx_interval.hh:47
void neg()
Negates *this.
Definition apxx_interval_inline.hh:316
bool is_top() const
Whether *this equals ]-oo;+oo[.
Definition apxx_interval_inline.hh:260
interval & set(const interval &x)
Copies an interval into *this.
Definition apxx_interval_inline.hh:146
scalar & get_inf()
Gets a (modifiable) reference to the lower bound.
Definition apxx_interval_inline.hh:222
void init()
Internal initialisation.
Definition apxx_interval_inline.hh:28
interval & operator=(const interval &x)
Copies an interval into *this.
Definition apxx_interval_inline.hh:125
long hash() const
Returns a hash code.
Definition apxx_interval_inline.hh:328
interval operator-() const
Returns a new interval which is the opposite of *this.
Definition apxx_interval_inline.hh:321
scalar & get_sup()
Gets a (modifiable) reference to the upper bound.
Definition apxx_interval_inline.hh:227
~interval()
Definition apxx_interval_inline.hh:113
order
Returned by ordering functions.
Definition apxx_interval.hh:66
bool is_bottom() const
Whether *this represents an empty interval.
Definition apxx_interval_inline.hh:265
interval()
Makes a new interval [0,0] with double bounds.
Definition apxx_interval_inline.hh:40
const ap_interval_t * get_ap_interval_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_interval_inline.hh:336
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_interval_inline.hh:251
ap_interval_t c
Structure managed by APRON.
Definition apxx_interval.hh:50
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
Empty interval or domain, to simplify initialisations and assignments.
Definition apxx_interval.hh:33
A fraction with native int coefficients, to simplify initialisations and assignments.
Definition apxx_scalar.hh:41
unsigned long den
Denominator.
Definition apxx_scalar.hh:44
long num
Numerator.
Definition apxx_scalar.hh:43
Full interval (]-oo,+oo[) or domain, to simplify initialisations and assignments.
Definition apxx_interval.hh:27