APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_coeff.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_coeff.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_COEFF_HH
17#define __APXX_COEFF_HH
18
19#include "ap_coeff.h"
20#include "apxx_scalar.hh"
21#include "apxx_interval.hh"
22
23
24namespace apron {
25
26
27/* ================================= */
28/* coeff */
29/* ================================= */
30
31
32
33 *
34 * A coeff is either a scalar or an interval.
35 */
36class coeff : public use_malloc {
37
38protected:
39
40 ap_coeff_t c;
41
42public:
43
44
45 /* constructors */
46 /* ============ */
47
48 /** @name Constructors */
50
52 coeff();
53
54 //! Makes a copy of a coeff.
55 coeff(const coeff& x);
56
58 coeff(const scalar& x);
59
60 //! Makes a MPQ scalar coeff from a native integer.
61 coeff(int x);
62
64 coeff(long x);
65
66 //! Makes a double scalar coeff from a double.
67 coeff(double x);
68
70 coeff(const frac& x);
71
72 //! Makes a MPQ scalar coeff from a MPQ (copied).
73 coeff(const mpq_class& x);
74
76 coeff(mpfr_t x);
77
78 //! Makes an interval coeff from an interval (copied).
79 coeff(const interval& x);
80
82 coeff(const scalar& inf, const scalar& sup);
83
85 coeff(int inf, int sup);
86
87 //! Makes an interval coeff with MPQ bounds from native integer bounds.
88 coeff(long inf, long sup);
89
91 coeff(double inf, double sup);
92
93
94 coeff(const frac& inf, const frac& sup);
95
97 coeff(const mpq_class& inf, const mpq_class& sup);
98
100 coeff(mpfr_t inf, mpfr_t sup);
101
102 //! Makes an interval coeff representing ]-oo,+oo[.
103 coeff(top t);
104
106 coeff(bottom t);
107
108 //@}
109
110
111 /* destructor */
112 /* ========== */
113
114 /** @name Destructor */
116
117 ~coeff();
118
119
121
122 /* assignments */
123 /* =========== */
124
125
126 //@{
127
129 coeff& operator= (const coeff& x);
130
132 coeff& operator= (const scalar& x);
133
134 //! Assigns a native integer to *this, setting its type to MPQ scalar coeff.
135 coeff& operator= (int x);
136
138 coeff& operator= (long x);
139
140 //! Assigns a double to *this, setting its type to double scalar coeff.
141 coeff& operator= (double x);
142
144 coeff& operator= (const frac& x);
145
146 //! Assigns a MPQ to *this, setting its type to MPQ scalar coeff and copying the MPQ.
147 coeff& operator= (const mpq_class& x);
148
150 coeff& operator= (mpfr_t x);
151
153 coeff& operator= (const interval& x);
154
160
162 coeff& set(const coeff& x);
163
165 coeff& set(const scalar& x);
166
168 coeff& set(int x);
169
170
171 coeff& set(long x);
172
174 coeff& set(double x) ;
175
176
177 coeff& set(const frac& x);
178
180 coeff& set(const mpq_class& x);
181
182
183 coeff& set(mpfr_t x);
184
186 coeff& set(const interval& x);
187
188
189 coeff& set(const scalar& inf, const scalar& sup);
190
192 coeff& set(int inf, int sup);
193
194
195 coeff& set(long inf, long sup);
196
198 coeff& set(double inf, double sup);
199
200
201 coeff& set(const frac& inf, const frac& sup);
202
204 coeff& set(const mpq_class& inf, const mpq_class& sup);
205
206
207 coeff& set(mpfr_t inf, mpfr_t sup);
208
210 coeff& set(top t);
211
212
214
215
217 friend void swap(coeff& a, coeff &b);
218
219 //@}
220
221
222 /* access */
223 /* ====== */
224
225 /** @name Accesses */
227
230
232 ap_coeff_discr_t get_discr() const;
233
236 * \throw bad_discriminant when the coeff is not of scalar type
237 */
239
240
242 * \throw bad_discriminant when the coeff is not of scalar type
243 */
244 const scalar& get_scalar() const;
245
246
247 /*! \brief Returns a (modifiable) reference to the interval contained in the coeff.
248 *
249 * \throw bad_discriminant when the coeff is not of interval type
250 */
252
253 /*! \brief Returns a reference to the interval contained in the coeff.
254 *
255 * \throw bad_discriminant when the coeff is not of interval type
256 */
257 const interval& get_interval() const;
258
259 //@}
260
261
262 /* print */
263 /* ===== */
264
266 //@{
267
269 friend std::ostream& operator<< (std::ostream& os, const coeff& s);
270
271
272 void print(FILE* stream=stdout) const;
273
275
276
277 /* tests */
278 /* ===== */
279
282
283
284 bool is_zero() const;
285
287 friend int cmp(const coeff& a, const coeff& b);
288
289 /*
290 //! Set inclusion.
291 friend bool operator<= (const coeff& a, const coeff& b);
292
294 friend bool operator>= (const coeff& a, const coeff& b);
295
296 //! Strict set inclusion.
297 friend bool operator< (const coeff& a, const coeff& b);
298
300 friend bool operator> (const coeff& a, const coeff& b);
301 */
304 friend bool operator== (const coeff& a, const coeff& b);
305
307 friend bool operator!= (const coeff& a, const coeff& b);
310
311
312 /* other operators */
313 /* =============== */
314
315 /** @name Operators */
317
319 void reduce();
320
321 //! Negates *this.
322 void neg();
323
325 coeff operator- () const;
326
328 long hash() const;
331
332
333 /* C-level compatibility */
334 /* ===================== */
338
340 const ap_coeff_t* get_ap_coeff_t() const;
343 ap_coeff_t* get_ap_coeff_t();
344
346};
348#include "apxx_coeff_inline.hh"
349
350}
351
352#endif /* __APXX_COEFF_HH */
scalar & get_scalar()
Returns a (modifiable) reference to the scalar contained in the coeff.
Definition apxx_coeff.hh:241
friend bool operator!=(const coeff &a, const coeff &b)
Set inequality.
Definition apxx_coeff.hh:450
coeff & operator=(const coeff &x)
Copies the coeff into *this (setting its type and value).
Definition apxx_coeff.hh:165
long hash() const
Returns a hash code.
Definition apxx_coeff.hh:476
ap_coeff_discr_t get_discr() const
Whether the coeff is a scalar or an interval.
Definition apxx_coeff.hh:236
coeff & set(const coeff &x)
Copies the coeff into *this (setting its type and value).
Definition apxx_coeff.hh:266
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_coeff.hh:401
~coeff()
Definition apxx_coeff.hh:156
friend bool operator==(const coeff &a, const coeff &b)
Set equality.
Definition apxx_coeff.hh:445
coeff(const mpq_class &x)
Makes a MPQ scalar coeff from a MPQ (copied).
Definition apxx_coeff.hh:72
coeff(const frac &x)
Makes a MPQ scalar coeff from a fraction with native integer coefficients.
Definition apxx_coeff.hh:66
void neg()
Negates *this.
Definition apxx_coeff.hh:466
friend std::ostream & operator<<(std::ostream &os, const coeff &s)
Printing.
Definition apxx_coeff.hh:392
friend int cmp(const coeff &a, const coeff &b)
Non-total comparison.
Definition apxx_coeff.hh:415
bool is_zero() const
Whether the coeff is the scalar 0 or the interval [0;0].
Definition apxx_coeff.hh:410
coeff()
Makes a double scalar coeff equal to 0.0.
Definition apxx_coeff.hh:28
void reduce()
Converts a singleton intervals to scalar.
Definition apxx_coeff.hh:461
const ap_coeff_t * get_ap_coeff_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_coeff.hh:484
interval & get_interval()
Returns a (modifiable) reference to the interval contained in the coeff.
Definition apxx_coeff.hh:253
coeff operator-() const
Returns the opposite of *this.
Definition apxx_coeff.hh:471
ap_coeff_t c
Structure managed by APRON.
Definition apxx_coeff.hh:40
friend void swap(coeff &a, coeff &b)
Swaps the contents and type of both coeff.
Definition apxx_coeff.hh:382
Interval (ap_interval_t wrapper).
Definition apxx_interval.hh:47
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
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
Inherited by most wrappers to map new and delete to malloc and free.
Definition apxx_scalar.hh:69