APRONXX  0.9.12
/home/mine/apron/apronxx/apxx_generator0_inline.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * apxx_generator0_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 /* generator0 */
21 /* ================================= */
22 
23 
24 /* constructors */
25 /* ============ */
26 
27 inline generator0::generator0(ap_gentyp_t gentyp)
28 {
29  ap_linexpr0_t* llin = ap_linexpr0_alloc(AP_LINEXPR_SPARSE,0);
30  l = ap_generator0_make(gentyp, llin);
31 }
32 
33 inline generator0::generator0(ap_gentyp_t gentyp, const linexpr0& lin)
34 {
35  ap_linexpr0_t* llin = ap_linexpr0_copy(const_cast<ap_linexpr0_t*>(lin.get_ap_linexpr0_t()));
36  l = ap_generator0_make(gentyp, llin);
37 }
38 
39 inline generator0::generator0(const generator0& x)
40 {
41  l = ap_generator0_copy(const_cast<ap_generator0_t*>(&x.l));
42 }
43 
44 
45 inline generator0::generator0(const generator0& x, const dimchange& d)
46 {
47  if (!x.l.linexpr0) throw std::invalid_argument("apron::generator0::generator0(const generator0&, cont dimchange&) empty expression");
48  l = ap_generator0_add_dimensions(const_cast<ap_generator0_t*>(&x.l),
49  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
50 }
51 
52 inline generator0::generator0(const generator0& x, const dimperm& d)
53 {
54  if (!x.l.linexpr0) throw std::invalid_argument("apron::generator0::generator0(const generator0&, cont dimperm&) empty expression");
55  l = ap_generator0_permute_dimensions(const_cast<ap_generator0_t*>(&x.l),
56  const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
57 }
58 
59 
60 
61 /* destructor */
62 /* ========== */
63 
64 inline generator0::~generator0()
65 {
66  ap_generator0_clear(const_cast<ap_generator0_t*>(&l));
67 }
68 
69 
70 /* assignment */
71 /* ========== */
72 
73 inline generator0& generator0::operator= (const generator0& x)
74 {
75  if (&x!=this) {
76  ap_generator0_clear(const_cast<ap_generator0_t*>(&l));
77  l = ap_generator0_copy(const_cast<ap_generator0_t*>(&x.l));
78  }
79  return *this;
80 }
81 
82 
83 /* dimension operations */
84 /* ==================== */
85 
86 inline void generator0::resize(size_t size)
87 {
88  if (!l.linexpr0) throw std::invalid_argument("apron::generator0::resize(size_t) empty expression");
89  ap_linexpr0_realloc(l.linexpr0, size);
90 }
91 
92 inline void generator0::add_dimensions(const dimchange& d)
93 {
94  if (!l.linexpr0) throw std::invalid_argument("apron::generator0::add_dimensions(const dimchange&) empty expression");
95  ap_generator0_add_dimensions_with(&l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
96 }
97 
98 inline void generator0::permute_dimensions(const dimperm& d)
99 {
100  if (!l.linexpr0) throw std::invalid_argument("apron::generator0::permute_dimensions(const dimperm&) empty expression");
101  ap_generator0_permute_dimensions_with(&l, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
102 }
103 
104 
105 /* access */
106 /* ====== */
107 
108 /* size */
109 
110 inline size_t generator0::size() const
111 {
112  if (!l.linexpr0) throw std::invalid_argument("apron::generator0::size() empty expression");
113  return ap_linexpr0_size(const_cast<ap_linexpr0_t*>(l.linexpr0));
114 }
115 
116 
117 /* get */
118 
119 inline ap_gentyp_t& generator0::get_gentyp()
120 {
121  return l.gentyp;
122 }
123 
124 inline const ap_gentyp_t& generator0::get_gentyp() const
125 {
126  return l.gentyp;
127 }
128 
129 inline bool generator0::has_linexpr() const
130 {
131  return l.linexpr0!=NULL;
132 }
133 
134 inline linexpr0& generator0::get_linexpr()
135 {
136  if (!l.linexpr0) throw std::invalid_argument("apron::generator0::get_linexpr() empty expression");
137  return reinterpret_cast<linexpr0&>(*l.linexpr0);
138 }
139 
140 inline const linexpr0& generator0::get_linexpr() const
141 {
142  if (!l.linexpr0) throw std::invalid_argument("apron::generator0::get_linexpr() empty expression");
143  return reinterpret_cast<linexpr0&>(*l.linexpr0);
144 }
145 
146 inline void generator0::set_linexpr(const linexpr0& c)
147 {
148  if (l.linexpr0) ap_linexpr0_free(l.linexpr0);
149  l.linexpr0 = ap_linexpr0_copy(const_cast<ap_linexpr0_t*>(c.get_ap_linexpr0_t()));
150 }
151 
152 
153 /* print */
154 /* ===== */
155 
156 inline std::ostream& operator<< (std::ostream& os, const generator0& s)
157 {
158  if (!s.has_linexpr())
159  throw std::invalid_argument("apron::operator<<(ostream&, const generator0&) empty expression");
160  switch (s.get_gentyp()) {
161  case AP_GEN_LINE: os << "LINE: "; break;
162  case AP_GEN_RAY: os << "RAY: "; break;
163  case AP_GEN_VERTEX: os << "VERTEX: "; break;
164  case AP_GEN_LINEMOD: os << "LINEMOD: "; break;
165  case AP_GEN_RAYMOD: os << "RAYMOD: "; break;
166  default: throw std::invalid_argument("apron::operator<<(ostream&, const generator0&) invalid generator type");
167  }
168  return os << s.get_linexpr();
169 }
170 
171 
172 inline void generator0::print(char** name_of_dim, FILE* stream) const
173 {
174  ap_generator0_fprint(stream, const_cast<ap_generator0_t*>(&l), name_of_dim);
175 }
176 
177 
178 /* C-level compatibility */
179 /* ===================== */
180 
181 inline const ap_generator0_t* generator0::get_ap_generator0_t() const
182 {
183  return &l;
184 }
185 
186 inline ap_generator0_t* generator0::get_ap_generator0_t()
187 {
188  return &l;
189 }
190 
191 
192 
193 /* ================================= */
194 /* generator0_array */
195 /* ================================= */
196 
197 
198 /* constructors */
199 /* ============ */
200 
201 inline generator0_array::generator0_array(size_t size)
202  : a(ap_generator0_array_make(size))
203 {
204 }
205 
206 inline generator0_array::generator0_array(const generator0_array& x)
207  : a(ap_generator0_array_make(x.a.size))
208 {
209  for (size_t i=0; i<a.size; i++)
210  a.p[i] = ap_generator0_copy(&x.a.p[i]);
211 }
212 
213 inline generator0_array::generator0_array(size_t size, const generator0 x[])
214  : a(ap_generator0_array_make(size))
215 {
216  for (size_t i=0; i<size; i++)
217  a.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>(x[i].get_ap_generator0_t()));
218 }
219 
220 inline generator0_array::generator0_array(const std::vector<generator0>& x)
221  : a(ap_generator0_array_make(x.size()))
222 {
223  for (size_t i=0; i<a.size; i++)
224  a.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>(x[i].get_ap_generator0_t()));
225 }
226 
227 inline generator0_array::generator0_array(const generator0_array& x, const dimchange& d)
228 {
229  a = ap_generator0_array_add_dimensions(const_cast<ap_generator0_array_t*>(&x.a),
230  const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
231 }
232 
233 inline generator0_array::generator0_array(const generator0_array& x, const dimperm& d)
234 {
235  a = ap_generator0_array_permute_dimensions(const_cast<ap_generator0_array_t*>(&x.a),
236  const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
237 }
238 
239 
240 /* destructor */
241 /* ========== */
242 
243 inline generator0_array::~generator0_array()
244 {
245  ap_generator0_array_clear(&a);
246 }
247 
248 
249 /* assignment */
250 /* ========== */
251 
252 inline generator0_array& generator0_array::operator= (const generator0_array& x)
253 {
254  if (&x!=this) {
255  ap_generator0_array_clear(&a);
256  a = ap_generator0_array_make(x.a.size);
257  for (size_t i=0; i<a.size; i++) a.p[i] = ap_generator0_copy(&x.a.p[i]);
258  }
259  return *this;
260 }
261 
262 inline generator0_array& generator0_array::operator= (const generator0 x[])
263 {
264  size_t size = a.size;
265  ap_generator0_array_clear(&a);
266  a = ap_generator0_array_make(size);
267  for (size_t i=0; i<size; i++)
268  a.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>(x[i].get_ap_generator0_t()));
269  return *this;
270 }
271 
272 inline generator0_array& generator0_array::operator= (const std::vector<generator0>& x)
273 {
274  size_t size = x.size();
275  ap_generator0_array_clear(&a);
276  a = ap_generator0_array_make(size);
277  for (size_t i=0; i<size; i++)
278  a.p[i] = ap_generator0_copy(const_cast<ap_generator0_t*>(x[i].get_ap_generator0_t()));
279  return *this;
280 }
281 
282 
283 /* dimension operations */
284 /* ==================== */
285 
286 inline void generator0_array::resize(size_t size)
287 {
288  ap_generator0_array_resize(&a, size);
289 }
290 
291 inline void generator0_array::add_dimensions(const dimchange& d)
292 {
293  ap_generator0_array_add_dimensions_with(&a, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
294 }
295 
296 inline void generator0_array::permute_dimensions(const dimperm& d)
297 {
298  ap_generator0_array_permute_dimensions_with(&a, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
299 }
300 
301 
302 /* access */
303 /* ====== */
304 
305 inline size_t generator0_array::size() const
306 {
307  return a.size;
308 }
309 
310 inline generator0* generator0_array::contents()
311 {
312  return reinterpret_cast<generator0*>(a.p);
313 }
314 
315 inline const generator0* generator0_array::contents() const
316 {
317  return reinterpret_cast<generator0*>(a.p);
318 }
319 
320 inline generator0& generator0_array::operator[](size_t i)
321 {
322  return reinterpret_cast<generator0&>(a.p[i]);
323 }
324 
325 inline const generator0& generator0_array::operator[](size_t i) const
326 {
327  return reinterpret_cast<generator0&>(a.p[i]);
328 }
329 
330 inline generator0& generator0_array::get(size_t i)
331 {
332  if (i >= a.size) throw std::out_of_range("apron::generator0_array::get(size_t)");
333  return reinterpret_cast<generator0&>(a.p[i]);
334 }
335 
336 inline const generator0& generator0_array::get(size_t i) const
337 {
338  if (i >= a.size) throw std::out_of_range("apron::generator0_array::get(size_t)");
339  return reinterpret_cast<generator0&>(a.p[i]);
340 }
341 
342 
343 /* conversion */
344 /* ========== */
345 
346 inline generator0_array::operator std::vector<generator0>() const
347 {
348  size_t sz = size();
349  std::vector<generator0> v = std::vector<generator0>(sz);
350  for (size_t i=0;i<sz;i++)
351  v[i] = (*this)[i];
352  return v;
353 }
354 
355 
356 /* print */
357 /* ===== */
358 
359 inline std::ostream& operator<< (std::ostream& os, const generator0_array& s)
360 {
361  size_t size = s.size();
362  os << "{ ";
363  for (size_t i=0;i<size;i++)
364  os << s[i] << "; ";
365  return os << "}";
366 }
367 
368 inline void generator0_array::print(char** name_of_dim, FILE* stream) const
369 {
370  ap_generator0_array_fprint(stream, const_cast<ap_generator0_array_t*>(&a), name_of_dim);
371 }
372 
373 
374 /* C-level compatibility */
375 /* ===================== */
376 
377 inline const ap_generator0_array_t* generator0_array::get_ap_generator0_array_t() const
378 {
379  return &a;
380 }
381 
382 inline ap_generator0_array_t* generator0_array::get_ap_generator0_array_t()
383 {
384  return &a;
385 }
abstract0 & add_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimchange &d, bool project=false)
Definition: apxx_abstract0_inline.hh:1037
std::ostream & operator<<(std::ostream &os, const generator0 &s)
Definition: apxx_generator0_inline.hh:156
abstract0 & permute_dimensions(manager &m, abstract0 &dst, const abstract0 &src, const dimperm &d)
Definition: apxx_abstract0_inline.hh:1060