APRONXX 0.9.14
/builddir/build/BUILD/apron-0.9.15-build/apron-0.9.15/apronxx/apxx_linexpr1_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_linexpr1_inline.hh
3 *
4 * APRON Library / C++ inline functions
5 *
6 * DO NOT INCLUDE THIS FILE DIRECTLY
7 *
8 * Copyright (C) Antoine Mine' 2007
9 *
10 */
11/* This file is part of the APRON Library, released under LGPL license
12 with an exception allowing the redistribution of statically linked
13 executables.
14
15 Please read the COPYING file packaged in the distribution.
16*/
17
18
19/* ================================= */
20/* linexpr1 */
21/* ================================= */
22
23
24
25/* constructors */
26/* ============ */
27
28inline linexpr1::linexpr1(ap_linexpr1_t& p) : l(p)
29{
30}
31
32inline linexpr1::linexpr1(const environment& e, const linexpr0& x)
33{
34 l = ap_linexpr1_of_linexpr0(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
35 ap_linexpr0_copy(const_cast<ap_linexpr0_t*>(x.get_ap_linexpr0_t())));
36}
37
38inline linexpr1::linexpr1(const environment& e, ap_linexpr_discr_t lin_discr, size_t size)
39{
40 l = ap_linexpr1_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
41 lin_discr, size);
42}
43
45{
46 l = ap_linexpr1_copy(const_cast<ap_linexpr1_t*>(&x.l));
47}
48
49inline linexpr1::linexpr1(const linexpr1& x, const environment& e)
50{
51 bool r =
52 ap_linexpr1_extend_environment(&l,
53 const_cast<ap_linexpr1_t*>(&x.l),
54 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
55 if (r) throw std::invalid_argument("apron::linexpr1::linexpr1(const linexpr1&, environment&) not a super-environment");
56}
57
58
59/* destructor */
60/* ========== */
61
62
64{
65 ap_linexpr1_clear(&l);
66}
67
68
69/* assignment */
70/* ========== */
71
73{
74 ap_linexpr1_t ll = ap_linexpr1_copy(const_cast<ap_linexpr1_t*>(&x.l));
75 ap_linexpr1_clear(&l);
76 l = ll;
77 return *this;
78}
79
80
81/* dimension operations */
82/* ==================== */
83
85{
86 bool r =
87 ap_linexpr1_extend_environment_with(&l,
88 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
89 if (r) throw std::invalid_argument("apron::linexpr1::extend_environment(const environment&) not a super-environment");
90}
91
92
93/* access */
94/* ====== */
95
96
98{
99 return ap_environment_copy(ap_linexpr1_envref(const_cast<ap_linexpr1_t*>(&l)));
100}
101
102inline const linexpr0& linexpr1::get_linexpr0() const
103{
104 return reinterpret_cast<linexpr0&>(*ap_linexpr1_linexpr0ref(const_cast<ap_linexpr1_t*>(&l)));
105}
106
108{
109 return reinterpret_cast<linexpr0&>(*ap_linexpr1_linexpr0ref(&l));
110}
111
112inline size_t linexpr1::size() const
113{
114 return ap_linexpr0_size(ap_linexpr1_linexpr0ref(const_cast<ap_linexpr1_t*>(&l)));
115}
116
117inline ap_linexpr_discr_t linexpr1::get_discr() const
118{
119 return ap_linexpr1_linexpr0ref(const_cast<ap_linexpr1_t*>(&l))->discr;
120}
121
123{
124 return reinterpret_cast<coeff&>(*ap_linexpr1_cstref(&l));
125}
126
127inline const coeff& linexpr1::get_cst() const
128{
129 return reinterpret_cast<coeff&>(*ap_linexpr1_cstref(const_cast<ap_linexpr1_t*>(&l)));
130}
131
132inline coeff& linexpr1::operator[](const var& var)
133{
134 ap_coeff_t* x = ap_linexpr1_coeffref(&l,
135 const_cast<ap_var_t>(var.get_ap_var_t()));
136 if (!x) throw std::invalid_argument("apron::linexpr1::operator[](const var&) variable not in environment");
137 return reinterpret_cast<coeff&>(*x);
138}
139
140inline const coeff& linexpr1::operator[](const var& var) const
141{
142 ap_coeff_t* x = ap_linexpr1_coeffref(const_cast<ap_linexpr1_t*>(&l),
143 const_cast<ap_var_t>(var.get_ap_var_t()));
144 if (!x) throw std::invalid_argument("apron::linexpr1::operator[](const var&) variable not in environment");
145 return reinterpret_cast<coeff&>(*x);
146}
147
148
149/* print */
150/* ===== */
151
152inline std::ostream& operator<<(std::ostream& os, const linexpr1& s)
153{
154 bool first = true;
155 for (linexpr1::const_iterator i=s.begin();i.valid();++i) {
156 if (print_coeff_sign(os, i.get_coeff(), first, false))
157 os << i.get_var();
158 }
159 print_coeff_sign(os, s.get_cst(), first, true);
160 if (first) os << "0";
161 return os;
162}
163
164inline void linexpr1::print(FILE* stream) const
165{
166 ap_linexpr1_fprint(stream, const_cast<ap_linexpr1_t*>(&l));
167}
168
169
170/* tests */
171/* ===== */
172
173inline bool linexpr1::is_integer() const
174{
175 return ap_linexpr1_is_integer(const_cast<ap_linexpr1_t*>(&l));
176}
177
178inline bool linexpr1::is_real() const
179{
180 return ap_linexpr1_is_real(const_cast<ap_linexpr1_t*>(&l));
181}
182
183inline ap_linexpr_type_t linexpr1::get_type() const
184{
185 return ap_linexpr1_type(const_cast<ap_linexpr1_t*>(&l));
186}
187
188inline bool linexpr1::is_linear() const
189{
190 return ap_linexpr1_is_linear(const_cast<ap_linexpr1_t*>(&l));
191}
192
193inline bool linexpr1::is_quasilinear() const
194{
195 return ap_linexpr1_is_quasilinear(const_cast<ap_linexpr1_t*>(&l));
196}
197
198
199/* iterators */
200/* ========= */
201
203{
204 if (l->linexpr0->discr == AP_LINEXPR_DENSE) return;
205 while (pos < l->linexpr0->size && l->linexpr0->p.linterm[pos].dim == AP_DIM_MAX) pos++;
206}
207
208inline linexpr1::const_iterator::const_iterator(ap_linexpr1_t* e)
209 : l(e), pos(0)
210{
212}
213
215{
216 l = const_cast<ap_linexpr1_t*>(e.get_ap_linexpr1_t());
217 pos = 0;
218 skip_AP_DIM_MAX();
219}
220
222 : l(i.l), pos(i.pos)
223{}
224
225
226inline linexpr1::iterator::iterator(ap_linexpr1_t* e)
228{}
229
233
237
239{
240 l = i.l;
241 pos = i.pos;
242 return *this;
243}
244
246{
247 l = i.l;
248 pos = i.pos;
249 return *this;
250}
251
253{
254 if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::const_iterator::get_dim()");
255 if (l->linexpr0->discr == AP_LINEXPR_DENSE) return pos;
256 else return l->linexpr0->p.linterm[pos].dim;
257}
258
260{
261 ap_dim_t d;
262 if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::const_iterator::get_var()");
263 if (l->linexpr0->discr == AP_LINEXPR_DENSE) d = pos;
264 else d = l->linexpr0->p.linterm[pos].dim;
265 return *reinterpret_cast<var*>(&l->env->var_of_dim[d]);
266}
267
269{
270 if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::const_iterator::get_coeff()");
271 if (l->linexpr0->discr == AP_LINEXPR_DENSE) return reinterpret_cast<coeff&>(l->linexpr0->p.coeff[pos]);
272 else return reinterpret_cast<coeff&>(l->linexpr0->p.linterm[pos].coeff);
273}
274
276{
277 if (pos >= l->linexpr0->size) throw std::out_of_range("apron::linexpr1::iterator::get_coeff()");
278 if (l->linexpr0->discr == AP_LINEXPR_DENSE) return reinterpret_cast<coeff&>(l->linexpr0->p.coeff[pos]);
279 else return reinterpret_cast<coeff&>(l->linexpr0->p.linterm[pos].coeff);
280}
281
283{
284 pos++;
285 skip_AP_DIM_MAX();
286}
287
289{
290 next();
291}
292
294{
295 return pos < l->linexpr0->size;
296}
297
299{
300 return const_iterator(*this);
301}
302
304{
305 return iterator(*this);
306}
307
308
309/* other operators */
310/* =============== */
311
313{
314 ap_linexpr1_minimize(&l);
315}
316
317
318/* C-level compatibility */
319/* ===================== */
320
321inline const ap_linexpr1_t* linexpr1::get_ap_linexpr1_t() const
322{
323 return &l;
324}
325
326inline ap_linexpr1_t* linexpr1::get_ap_linexpr1_t()
327{
328 return &l;
329}
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition apxx_abstract0_inline.hh:292
static bool print_coeff_sign(std::ostream &os, const coeff &c, bool &first, bool cst)
Definition apxx_linexpr0_inline.hh:206
Coefficient (ap_coeff_t wrapper).
Definition apxx_coeff.hh:36
Level 1 environment (ap_environment_t wrapper).
Definition apxx_environment.hh:51
const ap_environment_t * get_ap_environment_t() const
Returns a pointer to the internal APRON object pointed by *this.
Definition apxx_environment_inline.hh:425
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition apxx_linexpr0.hh:44
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
Iterator to traverse a constant linexpr1.
Definition apxx_linexpr1.hh:235
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_inline.hh:293
void next()
Moves the iterator to the following position.
Definition apxx_linexpr1_inline.hh:282
const_iterator(ap_linexpr1_t *l)
Internal use only.
const coeff & get_coeff() const
Returns a reference to the coefficient at the current iterator position.
Definition apxx_linexpr1_inline.hh:268
void operator++()
Moves the iterator to the following position.
Definition apxx_linexpr1_inline.hh:288
const var & get_var() const
Returns the variable name of the coefficient at the current iterator position.
Definition apxx_linexpr1_inline.hh:259
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_inline.hh:238
void skip_AP_DIM_MAX()
Internal use only. Skips free coefficients in sparse expressions.
Definition apxx_linexpr1_inline.hh:202
ap_dim_t get_dim() const
Returns the dimension of the coefficient at the current iterator position.
Definition apxx_linexpr1_inline.hh:252
Iterator to traverse and mutate a linear expression.
Definition apxx_linexpr1.hh:306
iterator(ap_linexpr1_t *l)
Internal use only.
coeff & get_coeff() const
Returns a (modifiable) reference to the coefficient at the current iterator position.
Definition apxx_linexpr1_inline.hh:275
iterator & operator=(const iterator &i)
Assigns the iterator.
Definition apxx_linexpr1_inline.hh:245
Level 1 linear expression (ap_linexpr1_t wrapper).
Definition apxx_linexpr1.hh:39
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition apxx_linexpr1_inline.hh:122
iterator begin()
Returns a new iterator to traverse and mutate the linear expression.
Definition apxx_linexpr1_inline.hh:303
void minimize()
Minimizes all coefficients.
Definition apxx_linexpr1_inline.hh:312
ap_linexpr_discr_t get_discr() const
Returns the type of underlying linexpr0.
Definition apxx_linexpr1_inline.hh:117
~linexpr1()
Frees all space for the expression and coefficients, and decrements the reference count of the enviro...
Definition apxx_linexpr1_inline.hh:63
void extend_environment(const environment &e)
Extends the environment of the expression.
Definition apxx_linexpr1_inline.hh:84
const linexpr0 & get_linexpr0() const
Returns a reference to the underlying linexpr0.
Definition apxx_linexpr1_inline.hh:102
bool is_linear() const
Whether all coefficients are scalar.
Definition apxx_linexpr1_inline.hh:188
const ap_linexpr1_t * get_ap_linexpr1_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_linexpr1_inline.hh:321
environment get_environment() const
Returns the environment of the expression (with incremented reference count).
Definition apxx_linexpr1_inline.hh:97
bool is_quasilinear() const
Whether all coefficients are scalar, except maybe the constant one.
Definition apxx_linexpr1_inline.hh:193
bool is_integer() const
Whether the expression only depends on integer variables.
Definition apxx_linexpr1_inline.hh:173
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_inline.hh:28
linexpr1 & operator=(const linexpr1 &x)
Makes a (deep) copy.
Definition apxx_linexpr1_inline.hh:72
size_t size() const
Returns the number of coefficients in the expression.
Definition apxx_linexpr1_inline.hh:112
coeff & operator[](const var &v)
Returns a (modifiable) reference to the coefficient corresponding to the given variable name.
ap_linexpr_type_t get_type() const
Gets the type of the linear expression.
Definition apxx_linexpr1_inline.hh:183
bool is_real() const
Whether the expression only depends on real variables.
Definition apxx_linexpr1_inline.hh:178
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_linexpr1_inline.hh:164
Variable name (ap_var_t wrapper).
Definition apxx_var.hh:39
const ap_var_t & get_ap_var_t() const
Returns a reference to the APRON object wrapped (no copy).
Definition apxx_var_inline.hh:156