SheafSystem  0.0.0.0
poset_bounds_descriptor.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 poset_bounds_descriptor
19 
20 
21 #include "SheafSystem/poset_bounds_descriptor.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 // PUBLIC MEMBER FUNCTIONS
25 
26 // CANONICAL MEMBERS
27 
30 {
31  // Preconditions:
32 
33  // Body:
34 
35  _mode = NOT_A_MODE;
36  _lb_id = invalid_pod_index();
37  _ub_id = invalid_pod_index();
38 
39  // Postconditions:
40 
41  ensure(invariant());
42  ensure(mode() == NOT_A_MODE);
43  ensure(!is_valid(lb_id()));
44  ensure(!is_valid(ub_id()));
45 
46  // Exit
47 
48  return;
49 }
50 
53 {
54  // Preconditions:
55 
56  // Body:
57 
58  *this = xother;
59 
60  // Postconditions:
61 
62  ensure(invariant());
63  ensure(*this == xother);
64 }
65 
69 {
70 
71  // Preconditions:
72 
73  // Body:
74 
75  _mode = xother._mode;
76  _lb_id = xother._lb_id;
77  _ub_id = xother._ub_id;
78 
79  // Postconditions:
80 
81  ensure(invariant());
82  ensure(*this == xother);
83 
84  // Exit:
85 
86  return *this;
87 }
88 
89 bool
91 operator==(const poset_bounds_descriptor& xother) const
92 {
93  bool result;
94 
95  // Preconditions:
96 
97  // Body:
98 
99  result =
100  (_mode == xother._mode) &&
101  (_lb_id == xother._lb_id) &&
102  (_ub_id == xother._ub_id);
103 
104  // Postconditions:
105 
106  ensure(invariant());
107 
108  // Exit:
109 
110  return result;
111 }
112 
115 clone() const
116 {
117  poset_bounds_descriptor* result;
118 
119  // Preconditions:
120 
121  // Body:
122 
123  result = new poset_bounds_descriptor(*this);
124 
125  // Postconditions:
126 
127  ensure(result != 0);
128  ensure(is_same_type(result));
129 
130  // Exit:
131 
132  return result;
133 }
134 
137 {
138 
139  // Preconditions:
140 
141  // Body:
142 
143  // Postconditions:
144 
145  // Exit:
146 
147  return;
148 }
149 
150 
151 bool
153 invariant() const
154 {
155  bool result = true;
156 
157  // Preconditions:
158 
159  // Body:
160 
161  // Must satisfy base class invariant
162 
163  result = result && any::invariant();
164 
165  if(invariant_check())
166  {
167  // Prevent recursive calls to invariant
168 
170 
173 
174  // Finished, turn invariant checking back on.
175 
177  }
178 
179  // Postconditions:
180 
181  // Exit
182 
183  return result;
184 }
185 
186 bool
188 is_ancestor_of(const any* other) const
189 {
190 
191  // Preconditions:
192 
193  require(other != 0);
194 
195  // Body:
196 
197  // True if other conforms to this
198 
199  bool result = dynamic_cast<const poset_bounds_descriptor*>(other) != 0;
200 
201  // Postconditions:
202 
203  return result;
204 
205 }
206 
207 // POSET_BOUNDS_DESCRIPTOR FACET
208 
209 int
212 {
213  int result;
214 
215  // Preconditions:
216 
217  // Body:
218 
222 
223  switch(xmode)
224  {
225  case MEMBER_MEMBER:
226  result = 0;
227  break;
228  case MEMBER_SUBPOSET:
229  result = 1;
230  break;
231  case SUBPOSET_MEMBER:
232  result = 2;
233  break;
234  case SUBPOSET_SUBPOSET:
235  result = 3;
236  break;
237  default:
238  post_fatal_error_message("unrecognized specification mode");
239  break;
240  }
241 
242  // Postconditions:
243 
244  // Exit
245 
246  return result;
247 }
248 
251 int_to_mode(int xmode)
252 {
253  specification_mode result;
254 
255  // Preconditions:
256 
257  require((0 <= xmode) && (xmode <= 3));
258 
259  // Body:
260 
261  switch(xmode)
262  {
263  case 0:
264  result = MEMBER_MEMBER;
265  break;
266  case 1:
267  result = MEMBER_SUBPOSET;
268  break;
269  case 2:
270  result = SUBPOSET_MEMBER;
271  break;
272  case 3:
273  result = SUBPOSET_SUBPOSET;
274  break;
275  }
276 
277  // Postconditions:
278 
279  // Exit
280 
281  return result;
282 }
283 
286  pod_index_type xlb_id,
287  pod_index_type xub_id)
288  : _mode(xmode),
289  _lb_id(xlb_id),
290  _ub_id(xub_id)
291 {
292  // Preconditions:
293 
294  // Body:
295 
296  // Postconditions:
297 
298  ensure(invariant());
299  ensure(mode() == xmode);
300  ensure(lb_id() == xlb_id);
301  ensure(ub_id() == xub_id);
302 
303  // Exit
304 
305  return;
306 }
307 
310  const scoped_index& xlb_id,
311  const scoped_index& xub_id)
312  : _mode(xmode),
313  _lb_id(xlb_id.hub_pod()),
314  _ub_id(xub_id.hub_pod())
315 {
316  // Preconditions:
317 
318  // Body:
319 
320  // Postconditions:
321 
322  ensure(invariant());
323  ensure(mode() == xmode);
324  ensure(lb_id() == xlb_id.hub_pod());
325  ensure(ub_id() == xub_id.hub_pod());
326 
327  // Exit
328 
329  return;
330 }
331 
334 mode() const
335 {
336  specification_mode result;
337 
338  // Preconditions:
339 
340  // Body:
341 
342  result = _mode;
343 
344  // Postconditions:
345 
346  // Can't call invariant because it's not const
347  // ensure(invariant());
348 
349  // Exit
350 
351  return result;
352 }
353 
354 bool
357 {
358  bool result;
359 
360  // Preconditions:
361 
362  // Body:
363 
364  result = ((mode() == MEMBER_MEMBER) || (mode() == MEMBER_SUBPOSET));
365 
366  // Postconditions:
367 
368  // Can't call invariant because it's not const
369  // ensure(invariant());
370  ensure(result == ((mode() == MEMBER_MEMBER) || (mode() == MEMBER_SUBPOSET)));
371 
372  // Exit
373 
374  return result;
375 }
376 
377 bool
380 {
381  bool result;
382 
383  // Preconditions:
384 
385  // Body:
386 
387  result = ((mode() == MEMBER_MEMBER) || (mode() == SUBPOSET_MEMBER));
388 
389  // Postconditions:
390 
391  // Can't call invariant because it's not const
392  // ensure(invariant());
393  ensure(result == ((mode() == MEMBER_MEMBER) || (mode() == SUBPOSET_MEMBER)));
394 
395  // Exit
396 
397  return result;
398 }
399 
402 lb_id() const
403 {
404  return _lb_id;
405 }
406 
407 void
410 {
411  // Preconditions:
412 
413  // Body:
414 
415  _lb_id = xlb_id;
416 
417  // Postconditions:
418 
419  ensure(lb_id() == xlb_id);
420 
421  // Exit:
422 
423  return;
424 }
425 
426 void
428 put_lb_id(const scoped_index& xlb_id)
429 {
430  // Preconditions:
431 
432  // Body:
433 
434  _lb_id = xlb_id.hub_pod();
435 
436  // Postconditions:
437 
438  ensure(lb_id() == xlb_id.hub_pod());
439 
440  // Exit:
441 
442  return;
443 }
444 
447 ub_id() const
448 {
449  return _ub_id;
450 }
451 
452 void
455 {
456  // Preconditions:
457 
458  // Body:
459 
460  _ub_id = xub_id;
461 
462  // Postconditions:
463 
464  ensure(ub_id() == xub_id);
465 
466  // Exit:
467 
468  return;
469 }
470 
471 void
473 put_ub_id(const scoped_index& xub_id)
474 {
475  // Preconditions:
476 
477  // Body:
478 
479  _ub_id = xub_id.hub_pod();
480 
481  // Postconditions:
482 
483  ensure(ub_id() == xub_id.hub_pod());
484 
485  // Exit:
486 
487  return;
488 }
489 
490 bool
493 {
494  bool result = true;
495 
496  // Preconditions:
497 
498  require(xposet.state_is_read_accessible());
499 
500  // Body:
501 
502  if(lb_is_member())
503  {
504  result = xposet.contains_member(lb_id());
505  }
506  else
507  {
508  result =
509  lb_id() == TOC_INDEX || xposet.includes_subposet(lb_id());
510  }
511 
512 
513  // Postconditions:
514 
515  // Can't call invariant because it's not const
516  // ensure(invariant());
517  ensure(lb_is_member() ? xposet.contains_member(lb_id()) : true);
518 
519  ensure(!lb_is_member() ?
520  (lb_id() == TOC_INDEX) || xposet.includes_subposet(lb_id()) :
521  true);
522 
523  // Exit
524 
525  return result;
526 }
527 
528 bool
531 {
532  bool result = true;
533 
534  // Preconditions:
535 
536  require(xposet.state_is_read_accessible());
537 
538  // Body:
539 
540  result = (ub_is_member() ?
541  xposet.contains_member(ub_id()) :
542  xposet.includes_subposet(ub_id()));
543 
544  // Postconditions:
545 
546  // Can't call invariant because it's not const
547  // ensure(invariant());
548  ensure(result == (ub_is_member() ?
549  xposet.contains_member(ub_id()) :
550  xposet.includes_subposet(ub_id())));
551 
552  // Exit
553 
554  return result;
555 }
556 
557 bool
559 is_valid_for(const poset_state_handle& xposet) const
560 {
561  bool result = true;
562 
563  // Preconditions:
564 
565  require(xposet.state_is_read_accessible());
566 
567  // Body:
568 
569  result = (lb_is_valid_for(xposet) && ub_is_valid_for(xposet));
570 
571  // Postconditions:
572 
573  // Can't call invariant because it's not const
574  // ensure(invariant());
575  ensure(result == (lb_is_valid_for(xposet) && ub_is_valid_for(xposet)));
576 
577  // Exit
578 
579  return result;
580 }
581 
582 
583 bool
586 {
587  bool result;
588 
589  // Preconditions:
590 
591  // Body:
592 
593  result = (lb_is_member() && (lb_id() == BOTTOM_INDEX));
594 
595  // Postconditions:
596 
597  // Can't call invariant because it's not const
598  // ensure(invariant());
599 
600  ensure(result == (lb_is_member() && (lb_id() == BOTTOM_INDEX)));
601 
602  // Exit
603 
604  return result;
605 }
606 
607 bool
610 {
611  bool result = true;
612 
613  // Preconditions:
614 
615  // Body:
616 
617  result = (ub_is_member() && (ub_id() != TOP_INDEX));
618 
619  // Postconditions:
620 
621  // Can't call invariant because it's not const
622  // ensure(invariant());
623 
624  ensure(result == (ub_is_member() && (ub_id() != TOP_INDEX)));
625 
626  // Exit
627 
628  return result;
629 }
630 
633 BOTTOM_TOP = *(new poset_bounds_descriptor(MEMBER_MEMBER, BOTTOM_INDEX, TOP_INDEX));
634 
637 BOTTOM_BOTTOM = *(new poset_bounds_descriptor(MEMBER_MEMBER, BOTTOM_INDEX, BOTTOM_INDEX));
638 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
static specification_mode int_to_mode(int xmode)
Converts int xmode to a mode.
virtual poset_bounds_descriptor * clone() const
Virtual constructor; makes a new instance of the same type as this.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
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 ub_is_member() const
True if mode == MEMBER_MEMBER or SUBPOSET_MEMBER.
A client handle for a general, abstract partially order set.
virtual bool includes_subposet(pod_index_type xsubposet_hub_id, bool xauto_access=true) const
True if this poset includes subposet with hub id xsubposet_hub_id.
pod_index_type ub_id() const
The index of the upper bound member, if the upper bound contains a single member. ...
void put_lb_id(pod_index_type xlb_id)
Sets the index of the lower bound to xlb_id.
virtual ~poset_bounds_descriptor()
Destructor.
Abstract base class with useful features for all objects.
Definition: any.h:39
specification_mode
Enumeration for mode of specifying the lower and upper bounds.
static int mode_to_int(specification_mode xmode)
Converts mode xmode to an int.
bool ub_member_is_not_top() const
True if ub_is_member() and ub_id() is not sheaf_constants::TOP_INDEX.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
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. ...
static const poset_bounds_descriptor & BOTTOM_TOP
An instance with lb() == {bottom} and ub() == {top}.
bool is_valid_for(const poset_state_handle &xposet) const
True if the members and/or subposets mentioned in this descriptor exist in xposet.
bool operator==(const poset_bounds_descriptor &xother) const
Comparison operator.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
static const poset_bounds_descriptor & BOTTOM_BOTTOM
An instance with lb() == {bottom} and ub() == {bottom}.
bool lb_member_is_bottom() const
True if lb_is_member() and lb_id() is sheaf_constants::BOTTOM_INDEX.
bool lb_is_member() const
True if mode == MEMBER_MEMBER or MEMBER_SUBPOSET.
A description of a (lower, upper) bounds pair for a poset. Specifies a portion of a poset for a bound...
poset_bounds_descriptor()
Default constructor.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
poset_bounds_descriptor & operator=(const poset_bounds_descriptor &xother)
Assignment operator.
bool ub_is_valid_for(const poset_state_handle &xposet) const
True if the upper bound member or subposet mentioned in this descriptor exists in xposet...
bool lb_is_valid_for(const poset_state_handle &xposet) const
True if the lower bound member or subposet mentioned in this descriptor exists in xposet...
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
virtual bool invariant() const
Class invariant.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
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
void put_ub_id(pod_index_type xub_id)
Sets the index of the upper bound to xub_id.
specification_mode mode() const
Specification mode for this.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710