APRONXX  0.9.12
/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 
24 namespace apron {
25 
27 struct top {
28  top() {}
29 };
30 
31 
33 struct bottom {
34  bottom() {}
35 };
36 
37 
38 /* ================================= */
39 /* interval */
40 /* ================================= */
41 
42 
47 class interval : public use_malloc {
48 
49 protected:
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 
63 public:
64 
66  enum order {
67  INCLUDED = -1,
68  EQUAL = 0,
69  CONTAINS = 1,
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);
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 
127 
128  /* assignments */
129  /* =========== */
130 
133 
134  /* = */
135 
137  interval& operator= (const interval& x);
140  interval& operator= (top t);
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 
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 
174 
176  interval& set(bottom t);
177 
178 
179  /* swap */
180 
182  friend void swap(interval& a, interval &b);
183 
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 
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);
254  friend order cmp (const interval&a, const interval &b);
255 
257 
258 
259  /* other operators */
260  /* =============== */
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 
302 class interval_array : public use_malloc {
303 
304 protected:
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 
315 public:
316 
317  /* constructors */
318  /* ============ */
319 
327  interval_array(size_t size);
328 
330  interval_array(const interval_array &x);
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 
348  ~interval_array();
349 
351 
352 
353  /* assignment */
354  /* ========== */
355 
358 
369  interval_array& operator= (const std::vector<interval>& x);
370 
376  interval_array& operator= (const interval x[]);
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 
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();
454 };
455 
456 
457 #include "apxx_interval_inline.hh"
458 
459 }
461 #endif /* __APXX_INTERVAL_HH */
Means i2 is included in i1.
Definition: apxx_interval.hh:69
interval & set(const interval &x)
Copies an interval into *this.
Definition: apxx_interval.hh:147
Definition: apxx_abstract0.hh:27
top()
Definition: apxx_interval.hh:28
interval & get(size_t i)
Definition: apxx_interval.hh:480
friend bool operator!=(const interval &a, const interval &b)
Set disequality.
Definition: apxx_interval.hh:301
interval(bottom t)
Makes a new empty interval [+1;-1].
Definition: apxx_interval.hh:104
~interval_array()
Frees the space occupied by the array and all its elements.
Definition: apxx_interval.hh:394
Means i1 is included in i2.
Definition: apxx_interval.hh:67
friend bool operator<(const interval &a, const interval &b)
Strict set inclusion.
Definition: apxx_interval.hh:283
array of interval(s).
Definition: apxx_interval.hh:302
friend bool operator<=(const interval &a, const interval &b)
Set inclusion.
Definition: apxx_interval.hh:271
Level 0 abstract value (ap_abstract0_t* wrapper).
Definition: apxx_abstract0.hh:78
friend bool operator==(const interval &a, const interval &b)
Set equality.
Definition: apxx_interval.hh:295
~interval()
Definition: apxx_interval.hh:114
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()
Makes a new interval [0,0] with double bounds.
Definition: apxx_interval.hh:41
size_t sz
Array size.
Definition: apxx_interval.hh:306
interval_array & operator=(const interval_array &x)
Copies an interval array into *this.
Definition: apxx_interval.hh:403
ap_interval_t c
Structure managed by APRON.
Definition: apxx_interval.hh:50
bool is_bottom() const
Whether *this represents an empty interval.
Definition: apxx_interval.hh:266
friend bool operator>=(const interval &a, const interval &b)
Set inclusion.
Definition: apxx_interval.hh:277
scalar & get_inf()
Gets a (modifiable) reference to the lower bound.
Definition: apxx_interval.hh:223
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
Means min i1 >= min i2.
Definition: apxx_interval.hh:71
void init()
Internal initialisation.
Definition: apxx_interval.hh:29
bool is_top() const
Whether *this equals ]-oo;+oo[.
Definition: apxx_interval.hh:261
void neg()
Negates *this.
Definition: apxx_interval.hh:317
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_interval.hh:252
Level 0 arbitrary expression tree (ap_texpr0_t wrapper).
Definition: apxx_texpr0.hh:92
order
Returned by ordering functions.
Definition: apxx_interval.hh:66
Empty interval or domain, to simplify initialisations and assignments.
Definition: apxx_interval.hh:33
Level 1 abstract value (ap_abstract1_t wrapper).
Definition: apxx_abstract1.hh:42
Full interval (]-oo,+oo[) or domain, to simplify initialisations and assignments.
Definition: apxx_interval.hh:27
long hash() const
Returns a hash code.
Definition: apxx_interval.hh:329
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
Inherited by most wrappers to map new and delete to malloc and free.
Definition: apxx_scalar.hh:69
A fraction with native int coefficients, to simplify initialisations and assignments.
Definition: apxx_scalar.hh:41
friend bool operator>(const interval &a, const interval &b)
Strict set inclusion.
Definition: apxx_interval.hh:289
friend void swap(interval &a, interval &b)
Swaps the contents of two intervals.
Definition: apxx_interval.hh:214
interval & operator=(const interval &x)
Copies an interval into *this.
Definition: apxx_interval.hh:126
size_t size() const
Returns the array size.
Definition: apxx_interval.hh:474
Means i1 equals i2.
Definition: apxx_interval.hh:68
interval operator-() const
Returns a new interval which is the opposite of *this.
Definition: apxx_interval.hh:322
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
scalar & get_sup()
Gets a (modifiable) reference to the upper bound.
Definition: apxx_interval.hh:228
interval & operator[](size_t i)
Returns a (modifiable) reference to an element, no bound checking.
Definition: apxx_interval.hh:492
bottom()
Definition: apxx_interval.hh:34
Means min i1 <= min i2.
Definition: apxx_interval.hh:70
friend std::ostream & operator<<(std::ostream &os, const interval_array &s)
Printing.
Definition: apxx_interval.hh:452
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition: apxx_linexpr0.hh:44
friend std::ostream & operator<<(std::ostream &os, const interval &s)
Printing.
Definition: apxx_interval.hh:247
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
Scalar (ap_scalar_t wrapper).
Definition: apxx_scalar.hh:89
friend order cmp(const interval &a, const interval &b)
Interval ordering.
Definition: apxx_interval.hh:307