PPL  1.2
Og_Status_inlines.hh
Go to the documentation of this file.
1 /* Octagonal_Shape<T>::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_Og_Status_inlines_hh
25 #define PPL_Og_Status_inlines_hh 1
26 
27 namespace Parma_Polyhedra_Library {
28 
29 template <typename T>
30 inline
32  : flags(mask) {
33 }
34 
35 template <typename T>
36 inline
38  : flags(ZERO_DIM_UNIV) {
39 }
40 
41 template <typename T>
42 inline bool
44  return (flags & mask) == mask;
45 }
46 
47 template <typename T>
48 inline bool
50  return (flags & mask) != 0;
51 }
52 
53 template <typename T>
54 inline void
56  flags |= mask;
57 }
58 
59 template <typename T>
60 inline void
62  flags &= ~mask;
63 }
64 
65 template <typename T>
66 inline bool
68  return flags == ZERO_DIM_UNIV;
69 }
70 
71 template <typename T>
72 inline void
74  // This is a no-op if the current status is not zero-dim.
75  if (flags == ZERO_DIM_UNIV) {
76  // In the zero-dim space, if it is not the universe it is empty.
77  flags = EMPTY;
78  }
79 }
80 
81 template <typename T>
82 inline void
84  // Zero-dim universe is incompatible with anything else.
85  flags = ZERO_DIM_UNIV;
86 }
87 
88 template <typename T>
89 inline bool
91  return test_any(EMPTY);
92 }
93 
94 template <typename T>
95 inline void
97  reset(EMPTY);
98 }
99 
100 template <typename T>
101 inline void
103  flags = EMPTY;
104 }
105 
106 template <typename T>
107 inline bool
109  return test_any(STRONGLY_CLOSED);
110 }
111 
112 template <typename T>
113 inline void
115  reset(STRONGLY_CLOSED);
116 }
117 
118 template <typename T>
119 inline void
121  set(STRONGLY_CLOSED);
122 }
123 
124 template <typename T>
125 inline bool
127  if (test_zero_dim_univ()) {
128  // Zero-dim universe is OK.
129  return true;
130  }
131 
132  if (test_empty()) {
133  Status copy = *this;
134  copy.reset_empty();
135  if (copy.test_zero_dim_univ()) {
136  return true;
137  }
138  else {
139 #ifndef NDEBUG
140  std::cerr << "The empty flag is incompatible with any other one."
141  << std::endl;
142 #endif
143  return false;
144  }
145  }
146 
147  // Any other case is OK.
148  return true;
149 }
150 
151 
152 namespace Implementation {
153 
154 namespace Octagonal_Shapes {
155 // These are the keywords that indicate the individual assertions.
156 extern const char* zero_dim_univ;
157 extern const char* empty;
158 extern const char* strong_closed;
159 const char yes = '+';
160 const char no = '-';
161 const char separator = ' ';
162 
170 inline bool
171 get_field(std::istream& s, const char* keyword, bool& positive) {
172  std::string str;
173  if (!(s >> str)
174  || (str[0] != yes && str[0] != no)
175  || str.substr(1) != keyword) {
176  return false;
177  }
178  positive = (str[0] == yes);
179  return true;
180 }
181 
182 } // namespace Octagonal_Shapes
183 
184 } // namespace Implementation
185 
186 template <typename T>
187 inline void
189  using namespace Implementation::Octagonal_Shapes;
190  s << (test_zero_dim_univ() ? yes : no) << zero_dim_univ
191  << separator
192  << (test_empty() ? yes : no) << empty
193  << separator
194  << separator
195  << (test_strongly_closed() ? yes : no) << strong_closed
196  << separator;
197 }
198 
199 template <typename T>
200 inline bool
202  using namespace Implementation::Octagonal_Shapes;
203  PPL_UNINITIALIZED(bool, positive);
204 
205  if (!get_field(s, zero_dim_univ, positive)) {
206  return false;
207  }
208  if (positive) {
210  }
211 
212  if (!get_field(s, empty, positive)) {
213  return false;
214  }
215 
216  if (positive) {
217  set_empty();
218  }
219 
220  if (!get_field(s, strong_closed, positive)) {
221  return false;
222  }
223  if (positive) {
225  }
226  else {
228  }
229  // Check invariants.
230  PPL_ASSERT(OK());
231  return true;
232 }
233 
234 } // namespace Parma_Polyhedra_Library
235 
236 #endif // !defined(PPL_Og_Status_inlines_hh)
bool OK() const
Checks if all the invariants are satisfied.
The empty element, i.e., the empty set.
Status()
By default Status is the zero-dim universe assertion.
void reset(flags_t mask)
Reset the bits in mask.
bool test_all(flags_t mask) const
Check whether all bits in mask are set.
void set(flags_t mask)
Set the bits in mask.
bool OK() const
Checks if all the invariants are satisfied.
A conjunctive assertion about a Octagonal_Shape object.
void set_strongly_closed()
Marks *this as strongly closed.
void ascii_dump(std::ostream &s) const
Writes to s an ASCII representation of the internal representation of *this.
bool test_any(flags_t mask) const
Check whether at least one bit in mask is set.
The entire library is confined to this namespace.
Definition: version.hh:61
unsigned int flags_t
Status is implemented by means of a finite bitset.
bool get_field(std::istream &s, const char *keyword, bool &positive)
void set_zero_dim_univ()
Turns *this into a zero-dimensional universe OS.
void reset_strongly_closed()
Marks *this as possibly not strongly closed.
void set_empty()
Turns *this into an empty OS.
#define PPL_UNINITIALIZED(type, name)
Definition: compiler.hh:72
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...