APRONXX 0.9.15
/home/mine/apron/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/* ================================= */
42
45
46 */
47class interval : public use_malloc {
48
49protected:
50 ap_interval_t c;
51
52 //! Internal initialisation.
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
65
66 enum order {
67 INCLUDED = -1,
68 EQUAL = 0,
70 LESS = -2,
71 GREATER = 2,
72 };
73
74
75 /* constructors */
76 /* ============ */
77
78 /** @name Constructors */
80
82 interval();
83
84 //! Makes a copy of an interval (bounds are copied).
85 interval(const interval& x);
86
88 interval(const scalar& inf, const scalar& sup);
89
91 interval(int inf, int sup);
94 interval(long inf, long sup);
95
97 interval(double inf, double sup);
100 interval(const frac& inf, const frac& sup);
101
103 interval(const mpq_class& inf, const mpq_class& sup);
106 interval(mpfr_t inf, mpfr_t sup);
107
109 interval(top t);
110
112 interval(bottom t);
113
114 //@}
115
116
117 /* destructor */
118 /* ========== */
119
122
123 ~interval();
124
127
128 /* assignments */
129 /* =========== */
130
131
132 //@{
133
134 /* = */
135
137 interval& operator= (const interval& x);
141
144
145
146 /* set */
149 interval& set(const interval& x);
150
152 interval& set(const scalar& inf, const scalar& sup);
155 interval& set(int inf, int sup);
156
158 interval& set(long inf, long sup);
159
160
161 interval& set(double inf, double sup);
162
164 interval& set(const frac& inf, const frac& sup);
165
166
167 interval& set(const mpq_class& inf, const mpq_class& sup);
168
170 interval& set(mpfr_t inf, mpfr_t sup);
171
172
174
176 interval& set(bottom t);
177
178
179 /* swap */
180
182 friend void swap(interval& a, interval &b);
183
184
186
187 /* access */
188 /* ====== */
189
192
193 //! Gets a (modifiable) reference to the lower bound.
194 scalar& get_inf();
195
197 scalar& get_sup();
198
199 //! Gets a reference to the lower bound.
200 const scalar& get_inf() const;
201
203 const scalar& get_sup() const;
204
205 //@}
206
207
208 /* print */
209 /* ===== */
210
213
214 //! Printing.
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
227
230 bool is_top() const;
231
232
233 bool is_bottom() const;
234
236 friend bool operator<= (const interval&a, const interval &b);
237
238 //! Set inclusion.
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
247 //! Set equality.
248 friend bool operator== (const interval&a, const interval &b);
249
251 friend bool operator!= (const interval&a, const interval &b);
254 friend order cmp (const interval&a, const interval &b);
255
256
257
258
259 /* other operators */
260 /* =============== */
264
265
266 void neg();
267
269 interval operator- () const;
270
271 //! Returns a hash code.
272 long hash() const;
273
275
276
277 /* C API compatibility */
278 /* =================== */
279
282
283 //! Returns a pointer to the internal APRON object stored in *this.
284 const ap_interval_t* get_ap_interval_t() const;
285
287 ap_interval_t* get_ap_interval_t();
288
289 //@}
290};
291
292
293
294
295/* ================================= */
296/* interval_array */
297/* ================================= */
298
299
300
301 */
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
321
327 interval_array(size_t size);
328
329 //! Makes a copy of an interval array (copying all elements).
331
333 interval_array(const std::vector<interval>& x);
334
336 interval_array(size_t size, const interval x[]);
339
340
341 /* destructor */
342 /* ========== */
343
346
349
351
352
353 /* assignment */
354 /* ========== */
355
356 /** @name Assignments */
358
359
367
368 */
369 interval_array& operator= (const std::vector<interval>& x);
370
374
375 */
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
417 //! Returns a pointer to the start of the array of elements used internally.
418 interval** contents();
419
421 interval& operator[](size_t i);
422
424 const interval& operator[](size_t i) const;
425
428
429 */
430 interval& get(size_t i);
431
435
436 const interval& get(size_t i) const;
437
439
441 /* C-level compatibility */
442 /* ===================== */
443
446
447
448 const ap_interval_t * const * get_ap_interval_t_array() const;
449
451 ap_interval_t** get_ap_interval_t_array();
454};
455
456
458
459}
461#endif /* __APXX_INTERVAL_HH */
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.hh:356
size_t sz
Array size.
Definition apxx_interval.hh:306
friend class abstract0
Definition apxx_interval.hh:312
friend std::ostream & operator<<(std::ostream &os, const interval_array &s)
Printing.
Definition apxx_interval.hh:452
interval ** contents()
Returns a pointer to the start of the array of elements used internally.
Definition apxx_interval.hh:477
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.hh:506
interval_array & operator=(const interval_array &x)
Copies an interval array into *this.
Definition apxx_interval.hh:403
size_t size() const
Returns the array size.
Definition apxx_interval.hh:474
interval & get(size_t i)
Definition apxx_interval.hh:480
~interval_array()
Frees the space occupied by the array and all its elements.
Definition apxx_interval.hh:394
friend class abstract1
Definition apxx_interval.hh:313
interval & operator[](size_t i)
Returns a (modifiable) reference to an element, no bound checking.
Definition apxx_interval.hh:492
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_interval.hh:460
Interval (ap_interval_t wrapper).
Definition apxx_interval.hh:47
void neg()
Negates *this.
Definition apxx_interval.hh:317
bool is_top() const
Whether *this equals ]-oo;+oo[.
Definition apxx_interval.hh:261
friend class abstract0
Definition apxx_interval.hh:58
friend bool operator<=(const interval &a, const interval &b)
Set inclusion.
Definition apxx_interval.hh:271
interval(bottom t)
Makes a new empty interval [+1;-1].
Definition apxx_interval.hh:104
friend std::ostream & operator<<(std::ostream &os, const interval &s)
Printing.
Definition apxx_interval.hh:247
interval(ap_interval_t *i)
Internal use only. Take ownership of an object created by ap_interval_alloc.
Definition apxx_interval.hh:35
friend order cmp(const interval &a, const interval &b)
Interval ordering.
Definition apxx_interval.hh:307
interval & set(const interval &x)
Copies an interval into *this.
Definition apxx_interval.hh:147
scalar & get_inf()
Gets a (modifiable) reference to the lower bound.
Definition apxx_interval.hh:223
friend bool operator==(const interval &a, const interval &b)
Set equality.
Definition apxx_interval.hh:295
friend class texpr0
Definition apxx_interval.hh:61
void init()
Internal initialisation.
Definition apxx_interval.hh:29
interval & operator=(const interval &x)
Copies an interval into *this.
Definition apxx_interval.hh:126
friend bool operator>(const interval &a, const interval &b)
Strict set inclusion.
Definition apxx_interval.hh:289
long hash() const
Returns a hash code.
Definition apxx_interval.hh:329
friend bool operator>=(const interval &a, const interval &b)
Set inclusion.
Definition apxx_interval.hh:277
interval operator-() const
Returns a new interval which is the opposite of *this.
Definition apxx_interval.hh:322
scalar & get_sup()
Gets a (modifiable) reference to the upper bound.
Definition apxx_interval.hh:228
~interval()
Definition apxx_interval.hh:114
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.hh:266
interval()
Makes a new interval [0,0] with double bounds.
Definition apxx_interval.hh:41
friend class abstract1
Definition apxx_interval.hh:59
friend bool operator<(const interval &a, const interval &b)
Strict set inclusion.
Definition apxx_interval.hh:283
const ap_interval_t * get_ap_interval_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_interval.hh:337
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_interval.hh:252
ap_interval_t c
Structure managed by APRON.
Definition apxx_interval.hh:50
friend class linexpr0
Definition apxx_interval.hh:60
friend void swap(interval &a, interval &b)
Swaps the contents of two intervals.
Definition apxx_interval.hh:214
friend bool operator!=(const interval &a, const interval &b)
Set disequality.
Definition apxx_interval.hh:301
Scalar (ap_scalar_t wrapper).
Definition apxx_scalar.hh:89
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