SheafSystem  0.0.0.0
explicit_index_space_collection.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/abstract_product_structure.h"
22 #include "SheafSystem/explicit_index_space_collection.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/explicit_index_space_state.h"
25 #include "SheafSystem/hub_index_space_handle.h"
26 #include "SheafSystem/index_space_iterator.h"
27 
28 // ===========================================================
29 // EXPLICIT_INDEX_SPACE_COLLECTION FACET
30 // ===========================================================
31 
32 // PUBLIC MEMBER FUNCTIONS
33 
36 {
37  // Preconditions:
38 
39  // Body:
40 
41  map_type::iterator itr = _states.begin();
42  while(itr != _states.end())
43  {
44  explicit_index_space_state* lstate = itr->second;
45  ++itr;
46  delete lstate;
47  }
48 
49  // Postconditions:
50 
51  // Exit:
52 
53  return;
54 }
55 
58 capacity() const
59 {
60  // Preconditions:
61 
62  // Body:
63 
64  size_type result = (2 * _states.bucket_count());
65 
66  // Postconditions:
67 
68  ensure(is_basic_query);
69 
70  // Exit:
71 
72  return result;
73 }
74 
75 void
78 {
79  // Preconditions:
80 
81  require(!contains(local_scope(xid_space.index())));
82 
83  // Body:
84 
85  // Local scope is the same is family scope,
86  // no need to convert.
87 
88  _states[xid_space.index()] = &xid_space;
89 
90  // Postconditions:
91 
92  ensure(contains(local_scope(xid_space.index())));
93 
94  // Exit:
95 
96  return;
97 }
98 
99 // PROTECTED MEMBER FUNCTIONS
100 
104 {
105  // Preconditions:
106 
107  // Body:
108 
109  // Postconditions:
110 
111  ensure(invariant());
112 
113  // Exit:
114 
115  return;
116 }
117 
118 // PRIVATE MEMBER FUNCTIONS
119 
120 
121 // ===========================================================
122 // INDEX_SPACE_COLLECTION FACET
123 // ===========================================================
124 
125 // PUBLIC MEMBER FUNCTIONS
126 
127 bool
129 operator==(const index_space_collection& xother) const
130 {
131  // Preconditions:
132 
133  require(is_ancestor_of(&xother));
134 
135  // Body:
136 
137  const explicit_index_space_collection& lother =
138  dynamic_cast<const explicit_index_space_collection&>(xother);
139 
142 // bool result = (_states == lother._states);
143 // result = result && (_id_spaces == lother._id_spaces);
144 
145  bool result = (_id_spaces == lother._id_spaces);
146 
147  // Postconditions:
148 
149  // Exit
150 
151  return result;
152 }
153 
154 bool
156 contains(pod_type xlocal_id) const
157 {
158  // Preconditions:
159 
160  // Body:
161 
162  // Local scope is the same is family scope,
163  // no need to convert.
164 
165  map_type::const_iterator itr = _states.find(xlocal_id);
166 
167  bool result = (itr != _states.end());
168 
169  // Postconditions:
170 
171  ensure(is_basic_query);
172 
173  // Exit:
174 
175  return result;
176 }
177 
178 bool
180 contains_family(pod_type xspace_id) const
181 {
182  // Preconditions:
183 
184  // Body:
185 
186  // Local scope is the same is family scope,
187  // no need to convert.
188 
189  map_type::const_iterator itr = _states.find(xspace_id);
190 
191  bool result = (itr != _states.end());
192 
193  // Postconditions:
194 
195  ensure(is_basic_query);
196 
197  // Exit:
198 
199  return result;
200 }
201 
204 local_scope(pod_type xspace_id) const
205 {
206  // Preconditions:
207 
208  // Body:
209 
210  // Local scope is the same is family scope,
211  // no need to convert.
212 
213  pod_type result = contains(xspace_id) ? xspace_id : invalid_pod_index();
214 
215  // Postconditions:
216 
217  ensure(!is_valid(result) || contains(result));
218 
219  // Exit:
220 
221  return result;
222 }
223 
226 family_scope(pod_type xlocal_id) const
227 {
228  // Preconditions:
229 
230  // Body:
231 
232  // Local scope is the same is family scope,
233  // no need to convert.
234 
235  pod_type result = contains(xlocal_id) ? xlocal_id : invalid_pod_index();
236 
237  // Postconditions:
238 
239  ensure(!is_valid(result) || contains_family(result));
240 
241  // Exit:
242 
243  return result;
244 }
245 
246 // PROTECTED MEMBER FUNCTIONS
247 
251 {
252  // Preconditions:
253 
254  require(is_ancestor_of(&xother));
255 
256  // Body:
257 
258  const explicit_index_space_collection& lother =
259  dynamic_cast<const explicit_index_space_collection&>(xother);
260 
261  _states = lother._states;
262  _id_spaces = lother._id_spaces;
263 
264  // Postconditions:
265 
266  ensure(invariant());
267  ensure((*this) == xother);
268 
269  // Exit:
270 
271  return *this;
272 }
273 
276 explicit_state(pod_type xlocal_id) const
277 {
278  // Preconditions:
279 
280  // Body:
281 
283  contains(xlocal_id) ? _states.find(xlocal_id)->second : 0;
284 
285  // Postconditions:
286 
287  ensure(is_basic_query);
288 
289  // Exit:
290 
291  return result;
292 }
293 
294 // PRIVATE MEMBER FUNCTIONS
295 
296 
297 // ===========================================================
298 // INDEX SPACE FACET
299 // ===========================================================
300 
301 // PUBLIC MEMBER FUNCTIONS
302 
305 id_spaces() const
306 {
307  // Preconditions:
308 
309  // Body:
310 
311  const index_space_family& result = *_id_spaces;
312 
313  // Postconditions:
314 
315  ensure(is_basic_query);
316 
317  // Exit:
318 
319  return result;
320 }
321 
325 {
326  // Preconditions:
327 
328  // Body:
329 
330  index_space_family& result = *_id_spaces;
331 
332  // Postconditions:
333 
334  ensure(is_basic_query);
335 
336  // Exit:
337 
338  return result;
339 }
340 
341 void
343 remove(pod_type xlocal_id)
344 {
345  // Preconditions:
346 
347  // Body:
348 
349  if(contains(xlocal_id))
350  {
351  _states.erase(xlocal_id);
352  }
353 
354  // Postconditions:
355 
356  ensure(!contains(xlocal_id));
357 
358  // Exit:
359 
360  return;
361 }
362 
365 ct(pod_type xlocal_id) const
366 {
367  // Preconditions:
368 
369  require(contains(xlocal_id));
370 
371  // Body:
372 
373  size_type result = _states.find(xlocal_id)->second->ct();
374 
375  // Postconditions:
376 
377  ensure(is_basic_query);
378 
379  // Exit:
380 
381  return result;
382 }
383 
386 begin(pod_type xlocal_id) const
387 {
388  // Preconditions:
389 
390  require(contains(xlocal_id));
391 
392  // Body:
393 
394  pod_type result = _states.find(xlocal_id)->second->begin();
395 
396  // Postconditions:
397 
398  ensure(is_basic_query);
399 
400  // Exit:
401 
402  return result;
403 }
404 
407 end(pod_type xlocal_id) const
408 {
409  // Preconditions:
410 
411  require(contains(xlocal_id));
412 
413  // Body:
414 
415  pod_type result = _states.find(xlocal_id)->second->end();
416 
417  // Postconditions:
418 
419  ensure(is_basic_query);
420 
421  // Exit:
422 
423  return result;
424 }
425 
426 bool
428 contains(pod_type xlocal_id, pod_type xid) const
429 {
430  // Preconditions:
431 
432  require(contains(xlocal_id));
433 
434  // Body:
435 
436  bool result = _states.find(xlocal_id)->second->contains(xid);
437 
438  // Postconditions:
439 
440  ensure(is_basic_query);
441 
442  // Exit:
443 
444  return result;
445 }
446 
447 bool
450 {
451  // Preconditions:
452 
453  require(contains(xlocal_id));
454 
455  // Body:
456 
457  bool result = _states.find(xlocal_id)->second->contains_unglued_hub(xid);
458 
459  // Postconditions:
460 
461  ensure(is_basic_query);
462 
463  // Exit:
464 
465  return result;
466 }
467 
468 bool
470 contains(pod_type xlocal_id, pod_type xid, pod_type xhub_id) const
471 {
472  // Preconditions:
473 
474  require(contains(xlocal_id));
475 
476  // Body:
477 
478  bool result = _states.find(xlocal_id)->second->contains(xid, xhub_id);
479 
480  // Postconditions:
481 
482  ensure(is_basic_query);
483 
484  // Exit:
485 
486  return result;
487 }
488 
491 pod(pod_type xlocal_id, pod_type xid) const
492 {
493  // Preconditions:
494 
495  require(contains(xlocal_id));
496 
497  // Body:
498 
499  pod_type result = _states.find(xlocal_id)->second->pod(xid);
500 
501  // Postconditions:
502 
503  ensure(!is_valid(result) || contains(xlocal_id, result));
504 
505  // Exit:
506 
507  return result;
508 }
509 
512 unglued_hub_pod(pod_type xlocal_id, pod_type xid) const
513 {
514  // Preconditions:
515 
516  require(contains(xlocal_id));
517 
518  // Body:
519 
520  pod_type result = _states.find(xlocal_id)->second->unglued_hub_pod(xid);
521 
522  // Postconditions:
523 
524  ensure(!is_valid(result) || contains_unglued_hub(xlocal_id, result));
525 
526  // Exit:
527 
528  return result;
529 }
530 
531 bool
533 is_persistent(pod_type xlocal_id) const
534 {
535  // Preconditions:
536 
537  require(contains(xlocal_id));
538 
539  // Body:
540 
541  bool result = _states.find(xlocal_id)->second->is_persistent();
542 
543  // Postconditions:
544 
545  ensure(is_basic_query);
546 
547  // Exit:
548 
549  return result;
550 }
551 
552 // PROTECTED MEMBER FUNCTIONS
553 
554 // PRIVATE MEMBER FUNCTIONS
555 
556 
557 // ===========================================================
558 // PRODUCT STRUCTURE FACET
559 // ===========================================================
560 
561 // PUBLIC MEMBER FUNCTIONS
562 
563 void
566  const abstract_product_structure& xproduct)
567 {
568  // Preconditions:
569 
570  require(contains(xlocal_id));
571 
572  // Body:
573 
574  _states.find(xlocal_id)->second->new_product_structure(xproduct);
575 
576  // Postconditions:
577 
578  ensure(has_product_structure(xlocal_id));
579 
580  // Exit:
581 
582  return;
583 }
584 
585 void
588 {
589  // Preconditions:
590 
591  require(contains(xlocal_id));
592 
593  // Body:
594 
595  _states.find(xlocal_id)->second->delete_product_structure();
596 
597  // Postconditions:
598 
599  ensure(!has_product_structure(xlocal_id));
600 
601  // Exit:
602 
603  return;
604 }
605 
608 product_structure(pod_type xlocal_id) const
609 {
610  // Preconditions:
611 
612  require(contains(xlocal_id));
613  require(has_product_structure(xlocal_id));
614 
615  // Body:
616 
617  const abstract_product_structure& result =
618  _states.find(xlocal_id)->second->product_structure();
619 
620  // Postconditions:
621 
622  ensure(is_basic_query);
623 
624  // Exit:
625 
626  return result;
627 }
628 
632 {
633  // Preconditions:
634 
635  require(contains(xlocal_id));
636  require(has_product_structure(xlocal_id));
637 
638  // Body:
639 
640  abstract_product_structure& result =
641  _states.find(xlocal_id)->second->product_structure();
642 
643  // Postconditions:
644 
645  ensure(is_basic_query);
646 
647  // Exit:
648 
649  return result;
650 }
651 
652 bool
655 {
656  // Preconditions:
657 
658  require(contains(xlocal_id));
659 
660  // Body:
661 
662  bool result = _states.find(xlocal_id)->second->has_product_structure();
663 
664  // Postconditions:
665 
666  ensure(is_basic_query);
667 
668  // Exit:
669 
670  return result;
671 }
672 
673 // PROTECTED MEMBER FUNCTIONS
674 
675 // PRIVATE MEMBER FUNCTIONS
676 
677 
678 // ===========================================================
679 // HANDLE POOL FACET
680 // ===========================================================
681 
682 // PUBLIC MEMBER FUNCTIONS
683 
686 get_id_space(pod_type xlocal_id) const
687 {
688  // Preconditions:
689 
690  require(contains(xlocal_id));
691 
692  // Body:
693 
694  index_space_handle& result =
695  _states.find(xlocal_id)->second->get_id_space();
696 
697  // Postconditions:
698 
699  ensure(result.is_attached());
700 
701  // Exit:
702 
703  return result;
704 }
705 
706 void
709 {
710  // Preconditions:
711 
712  require(allocated_id_space(xid_space));
713 
714  // Body:
715 
716  _states.find(local_scope(xid_space.index()))->
717  second->release_id_space(xid_space);
718 
719  // Postconditions:
720 
721  ensure(is_basic_query);
722 
723  // Exit:
724 
725  return;
726 }
727 
728 bool
730 allocated_id_space(const index_space_handle& xid_space) const
731 {
732  // Preconditions:
733 
734  // Body:
735 
736  map_type::const_iterator itr = _states.find(local_scope(xid_space.index()));
737 
738  bool result =
739  (itr != _states.end()) && itr->second->allocated_id_space(xid_space);
740 
741  // Postconditions:
742 
743  ensure(is_basic_query);
744 
745  // Exit:
746 
747  return result;
748 }
749 
750 // PROTECTED MEMBER FUNCTIONS
751 
752 // PRIVATE MEMBER FUNCTIONS
753 
754 
755 // ===========================================================
756 // ITERATOR POOL FACET
757 // ===========================================================
758 
759 // PUBLIC MEMBER FUNCTIONS
760 
764 {
765  // Preconditions:
766 
767  require(contains(xlocal_id));
768 
769  // Body:
770 
771  index_space_iterator& result =
772  _states.find(xlocal_id)->second->get_iterator();
773 
774  // Postconditions:
775 
776  ensure(result.is_attached());
777 
778  // Exit:
779 
780  return result;
781 }
782 
783 void
786 {
787  // Preconditions:
788 
789  require(allocated_id_space_iterator(xitr));
790 
791  // Body:
792 
793  _states.find(local_scope(xitr.index()))->second->release_iterator(xitr);
794 
795  // Postconditions:
796 
797  ensure(is_basic_query);
798 
799  // Exit:
800 
801  return;
802 }
803 
804 bool
807 {
808  // Preconditions:
809 
810  // Body:
811 
812  map_type::const_iterator itr = _states.find(local_scope(xitr.index()));
813 
814  bool result =
815  (itr != _states.end()) && itr->second->allocated_iterator(xitr);
816 
817  // Postconditions:
818 
819  ensure(is_basic_query);
820 
821  // Exit:
822 
823  return result;
824 }
825 
826 // PROTECTED MEMBER FUNCTIONS
827 
828 // PRIVATE MEMBER FUNCTIONS
829 
830 
831 // ===========================================================
832 // ANY FACET
833 // ===========================================================
834 
835 // PUBLIC MEMBER FUNCTIONS
836 
837 bool
839 is_ancestor_of(const any *other) const
840 {
841  // Preconditions:
842 
843  require(other != 0);
844 
845  // Body:
846 
847  // True if other conforms to this
848 
849  bool result = dynamic_cast<const explicit_index_space_collection*>(other) != 0;
850 
851  // Postconditions:
852 
853  // Exit
854 
855  return result;
856 }
857 
858 bool
860 invariant() const
861 {
862  bool result = true;
863 
864  if(invariant_check())
865  {
866  // Prevent recursive calls to invariant
867 
869 
870  // Must satisfy base class invariant
871 
872  invariance(index_space_collection::invariant());
873 
874  // Invariances for this class:
875 
876  // Finished, turn invariant checking back on.
877 
879  }
880 
881  // Exit
882 
883  return result;
884 }
885 
886 // PROTECTED MEMBER FUNCTIONS
887 
888 // PRIVATE MEMBER FUNCTIONS
889 
890 
891 // ===========================================================
892 // NON-MEMBER FUNCTIONS
893 // ===========================================================
894 
895 size_t
896 sheaf::
897 deep_size(const explicit_index_space_collection& xn, bool xinclude_shallow)
898 {
899  // Preconditions:
900 
901  // Body:
902 
903  size_t result = xinclude_shallow ? sizeof(xn) : 0;
904 
906 
907  // Postconditions:
908 
909  ensure(result >= 0);
910 
911  // Exit
912 
913  return result;
914 }
virtual size_type ct(pod_type xlocal_id) const
The number of members for the id space with id xlocal_id.
virtual pod_type family_scope(pod_type xlocal_id) const
Id relative to the id space family equivalent to the local id xlocal_id.
An abstract class that defines the product structure for an id space.
virtual explicit_index_space_state * explicit_state(pod_type xlocal_id) const
The explicit id space state for id xlocal_id. Returns null if there is no explicit id space for xloca...
virtual bool is_persistent(pod_type xlocal_id) const
True if the id space with id xlocal_id should be written to disk.
An abstract iterator over the ids of an id space.
virtual pod_type unglued_hub_pod(pod_type xlocal_id, pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in the id space with id xlocal_id...
virtual const abstract_product_structure & product_structure(pod_type xlocal_id) const
The product structure for the id space with id xlocal_id (const version).
virtual pod_type local_scope(pod_type xspace_id) const
Id relative to this collection equivalent to the id space family id xspace_id.
virtual explicit_index_space_collection & operator=(const index_space_collection &xother)
Assignment operator.
virtual void remove(pod_type xlocal_id)
Remove the id space with id xlocal_id.
virtual index_space_handle & get_id_space(pod_type xlocal_id) const
Allocates an id space handle from the handle pool attached to state with id xlocal_id.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
pod_index_type pod_type
The "plain old data" index type for this.
virtual pod_type index() const =0
Index of this space.
virtual bool is_attached() const =0
True if this handle is attached to a state.
virtual void delete_product_structure(pod_type xlocal_id)
Deletes the product structure for the id space with id xlocal_id.
Abstract base class with useful features for all objects.
Definition: any.h:39
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
void insert(explicit_index_space_state &xid_space)
Insert the explicit id space xid_space into this interval.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual bool invariant() const
Class invariant.
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
virtual bool contains(pod_type xlocal_id) const
True if this collection contains the id space with local id xlocal_id.
virtual pod_type index() const =0
Index of this space.
virtual bool has_product_structure(pod_type xlocal_id) const
True if the id space with id xlocal_id has a product structure.
virtual bool contains_family(pod_type xspace_id) const
True if this collection contains the id space with family id xspace_id.
virtual bool allocated_id_space(const index_space_handle &xid_space) const
True if and only if id space handle xid_space was allocated by the handle pool.
virtual bool allocated_id_space_iterator(const index_space_iterator &xitr) const
True if and only if id space iterator xitr was allocated by the iterator pool.
map_type _states
The map from space id to explicit id space.
virtual pod_type pod(pod_type xlocal_id, pod_type xid) const
The pod index in the space with id xlocal_id equivalent to xid in the hub id space.
virtual bool is_attached() const =0
True if this iterator is attached to a state.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual const index_space_family & id_spaces() const
The id space family for this (const version).
pod_type index() const
The index of this id space.
virtual void new_product_structure(pod_type xlocal_id, const abstract_product_structure &xproduct)
Creates a new product structure for the id space with id xlocal_id by cloning the product structure...
virtual ~explicit_index_space_collection()
Creates an arg list for constructing an instance of this.
virtual pod_type end(pod_type xlocal_id) const
Ending id of the space with id xlocal_id.
An implementation of index_space_collection for a sparse collection of explicit id spaces...
virtual bool contains_unglued_hub(pod_type xlocal_id, pod_type xid) const
True if the space with id xlocal_id contains an id equivalent to xid in the unglued hub id space...
Factory and container for a family of id spaces.
virtual void release_id_space_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
virtual void release_id_space(index_space_handle &xid_space) const
Returns the id space handle xid_space to the handle pool.
virtual bool invariant() const
Class invariant.
virtual pod_type begin(pod_type xlocal_id) const
Beginning id of the space with id xlocal_id.
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
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
virtual index_space_iterator & get_id_space_iterator(pod_type xlocal_id) const
Allocates an id space iterator from the iterator pool attached to state with id xlocal_id.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
size_type capacity() const
The capacity of this collection.
index_space_family * _id_spaces
The index space family of this collection.
virtual bool operator==(const index_space_collection &xother) const
True if this is equivalent to xother.