APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_dimension.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_dimension.hh
3 *
4 * APRON Library / C++ class wrappers
5 *
6 * Copyright (C) Antoine Mine' 2007
7 *
8 */
9/* This file is part of the APRON Library, released under LGPL license
10 with an exception allowing the redistribution of statically linked
11 executables.
12
13 Please read the COPYING file packaged in the distribution.
14*/
15
16#ifndef __APXX_DIMENSION_HH
17#define __APXX_DIMENSION_HH
18
19#include "ap_dimension.h"
20
21
22namespace apron {
23
24
25/* ================================= */
26/* varname */
27/* ================================= */
28
41
43class varname {
45protected:
46
48 static const int xindex;
49
51 const std::vector<std::string>& names;
52
53public:
54
59 * If there are not enough names, printing functions will revert to
60 * xi, xi+1... To disable variable names, simply pass an empty vector.
61 *
62 * A reference to \c names is kept by the object and will be passed to the
63 * stream by the modifier. The stream will then make a deep copy and the
64 * varname object and the original vector can be safely deleted.
65 *
66 */
67 varname(const std::vector<std::string>& names);
68
69
70 template<class charT, class Traits>
71 friend
72 std::basic_ostream<charT,Traits>&
73 operator<<(std::basic_ostream<charT,Traits>& os, const varname& v);
74
76
77 * \return a pointer to the vector formerly associated to the
78 * stream, or NULL.
79 */
80 template<class charT, class Traits>
81 friend
82 std::vector<std::string>* get_varname(std::basic_ostream<charT,Traits>& os);
83
84};
85
86
87
88
89/* ================================= */
90/* dimchange */
91/* ================================= */
92
93
94
99 * an array of indices where to add/remove dimensions.
100 * The array should be sorted in increasing order.
101 */
102class dimchange : public use_malloc {
103
104protected:
105
106 ap_dimchange_t c;
107
108public:
110 /* constructor */
111 /* =========== */
112
114
117 dimchange(size_t intdim=0, size_t realdim=0);
118
123 dimchange(size_t intdim, size_t realdim, const ap_dim_t d[]);
124
127 * \exception std::invalid_argument if d contains less than intdim+realdim dimensions.
128 */
129 dimchange(size_t intdim, size_t realdim, const std::vector<ap_dim_t>& d);
130
131
133 * \arg inv if inv==true, then the constructed dimchange is the inverse of x (see add_invert).
134 */
135 dimchange(const dimchange& x, bool inv=false);
136
137 //@}
138
139
140 /* destructor */
141 /* ========== */
142
143 /** @name Destructor */
145
146 ~dimchange();
147
148
150
151 /* assignment */
152 /* ========== */
153
154 /** @name Assignments */
156
158 dimchange& operator= (const dimchange& x);
159
163 */
164 dimchange& operator= (const ap_dim_t d[]);
165
170 dimchange& operator= (const std::vector<ap_dim_t>& d);
171
173
174
175 /* access */
176 /* ====== */
177
179
182 size_t get_intdim() const;
183
184
185 size_t get_realdim() const;
186
189 * \arg \c dim should be strictly smaller than intdim+realdim (not bound-checked).
190 */
191 ap_dim_t& operator[](size_t dim);
192
193
195 * \arg \c dim should be strictly smaller than intdim+realdim (not bound-checked).
196 */
197 const ap_dim_t& operator[](size_t dim) const;
198
199
203 ap_dim_t& get(size_t dim);
204
205 /*! \brief Returns a reference to a (checked) index in the underlying array (bound-checked).
206 *
207 * \exception std::out_of_range is thrown if dim>=intdim+realdim.
208 */
209 const ap_dim_t& get(size_t dim) const;
212
213
214 /* print */
215 /* ===== */
216
219
224 friend std::ostream& operator<< (std::ostream& os, const dimchange& s);
225
227 void print(FILE* stream=stdout) const;
228
229 //@}
230
231
232
233 /* other operators */
234 /* =============== */
238
240
241 * If the dimchange was used to add some dimensions, it can now be used to remove the
242 * added dimensions (but not the converse).
243 */
244 void add_invert();
245
247
248 * See \c add_invert.
249 */
250 dimchange operator- () const;
251
253
255 /* C-level compatibility */
256 /* ===================== */
257
260
262 const ap_dimchange_t* get_ap_dimchange_t() const;
263
265 ap_dimchange_t* get_ap_dimchange_t();
266
268};
269
270
271
273struct id {
274 size_t size;
275
276 id(size_t size) : size(size) {}
277};
278
279
280
281/* ================================= */
282/* dimperm */
283/* ================================= */
284
285
286/*! \brief Dimension permutation object (ap_dimperm_t wrapper).
287 *
288 * dimperm objects can be used to permute dimensions in expressions, constraints, and domains.
289 * They hold a map i->p[i]: [0,size-1]=>[0,size-1] using an array p of dimensions.
290 * All the p[i] must be distinct and in the range [0,size-1] where size is the size of p.
291 */
292class dimperm : public use_malloc {
293
294protected:
295
296 ap_dimperm_t c;
297
298public:
299
300
301 /* constructor */
302 /* =========== */
303
306
308 dimperm(size_t size=0);
309
311
314 dimperm(size_t size, const ap_dim_t d[]);
315
316 //! Makes a dimperm initialized with the vector d.
317 dimperm(const std::vector<ap_dim_t>& d);
318
319
320
321 dimperm(id t);
322
325
326 */
327 dimperm(const dimperm& x, bool inv=false);
328
330 dimperm(const dimperm& x, const dimperm& y);
333
334
335 /* destructor */
336 /* ========== */
340
341 ~dimperm();
342
344
345
346 /* assignment */
347 /* ========== */
348
351
353 dimperm& operator= (const dimperm& x);
354
356 dimperm& operator= (id t);
357
362 dimperm& operator= (const ap_dim_t d[]);
363
365 dimperm& operator= (const std::vector<ap_dim_t>& d);
366
368
370 /* access */
371 /* ====== */
372
373
375
377 size_t size() const;
378
381 * \arg \c dim should be strictly smaller than size (not bound-checked).
382 */
383 ap_dim_t& operator[](size_t dim);
384
389 const ap_dim_t& operator[](size_t dim) const;
390
392
393 * \exception std::out_of_range is thrown if dim>=size.
394 */
395 ap_dim_t& get(size_t dim);
396
401 const ap_dim_t& get(size_t dim) const;
402
404
406 /* print */
407 /* ===== */
408
410
416 friend std::ostream& operator<< (std::ostream& os, const dimperm& s);
417
419 void print(FILE* stream=stdout) const;
420
422
424 /* other operators */
425 /* =============== */
426
427
428 //@{
429
430 /* composition */
431
432
436 dimperm& operator*= (const dimperm& y);
437
442 friend dimperm operator* (const dimperm& x, const dimperm& y);
443
444
445
446 /* inversion */
447
449 void invert();
450
452 dimperm operator- () const;
453
455
456
457 /* C-level compatibility */
458 /* ===================== */
459
462
464 const ap_dimperm_t* get_ap_dimperm_t() const;
465
467 ap_dimperm_t* get_ap_dimperm_t();
468
470
471};
472
474
475}
476
477#endif /* __APXX_DIMENSION_HH */
Represents a dimension (i.e., variable by index) in an expression tree.
Definition apxx_texpr0.hh:33
Dimension change object (ap_dimchange_t wrapper).
Definition apxx_dimension.hh:102
ap_dim_t & operator[](size_t dim)
Returns a (modifiable) reference to an index in the underlying array.
Definition apxx_dimension.hh:149
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
void add_invert()
Inverts *this.
Definition apxx_dimension.hh:189
friend std::ostream & operator<<(std::ostream &os, const dimchange &s)
Printing.
Definition apxx_dimension.hh:163
dimchange & operator=(const dimchange &x)
(Deep) copy.
Definition apxx_dimension.hh:99
dimchange operator-() const
Returns the inverse of *this.
Definition apxx_dimension.hh:194
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
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_dimension.hh:180
size_t get_intdim() const
Returns the number of integer dimensions to add/remove.
Definition apxx_dimension.hh:127
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
~dimchange()
Definition apxx_dimension.hh:90
size_t get_realdim() const
Returns the number of real dimensions to add/remove.
Definition apxx_dimension.hh:132
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
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_dimension.hh:369
dimperm(size_t size=0)
Makes an uninitialized dimperm of the given size.
Definition apxx_dimension.hh:224
size_t size() const
Returns the size of the permutation.
Definition apxx_dimension.hh:316
ap_dim_t & operator[](size_t dim)
Returns a (modifiable) reference to the image of dim.
Definition apxx_dimension.hh:321
ap_dimperm_t * get_ap_dimperm_t()
Returns a pointer to the internal APRON object stored in *this.
Definition apxx_dimension.hh:428
ap_dim_t & get(size_t dim)
Returns a (modifiable) reference to the image of dim (bound-checked).
Definition apxx_dimension.hh:331
void invert()
Inverts *this.
Definition apxx_dimension.hh:405
friend std::ostream & operator<<(std::ostream &os, const dimperm &s)
Printing.
Definition apxx_dimension.hh:347
~dimperm()
Definition apxx_dimension.hh:265
dimperm & operator=(const dimperm &x)
Copies x.
Definition apxx_dimension.hh:274
ap_dimperm_t c
Structure managed by APRON.
Definition apxx_dimension.hh:296
dimperm operator-() const
Returns a new dimperm that is the inverse of *this.
Definition apxx_dimension.hh:411
friend dimperm operator*(const dimperm &x, const dimperm &y)
Returns a new dimperm that is the composition of x and y.
Definition apxx_dimension.hh:393
dimperm & operator*=(const dimperm &y)
Composes *this with y.
Definition apxx_dimension.hh:380
Stream modifier to set variable names to dimensions.
Definition apxx_dimension.hh:43
friend std::vector< std::string > * get_varname(std::basic_ostream< charT, Traits > &os)
Gets the variable name vector associated to the stream.
Definition apxx_dimension.hh:44
static const int xindex
Index to stream-local data, allocated with xalloc.
Definition apxx_dimension.hh:48
friend std::basic_ostream< charT, Traits > & operator<<(std::basic_ostream< charT, Traits > &os, const varname &v)
Associates the modifier to the stream.
Definition apxx_dimension.hh:32
const std::vector< std::string > & names
Names of variables.
Definition apxx_dimension.hh:51
varname(const std::vector< std::string > &names)
Creates a modifier to associate variable names to dimensions.
Definition apxx_dimension.hh:25
Definition apxx_abstract0.hh:27
id(size_t size)
Definition apxx_dimension.hh:276
size_t size
Size of the permutation.
Definition apxx_dimension.hh:274
Inherited by most wrappers to map new and delete to malloc and free.
Definition apxx_scalar.hh:69