APRONXX 0.9.12
/builddir/build/BUILD/apron-0.9.13/apronxx/apxx_interval.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_interval.hh
3 *
4 * APRON Library / C++ class wrappers
5 *
6 * Copyright (C) Antoine Mine' 2007
7 *
8 */
9/* This file is part of the APRON Library, released under LGPL license
10 with an exception allowing the redistribution of statically linked
11 executables.
12
13 Please read the COPYING file packaged in the distribution.
14*/
15
16#ifndef __APXX_INTERVAL_HH
17#define __APXX_INTERVAL_HH
18
19#include <vector>
20#include "ap_interval.h"
21#include "apxx_scalar.hh"
22
23
24namespace apron {
25
27struct top {
28 top() {}
29};
30
31
33struct bottom {
34 bottom() {}
35};
36
37
38/* ================================= */
39/* interval */
40/* ================================= */
41
42
47class interval : public use_malloc {
48
49protected:
50 ap_interval_t c;
51
53 void init();
54
56 interval(ap_interval_t* i);
57
58 friend class abstract0;
59 friend class abstract1;
60 friend class linexpr0;
61 friend class texpr0;
62
63public:
64
66 enum order {
67 INCLUDED = -1,
68 EQUAL = 0,
70 LESS = -2,
71 GREATER = 2,
72 };
73
74
75 /* constructors */
76 /* ============ */
77
80
82 interval();
83
85 interval(const interval& x);
86
88 interval(const scalar& inf, const scalar& sup);
89
91 interval(int inf, int sup);
92
94 interval(long inf, long sup);
95
97 interval(double inf, double sup);
98
100 interval(const frac& inf, const frac& sup);
101
103 interval(const mpq_class& inf, const mpq_class& sup);
104
106 interval(mpfr_t inf, mpfr_t sup);
107
109 interval(top t);
110
112 interval(bottom t);
113
115
116
117 /* destructor */
118 /* ========== */
119
122
123 ~interval();
124
126
127
128 /* assignments */
129 /* =========== */
130
133
134 /* = */
135
137 interval& operator= (const interval& x);
138
141
144
145
146 /* set */
147
149 interval& set(const interval& x);
150
152 interval& set(const scalar& inf, const scalar& sup);
153
155 interval& set(int inf, int sup);
156
158 interval& set(long inf, long sup);
159
161 interval& set(double inf, double sup);
162
164 interval& set(const frac& inf, const frac& sup);
165
167 interval& set(const mpq_class& inf, const mpq_class& sup);
168
170 interval& set(mpfr_t inf, mpfr_t sup);
171
173 interval& set(top t);
174
176 interval& set(bottom t);
177
178
179 /* swap */
180
182 friend void swap(interval& a, interval &b);
183
185
186
187 /* access */
188 /* ====== */
189
192
194 scalar& get_inf();
195
197 scalar& get_sup();
198
200 const scalar& get_inf() const;
201
203 const scalar& get_sup() const;
204
206
207
208 /* print */
209 /* ===== */
210
213
215 friend std::ostream& operator<< (std::ostream& os, const interval& s);
216
218 void print(FILE* stream=stdout) const;
219
221
222
223 /* tests */
224 /* ===== */
225
228
230 bool is_top() const;
231
233 bool is_bottom() const;
234
236 friend bool operator<= (const interval&a, const interval &b);
237
239 friend bool operator>= (const interval&a, const interval &b);
240
242 friend bool operator< (const interval&a, const interval &b);
243
245 friend bool operator> (const interval&a, const interval &b);
246
248 friend bool operator== (const interval&a, const interval &b);
249
251 friend bool operator!= (const interval&a, const interval &b);
252
254 friend order cmp (const interval&a, const interval &b);
255
257
258
259 /* other operators */
260 /* =============== */
261
264
266 void neg();
267
269 interval operator- () const;
270
272 long hash() const;
273
275
276
277 /* C API compatibility */
278 /* =================== */
279
282
284 const ap_interval_t* get_ap_interval_t() const;
285
287 ap_interval_t* get_ap_interval_t();
288
290};
291
292
293
294
295/* ================================= */
296/* interval_array */
297/* ================================= */
298
299
303
304protected:
305
306 size_t sz;
307 ap_interval_t** c;
308
310 interval_array(size_t size, ap_interval_t** c);
311
312 friend class abstract0;
313 friend class abstract1;
314
315public:
316
317 /* constructors */
318 /* ============ */
319
322
327 interval_array(size_t size);
328
331
333 interval_array(const std::vector<interval>& x);
334
336 interval_array(size_t size, const interval x[]);
337
339
340
341 /* destructor */
342 /* ========== */
343
346
349
351
352
353 /* assignment */
354 /* ========== */
355
358
364
369 interval_array& operator= (const std::vector<interval>& x);
370
377
379
380
381 /* conversion */
382 /* ========== */
383
386
388 operator std::vector<interval>() const;
389
391
392
393 /* print */
394 /* ===== */
395
398
400 friend std::ostream& operator<< (std::ostream& os, const interval_array& s);
401
403 void print(FILE* stream=stdout) const;
404
406
407
408 /* access */
409 /* ====== */
410
413
415 size_t size() const;
416
418 interval** contents();
419
421 interval& operator[](size_t i);
422
424 const interval& operator[](size_t i) const;
425
430 interval& get(size_t i);
431
436 const interval& get(size_t i) const;
437
439
440
441 /* C-level compatibility */
442 /* ===================== */
443
446
448 const ap_interval_t * const * get_ap_interval_t_array() const;
449
451 ap_interval_t** get_ap_interval_t_array();
452
454};
455
456
458
459}
460
461#endif /* __APXX_INTERVAL_HH */
Level 0 abstract value (ap_abstract0_t* wrapper).
Definition: apxx_abstract0.hh:78
Level 1 abstract value (ap_abstract1_t wrapper).
Definition: apxx_abstract1.hh:42
array of interval(s).
Definition: apxx_interval.hh:302
size_t sz
Array size.
Definition: apxx_interval.hh:306
friend std::ostream & operator<<(std::ostream &os, const interval_array &s)
Printing.
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
friend bool operator<=(const interval &a, const interval &b)
Set inclusion.
friend std::ostream & operator<<(std::ostream &os, const interval &s)
Printing.
friend order cmp(const interval &a, const interval &b)
Interval ordering.
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
friend bool operator==(const interval &a, const interval &b)
Set equality.
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
friend bool operator>(const interval &a, const interval &b)
Strict set inclusion.
long hash() const
Returns a hash code.
Definition: apxx_interval_inline.hh:328
friend bool operator>=(const interval &a, const interval &b)
Set inclusion.
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
@ LESS
Means min i1 <= min i2.
Definition: apxx_interval.hh:70
@ INCLUDED
Means i1 is included in i2.
Definition: apxx_interval.hh:67
@ CONTAINS
Means i2 is included in i1.
Definition: apxx_interval.hh:69
@ GREATER
Means min i1 >= min i2.
Definition: apxx_interval.hh:71
@ EQUAL
Means i1 equals i2.
Definition: apxx_interval.hh:68
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
friend bool operator<(const interval &a, const interval &b)
Strict set inclusion.
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
friend void swap(interval &a, interval &b)
Swaps the contents of two intervals.
friend bool operator!=(const interval &a, const interval &b)
Set disequality.
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition: apxx_linexpr0.hh:44
Scalar (ap_scalar_t wrapper).
Definition: apxx_scalar.hh:89
Level 0 arbitrary expression tree (ap_texpr0_t wrapper).
Definition: apxx_texpr0.hh:92
Definition: apxx_abstract0.hh:27
Empty interval or domain, to simplify initialisations and assignments.
Definition: apxx_interval.hh:33
bottom()
Definition: apxx_interval.hh:34
A fraction with native int coefficients, to simplify initialisations and assignments.
Definition: apxx_scalar.hh:41
Full interval (]-oo,+oo[) or domain, to simplify initialisations and assignments.
Definition: apxx_interval.hh:27
top()
Definition: apxx_interval.hh:28
Inherited by most wrappers to map new and delete to malloc and free.
Definition: apxx_scalar.hh:69