APRONXX 0.9.14
/builddir/build/BUILD/apron-0.9.15-build/apron-0.9.15/apronxx/apxx_generator1_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_generator1_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/* ================================= */
21/* generator1 */
22/* ================================= */
23
24
25/* constructors */
26/* ============ */
27
28inline generator1::generator1(ap_generator1_t p) : l(p)
29{}
30
32{
33 l.env = ap_environment_copy(const_cast<ap_environment_t*>(e.get_ap_environment_t()));
34 l.generator0 = ap_generator0_copy(const_cast<ap_generator0_t*>(x.get_ap_generator0_t()));
35}
36
37inline generator1::generator1(const environment& e, ap_gentyp_t gentyp)
38{
39 ap_linexpr1_t llin =
40 ap_linexpr1_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), AP_LINEXPR_SPARSE, 0);
41 l = ap_generator1_make(gentyp, &llin);
42}
43
44inline generator1::generator1(ap_gentyp_t gentyp, const linexpr1& lin)
45{
46 ap_linexpr1_t llin = ap_linexpr1_copy(const_cast<ap_linexpr1_t*>(lin.get_ap_linexpr1_t()));
47 l = ap_generator1_make(gentyp, &llin);
48}
49
51{
52 l = ap_generator1_copy(const_cast<ap_generator1_t*>(&x.l));
53}
54
56{
57 if (!x.has_linexpr())
58 throw std::invalid_argument("apron::generator1::generator1(const generator&, const environment&) empty expression");
59 bool r =
60 ap_generator1_extend_environment(&l,
61 const_cast<ap_generator1_t*>(&x.l),
62 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
63 if (r) throw std::invalid_argument("apron::generator1::generator1(const generator&, const environment&) not a super-environment");
64}
65
66
67/* destructor */
68/* ========== */
69
71{
72 ap_generator1_clear(&l);
73}
74
75
76/* assignment */
77/* ========== */
78
80{
81 ap_generator1_t ll = ap_generator1_copy(const_cast<ap_generator1_t*>(&x.l));
82 ap_generator1_clear(&l);
83 l = ll;
84 return *this;
85}
86
91
92
93/* dimension operations */
94/* ==================== */
95
97{
98 if (!has_linexpr())
99 throw std::invalid_argument("apron::generator1::extend_environment(cconst environment&) empty expression");
100 bool r =
101 ap_generator1_extend_environment_with(&l,
102 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
103 if (r) throw std::invalid_argument("apron::generator1::extend_environment(const environment&) not a super-environment");
104
105}
106
107
108/* access */
109/* ====== */
110
112{
113 return (ap_environment_copy(ap_generator1_envref(const_cast<ap_generator1_t*>(&l))));
114}
115
117{
118 return reinterpret_cast<generator0&>(*ap_generator1_generator0ref(const_cast<ap_generator1_t*>(&l)));
119}
120
122{
123 return reinterpret_cast<generator0&>(*ap_generator1_generator0ref(&l));
124}
125
126inline size_t generator1::size() const
127{
128 return get_generator0().size();
129}
130
131inline ap_gentyp_t& generator1::get_gentyp()
132{
133 return get_generator0().get_gentyp();
134}
135
136inline const ap_gentyp_t& generator1::get_gentyp() const
137{
138 return get_generator0().get_gentyp();
139}
140
141inline bool generator1::has_linexpr() const
142{
143 return get_generator0().has_linexpr();
144}
145
147{
148 if (!has_linexpr())
149 throw std::invalid_argument("apron::generator1::get_linexpr() empty expression");
151 return linexpr1(get_environment(),ll);
152}
153
155{
156 if (!has_linexpr())
157 throw std::invalid_argument("apron::generator1::get_cst() empty expression");
158 return reinterpret_cast<coeff&>(*ap_generator1_cstref(&l));
159}
160
161inline const coeff& generator1::get_cst() const
162{
163 if (!has_linexpr())
164 throw std::invalid_argument("apron::generator1::get_cst() empty expression");
165 return reinterpret_cast<coeff&>(*ap_generator1_cstref(const_cast<ap_generator1_t*>(&l)));
166}
167
168inline coeff& generator1::operator[](const var& var)
169{
170 if (!has_linexpr())
171 throw std::invalid_argument("apron::generator1::operator[](const var&) empty expression");
172 ap_coeff_t* x = ap_generator1_coeffref(&l, const_cast<ap_var_t>(var.get_ap_var_t()));
173 if (!x) throw std::invalid_argument("apron::generator1::operator[](const var&) variable not in environment");
174 return reinterpret_cast<coeff&>(*x);
175}
176
177inline const coeff& generator1::operator[](const var& var) const
178{
179 if (!has_linexpr())
180 throw std::invalid_argument("apron::generator1::operator[](const var&) empty expression");
181 ap_coeff_t* x = ap_generator1_coeffref(const_cast<ap_generator1_t*>(&l),
182 const_cast<ap_var_t>(var.get_ap_var_t()));
183 if (!x) throw std::invalid_argument("apron::generator1::operator[](const var&) variable not in environment");
184 return reinterpret_cast<coeff&>(*x);
185}
186
187
188/* print */
189/* ===== */
190
191inline std::ostream& operator<< (std::ostream& os, const generator1& s)
192{
193 if (!s.has_linexpr())
194 throw std::invalid_argument("apron::operator<<(ostream&, const generator1&) empty expression");
195 switch (s.get_gentyp()) {
196 case AP_GEN_LINE: os << "LINE: "; break;
197 case AP_GEN_RAY: os << "RAY: "; break;
198 case AP_GEN_VERTEX: os << "VERTEX: "; break;
199 case AP_GEN_LINEMOD: os << "LINEMOD: "; break;
200 case AP_GEN_RAYMOD: os << "RAYMOD: "; break;
201 default: throw std::invalid_argument("apron::operator<<(ostream&, const generator1&) invalid generator type");
202 }
203 return os << s.get_linexpr();
204}
205
206inline void generator1::print(FILE* stream) const
207{
208 ap_generator1_fprint(stream, const_cast<ap_generator1_t*>(&l));
209}
210
211
212/* C-level compatibility */
213/* ===================== */
214
215inline const ap_generator1_t* generator1::get_ap_generator1_t() const
216{
217 return &l;
218}
219
220inline ap_generator1_t* generator1::get_ap_generator1_t()
221{
222 return &l;
223}
224
225
226
227
228/* ================================= */
229/* generator1_array */
230/* ================================= */
231
232
233
234/* constructors */
235/* ============ */
236
237inline generator1_array::generator1_array(ap_generator1_array_t& a) : a(a)
238{}
239
241{
242 size_t sz = x.size();
243 a = ap_generator1_array_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), sz);
244 for (size_t i=0; i<sz; i++)
245 a.generator0_array.p[i] = ap_generator0_copy(&x.a.p[i]);
246}
247
249{
250 a = ap_generator1_array_make(const_cast<ap_environment_t*>(e.get_ap_environment_t()), size);
251}
252
254{
255 size_t sz = x.size();
256 a = ap_generator1_array_make(x.get_environment().get_ap_environment_t(), sz);
257 for (size_t i=0; i<sz; i++)
258 a.generator0_array.p[i] = ap_generator0_copy(&x.a.generator0_array.p[i]);
259}
260
262{
263 bool r =
264 ap_generator1_array_extend_environment(&a,
265 const_cast<ap_generator1_array_t*>(&x.a),
266 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
267 if (r) throw std::invalid_argument("apron::generator1_array::generator1_array(const generator1_array&, const environment&) not a super-environment");
268}
269
270inline generator1_array::generator1_array(size_t sz, const generator1 x[])
271{
272 if (sz<1) throw std::invalid_argument("apron::generator1_array::generator1_array(size_t sz, const generator1[]) null size");
273 a = ap_generator1_array_make(x[0].get_environment().get_ap_environment_t(), sz);
274 for (size_t i=0; i<sz; i++)
275 a.generator0_array.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>
276 (x[i].get_generator0().get_ap_generator0_t()));
277}
278
279inline generator1_array::generator1_array(const std::vector<generator1>& x)
280{
281 size_t sz = x.size();
282 if (sz<1) throw std::invalid_argument("apron::generator1_array::generator1_array(const vector<generator1>&) null size");
283 a = ap_generator1_array_make(x[0].get_environment().get_ap_environment_t(), sz);
284 for (size_t i=0; i<sz; i++)
285 a.generator0_array.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>
286 (x[i].get_generator0().get_ap_generator0_t()));
287}
288
289
290/* destructor */
291/* ========== */
292
294{
295 ap_generator1_array_clear(&a);
296}
297
298
299/* assignment */
300/* ========== */
301
303{
304 if (this!=&x) {
305 size_t sz = x.size();
306 ap_generator1_array_clear(&a);
307 a = ap_generator1_array_make(x.get_environment().get_ap_environment_t(), sz);
308 for (size_t i=0; i<sz; i++)
309 a.generator0_array.p[i] = ap_generator0_copy(&x.a.generator0_array.p[i]);
310 }
311 return *this;
312}
313
315{
316 size_t sz = size();
317 for (size_t i=0; i<sz; i++) {
318 ap_generator0_clear(&a.generator0_array.p[i]);
319 a.generator0_array.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>
320 (x[i].get_generator0().get_ap_generator0_t()));
321 }
322 return *this;
323}
324
325inline generator1_array& generator1_array::operator= (const std::vector<generator1>& x)
326{
327 size_t size = x.size();
328 if (size<1) {
329 ap_generator1_array_t aa = ap_generator1_array_make(a.env,0);
330 ap_generator1_array_clear(&a);
331 a = aa;
332 return *this;
333 }
334 ap_generator1_array_clear(&a);
335 a = ap_generator1_array_make(x[0].get_environment().get_ap_environment_t(), size);
336 for (size_t i=0; i<size; i++)
337 a.generator0_array.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>
338 (x[i].get_generator0().get_ap_generator0_t()));
339 return *this;
340}
341
342
343/* dimension operations */
344/* ==================== */
345
346inline void generator1_array::resize(size_t size)
347{
348 ap_generator0_array_resize(&a.generator0_array, size);
349}
350
352{
353 bool r =
354 ap_generator1_array_extend_environment_with(&a,
355 const_cast<ap_environment_t*>(e.get_ap_environment_t()));
356 if (r) throw std::invalid_argument("apron::generator1_array::extend_environment(const environment&) not a super-environment");
357}
358
359
360/* access */
361/* ====== */
362
363inline size_t generator1_array::size() const
364{
365 return ap_generator1_array_size(const_cast<ap_generator1_array_t*>(&a));
366}
367
369{
370 return (ap_environment_copy(ap_generator1_array_envref(const_cast<ap_generator1_array_t*>(&a))));
371}
372
374{
375 return reinterpret_cast<generator0_array&>(const_cast<ap_generator0_array_t&>(a.generator0_array));
376}
377
379{
380 return reinterpret_cast<generator0_array&>(a.generator0_array);
381}
382
383inline generator1 generator1_array::get(size_t i) const
384{
385 if (i>=size()) throw std::out_of_range("apron::generator1_array::get(size_t)");
386 ap_generator1_t c = ap_generator1_array_get(const_cast<ap_generator1_array_t*>(&a),i);
387 return generator1(ap_generator1_copy(&c));
388}
389
390inline void generator1_array::set(size_t i, const generator1& x)
391{
392 if (i>=size()) throw std::out_of_range("apron::generator1_array::get(size_t)");
393 ap_generator0_clear(&a.generator0_array.p[i]);
394 a.generator0_array.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>
396}
397
398
399/* conversion */
400/* ========== */
401
402inline generator1_array::operator std::vector<generator1>() const
403{
404 size_t sz = size();
405 generator1 dummy(get_environment(),generator0());
406 std::vector<generator1> v(sz,dummy);
407 for (size_t i=0;i<sz;i++) {
408 ap_generator1_t c = ap_generator1_array_get(const_cast<ap_generator1_array_t*>(&a),i);
409 v[i] = ap_generator1_copy(&c);
410 }
411 return v;
412}
413
414
415/* print */
416/* ===== */
417
418inline std::ostream& operator<< (std::ostream& os, const generator1_array& s)
419{
420 size_t sz = s.size();
421 os << "{ ";
422 for (size_t i=0;i<sz;i++)
423 os << s.get(i) << "; ";
424 return os << "}";
425}
426
427inline void generator1_array:: print(FILE* stream) const
428{
429 ap_generator1_array_fprint(stream, const_cast<ap_generator1_array_t*>(&a));
430}
431
432
433/* C-level compatibility */
434/* ===================== */
435
436inline const ap_generator1_array_t* generator1_array::get_ap_generator1_array_t() const
437{
438 return &a;
439}
440
441inline ap_generator1_array_t* generator1_array::get_ap_generator1_array_t()
442{
443 return &a;
444}
445
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition apxx_abstract0_inline.hh:292
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
Array of generators (ap_generator0_array_t wrapper).
Definition apxx_generator0.hh:214
size_t size() const
Returns the size of the array.
Definition apxx_generator0_inline.hh:305
ap_generator0_array_t a
Structure managed by APRON.
Definition apxx_generator0.hh:218
Level 0 generator (ap_generator0_t wrapper).
Definition apxx_generator0.hh:39
void set_linexpr(const linexpr0 &c)
Sets the underlying linear expression to c (copied).
Definition apxx_generator0_inline.hh:146
bool has_linexpr() const
Returns whether the generator has a valid linear expression.
Definition apxx_generator0_inline.hh:129
ap_gentyp_t & get_gentyp()
Returns a (modifiable) reference to the constraint type.
Definition apxx_generator0_inline.hh:119
const ap_generator0_t * get_ap_generator0_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_generator0_inline.hh:181
linexpr0 & get_linexpr()
Returns a (modifiable) reference to the underlying linear expression.
Definition apxx_generator0_inline.hh:134
size_t size() const
Returns the size of the underlying linear expression.
Definition apxx_generator0_inline.hh:110
Array of generators (ap_generator1_array_t wrapper).
Definition apxx_generator1.hh:272
ap_generator1_array_t a
Structure managed by APRON.
Definition apxx_generator1.hh:276
size_t size() const
Returns the size of the array.
Definition apxx_generator1_inline.hh:363
environment get_environment() const
Returns the environment shared by all generators (with incremented reference count).
Definition apxx_generator1_inline.hh:368
void resize(size_t size)
Resizes the array.
Definition apxx_generator1_inline.hh:346
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_generator1_inline.hh:427
void extend_environment(const environment &e)
Extends the environment of all generators in the array.
Definition apxx_generator1_inline.hh:351
generator1_array(ap_generator1_array_t &a)
Internal use only. Shallow copy (no copy of generator0_array or environment).
Definition apxx_generator1_inline.hh:237
const ap_generator1_array_t * get_ap_generator1_array_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_generator1_inline.hh:436
generator1_array & operator=(const generator1_array &x)
(Deep) copy.
Definition apxx_generator1_inline.hh:302
~generator1_array()
Frees the space used by the array and all its generators, and decrements the reference count of the e...
Definition apxx_generator1_inline.hh:293
generator1 get(size_t i) const
Returns a copy of the generator at index i.
Definition apxx_generator1_inline.hh:383
void set(size_t i, const generator1 &x)
Changes the generator at index i.
Definition apxx_generator1_inline.hh:390
const generator0_array & get_generator0_array() const
Returns a reference to the underlying generator0_array.
Definition apxx_generator1_inline.hh:373
Level 1 generator (ap_generator1_t wrapper).
Definition apxx_generator1.hh:40
ap_gentyp_t & get_gentyp()
Returns a (modifiable) reference to the constraint type.
Definition apxx_generator1_inline.hh:131
bool has_linexpr() const
Whether the generator has a valid linear expression.
Definition apxx_generator1_inline.hh:141
generator1 & operator=(const generator1 &x)
Makes a (deep) copy.
Definition apxx_generator1_inline.hh:79
coeff & get_cst()
Returns a (modifiable) reference to the constant coefficient.
Definition apxx_generator1_inline.hh:154
void set_linexpr(const linexpr1 &c)
Sets the underlying linear expression to c (copied).
Definition apxx_generator1_inline.hh:87
ap_generator1_t l
Structure managed by APRON.
Definition apxx_generator1.hh:44
coeff & operator[](const var &v)
Returns a (modifiable) reference to the coefficient corresponding to the given variable name.
void extend_environment(const environment &e)
Extends the environment of the generator.
Definition apxx_generator1_inline.hh:96
linexpr1 get_linexpr() const
Returns a copy of the underlying linear expression.
Definition apxx_generator1_inline.hh:146
const ap_generator1_t * get_ap_generator1_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_generator1_inline.hh:215
environment get_environment() const
Returns the environment of the generator (with incremented reference count).
Definition apxx_generator1_inline.hh:111
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_generator1_inline.hh:206
generator1(ap_generator1_t p)
Internal use only. Shallow copy (no copy of generator0 or environment).
Definition apxx_generator1_inline.hh:28
const generator0 & get_generator0() const
Returns a reference to the underlying generator0.
Definition apxx_generator1_inline.hh:116
~generator1()
Frees all space for the generator, and decrements the reference count of the environment.
Definition apxx_generator1_inline.hh:70
size_t size() const
Returns the size of the underlying linear expression.
Definition apxx_generator1_inline.hh:126
Level 0 linear expression (ap_linexpr0_t wrapper).
Definition apxx_linexpr0.hh:44
Level 1 linear expression (ap_linexpr1_t wrapper).
Definition apxx_linexpr1.hh:39
const linexpr0 & get_linexpr0() const
Returns a reference to the underlying linexpr0.
Definition apxx_linexpr1_inline.hh:102
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
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