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"
26 #include "Linear_Expression_defs.hh"
27
28 #include "Linear_Expression_Impl_defs.hh"
29 #include "Dense_Row_defs.hh"
30 #include "Sparse_Row_defs.hh"
31
32 namespace PPL = Parma_Polyhedra_Library;
33
34 PPL::dimension_type
max_space_dimension()35 PPL::Linear_Expression::max_space_dimension() {
36 return Dense_Row::max_size() - 1;
37 }
38
39 const PPL::Linear_Expression* PPL::Linear_Expression::zero_p = 0;
40
41 void
initialize()42 PPL::Linear_Expression::initialize() {
43 PPL_ASSERT(zero_p == 0);
44 zero_p = new Linear_Expression(Coefficient_zero());
45 }
46
47 void
finalize()48 PPL::Linear_Expression::finalize() {
49 PPL_ASSERT(zero_p != 0);
50 delete zero_p;
51 zero_p = 0;
52 }
53
Linear_Expression(Representation r)54 PPL::Linear_Expression::Linear_Expression(Representation r) {
55 switch (r) {
56 case DENSE:
57 impl = new Linear_Expression_Impl<Dense_Row>();
58 break;
59 case SPARSE:
60 impl = new Linear_Expression_Impl<Sparse_Row>();
61 break;
62 default:
63 PPL_UNREACHABLE;
64 }
65 }
66
Linear_Expression(dimension_type space_dim,bool x,Representation r)67 PPL::Linear_Expression::Linear_Expression(dimension_type space_dim, bool x,
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
Linear_Expression(const Linear_Expression & e)81 PPL::Linear_Expression::Linear_Expression(const Linear_Expression& e) {
82 switch (e.representation()) {
83 case DENSE:
84 impl = new Linear_Expression_Impl<Dense_Row>(*e.impl);
85 break;
86 case SPARSE:
87 impl = new Linear_Expression_Impl<Sparse_Row>(*e.impl);
88 break;
89 default:
90 PPL_UNREACHABLE;
91 }
92 }
93
Linear_Expression(const Linear_Expression & e,Representation r)94 PPL::Linear_Expression::Linear_Expression(const Linear_Expression& e,
95 Representation r) {
96 switch (r) {
97 case DENSE:
98 impl = new Linear_Expression_Impl<Dense_Row>(*e.impl);
99 break;
100 case SPARSE:
101 impl = new Linear_Expression_Impl<Sparse_Row>(*e.impl);
102 break;
103 default:
104 PPL_UNREACHABLE;
105 }
106 }
107
Linear_Expression(const Linear_Expression & e,dimension_type space_dim)108 PPL::Linear_Expression::Linear_Expression(const Linear_Expression& e,
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
Linear_Expression(const Linear_Expression & e,dimension_type space_dim,Representation r)122 PPL::Linear_Expression::Linear_Expression(const Linear_Expression& e,
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
Linear_Expression(Coefficient_traits::const_reference n,Representation r)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:
144 impl = new Linear_Expression_Impl<Sparse_Row>(n);
145 break;
146 default:
147 PPL_UNREACHABLE;
148 }
149 }
150
Linear_Expression(const Variable v,Representation r)151 PPL::Linear_Expression::Linear_Expression(const Variable v, Representation r) {
152 switch (r) {
153 case DENSE:
154 impl = new Linear_Expression_Impl<Dense_Row>(v);
155 break;
156 case SPARSE:
157 impl = new Linear_Expression_Impl<Sparse_Row>(v);
158 break;
159 default:
160 PPL_UNREACHABLE;
161 break;
162 }
163 }
164
165 void
set_representation(Representation r)166 PPL::Linear_Expression::set_representation(Representation r) {
167 if (representation() == r) {
168 return;
169 }
170 Linear_Expression tmp(*this, r);
171 swap(*this, tmp);
172 }
173
PPL_OUTPUT_DEFINITIONS(Linear_Expression)174 PPL_OUTPUT_DEFINITIONS(Linear_Expression)
175
176 bool
177 PPL::Linear_Expression::OK() const {
178 return impl->OK();
179 }
180