1 /* Variables_Set 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 #include "ppl-config.h"
25 #include "Variables_Set_defs.hh"
26 #include <iostream>
27 
28 namespace PPL = Parma_Polyhedra_Library;
29 
Variables_Set(const Variable v,const Variable w)30 PPL::Variables_Set::Variables_Set(const Variable v, const Variable w)
31   : Base() {
32   for (dimension_type d = v.id(), last = w.id(); d <= last; ++d) {
33     insert(d);
34   }
35 }
36 
37 bool
OK() const38 PPL::Variables_Set::OK() const {
39   for (const_iterator i = begin(), set_end = end();
40        i != set_end; ++i) {
41     if (!Variable(*i).OK()) {
42       return false;
43     }
44   }
45   return true;
46 }
47 
48 /*! \relates Parma_Polyhedra_Library::Variables_Set */
49 std::ostream&
operator <<(std::ostream & s,const Variables_Set & vs)50 PPL::IO_Operators::operator<<(std::ostream& s, const Variables_Set& vs) {
51   s << '{';
52   for (Variables_Set::const_iterator i = vs.begin(),
53          vs_end = vs.end(); i != vs_end; ) {
54     s << ' ' << Variable(*i);
55     ++i;
56     if (i != vs_end) {
57       s << ',';
58     }
59   }
60   s << " }";
61   return s;
62 }
63 
64 void
ascii_dump(std::ostream & s) const65 PPL::Variables_Set::ascii_dump(std::ostream& s) const {
66   const dimension_type variables_set_size = size();
67   s << "\nvariables( " << variables_set_size << " )\n";
68   for (Variables_Set::const_iterator i = begin(),
69          i_end = end(); i != i_end; ++i) {
70     s << *i << " ";
71   }
72 }
73 
PPL_OUTPUT_DEFINITIONS(Variables_Set)74 PPL_OUTPUT_DEFINITIONS(Variables_Set)
75 
76 bool
77 PPL::Variables_Set::ascii_load(std::istream& s) {
78   clear();
79   std::string str;
80   if (!(s >> str) || str != "variables(") {
81     return false;
82   }
83 
84   dimension_type size;
85 
86   if (!(s >> size)) {
87     return false;
88   }
89 
90   if (!(s >> str) || str != ")") {
91     return false;
92   }
93 
94   for (dimension_type i = 0; i < size; ++i) {
95     dimension_type variable_value;
96     if (!(s >> variable_value)) {
97       return false;
98     }
99     insert(variable_value);
100   }
101   return true;
102 }
103