SheafSystem  0.0.0.0
sum_index_space_handle.cc
Go to the documentation of this file.
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 
20 
21 #include "SheafSystem/sum_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/scoped_index.h"
25 #include "SheafSystem/sum_index_space_state.h"
26 
27 // ===========================================================
28 // SUM_INDEX_SPACE_HANDLE FACET
29 // ===========================================================
30 
31 // PUBLIC MEMBER FUNCTIONS
32 
36 {
37  // Preconditions:
38 
39  // Body:
40 
41  // Postconditions:
42 
43  ensure(invariant());
44 
45  // Exit:
46 
47  return;
48 }
49 
52 {
53  // Preconditions:
54 
55  // Body:
56 
57  (*this) = xother;
58 
59  // Postconditions:
60 
61  ensure(invariant());
62  ensure((*this) == xother);
63 
64  // Exit:
65 
66  return;
67 }
68 
71  pod_type xindex)
72 {
73  // Preconditions:
74 
75  require(xid_spaces.contains(xindex));
76  require(conforms_to_state(xid_spaces, xindex));
77 
78  // Body:
79 
80  attach_to(xid_spaces, xindex);
81 
82  // Postconditions:
83 
84  ensure(invariant());
85  ensure(is_attached());
86  ensure(&id_spaces() == &xid_spaces);
87  ensure(index() == xindex);
88 
89  // Exit:
90 
91  return;
92 }
93 
96  const std::string& xname)
97 {
98  // Preconditions:
99 
100  require(xid_spaces.contains(xname));
101  require(conforms_to_state(xid_spaces, xname));
102 
103  // Body:
104 
105  attach_to(xid_spaces, xname);
106 
107  // Postconditions:
108 
109  ensure(invariant());
110  ensure(is_attached());
111  ensure(&id_spaces() == &xid_spaces);
112  ensure(name() == xname);
113 
114  // Exit:
115 
116  return;
117 }
118 
122 {
123  // Preconditions:
124 
125  require(xother.is_attached() ? conforms_to_state(xother) : true);
126 
127  // Body:
128 
129  attach_to(xother);
130 
131  // Postconditions:
132 
133  ensure(invariant());
134  ensure((*this) == xother);
135 
136  // Exit:
137 
138  return *this;
139 }
140 
143 {
144  // Preconditions:
145 
146  // Body:
147 
148  // nothing to do.
149 
150  // Postconditions:
151 
152  // Exit:
153 
154  return;
155 }
156 
157 // PROTECTED MEMBER FUNCTIONS
158 
162 {
163  // Preconditions:
164 
165  require(is_attached());
166 
167  // Body:
168 
169  sum_index_space_state& result =
170  reinterpret_cast<sum_index_space_state&>(*_state);
171 
172  // Postconditions:
173 
174  ensure(is_basic_query);
175 
176  // Exit:
177 
178  return result;
179 }
180 
183 state() const
184 {
185  // Preconditions:
186 
187  require(is_attached());
188 
189  // Body:
190 
191  const sum_index_space_state& result =
192  reinterpret_cast<const sum_index_space_state&>(*_state);
193 
194  // Postconditions:
195 
196  ensure(is_basic_query);
197 
198  // Exit:
199 
200  return result;
201 }
202 
203 // PRIVATE MEMBER FUNCTIONS
204 
205 
206 // ===========================================================
207 // SUM INDEX SPACE FACET
208 // ===========================================================
209 
210 // PUBLIC MEMBER FUNCTIONS
211 
212 void
215 {
216  // Preconditions:
217 
218  require(contains_hub(xhub_id));
219 
220  // Body:
221 
222  state().equivalence_class(xhub_id, result);
223 
224  // Postconditions:
225 
226  ensure(!result.empty());
227 
228  // Exit:
229 
230  return;
231 }
232 
235 equivalence_ct(pod_type xhub_id) const
236 {
237  // Preconditions:
238 
239  require(contains_hub(xhub_id));
240 
241  // Body:
242 
243  size_type result = state().equivalence_ct(xhub_id);
244 
245  // Postconditions:
246 
247  ensure(result > 0);
248 
249  // Exit:
250 
251  return result;
252 }
253 
254 bool
256 contains_rep(pod_type xhub_id) const
257 {
258  // Preconditions:
259 
260  // Body:
261 
262  bool result = state().contains_rep(xhub_id);
263 
264  // Postconditions:
265 
266  ensure(result ? contains_hub(xhub_id) : true);
267 
268  // Exit:
269 
270  return result;
271 }
272 
273 bool
276 {
277  // Preconditions:
278 
279  // Body:
280 
281  bool result = state().contains_unique_rep(xhub_id);
282 
283  // Postconditions:
284 
285  ensure(result ? contains_hub(xhub_id) : true);
286  ensure(result ? contains_rep(xhub_id) : true);
287 
288  // Exit:
289 
290  return result;
291 }
292 
295 rep(pod_type xhub_id) const
296 {
297  // Preconditions:
298 
299  require(contains_hub(xhub_id));
300 
301  // Body:
302 
303  pod_type result = state().rep(xhub_id);
304 
305  // Postconditions:
306 
307  ensure(is_basic_query);
308 
309  // Exit:
310 
311  return true;
312 }
313 
316 host_rep(pod_type xhub_id) const
317 {
318  // Preconditions:
319 
320  require(contains_hub(xhub_id));
321 
322  // Body:
323 
324  pod_type result = state().host_rep(xhub_id);
325 
326  // Postconditions:
327 
328  ensure(contains(result));
329 
330  // Exit:
331 
332  return result;
333 }
334 
338 {
339  // Preconditions:
340 
341  // Body:
342 
343  pod_type result = state().term_id_begin();
344 
345  // Postconditions:
346 
347  ensure(is_basic_query);
348 
349  // Exit:
350 
351  return result;
352 }
353 
356 term_id_end() const
357 {
358  // Preconditions:
359 
360  // Body:
361 
362  pod_type result = state().term_id_end();
363 
364  // Postconditions:
365 
366  ensure(is_basic_query);
367 
368  // Exit:
369 
370  return result;
371 }
372 
373 bool
376 {
377  // Preconditions:
378 
379  // Body:
380 
381  bool result = state().contains_term_id(xi);
382 
383  // Postconditions:
384 
385  ensure(is_basic_query);
386 
387  // Exit:
388 
389  return result;
390 }
391 
394 term(pod_type xi) const
395 {
396  // Preconditions:
397 
398  require(contains_term_id(xi));
399 
400  // Body:
401 
402  const index_space_handle& result = state().term(xi);
403 
404  // Postconditions:
405 
406  ensure(is_basic_query);
407 
408  // Exit:
409 
410  return result;
411 }
412 
415 term_of(pod_type xid) const
416 {
417  // Preconditions:
418 
419  require(contains(xid));
420 
421  // Body:
422 
423  const index_space_handle& result = state().term_of(xid);
424 
425  // Postconditions:
426 
427  ensure(is_basic_query);
428 
429  // Exit:
430 
431  return result;
432 }
433 
436 term_of(const scoped_index& xid) const
437 {
438  // Preconditions:
439 
440  require(xid.in_scope());
441  require(contains(xid));
442 
443  // Body:
444 
445  const index_space_handle& result = state().term_of(xid);
446 
447  // Postconditions:
448 
449  ensure(is_basic_query);
450 
451  // Exit:
452 
453  return result;
454 }
455 
458 last_term() const
459 {
460  // Preconditions:
461 
462  require(!is_empty());
463 
464  // Body:
465 
466  const index_space_handle& result = state().last_term();
467 
468  // Postconditions:
469 
470  ensure(is_basic_query);
471 
472  // Exit:
473 
474  return result;
475 }
476 
480 {
481  // Preconditions:
482 
483  require(contains_term_id(xi));
484 
485  // Body:
486 
487  pod_type result = state().term_begin(xi);
488 
489  // Postconditions:
490 
491  ensure(is_basic_query);
492 
493  // Exit:
494 
495  return result;
496 }
497 
501 {
502  // Preconditions:
503 
504  require(contains_term_id(xi));
505 
506  // Body:
507 
508  pod_type result = state().term_end(xi);
509 
510  // Postconditions:
511 
512  ensure(is_basic_query);
513 
514  // Exit:
515 
516  return result;
517 }
518 
522 {
523  // Preconditions:
524 
525  require(contains_term_id(xi));
526 
527  // Body:
528 
529  pod_type result = state().term_hub_begin(xi);
530 
531  // Postconditions:
532 
533  ensure(is_basic_query);
534 
535  // Exit:
536 
537  return result;
538 }
539 
543 {
544  // Preconditions:
545 
546  require(contains_term_id(xi));
547 
548  // Body:
549 
550  pod_type result = state().term_hub_end(xi);
551 
552  // Postconditions:
553 
554  ensure(is_basic_query);
555 
556  // Exit
557 
558  return result;
559 }
560 
563 term_id(pod_type xid) const
564 {
565  // Preconditions:
566 
567  // Body:
568 
569  pod_type result = state().term_id(xid);
570 
571  // Postconditions:
572 
573  ensure(!is_valid(result) || contains_term_id(result));
574 
575  // Exit:
576 
577  return result;
578 }
579 
580 void
582 binary(pod_type xindex, pod_type& xterm_id, pod_type& xlocal_id) const
583 {
584  // Preconditions:
585 
586  require(contains_hub(xindex));
587 
588  // Body:
589 
590  state().binary(xindex, xterm_id, xlocal_id);
591 
592  // Postconditions:
593 
594  ensure(contains_term_id(xterm_id));
595  ensure(term(xterm_id).contains(xlocal_id));
596 
597  // Exit:
598 
599  return;
600 }
601 
602 void
604 simple(pod_type xterm_id, pod_type xlocal_id, pod_type& xindex) const
605 {
606  // Preconditions:
607 
608  require(contains_term_id(xterm_id));
609  require(term(xterm_id).contains(xlocal_id));
610 
611  // Body:
612 
613  state().simple(xterm_id, xlocal_id, xindex);
614 
615  // Postconditions:
616 
617  ensure(contains_hub(xindex));
618 
619  // Exit:
620 
621  return;
622 }
623 
624 void
627 {
628  // Preconditions:
629 
630  // Body:
631 
632  state().clear();
633 
634  // Postconditions:
635 
636  ensure(invariant());
637  ensure(is_empty());
638 
639  // Exit:
640 
641  return;
642 }
643 
644 // PROTECTED MEMBER FUNCTIONS
645 
646 // PRIVATE MEMBER FUNCTIONS
647 
648 
649 // ===========================================================
650 // EXPLICIT_INDEX_SPACE_HANDLE FACET
651 // ===========================================================
652 
653 // PUBLIC MEMBER FUNCTIONS
654 
655 // PROTECTED MEMBER FUNCTIONS
656 
657 // PRIVATE MEMBER FUNCTIONS
658 
659 
660 // ===========================================================
661 // INDEX_SPACE_HANDLE FACET
662 // ===========================================================
663 
664 // PUBLIC MEMBER FUNCTIONS
665 
669 {
670  // Preconditions:
671 
672  require(xother.is_attached() ? conforms_to_state(xother) : true);
673 
674  // Body:
675 
676  attach_to(xother);
677 
678  // Postconditions:
679 
680  ensure(invariant());
681  ensure((*this) == xother);
682 
683  // Exit:
684 
685  return *this;
686 }
687 
690 clone() const
691 {
692  sum_index_space_handle* result;
693 
694  // Preconditions:
695 
696  // Body:
697 
698  result = new sum_index_space_handle(*this);
699 
700  // Postconditions:
701 
702  ensure(result != 0);
703  ensure(is_same_type(result));
704  ensure(*result == *this);
705 
706  // Exit:
707 
708  return result;
709 }
710 
711 // PROTECTED MEMBER FUNCTIONS
712 
713 // PRIVATE MEMBER FUNCTIONS
714 
715 
716 // ===========================================================
717 // HANDLE FACET
718 // ===========================================================
719 
720 // PUBLIC MEMBER FUNCTIONS
721 
722 bool
725  pod_type xlocal_id) const
726 {
727  // Preconditions:
728 
729  require(xhost.contains(xlocal_id));
730 
731  // Body:
732 
733  bool result =
734  (dynamic_cast<sum_index_space_state*>(state(xhost, xlocal_id)) != 0);
735 
736  // Postconditions:
737 
738  ensure(is_basic_query);
739 
740  // Exit:
741 
742  return result;
743 }
744 
745 // PROTECTED MEMBER FUNCTIONS
746 
747 // PRIVATE MEMBER FUNCTIONS
748 
749 
750 // ===========================================================
751 // ANY FACET
752 // ===========================================================
753 
754 // PUBLIC MEMBER FUNCTIONS
755 
756 bool
758 is_ancestor_of(const any *other) const
759 {
760  // Preconditions:
761 
762  require(other != 0);
763 
764  // Body:
765 
766  // True if other conforms to this
767 
768  bool result = dynamic_cast<const sum_index_space_handle*>(other) != 0;
769 
770  // Postconditions:
771 
772  // Exit:
773 
774  return result;
775 }
776 
777 bool
779 invariant() const
780 {
781  bool result = true;
782 
783  if(invariant_check())
784  {
785  // Prevent recursive calls to invariant
786 
788 
789  // Must satisfy base class invariant
790 
792 
793  // Invariances for this class:
794 
795  // Finished, turn invariant checking back on.
796 
798  }
799 
800  // Exit
801 
802  return result;
803 }
804 
805 // PROTECTED MEMBER FUNCTIONS
806 
807 // PRIVATE MEMBER FUNCTIONS
808 
809 
810 // ===========================================================
811 // NON-MEMBER FUNCTIONS
812 // ===========================================================
813 
814 
815 
virtual bool conforms_to_state(const index_space_collection &xhost, pod_type xlocal_id) const
True if this conforms to the handle type required by the state with local scope id xlocal_id in the h...
pod_type term_begin(pod_type xi) const
Beginning id of the xi-th term.
pod_type term_id_begin() const
Beginning index of the terms in this sum.
virtual sum_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
virtual void attach_to(pod_type xindex)
Attach to the state with index xindex in the id space family id_spaces().
sum_index_space_handle & operator=(const sum_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
virtual pod_type index() const
Index of this space.
pod_type term_id_end() const
Ending index of the terms in this sum.
bool in_scope() const
True if and only if scope() contains an entry for pod().
Definition: scoped_index.h:584
bool is_empty() const
True if there are no ids in the space.
void simple(pod_type xterm_id, pod_type xlocal_id, pod_type &xindex) const
Converts binary components xterm_id, xlocal_id to simple index xindex.
pod_type term_id(pod_type xid) const
The id of the term containing id xid.
size_type equivalence_ct(pod_type xhub_id) const
The number of members of the equivalence class of hub id xhub_id.
void equivalence_class(pod_type xhub_id, equivalence_class_type &result) const
The equivalence class associated with the hub id xhub_id.
virtual bool contains_term_id(pod_type xi) const =0
True if this map contains the xi-th term.
bool contains_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space. synonym for contains...
pod_type term_hub_end(pod_type xi) const
Ending hub id of the xi-th term.
bool contains_unique_rep(pod_type xhub_id) const
True if and only if hub id xhub_id is the only member of its equivalence class.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
virtual const index_space_family & id_spaces() const
The id space family for this (const version).
virtual pod_type host_rep(pod_type xhub_id) const =0
The host id associated with the representative member of the equivalence class of hub id xhub_id...
virtual bool is_attached() const =0
True if this handle is attached to a state.
std::list< pod_type > equivalence_class_type
The type used to represent an equivalence class.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
const index_space_handle & term(pod_type xi) const
The xi-th term.
virtual pod_type term_id_end() const =0
Ending index of the terms in this sum.
pod_type host_rep(pod_type xhub_id) const
The host id associated with the representative member of the equivalence class of hub id xhub_id...
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
void binary(pod_type xindex, pod_type &xterm_id, pod_type &xlocal) const
Converts simple index xindex to its binary components xterm_id and xlocal_id.
void binary(pod_type xindex, pod_type &xterm_id, pod_type &xlocal) const
Converts simple index xindex to its binary components xterm_id and xlocal_id.
pod_type term_end(pod_type xi) const
Ending id of the xi-th term.
An implementation of class index_space_handle for an explicit_index_space_state.
std::string name() const
Name of this space.
pod_index_type pod_type
The "plain old data" index type for this.
sum_index_space_handle()
Default constructor.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual bool is_attached() const
True if this handle is attached to a state.
An abstract id space of alternate integer identifiers which is the sum (disjoint union) of two or mor...
const index_space_handle & term_of(pod_type xid) const
The term containing id xid.
pod_type term_begin(pod_type xi) const
Beginning id of the xi-th term.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
pod_type term_hub_end(pod_type xi) const
Ending hub id of the xi-th term.
const index_space_handle & last_term() const
The last term.
virtual bool invariant() const
Class invariant.
void simple(pod_type xterm_id, pod_type xlocal_id, pod_type &xindex) const
Converts binary components xterm_id, xlocal_id to simple index xindex.
pod_type term_id(pod_type xid) const
The id of the term containing id xid.
pod_type term_end(pod_type xi) const
Ending id of the xi-th term.
A collection of id space states. This is a virtual class with provides an interface for accessing the...
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
sum_index_space_state & state()
The sum id space state (mutable version).
bool contains_term_id(pod_type xi) const
True if this map contains the xi-th term.
virtual bool contains_rep(pod_type xhub_id) const =0
True if and only if hub id xhub_id is the representative member of its equivalence class...
virtual bool contains(pod_type xlocal_id) const =0
True if this collection contains the id space with local id xlocal_id.
An implemenation of class explicit_index_space_handle that has a sum id space state.
void clear()
Deletes all entries.
pod_type rep(pod_type xhub_id) const
The representative member of the equivalence class of hub id xhub_id.
void equivalence_class(pod_type xhub_id, equivalence_class_type &result) const
The equivalence class associated with the hub id xhub_id.
pod_type term_hub_begin(pod_type xi) const
Beginning hub id of the xi-th term.
const index_space_handle & last_term() const
The last term.
bool contains_unique_rep(pod_type xhub_id) const
True if and only if hub id xhub_id is the only member of its equivalence class.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
const index_space_handle & term(pod_type xi) const
The xi-th term.
virtual pod_type rep(pod_type xhub_id) const =0
The representative member of the equivalence class of hub id xhub_id.
virtual pod_type term_id_begin() const =0
Beginning index of the terms in this sum.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
virtual ~sum_index_space_handle()
Destructor.
virtual void clear()
Deletes all entries.
Factory and container for a family of id spaces.
bool contains_rep(pod_type xhub_id) const
True if and only if hub id xhub_id is the representative member of its equivalence class...
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
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
pod_type term_hub_begin(pod_type xi) const
Beginning hub id of the xi-th term.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
const index_space_handle & term_of(pod_type xid) const
The term containing id xid.
virtual bool contains(pod_type xid) const
True if this space contains id xid.
size_type equivalence_ct(pod_type xhub_id) const
The number of members of the equivalence class of hub id xhub_id.