SheafSystem  0.0.0.0
constant_index_space_interval.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/constant_index_space_interval.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/constant_implicit_index_space_iterator.h"
25 #include "SheafSystem/forwarding_index_space_handle.h"
26 #include "SheafSystem/explicit_index_space_state.h"
27 #include "SheafSystem/hub_index_space_handle.h"
28 #include "SheafSystem/index_space_family.h"
29 
30 // ===========================================================
31 // SPACE FACTORY FACET
32 // ===========================================================
33 
34 // PUBLIC MEMBER FUNCTIONS
35 
39  size_type xub,
40  pod_type xhub_id)
41 {
42  // Preconditions:
43 
44  require(xub > 0);
45 
46  // Body:
47 
48  define_old_variable(size_type old_id_spaces_end = xid_spaces.end());
49 
51  result_ptr->new_state(xid_spaces, xub);
52 
53  result_ptr->_hub_id = xhub_id;
54 
55  const constant_index_space_interval& result = *result_ptr;
56 
57  // Postconditions:
58 
59  ensure(&result.id_spaces() == &xid_spaces);
60  ensure(result.begin() == old_id_spaces_end);
61  ensure(result.end() == xid_spaces.end());
62  ensure(result.end() == result.begin() + xub);
63 
64  ensure(result.hub_id() == xhub_id);
65 
66  // Exit:
67 
68  return result;
69 }
70 
71 // PROTECTED MEMBER FUNCTIONS
72 
73 // PRIVATE MEMBER FUNCTIONS
74 
75 
76 // ===========================================================
77 // CONSTANT_INDEX_SPACE_INTERVAL FACET
78 // ===========================================================
79 
80 // PUBLIC MEMBER FUNCTIONS
81 
84 {
85  // Preconditions:
86 
87  // Body:
88 
89  // Nothing to do.
90 
91  // Postconditions:
92 
93  // Exit:
94 
95  return;
96 }
97 
100 hub_id() const
101 {
102  // Preconditions:
103 
104  // Body:
105 
106  // Postconditions:
107 
108  ensure(is_basic_query);
109 
110  // Exit:
111 
112  return _hub_id;
113 }
114 
115 // PROTECTED MEMBER FUNCTIONS
116 
120 {
121  // Preconditions:
122 
123  // Body:
124 
125  // Postconditions:
126 
127  ensure(invariant());
128 
129  // Exit:
130 
131  return;
132 }
133 
134 // PRIVATE MEMBER FUNCTIONS
135 
136 
137 // ===========================================================
138 // INDEX_SPACE_INTERVAL FACET
139 // ===========================================================
140 
141 // PUBLIC MEMBER FUNCTIONS
142 
143 // PROTECTED MEMBER FUNCTIONS
144 
145 // PRIVATE MEMBER FUNCTIONS
146 
147 
148 // ===========================================================
149 // FACTORY FACET
150 // ===========================================================
151 
152 // PUBLIC MEMBER FUNCTIONS
153 
154 const std::string&
156 class_name() const
157 {
158  static const std::string result("constant_index_space_interval");
159  return result;
160 }
161 
164 clone() const
165 {
166  // Preconditions:
167 
168  // Body:
169 
172 
173  // Postconditions:
174 
175  ensure(result != 0);
176  ensure(is_same_type(result));
177 
178  // Exit:
179 
180  return result;
181 }
182 
183 // PROTECTED MEMBER FUNCTIONS
184 
185 // PRIVATE MEMBER FUNCTIONS
186 
187 bool
188 sheaf::constant_index_space_interval::
189 make_prototype()
190 {
191  // Preconditions:
192 
193  // Body:
194 
196 
197  id_space_interval_factory().insert_prototype(lproto);
198 
199  // Postconditions:
200 
201  // Exit:
202 
203  return true;
204 }
205 
206 
207 // ===========================================================
208 // INDEX_SPACE_COLLECTION FACET
209 // ===========================================================
210 
211 // PUBLIC MEMBER FUNCTIONS
212 
213 bool
215 operator==(const index_space_collection& xother) const
216 {
217  // Preconditions:
218 
219  require(is_ancestor_of(&xother));
220 
221  // Body:
222 
223  const constant_index_space_interval& lother =
224  dynamic_cast<const constant_index_space_interval&>(xother);
225 
226  bool result = index_space_interval::operator==(xother);
227 
228  result = result && (_hub_id == lother._hub_id);
229 
230  // Postconditions:
231 
232  // Exit
233 
234  return result;
235 }
236 
239 deep_size(bool xinclude_shallow) const
240 {
241  // Preconditions:
242 
243  // Body:
244 
245  size_type result = sheaf::deep_size(*this, xinclude_shallow);
246 
247  // Postconditions:
248 
249  ensure(result >= 0);
250 
251  // Exit:
252 
253  return result;
254 }
255 
256 // PROTECTED MEMBER FUNCTIONS
257 
261 {
262  // Preconditions:
263 
264  require(is_ancestor_of(&xother));
265 
266  // Body:
267 
268  const constant_index_space_interval& lother =
269  dynamic_cast<const constant_index_space_interval&>(xother);
270 
271  _hub_id = lother._hub_id;
272 
274 
275  // Postconditions:
276 
277  ensure(invariant());
278  ensure((*this) == xother);
279 
280  // Exit:
281 
282  return *this;
283 }
284 
287 explicit_state(pod_type xlocal_id) const
288 {
289  // Preconditions:
290 
291  // Body:
292 
294 
295  explicit_index_space_state* result = 0;
296 
297  // Postconditions:
298 
299  ensure(is_basic_query);
300 
301  // Exit:
302 
303  return result;
304 }
305 
306 // PRIVATE MEMBER FUNCTIONS
307 
308 
309 // ===========================================================
310 // INDEX SPACE FACET
311 // ===========================================================
312 
313 // PUBLIC MEMBER FUNCTIONS
314 
315 void
317 remove(pod_type xlocal_id)
318 {
319  // Preconditions:
320 
321  // Body:
322 
324 
325  not_implemented();
326 
327  // Postconditions:
328 
329  ensure(!contains(xlocal_id));
330 
331  // Exit:
332 
333  return;
334 }
335 
338 ct(pod_type xlocal_id) const
339 {
340  // Preconditions:
341 
342  require(contains(xlocal_id));
343 
344  // Body:
345 
346  size_type result = 1;
347 
348  // Postconditions:
349 
350  ensure(is_basic_query);
351 
352  // Exit:
353 
354  return result;
355 }
356 
359 begin(pod_type xlocal_id) const
360 {
361  // Preconditions:
362 
363  require(contains(xlocal_id));
364 
365  // Body:
366 
367  pod_type result = 0;
368 
369  // Postconditions:
370 
371  ensure(is_basic_query);
372 
373  // Exit:
374 
375  return result;
376 }
377 
380 end(pod_type xlocal_id) const
381 {
382  // Preconditions:
383 
384  require(contains(xlocal_id));
385 
386  // Body:
387 
388  pod_type result = 1;
389 
390  // Postconditions:
391 
392  ensure(is_basic_query);
393 
394  // Exit:
395 
396  return result;
397 }
398 
399 bool
401 contains(pod_type xlocal_id, pod_type xid) const
402 {
403  // Preconditions:
404 
405  require(contains(xlocal_id));
406 
407  // Body:
408 
409  bool result = (xid == 0);
410 
411  // Postconditions:
412 
413  ensure(is_basic_query);
414 
415  // Exit:
416 
417  return result;
418 }
419 
420 bool
423 {
424  // Preconditions:
425 
426  require(contains(xlocal_id));
427 
428  // Body:
429 
430  bool result = (xid == _hub_id);
431 
432  // Postconditions:
433 
434  ensure(is_basic_query);
435 
436  // Exit:
437 
438  return result;
439 }
440 
441 bool
443 contains(pod_type xlocal_id, pod_type xid, pod_type xhub_id) const
444 {
445  // Preconditions:
446 
447  require(contains(xlocal_id));
448 
449  // Body:
450 
451  bool result =
452  (xid == 0) &&
453  (_hub_id == xhub_id);
454 
455  // Postconditions:
456 
457  ensure(is_basic_query);
458 
459  // Exit:
460 
461  return result;
462 }
463 
466 pod(pod_type xlocal_id, pod_type xid) const
467 {
468  // Preconditions:
469 
470  require(contains(xlocal_id));
471 
472  // Body:
473 
474  pod_type result = contains_hub(xlocal_id, xid) ? 0 : invalid_pod_index();
475 
476  // Postconditions:
477 
478  ensure(!is_valid(result) || contains(xlocal_id, result));
479 
480  // Exit:
481 
482  return result;
483 }
484 
487 unglued_hub_pod(pod_type xlocal_id, pod_type xid) const
488 {
489  // Preconditions:
490 
491  require(contains(xlocal_id));
492 
493  // Body:
494 
495  pod_type result =
496  (xid == 0) ? _hub_id : invalid_pod_index();
497 
498  // Postconditions:
499 
500  ensure(!is_valid(result) || contains_unglued_hub(xlocal_id, result));
501 
502  // Exit:
503 
504  return result;
505 }
506 
507 bool
509 is_persistent(pod_type xlocal_id) const
510 {
511  // Preconditions:
512 
513  require(contains(xlocal_id));
514 
515  // Body:
516 
517  bool result = false;
518 
519  // Postconditions:
520 
521  ensure(is_basic_query);
522 
523  // Exit:
524 
525  return result;
526 }
527 
528 // PROTECTED MEMBER FUNCTIONS
529 
530 // PRIVATE MEMBER FUNCTIONS
531 
532 
533 // ===========================================================
534 // PRODUCT STRUCTURE FACET
535 // ===========================================================
536 
537 // PUBLIC MEMBER FUNCTIONS
538 
539 void
542  const abstract_product_structure& xproduct)
543 {
544  // Preconditions:
545 
546  require(contains(xlocal_id));
547 
548  // Body:
549 
551 
552  not_implemented();
553 
554  // Postconditions:
555 
556  ensure(has_product_structure(xlocal_id));
557 
558  // Exit:
559 
560  return;
561 }
562 
563 void
566 {
567  // Preconditions:
568 
569  require(contains(xlocal_id));
570 
571  // Body:
572 
574 
575  not_implemented();
576 
577  // Postconditions:
578 
579  ensure(!has_product_structure(xlocal_id));
580 
581  // Exit:
582 
583  return;
584 }
585 
588 product_structure(pod_type xlocal_id) const
589 {
590  // Preconditions:
591 
592  require(contains(xlocal_id));
593  require(has_product_structure(xlocal_id));
594 
595  // Body:
596 
598 
599  const abstract_product_structure* result = 0; // Just to silence compiler warnings.
600 
601  not_implemented();
602 
603  // Postconditions:
604 
605  ensure(is_basic_query);
606 
607  // Exit:
608 
609  return *result;
610 }
611 
615 {
616  // Preconditions:
617 
618  require(contains(xlocal_id));
619  require(has_product_structure(xlocal_id));
620 
621  // Body:
622 
624 
625  abstract_product_structure* result = 0; // Just to silence compiler warnings.
626 
627  not_implemented();
628 
629  // Postconditions:
630 
631  ensure(is_basic_query);
632 
633  // Exit:
634 
635  return *result;
636 }
637 
638 bool
641 {
642  // Preconditions:
643 
644  require(contains(xlocal_id));
645 
646  // Body:
647 
649 
650  bool result = false; // Just to silence compiler warnings.
651 
652  not_implemented();
653 
654  // Postconditions:
655 
656  ensure(is_basic_query);
657 
658  // Exit:
659 
660  return result;
661 }
662 
663 // PROTECTED MEMBER FUNCTIONS
664 
665 // PRIVATE MEMBER FUNCTIONS
666 
667 
668 // ===========================================================
669 // HANDLE POOL FACET
670 // ===========================================================
671 
672 // PUBLIC MEMBER FUNCTIONS
673 
676 get_id_space(pod_type xlocal_id) const
677 {
678  // Preconditions:
679 
680  require(contains(xlocal_id));
681 
682  // Body:
683 
684  index_space_handle& result = _handles.get();
685  result.attach_to(*this, xlocal_id);
686 
687  // Postconditions:
688 
689  ensure(result.is_attached());
690 
691  // Exit:
692 
693  return result;
694 }
695 
696 void
699 {
700  // Preconditions:
701 
702  require(allocated_id_space(xid_space));
703 
704  // Body:
705 
706  // Detach the handle.
707 
708  xid_space.detach();
709 
710  // Release the handle to the pool.
711 
712  _handles.release(reinterpret_cast<forwarding_index_space_handle&>(xid_space));
713 
714  // Postconditions:
715 
716  ensure(is_basic_query);
717 
718  // Exit:
719 
720  return;
721 }
722 
723 bool
725 allocated_id_space(const index_space_handle& xid_space) const
726 {
727  // Preconditions:
728 
729  // Body:
730 
731  const forwarding_index_space_handle* lid_space =
732  dynamic_cast<const forwarding_index_space_handle*>(&xid_space);
733 
734  bool result = (lid_space != 0) && _handles.allocated(*lid_space);
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 // ITERATOR POOL FACET
752 // ===========================================================
753 
754 // PUBLIC MEMBER FUNCTIONS
755 
759 {
760  // Preconditions:
761 
762  require(contains(xlocal_id));
763 
764  // Body:
765 
766  index_space_iterator& result = _iterators.get();
767  result.attach_to(*this, xlocal_id);
768 
769  // Postconditions:
770 
771  ensure(result.is_attached());
772 
773  // Exit:
774 
775  return result;
776 }
777 
778 void
781 {
782  // Preconditions:
783 
784  require(allocated_id_space_iterator(xitr));
785 
786  // Body:
787 
788  // Detach the iterator.
789 
790  xitr.detach();
791 
792  // Release the iterator to the pool.
793 
794  _iterators.release(reinterpret_cast<constant_implicit_index_space_iterator&>(xitr));
795 
796  // Postconditions:
797 
798  ensure(is_basic_query);
799 
800  // Exit:
801 
802  return;
803 }
804 
805 bool
808 {
809  // Preconditions:
810 
811  // Body:
812 
814  dynamic_cast<const constant_implicit_index_space_iterator*>(&xitr);
815 
816  bool result = (litr != 0) && _iterators.allocated(*litr);
817 
818  // Postconditions:
819 
820  ensure(is_basic_query);
821 
822  // Exit:
823 
824  return result;
825 }
826 
827 // PROTECTED MEMBER FUNCTIONS
828 
829 // PRIVATE MEMBER FUNCTIONS
830 
831 
832 // ===========================================================
833 // ANY FACET
834 // ===========================================================
835 
836 // PUBLIC MEMBER FUNCTIONS
837 
838 bool
840 is_ancestor_of(const any *other) const
841 {
842  // Preconditions:
843 
844  require(other != 0);
845 
846  // Body:
847 
848  // True if other conforms to this
849 
850  bool result = dynamic_cast<const constant_index_space_interval*>(other) != 0;
851 
852  // Postconditions:
853 
854  // Exit:
855 
856  return result;
857 }
858 
859 bool
861 invariant() const
862 {
863  bool result = true;
864 
865  if(invariant_check())
866  {
867  // Prevent recursive calls to invariant
868 
870 
871  // Must satisfy base class invariant
872 
873  invariance(index_space_interval::invariant());
874 
875  // Invariances for this class:
876 
877  // Finished, turn invariant checking back on.
878 
880  }
881 
882  // Exit
883 
884  return result;
885 }
886 
887 // PROTECTED MEMBER FUNCTIONS
888 
889 // PRIVATE MEMBER FUNCTIONS
890 
891 
892 // ===========================================================
893 // NON-MEMBER FUNCTIONS
894 // ===========================================================
895 
896 size_t
897 sheaf::
898 deep_size(const constant_index_space_interval& xn, bool xinclude_shallow)
899 {
900  // Preconditions:
901 
902  // Body:
903 
904  size_t result = xinclude_shallow ? sizeof(xn) : 0;
905 
906  // Add contributions for _handles.
907 
908  result += deep_size(xn._handles, false);
909 
910  // Add contributions for _iterators.
911 
912  result += deep_size(xn._iterators, false);
913 
914  // Postconditions:
915 
916  ensure(result >= 0);
917 
918  // Exit
919 
920  return result;
921 }
virtual void remove(pod_type xlocal_id)
Remove the id space with id xlocal_id.
pod_type end() const
The ending index of the id spaces.
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.
An abstract class that defines the product structure for an id space.
virtual constant_index_space_interval * clone() const
Virtual constructor; create a new instance of the same type at this.
virtual void release_id_space(index_space_handle &xid_space) const
Returns the id space handle xid_space to the handle pool.
virtual const index_space_family & id_spaces() const
The id space family for this (const version).
An abstract iterator over the ids of an 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 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...
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.
virtual index_space_interval & operator=(const index_space_collection &xother)
Assignment operator.
virtual constant_index_space_interval & operator=(const index_space_collection &xother)
Assignment operator.
An implementation of index_space_interval for an interval of implicit id spaces with a single id and ...
An implementation of implicit_index_space_iterator for an implicit id space in an constant_index_spac...
virtual bool invariant() const
Class invariant.
virtual void detach()=0
Detach this handle form its state, if any.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
virtual bool operator==(const index_space_collection &xother) const
True if this is equivalent to xother.
pod_index_type pod_type
The "plain old data" index type for this.
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 bool is_attached() const =0
True if this handle is attached to a state.
virtual void detach()=0
Detach this handle form its state, if any.
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...
list_pool< forwarding_index_space_handle > _handles
The handle pool.
virtual void delete_product_structure(pod_type xlocal_id)
Deletes the product structure for the id space with id xlocal_id.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
An implemenation of index_space_collection that adds an interface for the interval [begin()...
virtual bool contains(pod_type xlocal_id, pod_type xid) const
True if the space with id xlocal_id contains id xid.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
An implementation of class index_space_handle for an forwarding_index_space_state.
void attach_to(const index_space_family &xid_spaces, pod_type xindex)
Attach to the state with index xindex in the id space family xid_spaces.
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.
virtual size_type ct(pod_type xlocal_id) const
The number of members for the id space with id xlocal_id.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
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 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.
virtual pod_type begin(pod_type xlocal_id) const
Beginning id of the space with id xlocal_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.
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
void attach_to(const index_space_family &xid_spaces, pod_type xindex)
Attach to the state with index xindex in the id space family xid_spaces.
static factory< index_space_interval > & id_space_interval_factory()
A factory for making descendants of this class.
virtual bool operator==(const index_space_collection &xother) const
True if this is equivalent to xother.
virtual const std::string & class_name() const
The name of this class.
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 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...
static const constant_index_space_interval & new_space(index_space_family &xid_spaces, size_type xub, pod_type xhub_id)
Create a new interval of id spaces with an constant representation in the id space family xid_spaces ...
pod_type end() const
Ending space id of this interval in the id space family scope.
virtual bool is_persistent(pod_type xlocal_id) const
True if the id space with id xlocal_id should be written to disk.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
Factory and container for a family of id spaces.
bool contains_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 hub id space...
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 void release_id_space_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
pod_type hub_id() const
The constant hub id.
pod_type begin() const
Beginning space id of this interval in the id space family scope.
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
virtual bool has_product_structure(pod_type xlocal_id) const
True if the id space with id xlocal_id has a product structure.
list_pool< constant_implicit_index_space_iterator > _iterators
The iterator pool.
virtual pod_type end(pod_type xlocal_id) const
Ending id of the space with id xlocal_id.
friend SHEAF_DLL_SPEC size_t deep_size(const constant_index_space_interval &xn, bool xinclude_shallow)
The deep size of constant_index_space_interval& xn.