SheafSystem  0.0.0.0
member_member_poset_bounds.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Implementation for class member_member_poset_bounds
19 
20 #include "SheafSystem/member_member_poset_bounds.h"
21 
22 #include "SheafSystem/index_iterator.h"
23 #include "SheafSystem/poset_bounds_descriptor.h"
24 #include "SheafSystem/poset_state_handle.h"
25 #include "SheafSystem/assert_contract.h"
26 #include "SheafSystem/zn_to_bool.h"
27 
28 // PUBLIC MEMBER FUNCTIONS
29 
30 // CANONICAL MEMBERS
31 
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  _lb_is_singleton = true;
41  _lb_id = BOTTOM_INDEX;
42  _bounded_below = false;
43  _lb = 0;
44 
45  _ub_is_singleton = true;
46  _ub_id = TOP_INDEX;
47  _bounded_above = false;
48  _ub = 0;
49 
50  // Postconditions:
51 
52  ensure(invariant());
53  ensure(!is_attached());
54 
55  // Exit:
56 
57  return;
58 }
59 
63  : poset_bounds(xother)
64 {
65 
66  // Preconditions:
67 
68  // Body:
69 
71  const_cast<member_member_poset_bounds&>(xother);
72 
73  _lb = lother._lb != 0 ? new zn_to_bool(*(lother._lb)) : 0;
74  _ub = lother._ub != 0 ? new zn_to_bool(*(lother._ub)) : 0;
75 
76  // Postconditions:
77 
78  ensure(invariant());
79 }
80 
84 clone() const
85 {
87 
88  // Preconditions:
89 
90  // Body:
91 
92  result = new member_member_poset_bounds(*this);
93 
94  // Postconditions:
95 
96  ensure(result != 0);
97  ensure(is_same_type(result));
99  ensure(unexecutable("result->is_attached() == is_attached()"));
100 
101  // Exit:
102 
103  return result;
104 }
105 
109 {
110 
111  // Preconditions:
112 
113  // Body:
114 
116 
117  // Postconditions:
118 
119  // Exit:
120 
121  return;
122 }
123 
125 bool
127 invariant() const
128 {
129  bool result = true;
130 
131  // Preconditions:
132 
133  // Body:
134 
135  // Must satisfy base class invariant
136 
137  result = result && poset_bounds::invariant();
138 
139  if(invariant_check())
140  {
141  // Prevent recursive calls to invariant
142 
144 
145  invariance(is_attached() == !(_lb == 0));
146  invariance((_lb == 0) == (_ub == 0));
147  invariance(lb_is_singleton());
148  invariance(ub_is_singleton());
149 
150  // Finished, turn invariant checking back on.
151 
153  }
154 
155  // Postconditions:
156 
157  // Exit
158 
159  return result;
160 }
161 
163 bool
165 is_ancestor_of(const any* other) const
166 {
167 
168  // Preconditions:
169 
170  require(other != 0);
171 
172  // Body:
173 
174  // True if other conforms to this
175 
176  bool result = dynamic_cast<const member_member_poset_bounds*>(other) != 0;
177 
178  // Postconditions:
179 
180  return result;
181 
182 }
183 
184 // POSET_BOUNDS FACET
185 
187 bool
190 {
191  bool result;
192 
193  // Preconditions:
194 
195  require(is_attached());
196 
197  // Body:
198 
199  result = (xindex == lb_id());
200 
201  // Postconditions:
202 
203  // Exit
204 
205  return result;
206 }
207 
212 {
213  // Preconditions:
214 
215  require(is_attached());
216 
217  // Body:
218 
219  index_iterator result(_lb);
220 
221  // Postconditions:
222 
223  // Exit
224 
225  return result;
226 }
227 
229 bool
232 {
233  bool result;
234 
235  // Preconditions:
236 
237  require(is_attached());
238 
239  // Body:
240 
241  result = (xindex == ub_id());
242 
243  // Postconditions:
244 
245  // Exit
246 
247  return result;
248 }
249 
250 
255 {
256  // Preconditions:
257 
258  require(is_attached());
259 
260  // Body:
261 
262  index_iterator result(_ub);
263 
264  // Postconditions:
265 
266  // Exit
267 
268  return result;
269 }
270 
272 bool
275 {
276  bool result;
277 
278  // Preconditions:
279 
280  // Body:
281 
282  result = _lb != 0;
283 
284  // Postconditions:
285 
286  // Exit
287 
288  return result;
289 }
290 
292 void
295 {
296  // Preconditions:
297 
298  require(!is_attached());
299  require(xhost != 0);
300  require(xhost->state_is_read_accessible());
301  require(xhost->contains_member(lb_id()));
302  require(xhost->contains_member(ub_id()));
303 
304  // Body:
305 
307 
308  _lb = new zn_to_bool(lb_id() + 1);
309  _lb->put(_lb_id, true);
310 
311  _ub = new zn_to_bool(ub_id()+ 1);
312  _ub->put(_ub_id, true);
313 
314  // Postconditions:
315 
316  ensure(invariant());
317  ensure(is_attached());
318 
319  // Exit
320 
321  return;
322 }
323 
325 void
328 {
329  // Preconditions:
330 
331  // Body:
332 
333  if(_lb != 0)
334  {
335  delete _lb;
336  _lb = 0;
337  }
338 
339  if(_ub != 0)
340  {
341  delete _ub;
342  _ub = 0;
343  }
344 
345  // Postconditions:
346 
347  ensure(invariant());
348  ensure(!is_attached());
349 
350  // Exit
351 
352  return;
353 }
354 
359 {
360  // Preconditions:
361 
362  // Body:
363 
365  result(poset_bounds_descriptor::MEMBER_MEMBER, lb_id(), ub_id());
366 
367  // Postconditions:
368 
369  ensure(result.mode() == poset_bounds_descriptor::MEMBER_MEMBER);
370  ensure(result.lb_id() == lb_id());
371  ensure(result.ub_id() == ub_id());
372 
373  // Exit
374 
375  return result;
376 }
377 
378 // MEMBER_MEMBER_POSET_BOUNDS FACET
379 
382 member_member_poset_bounds(int xlb_id, int xub_id)
383 {
384  // Preconditions:
385 
386  // Body:
387 
388  _lb = 0;
389  _lb_id = xlb_id;
390  _lb_is_singleton = true;
391  _bounded_below = _lb_id != BOTTOM_INDEX;
392 
393  _ub = 0;
394  _ub_id = xub_id;
395  _ub_is_singleton = true;
396  _bounded_above = _ub_id != TOP_INDEX;
397 
398  // Postconditions:
399 
400  ensure(invariant());
401  ensure(!is_attached());
402 
403  // Exit
404 
405  return;
406 }
407 
408 
409 // PRIVATE MEMBER FUNCTIONS
410 
411 
bool _bounded_below
True if the lower bound is not the bottom.
Definition: poset_bounds.h:202
pod_index_type ub_id() const
The index of the upper bound member, if the upper bound contains a single member. ...
member_member_poset_bounds()
Default constructor; private to prevent default construction.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
bool lb_is_singleton() const
True if the lower bound contains a single member.
virtual bool ub_contains_member(const scoped_index &xindex)
True if the upper bound contains the member with index xindex.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
bool _bounded_above
True if the upper bound is not the top.
Definition: poset_bounds.h:217
virtual index_iterator lb_iterator()
An iterator for the members of the lower bound.
A client handle for a general, abstract partially order set.
void put(int i, bool value)
Sets i-th member to value.
Definition: zn_to_bool.cc:537
virtual void detach_from_state()
Detaches the lower and upper bounds.
pod_index_type ub_id() const
The index of the upper bound member, if the upper bound contains a single member. ...
A (lower, upper) bounds pair for a poset. Specifies a portion of a poset for a bounded i/o operation...
Definition: poset_bounds.h:50
virtual index_iterator ub_iterator()
An iterator for the members of the upper bound.
virtual poset_bounds_descriptor descriptor()
A descriptor for this.
virtual member_member_poset_bounds * clone() const
Virtual constructor; makes a new instance of the same type as this.
virtual void attach_to_state(poset_state_handle *xhost)
Attaches the lower and upper bounds.
A poset bounds pair with lower and upper bounds each specified by a single member.
Abstract base class with useful features for all objects.
Definition: any.h:39
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
Definition: zn_to_bool.h:52
bool _ub_is_singleton
True if the upper bound contains a single member.
Definition: poset_bounds.h:212
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
bool _lb_is_singleton
True if the lower bound contains a single member.
Definition: poset_bounds.h:197
pod_index_type lb_id() const
The index of the lower bound.
virtual bool contains_member(pod_index_type xmbr_hub_id, bool xauto_access=true) const
True if some version of this poset contains poset member with hub id xmbr_hub_id. ...
bool ub_is_singleton() const
True if the upper bound contains a single member.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
Iterates over the subset of Zn defined by the characteristic function host().
virtual bool lb_contains_member(const scoped_index &xindex)
True if the lower bound contains the member with index xindex.
A description of a (lower, upper) bounds pair for a poset. Specifies a portion of a poset for a bound...
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool invariant() const
Class invariant.
pod_index_type lb_id() const
The index of the lower bound member, if the lower bound contains a single member. ...
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
specification_mode mode() const
Specification mode for this.
virtual bool invariant() const
Class invariant.
Definition: poset_bounds.cc:50
bool is_attached()
True if lb() and ub() are attached.