SheafSystem  0.0.0.0
list_index_space_state.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/list_index_space_state.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/list_index_space_handle.h"
24 #include "SheafSystem/list_index_space_iterator.h"
25 #include "SheafSystem/deep_size.h"
26 #include "SheafSystem/index_space_family.h"
27 #include "SheafSystem/hub_index_space_handle.h"
28 
29 // ===========================================================
30 // SPACE FACTORY FACET
31 // ===========================================================
32 
33 // PUBLIC MEMBER FUNCTIONS
34 
38  const std::string& xname,
39  bool xis_persistent)
40 {
41  // Preconditions:
42 
43  require(!xname.empty());
44  require(!xid_spaces.contains(xname));
45 
46  // Body:
47 
49  lstate->new_state(xid_spaces, xname, xis_persistent);
50 
51  list_index_space_handle result(*lstate);
52 
53  // Postconditions:
54 
55  ensure(&result.id_spaces() == &xid_spaces);
56  ensure(xid_spaces.contains(xname));
57  ensure(result.conforms_to_state(xname));
58 
59  ensure(result.is_persistent() == xis_persistent);
60  ensure(result.name() == xname);
61 
62  ensure(result.capacity() >= 0);
63 
64  // Exit:
65 
66  return result;
67 }
68 
71 new_space(index_space_family& xid_spaces,
72  pod_index_type xid,
73  const std::string& xname,
74  bool xis_persistent)
75 {
76  // Preconditions:
77 
78  require(!xid_spaces.contains(xid));
79  require(xid_spaces.is_explicit_interval(xid));
80  require(!xname.empty());
81  require(!xid_spaces.contains(xname));
82 
83  // Body:
84 
86  lstate->new_state(xid_spaces, xid, xname, xis_persistent);
87 
88  list_index_space_handle result(*lstate);
89 
90  // Postconditions:
91 
92  ensure(&result.id_spaces() == &xid_spaces);
93  ensure(xid_spaces.contains(xname));
94  ensure(result.conforms_to_state(xname));
95 
96  ensure(result.index() == xid);
97  ensure(result.is_persistent() == xis_persistent);
98  ensure(result.name() == xname);
99 
100  // ensure(result.capacity() >= 0);
101 
102  // Exit:
103 
104  return result;
105 }
106 
107 // PROTECTED MEMBER FUNCTIONS
108 
109 // PRIVATE MEMBER FUNCTIONS
110 
111 
112 // ===========================================================
113 // LIST_INDEX_SPACE_STATE FACET
114 // ===========================================================
115 
116 // PUBLIC MEMBER FUNCTIONS
117 
118 void
120 reverse(bool xupdate_extrema)
121 {
122  // Preconditions:
123 
124  // Body:
125 
126  _to_range.reverse();
127 
128 
129  if(xupdate_extrema)
130  {
131  update_extrema();
132  }
133 
134  // Postconditions:
135 
136  // Exit:
137 
138  return;
139 }
140 
143 front() const
144 {
145  return _to_range.front();
146 }
147 
150 back() const
151 {
152  return _to_range.back();
153 }
154 
155 void
158 {
159  // cout << endl << "Entering list_index_space_state::push_front." << endl;
160 
161  // Preconditions:
162 
163  require(!contains_unglued_hub(xhub_id));
164 
165  // Body:
166 
167  define_old_variable(size_type old_ct = _ct);
168  define_old_variable(pod_type old_begin = _begin);
169  define_old_variable(pod_type old_end = _end);
170 
171  // Insert the entry in the list.
172 
173  _to_range.push_front(xhub_id);
174 
175  // Update the count.
176 
177  ++_ct;
178 
179  // Update the extrema.
180 
181  _begin = 0;
182 
183  if(_ct > 1)
184  {
185  ++_end;
186  }
187  else
188  {
189  _end = 1;
190  }
191 
192  // Postconditions:
193 
194  ensure(invariant());
195  ensure(unglued_hub_pod(0) == xhub_id);
196  ensure(ct() == old_ct + 1);
197  ensure(begin() == 0);
198  ensure(ct() > 1 ? end() == old_end+1 : end() == 1);
199 
200  // Exit:
201 
202  // cout << "Leaving list_index_space_state::push_front." << endl;
203  return;
204 }
205 
206 void
208 replace_range_id(pod_type xold_range_id, pod_type xnew_range_id)
209 {
210  // cout << endl << "Entering list_index_space_state::replace_range_id." << endl;
211 
212  // Preconditions:
213 
214  require((xnew_range_id != xold_range_id) ? !contains_unglued_hub(xnew_range_id) : true);
215 
216  // Body:
217 
218  define_old_variable(bool old_contains_xold_range_id = contains_unglued_hub(xold_range_id));
219  define_old_variable(pod_type old_domain_id = pod(xold_range_id));
220 
221  to_range_type::iterator litr = to_range_itr(xold_range_id, true);
222  if(litr != _to_range.end())
223  {
224  *litr = xnew_range_id;
225  }
226 
227 
228  // Postconditions:
229 
230  ensure(old_contains_xold_range_id ? contains_unglued_hub(xnew_range_id) : true);
231  ensure((xnew_range_id != xold_range_id) ? !contains_unglued_hub(xold_range_id) : true);
232  ensure(old_contains_xold_range_id ? pod(xnew_range_id) == old_domain_id : true);
233 
234  // Exit:
235 
236  // cout << "Leaving list_index_space_state::replace_range_id." << endl;
237  return;
238 }
239 
240 
241 // PROTECTED MEMBER FUNCTIONS
242 
246 {
247  // Preconditions:
248 
249  // Body:
250 
251  _capacity = 0;
252 
253  // Postconditions:
254 
255  ensure(invariant());
256  ensure(is_empty());
257  ensure(capacity() == 0);
258 
259  // Exit:
260 
261  return;
262 }
263 
266 {
267  // Preconditions:
268 
269  // Body:
270 
271  // nothing to do.
272 
273  // Postconditions:
274 
275  // Exit:
276 
277  return;
278 }
279 
280 
281 // PRIVATE MEMBER FUNCTIONS
282 
283 
284 // ===========================================================
285 // GATHERED_INSERTION INDEX SPACE FACET
286 // ===========================================================
287 
288 // PUBLIC MEMBER FUNCTIONS
289 
290 
291 void
294 {
295  // Preconditions:
296 
297  // Body:
298 
299  // List is always gathered by defintion.
300 
301  if(_ct == 0)
302  {
303  // The map is empty.
304 
307  }
308  else
309  {
310  _begin = 0;
311  _end = _ct;
312  }
313 
314  // Postconditions:s
315 
316  // Exit
317 
318  return;
319 }
320 
321 void
323 reserve(size_type xcapacity)
324 {
325  // Preconditions:
326 
327  // Body:
328 
329  _capacity = xcapacity;
330 
331  // Postconditions:
332 
333  ensure(invariant());
334  ensure(capacity() >= xcapacity);
335 
336  // Exit:
337 
338  return;
339 }
340 
343 capacity() const
344 {
345  // Preconditions:
346 
347  // Body:
348 
349  size_type result = _capacity;
350 
351  // Postconditions:
352 
353  ensure(is_basic_query);
354 
355  // Exit:
356 
357  return result;
358 }
359 
360 // PROTECTED MEMBER FUNCTIONS
361 
362 // PRIVATE MEMBER FUNCTIONS
363 
364 
365 // ===========================================================
366 // MAP REPRESENTATION FACET
367 // ===========================================================
368 
369 // PUBLIC MEMBER FUNCTIONS
370 
374 {
375  return _to_range;
376 }
377 
380 to_range() const
381 {
382  return _to_range;
383 }
384 
385 
386 // PROTECTED MEMBER FUNCTIONS
387 
388 void
391 {
392  // Preconditions:
393 
394  require(!contains_hub(xrange_id));
395 
396  // Body:
397 
398  define_old_variable(pod_type old_next_id = next_id());
399 
400  _to_range.push_back(xrange_id);
401 
402  // Postconditions:
403 
404  // Not finished pushing back; do not ensure invariant.
405 
406  ensure(contains(old_next_id, xrange_id));
407 
408  // Exit
409 
410  return;
411 }
412 
413 void
416 {
417  // Preconditions:
418 
419  require(allocated_iterator(xitr));
420  require(!contains_hub(xrange_id));
421 
422  // Body:
423 
424  define_old_variable(pod_type old_itr_pod = xitr.pod());
425  define_old_variable(pod_type old_itr_hub_pod = xitr.hub_pod());
426 
428  reinterpret_cast<list_index_space_iterator&>(xitr);
429 
430  // Insert an item before the current position.
431 
432  litr._itr = _to_range.insert(litr._itr, xrange_id);
433 
434  // Increment to the next position in the iteration
435  // (old_itr_pod+1, old_itr_hub_pod).
436 
437  ++litr._itr;
438 
439  // Update the pod value.
440 
441  ++litr._pod;
442 
443  // Postconditions:
444 
445  // Not finished inserting entry, do not ensure invariant.
446 
447  ensure(contains(old_itr_pod, xrange_id));
448  ensure(xitr.pod() == old_itr_pod+1);
449  ensure(xitr.hub_pod() == old_itr_hub_pod);
450 
451  // Exit:
452 
453  return;
454 }
455 
458 map_rep_remove_entry(pod_type xid, bool xis_range_id)
459 {
460  // Preconditions:
461 
462 
463  define_old_variable(bool old_contains_entry = xis_range_id ? contains_hub(xid) : contains(xid));
464  define_old_variable(pod_type old_pod = xis_range_id ? pod(xid) : xid);
465  define_old_variable(pod_type old_hub_pod = xis_range_id ? xid : hub_pod(xid));
466 
467  // Body:
468 
469  // $$SCRIBBLE: need to actually remove the entry
470 
471  size_type result = 0;
472 
473  to_range_type::iterator litr = to_range_itr(xid, xis_range_id);
474  if(litr != _to_range.end())
475  {
476  _to_range.erase(litr);
477  result = 1;
478  }
479 
480 // size_type result = 0;
481 
482 // if(xis_range_id)
483 // {
484 // to_range_type::iterator litr = _to_range.begin();
485 
486 // while(litr != _to_range.end())
487 // {
488 // if(*litr == xid)
489 // {
490 // // Found the id, remove it.
491 
492 // *litr = invalid_pod_index();
493 // result = 1;
494 // break;
495 // }
496 // else
497 // {
498 // // Not the id, iterate to the next item.
499 
500 // ++litr;
501 // }
502 // }
503 // }
504 // else
505 // {
506 // pod_type ldomain_id;
507 
508 // to_range_type::iterator itr;
509 
510 // for(itr = _to_range.begin(), ldomain_id = 0;
511 // itr != _to_range.end();
512 // ++itr, ++ldomain_id)
513 // {
514 // if(ldomain_id == xid)
515 // {
516 // // Found the id.
517 
518 // if(!is_valid(*itr))
519 // {
520 // // Entry does not exist, exit loop.
521 
522 // break;
523 // }
524 
525 // // Entry exists, remove it.
526 
527 // *itr = invalid_pod_index();
528 // result = 1;
529 
530 // break;
531 // }
532 // }
533 // }
534 
535 // if(result > 0)
536 // {
537 // // No invalid ids should be on the tail of the list, prone them.
538 
539 // while(!_to_range.empty() && !is_valid(_to_range.back()))
540 // {
541 // _to_range.pop_back();
542 // }
543 // }
544 
545  // Postconditions:
546 
547  // Not finished removing entry; do not ensure invariant.
548 
549  // ensure(xis_range_id ? !contains_hub(xid) : !contains(xid));
550  ensure(!old_contains_entry || !contains(old_pod, old_hub_pod));
551  ensure((result == 0) || (result == 1));
552 
553  // Exit
554 
555  return result;
556 }
557 
558 void
561 {
562  // Preconditions:
563 
564  require(allocated_iterator(xitr));
565  require(!xitr.is_done());
566  require(contains(xitr.pod()));
567 
568  // Body:
569 
570  define_old_variable(pod_type old_itr_id = xitr.pod());
571  define_old_variable(pod_type old_itr_hub_id = xitr.hub_pod());
572 
574  reinterpret_cast<list_index_space_iterator&>(xitr);
575 
576  // Remove the current position.
577  // Note that since the id space is determined by sequentially
578  // numbering the items in the list, the pod id
579  // associated with the new value of the iterator is unchanged.
580 
581  litr._itr = _to_range.erase(litr._itr);
582 
583  if(litr._itr == _to_range.end())
584  {
585  // Erased the last item in the list, the iteration is done.
586 
587  litr.invalidate_ids();
588  }
589  else
590  {
591  // Update the hub pod.
592 
593  litr._hub_pod = *litr._itr;
594  }
595 
596  // Postconditions:
597 
598  ensure(!contains_hub(old_itr_hub_id));
599  ensure(xitr.is_done() || xitr.pod() == old_itr_id);
600  ensure(unexecutable("xitr.is_done() || xitr.hub_pod() == old_next_itr_hub_pod"));
601 
602  // Exit:
603 
604  return;
605 }
606 
607 void
610 {
611  // Preconditions:
612 
613  // Body:
614 
615  _to_range.clear();
616 
617  // Postconditions:
618 
619  // Not finished clearing; do not ensure invariant.
620  // Map rep is empty, but _ct not reset, so can't ensure is_empty.
621 
622  ensure(unexecutable("map rep is empty"));
623 
624  // Exit:
625 
626  return;
627 }
628 
629 void
632 {
633  // Preconditions:
634 
635  // Body:
636 
637  // $$SCRIBBLE: no need to do anything. Map is always gatherd.
638 
639 // to_range_type::iterator itr;
640 // to_range_type::iterator new_itr;
641 
642 // for(itr = _to_range.begin(), new_itr = _to_range.begin();
643 // itr != _to_range.end();
644 // ++itr)
645 // {
646 // if(is_valid(*itr) && (itr != new_itr))
647 // {
648 // // The current value is value and the position has changed,
649 // // assign value to new position.
650 
651 // *new_itr = *itr;
652 // ++new_itr;
653 // }
654 // }
655 
656 // if(new_itr != _to_range.end())
657 // {
658 // // Trim the map to the new size.
659 
660 // _to_range.erase(++new_itr, _to_range.end());
661 // }
662 
663  // Postconditions:
664 
665  ensure(unexecutable("map rep is gathered"));
666 
667  // Exit:
668 
669  return;
670 }
671 
672 sheaf::list_index_space_state::to_range_type::iterator
674 to_range_itr(pod_type xid, bool xis_range_id)
675 {
676  // cout << endl << "Entering list_index_space_state::to_range_itr." << endl;
677 
678  // Preconditions:
679 
680 
681  // Body:
682 
683  to_range_type::iterator result;
684 
685  if(xis_range_id)
686  {
687  for(result = _to_range.begin(); result != _to_range.end(); ++result)
688  {
689  if(*result == xid)
690  {
691  break;
692  }
693  }
694  }
695  else
696  {
697  pod_type ldomain_id;
698  for(result = _to_range.begin(), ldomain_id = 0; result != _to_range.end(); ++result, ++ldomain_id)
699  {
700  if(ldomain_id == xid)
701  {
702  break;
703  }
704  }
705  }
706 
707 
708  // Postconditions:
709 
710  // Exit:
711 
712  // cout << "Leaving list_index_space_state::to_range_itr." << endl;
713  return result;
714 }
715 
716 sheaf::list_index_space_state::to_range_type::const_iterator
718 to_range_const_itr(pod_type xid, bool xis_range_id) const
719 {
720  // cout << endl << "Entering list_index_space_state::to_range_const_itr." << endl;
721 
722  // Preconditions:
723 
724 
725  // Body:
726 
727  to_range_type::const_iterator result;
728 
729  if(xis_range_id)
730  {
731  for(result = _to_range.begin(); result != _to_range.end(); ++result)
732  {
733  if(*result == xid)
734  {
735  break;
736  }
737  }
738  }
739  else
740  {
741  pod_type ldomain_id;
742  for(result = _to_range.begin(), ldomain_id = 0; result != _to_range.end(); ++result, ++ldomain_id)
743  {
744  if(ldomain_id == xid)
745  {
746  break;
747  }
748  }
749  }
750 
751 
752  // Postconditions:
753 
754  // Exit:
755 
756  // cout << "Leaving list_index_space_state::to_range_const_itr." << endl;
757  return result;
758 }
759 
760 
761 // PRIVATE MEMBER FUNCTIONS
762 
763 
764 // ===========================================================
765 // EXPLICIT_INDEX_SPACE_STATE FACET
766 // ===========================================================
767 
768 // PUBLIC MEMBER FUNCTIONS
769 
770 bool
773 {
774  // Preconditions:
775 
776  require(is_ancestor_of(&xother));
777 
778  // Body:
779 
780  const list_index_space_state& lother =
781  dynamic_cast<const list_index_space_state&>(xother);
782 
784  result = result && (_to_range == lother._to_range);
785  result = result && (_capacity == lother._capacity);
786 
787  // Postconditions:
788 
789  // Exit
790 
791  return result;
792 }
793 
796 deep_size(bool xinclude_shallow) const
797 {
798  // Preconditions:
799 
800  // Body:
801 
802  size_type result = sheaf::deep_size(*this, xinclude_shallow);
803 
804  // Postconditions:
805 
806  ensure(result >= 0);
807 
808  // Exit:
809 
810  return result;
811 }
812 
813 // PROTECTED MEMBER FUNCTIONS
814 
818 {
819  // Preconditions:
820 
821  require(is_ancestor_of(&xother));
822 
823  // Body:
824 
825  const list_index_space_state& lother =
826  dynamic_cast<const list_index_space_state&>(xother);
827 
828  _to_range = lother._to_range;
829  _capacity = lother._capacity;
830 
831  (void) gathered_insertion_index_space_state::operator=(xother);
832 
833  // Postconditions:
834 
835  ensure(invariant());
836  ensure((*this) == xother);
837 
838  // Exit
839 
840  return *this;
841 }
842 
843 // PRIVATE MEMBER FUNCTIONS
844 
845 
846 // ===========================================================
847 // INDEX SPACE FACET
848 // ===========================================================
849 
850 // PUBLIC MEMBER FUNCTIONS
851 
852 bool
854 contains(pod_type xid) const
855 {
856  // Preconditions:
857 
858  // Body:
859 
860  // If _ct = 0 then _begin == _end == invalid_pod_index() and
861  // the following expression returns false for any xid. So we don't
862  // have to test whether _begin or _end is valid.
863 
864  assertion(is_valid(_begin) == is_valid(_end));
865 
866  bool result = (_begin <= xid) && (xid < _end);
867 
868 // bool result = false;
869 
870 // pod_index_type ldomain_id;
871 // to_range_type::const_iterator itr;
872 
873 // for(itr = _to_range.begin(), ldomain_id = 0;
874 // itr != _to_range.end();
875 // ++itr, ++ldomain_id)
876 // {
877 // if(ldomain_id == xid)
878 // {
879 // result = is_valid(*itr);
880 // break;
881 // }
882 // }
883 
884  // Postconditions:
885 
886  ensure(is_basic_query);
887 
888  // Exit
889 
890  return result;
891 }
892 
893 bool
896 {
897  // Preconditions:
898 
899  // Body:
900 
901  bool result = to_range_const_itr(xhub_id, true) != _to_range.end();
902 
903 
904 // bool result = false;
905 
906 // to_range_type::const_iterator itr;
907 
908 // for(itr = _to_range.begin(); itr != _to_range.end(); ++itr)
909 // {
910 // if(*itr == xhub_id)
911 // {
912 // result = true;
913 // break;
914 // }
915 // }
916 
917  // Postconditions:
918 
919  ensure(is_basic_query);
920 
921  // Exit
922 
923  return result;
924 }
925 
926 bool
928 contains(pod_type xid, pod_type xhub_id) const
929 {
930  // Preconditions:
931 
932  // Body:
933 
934  to_range_type::const_iterator litr = to_range_const_itr(xid, false);
935  bool result = (litr != _to_range.end()) && (*litr == xhub_id);
936 
937 
938 // bool result = false;
939 
940 // pod_index_type ldomain_id;
941 // to_range_type::const_iterator itr;
942 
943 // for(itr = _to_range.begin(), ldomain_id = 0; itr != _to_range.end(); ++itr, ++ldomain_id)
944 // {
945 // if(ldomain_id == xid)
946 // {
947 // result = (*itr == xhub_id);
948 // break;
949 // }
950 // }
951 
952  // Postconditions:
953 
954  ensure(is_basic_query);
955 
956  // Exit:
957 
958  return result;
959 }
960 
963 pod(pod_type xhub_id) const
964 {
965  // Preconditions:
966 
967  // Body:
968 
969  pod_type result = invalid_pod_index();
970 
971  pod_index_type ldomain_id;
972  to_range_type::const_iterator itr;
973 
974  for(itr = _to_range.begin(), ldomain_id = 0; itr != _to_range.end(); ++itr, ++ldomain_id)
975  {
976  if(*itr == xhub_id)
977  {
978  result = ldomain_id;
979  break;
980  }
981  }
982 
983  // Postconditions:
984 
985  ensure(!is_valid(result) || contains(result));
986 
987  // Exit
988 
989  return result;
990 }
991 
995 {
996  // Preconditions:
997 
998  // Body:
999 
1000  to_range_type::const_iterator litr = to_range_const_itr(xid, false);
1001  pod_type result = (litr != _to_range.end()) ? *litr : invalid_pod_index();
1002 
1003 // pod_type result = invalid_pod_index();
1004 
1005 // pod_index_type ldomain_id;
1006 // to_range_type::const_iterator itr;
1007 
1008 // for(itr = _to_range.begin(), ldomain_id = 0; itr != _to_range.end(); ++itr, ++ldomain_id)
1009 // {
1010 // if(ldomain_id == xid)
1011 // {
1012 // result = *itr;
1013 // break;
1014 // }
1015 // }
1016 
1017  // Postconditions:
1018 
1019  ensure(!is_valid(result) || contains_unglued_hub(result));
1020 
1021  // Exit:
1022 
1023  return result;
1024 }
1025 
1026 // PROTECTED MEMBER FUNCTIONS
1027 
1028 // PRIVATE MEMBER FUNCTIONS
1029 
1030 
1031 // ===========================================================
1032 // HANDLE POOL FACET
1033 // ===========================================================
1034 
1035 // PUBLIC MEMBER FUNCTIONS
1036 
1040 {
1041  // Preconditions:
1042 
1043  // Body:
1044 
1045  size_type result = handles().ct();
1046 
1047  // Postconditions:
1048 
1049  ensure(result >= 0);
1050 
1051  // Exit:
1052 
1053  return result;
1054 }
1055 
1059 {
1060  // Preconditions:
1061 
1062  // Body:
1063 
1064  size_type result = sheaf::deep_size(handles(), true);
1065 
1066  // Postconditions:
1067 
1068  ensure(result >= 0);
1069 
1070  // Exit:
1071 
1072  return result;
1073 }
1074 
1078 {
1079  // Preconditions:
1080 
1081  // Body:
1082 
1083  list_index_space_handle& result = handles().get();
1084  attach(result);
1085 
1086  // Postconditions:
1087 
1088  ensure(result.is_attached());
1089 
1090  // Exit:
1091 
1092  return result;
1093 }
1094 
1095 void
1098 {
1099  // Preconditions:
1100 
1101  require(allocated_id_space(xid_space));
1102 
1103  // Body:
1104 
1105  // Detach the handle.
1106 
1107  xid_space.detach();
1108 
1109  // Release the handle to the pool.
1110 
1111  handles().release(reinterpret_cast<list_index_space_handle&>(xid_space));
1112 
1113  // Postconditions:
1114 
1115  ensure(is_basic_query);
1116 
1117  // Exit:
1118 
1119  return;
1120 }
1121 
1122 bool
1125 {
1126  // Preconditions:
1127 
1128  // Body:
1129 
1130  const list_index_space_handle* lid_space =
1131  dynamic_cast<const list_index_space_handle*>(&xid_space);
1132 
1133  bool result = (lid_space != 0) && handles().allocated(*lid_space);
1134 
1135  // Postconditions:
1136 
1137  ensure(is_basic_query);
1138 
1139  // Exit:
1140 
1141  return result;
1142 }
1143 
1144 // PROTECTED MEMBER FUNCTIONS
1145 
1146 // PRIVATE MEMBER FUNCTIONS
1147 
1149 sheaf::list_index_space_state::
1150 handles()
1151 {
1152  // Preconditions:
1153 
1154  // Body:
1155 
1156  static list_pool<list_index_space_handle> result;
1157 
1158  // Postconditions:
1159 
1160  ensure(is_basic_query);
1161 
1162  // Exit:
1163 
1164  return result;
1165 }
1166 
1167 
1168 // ===========================================================
1169 // ITERATOR POOL FACET
1170 // ===========================================================
1171 
1172 // PUBLIC MEMBER FUNCTIONS
1173 
1177 {
1178  // Preconditions:
1179 
1180  // Body:
1181 
1182  size_type result = iterators().ct();
1183 
1184  // Postconditions:
1185 
1186  ensure(result >= 0);
1187 
1188  // Exit:
1189 
1190  return result;
1191 }
1192 
1196 {
1197  // Preconditions:
1198 
1199  // Body:
1200 
1201  size_type result = sheaf::deep_size(iterators(), true);
1202 
1203  // Postconditions:
1204 
1205  ensure(result >= 0);
1206 
1207  // Exit:
1208 
1209  return result;
1210 }
1211 
1215 {
1216  // Preconditions:
1217 
1218  // Body:
1219 
1220  list_index_space_iterator& result = iterators().get();
1221  attach(result);
1222 
1223  // Postconditions:
1224 
1225  ensure(result.is_attached());
1226 
1227  // Exit:
1228 
1229  return result;
1230 }
1231 
1232 void
1235 {
1236  // Preconditions:
1237 
1238  require(allocated_iterator(xitr));
1239 
1240  // Body:
1241 
1242  // Detach the iterator.
1243 
1244  xitr.detach();
1245 
1246  // Release the iterator to the pool.
1247 
1248  iterators().release(reinterpret_cast<list_index_space_iterator&>(xitr));
1249 
1250  // Postconditions:
1251 
1252  ensure(is_basic_query);
1253 
1254  // Exit:
1255 
1256  return;
1257 }
1258 
1259 bool
1262 {
1263  // Preconditions:
1264 
1265  // Body:
1266 
1267  const list_index_space_iterator* litr =
1268  dynamic_cast<const list_index_space_iterator*>(&xitr);
1269 
1270  bool result = (litr != 0) && iterators().allocated(*litr);
1271 
1272  // Postconditions:
1273 
1274  ensure(is_basic_query);
1275 
1276  // Exit:
1277 
1278  return result;
1279 }
1280 
1281 // PROTECTED MEMBER FUNCTIONS
1282 
1283 // PRIVATE MEMBER FUNCTIONS
1284 
1286 sheaf::list_index_space_state::
1287 iterators()
1288 {
1289  // Preconditions:
1290 
1291  // Body:
1292 
1294 
1295  // Postconditions:
1296 
1297  ensure(is_basic_query);
1298 
1299  // Exit:
1300 
1301  return result;
1302 }
1303 
1304 
1305 // ===========================================================
1306 // FACTORY FACET
1307 // ===========================================================
1308 
1309 // PUBLIC MEMBER FUNCTIONS
1310 
1311 const std::string&
1313 class_name() const
1314 {
1315  static const std::string result("list_index_space_state");
1316  return result;
1317 }
1318 
1321 clone() const
1322 {
1323  // Preconditions:
1324 
1325  // Body:
1326 
1328 
1329  // Postconditions:
1330 
1331  ensure(result != 0);
1332  ensure(is_same_type(result));
1333 
1334  // Exit:
1335 
1336  return result;
1337 }
1338 
1339 // PROTECTED MEMBER FUNCTIONS
1340 
1341 // PRIVATE MEMBER FUNCTIONS
1342 
1343 bool
1344 sheaf::list_index_space_state::
1345 make_prototype()
1346 {
1347  // Preconditions:
1348 
1349  // Body:
1350 
1352 
1353  id_space_factory().insert_prototype(lproto);
1354 
1355  // Postconditions:
1356 
1357  // Exit:
1358 
1359  return true;
1360 }
1361 
1362 
1363 // ===========================================================
1364 // ANY FACET
1365 // ===========================================================
1366 
1367 // PUBLIC MEMBER FUNCTIONS
1368 
1369 bool
1371 is_ancestor_of(const any *other) const
1372 {
1373  // Preconditions:
1374 
1375  require(other != 0);
1376 
1377  // Body:
1378 
1379  // True if other conforms to this
1380 
1381  bool result = dynamic_cast<const list_index_space_state*>(other) != 0;
1382 
1383  // Postconditions:
1384 
1385  // Exit:
1386 
1387  return result;
1388 }
1389 
1390 bool
1392 invariant() const
1393 {
1394  bool result = true;
1395 
1396  if(invariant_check())
1397  {
1398  // Prevent recursive calls to invariant
1399 
1401 
1402  // Must satisfy base class invariant
1403 
1405 
1406  // Invariances for this class:
1407 
1408  invariance(is_valid(begin()) == is_valid(end()));
1409  invariance((begin() == 0) || !is_valid(begin()));
1410 
1411  // Finished, turn invariant checking back on.
1412 
1414  }
1415 
1416  // Exit
1417 
1418  return result;
1419 }
1420 
1421 // PROTECTED MEMBER FUNCTIONS
1422 
1423 // PRIVATE MEMBER FUNCTIONS
1424 
1425 
1426 // ===========================================================
1427 // NON-MEMBER FUNCTIONS
1428 // ===========================================================
1429 
1430 size_t
1431 sheaf::
1432 deep_size(const list_index_space_state& xn, bool xinclude_shallow)
1433 {
1434  // Preconditions:
1435 
1436  // Body:
1437 
1438  size_t result = xinclude_shallow ? sizeof(xn) : 0;
1439 
1440  // Add any contributions from the parent class.
1441 
1443  result += deep_size(ixn, false);
1444 
1445  // Add contribution from list<pod_type> _to_range.
1446 
1447  result += deep_size(xn._to_range, false);
1448 
1449  // Postconditions:
1450 
1451  ensure(result >= 0);
1452 
1453  // Exit
1454 
1455  return result;
1456 }
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...
virtual pod_type pod(pod_type xid) const
The pod index in this space equivalent to xid in the hub id space.
std::list< pod_type > to_range_type
The type of the domain id to range id map.
size_type ct() const
The number of members.
virtual pod_type index() const
Index of this space.
virtual const std::string & class_name() const
The name of this class.
An abstract iterator over the ids of an id space.
virtual list_index_space_state * clone() const
Virtual constructor; create a new instance of the same type at this.
virtual index_space_iterator & get_iterator() const
Allocates an id space iterator from the iterator pool.
virtual ~list_index_space_state()
Destructor.
pod_type end() const
Ending id of this space.
virtual index_space_handle & get_id_space() const
The id space handle with this state.
pod_type pod() const
The current id in the iteration.
An list implementation of class gathered_insertion_index_space_state. This representation is intended...
virtual pod_type unglued_hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual bool is_persistent() const
True if this id space should be written to disk.
list_index_space_state()
Default constructor.
static list_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent)
Create a new list id space in the id space family xid_space at the next available id space index with...
static size_type iterator_pool_deep_size()
The deep size of the iterator pool.
virtual void map_rep_push(index_space_iterator &xitr, pod_type xrange_id)
Inserts entry (xitr.pod(), xrange_id) into the map representation. Increments all domain ids greater ...
An map implementation of class scattered_insertion_index_space_handle. This representation is intende...
to_range_type & to_range()
The representation of the domain id to range id map. Warning: direct manipulation of the to_range map...
to_range_type _to_range
The representation of the domain id to range id map.
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 const index_space_family & id_spaces() const
The id space family for this (const version).
virtual bool allocated_iterator(const index_space_iterator &xitr) const
True if and only if id space iterator xitr was allocated by the iterator pool.
virtual void detach()=0
Detach this handle form its state, if any.
pod_type back() const
The back of the list used to represent this id space; equivalent to hub_pod(last id).
void attach(explicit_index_space_handle &xid_space) const
Attach the id space handle xid_space to this state.
static size_type iterator_pool_ct()
The number of iterators in the pool.
pod_type _end
Ending id of this space.
pod_type _capacity
The capacity of this map.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual list_index_space_state & operator=(const explicit_index_space_state &xother)
Assignment operator.
to_range_type::const_iterator to_range_const_itr(pod_type xid, bool xis_range_id) const
A const_iterator pointing to the _to_range entry with range id (xis_range_id true) or domain id (xis_...
virtual bool invariant() const
Class invariant.
pod_type front() const
The front of the list used to represent this id space; equivalent to hub_pod(begin()).
bool is_done() const
True if iteration is finished.
virtual void reserve(size_type xcapacity)
Reserve enough memory for xcapacity number of ids.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
virtual void release_id_space(index_space_handle &xid_space) const
Release the id space handle xid_space.
virtual void map_rep_gather()
Gathers the map representation into an interval.
std::string name() const
Name of this space.
An iterator over an id space in which the equivalence between the ids in the space and the hub id spa...
pod_type begin() const
Beginning id of this space.
friend SHEAF_DLL_SPEC size_t deep_size(const list_index_space_state &xn, bool xinclude_shallow)
The deep size of list_index_space_state& xn.
virtual bool is_attached() const
True if this handle is attached to a state.
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 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...
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
bool is_explicit_interval(pod_type xid)
True, if and only if the id space interval that contains index xid is an explicit interval...
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 is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual size_type map_rep_remove_entry(pod_type xid, bool xis_range_id)
Removes the entry containing range id xid (xis_range_id true) or domain id xid (xis_range_id false) f...
void push_front(pod_type xhub_id)
Pushes hub id xhub_id onto the front of the list used to represent this id space; increments the doma...
to_range_type::iterator to_range_itr(pod_type xid, bool xis_range_id)
An iterator pointing to the _to_range entry with range id (xis_range_id true) or domain id (xis_range...
virtual bool contains_unglued_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space.
virtual void map_rep_push_back(pod_type xrange_id)
Inserts entry (next_id(), xrange_id) into the map representation.
size_type capacity() const
The number of ids reserved in memory.
static size_type handle_pool_deep_size()
The deep size of the handle pool.
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 contains(pod_type xid) const
True if this space contains id xid.
size_type _ct
The number of members.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
pod_index_type pod_type
The "plain old data" index type for this.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual size_type capacity() const
The number of ids reserved in memory.
void replace_range_id(pod_type xold_range_id, pod_type xnew_range_id)
Replaces xold_range_id with xnew_range_id.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
bool is_empty() const
True if there are no ids in the space.
Factory and container for a family of id spaces.
An implementation of class explicit_index_space_state that supports gathered insertion of new members...
void reverse(bool xupdate_extrema)
Reverse the order, for instance hub_pod(new 0) = hub_pod(old last);.
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
static factory< explicit_index_space_state > & id_space_factory()
A factory for making descendants of this class.
pod_type _begin
Beginning id of this space.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
pod_type next_id() const
The id inserted by the next call to push_back.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
static size_type handle_pool_ct()
The number of handles in the pool.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
to_hub_type::iterator _itr
The stl iterator over ids.
virtual bool is_attached() const
True if this iterator is attached to a state.
virtual void release_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
pod_type hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space. synonym for unglued_hub...
A reallocated pool of objects of type T. Objects in the pool are either allocated or stored in a free...
Definition: list_pool.h:42
virtual void map_rep_clear()
Removes all entrires from the map representation.
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().
virtual void update_extrema()
Update the id extrema.