APRONXX  0.9.12
/home/mine/apron/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 
25 namespace apron {
26 
27 
28 
29 /* ================================= */
30 /* linexpr0 */
31 /* ================================= */
32 
33 
44 class linexpr0 : public use_malloc {
45 
46 protected:
47 
48  ap_linexpr0_t l;
49 
51  linexpr0(ap_linexpr0_t* p);
52 
53  friend class texpr0_tmp;
54  friend class texpr0;
55 
56 public:
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);
146  void permute_dimensions(const dimperm& d);
147 
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();
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  /* ===== */
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
245  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
265 
266  /* iterators */
267  /* ========= */
269 
272 
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 
311  const_iterator(const const_iterator& i);
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);
363  friend class linexpr0;
364 
365 
366  public:
367 
369  iterator(linexpr0& e);
370 
372  iterator(const iterator& i);
373 
376 
381  coeff& get_coeff() const;
382 
383  };
384 
387 
389  const_iterator begin() const;
390 
392 
394  /* other operators */
395  /* =============== */
396 
399 
404  void minimize();
405 
407  long hash() const;
408 
410 
411 
412  /* TODO: evaluation, linearization, intelligent constructors */
413 
415  /* C-level compatibility */
416  /* ===================== */
417 
422  const ap_linexpr0_t* get_ap_linexpr0_t() const;
423 
425  ap_linexpr0_t* get_ap_linexpr0_t();
426 
428 
429 };
431 #include "apxx_linexpr0_inline.hh"
432 
433 }
434 
435 #endif /* __APXX_LINEXPR0_HH */
bool is_quasilinear() const
Whether all coefficients are scalar, except maybe the constant one.
Definition: apxx_linexpr0.hh:283
ap_linexpr0_t l
Structure managed by APRON.
Definition: apxx_linexpr0.hh:48
Dimension permutation object (ap_dimperm_t wrapper).
Definition: apxx_dimension.hh:292
Dimension change object (ap_dimchange_t wrapper).
Definition: apxx_dimension.hh:102
long hash() const
Returns a hash-code.
Definition: apxx_linexpr0.hh:450
const_iterator & operator=(const const_iterator &i)
Assigns the iterator.
Definition: apxx_linexpr0.hh:379
Definition: apxx_abstract0.hh:27
const coeff & get_coeff() const
Returns a reference to the coefficient at the current iterator position.
Definition: apxx_linexpr0.hh:400
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition: apxx_linexpr0.hh:179
void skip_AP_DIM_MAX()
Internal use only. Skips free coefficients in sparse expressions.
Definition: apxx_linexpr0.hh:343
bool valid() const
Whether we are at a valid position (true) or past the last iterator position (false).
Definition: apxx_linexpr0.hh:425
bool is_linear() const
Whether all coefficients are scalar.
Definition: apxx_linexpr0.hh:278
~linexpr0()
Frees all space for the expression and coefficients.
Definition: apxx_linexpr0.hh:121
linexpr0 & operator=(const linexpr0 &x)
Makes a (deep) copy.
Definition: apxx_linexpr0.hh:130
friend int compare(const linexpr0 &x, const linexpr0 &y)
Lexicography ordering, terminating with constant coefficients.
Definition: apxx_linexpr0.hh:288
friend std::ostream & operator<<(std::ostream &os, const linexpr0 &s)
Printing.
Definition: apxx_linexpr0.hh:230
coeff & get_coeff() const
Returns a (modifiable) reference to the coefficient at the current iterator position.
Definition: apxx_linexpr0.hh:407
friend class texpr0_tmp
Definition: apxx_linexpr0.hh:53
coeff & operator[](ap_dim_t dim)
Returns a (modifiable) reference to the coefficient corresponding to the given dimension.
Definition: apxx_linexpr0.hh:189
void resize(size_t size)
Changes the number of coefficients in the expression. (Useful only for dense expressions....
Definition: apxx_linexpr0.hh:144
ap_linexpr0_t * l
Internal use only. Pointer to the underlying APRON structure.
Definition: apxx_linexpr0.hh:294
ap_linexpr_discr_t get_discr() const
Returns the expression type.
Definition: apxx_linexpr0.hh:173
bool operator==(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:410
ap_linexpr_type_t get_type() const
Gets the type of the linear expression.
Definition: apxx_linexpr0.hh:273
iterator & operator=(const iterator &i)
Assigns the iterator.
Definition: apxx_linexpr0.hh:386
bool operator>(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:434
bool is_real(size_t intdim) const
Whether only dimensions strictly smaller than intdim have a non-zero coefficient.
Definition: apxx_linexpr0.hh:268
ap_dim_t pos
Internal use only. Current index.
Definition: apxx_linexpr0.hh:295
Iterator to traverse a constant linexpr0.
Definition: apxx_linexpr0.hh:286
Iterator to traverse and mutate a linear expression.
Definition: apxx_linexpr0.hh:352
ap_dim_t get_dim() const
Returns the dimension of the coefficient at the current iterator position.
Definition: apxx_linexpr0.hh:393
void minimize()
Minimizes all coefficients.
Definition: apxx_linexpr0.hh:445
void permute_dimensions(const dimperm &d)
Applies a permutation on coefficients.
Definition: apxx_linexpr0.hh:154
size_t size() const
Returns the number of coefficients in the expression.
Definition: apxx_linexpr0.hh:165
linexpr0(ap_linexpr0_t *p)
Internal use only. Shallow copy of structure followed by a free to take ownership of expression.
Definition: apxx_linexpr0.hh:61
Level 0 arbitrary expression tree (ap_texpr0_t wrapper).
Definition: apxx_texpr0.hh:92
bool operator>=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:429
Coefficient (ap_coeff_t wrapper).
Definition: apxx_coeff.hh:36
iterator begin()
Returns a new iterator to traverse and mutate the linear expression.
Definition: apxx_linexpr0.hh:430
linexpr0(const linexpr0 &x)
Makes a (deep) copy.
Definition: apxx_linexpr0.hh:71
void print(char **name_of_dim=NULL, FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_linexpr0.hh:254
bool operator!=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:417
Inherited by most wrappers to map new and delete to malloc and free.
Definition: apxx_scalar.hh:69
bool is_integer(size_t intdim) const
Whether only dimensions greater than intdim have a non-zero coefficient.
Definition: apxx_linexpr0.hh:263
void add_dimensions(const dimchange &d)
Adds some dimensions, shifting coefficients if needed.
Definition: apxx_linexpr0.hh:149
friend bool equal(const linexpr0 &x, const linexpr0 &y)
Structural, syntactical equality.
Definition: apxx_linexpr0.hh:294
iterator(ap_linexpr0_t *l)
Internal use only.
Definition: apxx_linexpr0.hh:367
bool operator<=(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:422
Represents a dimension (i.e., variable by index) in an expression tree.
Definition: apxx_texpr0.hh:33
const ap_linexpr0_t * get_ap_linexpr0_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition: apxx_linexpr0.hh:460
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition: apxx_linexpr0.hh:44
void next()
Moves the iterator to the following position.
Definition: apxx_linexpr0.hh:414
bool operator<(const abstract0 &x, const abstract0 &y)
Definition: apxx_abstract0.hh:439
const_iterator(ap_linexpr0_t *l)
Internal use only.
Definition: apxx_linexpr0.hh:349
void operator++()
Moves the iterator to the following position.
Definition: apxx_linexpr0.hh:420