SheafSystem  0.0.0.0
index_space_handle.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #include "SheafSystem/abstract_product_structure.h"
22 #include "SheafSystem/index_space_handle.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/hub_index_space_handle.h"
25 #include "SheafSystem/index_space_family.h"
26 #include "SheafSystem/index_space_iterator.h"
27 #include "SheafSystem/scoped_index.h"
28 #include "SheafSystem/std_iomanip.h"
29 
30 // ===========================================================
31 // INDEX_SPACE_HANDLE FACET
32 // ===========================================================
33 
34 // PUBLIC MEMBER FUNCTIONS
35 
38 {
39  // Preconditions:
40 
41  // Body:
42 
43  // nothing to do.
44 
45  // Postconditions:
46 
47  // Exit:
48 
49  return;
50 }
51 
55 {
56  // Preconditions:
57 
58  require(xother.is_attached() ? conforms_to_state(xother) : true);
59 
60  // Body:
61 
62  attach_to(xother);
63 
64  // Postconditions:
65 
66  ensure(invariant());
67  ensure((*this) == xother);
68 
69  // Exit:
70 
71  return *this;
72 }
73 
74 bool
76 operator==(const index_space_handle& xother) const
77 {
78  // Preconditions:
79 
80  // Body:
81 
82  bool result = (is_attached() == xother.is_attached());
83  if(result && is_attached())
84  {
85  result = result && (&id_spaces() == &xother.id_spaces());
86  result = result && (index() == xother.index());
87  }
88 
89  // Postconditions:
90 
91  ensure(is_basic_query);
92 
93  // Exit:
94 
95  return result;
96 }
97 
100 clone() const
101 {
102  index_space_handle* result;
103 
104  // Preconditions:
105 
106  // Body:
107 
108  result = 0; // Just to silence compiler warnings.
109 
110  is_abstract();
111 
112  // Postconditions:
113 
114  ensure(result != 0);
115  ensure(is_same_type(result));
116  ensure(*result == *this);
117 
118  // Exit:
119 
120  return result;
121 }
122 
123 // PROTECTED MEMBER FUNCTIONS
124 
127 {
128  // Preconditions:
129 
130  // Body:
131 
132  // Postconditions:
133 
134  // Can't call invariant because it calls pure virtual functions.
135  //ensure(invariant());
136 
137  // Exit:
138 
139  return;
140 }
141 
142 // PRIVATE MEMBER FUNCTIONS
143 
144 
145 // ===========================================================
146 // INDEX SPACE FACET
147 // ===========================================================
148 
149 // PUBLIC MEMBER FUNCTIONS
150 
153 id_spaces() const
154 {
155  // Preconditions:
156 
157  require(is_attached());
158 
159  // Body:
160 
161  const index_space_family* result = 0;
162 
163  is_abstract();
164 
165  // Postconditions:
166 
167  ensure(is_basic_query);
168 
169  // Exit:
170 
171  return *result;
172 }
173 
177 {
178  // Preconditions:
179 
180  require(is_attached());
181 
182  // Body:
183 
184  index_space_family* result = 0;
185 
186  is_abstract();
187 
188  // Postconditions:
189 
190  ensure(is_basic_query);
191 
192  // Exit:
193 
194  return *result;
195 }
196 
200 {
201  // Preconditions:
202 
203  require(is_attached());
204 
205  // Body:
206 
207  const hub_index_space_handle& result = id_spaces().hub_id_space();
208 
209  // Postconditions:
210 
211  ensure(is_basic_query);
212 
213  // Exit:
214 
215  return result;
216 }
217 
220 ct() const
221 {
222  // Preconditions:
223 
224  require(is_attached());
225 
226  // Body:
227 
228  size_type result = 0; // Just to silence compiler warnings.
229 
230  is_abstract();
231 
232  // Postconditions:
233 
234  ensure(is_basic_query);
235 
236  // Exit:
237 
238  return result;
239 }
240 
241 bool
243 is_empty() const
244 {
245  // Preconditions:
246 
247  require(is_attached());
248 
249  // Body:
250 
251  bool result = (ct() == 0);
252 
253  // Postconditions:
254 
255  ensure(is_basic_query);
256 
257  // Exit:
258 
259  return result;
260 }
261 
264 begin() const
265 {
266  // Preconditions:
267 
268  require(is_attached());
269 
270  // Body:
271 
272  pod_type result = 0; // Just to silence compiler warnings.
273 
274  is_abstract();
275 
276  // Postconditions:
277 
278  ensure(is_basic_query);
279 
280  // Exit:
281 
282  return result;
283 }
284 
287 end() const
288 {
289  // Preconditions:
290 
291  require(is_attached());
292 
293  // Body:
294 
295  pod_type result = 0; // Just to silence compiler warnings.
296 
297  is_abstract();
298 
299  // Postconditions:
300 
301  ensure(is_basic_query);
302 
303  // Exit:
304 
305  return result;
306 }
307 
308 bool
310 is_gathered() const
311 {
312  // Preconditions:
313 
314  require(is_attached());
315 
316  // Body:
317 
318  bool result = (begin() == 0) && (end() == ct());
319 
320  // Postconditions:
321 
322  ensure(is_basic_query);
323 
324  // Exit:
325 
326  return result;
327 }
328 
329 bool
331 contains(pod_type xid) const
332 {
333  // Preconditions:
334 
335  require(is_attached());
336 
337  // Body:
338 
339  bool result = false; // Just to silence compiler warnings.
340 
341  is_abstract();
342 
343  // Postconditions:
344 
345  ensure(is_basic_query);
346 
347  // Exit:
348 
349  return result;
350 }
351 
352 bool
354 contains(const scoped_index& xid) const
355 {
356  // Preconditions:
357 
358  require(is_attached());
359 
360  // Body:
361 
362  bool result = contains_hub(xid.hub_pod());
363 
364  // Postconditions:
365 
366  ensure(is_basic_query);
367 
368  // Exit:
369 
370  return result;
371 }
372 
373 bool
376 {
377  // Preconditions:
378 
379  require(is_attached());
380 
381  // Body:
382 
383  bool result = contains_unglued_hub(xid);
384 
385  // Postconditions:
386 
387  ensure(is_basic_query);
388 
389  // Exit:
390 
391  return result;
392 }
393 
394 bool
397 {
398  // Preconditions:
399 
400  require(is_attached());
401 
402  // Body:
403 
404  bool result = false; // Just to silence compiler warnings.
405 
406  is_abstract();
407 
408  // Postconditions:
409 
410  ensure(is_basic_query);
411 
412  // Exit:
413 
414  return result;
415 }
416 
417 bool
420 {
421  // Preconditions:
422 
423  require(is_attached());
424 
425  // Body:
426 
427  bool result = false; // Just to silence compiler warnings.
428 
429  is_abstract();
430 
431  // Postconditions:
432 
433  ensure(is_basic_query);
434 
435  // Exit:
436 
437  return result;
438 }
439 
440 bool
442 contains(pod_type xid, const scoped_index& xhub_id) const
443 {
444  // Preconditions:
445 
446  require(is_attached());
447 
448  // Body:
449 
450  bool result = contains(xid, xhub_id.hub_pod());
451 
452  // Postconditions:
453 
454  ensure(is_basic_query);
455 
456  // Exit:
457 
458  return result;
459 }
460 
461 bool
463 contains(pod_type xid, pod_type xhub_id) const
464 {
465  // Preconditions:
466 
467  require(is_attached());
468 
469  // Body:
470 
471  bool result = false; // Just to silence compiler warnings.
472 
473  is_abstract();
474 
475  // Postconditions:
476 
477  ensure(is_basic_query);
478 
479  // Exit:
480 
481  return result;
482 }
483 
486 pod(pod_type xid) const
487 {
488  // Preconditions:
489 
490  require(is_attached());
491 
492  // Body:
493 
494  pod_type result = 0; // Just to silence compiler warnings.
495 
496  is_abstract();
497 
498  // Postconditions:
499 
500  ensure(!is_valid(result) || contains(result));
501 
502  // Exit:
503 
504  return result;
505 }
506 
509 pod(const scoped_index& xid) const
510 {
511  // Preconditions:
512 
513  require(is_attached());
514 
515  // Body:
516 
517  pod_type result = pod(xid.hub_pod());
518 
519  // Postconditions:
520 
521  ensure(!is_valid(result) || contains(result));
522 
523  // Exit:
524 
525  return result;
526 }
527 
530 hub_pod(pod_type xid) const
531 {
532  // Preconditions:
533 
534  require(is_attached());
535 
536  // Body:
537 
538  pod_type result = unglued_hub_pod(xid);
539 
540  // Postconditions:
541 
542  ensure(!is_valid(result) || contains_hub(result));
543 
544  // Exit:
545 
546  return result;
547 }
548 
552 {
553  // Preconditions:
554 
555  require(is_attached());
556 
557  // Body:
558 
559  pod_type result = 0; // Just to silence compiler warnings.
560 
561  is_abstract();
562 
563  // Postconditions:
564 
565  ensure(!is_valid(result) || contains_unglued_hub(result));
566 
567  // Exit:
568 
569  return result;
570 }
571 
575 {
576  // Preconditions:
577 
578  require(is_attached());
579 
580  // Body:
581 
582  pod_type result = 0; // Just to silence compiler warnings.
583 
584  is_abstract();
585 
586  // Postconditions:
587 
588  ensure(!is_valid(result) || contains_glued_hub(result));
589 
590  // Exit:
591 
592  return result;
593 }
594 
595 bool
598 {
599  // Preconditions:
600 
601  require(is_attached());
602 
603  // Body:
604 
605  bool result = false; // Just to silence compiler warnings.
606 
607  is_abstract();
608 
609  // Postconditions:
610 
611  ensure(is_basic_query);
612 
613  // Exit:
614 
615  return result;
616 }
617 
618 // PROTECTED MEMBER FUNCTIONS
619 
620 // PRIVATE MEMBER FUNCTIONS
621 
622 
623 // ===========================================================
624 // PRODUCT STRUCTURE FACET
625 // ===========================================================
626 
627 // PUBLIC MEMBER FUNCTIONS
628 
629 void
632 {
633  // Preconditions:
634 
635  require(is_attached());
636 
637  // Body:
638 
639  is_abstract();
640 
641  // Postconditions:
642 
643  ensure(has_product_structure());
644 
645  // Exit:
646 
647  return;
648 }
649 
650 void
653 {
654  // Preconditions:
655 
656  require(is_attached());
657 
658  // Body:
659 
660  is_abstract();
661 
662  // Postconditions:
663 
664  ensure(!has_product_structure());
665 
666  // Exit:
667 
668  return;
669 }
670 
674 {
675  // Preconditions:
676 
677  require(is_attached());
678  require(has_product_structure());
679 
680  // Body:
681 
682  const abstract_product_structure* result = 0; // Just to silence compiler warnings.
683 
684  is_abstract();
685 
686  // Postconditions:
687 
688  ensure(is_basic_query);
689 
690  // Exit:
691 
692  return *result;
693 }
694 
698 {
699  // Preconditions:
700 
701  require(is_attached());
702  require(has_product_structure());
703 
704  // Body:
705 
706  abstract_product_structure* result = 0; // Just to silence compiler warnings.
707 
708  is_abstract();
709 
710  // Postconditions:
711 
712  ensure(is_basic_query);
713 
714  // Exit:
715 
716  return *result;
717 }
718 
719 bool
722 {
723  // Preconditions:
724 
725  require(is_attached());
726 
727  // Body:
728 
729  bool result = false; // Just to silence compiler warnings.
730 
731  is_abstract();
732 
733  // Postconditions:
734 
735  ensure(is_basic_query);
736 
737  // Exit:
738 
739  return result;
740 }
741 
742 // PROTECTED MEMBER FUNCTIONS
743 
744 // PRIVATE MEMBER FUNCTIONS
745 
746 
747 // ===========================================================
748 // HANDLE FACET
749 // ===========================================================
750 
751 // PUBLIC MEMBER FUNCTIONS
752 
755 host() const
756 {
757  // Preconditions:
758 
759  require(is_attached());
760 
761  // Body:
762 
763  index_space_collection* result = 0; // Just to silence compiler warnings.
764 
765  is_abstract();
766 
767  // Postconditions:
768 
769  ensure(is_basic_query);
770 
771  // Exit:
772 
773  return *result;
774 }
775 
778 index() const
779 {
780  // Preconditions:
781 
782  require(is_attached());
783 
784  // Body:
785 
786  pod_type result = 0; // Just to silence compiler warnings.
787 
788  is_abstract();
789 
790  // Postconditions:
791 
792  ensure(id_spaces().contains(result));
793 
794  // Exit:
795 
796  return result;
797 }
798 
799 std::string
801 name() const
802 {
803  // Preconditions:
804 
805  require(is_attached());
806 
807  // Body:
808 
809  std::string result = id_spaces().name(index());
810 
811  // Postconditions:
812 
813  ensure(result.empty() || id_spaces().contains(result));
814 
815  // Exit:
816 
817  return result;
818 }
819 
820 void
822 put_name(const std::string& xname)
823 {
824  // Preconditions:
825 
826  require(!xname.empty());
827  require(!id_spaces().contains(xname));
828 
829  // Body:
830 
831  id_spaces().put_name(index(), xname);
832 
833  // Postconditions:
834 
835  ensure(id_spaces().contains(xname));
836  ensure(id_spaces().name(index()) == xname);
837 
838  // Exit:
839 
840  return;
841 }
842 
843 bool
845 is_attached() const
846 {
847  // Preconditions:
848 
849  require(is_attached());
850 
851  // Body:
852 
853  bool result = false; // Just to silence compiler warnings.
854 
855  is_abstract();
856 
857  // Postconditions:
858 
859  ensure(is_basic_query);
860 
861  // Exit:
862 
863  return result;
864 }
865 
866 void
868 attach_to(const index_space_family& xid_spaces, pod_type xindex)
869 {
870  // Preconditions:
871 
872  require(xid_spaces.contains(xindex));
873  require(conforms_to_state(xid_spaces, xindex));
874 
875  // Body:
876 
877  const index_space_collection* lhost = xid_spaces.collection(xindex);
878  attach_to(*lhost, lhost->local_scope(xindex));
879 
880  // Postconditions:
881 
882  ensure(is_attached());
883  ensure(&id_spaces() == &xid_spaces);
884  ensure(index() == xindex);
885 
886  // Exit:
887 
888  return;
889 }
890 
891 void
893 attach_to(const index_space_family& xid_spaces, const std::string& xname)
894 {
895  // Preconditions:
896 
897  require(!xname.empty());
898  require(xid_spaces.contains(xname));
899  require(conforms_to_state(xid_spaces, xname));
900 
901  // Body:
902 
903  attach_to(xid_spaces, xid_spaces.index(xname));
904 
905  // Postconditions:
906 
907  ensure(is_attached());
908  ensure(&id_spaces() == &xid_spaces);
909  ensure(name() == xname);
910 
911  // Exit:
912 
913  return;
914 }
915 
916 void
919 {
920  // Preconditions:
921 
922  require(is_attached());
923  require(id_spaces().contains(xindex));
924  require(conforms_to_state(xindex));
925 
926  // Body:
927 
928  define_old_variable(const index_space_family& old_id_spaces = id_spaces());
929 
930  is_abstract();
931 
932  // Postconditions:
933 
934  ensure(is_attached());
935  ensure(&id_spaces() == &old_id_spaces);
936  ensure(index() == xindex);
937 
938  // Exit:
939 
940  return;
941 }
942 
943 void
945 attach_to(const std::string& xname)
946 {
947  // Preconditions:
948 
949  require(is_attached());
950  require(id_spaces().contains(xname));
951  require(conforms_to_state(xname));
952 
953  // Body:
954 
955  define_old_variable(const index_space_family& old_id_spaces = id_spaces());
956 
957  attach_to(id_spaces().index(xname));
958 
959  // Postconditions:
960 
961  ensure(is_attached());
962  ensure(&id_spaces() == &old_id_spaces);
963  ensure(name() == xname);
964 
965  // Exit:
966 
967  return;
968 }
969 
970 void
973 {
974  // Preconditions:
975 
976  require(xother.is_attached() ? conforms_to_state(xother) : true);
977 
978  // Body:
979 
980  if(xother.is_attached())
981  {
982  // xother is attached; attach this to the state of xother.
983 
984  if(is_attached() && (host() == xother.host()))
985  {
986  attach_to(xother.index());
987  }
988  else
989  {
990  attach_to(xother.id_spaces(), xother.index());
991  }
992  }
993  else
994  {
995  // xother is not attached; detach this.
996 
997  detach();
998  }
999 
1000  // Postconditions:
1001 
1002  ensure(is_attached() == xother.is_attached());
1003  ensure(is_attached() ? &host() == &xother.host() : true);
1004  ensure(is_attached() ? index() == xother.index() : true);
1005 
1006  // Exit:
1007 
1008  return;
1009 }
1010 
1011 void
1014 {
1015  // Preconditions:
1016 
1017  require(xhost.contains(xlocal_id));
1018  require(conforms_to_state(xhost, xlocal_id));
1019 
1020  // Body:
1021 
1022  is_abstract();
1023 
1024  // Postconditions:
1025 
1026  ensure(is_attached());
1027  ensure(&host() == &xhost);
1028  ensure(index() == xhost.family_scope(xlocal_id));
1029 
1030  // Exit:
1031 
1032  return;
1033 }
1034 
1035 void
1038 {
1039  // Preconditions:
1040 
1041  // Body:
1042 
1043  is_abstract();
1044 
1045  // Postconditions:
1046 
1047  ensure(!is_attached());
1048 
1049  // Exit:
1050 
1051  return;
1052 }
1053 
1054 bool
1057  pod_type xindex) const
1058 {
1059  // Preconditions:
1060 
1061  require(xid_spaces.contains(xindex));
1062 
1063  // Body:
1064 
1065  const index_space_collection* lhost = xid_spaces.collection(xindex);
1066  bool result = conforms_to_state(*lhost, lhost->local_scope(xindex));
1067 
1068  // Postconditions:
1069 
1070  ensure(is_basic_query);
1071 
1072  // Exit:
1073 
1074  return result;
1075 }
1076 
1077 bool
1080  const std::string& xname) const
1081 {
1082  // Preconditions:
1083 
1084  require(xid_spaces.contains(xname));
1085 
1086  // Body:
1087 
1088  bool result = conforms_to_state(xid_spaces, xid_spaces.index(xname));
1089 
1090  // Postconditions:
1091 
1092  ensure(is_basic_query);
1093 
1094  // Exit:
1095 
1096  return result;
1097 }
1098 
1099 bool
1102 {
1103  // Preconditions:
1104 
1105  require(id_spaces().contains(xindex));
1106 
1107  // Body:
1108 
1109  bool result = conforms_to_state(id_spaces(), xindex);
1110 
1111  // Postconditions:
1112 
1113  ensure(is_basic_query);
1114 
1115  // Exit:
1116 
1117  return result;
1118 }
1119 
1120 bool
1122 conforms_to_state(const std::string& xname) const
1123 {
1124  // Preconditions:
1125 
1126  require(id_spaces().contains(xname));
1127 
1128  // Body:
1129 
1130  bool result = conforms_to_state(id_spaces(), xname);
1131 
1132  // Postconditions:
1133 
1134  ensure(is_basic_query);
1135 
1136  // Exit:
1137 
1138  return result;
1139 }
1140 
1141 bool
1144 {
1145  // Preconditions:
1146 
1147  // Body:
1148 
1149  // Any handle can conform to an unattached state.
1150 
1151  bool result = !xother.is_attached();
1152 
1153  if(!result)
1154  {
1155  // xother is attached to a state; check to see if this handle
1156  // conforms to the state of xother.
1157 
1158  if(is_attached() && (host() == xother.host()))
1159  {
1160  result = conforms_to_state(xother.index());
1161  }
1162  else
1163  {
1164  result = conforms_to_state(xother.id_spaces(), xother.index());
1165  }
1166  }
1167 
1168  // Postconditions:
1169 
1170  ensure(is_basic_query);
1171 
1172  // Exit:
1173 
1174  return result;
1175 }
1176 
1177 bool
1180  pod_type xlocal_id) const
1181 {
1182  // Preconditions:
1183 
1184  require(xhost.contains(xlocal_id));
1185 
1186  // Body:
1187 
1188  bool result = false;
1189 
1190  is_abstract();
1191 
1192  // Postconditions:
1193 
1194  ensure(is_basic_query);
1195 
1196  // Exit:
1197 
1198  return result;
1199 }
1200 
1201 // PROTECTED MEMBER FUNCTIONS
1202 
1203 // PRIVATE MEMBER FUNCTIONS
1204 
1205 
1206 // ===========================================================
1207 // HANDLE POOL FACET
1208 // ===========================================================
1209 
1210 // PUBLIC MEMBER FUNCTIONS
1211 
1215 {
1216  // Preconditions:
1217 
1218  require(is_attached());
1219 
1220  // Body:
1221 
1222  index_space_handle* result = 0; // Just to silence compiler warnings.
1223 
1224  is_abstract();
1225 
1226  // Postconditions:
1227 
1228  ensure(result->is_attached());
1229 
1230  // Exit:
1231 
1232  return *result;
1233 }
1234 
1235 void
1238 {
1239  // Preconditions:
1240 
1241  require(is_attached());
1242  require(allocated_id_space());
1243 
1244  // Body:
1245 
1246  is_abstract();
1247 
1248  // Postconditions:
1249 
1250  ensure(is_basic_query);
1251 
1252  // Exit:
1253 
1254  return;
1255 }
1256 
1257 bool
1260 {
1261  // Preconditions:
1262 
1263  require(is_attached());
1264 
1265  // Body:
1266 
1267  bool result = false; // Just to silence compiler warnings.
1268 
1269  is_abstract();
1270 
1271  // Postconditions:
1272 
1273  ensure(is_basic_query);
1274 
1275  // Exit:
1276 
1277  return result;
1278 }
1279 
1280 // PROTECTED MEMBER FUNCTIONS
1281 
1282 // PRIVATE MEMBER FUNCTIONS
1283 
1284 
1285 // ===========================================================
1286 // ITERATOR POOL FACET
1287 // ===========================================================
1288 
1289 // PUBLIC MEMBER FUNCTIONS
1290 
1294 {
1295  // Preconditions:
1296 
1297  require(is_attached());
1298 
1299  // Body:
1300 
1301  index_space_iterator* result = 0; // Just to silence compiler warnings.
1302 
1303  is_abstract();
1304 
1305  // Postconditions:
1306 
1307  ensure(result->is_attached());
1308 
1309  // Exit:
1310 
1311  return *result;
1312 }
1313 
1314 void
1317 {
1318  // Preconditions:
1319 
1320  require(is_attached());
1321  require(allocated_iterator(xitr));
1322 
1323  // Body:
1324 
1325  is_abstract();
1326 
1327  // Postconditions:
1328 
1329  ensure(is_basic_query);
1330 
1331  // Exit:
1332 
1333  return;
1334 }
1335 
1336 bool
1339 {
1340  // Preconditions:
1341 
1342  require(is_attached());
1343 
1344  // Body:
1345 
1346  bool result = false; // Just to silence compiler warnings.
1347 
1348  is_abstract();
1349 
1350  // Postconditions:
1351 
1352  ensure(is_basic_query);
1353 
1354  // Exit:
1355 
1356  return result;
1357 }
1358 
1359 // PROTECTED MEMBER FUNCTIONS
1360 
1361 // PRIVATE MEMBER FUNCTIONS
1362 
1363 
1364 // ===========================================================
1365 // ANY FACET
1366 // ===========================================================
1367 
1368 // PUBLIC MEMBER FUNCTIONS
1369 
1370 bool
1372 is_ancestor_of(const any *other) const
1373 {
1374  // Preconditions:
1375 
1376  require(other != 0);
1377 
1378  // Body:
1379 
1380  // True if other conforms to this
1381 
1382  bool result = dynamic_cast<const index_space_handle*>(other) != 0;
1383 
1384  // Postconditions:
1385 
1386  // Exit:
1387 
1388  return result;
1389 }
1390 
1391 bool
1393 invariant() const
1394 {
1395  bool result = true;
1396 
1397  if(invariant_check())
1398  {
1399  // Prevent recursive calls to invariant
1400 
1402 
1403  // Must satisfy base class invariant
1404 
1405  invariance(any::invariant());
1406 
1407  // Invariances for this class:
1408 
1409  invariance(is_attached() ? is_valid(index()) : true);
1410  invariance(is_attached() ? id_spaces().contains(index()) : true);
1411 
1412  // Finished, turn invariant checking back on.
1413 
1415  }
1416 
1417  // Exit
1418 
1419  return result;
1420 }
1421 
1422 // PROTECTED MEMBER FUNCTIONS
1423 
1424 // PRIVATE MEMBER FUNCTIONS
1425 
1426 
1427 // ===========================================================
1428 // NON-MEMBER FUNCTIONS
1429 // ===========================================================
1430 
1431 std::ostream&
1432 sheaf::
1433 operator << (std::ostream& xos, const index_space_handle& xi)
1434 {
1435  // Preconditions:
1436 
1437  // Body:
1438 
1439  using namespace std;
1440 
1441  if(xi.is_attached())
1442  {
1443  xos << "index_space:"
1444  << " index = " << xi.index()
1445  << " name = \'" << xi.name() << "\'"
1446  << endl;
1447 
1448  xos << "ct: " << xi.ct() << endl;
1449  xos << "begin: " << xi.begin() << endl;
1450  xos << "end: " << xi.end() << endl;
1451  xos << "persistent: " << boolalpha << xi.is_persistent() << noboolalpha << endl;
1452 
1453  xos << "ids: ";
1454  index_space_iterator& litr = xi.get_iterator();
1455  while(!litr.is_done())
1456  {
1457  xos << setw(10) << litr.pod();
1458  litr.next();
1459  }
1460  xos << endl;
1461 
1462  xos << "hub ids: ";
1463  litr.reset();
1464  while(!litr.is_done())
1465  {
1466  xos << setw(10) << litr.hub_pod();
1467  litr.next();
1468  }
1469  xos << endl;
1470  xi.release_iterator(litr);
1471  }
1472  else
1473  {
1474  xos << "index_space: index = -1 name = \'\'"
1475  << endl;
1476  }
1477 
1478  // Postconditions:
1479 
1480  // Exit:
1481 
1482  return xos;
1483 }
1484 
1485 size_t
1486 sheaf::
1487 deep_size(const index_space_handle& xn, bool xinclude_shallow)
1488 {
1489  // Preconditions:
1490 
1491  // Body:
1492 
1493  size_t result = xinclude_shallow ? sizeof(xn) : 0;
1494 
1495  // Postconditions:
1496 
1497  ensure(result >= 0);
1498 
1499  // Exit
1500 
1501  return result;
1502 }
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
const index_space_collection * collection(pod_type xid) const
Id space collection for id xid (const version).
virtual void delete_product_structure()=0
Deletes the product structure for this id space.
virtual bool has_product_structure() const =0
True if this id space has a product structure.
virtual bool allocated_id_space() const =0
True if and only if this id space handle was allocated by the handle pool.
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 is_empty() const
True if there are no ids in the space.
virtual const abstract_product_structure & product_structure() const =0
The product structure for this id space (const version).
virtual pod_type end() const =0
Ending id of this space.
An abstract iterator over the ids of an id space.
pod_type pod() const
The current id in the iteration.
virtual pod_type family_scope(pod_type xlocal_id) const =0
Id relative to the id space family equivalent to the local id xlocal_id.
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...
bool operator==(const index_space_handle &xother) const
True if this is a handle has the same state as xother.
STL namespace.
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 =0
The id space family for this (const version).
virtual pod_type unglued_hub_pod(pod_type xid) const =0
The pod index in the unglued hub id space equivalent to xid in this id space.
void put_name(pod_type xid, const std::string &xname)
Associate name xname with id space index xid.
virtual void release_id_space() const =0
Returns this id space handle to the handle pool.
virtual index_space_handle & get_id_space() const =0
Allocates an id space handle from the handle pool attached to the same id space.
virtual pod_type index() const =0
Index of this space.
virtual void next()=0
Makes id() the next id in the iteration.
index_space_handle()
Default constructor.
virtual bool is_attached() const =0
True if this handle is attached to a state.
virtual void detach()=0
Detach this handle form its state, if any.
virtual bool contains(pod_type xid) const =0
True if this space contains id xid.
An implementation of class sum_index_space_handle that has a primary sum id space state...
virtual bool contains_glued_hub(pod_type xid) const =0
True if this space contains an id equivalent to xid in the glued hub id space.
const hub_index_space_handle & hub_id_space() const
The hub id space.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
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.
virtual void reset()=0
Restarts the iteration.
Abstract base class with useful features for all objects.
Definition: any.h:39
bool is_done() const
True if iteration is finished.
std::string name() const
Name of this space.
pod_index_type pod_type
The "plain old data" index type for this.
virtual void release_iterator(index_space_iterator &xitr) const =0
Returns the id space iterator xitr to the iterator pool.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
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.
bool is_gathered() const
True if begin() == 0 and end() == ct().
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
void put_name(const std::string &xname)
Associate name xname with this id space.
bool conforms_to_state(const index_space_family &xid_spaces, pod_type xindex) const
True if this conforms to the handle type required by the state with index xindex in the id space fami...
virtual pod_type glued_hub_pod(pod_type xid) const =0
The pod index in the hub id space equivalent to xid in this id space. synonym for unglued_hub_pod(xid...
virtual size_type ct() const =0
The number of members.
virtual index_space_handle & operator=(const index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
virtual const index_space_collection & host() const =0
The host collection.
A collection of id space states. This is a virtual class with provides an interface for accessing the...
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
void attach_to(const index_space_family &xid_spaces, pod_type xindex)
Attach to the state with index xindex in the id space family xid_spaces.
virtual bool contains_unglued_hub(pod_type xid) const =0
True if this space contains an id equivalent to xid in the unglued hub id space.
virtual pod_type pod(pod_type xid) const =0
The pod index in this space equivalent to xid in the hub id space.
virtual bool contains(pod_type xlocal_id) const =0
True if this collection contains the id space with local id xlocal_id.
virtual pod_type begin() const =0
Beginning id of this space.
virtual index_space_iterator & get_iterator() const =0
Allocates an id space iterator from the iterator pool.
virtual bool allocated_iterator(const index_space_iterator &xitr) const =0
True if and only if id space iterator xitr was allocated by 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...
virtual bool is_persistent() const =0
True if this id space should be written to disk.
virtual bool is_attached() const =0
True if this iterator is attached to a state.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual void new_product_structure(const abstract_product_structure &xproduct)=0
Creates a new product structure for this id space by cloning the product structure, xproduct.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
virtual index_space_handle * clone() const =0
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
virtual bool invariant() const
Class invariant.
Factory and container for a family of id spaces.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
virtual ~index_space_handle()
Destructor.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
const hub_index_space_handle & hub_id_space() const
The hub id space of this family.
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710