APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_linexpr1.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_linexpr1.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_LINEXPR1_HH
17#define __APXX_LINEXPR1_HH
18
19#include "ap_linexpr1.h"
20#include "apxx_environment.hh"
21#include "apxx_linexpr0.hh"
22
23
24namespace apron {
25
26
27/* ================================= */
28/* linexpr1 */
29/* ================================= */
30
31
32
33 *
34 * Level 1 version of linear expressions with scalar or interval coefficients (coeff).
35 * Terms are indexed using variable names (var) instead of dimensions (ap_dim_t).
36 * Internally, a linexpr1 wraps together a linexpr0 (memory managed) and an environment (holding a
37 * reference count).
38 */
39class linexpr1 : public use_malloc {
40
41protected:
42
43 ap_linexpr1_t l;
44
45 //! Internal use only. Shallow copy (no copy of linexpr0 or environment).
46 linexpr1(ap_linexpr1_t& p);
47
48
49public:
51
52 /* constructors */
53 /* ============ */
54
57
58
61 linexpr1(const environment& e, const linexpr0& x);
62
64 *
65 * \arg \c e associates a variable name to each dimension.
66 * \arg \c discr whether the expression is sparse (\c AP_LINEXPR_SPARSE) or dense (\c AP_LINEXPR_DENSE).
67 * \arg \c size, for \c AP_LINEXPR_SPARSE expressions, is the initial number of dimensions in the
68 * underlying linexpr0 (new dimensions being added as needed); ignored for \c AP_LINEXPR_DENSE
69 * expressions (the size being always the size of the environment).
70 */
71 linexpr1(const environment& e, ap_linexpr_discr_t lin_discr=AP_LINEXPR_SPARSE, size_t size=0);
72
73 //! Makes a (deep) copy.
74 linexpr1(const linexpr1& x);
75
80 linexpr1(const linexpr1& x, const environment& e);
81
83
84
85 /* destructor */
86 /* ========== */
87
90
92
94 ~linexpr1();
95
97
99 /* assignment */
100 /* ========== */
101
102
103 //@{
104
106 linexpr1& operator= (const linexpr1& x);
107
108 //@}
109
110
111 /* dimension operations */
112 /* ==================== */
116
117
119 * \throw std::invalid_argument if e is not a super-environment of that of *this.
120 */
121 void extend_environment(const environment& e);
122
123 //@}
124
125
126 /* access */
127 /* ====== */
131
132
134
136 const linexpr0& get_linexpr0() const;
137
140
141 //! Returns the number of coefficients in the expression.
142 size_t size() const;
143
148 ap_linexpr_discr_t get_discr() const;
149
151 coeff& get_cst();
152
153 //! Returns a reference to the constant coefficient.
154 const coeff& get_cst() const;
155
160 coeff& operator[](const var& v);
161
164
165 */
166 const coeff& operator[](const var& v) const;
167
169
170
171 /* print */
172 /* ===== */
173
174 /** @name Printing */
176
178 friend std::ostream& operator<< (std::ostream& os, const linexpr1& s);
181 void print(FILE* stream=stdout) const;
182
183
185
186 /* tests */
187 /* ===== */
188
189 /** @name Tests */
191
193 bool is_integer() const;
196 bool is_real() const;
197
198
203 */
204 ap_linexpr_type_t get_type() const;
205
207 bool is_linear() const;
208
209 //! Whether all coefficients are scalar, except maybe the constant one.
210 bool is_quasilinear() const;
211
212
213 // TODO: equal, compare (currently not in ap_linexpr1.h) ???
214
217
218 /* iterators */
219 /* ========= */
220
221
222 //@{
223
225
227 * The expression is traversed in increasing order of integer variable names followed by
228 * real variable names also in increasing order.
229 *
230 * To mutate a linear expression, use the iterator class instead.
232 * Sample code:
233 * \code for (linexpr1::const_iterator i = m.begin();i.valid();++i) cout << i.get_coeff() << " "; \endcode
234 */
236
237 /* TODO:
238 - reverse traversal (operator--).
239 */
240
241 friend class linexpr1;
242
243 protected:
244
245 ap_linexpr1_t* l;
246 ap_dim_t pos;
247
249 void skip_AP_DIM_MAX();
250
252 const_iterator(ap_linexpr1_t* l);
254 public:
255
257 const_iterator(const linexpr1& e);
258
259
268
269 const var& get_var() const;
270
275 ap_dim_t get_dim() const;
281 const coeff& get_coeff() const;
282
283 //! Moves the iterator to the following position.
284 void next();
285
288
289 */
290 void operator++();
291
293 bool valid() const;
295 };
296
298
299 * As const_iterator, but for non-constant linexpr1.
300 *
301 * Caution: do not modify the expression during traversal, except through the iterator.
302 *
303 * Sample code:
304 * \code for (linexpr1::iterator i = m.begin();i.valid();++i) i.get_coeff().neg(); \endcode
305 */
306 class iterator : public const_iterator {
307
308 /* TODO:
309 - removing/inserting coefficients at iterator position for sparse expressions.
310 */
311
312 protected:
314 friend class linexpr1;
315
317 iterator(ap_linexpr1_t* l);
318
319 public:
320
323
325 iterator(const iterator& i);
326
327 //! Assigns the iterator.
328 iterator& operator=(const iterator& i);
329
331
334 coeff& get_coeff() const;
335
336 };
337
339 iterator begin();
340
342 const_iterator begin() const;
343
345
346
347 /* other operators */
348 /* =============== */
349
352
357 void minimize();
358
360
361
362 /* TODO: evaluation, linearization, intelligent constructors */
363
364
365 /* C-level compatibility */
366 /* ===================== */
367
370
372 const ap_linexpr1_t* get_ap_linexpr1_t() const;
373
375 ap_linexpr1_t* get_ap_linexpr1_t();
376
378
379};
380
382
383}
384
385#endif /* __APXX_LINEXPR1_HH */
Coefficient (ap_coeff_t wrapper).
Definition apxx_coeff.hh:36
Level 1 environment (ap_environment_t wrapper).
Definition apxx_environment.hh:51
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition apxx_linexpr0.hh:44
ap_linexpr1_t * l
Internal use only. Pointer to the underlying APRON structure.
Definition apxx_linexpr1.hh:245
bool valid() const
Whether we are at a valid position (true) or past the last iterator position (false).
Definition apxx_linexpr1.hh:294
friend class linexpr1
Definition apxx_linexpr1.hh:241
void next()
Moves the iterator to the following position.
Definition apxx_linexpr1.hh:283
const_iterator(ap_linexpr1_t *l)
Internal use only.
Definition apxx_linexpr1.hh:209
const coeff & get_coeff() const
Returns a reference to the coefficient at the current iterator position.
Definition apxx_linexpr1.hh:269
void operator++()
Moves the iterator to the following position.
Definition apxx_linexpr1.hh:289
const var & get_var() const
Returns the variable name of the coefficient at the current iterator position.
Definition apxx_linexpr1.hh:260
ap_dim_t pos
Internal use only. Current index.
Definition apxx_linexpr1.hh:246
const_iterator & operator=(const const_iterator &i)
Assigns the iterator.
Definition apxx_linexpr1.hh:239
void skip_AP_DIM_MAX()
Internal use only. Skips free coefficients in sparse expressions.
Definition apxx_linexpr1.hh:203
ap_dim_t get_dim() const
Returns the dimension of the coefficient at the current iterator position.
Definition apxx_linexpr1.hh:253
Iterator to traverse and mutate a linear expression.
Definition apxx_linexpr1.hh:306
iterator(ap_linexpr1_t *l)
Internal use only.
Definition apxx_linexpr1.hh:227
friend class linexpr1
Definition apxx_linexpr1.hh:314
coeff & get_coeff() const
Returns a (modifiable) reference to the coefficient at the current iterator position.
Definition apxx_linexpr1.hh:276
iterator & operator=(const iterator &i)
Assigns the iterator.
Definition apxx_linexpr1.hh:246
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition apxx_linexpr1.hh:123
iterator begin()
Returns a new iterator to traverse and mutate the linear expression.
Definition apxx_linexpr1.hh:304
void minimize()
Minimizes all coefficients.
Definition apxx_linexpr1.hh:313
ap_linexpr_discr_t get_discr() const
Returns the type of underlying linexpr0.
Definition apxx_linexpr1.hh:118
~linexpr1()
Frees all space for the expression and coefficients, and decrements the reference count of the enviro...
Definition apxx_linexpr1.hh:64
void extend_environment(const environment &e)
Extends the environment of the expression.
Definition apxx_linexpr1.hh:85
friend std::ostream & operator<<(std::ostream &os, const linexpr1 &s)
Printing.
Definition apxx_linexpr1.hh:153
const linexpr0 & get_linexpr0() const
Returns a reference to the underlying linexpr0.
Definition apxx_linexpr1.hh:103
bool is_linear() const
Whether all coefficients are scalar.
Definition apxx_linexpr1.hh:189
const ap_linexpr1_t * get_ap_linexpr1_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_linexpr1.hh:322
environment get_environment() const
Returns the environment of the expression (with incremented reference count).
Definition apxx_linexpr1.hh:98
bool is_quasilinear() const
Whether all coefficients are scalar, except maybe the constant one.
Definition apxx_linexpr1.hh:194
bool is_integer() const
Whether the expression only depends on integer variables.
Definition apxx_linexpr1.hh:174
ap_linexpr1_t l
Structure managed by APRON.
Definition apxx_linexpr1.hh:43
linexpr1(ap_linexpr1_t &p)
Internal use only. Shallow copy (no copy of linexpr0 or environment).
Definition apxx_linexpr1.hh:29
linexpr1 & operator=(const linexpr1 &x)
Makes a (deep) copy.
Definition apxx_linexpr1.hh:73
size_t size() const
Returns the number of coefficients in the expression.
Definition apxx_linexpr1.hh:113
coeff & operator[](const var &v)
Returns a (modifiable) reference to the coefficient corresponding to the given variable name.
Definition apxx_linexpr1.hh:133
ap_linexpr_type_t get_type() const
Gets the type of the linear expression.
Definition apxx_linexpr1.hh:184
bool is_real() const
Whether the expression only depends on real variables.
Definition apxx_linexpr1.hh:179
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_linexpr1.hh:165
Variable name (ap_var_t wrapper).
Definition apxx_var.hh:39
Definition apxx_abstract0.hh:27
Inherited by most wrappers to map new and delete to malloc and free.
Definition apxx_scalar.hh:69