28 inline linexpr1::linexpr1(ap_linexpr1_t& p) : l(p)
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())));
40 l = ap_linexpr1_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
46 l = ap_linexpr1_copy(const_cast<ap_linexpr1_t*>(&x.l));
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");
65 ap_linexpr1_clear(&
l);
74 ap_linexpr1_t ll = ap_linexpr1_copy(const_cast<ap_linexpr1_t*>(&x.l));
75 ap_linexpr1_clear(&
l);
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");
99 return ap_environment_copy(ap_linexpr1_envref(const_cast<ap_linexpr1_t*>(&
l)));
104 return reinterpret_cast<linexpr0&
>(*ap_linexpr1_linexpr0ref(const_cast<ap_linexpr1_t*>(&
l)));
109 return reinterpret_cast<linexpr0&
>(*ap_linexpr1_linexpr0ref(&
l));
114 return ap_linexpr0_size(ap_linexpr1_linexpr0ref(const_cast<ap_linexpr1_t*>(&
l)));
119 return ap_linexpr1_linexpr0ref(const_cast<ap_linexpr1_t*>(&
l))->discr;
124 return reinterpret_cast<coeff&
>(*ap_linexpr1_cstref(&
l));
129 return reinterpret_cast<coeff&
>(*ap_linexpr1_cstref(const_cast<ap_linexpr1_t*>(&
l)));
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);
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);
155 for (linexpr1::const_iterator i=s.begin();i.valid();++i) {
160 if (first) os <<
"0";
166 ap_linexpr1_fprint(stream, const_cast<ap_linexpr1_t*>(&
l));
175 return ap_linexpr1_is_integer(const_cast<ap_linexpr1_t*>(&
l));
180 return ap_linexpr1_is_real(const_cast<ap_linexpr1_t*>(&
l));
185 return ap_linexpr1_type(const_cast<ap_linexpr1_t*>(&
l));
190 return ap_linexpr1_is_linear(const_cast<ap_linexpr1_t*>(&
l));
195 return ap_linexpr1_is_quasilinear(const_cast<ap_linexpr1_t*>(&
l));
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++;
216 l =
const_cast<ap_linexpr1_t*
>(e.get_ap_linexpr1_t());
227 : linexpr1::const_iterator(e)
231 : linexpr1::const_iterator(e.get_ap_linexpr1_t())
235 : linexpr1::const_iterator(i.l)
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;
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]);
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);
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);
295 return pos <
l->linexpr0->size;
300 return const_iterator(*
this);
305 return iterator(*
this);
314 ap_linexpr1_minimize(&
l);
iterator begin()
Returns a new iterator to traverse and mutate the linear expression.
Definition: apxx_linexpr1.hh:304
const_iterator & operator=(const const_iterator &i)
Assigns the iterator.
Definition: apxx_linexpr1.hh:239
size_t size() const
Returns the number of coefficients in the expression.
Definition: apxx_linexpr1.hh:113
friend std::ostream & operator<<(std::ostream &os, const linexpr1 &s)
Printing.
Definition: apxx_linexpr1.hh:153
bool is_quasilinear() const
Whether all coefficients are scalar, except maybe the constant one.
Definition: apxx_linexpr1.hh:194
static bool print_coeff_sign(std::ostream &os, const coeff &c, bool &first, bool cst)
Definition: apxx_linexpr0.hh:207
const linexpr0 & get_linexpr0() const
Returns a reference to the underlying linexpr0.
Definition: apxx_linexpr1.hh:103
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition: apxx_linexpr1.hh:123
iterator & operator=(const iterator &i)
Assigns the iterator.
Definition: apxx_linexpr1.hh:246
iterator(ap_linexpr1_t *l)
Internal use only.
Definition: apxx_linexpr1.hh:227
const_iterator(ap_linexpr1_t *l)
Internal use only.
Definition: apxx_linexpr1.hh:209
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_linexpr1.hh:165
~linexpr1()
Frees all space for the expression and coefficients, and decrements the reference count of the enviro...
Definition: apxx_linexpr1.hh:64
coeff & operator[](const var &v)
Returns a (modifiable) reference to the coefficient corresponding to the given variable name...
Definition: apxx_linexpr1.hh:133
void minimize()
Minimizes all coefficients.
Definition: apxx_linexpr1.hh:313
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
void next()
Moves the iterator to the following position.
Definition: apxx_linexpr1.hh:283
bool is_linear() const
Whether all coefficients are scalar.
Definition: apxx_linexpr1.hh:189
const var & get_var() const
Returns the variable name of the coefficient at the current iterator position.
Definition: apxx_linexpr1.hh:260
ap_linexpr1_t l
Structure managed by APRON.
Definition: apxx_linexpr1.hh:43
environment get_environment() const
Returns the environment of the expression (with incremented reference count).
Definition: apxx_linexpr1.hh:98
ap_linexpr_discr_t get_discr() const
Returns the type of underlying linexpr0.
Definition: apxx_linexpr1.hh:118
ap_dim_t get_dim() const
Returns the dimension of the coefficient at the current iterator position.
Definition: apxx_linexpr1.hh:253
linexpr1(ap_linexpr1_t &p)
Internal use only. Shallow copy (no copy of linexpr0 or environment).
Definition: apxx_linexpr1.hh:29
void extend_environment(const environment &e)
Extends the environment of the expression.
Definition: apxx_linexpr1.hh:85
void operator++()
Moves the iterator to the following position.
Definition: apxx_linexpr1.hh:289
bool valid() const
Whether we are at a valid position (true) or past the last iterator position (false).
Definition: apxx_linexpr1.hh:294
const coeff & get_coeff() const
Returns a reference to the coefficient at the current iterator position.
Definition: apxx_linexpr1.hh:269
linexpr1 & operator=(const linexpr1 &x)
Makes a (deep) copy.
Definition: apxx_linexpr1.hh:73
coeff & get_coeff() const
Returns a (modifiable) reference to the coefficient at the current iterator position.
Definition: apxx_linexpr1.hh:276
bool is_real() const
Whether the expression only depends on real variables.
Definition: apxx_linexpr1.hh:179
ap_linexpr_type_t get_type() const
Gets the type of the linear expression.
Definition: apxx_linexpr1.hh:184
bool is_integer() const
Whether the expression only depends on integer variables.
Definition: apxx_linexpr1.hh:174
void skip_AP_DIM_MAX()
Internal use only. Skips free coefficients in sparse expressions.
Definition: apxx_linexpr1.hh:203