APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_environment.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_environment.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_ENVIRONMENT_HH
17#define __APXX_ENVIRONMENT_HH
18
19#include <string>
20#include <vector>
22#include "ap_environment.h"
23#include "apxx_dimension.hh"
24#include "apxx_var.hh"
25
26
27namespace apron {
28
29
30/* ================================= */
31/* environment */
32/* ================================= */
33
40
45 * variable name addition, deletion, or renaming. Thus, such an operation can change the dimension associated to existing
46 * variable names.
47 *
48 * Environments are reference-counted and the API is fully functional (i.e., functions do not change *this but return
49 * a new object instead).
50 */
51class environment : public use_malloc {
52
53protected:
54
55 ap_environment_t* e;
56
58 environment(ap_environment_t* x) : e(x) {}
60 friend class linexpr1;
61 friend class lincons1;
62 friend class lincons1_array;
63 friend class generator1;
64 friend class generator1_array;
65 friend class texpr1;
66 friend class tcons1;
67 friend class tcons1_array;
68 friend class abstract1;
69
70public:
72
73 /* constructors */
74 /* ============ */
75
76
79
80 //! Creates a new empty environment.
82
87 environment(const std::vector<var>& intdim, const std::vector<var>& realdim);
88
93 environment(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size);
94
96 environment(const environment& x);
97
99
100
102
105 ~environment();
106
108
109
110 /* assignment */
111 /* ========== */
112
113 /** @name Assignment */
115
117 const environment& operator=(const environment& x);
118
120
121
122 /* operations */
123 /* ========== */
124
125
126 //@{
127
132 environment add(const std::vector<var>& intdim, const std::vector<var>& realdim) const;
133
138 environment add(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size) const;
139
140 /*! \brief Returns a copy of the environment with some integer and/or real variable names added.
141 *
142 * Sets perm to the dimension permutation that has been performed after appending variable names at the end of
143 * integer (resp. real) dimensions to get them sorted again.
144 *
145 * \throw std::invalid_argument if the resulting environment has duplicate variable names.
146 */
147 environment add(const std::vector<var>& intdim, const std::vector<var>& realdim, dimperm& perm) const;
148
149 /*! \brief Returns a copy of the environment with intdim_size integer and realdim_size real variable names added.
150 *
151 * Sets perm to the dimension permutation that has been performed after appending variable names at the end of
152 * integer (resp. real) dimensions to get them sorted again.
153 *
154 * \throw std::invalid_argument if the resulting environment has duplicate variable names.
155 */
156 environment add(const var* intdim, size_t intdim_size, const var* realdim, size_t realdim_size, dimperm& perm) const;
157
158
160 * \throw std::invalid_argument if some variable name does not exist.
161 */
162 environment remove(const std::vector<var>& dims) const;
163
168 environment remove(const var* dims, size_t dims_size) const;
169
170
172 * dims[i].first is replaced with dims[i].second.
173 *
174 * \throw std::invalid_argument if some variable name does not exist.
175 */
176 environment rename(const std::vector<std::pair<var,var> >& dims) const;
177
183
184 environment rename(const var* before, const var* after, size_t dims_size) const;
185
194 environment rename(const std::vector<std::pair<var,var> >& dims, dimperm& perm) const;
195
197
198 * before[i] is replaced with after[i]. Both array should contain dims_size elements.
199 * Sets perm to the dimension permutation that has been performed after renaming the variable names in-place to get them
200 * sorted again.
201 *
202 * \throw std::invalid_argument if some variable name does not exist.
203 */
204 environment rename(const var* before, const var* after, size_t dims_size, dimperm& perm) const;
205
210 friend environment lce(const environment& x, const environment& y);
211
214 * Sets chgx (resp. chgy) to the dimension transformation that has been performed after appending the required
215 * variable names to x (resp. y) to keep them sorted.
216 *
217 * \throw std::invalid_argument if some variable name has different type in both environments
218 */
219 friend environment lce(const environment& x, const environment& y, dimchange& chgx, dimchange& chgy);
220
222
223 * \throw std::invalid_argument if some variable name has different type in different environments
224 */
225 friend environment lce(const std::vector<environment>& x);
226
231 friend environment lce(const environment* env, size_t env_size);
232
236
237 * chg must have space for at least env_size elements.
238 *
239 * \throw std::invalid_argument if some variable name has different type in different environments
240 */
241 friend environment lce(const std::vector<environment>& x, std::vector<dimchange>& chg);
242
251 friend environment lce(const environment* env, dimchange* chg, size_t env_size);
252
253
255 * \throw std::invalid_argument if x is not a subset of y, or if x and chg have different size.
256 */
257 friend dimchange get_dimchange(const environment& x, const environment& y);
258
260
261
262 /* access */
263 /* ====== */
264
267
268
269 size_t intdim() const;
270
272 size_t realdim() const;
273
275 bool contains(const var& x) const;
276
281 ap_dim_t operator[] (const var& x) const;
282
284 const var& operator[] (ap_dim_t d) const;
285
290 ap_dim_t get_dim(const var& x) const;
291
292
294 * \throw std::out_of_range if the dimension is larger than the environment size.
295 */
296 const var& get_var(ap_dim_t d) const;
297
299 std::vector<var> get_vars() const;
300
301
303
304
305 /* Tests */
306 /* ===== */
307
310
312 friend bool operator==(const environment& x, const environment& y);
313
314 //! Disequality testing.
315 friend bool operator!=(const environment& x, const environment& y);
316
318 friend bool operator<=(const environment& x, const environment& y);
319
321 friend bool operator>=(const environment& x, const environment& y);
322
323
328 * - 0 if x equals y
329 * - +1 if x is a super-environment of y
330 * - +2 if x and y a not comparable but there exists a lowest upper bound
331 */
332 friend int cmp(const environment& x, const environment& y);
335
336
337 /* print */
338 /* ===== */
339
342
343 //! Printing.
344 friend std::ostream& operator<< (std::ostream& os, const environment& s);
345
347 void print(FILE* stream=stdout) const;
348
349
351
352 /* C API compatibility */
353 /* =================== */
354
355 /** @name C API compatibility */
357
359 const ap_environment_t* get_ap_environment_t() const;
360
361
362 ap_environment_t* get_ap_environment_t();
363
365
366};
367
369
370}
371
372#endif /* __APXX_ENVIRONMENT_HH */
Dimension change object (ap_dimchange_t wrapper).
Definition apxx_dimension.hh:102
Dimension permutation object (ap_dimperm_t wrapper).
Definition apxx_dimension.hh:292
const ap_environment_t * get_ap_environment_t() const
Returns a pointer to the internal APRON object pointed by *this.
Definition apxx_environment.hh:426
ap_environment_t * e
Definition apxx_environment.hh:55
friend int cmp(const environment &x, const environment &y)
Environment comparison.
Definition apxx_environment.hh:399
void print(FILE *stream=stdout) const
Prints to a C stream.
Definition apxx_environment.hh:417
size_t realdim() const
Returns the number of real dimensions in the environment.
Definition apxx_environment.hh:333
const environment & operator=(const environment &x)
Assignment (reference counter manipulation).
Definition apxx_environment.hh:80
environment add(const std::vector< var > &intdim, const std::vector< var > &realdim) const
Returns a copy of the environment with some integer and/or real variable names added.
Definition apxx_environment.hh:93
environment remove(const std::vector< var > &dims) const
Returns a copy of the environment with some variable names removed.
Definition apxx_environment.hh:140
std::vector< var > get_vars() const
Returns (a copy of) the full map from dimensions to variable names.
Definition apxx_environment.hh:368
environment rename(const var *before, const var *after, size_t dims_size, dimperm &perm) const
Returns a copy of the environment with dims_size variable names substituted.
Definition apxx_environment.hh:198
friend std::ostream & operator<<(std::ostream &os, const environment &s)
Printing.
Definition apxx_environment.hh:407
friend class linexpr1
Definition apxx_environment.hh:60
friend class tcons1
Definition apxx_environment.hh:66
friend class generator1
Definition apxx_environment.hh:63
bool contains(const var &x) const
Whether the environment contains the variable name x.
Definition apxx_environment.hh:338
ap_dim_t get_dim(const var &x) const
Returns the dimension associated with a variable name.
Definition apxx_environment.hh:355
friend bool operator==(const environment &x, const environment &y)
Equality testing.
Definition apxx_environment.hh:379
friend environment lce(const environment &x, const environment &y)
Returns the least common environment of two environments.
Definition apxx_environment.hh:213
ap_dim_t operator[](const var &x) const
Returns the dimension associated with the variable name.
Definition apxx_environment.hh:343
size_t intdim() const
Returns the number of integer dimensions in the environment.
Definition apxx_environment.hh:328
const var & get_var(ap_dim_t d) const
Returns the variable name at a given dimension (bound-checked).
Definition apxx_environment.hh:362
friend bool operator!=(const environment &x, const environment &y)
Disequality testing.
Definition apxx_environment.hh:384
environment()
Creates a new empty environment.
Definition apxx_environment.hh:45
friend class lincons1
Definition apxx_environment.hh:61
environment(ap_environment_t *x)
Used internally only. Wraps the APRON object in an environment object (no copy, no change in referenc...
Definition apxx_environment.hh:58
friend bool operator>=(const environment &x, const environment &y)
Inclusion testing.
Definition apxx_environment.hh:394
friend bool operator<=(const environment &x, const environment &y)
Inclusion testing.
Definition apxx_environment.hh:389
friend class abstract1
Definition apxx_environment.hh:68
friend class tcons1_array
Definition apxx_environment.hh:67
friend class texpr1
Definition apxx_environment.hh:65
friend class lincons1_array
Definition apxx_environment.hh:62
environment rename(const std::vector< std::pair< var, var > > &dims) const
Returns a copy of the environment with some variable names substituted.
Definition apxx_environment.hh:159
~environment()
Decrements the reference counter and, if null, actually frees the environment.
Definition apxx_environment.hh:71
environment rename(const std::vector< std::pair< var, var > > &dims, dimperm &perm) const
Returns a copy of the environment with some variable names substituted.
Definition apxx_environment.hh:184
friend class generator1_array
Definition apxx_environment.hh:64
friend dimchange get_dimchange(const environment &x, const environment &y)
Returns the dimension change to transform an environment x into a super-environment y.
Definition apxx_environment.hh:314
Variable name (ap_var_t wrapper).
Definition apxx_var.hh:39
Definition apxx_abstract0.hh:27
Inherited by most wrappers to map new and delete to malloc and free.
Definition apxx_scalar.hh:69