SheafSystem  0.0.0.0
index_space_family.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/index_space_family.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/explicit_index_space_interval.h"
24 #include "SheafSystem/hub_index_space_handle.h"
25 #include "SheafSystem/index_equivalence_iterator.h"
26 #include "SheafSystem/index_space_family_iterator.h"
27 #include "SheafSystem/index_space_interval_iterator.h"
28 #include "SheafSystem/index_space_iterator.h"
29 #include "SheafSystem/interval_index_space_state.h"
30 #include "SheafSystem/scattered_insertion_index_space_handle.h"
31 #include "SheafSystem/poset_path.h"
32 #include "SheafSystem/primary_index_space_handle.h"
33 #include "SheafSystem/primary_sum_index_space_state.h"
34 #include "SheafSystem/scoped_index.h"
35 #include "SheafSystem/std_iomanip.h"
36 #include "SheafSystem/std_set.h"
37 
38 using namespace std;
39 
40 // ===========================================================
41 // INDEX_SPACE_FAMILY FACET
42 // ===========================================================
43 
44 // PUBLIC MEMBER FUNCTIONS
45 
48  : _end(0),
49  _standard_end(0),
50  _explicit_interval(0),
51  _next_explicit_id(0)
52 {
53  // Preconditions:
54 
55  // Body:
56 
57  // Create the primary sum id space state.
58 
60  primary_sum_index_space_state::new_space(const_cast<index_space_family&>(*this),
62 
63  // Postconditions:
64 
65  ensure(invariant());
66 
67  // Exit:
68 
69  return;
70 }
71 
74 {
75  // Preconditions:
76 
77  // Body:
78 
79  // Delete the intervals.
80 
81  interval_map_type::iterator litr = _intervals.begin();
82 
83  while(litr != _intervals.end())
84  {
85  index_space_interval* linterval = litr->second;
86  ++litr;
87 
88  if(linterval != 0)
89  {
90  delete linterval;
91  }
92  }
93 
94  // Postconditions:
95 
96  // Exit:
97 
98  return;
99 }
100 
101 std::string
103 name(pod_type xid) const
104 {
105  // Preconditions:
106 
107  // Body:
108 
109  string result = _name_to_index.name(xid);
110 
111  // Postconditions:
112 
113  ensure(result.empty() || contains(result));
114 
115  // Exit:
116 
117  return result;
118 }
119 
122 index(const std::string& xname) const
123 {
124  // Preconditions:
125 
126  require(!xname.empty());
127 
128  // Body:
129 
130  pod_type result = _name_to_index.index(xname);
131 
132  // Postconditions:
133 
134  ensure(!is_valid(result) || contains(result));
135 
136  // Exit:
137 
138  return result;
139 }
140 
141 void
143 put_name(pod_type xid, const std::string& xname)
144 {
145  // Preconditions:
146 
147  require(contains(xid));
148  require(!contains(xname));
149 
150  // Body:
151 
152  _name_to_index.put_entry(xid, xname, false);
153 
154  // Postconditions:
155 
156  ensure(contains(xname));
157 
158  // Exit:
159 
160  return;
161 }
162 
163 bool
165 contains(pod_type xid) const
166 {
167  // Preconditions:
168 
169  // Body:
170 
171  const index_space_collection* lcollection = collection(xid);
172 
173  bool result = (lcollection != 0) && lcollection->contains_family(xid);
174 
175  // Postconditions:
176 
177  ensure(is_basic_query);
178 
179  // Exit:
180 
181  return result;
182 }
183 
184 bool
186 contains(const std::string& xname) const
187 {
188  // Preconditions:
189 
190  // Body:
191 
192  pod_type lid = _name_to_index.index(xname);
193 
194  bool result = is_valid(lid) ? contains(lid) : false;
195 
196  // Postconditions:
197 
198  ensure(is_basic_query);
199 
200  // Exit:
201 
202  return result;
203 }
204 
207 begin() const
208 {
209  // Preconditions:
210 
211  // Body:
212 
213  pod_type result = 0;
214 
215  // Postconditions:
216 
217  ensure(is_basic_query);
218 
219  // Exit:
220 
221  return result;
222 }
223 
226 end() const
227 {
228  // Preconditions:
229 
230  // Body:
231 
232  pod_type result = _end;
233 
234  // Postconditions:
235 
236  ensure(is_basic_query);
237 
238  // Exit:
239 
240  return result;
241 }
242 
243 bool
246 {
247  // Preconditions:
248 
249  // Body:
250 
251  bool result = (_standard_end == _end);
252 
253  // Postconditions:
254 
255  ensure(is_basic_query);
256 
257  // Exit:
258 
259  return result;
260 }
261 
262 void
265 {
266  // Preconditions:
267 
268  // Body:
269 
272 
273  // Postconditions:
274 
275  ensure(has_only_standard_id_spaces());
276  ensure(hub_id_space().has_only_standard_ids());
277 
278  // Exit:
279 
280  return;
281 }
282 
283 void
286 {
287  // Preconditions:
288 
289  // Body:
290 
291  // Remove non-standard id spaces.
292 
293  interval_map_type::iterator itr = _intervals.begin();
294  while(itr != _intervals.end())
295  {
296  index_space_interval* linterval = itr->second;
297  interval_map_type::iterator old_itr = itr;
298 
299  // Increment to next interval.
300 
301  itr++;
302 
303  if(linterval != 0)
304  {
305  // Check the interval.
306 
307  if(linterval->begin() >= _standard_end)
308  {
309  // Interval is completely outside the standard id spaces, delete it.
310 
311  _intervals.erase(old_itr);
312  delete linterval;
313  }
314  else if((linterval->begin() < _standard_end) &&
315  (linterval->end() > _standard_end))
316  {
317  // Interval is partly outside the standard id spaces.
318 
319  assertion(dynamic_cast<explicit_index_space_interval*>(linterval) != 0);
320 
321  for(pod_type i=_standard_end; i<linterval->end(); ++i)
322  {
323  linterval->remove(linterval->local_scope(i));
324  }
325  }
326  else
327  {
328  // Interval complete inside the standard id spaces, do nothing.
329  }
330  }
331  }
332 
333  // Update the end id space.
334 
336 
337  // Remove non-standard ids from primary sum id space.
338 
340 
341  // Postconditions:
342 
343  ensure(invariant());
344  ensure(has_only_standard_id_spaces());
345  ensure(hub_id_space().has_only_standard_ids());
346 
347  // Exit:
348 
349  return;
350 }
351 
355 {
356  // Preconditions:
357 
358  // Body:
359 
360  static size_type result = 300;
361 
362  // Postconditions:
363 
364  // Exit:
365 
366  return result;
367 }
368 
369 // PROTECTED MEMBER FUNCTIONS
370 
371 // PRIVATE MEMBER FUNCTIONS
372 
373 
374 // ===========================================================
375 // STATE FACET
376 // ===========================================================
377 
378 // PUBLIC MEMBER FUNCTIONS
379 
380 void
383 {
384  // Preconditions:
385 
386  require(xid != hub_id_space().index());
387  require(contains(xid) ? !handle_conforms_to_state<primary_index_space_handle>(xid) : true);
388 
389  // Body:
390 
391  if(contains(xid))
392  {
393  if(is_explicit_interval(xid))
394  {
395  // The id space is explicit; delete the state object.
396 
397  delete_state(xid);
398  }
399  else
400  {
401  // The id space is implicit; delete the interval.
402 
403  delete_interval(xid);
404  }
405  }
406 
407  // Postconditions:
408 
409  ensure(invariant());
410  ensure(!contains(xid));
411 
412  // Exit:
413 
414  return;
415 }
416 
417 void
419 delete_space(const std::string& xname)
420 {
421  // Preconditions:
422 
423  require(xname != hub_id_space_name());
424  require(contains(xname) ? !handle_conforms_to_state<primary_index_space_handle>(xname) : true);
425 
426  // Body:
427 
428  if(_name_to_index.contains_name(xname))
429  {
431  }
432 
433  // Postconditions:
434 
435  ensure(invariant());
436  ensure(!contains(xname));
437 
438  // Exit:
439 
440  return;
441 }
442 
443 bool
446 {
447  // Preconditions:
448 
449  // Body:
450 
451  bool result =
452  (dynamic_cast<explicit_index_space_interval*>(collection(xid)) != 0);
453 
454  // Postconditions:
455 
456  ensure(is_basic_query);
457 
458  // Exit:
459 
460  return result;
461 }
462 
463 // PROTECTED MEMBER FUNCTIONS
464 
468 {
469  // Preconditions:
470 
471  // Body:
472 
474 
475  // Postconditions:
476 
477  ensure(invariant());
478  ensure(contains(result));
479 
480  // Exit:
481 
482  return result;
483 }
484 
488 {
489  // Preconditions:
490 
491  // Body:
492 
493  pod_type result = _hub_id_space.new_primary_term(xid, xct);
494 
495  // Postconditions:
496 
497  ensure(invariant());
498  ensure(contains(result));
499 
500  // Exit:
501 
502  return result;
503 }
504 
505 void
508 {
509  // Preconditions:
510 
511  require(xid != hub_id_space().index());
512  require(contains(xid));
513  require(handle_conforms_to_state<primary_index_space_handle>(xid));
514 
515  // Body:
516 
517  // Remove the term from the hub id space..
518 
520  get_id_space<primary_index_space_handle>(xid);
521 
523 
524  // Delete the state.
525 
526  delete_state(xid);
527 
528  // Postconditions:
529 
530  ensure(invariant());
531  ensure(!contains(xid));
532 
533  // Exit:
534 
535  return;
536 }
537 
538 void
540 new_state(const std::string& xname,
541  const std::string& xstate_class_name)
542 {
543  // Preconditions:
544 
545  require(!xname.empty());
546  require(!contains(xname));
547  require(!xstate_class_name.empty());
548  require(explicit_index_space_state::id_space_factory().contains_prototype(xstate_class_name));
549 
551  require(unexecutable("xstate_class_name is a mutable id space state"));
552 
553  // Body:
554 
556  explicit_index_space_state::id_space_factory().new_instance(xstate_class_name);
557 
558  lstate->new_state(const_cast<index_space_family&>(*this), xname, true);
559 
560  // Postconditions:
561 
562  ensure(invariant());
563  ensure(contains(xname));
564 
566  ensure(handle_conforms_to_state<scattered_insertion_index_space_handle>(xname));
567 
568  // Exit:
569 
570  return;
571 }
572 
573 void
576 {
577  // Preconditions:
578 
579  // Body:
580 
581  index_space_collection* lcollection = collection(xid);
582 
583  if(lcollection != 0)
584  {
585  pod_type local_id = lcollection->local_scope(xid);
586 
587  // Get the explicit state.
588 
589  explicit_index_space_state* lstate = lcollection->explicit_state(local_id);
590 
591  // Remove the state from the collection.
592 
593  lcollection->remove(local_id);
594 
595  // Delete the explicit state, if there is one.
596 
597  if(lstate != 0)
598  {
599  delete lstate;
600  }
601  }
602 
603  // Delete the names.
604 
606  {
608  }
609 
610  // Postconditions:
611 
612  ensure(invariant());
613  ensure(!contains(xid));
614 
615  // Exit:
616 
617  return;
618 }
619 
620 void
623 {
624  // Preconditions:
625 
626  require(xinterval.begin() == end());
627 
628  // Body:
629 
630  // Insert interval into the map.
631 
632  _intervals[xinterval.end()] = &xinterval;
633 
634  if(_intervals.find(xinterval.begin()) == _intervals.end())
635  {
636  // The beginning of the interval is not the end of some other
637  // interval.
638 
639  _intervals[xinterval.begin()] = 0;
640  }
641 
642  // Update the end of ths family.
643 
644  _end = xinterval.end();
645 
646  // Postconditions:
647 
648  // Exit:
649 
650  return;
651 }
652 
653 void
656 {
657  // Preconditions:
658 
659  require(xid != hub_id_space().index());
660  require(!contains(xid) || !handle_conforms_to_state<primary_index_space_handle>(xid));
661 
662  // Body:
663 
664  if(contains(xid))
665  {
666  interval_iterator_type litr = _intervals.upper_bound(xid);
667  pod_type lend = litr->first;
668 
669  index_space_interval* linterval = litr->second;
670 
671  interval_iterator_type lprevious = litr;
672  lprevious--;
673  pod_type lbegin = lprevious->first;
674 
675  interval_iterator_type lnext = litr;
676  lnext++;
677 
678  if(!lprevious->second)
679  {
680  if((lnext == _intervals.end()) || (!lnext->second))
681  {
682  // Remove previous so that no void value is at the end or
683  // back-to-back void values.
684 
685  _intervals.erase(litr);
686  _intervals.erase(lprevious);
687  }
688  else
689  {
690  // Adjust the void value to be the beginning of the next.
691 
692  _intervals[lend] = 0;
693  _intervals.erase(lprevious);
694  }
695  }
696  else
697  {
698  if((lnext == _intervals.end()) || (!lnext->second))
699  {
700  // The void value is in the correct spot, erase current entry.
701 
702  _intervals.erase(litr);
703  }
704  else
705  {
706  // A void value needs inserted at the current entry.
707 
708  _intervals[lend] = 0;
709  }
710  }
711 
712  // Update the end.
713 
714  if(lend == _end)
715  {
716  // There should always be an interval.
717 
718  assertion(_intervals.begin() != _intervals.end());
719 
720  _end = (--_intervals.end())->first;
721  }
722 
723  // Delete the interval.
724 
725  if(linterval != 0)
726  {
727  delete linterval;
728  }
729  }
730 
731  // Postconditions:
732 
733  ensure(invariant());
734  ensure(!contains(xid));
735 
736  // Exit:
737 
738  return;
739 }
740 
744 {
745  // Preconditions:
746 
747  // Body:
748 
749  const_interval_iterator_type litr = _intervals.upper_bound(xid);
750 
751  const index_space_collection* result =
752  (litr != _intervals.end()) ? litr->second : 0;
753 
754  // Postconditions:
755 
756  ensure(is_basic_query);
757 
758  // Exit:
759 
760  return result;
761 }
762 
766 {
767  // Preconditions:
768 
769  // Body:
770 
771  const_interval_iterator_type litr = _intervals.upper_bound(xid);
772 
773  index_space_collection* result =
774  (litr != _intervals.end()) ? litr->second : 0;
775 
776  // Postconditions:
777 
778  ensure(is_basic_query);
779 
780  // Exit:
781 
782  return result;
783 }
784 
788 {
789  // Preconditions:
790 
791  // Body:
792 
793  define_old_variable(pod_type old_next_explicit_id = _next_explicit_id);
794 
795  // Find the explicit id space interval.
796 
797  if((_explicit_interval == 0) ||
799  {
800  // Construct a new explicit id space interval.
801 
804 
806  }
807 
808  pod_type result = _next_explicit_id;
809 
810  // Increment the next explicit id.
811 
813 
814  // Postconditions:
815 
816  ensure(is_explicit_interval(result));
817 
818  // Exit:
819 
820  return result;
821 }
822 
826 {
827  return EXPLICIT_INTERVAL_SIZE;
828 }
829 
830 // PRIVATE MEMBER FUNCTIONS
831 
832 
833 // ===========================================================
834 // HUB ID SPACE FACET
835 // ===========================================================
836 
837 // PUBLIC MEMBER FUNCTIONS
838 
842 {
843  // Preconditions:
844 
845  // Body:
846 
848 
849  // Postconditions:
850 
851  ensure(hub_id_space().contains(result));
852 
853  // Exit:
854 
855  return result;
856 }
857 
861 {
862  // Preconditions:
863 
864  require(is_valid_reserved_id(xid));
865 
866  // Body:
867 
868  _hub_id_space.new_id(xid);
869 
870  // Postconditions:
871 
872  ensure(hub_id_space().contains(xid));
873 
874  // Exit:
875 
876  return xid;
877 }
878 
879 void
882 {
883  // Preconditions:
884 
885  // Body:
886 
888 
889  // Postconditions:
890 
891  ensure(!hub_id_space().contains(xid));
892 
893  // Exit:
894 
895  return;
896 }
897 
901 {
902  // Preconditions:
903 
904  // Body:
905 
906  const hub_index_space_handle& result = _hub_id_space;
907 
908  // Postconditions:
909 
910  ensure(is_basic_query);
911 
912  // Exit:
913 
914  return result;
915 }
916 
919 new_gathered_hub_id_space(bool xexclude_bottom)
920 {
921  // Preconditions:
922 
923  require(!has_gathered_hub_id_space());
924 
925  // Body:
926 
927  const index_space_handle& result =
928  _hub_id_space.new_gathered_id_space(xexclude_bottom);
929 
930  // Postconditions:
931 
932  ensure(has_gathered_hub_id_space());
934  ensure(xexclude_bottom == gathered_hub_id_space_excludes_bottom());
935 
936  // Exit:
937 
938  return result;
939 }
940 
941 void
944 {
945  // Preconditions:
946 
947  require(has_gathered_hub_id_space());
948 
949  // Body:
950 
952 
953  // Postconditions:
954 
956 
957  // Exit:
958 
959  return;
960 }
961 
965 {
966  // Preconditions:
967 
968  require(has_gathered_hub_id_space());
969 
970  // Body:
971 
972  const index_space_handle& result =
974 
975  // Postconditions:
976 
977  ensure(is_basic_query);
978 
979  // Exit:
980 
981  return result;
982 }
983 
984 bool
987 {
988  // Preconditions:
989 
990  // Body:
991 
992  bool result = _hub_id_space.has_gathered_id_space();
993 
994  // Postconditions:
995 
996  ensure(is_basic_query);
997 
998  // Exit:
999 
1000  return result;
1001 }
1002 
1003 bool
1006 {
1007  // Preconditions:
1008 
1009  // Body:
1010 
1012 
1013  // Postconditions:
1014 
1015  ensure(is_basic_query);
1016 
1017  // Exit:
1018 
1019  return result;
1020 }
1021 
1022 const std::string&
1025 {
1026  // Preconditions:
1027 
1028  // Body:
1029 
1030  static const std::string result(poset_path::reserved_prefix() + "hub");
1031 
1032  // Postconditions:
1033 
1034  ensure(is_basic_query);
1035 
1036  // Exit:
1037 
1038  return result;
1039 }
1040 
1041 bool
1044 {
1045  // Preconditions:
1046 
1047  // Body:
1048 
1049  bool result = _hub_id_space.is_valid_reserved_id(xid);
1050 
1051  // Postconditions:
1052 
1053  ensure(is_basic_query);
1054 
1055  // Exit:
1056 
1057  return result;
1058 }
1059 
1062 term_of(pod_type xid) const
1063 {
1064  // Preconditions:
1065 
1066  // Body:
1067 
1068  const index_space_handle& result = _hub_id_space.term_of(xid);
1069 
1070  // Postconditions:
1071 
1072  ensure(is_basic_query);
1073 
1074  // Exit:
1075 
1076  return result;
1077 }
1078 
1081 term_of(const scoped_index& xid) const
1082 {
1083  // Preconditions:
1084 
1085  // Body:
1086 
1087  const index_space_handle& result = _hub_id_space.term_of(xid);
1088 
1089  // Postconditions:
1090 
1091  ensure(is_basic_query);
1092 
1093  // Exit:
1094 
1095  return result;
1096 }
1097 
1100 last_term() const
1101 {
1102  // Preconditions:
1103 
1104  require(!hub_id_space().is_empty());
1105 
1106  // Body:
1107 
1108  const index_space_handle& result = _hub_id_space.last_term();
1109 
1110  // Postconditions:
1111 
1112  ensure(is_basic_query);
1113 
1114  // Exit:
1115 
1116  return result;
1117 }
1118 
1119 void
1122 {
1123  // Preconditions:
1124 
1125  require(!hub_id_space().is_empty());
1126 
1127  // Body:
1128 
1129  define_old_variable(scoped_index old_last_term_begin(last_term(), last_term().begin()));
1130 
1131  // Extend the last term.
1132 
1134 
1135  // Postconditions:
1136 
1137  ensure_for_range(scoped_index i=old_last_term_begin, i<old_last_term_begin+xct, ++i, i.in_scope());
1138 
1139  // Exit:
1140 
1141  return;
1142 }
1143 
1144 // PROTECTED MEMBER FUNCTIONS
1145 
1146 // PRIVATE MEMBER FUNCTIONS
1147 
1148 
1149 // ===========================================================
1150 // INDEX SPACE FACET
1151 // ===========================================================
1152 
1153 // PUBLIC MEMBER FUNCTIONS
1154 
1157 ct(const std::string& xname) const
1158 {
1159  // Preconditions:
1160 
1161  require(contains(xname));
1162 
1163  // Body:
1164 
1165  size_type result = ct(_name_to_index.index(xname));
1166 
1167  // Postconditions:
1168 
1169  ensure(is_basic_query);
1170 
1171  // Exit:
1172 
1173  return result;
1174 }
1175 
1178 ct(pod_type xspace_id) const
1179 {
1180  // Preconditions:
1181 
1182  require(contains(xspace_id));
1183 
1184  // Body:
1185 
1186  const index_space_collection* lcollection = collection(xspace_id);
1187  pod_type local_id = lcollection->local_scope(xspace_id);
1188 
1189  size_type result = lcollection->ct(local_id);
1190 
1191  // Postconditions:
1192 
1193  ensure(is_basic_query);
1194 
1195  // Exit:
1196 
1197  return result;
1198 }
1199 
1200 bool
1202 is_empty(const std::string& xname) const
1203 {
1204  // Preconditions:
1205 
1206  require(contains(xname));
1207 
1208  // Body:
1209 
1210  bool result = is_empty(_name_to_index.index(xname));
1211 
1212  // Postconditions:
1213 
1214  ensure(is_basic_query);
1215 
1216  // Exit:
1217 
1218  return result;
1219 }
1220 
1221 bool
1223 is_empty(pod_type xspace_id) const
1224 {
1225  // Preconditions:
1226 
1227  require(contains(xspace_id));
1228 
1229  // Body:
1230 
1231  bool result = (ct(xspace_id) == 0);
1232 
1233  // Postconditions:
1234 
1235  ensure(is_basic_query);
1236 
1237  // Exit:
1238 
1239  return result;
1240 }
1241 
1244 begin(const std::string& xname) const
1245 {
1246  // Preconditions:
1247 
1248  require(contains(xname));
1249 
1250  // Body:
1251 
1252  pod_type result = begin(_name_to_index.index(xname));
1253 
1254  // Postconditions:
1255 
1256  ensure(is_basic_query);
1257 
1258  // Exit:
1259 
1260  return result;
1261 }
1262 
1265 begin(pod_type xspace_id) const
1266 {
1267  // Preconditions:
1268 
1269  require(contains(xspace_id));
1270 
1271  // Body:
1272 
1273  const index_space_collection* lcollection = collection(xspace_id);
1274  pod_type local_id = lcollection->local_scope(xspace_id);
1275 
1276  pod_type result = lcollection->begin(local_id);
1277 
1278  // Postconditions:
1279 
1280  ensure(is_basic_query);
1281 
1282  // Exit:
1283 
1284  return result;
1285 }
1286 
1289 end(const std::string& xname) const
1290 {
1291  // Preconditions:
1292 
1293  require(contains(xname));
1294 
1295  // Body:
1296 
1297  pod_type result = end(_name_to_index.index(xname));
1298 
1299  // Postconditions:
1300 
1301  ensure(is_basic_query);
1302 
1303  // Exit:
1304 
1305  return result;
1306 }
1307 
1310 end(pod_type xspace_id) const
1311 {
1312  // Preconditions:
1313 
1314  require(contains(xspace_id));
1315 
1316  // Body:
1317 
1318  const index_space_collection* lcollection = collection(xspace_id);
1319  pod_type local_id = lcollection->local_scope(xspace_id);
1320 
1321  pod_type result = lcollection->end(local_id);
1322 
1323  // Postconditions:
1324 
1325  ensure(is_basic_query);
1326 
1327  // Exit:
1328 
1329  return result;
1330 }
1331 
1334 hub_begin(const std::string& xname) const
1335 {
1336  // Preconditions:
1337 
1338  require(contains(xname));
1339 
1340  // Body:
1341 
1342  pod_type result = hub_begin(_name_to_index.index(xname));
1343 
1344  // Postconditions:
1345 
1346  ensure(is_basic_query);
1347 
1348  // Exit:
1349 
1350  return result;
1351 }
1352 
1355 hub_begin(pod_type xspace_id) const
1356 {
1357  // Preconditions:
1358 
1359  require(contains(xspace_id));
1360 
1361  // Body:
1362 
1363  const index_space_collection* lcollection = collection(xspace_id);
1364  pod_type local_id = lcollection->local_scope(xspace_id);
1365 
1366  pod_type result = lcollection->hub_pod(local_id, lcollection->begin(local_id));
1367 
1368  // Postconditions:
1369 
1370  ensure(is_basic_query);
1371 
1372  // Exit:
1373 
1374  return result;
1375 }
1376 
1377 bool
1379 is_gathered(const std::string& xname) const
1380 {
1381  // Preconditions:
1382 
1383  require(contains(xname));
1384 
1385  // Body:
1386 
1387  bool result = is_gathered(_name_to_index.index(xname));
1388 
1389  // Postconditions:
1390 
1391  ensure(is_basic_query);
1392 
1393  // Exit:
1394 
1395  return result;
1396 }
1397 
1398 bool
1400 is_gathered(pod_type xspace_id) const
1401 {
1402  // Preconditions:
1403 
1404  require(contains(xspace_id));
1405 
1406  // Body:
1407 
1408  bool result = (begin(xspace_id) == 0) && (end(xspace_id) == ct(xspace_id));
1409 
1410  // Postconditions:
1411 
1412  ensure(is_basic_query);
1413 
1414  // Exit:
1415 
1416  return result;
1417 }
1418 
1419 bool
1421 contains(const std::string& xname, pod_type xid) const
1422 {
1423  // Preconditions:
1424 
1425  require(contains(xname));
1426 
1427  // Body:
1428 
1429  bool result = contains(_name_to_index.index(xname), xid);
1430 
1431  // Postconditions:
1432 
1433  ensure(is_basic_query);
1434 
1435  // Exit:
1436 
1437  return result;
1438 }
1439 
1440 bool
1442 contains(pod_type xspace_id, pod_type xid) const
1443 {
1444  // Preconditions:
1445 
1446  require(contains(xspace_id));
1447 
1448  // Body:
1449 
1450  const index_space_collection* lcollection = collection(xspace_id);
1451  pod_type local_id = lcollection->local_scope(xspace_id);
1452 
1453  bool result = lcollection->contains(local_id, xid);
1454 
1455  // Postconditions:
1456 
1457  ensure(is_basic_query);
1458 
1459  // Exit:
1460 
1461  return result;
1462 }
1463 
1464 bool
1466 contains(const std::string& xname, const scoped_index& xid) const
1467 {
1468  // Preconditions:
1469 
1470  require(contains(xname));
1471 
1472  // Body:
1473 
1474  bool result = contains_hub(_name_to_index.index(xname), xid.hub_pod());
1475 
1476  // Postconditions:
1477 
1478  ensure(is_basic_query);
1479 
1480  // Exit:
1481 
1482  return result;
1483 }
1484 
1485 bool
1487 contains(pod_type xspace_id, const scoped_index& xid) const
1488 {
1489  // Preconditions:
1490 
1491  require(contains(xspace_id));
1492 
1493  // Body:
1494 
1495  bool result = contains_hub(xspace_id, xid.hub_pod());
1496 
1497  // Postconditions:
1498 
1499  ensure(is_basic_query);
1500 
1501  // Exit:
1502 
1503  return result;
1504 }
1505 
1506 bool
1508 contains_hub(const std::string& xname, pod_type xid) const
1509 {
1510  // Preconditions:
1511 
1512  require(contains(xname));
1513 
1514  // Body:
1515 
1516  bool result = contains_unglued_hub(xname, xid);
1517 
1518  // Postconditions:
1519 
1520  ensure(is_basic_query);
1521 
1522  // Exit:
1523 
1524  return result;
1525 }
1526 
1527 bool
1529 contains_hub(pod_type xspace_id, pod_type xid) const
1530 {
1531  // Preconditions:
1532 
1533  require(contains(xspace_id));
1534 
1535  // Body:
1536 
1537  bool result = contains_unglued_hub(xspace_id, xid);
1538 
1539  // Postconditions:
1540 
1541  ensure(is_basic_query);
1542 
1543  // Exit:
1544 
1545  return result;
1546 }
1547 
1548 bool
1550 contains_unglued_hub(const std::string& xname, pod_type xid) const
1551 {
1552  // Preconditions:
1553 
1554  require(contains(xname));
1555 
1556  // Body:
1557 
1558  bool result = contains_unglued_hub(_name_to_index.index(xname), xid);
1559 
1560  // Postconditions:
1561 
1562  ensure(is_basic_query);
1563 
1564  // Exit:
1565 
1566  return result;
1567 }
1568 
1569 bool
1572 {
1573  // Preconditions:
1574 
1575  require(contains(xspace_id));
1576 
1577  // Body:
1578 
1579  const index_space_collection* lcollection = collection(xspace_id);
1580  pod_type local_id = lcollection->local_scope(xspace_id);
1581 
1582  bool result = lcollection->contains_unglued_hub(local_id, xid);
1583 
1584  // Postconditions:
1585 
1586  ensure(is_basic_query);
1587 
1588  // Exit:
1589 
1590  return result;
1591 }
1592 
1593 bool
1595 contains_glued_hub(const std::string& xname, pod_type xid) const
1596 {
1597  // Preconditions:
1598 
1599  require(contains(xname));
1600 
1601  // Body:
1602 
1603  bool result = contains_glued_hub(_name_to_index.index(xname), xid);
1604 
1605  // Postconditions:
1606 
1607  ensure(is_basic_query);
1608 
1609  // Exit:
1610 
1611  return result;
1612 }
1613 
1614 bool
1616 contains_glued_hub(pod_type xspace_id, pod_type xid) const
1617 {
1618  // Preconditions:
1619 
1620  require(contains(xspace_id));
1621 
1622  // Body:
1623 
1624  bool result =
1626 
1627  // Postconditions:
1628 
1629  ensure(is_basic_query);
1630 
1631  // Exit:
1632 
1633  return result;
1634 }
1635 
1636 bool
1638 contains(const std::string& xname, pod_type xid, const scoped_index& xhub_id) const
1639 {
1640  // Preconditions:
1641 
1642  require(contains(xname));
1643 
1644  // Body:
1645 
1646  bool result = contains(_name_to_index.index(xname), xid, xhub_id.hub_pod());
1647 
1648  // Postconditions:
1649 
1650  ensure(is_basic_query);
1651 
1652  // Exit:
1653 
1654  return result;
1655 }
1656 
1657 bool
1659 contains(pod_type xspace_id, pod_type xid, const scoped_index& xhub_id) const
1660 {
1661  // Preconditions:
1662 
1663  require(contains(xspace_id));
1664 
1665  // Body:
1666 
1667  bool result = contains(xspace_id, xid, xhub_id.hub_pod());
1668 
1669  // Postconditions:
1670 
1671  ensure(is_basic_query);
1672 
1673  // Exit:
1674 
1675  return result;
1676 }
1677 
1678 bool
1680 contains(const std::string& xname, pod_type xid, pod_type xhub_id) const
1681 {
1682  // Preconditions:
1683 
1684  require(contains(xname));
1685 
1686  // Body:
1687 
1688  bool result = contains(_name_to_index.index(xname), xid, xhub_id);
1689 
1690  // Postconditions:
1691 
1692  ensure(is_basic_query);
1693 
1694  // Exit:
1695 
1696  return result;
1697 }
1698 
1699 bool
1701 contains(pod_type xspace_id, pod_type xid, pod_type xhub_id) const
1702 {
1703  // Preconditions:
1704 
1705  require(contains(xspace_id));
1706 
1707  // Body:
1708 
1709  const index_space_collection* lcollection = collection(xspace_id);
1710  pod_type local_id = lcollection->local_scope(xspace_id);
1711 
1712  bool result = lcollection->contains(local_id, xid, xhub_id);
1713 
1714  // Postconditions:
1715 
1716  ensure(is_basic_query);
1717 
1718  // Exit:
1719 
1720  return result;
1721 }
1722 
1725 pod(const std::string& xname, pod_type xid) const
1726 {
1727  // Preconditions:
1728 
1729  require(contains(xname));
1730 
1731  // Body:
1732 
1733  pod_type result = pod(_name_to_index.index(xname), xid);
1734 
1735  // Postconditions:
1736 
1737  ensure(!is_valid(result) || contains(xname, result));
1738 
1739  // Exit:
1740 
1741  return result;
1742 }
1743 
1746 pod(pod_type xspace_id, pod_type xid) const
1747 {
1748  // Preconditions:
1749 
1750  require(contains(xspace_id));
1751 
1752  // Body:
1753 
1754  const index_space_collection* lcollection = collection(xspace_id);
1755  pod_type local_id = lcollection->local_scope(xspace_id);
1756 
1757  pod_type result = lcollection->pod(local_id, xid);
1758 
1759  // Postconditions:
1760 
1761  ensure(!is_valid(result) || contains(xspace_id, result));
1762 
1763  // Exit:
1764 
1765  return result;
1766 }
1767 
1770 pod(const std::string& xname, const scoped_index& xid) const
1771 {
1772  // Preconditions:
1773 
1774  require(contains(xname));
1775 
1776  // Body:
1777 
1778  pod_type result = pod(_name_to_index.index(xname), xid.hub_pod());
1779 
1780  // Postconditions:
1781 
1782  ensure(!is_valid(result) || contains(xname, result));
1783 
1784  // Exit:
1785 
1786  return result;
1787 }
1788 
1791 pod(pod_type xspace_id, const scoped_index& xid) const
1792 {
1793  // Preconditions:
1794 
1795  require(contains(xspace_id));
1796 
1797  // Body:
1798 
1799  pod_type result = pod(xspace_id, xid.hub_pod());
1800 
1801  // Postconditions:
1802 
1803  ensure(!is_valid(result) || contains(xspace_id, result));
1804 
1805  // Exit:
1806 
1807  return result;
1808 }
1809 
1812 hub_pod(const std::string& xname, pod_type xid) const
1813 {
1814  // Preconditions:
1815 
1816  require(contains(xname));
1817 
1818  // Body:
1819 
1820  pod_type result = unglued_hub_pod(xname, xid);
1821 
1822  // Postconditions:
1823 
1824  ensure(!is_valid(result) || contains_hub(xname, result));
1825 
1826  // Exit:
1827 
1828  return result;
1829 }
1830 
1833 hub_pod(pod_type xspace_id, pod_type xid) const
1834 {
1835  // Preconditions:
1836 
1837  require(contains(xspace_id));
1838 
1839  // Body:
1840 
1841  pod_type result = unglued_hub_pod(xspace_id, xid);
1842 
1843  // Postconditions:
1844 
1845  ensure(!is_valid(result) || contains_hub(xspace_id, result));
1846 
1847  // Exit:
1848 
1849  return result;
1850 }
1851 
1854 unglued_hub_pod(const std::string& xname, pod_type xid) const
1855 {
1856  // Preconditions:
1857 
1858  require(contains(xname));
1859 
1860  // Body:
1861 
1862  pod_type result = unglued_hub_pod(_name_to_index.index(xname), xid);
1863 
1864  // Postconditions:
1865 
1866  ensure(!is_valid(result) || contains_unglued_hub(xname, result));
1867 
1868  // Exit:
1869 
1870  return result;
1871 }
1872 
1875 unglued_hub_pod(pod_type xspace_id, pod_type xid) const
1876 {
1877  // Preconditions:
1878 
1879  require(contains(xspace_id));
1880 
1881  // Body:
1882 
1883  const index_space_collection* lcollection = collection(xspace_id);
1884  pod_type local_id = lcollection->local_scope(xspace_id);
1885 
1886  pod_type result = lcollection->hub_pod(local_id, xid);
1887 
1888  // Postconditions:
1889 
1890  ensure(!is_valid(result) || contains_unglued_hub(xspace_id, result));
1891 
1892  // Exit:
1893 
1894  return result;
1895 }
1896 
1899 glued_hub_pod(const std::string& xname, pod_type xid) const
1900 {
1901  // Preconditions:
1902 
1903  require(contains(xname));
1904 
1905  // Body:
1906 
1907  pod_type result = glued_hub_pod(_name_to_index.index(xname), xid);
1908 
1909  // Postconditions:
1910 
1911  ensure(!is_valid(result) || contains_glued_hub(xname, result));
1912 
1913  // Exit:
1914 
1915  return result;
1916 }
1917 
1920 glued_hub_pod(pod_type xspace_id, pod_type xid) const
1921 {
1922  // Preconditions:
1923 
1924  require(contains(xspace_id));
1925 
1926  // Body:
1927 
1928  pod_type result =
1929  hub_id_space().glued_hub_pod(unglued_hub_pod(xspace_id, xid));
1930 
1931  // Postconditions:
1932 
1933  ensure(!is_valid(result) || contains_glued_hub(xspace_id, result));
1934 
1935  // Exit:
1936 
1937  return result;
1938 }
1939 
1940 bool
1942 is_persistent(const std::string& xname) const
1943 {
1944  // Preconditions:
1945 
1946  require(contains(xname));
1947 
1948  // Body:
1949 
1950  bool result = is_persistent(_name_to_index.index(xname));
1951 
1952  // Postconditions:
1953 
1954  ensure(is_basic_query);
1955 
1956  // Exit:
1957 
1958  return result;
1959 }
1960 
1961 bool
1963 is_persistent(pod_type xspace_id) const
1964 {
1965  // Preconditions:
1966 
1967  require(contains(xspace_id));
1968 
1969  // Body:
1970 
1971  const index_space_collection* lcollection = collection(xspace_id);
1972  pod_type local_id = lcollection->local_scope(xspace_id);
1973 
1974  bool result = lcollection->is_persistent(local_id);
1975 
1976  // Postconditions:
1977 
1978  ensure(is_basic_query);
1979 
1980  // Exit:
1981 
1982  return result;
1983 }
1984 
1985 // PROTECTED MEMBER FUNCTIONS
1986 
1987 // PRIVATE MEMBER FUNCTIONS
1988 
1989 
1990 // ===========================================================
1991 // GLUING FACET
1992 // ===========================================================
1993 
1994 // PUBLIC MEMBER FUNCTIONS
1995 
1996 void
1999 {
2000  // Preconditions:
2001 
2002  require(hub_id_space().contains_unique_rep(xid)); // Can't already be glued.
2003  require(hub_id_space().contains_rep(xrep));
2004  require(hub_id_space().term_id(xid) > hub_id_space().term_id(xrep));
2005 
2006  // Body:
2007 
2008  _hub_id_space.glue(xid, xrep);
2009 
2010  // Postconditions:
2011 
2012  ensure(invariant());
2013  ensure(!hub_id_space().contains_rep(xid));
2014  ensure(hub_id_space().glued_hub_pod(xid) == xrep);
2015 
2016  // Exit:
2017 
2018  return;
2019 }
2020 
2021 void
2024 {
2025  // Preconditions:
2026 
2027  require(hub_id_space().contains(xid));
2028  require(!hub_id_space().contains_rep(xid));
2029 
2030  // Body:
2031 
2032  _hub_id_space.unglue(xid);
2033 
2034  // Postconditions:
2035 
2036  ensure(invariant());
2037  ensure(hub_id_space().contains_unique_rep(xid));
2038 
2039  // Exit:
2040 
2041  return;
2042 }
2043 
2044 void
2047 {
2048  // Preconditions:
2049 
2050  require(hub_id_space().contains_rep(xrep_id));
2051 
2052  // Body:
2053 
2054  _hub_id_space.unglue_all(xrep_id);
2055 
2056  // Postconditions:
2057 
2058  ensure(invariant());
2059  ensure(hub_id_space().contains_unique_rep(xrep_id));
2060 
2061  // Exit:
2062 
2063  return;
2064 }
2065 
2066 bool
2068 has_gluing() const
2069 {
2070  // Preconditions:
2071 
2072  // Body:
2073 
2074  bool result = _hub_id_space.has_gluing();
2075 
2076  // Postconditions:
2077 
2078  ensure(is_basic_query);
2079 
2080  // Exit:
2081 
2082  return result;
2083 }
2084 
2085 // PROTECTED MEMBER FUNCTIONS
2086 
2087 // PRIVATE MEMBER FUNCTIONS
2088 
2089 
2090 // ===========================================================
2091 // PRODUCT STRUCTURE FACET
2092 // ===========================================================
2093 
2094 // PUBLIC MEMBER FUNCTIONS
2095 
2096 void
2098 new_product_structure(const std::string& xname,
2099  const abstract_product_structure& xproduct)
2100 {
2101  // Preconditions:
2102 
2103  require(contains(xname));
2104 
2105  // Body:
2106 
2107  new_product_structure(_name_to_index.index(xname), xproduct);
2108 
2109  // Postconditions:
2110 
2111  ensure(has_product_structure(xname));
2112 
2113  // Exit:
2114 
2115  return;
2116 }
2117 
2118 void
2121  const abstract_product_structure& xproduct)
2122 {
2123  // Preconditions:
2124 
2125  require(contains(xspace_id));
2126 
2127  // Body:
2128 
2129  index_space_collection* lcollection = collection(xspace_id);
2130  pod_type local_id = lcollection->local_scope(xspace_id);
2131 
2132  lcollection->new_product_structure(local_id, xproduct);
2133 
2134  // Postconditions:
2135 
2136  ensure(has_product_structure(xspace_id));
2137 
2138  // Exit:
2139 
2140  return;
2141 }
2142 
2143 void
2145 delete_product_structure(const std::string& xname)
2146 {
2147  // Preconditions:
2148 
2149  require(contains(xname));
2150 
2151  // Body:
2152 
2154 
2155  // Postconditions:
2156 
2157  ensure(!has_product_structure(xname));
2158 
2159  // Exit:
2160 
2161  return;
2162 }
2163 
2164 void
2167 {
2168  // Preconditions:
2169 
2170  require(contains(xspace_id));
2171 
2172  // Body:
2173 
2174  index_space_collection* lcollection = collection(xspace_id);
2175  pod_type local_id = lcollection->local_scope(xspace_id);
2176 
2177  lcollection->delete_product_structure(local_id);
2178 
2179  // Postconditions:
2180 
2181  ensure(!has_product_structure(xspace_id));
2182 
2183  // Exit:
2184 
2185  return;
2186 }
2187 
2190 product_structure(const std::string& xname) const
2191 {
2192  // Preconditions:
2193 
2194  require(contains(xname));
2195  require(has_product_structure(xname));
2196 
2197  // Body:
2198 
2199  const abstract_product_structure& result =
2201 
2202  // Postconditions:
2203 
2204  ensure(is_basic_query);
2205 
2206  // Exit:
2207 
2208  return result;
2209 }
2210 
2213 product_structure(pod_type xspace_id) const
2214 {
2215  // Preconditions:
2216 
2217  require(contains(xspace_id));
2218  require(has_product_structure(xspace_id));
2219 
2220  // Body:
2221 
2222  const index_space_collection* lcollection = collection(xspace_id);
2223  pod_type local_id = lcollection->local_scope(xspace_id);
2224 
2225  const abstract_product_structure& result =
2226  lcollection->product_structure(local_id);
2227 
2228  // Postconditions:
2229 
2230  ensure(is_basic_query);
2231 
2232  // Exit:
2233 
2234  return result;
2235 }
2236 
2239 product_structure(const std::string& xname)
2240 {
2241  // Preconditions:
2242 
2243  require(contains(xname));
2244  require(has_product_structure(xname));
2245 
2246  // Body:
2247 
2248  abstract_product_structure& result =
2250 
2251  // Postconditions:
2252 
2253  ensure(is_basic_query);
2254 
2255  // Exit:
2256 
2257  return result;
2258 }
2259 
2263 {
2264  // Preconditions:
2265 
2266  require(contains(xspace_id));
2267  require(has_product_structure(xspace_id));
2268 
2269  // Body:
2270 
2271  index_space_collection* lcollection = collection(xspace_id);
2272  pod_type local_id = lcollection->local_scope(xspace_id);
2273 
2274  abstract_product_structure& result =
2275  lcollection->product_structure(local_id);
2276 
2277  // Postconditions:
2278 
2279  ensure(is_basic_query);
2280 
2281  // Exit:
2282 
2283  return result;
2284 }
2285 
2286 bool
2288 has_product_structure(const std::string& xname) const
2289 {
2290  // Preconditions:
2291 
2292  require(contains(xname));
2293 
2294  // Body:
2295 
2296  bool result = has_product_structure(_name_to_index.index(xname));
2297 
2298  // Postconditions:
2299 
2300  ensure(is_basic_query);
2301 
2302  // Exit:
2303 
2304  return result;
2305 }
2306 
2307 bool
2310 {
2311  // Preconditions:
2312 
2313  require(contains(xspace_id));
2314 
2315  // Body:
2316 
2317  const index_space_collection* lcollection = collection(xspace_id);
2318  pod_type local_id = lcollection->local_scope(xspace_id);
2319 
2320  bool result = lcollection->has_product_structure(local_id);
2321 
2322  // Postconditions:
2323 
2324  ensure(is_basic_query);
2325 
2326  // Exit:
2327 
2328  return result;
2329 }
2330 
2331 // PROTECTED MEMBER FUNCTIONS
2332 
2333 // PRIVATE MEMBER FUNCTIONS
2334 
2335 
2336 // ===========================================================
2337 // HANDLE POOL FACET
2338 // ===========================================================
2339 
2340 // PUBLIC MEMBER FUNCTIONS
2341 
2344 get_id_space(const std::string& xname) const
2345 {
2346  // Preconditions:
2347 
2348  require(contains(xname));
2349 
2350  // Body:
2351 
2353 
2354  // Postconditions:
2355 
2356  ensure(result.is_attached());
2357 
2358  // Exit:
2359 
2360  return result;
2361 }
2362 
2365 get_id_space(pod_type xspace_id) const
2366 {
2367  // Preconditions:
2368 
2369  require(contains(xspace_id));
2370 
2371  // Body:
2372 
2373  const index_space_collection* lcollection = collection(xspace_id);
2374  pod_type local_id = lcollection->local_scope(xspace_id);
2375 
2376  index_space_handle& result = lcollection->get_id_space(local_id);
2377 
2378  // Postconditions:
2379 
2380  ensure(result.is_attached());
2381 
2382  // Exit:
2383 
2384  return result;
2385 }
2386 
2387 void
2390 {
2391  // Preconditions:
2392 
2393  require(allocated_id_space(xid_space));
2394 
2395  // Body:
2396 
2397  collection(xid_space.index())->release_id_space(xid_space);
2398 
2399  // Postconditions:
2400 
2401  ensure(is_basic_query);
2402 
2403  // Exit:
2404 
2405  return;
2406 }
2407 
2408 bool
2411 {
2412  // Preconditions:
2413 
2414  // Body:
2415 
2416  bool result = collection(xid_space.index())->allocated_id_space(xid_space);
2417 
2418  // Postconditions:
2419 
2420  ensure(is_basic_query);
2421 
2422  // Exit:
2423 
2424  return result;
2425 }
2426 
2427 // PROTECTED MEMBER FUNCTIONS
2428 
2429 // PRIVATE MEMBER FUNCTIONS
2430 
2431 
2432 // ===========================================================
2433 // HANDLE POOL FACET
2434 // ===========================================================
2435 
2436 // PUBLIC MEMBER FUNCTIONS
2437 
2440 get_id_space_iterator(const std::string& xname) const
2441 {
2442  // Preconditions:
2443 
2444  require(contains(xname));
2445 
2446  // Body:
2447 
2449 
2450  // Postconditions:
2451 
2452  ensure(result.is_attached());
2453 
2454  // Exit:
2455 
2456  return result;
2457 }
2458 
2462 {
2463  // Preconditions:
2464 
2465  require(contains(xspace_id));
2466 
2467  // Body:
2468 
2469  const index_space_collection* lcollection = collection(xspace_id);
2470  pod_type local_id = lcollection->local_scope(xspace_id);
2471 
2472  index_space_iterator& result = lcollection->get_id_space_iterator(local_id);
2473 
2474  // Postconditions:
2475 
2476  ensure(result.is_attached());
2477 
2478  // Exit:
2479 
2480  return result;
2481 }
2482 
2483 void
2486 {
2487  // Preconditions:
2488 
2489  require(allocated_id_space_iterator(xitr));
2490 
2491  // Body:
2492 
2494 
2495  // Postconditions:
2496 
2497  ensure(is_basic_query);
2498 
2499  // Exit:
2500 
2501  return;
2502 }
2503 
2504 bool
2507 {
2508  // Preconditions:
2509 
2510  // Body:
2511 
2512  bool result = collection(xitr.index())->allocated_id_space_iterator(xitr);
2513 
2514  // Postconditions:
2515 
2516  ensure(is_basic_query);
2517 
2518  // Exit:
2519 
2520  return result;
2521 }
2522 
2523 // PROTECTED MEMBER FUNCTIONS
2524 
2525 // PRIVATE MEMBER FUNCTIONS
2526 
2527 
2528 // ===========================================================
2529 // ANY FACET
2530 // ===========================================================
2531 
2532 // PUBLIC MEMBER FUNCTIONS
2533 
2534 bool
2536 is_ancestor_of(const any *other) const
2537 {
2538  // Preconditions:
2539 
2540  require(other != 0);
2541 
2542  // Body:
2543 
2544  // True if other conforms to this
2545 
2546  bool result = dynamic_cast<const index_space_family*>(other) != 0;
2547 
2548  // Postconditions:
2549 
2550  // Exit:
2551 
2552  return result;
2553 }
2554 
2555 bool
2557 invariant() const
2558 {
2559  bool result = true;
2560 
2561  if(invariant_check())
2562  {
2563  // Prevent recursive calls to invariant
2564 
2566 
2567  // Must satisfy base class invariant
2568 
2569  invariance(any::invariant());
2570 
2571  // Invariances for this class:
2572 
2573  invariance(begin() == 0);
2574  invariance(contains(hub_id_space_name()));
2575 
2576  // Finished, turn invariant checking back on.
2577 
2579  }
2580 
2581  // Exit
2582 
2583  return result;
2584 }
2585 
2586 // PROTECTED MEMBER FUNCTIONS
2587 
2588 // PRIVATE MEMBER FUNCTIONS
2589 
2590 
2591 // ===========================================================
2592 // NON-MEMBER FUNCTIONS
2593 // ===========================================================
2594 
2595 std::ostream&
2596 sheaf::
2597 operator<<(std::ostream& xos, const index_space_family& xfamily)
2598 {
2599  // Preconditions:
2600 
2601  // Body:
2602 
2603  // Collect the id spaces into two sets (primary and secondary).
2604 
2605  set<pod_index_type> lprimary;
2606  set<pod_index_type> lsecondary;
2607 
2608  index_space_family_iterator litr(xfamily, false);
2609  while(!litr.is_done())
2610  {
2611  if(litr.name().substr(0, 5) == "__hub")
2612  {
2613  // This is a primary id space.
2614 
2615  lprimary.insert(litr.index());
2616  }
2617  else
2618  {
2619  // This is a secondary id space.
2620 
2621  lsecondary.insert(litr.index());
2622  }
2623 
2624  litr.next();
2625  }
2626 
2627  xos << "id spaces" << endl;
2628  xos << "---------" << endl;
2629  xos << endl;
2630 
2631  xos << " begin = " << xfamily.begin() << endl;
2632  xos << " end = " << xfamily.end() << endl << endl;
2633 
2634  xos << setw(10) << "index"
2635  << setw(32) << "name"
2636  << setw(10) << "ct"
2637  << setw(10) << "begin"
2638  << setw(10) << "end"
2639  << setw(12) << "persistent"
2640  << endl;
2641 
2642  xos << setw(10) << "---------"
2643  << setw(32) << "-------------------------------"
2644  << setw(10) << "---------"
2645  << setw(10) << "---------"
2646  << setw(10) << "---------"
2647  << setw(12) << "-----------"
2648  << endl;
2649 
2650  set<pod_index_type>::const_iterator lprimary_itr = lprimary.begin();
2651 
2652  // There's always a top id space and it must be first; print it out.
2653 
2654  size_type lct = xfamily.ct(*lprimary_itr);
2655 
2656  xos << setw(10) << *lprimary_itr
2657  << setw(32) << xfamily.name(*lprimary_itr)
2658  << setw(10) << lct;
2659 
2660  if(lct > 0)
2661  {
2662  xos << setw(10) << xfamily.begin(*lprimary_itr)
2663  << setw(10) << xfamily.end(*lprimary_itr);
2664  }
2665 
2666  xos << endl;
2667  lprimary_itr++;
2668 
2669  // Print out any primary id spaces.
2670 
2671  xos << " primary:" << endl;
2672 
2673  while(lprimary_itr != lprimary.end())
2674  {
2675  lct = xfamily.ct(*lprimary_itr);
2676 
2677  xos << setw(10) << *lprimary_itr
2678  << setw(32) << xfamily.name(*lprimary_itr)
2679  << setw(10) << lct;
2680 
2681  if(lct > 0)
2682  {
2683  xos << setw(10) << xfamily.begin(*lprimary_itr)
2684  << setw(10) << xfamily.end(*lprimary_itr);
2685  }
2686 
2687  xos << endl;
2688 
2689  lprimary_itr++;
2690  }
2691 
2692  // Print out the secondary id spaces.
2693 
2694  xos << " secondary:" << endl;
2695 
2696  set<pod_index_type>::const_iterator lsecondary_itr = lsecondary.begin();
2697 
2698  while(lsecondary_itr != lsecondary.end())
2699  {
2700  lct = xfamily.ct(*lsecondary_itr);
2701 
2702  xos << setw(10) << *lsecondary_itr
2703  << setw(32) << xfamily.name(*lsecondary_itr)
2704  << setw(10) << lct;
2705 
2706  if(lct > 0)
2707  {
2708  xos << setw(10) << xfamily.begin(*lsecondary_itr)
2709  << setw(10) << xfamily.end(*lsecondary_itr)
2710  << setw(12) << boolalpha << xfamily.is_persistent(*lsecondary_itr) << noboolalpha;
2711  }
2712 
2713  xos << endl;
2714 
2715  lsecondary_itr++;
2716  }
2717 
2718 
2719  xos << endl;
2720  xos << "equivalence classes" << endl;
2721  xos << "-------------------" << endl;
2722  xos << endl;
2723 
2724  const hub_index_space_handle& lhub_space = xfamily.hub_id_space();
2725 
2726  if(lhub_space.ct() <= index_space_family::max_rep_ids())
2727  {
2728  index_space_iterator& lid_itr = lhub_space.get_iterator();
2729 
2730  scoped_index lid(lhub_space);
2731  index_equivalence_iterator leqv_itr(xfamily, lid, false, true);
2732 
2733  while(!lid_itr.is_done())
2734  {
2735  lid = lid_itr.pod();
2736  leqv_itr.put_rep_id(lid);
2737  leqv_itr.reset();
2738 
2739  if(!leqv_itr.is_done())
2740  {
2741  // There are equivelence classes for lid, output them.
2742 
2743  xos << "("
2744  << setw(4) << lid.scope_id()
2745  << ", "
2746  << setw(4) << lid.pod()
2747  << "):";
2748 
2749  while(!leqv_itr.is_done())
2750  {
2751  xos << " ("
2752  << setw(4) << leqv_itr.item().first
2753  << ", "
2754  << setw(4) << leqv_itr.item().second
2755  << ")";
2756 
2757  leqv_itr.next();
2758  }
2759 
2760  xos << endl;
2761  }
2762 
2763  lid_itr.next();
2764  }
2765 
2766  lhub_space.release_iterator(lid_itr);
2767  }
2768  else
2769  {
2770  xos << " ... " << endl
2771  << " Equivalence class output terminated because the " << endl
2772  << " size of the hub id space exceeded "
2773  << index_space_family::max_rep_ids() << " ids," << endl
2774  << " use index_space_family::max_rep_ids() to change default." << endl;
2775 
2776  }
2777 
2778  // Postconditions:
2779 
2780  // Exit:
2781 
2782  return xos;
2783 }
2784 
2785 size_t
2786 sheaf::
2787 deep_size(const index_space_family& xfamily, bool xinclude_shallow)
2788 {
2789  size_t result = 0;
2790 
2791  // Preconditions:
2792 
2793  // Body:
2794 
2795  result = xinclude_shallow ? sizeof(xfamily) : 0;
2796 
2797  // Add the contributation from member _intervals.
2798 
2800  for(itr = xfamily._intervals.begin(); itr != xfamily._intervals.end(); ++itr)
2801  {
2802  if(itr->second != 0)
2803  {
2804  result += itr->second->deep_size(true);
2805  }
2806  }
2807 
2808  // Add contributions from member _name_to_index.
2809 
2810  result += deep_size(xfamily._name_to_index, false);
2811 
2812  // Postconditions:
2813 
2814  ensure(result >= 0);
2815 
2816  // Exit
2817 
2818  return result;
2819 }
virtual pod_type glued_hub_pod(pod_type xid) const
The pod index in the hub id space equivalent to xid in this id space. synonym for unglued_hub_pod(xid...
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
name_multimap _name_to_index
Map from name to id space index.
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 pod_type local_scope(pod_type xspace_id) const
Id relative to this collection equivalent to the id space family id xspace_id.
const index_space_collection * collection(pod_type xid) const
Id space collection for id xid (const version).
const member_type & item() const
The current equivalence class member.
friend SHEAF_DLL_SPEC size_t deep_size(const index_space_family &xfamily, bool xinclude_shallow)
The deep size of index_space_family& xn.
void insert_interval(index_space_interval &xinterval)
Inserts an id space interval into this family.
pod_type end() const
The ending index of the id spaces.
virtual void new_product_structure(pod_type xlocal_id, const abstract_product_structure &xproduct)=0
Creates a new product structure for the id space with id xlocal_id by cloning the product structure...
pod_type pod(const std::string &xname, pod_type xid) const
The pod index in the space with name xname equivalent to xid in the hub id space. ...
std::string name(pod_type xid) const
The name for id xid.
An abstract class that defines the product structure for an id space.
bool in_scope() const
True if and only if scope() contains an entry for pod().
Definition: scoped_index.h:584
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
An abstract iterator over the ids of an id space.
void next()
Makes item() the next item in the equivalence class.
void release_id_space(index_space_handle &xid_space) const
Returns the id space handle xid_space to the handle pool.
void extend_last_term(size_type xct)
Extends the last term to ct() == xct.
virtual bool contains_family(pod_type xspace_id) const =0
True if this collection contains the id space with family id xspace_id.
static const std::string & hub_id_space_name()
Name of the hub id space.
index_type index(const std::string &xname) const
The index associated with name xname.
void glue(pod_type xid, pod_type xrep)
Glues xid to xrep; adds xid to the equivalence class with representative member xrep.
pod_type hub_begin(const std::string &xname) const
Beginning id of the space in the hub id space with name xname.
pod_type pod() const
The current id in the iteration.
const index_space_handle & term_of(pod_type xid) const
The term in the hub id space containing id xid.
static hub_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname)
Create a new primary sum id space in the id space family xid_space at the next available id space ind...
bool is_persistent(const std::string &xname) const
True if the id space with name xname should be written to disk.
hub_index_space_handle _hub_id_space
The hub id space.
const abstract_product_structure & product_structure(const std::string &xname) const
The product structure for the id space with name xname (const version).
void extend_last_term(size_type xct)
Extends the last term to to ct == xct.
void put_rep_id(pod_index_type xrep_id)
Sets rep_id() to xrep_id.
interval_map_type::const_iterator const_interval_iterator_type
Type of interval map iterator.
index_space_handle & get_id_space(const std::string &xname) const
Allocates an id space handle from the handle pool attached to state with name xname.
void clear_id_spaces()
Clear all the non-standard id spaces in this family.
virtual void delete_product_structure(pod_type xlocal_id)=0
Deletes the product structure for the id space with id xlocal_id.
void delete_state(pod_type xid)
Delete the state with id xid.
bool is_valid_reserved_id(pod_type xid) const
True if and only if the reserved term containing xid is already a reserved term or is available for a...
virtual pod_type end(pod_type xlocal_id) const =0
Ending id of the space with id xlocal_id.
STL namespace.
pod_type _standard_end
Ending index of the standard id spaces.
static size_type explicit_interval_size()
Size of the explicit id space intervals.
pod_type _end
Ending index of the id spaces.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
void put_name(pod_type xid, const std::string &xname)
Associate name xname with id space index xid.
const index_space_handle & new_gathered_id_space(bool xexclude_bottom)
Construct a gathered id space from this id space. If xexclude_bottom, construct the id space without ...
virtual pod_type index() const =0
Index of this space.
virtual void next()=0
Makes id() the next id in the iteration.
virtual bool is_attached() const =0
True if this handle is attached to a state.
void update_standard_id_spaces()
Update the initially allocated id spaces.
An implementation of class sum_index_space_handle that has a primary sum id space state...
virtual index_space_iterator & get_iterator() const
Allocates an id space iterator from the iterator pool.
virtual bool contains_unglued_hub(pod_type xlocal_id, pod_type xid) const =0
True if the space with id xlocal_id contains an id equivalent to xid in the unglued hub id space...
index_space_iterator & get_id_space_iterator(const std::string &xname) const
Allocates an id space iterator from the iterator pool attached to state with name xname...
pod_type begin() const
The beginning index of the id spaces.
virtual explicit_index_space_state * explicit_state(pod_type xlocal_id) const =0
The explicit id space state for id xlocal_id. Returns null if there is no explicit id space for xloca...
interval_map_type::iterator interval_iterator_type
Type of interval map iterator.
void unglue_all(pod_type xrep_id)
Unglue all ids glued to representative xrep_id; makes each id in the equivalence class of xrep_id its...
virtual bool has_product_structure(pod_type xlocal_id) const =0
True if the id space with id xlocal_id has a product structure.
index_space_family()
Default constructor.
virtual pod_type local_scope(pod_type xspace_id) const =0
Id relative to this collection equivalent to the id space family id xspace_id.
pod_type index(const std::string &xname) const
The index for name xname.
An implementation of class explicit_index_space_handle that has a primary id space state...
pod_type scope_id() const
The index of the scope id space.
Definition: scoped_index.h:516
pod_type glued_hub_pod(const std::string &xname, pod_type xid) const
The pod index in the glued hub id space equivalent to xid in the id space with name xname...
void new_product_structure(const std::string &xname, const abstract_product_structure &xproduct)
Creates a new product structure for the id space with name xname by cloning the product structure...
An abstract iterator over the id spaces of a interval.
static size_type & max_rep_ids()
Maximum number of representive ids which are permitted by the stream insertion operator to output the...
Abstract base class with useful features for all objects.
Definition: any.h:39
const size_type EXPLICIT_INTERVAL_SIZE
Size of the explicit id space intervals.
Definition: sheaf.h:112
An implemenation of index_space_collection that adds an interface for the interval [begin()...
bool has_only_standard_id_spaces() const
True if and only if all the id spaces are standard id spaces.
bool is_done() const
True if iteration is finished.
virtual pod_type begin(pod_type xlocal_id) const =0
Beginning id of the space with id xlocal_id.
bool is_done() const
True if iteration is finished.
pod_type new_id()
Allocate the next available id in this family.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
void unglue(pod_type xid)
Unglues xid; makes xid its own representative.
pod_type new_primary_term(size_type xct)
Create a new primary term [next_id(), next_id()+xct). Returns the index of the term created...
pod_type hub_pod(const std::string &xname, pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in the id space with name xname...
void release_id_space_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
void unglue_all(pod_type xrep_id)
Unglue all ids glued to representative xrep_id; makes each id in the equivalence class of xrep_id its...
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
bool has_gathered_hub_id_space() const
True if there is a gathered hub id space for this family.
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.
std::string name() const
The name of the current id space in the iteration.
const index_space_handle & gathered_id_space() const
The gathered id space.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
void new_state(const std::string &xname, const std::string &xstate_class_name)
Create a new id space with class type xstate_class_name and name xname. Used by the I/O system to rea...
bool has_product_structure(const std::string &xname) const
True if the id space with name xname has a product structure.
void delete_id(pod_type xid)
Deallocate the id xid in this family.
bool contains_name(const std::string &xname) const
True if this already contains an entry with name xname.
virtual size_type ct(pod_type xlocal_id) const =0
The number of members for the id space with id xlocal_id.
static std::string reserved_prefix()
Prefix for identifying member names reserved by the sheaf system.
Definition: poset_path.cc:883
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 update_gathered_id_space()
Update the gathered id space.
void delete_primary_state(pod_type xid)
Delete the primary space state with id xid.
virtual pod_type pod(pod_type xlocal_id, pod_type xid) const =0
The pod index in the space with id xlocal_id equivalent to xid in the hub id space.
virtual bool is_persistent(pod_type xlocal_id) const =0
True if the id space with id xlocal_id should be written to disk.
bool gathered_hub_id_space_excludes_bottom() const
True, if the gathered hub id space excludes BOTTOM_INDEX.
pod_index_type pod_type
The "plain old data" index type for this.
void update_standard_ids()
Make end() the standard id end.
void clear_ids()
Deallocate all non-standard ids.
interval_map_type _intervals
Map from id to id space interval.
pod_type new_id()
Allocate the next available id in this space.
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 const abstract_product_structure & product_structure(pod_type xlocal_id) const =0
The product structure for the id space with id xlocal_id (const version).
bool contains_index(index_type xindex) const
True if this already contains an entry with index xindex.
virtual bool contains(pod_type xlocal_id) const =0
True if this collection contains the id space with local id xlocal_id.
void new_state(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent)
Create a new id space state in the id space family xid_spaces at the next available id space index wi...
virtual pod_type index() const =0
Index of this space.
void glue(pod_type xid, pod_type xrep)
Glues xid to xrep; adds xid to the equivalence class with representative member xrep.
An implementation of index_space_interval for an interval of explicit id spaces.
bool is_valid_reserved_id(pod_type xid) const
True if and only if the reserved term containing xid is already a reserved term or is available for a...
const index_space_handle & new_gathered_hub_id_space(bool xexclude_bottom)
Create a gathered hub id space for this family. If xexclude_bottom, construct the id space without BO...
virtual bool invariant() const
Class invariant.
pod_type index() const
The index of the current id space in the iteration.
void delete_id(pod_type xid)
Deallocate the id xid in this space.
void delete_interval(pod_type xid)
Delete the interval that contains the id space with id xid.
void delete_space(pod_type xid)
Delete the id space with index xid.
pod_type _next_explicit_id
The next available id for an explicit index space.
bool is_empty(const std::string &xname) const
True if there are no ids in the space with name xname.
const index_space_handle & last_term() const
The last term.
bool gathered_id_space_excludes_bottom() const
True, if the gathered id space excludes BOTTOM_INDEX.
pod_type new_primary_state(size_type xct)
Creates a new primary id space state with xct number of ids. Returns the index of the id space state ...
virtual bool is_attached() const =0
True if this iterator is attached to a state.
explicit_index_space_interval * _explicit_interval
The current explicit id space interval.
bool has_gathered_id_space() const
True, if the gathered id space exists.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
void next()
Makes id_space() the next id space in the iteration.
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.
void delete_product_structure(const std::string &xname)
Deletes the product structure for the id space with name xname.
bool is_gathered(const std::string &xname) const
True if begin(xspace_id) == 0 and end(xspace_id) == ct(xspace_id).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual index_space_handle & get_id_space(pod_type xlocal_id) const =0
Allocates an id space handle from the handle pool attached to state with id xlocal_id.
pod_type hub_term_id() const
The term id of this in the hub id space.
void update_gathered_hub_id_space()
Update the gathered hub id space.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
void put_entry(const entry_type &xentry, bool xunique)
Sets (xindex, xname) as an entry in the map. If xunique, deletes all other entries for xindex...
virtual index_space_iterator & get_id_space_iterator(pod_type xlocal_id) const =0
Allocates an id space iterator from the iterator pool attached to state with id xlocal_id.
pod_type end() const
Ending space id of this interval in the id space family scope.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
virtual void remove(pod_type xlocal_id)=0
Remove the id space with id xlocal_id.
bool contains_unglued_hub(const std::string &xname, pod_type xid) const
True if the space with name xname contains an id equivalent to xid in the unglued hub id space...
const index_space_handle & last_term() const
The last term in the hub id space.
virtual size_type ct() const
The number of members.
An iterator over members of an id equivalence class.
virtual void release_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
Factory and container for a family of id spaces.
bool is_done() const
True if iteration is finished.
std::string name(index_type xindex) const
The primary (0-th) name associated with index xindex.
pod_type hub_pod(pod_type xlocal_id, pod_type xid) const
The pod index in the glued hub id space equivalent to xid in the id space with id xlocal_id...
void remove_term(pod_type xi)
Remove xi-th term of this sum.
virtual pod_type begin(pod_type xlocal_id) const
Beginning id of the space with id xlocal_id.
virtual pod_type end(pod_type xlocal_id) const
Ending id of the space with id xlocal_id.
pod_type unglued_hub_pod(const std::string &xname, pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in the id space with name xname...
size_type ct(const std::string &xname) const
The number of members for the id space with name xname.
bool contains_glued_hub(const std::string &xname, pod_type xid) const
True if the space with name xname contains an id equivalent to xid in the glued 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
static factory< explicit_index_space_state > & id_space_factory()
A factory for making descendants of this class.
const index_space_handle & gathered_hub_id_space() const
A secondary id space that is a gathered version of the hub id space.
pod_type begin() const
Beginning space id of this interval in the id space family scope.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
void delete_index(index_type xindex)
Removes all entires for index xindex.
virtual ~index_space_family()
Destructor.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
bool has_gluing() const
Ture if there is any gluing.
bool has_gluing() const
Ture if there is any gluing in the hub id space.
const index_space_handle & term_of(pod_type xid) const
The term containing id xid.
pod_type reserve_next_explicit_id()
Reserve the next available id for an explicit index space.
const hub_index_space_handle & hub_id_space() const
The hub id space of this family.
bool contains_hub(const std::string &xname, pod_type xid) const
True if the space with name xname contains an id equivalent to xid in the unglued hub id space...
static const explicit_index_space_interval & new_space(index_space_family &xid_spaces, size_type xub)
Create a new interval of id spaces for explicit id spaces in the id space family xid_spaces with uppe...
void unglue(pod_type xid)
Unglues xid; makes xid its own representative.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710