PPL C Language Interface  1.2
ppl_c_implementation_common_inlines.hh
Go to the documentation of this file.
1 /* Implementation of the C interface: inline functions.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_ppl_c_implementation_common_inlines_hh
25 #define PPL_ppl_c_implementation_common_inlines_hh 1
26 
27 namespace Parma_Polyhedra_Library {
28 
29 namespace Interfaces {
30 
31 namespace C {
32 
33 // FIXME: this same function is used also in the OCaml interface.
34 // It should be placed in some common header file in the interfaces
35 // directory.
37 inline mpz_class&
38 reinterpret_mpz_class(mpz_t n) {
39  return reinterpret_cast<mpz_class&>(*n);
40 }
41 
43 
44 DECLARE_CONVERSIONS(Linear_Expression, Linear_Expression)
45 
46 DECLARE_CONVERSIONS(Constraint, Constraint)
47 
48 DECLARE_CONVERSIONS(Constraint_System, Constraint_System)
49 
50 DECLARE_CONVERSIONS(Constraint_System_const_iterator,
51  Constraint_System_const_iterator)
52 
53 DECLARE_CONVERSIONS(Generator, Generator)
54 
55 DECLARE_CONVERSIONS(Generator_System, Generator_System)
56 
57 DECLARE_CONVERSIONS(Generator_System_const_iterator,
58  Generator_System_const_iterator)
59 
60 DECLARE_CONVERSIONS(Congruence, Congruence)
61 
62 DECLARE_CONVERSIONS(Congruence_System, Congruence_System)
63 
64 typedef Congruence_System::const_iterator Congruence_System_const_iterator;
65 DECLARE_CONVERSIONS(Congruence_System_const_iterator,
66  Congruence_System_const_iterator)
67 
68 DECLARE_CONVERSIONS(Grid_Generator, Grid_Generator)
69 
70 DECLARE_CONVERSIONS(Grid_Generator_System, Grid_Generator_System)
71 
72 typedef Grid_Generator_System::const_iterator
73 Grid_Generator_System_const_iterator;
74 DECLARE_CONVERSIONS(Grid_Generator_System_const_iterator,
75  Grid_Generator_System_const_iterator)
76 
77 typedef PIP_Tree_Node::Artificial_Parameter
78 Artificial_Parameter;
79 DECLARE_CONVERSIONS(Artificial_Parameter, Artificial_Parameter)
80 
81 typedef PIP_Tree_Node::Artificial_Parameter_Sequence
82 Artificial_Parameter_Sequence;
83 DECLARE_CONVERSIONS(Artificial_Parameter_Sequence,
84  Artificial_Parameter_Sequence)
85 
86 typedef PIP_Tree_Node::Artificial_Parameter_Sequence::const_iterator
87 Artificial_Parameter_Sequence_const_iterator;
88 DECLARE_CONVERSIONS(Artificial_Parameter_Sequence_const_iterator,
89  Artificial_Parameter_Sequence_const_iterator)
90 
91 DECLARE_CONVERSIONS(MIP_Problem, MIP_Problem)
92 
93 DECLARE_CONVERSIONS(PIP_Problem, PIP_Problem)
94 
95 DECLARE_CONVERSIONS(PIP_Tree_Node, PIP_Tree_Node)
96 
97 DECLARE_CONVERSIONS(PIP_Decision_Node, PIP_Decision_Node)
98 
99 DECLARE_CONVERSIONS(PIP_Solution_Node, PIP_Solution_Node)
100 
101 inline Relation_Symbol
102 relation_symbol(enum ppl_enum_Constraint_Type t) {
103  switch (t) {
105  return LESS_THAN;
107  return LESS_OR_EQUAL;
109  return EQUAL;
111  return GREATER_OR_EQUAL;
113  return GREATER_THAN;
114  default:
115  return static_cast<Relation_Symbol>(t);
116  }
117 }
118 
120 bounded_integer_type_width(enum ppl_enum_Bounded_Integer_Type_Width w) {
121  switch (w) {
122  case PPL_BITS_8:
123  return BITS_8;
124  case PPL_BITS_16:
125  return BITS_16;
126  case PPL_BITS_32:
127  return BITS_32;
128  case PPL_BITS_64:
129  return BITS_64;
130  case PPL_BITS_128:
131  return BITS_128;
132  default:
133  return static_cast<Bounded_Integer_Type_Width>(w);
134  }
135 }
136 
138 bounded_integer_type_representation(enum ppl_enum_Bounded_Integer_Type_Representation r) {
139  switch (r) {
140  case PPL_UNSIGNED:
141  return UNSIGNED;
143  return SIGNED_2_COMPLEMENT;
144  default:
145  return static_cast<Bounded_Integer_Type_Representation>(r);
146  }
147 }
148 
150 bounded_integer_type_overflow(enum ppl_enum_Bounded_Integer_Type_Overflow o) {
151  switch (o) {
152  case PPL_OVERFLOW_WRAPS:
153  return OVERFLOW_WRAPS;
155  return OVERFLOW_UNDEFINED;
157  return OVERFLOW_IMPOSSIBLE;
158  default:
159  return static_cast<Bounded_Integer_Type_Overflow>(o);
160  }
161 }
162 
163 inline
166  : vec(v), vec_size(n), max_in_codomain_(not_a_dimension()), empty(-1) {
167 }
168 
169 inline bool
171  if (empty < 0) {
172  empty = 1;
173  for (size_t i = vec_size; i-- > 0; )
174  if (vec[i] != not_a_dimension()) {
175  empty = 0;
176  break;
177  }
178  }
179  return (empty != 0);
180 }
181 
182 inline dimension_type
185  for (size_t i = vec_size; i-- > 0; ) {
186  dimension_type vec_i = vec[i];
187  if (vec_i != not_a_dimension()
189  || vec_i > max_in_codomain_))
190  max_in_codomain_ = vec_i;
191  }
192  }
193  return max_in_codomain_;
194 }
195 
196 inline bool
198  dimension_type& j) const {
199  if (i >= vec_size)
200  return false;
201  dimension_type vec_i = vec[i];
202  if (vec_i == not_a_dimension())
203  return false;
204  j = vec_i;
205  return true;
206 }
207 
208 } // namespace C
209 
210 } // namespace Interfaces
211 
212 } // namespace Parma_Polyhedra_Library
213 
214 #endif // !defined(PPL_ppl_c_implementation_common_inlines_hh)
ppl_enum_Bounded_Integer_Type_Representation
Representation of bounded integer types.
Overflow is impossible.
dimension_type not_a_dimension()
dimension_type max_in_codomain() const
Returns the maximum value that belongs to the codomain of the partial function.
Array_Partial_Function_Wrapper(dimension_type *v, size_t n)
Construct a partial function wrapping the first n positions of v.
ppl_enum_Constraint_Type
Describes the relations represented by a constraint.
On overflow, wrapping takes place.
Bounded_Integer_Type_Overflow
bool has_empty_codomain() const
Returns true if and only if the represented partial function has an empty codomain (i...
bool maps(dimension_type i, dimension_type &j) const
Assigns to j the value associated to i by *this, if any.
#define DECLARE_CONVERSIONS(Type, CPP_Type)
Relation_Symbol
On overflow, the result is undefined.
Bounded_Integer_Type_Width
PPL_COEFFICIENT_TYPE Coefficient
dimension_type max_in_codomain_
Cache for computing the maximum dimension in the codomain.
ppl_enum_Bounded_Integer_Type_Width
Widths of bounded integer types.
ppl_enum_Bounded_Integer_Type_Overflow
Overflow behavior of bounded integer types.
Signed binary where negative values are represented by the two's complement of the absolute value...
const char * empty
Bounded_Integer_Type_Representation