APRONXX  0.9.12
/home/mine/apron/apronxx/apxx_dimension_inline.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * apxx_dimension_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 /* varname */
22 /* ================================= */
23 
24 inline varname::varname(const std::vector<std::string>& names)
25  : names(names)
26 {}
27 
28 template<class charT, class Traits>
29 inline
30 std::basic_ostream<charT,Traits>&
31 operator<<(std::basic_ostream<charT,Traits>& os, const varname& v)
32 {
33  std::vector<std::string>*& vv =
34  (std::vector<std::string>*&)os.pword(varname::xindex);
35  if (vv) delete vv;
36  if (v.names.size()) vv = new std::vector<std::string>(v.names);
37  else vv = NULL;
38  return os;
39 }
40 
41 template<class charT, class Traits>
42 inline
43 std::vector<std::string>* get_varname(std::basic_ostream<charT,Traits>& os)
44 {
45  return (std::vector<std::string>*)os.pword(varname::xindex);
46 }
47 
48 
49 
50 /* ================================= */
51 /* dimchange */
52 /* ================================= */
53 
54 
55 /* constructor */
56 /* =========== */
57 
58 inline dimchange::dimchange(size_t intdim, size_t realdim)
59 {
60  ap_dimchange_init(&c, intdim, realdim);
61 }
62 
63 inline dimchange::dimchange(size_t intdim, size_t realdim, const ap_dim_t d[])
64 {
65  ap_dimchange_init(&c, intdim, realdim);
66  memcpy(c.dim, d, sizeof(ap_dim_t) * (intdim + realdim));
67 }
68 
69 inline dimchange::dimchange(const dimchange& x, bool inv)
70 {
71  ap_dimchange_init(&c, x.c.intdim, x.c.realdim);
72  memcpy(c.dim, x.c.dim, sizeof(ap_dim_t) * (x.c.intdim + x.c.realdim));
73  if (inv) ap_dimchange_add_invert(&c);
74 }
75 
76 inline dimchange::dimchange(size_t intdim, size_t realdim, const std::vector<ap_dim_t>& d)
77 {
78  if (d.size()<intdim+realdim)
79  throw std::invalid_argument("apron::dimchange::dimchange(size_t, size_t, const vector<ap_dim_t>&) vector too short");
80  ap_dimchange_init(&c, intdim, realdim);
81  for (size_t i=0; i<intdim+realdim; i++)
82  c.dim[i] = d[i];
83 }
84 
85 
86 /* destructor */
87 /* ========== */
88 
89 inline dimchange::~dimchange()
90 {
91  ap_dimchange_clear(&c);
92 }
93 
94 
95 /* assignment */
96 /* ========== */
97 
98 inline dimchange& dimchange::operator= (const dimchange& x)
99 {
100  if (&x!=this) {
101  ap_dimchange_clear(&c);
102  ap_dimchange_init(&c, x.c.intdim, x.c.realdim);
103  memcpy(c.dim, x.c.dim, sizeof(ap_dim_t) * (x.c.intdim + x.c.realdim));
104  }
105  return *this;
106 }
107 
108 inline dimchange& dimchange::operator= (const ap_dim_t d[])
109 {
110  memcpy(c.dim, d, sizeof(ap_dim_t) * (c.intdim + c.realdim));
111  return *this;
112 }
113 
114 inline dimchange& dimchange::operator= (const std::vector<ap_dim_t>& d)
115 {
116  if (d.size()<c.intdim+c.realdim)
117  throw std::invalid_argument("apron::dimchange::operator=(const vector<ap_dim_t>&) vector too short");
118  for (size_t i=0; i<c.intdim+c.realdim; i++)
119  c.dim[i] = d[i];
120  return *this;
121 }
122 
123 /* access */
124 /* ====== */
125 
126 inline size_t dimchange::get_intdim() const
127 {
128  return c.intdim;
129 }
130 
131 inline size_t dimchange::get_realdim() const
132 {
133  return c.realdim;
134 }
135 
136 inline ap_dim_t& dimchange::get(size_t dim)
137 {
138  if (dim >= c.intdim + c.realdim) throw std::out_of_range("apron::dimchange::get(size_t)");
139  return c.dim[dim];
140 }
141 
142 inline const ap_dim_t& dimchange::get(size_t dim) const
143 {
144  if (dim >= c.intdim + c.realdim) throw std::out_of_range("apron::dimchange::get(size_t)");
145  return c.dim[dim];
146 }
147 
148 inline ap_dim_t& dimchange::operator[](size_t dim)
149 {
150  return c.dim[dim];
151 }
152 
153 inline const ap_dim_t& dimchange::operator[](size_t dim) const
154 {
155  return c.dim[dim];
156 }
157 
158 
159 /* print */
160 /* ===== */
161 
162 inline std::ostream& operator<< (std::ostream& os, const dimchange& s)
163 {
164  std::vector<std::string>* names = get_varname(os);
165  os << "dimchange: intdim=" << s.c.intdim << ", realdim=" << s.c.realdim << std::endl;
166  if (names) {
167  size_t sz = (*names).size();
168  for (size_t i=0;i<s.c.intdim+s.c.realdim;i++)
169  if (s.c.dim[i] < sz) os << (*names)[s.c.dim[i]] << " ";
170  else os << "x" << s.c.dim[i] << " ";
171  }
172  else {
173  for (size_t i=0;i<s.c.intdim+s.c.realdim;i++)
174  os << "x" << s.c.dim[i] << " ";
175  }
176  return os << std::endl;
177 }
178 
179 inline void dimchange::print(FILE* stream) const
180 {
181  ap_dimchange_fprint(stream, const_cast<ap_dimchange_t*>(&c));
182 }
183 
184 
185 /* other operators */
186 /* =============== */
187 
188 inline void dimchange::add_invert()
189 {
190  ap_dimchange_add_invert(&c);
191 }
192 
193 inline dimchange dimchange::operator- () const
194 {
195  dimchange r = *this; ap_dimchange_add_invert(&r.c);
196  return r;
197 }
198 
199 
200 
201 /* C-level compatibility */
202 /* ===================== */
203 
204 inline const ap_dimchange_t* dimchange::get_ap_dimchange_t() const
205 {
206  return &c;
207 }
208 
209 inline ap_dimchange_t* dimchange::get_ap_dimchange_t()
210 {
211  return &c;
212 }
213 
214 
215 /* ================================= */
216 /* dimperm */
217 /* ================================= */
218 
219 
220 /* constructor */
221 /* =========== */
222 
223 inline dimperm::dimperm(size_t size)
224 {
225  ap_dimperm_init(&c, size);
226 }
227 
228 inline dimperm::dimperm(size_t size, const ap_dim_t d[])
229 {
230  ap_dimperm_init(&c, size);
231  memcpy(c.dim, d, sizeof(ap_dim_t) * (size));
232 }
233 
234 inline dimperm::dimperm(id t)
235 {
236  ap_dimperm_init(&c, t.size);
237  ap_dimperm_set_id(&c);
238 }
239 
240 inline dimperm::dimperm(const dimperm& x, bool inv)
241 {
242  ap_dimperm_init(&c, x.c.size);
243  if (inv) ap_dimperm_invert(&c, const_cast<ap_dimperm_t*>(&x.c));
244  else memcpy(c.dim, x.c.dim, sizeof(ap_dim_t) * (x.c.size));
245 }
246 
247 inline dimperm::dimperm(const dimperm& x, const dimperm& y)
248 {
249  ap_dimperm_init(&c, x.c.size);
250  ap_dimperm_compose( &c, const_cast<ap_dimperm_t*>(&x.c), const_cast<ap_dimperm_t*>(&y.c) );
251 }
252 
253 inline dimperm::dimperm(const std::vector<ap_dim_t>& d)
254 {
255  ap_dimperm_init(&c, d.size());
256  for (size_t i=0; i<d.size(); i++)
257  c.dim[i] = d[i];
258 }
259 
260 
261 /* destructor */
262 /* ========== */
263 
264 inline dimperm::~dimperm()
265 {
266  ap_dimperm_clear(&c);
267 }
268 
269 
270 /* assignment */
271 /* ========== */
272 
273 inline dimperm& dimperm::operator= (const dimperm& x)
274 {
275  if (&x!=this) {
276  if (x.c.size!=c.size) {
277  ap_dimperm_clear(&c);
278  ap_dimperm_init(&c, x.c.size);
279  }
280  memcpy(c.dim, x.c.dim, sizeof(ap_dim_t) * c.size);
281  }
282  return *this;
283 }
284 
285 inline dimperm& dimperm::operator= (id t)
286 {
287  if (t.size!=c.size) {
288  ap_dimperm_clear(&c);
289  ap_dimperm_init(&c, t.size);
290  }
291  ap_dimperm_set_id(&c);
292  return *this;
293 }
294 
295 inline dimperm& dimperm::operator= (const ap_dim_t d[])
296 {
297  memcpy(c.dim, d, sizeof(ap_dim_t) * c.size);
298  return *this;
299 }
300 
301 inline dimperm& dimperm::operator= (const std::vector<ap_dim_t>& d)
302 {
303  if (c.size!=d.size()) {
304  ap_dimperm_clear(&c);
305  ap_dimperm_init(&c, d.size());
306  }
307  for (size_t i=0; i<c.size; i++) c.dim[i] = d[i];
308  return *this;
309 }
310 
311 
312 /* access */
313 /* ====== */
314 
315 inline size_t dimperm::size() const
316 {
317  return c.size;
318 }
319 
320 inline ap_dim_t& dimperm::operator[](size_t dim)
321 {
322  return c.dim[dim];
323 }
324 
325 inline const ap_dim_t& dimperm::operator[](size_t dim) const
326 {
327  return c.dim[dim];
328 }
329 
330 inline ap_dim_t& dimperm::get(size_t dim)
331 {
332  if (dim >= c.size) throw std::out_of_range("apron::dimperm::get(size_t)");
333  return c.dim[dim];
334 }
335 
336 inline const ap_dim_t& dimperm::get(size_t dim) const
337 {
338  if (dim >= c.size) throw std::out_of_range("apron::dimperm::get(size_t)");
339  return c.dim[dim];
340 }
341 
342 
343 /* print */
344 /* ===== */
345 
346 inline std::ostream& operator<< (std::ostream& os, const dimperm& s)
347 {
348  std::vector<std::string>* names = get_varname(os);
349  os << "dimperm: size=" << s.c.size << std::endl;
350  if (names) {
351  size_t sz = (*names).size();
352  for (size_t i=0;i<s.c.size;i++) {
353  if (i<sz) os << (*names)[i];
354  else os << "x" << i;
355  os << " -> ";
356  if (s.c.dim[i]<sz) os << (*names)[s.c.dim[i]];
357  else os << "x" << s.c.dim[i];
358  os << std::endl;
359  }
360  }
361  else {
362  for (size_t i=0;i<s.c.size;i++)
363  os << "x" << i << " -> " << "x" << s.c.dim[i] << std::endl;
364  }
365  return os;
366 }
367 
368 inline void dimperm::print(FILE* stream) const
369 {
370  ap_dimperm_fprint(stream, const_cast<ap_dimperm_t*>(&c));
371 }
372 
373 
374 /* other operators */
375 /* =============== */
376 
377 /* composition */
378 
379 inline dimperm& dimperm::operator*= (const dimperm& y)
380 {
381  if (c.size!=y.c.size)
382  throw std::invalid_argument("apron::dimperm::operator*= (const dimperm&) size mismatch");
383  if (&y==this) {
384  dimperm tmp = y;
385  ap_dimperm_compose(&c, &c, const_cast<ap_dimperm_t*>(&tmp.c));
386  }
387  else
388  ap_dimperm_compose(&c, &c, const_cast<ap_dimperm_t*>(&y.c));
389  return *this;
390 }
391 
392 inline dimperm operator* (const dimperm& x, const dimperm& y)
393 {
394  if (x.c.size!=y.c.size)
395  throw std::invalid_argument("apron::dimperm::operator* (const dimperm&, const dimperm&) size mismatch");
396  dimperm r = x.c.size;
397  ap_dimperm_compose(&r.c, const_cast<ap_dimperm_t*>(&x.c), const_cast<ap_dimperm_t*>(&y.c));
398  return r;
399 }
400 
401 
402 /* inversion */
403 
404 inline void dimperm::invert()
405 {
406  dimperm tmp = *this;
407  ap_dimperm_invert(&c, &tmp.c);
408 }
409 
410 inline dimperm dimperm::operator- () const
411 {
412  dimperm r = c.size;
413  ap_dimperm_invert(&r.c, const_cast<ap_dimperm_t*>(&c));
414  return r;
415 }
416 
417 
418 
419 /* C-level compatibility */
420 /* ===================== */
421 
422 inline const ap_dimperm_t* dimperm::get_ap_dimperm_t() const
423 {
424  return &c;
425 }
426 
427 inline ap_dimperm_t* dimperm::get_ap_dimperm_t()
428 {
429  return &c;
430 }
dimperm & operator=(const dimperm &x)
Copies x.
Definition: apxx_dimension.hh:274
ap_dim_t & get(size_t dim)
Returns a (modifiable) reference to an index in the underlying array (bound-checked).
Definition: apxx_dimension.hh:137
dimperm(size_t size=0)
Makes an uninitialized dimperm of the given size.
Definition: apxx_dimension.hh:224
const ap_dimperm_t * get_ap_dimperm_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition: apxx_dimension.hh:423
std::ostream & operator<<(std::ostream &os, const abstract0 &s)
Definition: apxx_abstract0.hh:293
size_t size() const
Returns the size of the permutation.
Definition: apxx_dimension.hh:316
const ap_dimchange_t * get_ap_dimchange_t() const
Returns a pointer to the internal APRON object stored in *this.
Definition: apxx_dimension.hh:205
dimchange operator-() const
Returns the inverse of *this.
Definition: apxx_dimension.hh:194
ap_dimchange_t c
Structure managed by APRON.
Definition: apxx_dimension.hh:106
dimchange(size_t intdim=0, size_t realdim=0)
Makes an uninitialized dimchange.
Definition: apxx_dimension.hh:59
~dimperm()
Definition: apxx_dimension.hh:265
ap_dim_t & operator[](size_t dim)
Returns a (modifiable) reference to the image of dim.
Definition: apxx_dimension.hh:321
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_dimension.hh:369
ap_dim_t & get(size_t dim)
Returns a (modifiable) reference to the image of dim (bound-checked).
Definition: apxx_dimension.hh:331
dimchange & operator=(const dimchange &x)
(Deep) copy.
Definition: apxx_dimension.hh:99
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition: apxx_dimension.hh:180
dimperm operator *(const dimperm &x, const dimperm &y)
Definition: apxx_dimension.hh:393
dimperm & operator *=(const dimperm &y)
Composes *this with y.
Definition: apxx_dimension.hh:380
size_t get_realdim() const
Returns the number of real dimensions to add/remove.
Definition: apxx_dimension.hh:132
size_t get_intdim() const
Returns the number of integer dimensions to add/remove.
Definition: apxx_dimension.hh:127
~dimchange()
Definition: apxx_dimension.hh:90
std::vector< std::string > * get_varname(std::basic_ostream< charT, Traits > &os)
Definition: apxx_dimension.hh:44
void add_invert()
Inverts *this.
Definition: apxx_dimension.hh:189
ap_dim_t & operator[](size_t dim)
Returns a (modifiable) reference to an index in the underlying array.
Definition: apxx_dimension.hh:149
dimperm operator-() const
Returns a new dimperm that is the inverse of *this.
Definition: apxx_dimension.hh:411
void invert()
Inverts *this.
Definition: apxx_dimension.hh:405
ap_dimperm_t c
Structure managed by APRON.
Definition: apxx_dimension.hh:296
static const int xindex
Index to stream-local data, allocated with xalloc.
Definition: apxx_dimension.hh:48