PPL  1.2
Box_Status_inlines.hh
Go to the documentation of this file.
1 /* Box<ITV>::Status 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_Box_Status_inlines_hh
25 #define PPL_Box_Status_inlines_hh 1
26 
27 #include <string>
28 
29 namespace Parma_Polyhedra_Library {
30 
31 template <typename ITV>
32 inline
34  : flags(mask) {
35 }
36 
37 template <typename ITV>
38 inline
40  : flags(y.flags) {
41 }
42 
43 template <typename ITV>
44 template <typename Other_ITV>
45 inline
47  : flags(y.flags) {
48 }
49 
50 template <typename ITV>
51 inline
53  : flags(NONE) {
54 }
55 
56 template <typename ITV>
57 inline bool
59  return (flags & mask) == mask;
60 }
61 
62 template <typename ITV>
63 inline bool
65  return (flags & mask) != 0;
66 }
67 
68 template <typename ITV>
69 inline void
71  flags |= mask;
72 }
73 
74 template <typename ITV>
75 inline void
77  flags &= ~mask;
78 }
79 
80 template <typename ITV>
81 inline bool
83  return test_any(EMPTY_UP_TO_DATE);
84 }
85 
86 template <typename ITV>
87 inline void
89  reset(EMPTY_UP_TO_DATE);
90 }
91 
92 template <typename ITV>
93 inline void
95  set(EMPTY_UP_TO_DATE);
96 }
97 
98 template <typename ITV>
99 inline bool
101  return test_any(EMPTY);
102 }
103 
104 template <typename ITV>
105 inline void
107  reset(EMPTY);
108 }
109 
110 template <typename ITV>
111 inline void
113  set(EMPTY);
114 }
115 
116 template <typename ITV>
117 inline bool
119  return test_any(UNIVERSE);
120 }
121 
122 template <typename ITV>
123 inline void
125  reset(UNIVERSE);
126 }
127 
128 template <typename ITV>
129 inline void
131  set(UNIVERSE);
132 }
133 
134 template <typename ITV>
135 bool
137  if (test_empty_up_to_date()
138  && test_empty()
139  && test_universe()) {
140 #ifndef NDEBUG
141  std::cerr
142  << "The status asserts emptiness and universality at the same time."
143  << std::endl;
144 #endif
145  return false;
146  }
147 
148  // Any other case is OK.
149  return true;
150 }
151 
152 
153 namespace Implementation {
154 
155 namespace Boxes {
156 
157 // These are the keywords that indicate the individual assertions.
158 extern const char* empty_up_to_date;
159 extern const char* empty;
160 extern const char* universe;
161 const char yes = '+';
162 const char no = '-';
163 const char separator = ' ';
164 
172 inline bool
173 get_field(std::istream& s, const char* keyword, bool& positive) {
174  std::string str;
175  if (!(s >> str)
176  || (str[0] != yes && str[0] != no)
177  || str.substr(1) != keyword) {
178  return false;
179  }
180  positive = (str[0] == yes);
181  return true;
182 }
183 
184 } // namespace Boxes
185 
186 } // namespace Implementation
187 
188 template <typename ITV>
189 void
190 Box<ITV>::Status::ascii_dump(std::ostream& s) const {
191  using namespace Implementation::Boxes;
192  s << (test_empty_up_to_date() ? yes : no) << empty_up_to_date << separator
193  << (test_empty() ? yes : no) << empty << separator
194  << (test_universe() ? yes : no) << universe << separator;
195 }
196 
198 
199 template <typename ITV>
200 bool
201 Box<ITV>::Status::ascii_load(std::istream& s) {
202  using namespace Implementation::Boxes;
203  PPL_UNINITIALIZED(bool, positive);
204 
205  if (!get_field(s, Implementation::Boxes::empty_up_to_date, positive)) {
206  return false;
207  }
208  if (positive) {
210  }
211 
212  if (!get_field(s, Implementation::Boxes::empty, positive)) {
213  return false;
214  }
215  if (positive) {
216  set_empty();
217  }
218  if (!get_field(s, universe, positive)) {
219  return false;
220  }
221  if (positive) {
222  set_universe();
223  }
224  else {
225  reset_universe();
226  }
227 
228  // Check invariants.
229  PPL_ASSERT(OK());
230  return true;
231 }
232 
233 } // namespace Parma_Polyhedra_Library
234 
235 #endif // !defined(PPL_Box_Status_inlines_hh)
The empty element, i.e., the empty set.
void set(flags_t mask)
Set the bits in mask.
void ascii_dump() const
Writes to std::cerr an ASCII representation of *this.
The standard C++ namespace.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
void reset(flags_t mask)
Reset the bits in mask.
#define PPL_OUTPUT_TEMPLATE_DEFINITIONS_ASCII_ONLY(type_symbol, class_prefix)
bool get_field(std::istream &s, const char *keyword, bool &positive)
bool test_any(flags_t mask) const
Check whether at least one bit in mask is set.
bool OK() const
Checks if all the invariants are satisfied.
bool test_all(flags_t mask) const
Check whether all bits in mask are set.
A not necessarily closed, iso-oriented hyperrectangle.
Definition: Box_defs.hh:299
unsigned int flags_t
Status is implemented by means of a finite bitset.
Definition: Box_defs.hh:87
The universe element, i.e., the whole vector space.
The entire library is confined to this namespace.
Definition: version.hh:61
void set_empty_up_to_date()
Asserts the validity of the empty flag of *this.
Definition: Box_inlines.hh:58
#define PPL_UNINITIALIZED(type, name)
Definition: compiler.hh:72
bool OK() const
Returns true if and only if *this satisfies all its invariants.
Status()
By default Status is the empty set of assertion.
void set_empty()
Causes the box to become empty, i.e., to represent the empty set.
Definition: Box_inlines.hh:44