APRONXX 0.9.14
/builddir/build/BUILD/apron-0.9.15-build/apron-0.9.15/apronxx/apxx_linexpr0.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_linexpr0.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_LINEXPR0_HH
17#define __APXX_LINEXPR0_HH
18
19#include "ap_linexpr0.h"
20#include "ap_linearize.h"
21#include "apxx_coeff.hh"
22#include "apxx_dimension.hh"
23
24
25namespace apron {
26
27
28
29/* ================================= */
30/* linexpr0 */
31/* ================================= */
32
33
44class linexpr0 : public use_malloc {
45
46protected:
47
48 ap_linexpr0_t l;
49
51 linexpr0(ap_linexpr0_t* p);
52
53 friend class texpr0_tmp;
54 friend class texpr0;
55
56public:
57
58
59 /* constructors */
60 /* ============ */
61
64
70 linexpr0(ap_linexpr_discr_t discr=AP_LINEXPR_SPARSE, size_t size=0);
71
73 linexpr0(const linexpr0& x);
74
76 linexpr0(const linexpr0& x, const dimchange& d);
77
79 linexpr0(const linexpr0& x, const dimperm& d);
80
87 linexpr0(size_t size, const coeff coeffs[], const coeff& cst, ap_linexpr_discr_t discr=AP_LINEXPR_SPARSE);
88
95 linexpr0(const std::vector<coeff>& coeffs, const coeff& cst, ap_linexpr_discr_t discr=AP_LINEXPR_SPARSE);
96
104 linexpr0(size_t size, const coeff coeffs[], const ap_dim_t dims[], const coeff& cst);
105
107
108
109 /* destructor */
110 /* ========== */
111
114
116 ~linexpr0();
117
119
120
121 /* assignment */
122 /* ========== */
123
126
128 linexpr0& operator= (const linexpr0& x);
129
131
132
133 /* dimension operations */
134 /* ==================== */
135
138
140 void resize(size_t size);
141
143 void add_dimensions(const dimchange& d);
144
146 void permute_dimensions(const dimperm& d);
147
149
150
151 /* access */
152 /* ====== */
153
156
157 /* size */
158
160 size_t size() const;
161
162
163 /* get */
164
169 ap_linexpr_discr_t get_discr() const;
170
172 coeff& get_cst();
173
175 const coeff& get_cst() const;
176
186 coeff& operator[](ap_dim_t dim);
187
189 const coeff& operator[](ap_dim_t dim) const;
190
192
193
194 /* print */
195 /* ===== */
196
199
204 friend std::ostream& operator<< (std::ostream& os, const linexpr0& s);
205
207 void print(char** name_of_dim = NULL, FILE* stream=stdout) const;
208
210
211
212 /* tests */
213 /* ===== */
214
217
219 bool is_integer(size_t intdim) const;
220
222 bool is_real(size_t intdim) const;
223
230 ap_linexpr_type_t get_type() const;
231
233 bool is_linear() const;
234
236 bool is_quasilinear() const;
237
239 friend int compare(const linexpr0& x, const linexpr0& y);
240
242 friend bool equal(const linexpr0& x, const linexpr0& y);
243
244#if 0 // overloaded to make constraints
246 friend bool operator>= (const linexpr0& x, const linexpr0& y);
247
249 friend bool operator<= (const linexpr0& x, const linexpr0& y);
250
252 friend bool operator> (const linexpr0& x, const linexpr0& y);
253
255 friend bool operator< (const linexpr0& x, const linexpr0& y);
256
258 friend bool operator== (const linexpr0& x, const linexpr0& y);
259
261 friend bool operator!= (const linexpr0& x, const linexpr0& y);
262#endif
263
265
266 /* iterators */
267 /* ========= */
268
269
272
273
287
288 /* TODO:
289 - reverse traversal (operator--).
290 */
291
292 protected:
293
294 ap_linexpr0_t* l;
295 ap_dim_t pos;
296
298 void skip_AP_DIM_MAX();
299
301 const_iterator(ap_linexpr0_t* l);
302
303 friend class linexpr0;
304
305 public:
306
308 const_iterator(const linexpr0& e);
309
312
315
320 ap_dim_t get_dim() const;
321
326 const coeff& get_coeff() const;
327
329 void next();
330
335 void operator++();
336
338 bool valid() const;
339
340 };
341
342
352 class iterator : public const_iterator {
353
354 /* TODO:
355 - removing/inserting coefficients at iterator position for sparse expressions.
356 */
357
358 protected:
359
361 iterator(ap_linexpr0_t* l);
362
363 friend class linexpr0;
364
365
366 public:
367
369 iterator(linexpr0& e);
370
372 iterator(const iterator& i);
373
375 iterator& operator=(const iterator& i);
376
381 coeff& get_coeff() const;
382
383 };
384
386 iterator begin();
387
389 const_iterator begin() const;
390
392
393
394 /* other operators */
395 /* =============== */
396
399
404 void minimize();
405
407 long hash() const;
408
410
411
412 /* TODO: evaluation, linearization, intelligent constructors */
413
414
415 /* C-level compatibility */
416 /* ===================== */
417
420
422 const ap_linexpr0_t* get_ap_linexpr0_t() const;
423
425 ap_linexpr0_t* get_ap_linexpr0_t();
426
428
429};
430
432
433}
434
435#endif /* __APXX_LINEXPR0_HH */
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:416
Coefficient (ap_coeff_t wrapper).
Definition apxx_coeff.hh:36
Represents a dimension (i.e., variable by index) in an expression tree.
Definition apxx_texpr0.hh:33
Dimension change object (ap_dimchange_t wrapper).
Definition apxx_dimension.hh:102
Dimension permutation object (ap_dimperm_t wrapper).
Definition apxx_dimension.hh:292
Iterator to traverse a constant linexpr0.
Definition apxx_linexpr0.hh:286
void operator++()
Moves the iterator to the following position.
Definition apxx_linexpr0_inline.hh:419
ap_dim_t pos
Internal use only. Current index.
Definition apxx_linexpr0.hh:295
void skip_AP_DIM_MAX()
Internal use only. Skips free coefficients in sparse expressions.
Definition apxx_linexpr0_inline.hh:342
ap_linexpr0_t * l
Internal use only. Pointer to the underlying APRON structure.
Definition apxx_linexpr0.hh:294
const_iterator & operator=(const const_iterator &i)
Assigns the iterator.
Definition apxx_linexpr0_inline.hh:378
ap_dim_t get_dim() const
Returns the dimension of the coefficient at the current iterator position.
Definition apxx_linexpr0_inline.hh:392
void next()
Moves the iterator to the following position.
Definition apxx_linexpr0_inline.hh:413
bool valid() const
Whether we are at a valid position (true) or past the last iterator position (false).
Definition apxx_linexpr0_inline.hh:424
const_iterator(ap_linexpr0_t *l)
Internal use only.
const coeff & get_coeff() const
Returns a reference to the coefficient at the current iterator position.
Definition apxx_linexpr0_inline.hh:399
Iterator to traverse and mutate a linear expression.
Definition apxx_linexpr0.hh:352
iterator & operator=(const iterator &i)
Assigns the iterator.
Definition apxx_linexpr0_inline.hh:385
iterator(ap_linexpr0_t *l)
Internal use only.
coeff & get_coeff() const
Returns a (modifiable) reference to the coefficient at the current iterator position.
Definition apxx_linexpr0_inline.hh:406
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition apxx_linexpr0.hh:44
void minimize()
Minimizes all coefficients.
Definition apxx_linexpr0_inline.hh:444
~linexpr0()
Frees all space for the expression and coefficients.
Definition apxx_linexpr0_inline.hh:120
linexpr0(ap_linexpr0_t *p)
Internal use only. Shallow copy of structure followed by a free to take ownership of expression.
Definition apxx_linexpr0_inline.hh:60
iterator begin()
Returns a new iterator to traverse and mutate the linear expression.
Definition apxx_linexpr0_inline.hh:429
bool is_integer(size_t intdim) const
Whether only dimensions greater than intdim have a non-zero coefficient.
Definition apxx_linexpr0_inline.hh:262
coeff & operator[](ap_dim_t dim)
Returns a (modifiable) reference to the coefficient corresponding to the given dimension.
Definition apxx_linexpr0_inline.hh:188
friend int compare(const linexpr0 &x, const linexpr0 &y)
Lexicography ordering, terminating with constant coefficients.
bool is_linear() const
Whether all coefficients are scalar.
Definition apxx_linexpr0_inline.hh:277
ap_linexpr_type_t get_type() const
Gets the type of the linear expression.
Definition apxx_linexpr0_inline.hh:272
friend class texpr0_tmp
Definition apxx_linexpr0.hh:53
bool is_real(size_t intdim) const
Whether only dimensions strictly smaller than intdim have a non-zero coefficient.
Definition apxx_linexpr0_inline.hh:267
linexpr0 & operator=(const linexpr0 &x)
Makes a (deep) copy.
Definition apxx_linexpr0_inline.hh:129
friend bool equal(const linexpr0 &x, const linexpr0 &y)
Structural, syntactical equality.
void resize(size_t size)
Changes the number of coefficients in the expression. (Useful only for dense expressions....
Definition apxx_linexpr0_inline.hh:143
void print(char **name_of_dim=NULL, FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_linexpr0_inline.hh:253
friend std::ostream & operator<<(std::ostream &os, const linexpr0 &s)
Printing.
bool is_quasilinear() const
Whether all coefficients are scalar, except maybe the constant one.
Definition apxx_linexpr0_inline.hh:282
long hash() const
Returns a hash-code.
Definition apxx_linexpr0_inline.hh:449
size_t size() const
Returns the number of coefficients in the expression.
Definition apxx_linexpr0_inline.hh:164
const ap_linexpr0_t * get_ap_linexpr0_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_linexpr0_inline.hh:459
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition apxx_linexpr0_inline.hh:178
void permute_dimensions(const dimperm &d)
Applies a permutation on coefficients.
Definition apxx_linexpr0_inline.hh:153
ap_linexpr_discr_t get_discr() const
Returns the expression type.
Definition apxx_linexpr0_inline.hh:172
ap_linexpr0_t l
Structure managed by APRON.
Definition apxx_linexpr0.hh:48
void add_dimensions(const dimchange &d)
Adds some dimensions, shifting coefficients if needed.
Definition apxx_linexpr0_inline.hh:148
Level 0 arbitrary expression tree (ap_texpr0_t wrapper).
Definition apxx_texpr0.hh:92
Definition apxx_abstract0.hh:27
Inherited by most wrappers to map new and delete to malloc and free.
Definition apxx_scalar.hh:69