PPL  1.2
Linear_Expression.cc
Go to the documentation of this file.
1 /* Linear_Expression class implementation (non-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 
25 #include "ppl-config.h"
27 
29 #include "Dense_Row_defs.hh"
30 #include "Sparse_Row_defs.hh"
31 
32 namespace PPL = Parma_Polyhedra_Library;
33 
36  return Dense_Row::max_size() - 1;
37 }
38 
40 
41 void
43  PPL_ASSERT(zero_p == 0);
44  zero_p = new Linear_Expression(Coefficient_zero());
45 }
46 
47 void
49  PPL_ASSERT(zero_p != 0);
50  delete zero_p;
51  zero_p = 0;
52 }
53 
55  switch (r) {
56  case DENSE:
58  break;
59  case SPARSE:
61  break;
62  default:
63  PPL_UNREACHABLE;
64  }
65 }
66 
68  Representation r) {
69  switch (r) {
70  case DENSE:
71  impl = new Linear_Expression_Impl<Dense_Row>(space_dim, x);
72  break;
73  case SPARSE:
74  impl = new Linear_Expression_Impl<Sparse_Row>(space_dim, x);
75  break;
76  default:
77  PPL_UNREACHABLE;
78  }
79 }
80 
82  switch (e.representation()) {
83  case DENSE:
85  break;
86  case SPARSE:
88  break;
89  default:
90  PPL_UNREACHABLE;
91  }
92 }
93 
95  Representation r) {
96  switch (r) {
97  case DENSE:
99  break;
100  case SPARSE:
102  break;
103  default:
104  PPL_UNREACHABLE;
105  }
106 }
107 
109  dimension_type space_dim) {
110  switch (e.representation()) {
111  case DENSE:
112  impl = new Linear_Expression_Impl<Dense_Row>(*e.impl, space_dim);
113  break;
114  case SPARSE:
115  impl = new Linear_Expression_Impl<Sparse_Row>(*e.impl, space_dim);
116  break;
117  default:
118  PPL_UNREACHABLE;
119  }
120 }
121 
123  dimension_type space_dim,
124  Representation r) {
125  switch (r) {
126  case DENSE:
127  impl = new Linear_Expression_Impl<Dense_Row>(*e.impl, space_dim);
128  break;
129  case SPARSE:
130  impl = new Linear_Expression_Impl<Sparse_Row>(*e.impl, space_dim);
131  break;
132  default:
133  PPL_UNREACHABLE;
134  }
135 }
136 
137 PPL::Linear_Expression::Linear_Expression(Coefficient_traits::const_reference n,
138  Representation r) {
139  switch (r) {
140  case DENSE:
141  impl = new Linear_Expression_Impl<Dense_Row>(n);
142  break;
143  case SPARSE:
145  break;
146  default:
147  PPL_UNREACHABLE;
148  }
149 }
150 
152  switch (r) {
153  case DENSE:
154  impl = new Linear_Expression_Impl<Dense_Row>(v);
155  break;
156  case SPARSE:
158  break;
159  default:
160  PPL_UNREACHABLE;
161  break;
162  }
163 }
164 
165 void
167  if (representation() == r) {
168  return;
169  }
170  Linear_Expression tmp(*this, r);
171  swap(*this, tmp);
172 }
173 
175 
176 bool
177 PPL::Linear_Expression::OK() const {
178  return impl->OK();
179 }
void swap(CO_Tree &x, CO_Tree &y)
size_t dimension_type
An unsigned integral type for representing space dimensions.
bool OK() const
Checks if all the invariants are satisfied.
static void finalize()
Finalizes the class.
A dimension of the vector space.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_Expression can handle.
static dimension_type max_size()
Returns the size() of the largest possible Dense_Row.
static void initialize()
Initializes the class.
void set_representation(Representation r)
Converts *this to the specified representation.
Coefficient_traits::const_reference Coefficient_zero()
Returns a const reference to a Coefficient with value 0.
#define PPL_OUTPUT_DEFINITIONS(class_name)
The entire library is confined to this namespace.
Definition: version.hh:61
Representation representation() const
Returns the current representation of *this.
static const Linear_Expression * zero_p
Holds (between class initialization and finalization) a pointer to the (zero-dimension space) constan...
Dense representation: the coefficient sequence is represented as a vector of coefficients, including the zero coefficients. If there are only a few nonzero coefficients, this representation is faster and also uses a bit less memory.
Sparse representation: only the nonzero coefficient are stored. If there are many nonzero coefficient...
Linear_Expression(Representation r=default_representation)
Default constructor: returns a copy of Linear_Expression::zero().