1 /* Congruence_System class implementation: 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_Congruence_System_inlines_hh
25 #define PPL_Congruence_System_inlines_hh 1
26 
27 #include "Congruence_defs.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 inline const Congruence&
operator [](const dimension_type k) const32 Congruence_System::operator[](const dimension_type k) const {
33   return rows[k];
34 }
35 
36 inline dimension_type
num_rows() const37 Congruence_System::num_rows() const {
38   return rows.size();
39 }
40 
41 inline bool
has_no_rows() const42 Congruence_System::has_no_rows() const {
43   return num_rows() == 0;
44 }
45 
46 inline void
remove_trailing_rows(dimension_type n)47 Congruence_System::remove_trailing_rows(dimension_type n) {
48   PPL_ASSERT(num_rows() >= n);
49   rows.resize(num_rows() - n);
50 }
51 
52 inline void
insert(const Congruence & cg)53 Congruence_System::insert(const Congruence& cg) {
54   Congruence tmp = cg;
55   insert(tmp, Recycle_Input());
56 }
57 
58 inline void
insert(Congruence & cg,Recycle_Input)59 Congruence_System::insert(Congruence& cg, Recycle_Input) {
60   PPL_ASSERT(cg.OK());
61   cg.strong_normalize();
62   PPL_ASSERT(cg.OK());
63   insert_verbatim(cg, Recycle_Input());
64   PPL_ASSERT(OK());
65 }
66 
67 inline
Congruence_System(Representation r)68 Congruence_System::Congruence_System(Representation r)
69   : rows(),
70     space_dimension_(0),
71     representation_(r) {
72 }
73 
74 inline
Congruence_System(const Congruence & cg,Representation r)75 Congruence_System::Congruence_System(const Congruence& cg, Representation r)
76   : rows(),
77     space_dimension_(0),
78     representation_(r) {
79   insert(cg);
80 }
81 
82 inline
Congruence_System(const Constraint & c,Representation r)83 Congruence_System::Congruence_System(const Constraint& c, Representation r)
84   : rows(),
85     space_dimension_(0),
86     representation_(r) {
87   insert(c);
88 }
89 
90 inline
Congruence_System(const Congruence_System & cgs)91 Congruence_System::Congruence_System(const Congruence_System& cgs)
92   : rows(cgs.rows),
93     space_dimension_(cgs.space_dimension_),
94     representation_(cgs.representation_) {
95 }
96 
97 inline
Congruence_System(const Congruence_System & cgs,Representation r)98 Congruence_System::Congruence_System(const Congruence_System& cgs,
99                                      Representation r)
100   : rows(cgs.rows),
101     space_dimension_(cgs.space_dimension_),
102     representation_(r) {
103   if (cgs.representation() != r) {
104     for (dimension_type i = 0; i < num_rows(); ++i) {
105       rows[i].set_representation(representation());
106     }
107   }
108 }
109 
110 inline
Congruence_System(const dimension_type d,Representation r)111 Congruence_System::Congruence_System(const dimension_type d, Representation r)
112   : rows(),
113     space_dimension_(d),
114     representation_(r) {
115 }
116 
117 inline
~Congruence_System()118 Congruence_System::~Congruence_System() {
119 }
120 
121 inline Congruence_System&
operator =(const Congruence_System & y)122 Congruence_System::operator=(const Congruence_System& y) {
123   Congruence_System tmp = y;
124   swap(*this, tmp);
125   return *this;
126 }
127 
128 inline Representation
representation() const129 Congruence_System::representation() const {
130   return representation_;
131 }
132 
133 inline void
set_representation(Representation r)134 Congruence_System::set_representation(Representation r) {
135   if (representation_ == r) {
136     return;
137   }
138   representation_ = r;
139   for (dimension_type i = 0; i < num_rows(); ++i) {
140     rows[i].set_representation(r);
141   }
142   PPL_ASSERT(OK());
143 }
144 
145 inline dimension_type
max_space_dimension()146 Congruence_System::max_space_dimension() {
147   return Congruence::max_space_dimension();
148 }
149 
150 inline dimension_type
space_dimension() const151 Congruence_System::space_dimension() const {
152   return space_dimension_;
153 }
154 
155 inline void
clear()156 Congruence_System::clear() {
157   rows.clear();
158   space_dimension_ = 0;
159 }
160 
161 inline const Congruence_System&
zero_dim_empty()162 Congruence_System::zero_dim_empty() {
163   PPL_ASSERT(zero_dim_empty_p != 0);
164   return *zero_dim_empty_p;
165 }
166 
167 inline
const_iterator()168 Congruence_System::const_iterator::const_iterator()
169   : i(), csp(0) {
170 }
171 
172 inline
const_iterator(const const_iterator & y)173 Congruence_System::const_iterator::const_iterator(const const_iterator& y)
174   : i(y.i), csp(y.csp) {
175 }
176 
177 inline
~const_iterator()178 Congruence_System::const_iterator::~const_iterator() {
179 }
180 
181 inline Congruence_System::const_iterator&
operator =(const const_iterator & y)182 Congruence_System::const_iterator::operator=(const const_iterator& y) {
183   i = y.i;
184   csp = y.csp;
185   return *this;
186 }
187 
188 inline const Congruence&
operator *() const189 Congruence_System::const_iterator::operator*() const {
190   return *i;
191 }
192 
193 inline const Congruence*
operator ->() const194 Congruence_System::const_iterator::operator->() const {
195   return i.operator->();
196 }
197 
198 inline Congruence_System::const_iterator&
operator ++()199 Congruence_System::const_iterator::operator++() {
200   ++i;
201   skip_forward();
202   return *this;
203 }
204 
205 inline Congruence_System::const_iterator
operator ++(int)206 Congruence_System::const_iterator::operator++(int) {
207   const const_iterator tmp = *this;
208   operator++();
209   return tmp;
210 }
211 
212 inline bool
operator ==(const const_iterator & y) const213 Congruence_System::const_iterator::operator==(const const_iterator& y) const {
214   return i == y.i;
215 }
216 
217 inline bool
operator !=(const const_iterator & y) const218 Congruence_System::const_iterator::operator!=(const const_iterator& y) const {
219   return i != y.i;
220 }
221 
222 inline
223 Congruence_System::const_iterator::
const_iterator(const Swapping_Vector<Congruence>::const_iterator & iter,const Congruence_System & cgs)224 const_iterator(const Swapping_Vector<Congruence>::const_iterator& iter,
225                const Congruence_System& cgs)
226   : i(iter), csp(&cgs.rows) {
227 }
228 
229 inline Congruence_System::const_iterator
begin() const230 Congruence_System::begin() const {
231   const_iterator i(rows.begin(), *this);
232   i.skip_forward();
233   return i;
234 }
235 
236 inline Congruence_System::const_iterator
end() const237 Congruence_System::end() const {
238   const const_iterator i(rows.end(), *this);
239   return i;
240 }
241 
242 inline bool
empty() const243 Congruence_System::empty() const {
244   return begin() == end();
245 }
246 
247 inline void
m_swap(Congruence_System & y)248 Congruence_System::m_swap(Congruence_System& y) {
249   using std::swap;
250   swap(rows, y.rows);
251   swap(space_dimension_, y.space_dimension_);
252   swap(representation_, y.representation_);
253   PPL_ASSERT(OK());
254   PPL_ASSERT(y.OK());
255 }
256 
257 inline memory_size_type
external_memory_in_bytes() const258 Congruence_System::external_memory_in_bytes() const {
259   return rows.external_memory_in_bytes();
260 }
261 
262 inline memory_size_type
total_memory_in_bytes() const263 Congruence_System::total_memory_in_bytes() const {
264   return rows.external_memory_in_bytes() + sizeof(*this);
265 }
266 
267 /*! \relates Congruence_System */
268 inline void
swap(Congruence_System & x,Congruence_System & y)269 swap(Congruence_System& x, Congruence_System& y) {
270   x.m_swap(y);
271 }
272 
273 } // namespace Parma_Polyhedra_Library
274 
275 #endif // !defined(PPL_Congruence_System_inlines_hh)
276