APRONXX 0.9.15
/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
24inline varname::varname(const std::vector<std::string>& names)
25 : names(names)
26{}
27
28template<class charT, class Traits>
29inline
30std::basic_ostream<charT,Traits>&
31operator<<(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
41template<class charT, class Traits>
42inline
43std::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
58inline dimchange::dimchange(size_t intdim, size_t realdim)
59{
60 ap_dimchange_init(&c, intdim, realdim);
61}
62
63inline 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
69inline 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
76inline 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
89inline dimchange::~dimchange()
90{
91 ap_dimchange_clear(&c);
92}
93
94
95/* assignment */
96/* ========== */
97
98inline 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
108inline 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
114inline 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
126inline size_t dimchange::get_intdim() const
127{
128 return c.intdim;
129}
130
131inline size_t dimchange::get_realdim() const
132{
133 return c.realdim;
134}
135
136inline 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
142inline 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
148inline ap_dim_t& dimchange::operator[](size_t dim)
149{
150 return c.dim[dim];
151}
152
153inline const ap_dim_t& dimchange::operator[](size_t dim) const
154{
155 return c.dim[dim];
156}
157
158
159/* print */
160/* ===== */
161
162inline 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
179inline 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
188inline void dimchange::add_invert()
189{
190 ap_dimchange_add_invert(&c);
191}
192
193inline 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
204inline const ap_dimchange_t* dimchange::get_ap_dimchange_t() const
205{
206 return &c;
207}
208
209inline 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
223inline dimperm::dimperm(size_t size)
224{
225 ap_dimperm_init(&c, size);
226}
227
228inline 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
234inline dimperm::dimperm(id t)
235{
236 ap_dimperm_init(&c, t.size);
237 ap_dimperm_set_id(&c);
238}
239
240inline 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
247inline 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
253inline 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
264inline dimperm::~dimperm()
265{
266 ap_dimperm_clear(&c);
267}
268
269
270/* assignment */
271/* ========== */
272
273inline 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
285inline 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
295inline 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
301inline 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
315inline size_t dimperm::size() const
316{
317 return c.size;
318}
319
320inline ap_dim_t& dimperm::operator[](size_t dim)
321{
322 return c.dim[dim];
323}
324
325inline const ap_dim_t& dimperm::operator[](size_t dim) const
326{
327 return c.dim[dim];
328}
329
330inline 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
336inline 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
346inline 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
368inline 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
379inline 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
392inline 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
404inline void dimperm::invert()
405{
406 dimperm tmp = *this;
407 ap_dimperm_invert(&c, &tmp.c);
408}
409
410inline 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
422inline const ap_dimperm_t* dimperm::get_ap_dimperm_t() const
423{
424 return &c;
425}
426
427inline ap_dimperm_t* dimperm::get_ap_dimperm_t()
428{
429 return &c;
430}
std::vector< std::string > * get_varname(std::basic_ostream< charT, Traits > &os)
Definition apxx_dimension_inline.hh:43
std::basic_ostream< charT, Traits > & operator<<(std::basic_ostream< charT, Traits > &os, const varname &v)
Definition apxx_dimension_inline.hh:31
dimperm operator*(const dimperm &x, const dimperm &y)
Definition apxx_dimension_inline.hh:392