SheafSystem  0.0.0.0
poset_component.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/poset_component.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/namespace_poset.h"
25 #include "SheafSystem/poset.h"
26 #include "SheafSystem/poset_state.h"
27 #include "SheafSystem/poset_crg_state.h"
28 #include "SheafSystem/pool.h"
29 #include "SheafSystem/std_typeinfo.h"
30 
31 using namespace std;
32 
33 // ===========================================================
34 // POSET_COMPONENT FACET
35 // ===========================================================
36 
37 // PUBLIC MEMBER FUNCTIONS
38 
41 {
42  // Preconditions:
43 
44  // Body:
45 
46  // Nothing todo.
47 
48  // Postconditions:
49 
50  // Exit:
51 
52  return;
53 }
54 
55 // PROTECTED MEMBER FUNCTIONS
56 
59 {
60  // Preconditions:
61 
62  // Body:
63 
64  _host = 0;
65 
66  _index.invalidate();
67 
68  _version = NOT_A_STANDARD_VERSION_INDEX;
69 
70  // Postconditions:
71 
72  ensure(invariant());
73  ensure(!is_attached());
74 
75  // Exit:
76 
77  return;
78 }
79 
82 state_obj() const
83 {
84  poset_state* result;
85 
86  // Precondition:
87 
88  // Body:
89 
90  result = _host != 0 ? _host->state_obj() : 0;
91 
92  // Note: poset_state_handle::invariant ensures _state != 0
93 
94  // Postcondition:
95 
96  ensure(_host == 0 ? result == 0 : true);
97 
98  // Exit:
99 
100  return result;
101 }
102 
105 powerset() const
106 {
107  return state_obj()->powerset();
108 }
109 
112 crg() const
113 {
114  return state_obj()->crg();
115 }
116 
119 powerset_member(const scoped_index& xindex) const
120 {
121  subposet_state* result;
122 
124 
125  // Preconditions:
126 
127  require(state_is_read_accessible());
128 
129  // Body:
130 
131  result = &(_host->powerset().member(xindex));
132 
133  // Postconditions:
134 
135  ensure(result != 0);
136 
137  // Exit
138 
139  return result;
140 }
141 
144 row_dof_tuple(const scoped_index& xindex) const
145 {
146  poset_dof_map* result;
147 
148  // Preconditions:
149 
150  require(state_is_read_accessible());
151 
152  // Body:
153 
154  result = state_obj()->table()->row_dof_tuple(xindex);
155 
156  // Postconditions:
157 
158  // Exit
159 
160  return result;
161 }
162 
163 void
166 {
167  // Preconditions:
168 
169  require(state_is_read_accessible());
170 
171  // Body:
172 
173  // Have just attached to a new or different host.
174  // Initialize the handle data members for the different host.
175 
176  // Nothing to do in this class; intended for redefintion in descendants.
177 
178  // Postconditions:
179 
180  ensure(unexecutable(data members created but not attached));
181 
182  // Exit
183 
184  return;
185 }
186 
187 void
190 {
191  // Preconditions:
192 
193  require(state_is_read_accessible());
194  require(unexecutable(data members created));
195 
196  // Body:
197 
198  // Have just attached to a new or different member in the same host.
199  // Attach the handle data members for the different member.
200 
201  // Nothing to do in this class; intended for redefintion in descendants.
202 
203  // Postconditions:
204 
205  ensure(unexecutable(data members attached()));
206 
207  // Exit
208 
209  return;
210 }
211 
212 // PRIVATE MEMBER FUNCTIONS
213 
214 
215 // ===========================================================
216 // COMPONENT INDEX FACET
217 // ===========================================================
218 
219 // PUBLIC MEMBER FUNCTIONS
220 
221 const sheaf::scoped_index&
223 index() const
224 {
225  // Preconditions:
226 
227  // Body:
228 
229  define_old_variable(const scoped_index& result = _index);
230 
231  // Postconditions:
232 
233  ensure(result.is_hub_scope() || !result.is_valid());
234  ensure(result.is_positive() || !result.is_valid());
235 
236  // Exit
237 
238  return _index;
239 }
240 
241 bool
243 is_valid_index(const poset_state_handle* xhost, pod_index_type xhub_id, int xversion) const
244 {
245  bool result = false;
246 
247  // Preconditions:
248 
249  require(xhost != 0);
250  require(xhost->state_is_read_accessible());
251  require(host_is_ancestor_of(xhost));
252 
253  // Body:
254 
255  is_abstract();
256 
257  // Postconditions:
258 
259  // Exit
260 
261  return result;
262 }
263 
264 bool
266 is_valid_index(const poset_state_handle* xhost, const scoped_index& xid, int xversion) const
267 {
268  bool result = false;
269 
270  // Preconditions:
271 
272  require(xhost != 0);
273  require(xhost->state_is_read_accessible());
274  require(host_is_ancestor_of(xhost));
275 
276  // Body:
277 
278  return is_valid_index(xhost, xid.hub_pod(), xversion);
279 }
280 
284 {
285  // Preconditions:
286 
287  require(state_is_read_accessible());
288 
289  // Body:
290 
291  static const hub_index_space_handle* result;
292 
293  is_abstract();
294 
295  // Postconditions:
296 
297  // Exit:
298 
299  return *result;
300 }
301 
302 const sheaf::scoped_index&
304 hub_id() const
305 {
306  // Preconditions:
307 
308  require(state_is_read_accessible());
309 
310  // Body:
311 
312  static const scoped_index result;
313 
314  is_abstract();
315 
316  // Postconditions:
317 
318  ensure(result.is_hub_scope());
319 
320  // Exit:
321 
322  return result;
323 }
324 
328 {
329  // Preconditions:
330 
331  require(state_is_read_accessible());
332 
333  // Body:
334 
335  static scoped_index result;
336 
337  is_abstract();
338 
339  // Postconditions:
340 
341  ensure(result.is_hub_scope());
342  ensure(result.pod() == xid);
343 
344  // Exit:
345 
346  return result;
347 }
348 
351 get_index_from_name(const poset_state_handle* xhost, const std::string& xname) const
352 {
353  // Preconditions:
354 
355  require(xhost != 0);
356  require(host_is_ancestor_of(xhost));
357  require(xhost->state_is_read_accessible());
358  require(!xname.empty());
359 
360  // Body:
361 
362  pod_index_type result = 0; // Just to silence the compiler.
363 
364  is_abstract();
365 
366  // Postconditions:
367 
368  // Exit
369 
370  return result;
371 }
372 
373 void
375 get_index_from_name(const poset_state_handle* xhost, const std::string& xname,
376  scoped_index& result) const
377 {
378  // Preconditions:
379 
380  require(xhost != 0);
381  require(host_is_ancestor_of(xhost));
382  require(xhost->state_is_read_accessible());
383  require(!xname.empty());
384 
385  // Body:
386 
387  is_abstract();
388 
389  // Postconditions:
390 
391  // Exit
392 
393  return;
394 }
395 
396 int
398 version(bool xunalias) const
399 {
400  int result;
401 
402  // Preconditions:
403 
404  require(xunalias ? state_is_read_accessible() : true);
405 
406  // Body:
407 
408  result = xunalias ? unaliased_version(_version) : _version;
409 
410  // Postconditions:
411 
412  ensure(result != CURRENT_MEMBER_VERSION);
413  ensure(xunalias ? (result != CURRENT_HOST_VERSION) : true);
414 
415  // Exit
416 
417  return result;
418 }
419 
420 void
422 put_version(int xversion, bool xunalias)
423 {
424  // Preconditions:
425 
426  require(xunalias ? state_is_read_accessible() : true);
427  require(has_version(xversion));
428  require(!xunalias ? xversion != CURRENT_MEMBER_VERSION : true);
429 
430  // Body:
431 
432  _version = xunalias ? unaliased_version(xversion) : xversion;
433 
434  // Postconditions:
435 
436  ensure(xunalias ?
437  version(false) == unaliased_version(xversion) :
438  version(false) == xversion);
439 
440  // Exit
441 
442  return;
443 }
444 
445 int
447 unaliased_version(int xversion) const
448 {
449  int result;
450 
451  // Preconditions:
452 
453  // Body:
454 
455  if(xversion == CURRENT_HOST_VERSION)
456  {
457  result = host()->version();
458  }
459  else if(xversion == CURRENT_MEMBER_VERSION)
460  {
461  result = _version;
462  if(result == CURRENT_HOST_VERSION)
463  {
464  result = host()->version();
465  }
466  }
467  else
468  {
469  result = xversion;
470  }
471 
472  // Postconditions:
473 
474 
475  ensure(result != CURRENT_HOST_VERSION);
476  ensure(result != CURRENT_MEMBER_VERSION);
477 
478  // Exit
479 
480  return result;
481 }
482 
486 {
487  // Preconditions:
488 
489  require(state_is_read_accessible());
490 
491  // Body:
492 
493  pod_index_type result = host()->version_index(version(true));
494 
495  // Postconditions:
496 
497  ensure(host()->includes_subposet(result));
498 
499  // Exit
500 
501  return result;
502 }
503 
504 void
507 {
508  // Preconditions:
509 
510  require(state_is_read_accessible());
511 
512  // Body:
513 
514  host()->version_index(version(true), result);
515 
516  // Postconditions:
517 
518  ensure(host()->includes_subposet(result));
519 
520  // Exit
521 
522  return;
523 }
524 
525 std::string
528 {
529  string result;
530 
531  // Preconditions:
532 
533  require(state_is_read_accessible());
534 
535  // Body:
536 
537  result = host()->version_to_name(version(true));
538 
539  // Postconditions:
540 
541  ensure(host()->includes_subposet(result));
542 
543  // Exit
544 
545  return result;
546 }
547 
548 bool
550 has_version(int xversion) const
551 {
552  bool result;
553 
554  // Preconditions:
555 
556  // Body:
557 
558  result = ((xversion == CURRENT_MEMBER_VERSION) ||
559  (xversion == CURRENT_HOST_VERSION) ||
560  host()->has_version(xversion));
561 
562  // Postconditions:
563 
564  ensure( result == ( (xversion == CURRENT_MEMBER_VERSION) ||
565  (xversion == CURRENT_HOST_VERSION) ||
566  host()->has_version(xversion)));
567 
568  // Exit
569 
570  return result;
571 }
572 
573 // PROTECTED MEMBER FUNCTIONS
574 
575 // PRIVATE MEMBER FUNCTIONS
576 
577 
578 // ===========================================================
579 // COMPONENT NAME FACET
580 // ===========================================================
581 
582 // PUBLIC MEMBER FUNCTIONS
583 
584 std::string
586 name() const
587 {
588  string result;
589 
590  // Preconditions:
591 
592  require(state_is_read_accessible());
593 
594  // Body:
595 
596  // Postconditions:
597 
598  ensure(unexecutable(result.empty() implies this has no name));
599 
600  // Exit:
601 
602  return name(false);
603 }
604 
605 std::string
607 name(bool xauto_access) const
608 {
609  string result;
610 
611  // Preconditions:
612 
613  require(xauto_access || state_is_read_accessible());
614 
615  // Body:
616 
617  is_abstract();
618 
619  // Postconditions:
620 
621  ensure(unexecutable(result.empty() implies this has no name));
622 
623  // Exit:
624 
625  return result;
626 }
627 
628 void
630 all_names(block<std::string>& xresult, bool xauto_access) const
631 {
632  // Preconditions:
633 
634  require(xauto_access || state_is_read_accessible());
635 
636  // Body:
637 
638  is_abstract();
639 
640  // Postconditions:
641 
642  ensure(xresult.ct() == name_ct(xauto_access));
643  ensure_for_all(i, 0, xresult.ct(), !xresult[i].empty());
644 
645  // Exit:
646 
647  return;
648 }
649 
652 name_ct(bool xauto_access) const
653 {
654  // Preconditions:
655 
656  require(xauto_access || state_is_read_accessible());
657 
658  // Body:
659 
660  size_type result = 0;
661 
662  is_abstract();
663 
664  // Postconditions:
665 
666  // Exit:
667 
668  return result;
669 }
670 
671 bool
673 has_name(const std::string& xname, bool xauto_access) const
674 {
675  // Preconditions:
676 
677  require(xauto_access || state_is_read_accessible());
678  require(!xname.empty());
679 
680  // Body:
681 
682  bool result = false;
683 
684  is_abstract();
685 
686  // Postconditions:
687 
688  // Exit:
689 
690  return result;
691 }
692 
693 void
695 put_name(const std::string& xname, bool xunique, bool xauto_access)
696 {
697  // Preconditions:
698 
699  require(is_attached());
700  require(xauto_access || state_is_read_write_accessible());
701  require(poset_path::is_valid_name(xname));
702 
703  // Body:
704 
705  is_abstract();
706 
707  // Postconditions:
708 
709  ensure(invariant());
710  ensure(xunique ? (name(xauto_access) == xname) : has_name(xname, xauto_access));
711 
712  // Exit
713 
714  return;
715 }
716 
717 void
719 delete_name(const std::string& xname, bool xauto_access)
720 {
721  // Preconditions:
722 
723  require(xauto_access || state_is_read_write_accessible());
724  require(!xname.empty());
725 
726  // Body:
727 
728  is_abstract();
729 
730  // Postconditions:
731 
732  ensure(!has_name(xname, xauto_access));
733 
734  // Exit:
735 
736  return;
737 }
738 
739 void
741 delete_all_names(bool xauto_access)
742 {
743  // Preconditions:
744 
745  require(xauto_access || state_is_read_write_accessible());
746 
747  // Body:
748 
749  is_abstract();
750 
751  // Postconditions:
752 
753  ensure(name_ct(xauto_access) == 0);
754 
755  // Exit:
756 
757  return;
758 }
759 
760 bool
762 is_valid_name(const poset_state_handle* xhost, const std::string& xname) const
763 {
764  bool result;
765 
766  // Preconditions:
767 
768  require(xhost != 0);
769  require(xhost->state_is_read_accessible());
770  require(!xname.empty());
771 
772  // Body:
773 
774  result = is_valid(get_index_from_name(xhost, xname));
775 
776  // Postconditions:
777 
778  ensure(unexecutable(xhost has a component of the same type as this with name xname));
779 
780  // Exit
781 
782  return result;
783 }
784 
787 path(bool xauto_access) const
788 {
789 
790  // Preconditions:
791 
792  require(is_attached());
793  require(xauto_access || state_is_read_accessible());
794 
795  if(xauto_access)
796  {
797  get_read_access();
798  }
799 
800  require(!name().empty());
801 
802  // Body:
803 
804  poset_path result(host()->name(), name());
805 
806  // Postconditions:
807 
808  ensure(result.poset_name() == host()->name());
809  ensure(result.member_name() == name());
810 
811  if(xauto_access)
812  {
813  release_access();
814  }
815 
816  // Exit:
817 
818  return result;
819 }
820 
821 bool
823 has_path(const poset_path& xpath, bool xauto_access) const
824 {
825  bool result;
826 
827  // Preconditions:
828 
829  require(state_is_auto_read_accessible(xauto_access));
830 
831  // Body:
832 
833  if(xauto_access)
834  {
835  get_read_access();
836  }
837 
838  result =
839  (host()->name() == xpath.poset_name())
840  && has_name(xpath.member_name(), xauto_access);
841 
842  if(xauto_access)
843  {
844  release_access();
845  }
846 
847  // Postconditions:
848 
849  // Exit:
850 
851  return result;
852 }
853 
854 // PROTECTED MEMBER FUNCTIONS
855 
856 // PRIVATE MEMBER FUNCTIONS
857 
858 
859 // ===========================================================
860 // HOST POSET FACET
861 // ===========================================================
862 
863 // PUBLIC MEMBER FUNCTIONS
864 
867 host() const
868 {
869  poset_state_handle* result;
870 
871  // Preconditions:
872 
873  // Body:
874 
875  result = _host;
876 
877  // Postconditions:
878 
879  // Exit
880 
881  return result;
882 }
883 
884 bool
887 {
888  bool result;
889 
890  // Preconditions:
891 
892  // Body:
893 
894  // Given the signature, the following is always true:
895  // result = dynamic_cast<const poset_state_handle*>(xother) != 0;
896 
897  result = true;
898 
899  // Postconditions:
900 
901  // Exit
902 
903  return result;
904 }
905 
906 bool
908 has_same_host(const poset_component* xother) const
909 {
910  bool result;
911 
912  // Preconditions:
913 
914  // Body:
915 
916  if(xother == 0)
917  {
918  result = false;
919  }
920  else if(is_attached())
921  {
922  result = xother->is_attached() && (xother->host()->is_same_state(host()));
923  }
924  else
925  {
926  result = !xother->is_attached();
927  }
928 
930 
931  // Postconditions:
932 
933  // ensure(result == ((xother != 0) && (xother->host()->is_same_state(host()))));
934 
935  // Exit
936 
937  return result;
938 }
939 
940 // PROTECTED MEMBER FUNCTIONS
941 
942 // PRIVATE MEMBER FUNCTIONS
943 
944 
945 // ===========================================================
946 // NAMESPACE FACET
947 // ===========================================================
948 
949 // PUBLIC MEMBER FUNCTIONS
950 
953 name_space() const
954 {
955  namespace_poset* result;
956 
957  // Preconditions:
958 
959  // Body:
960 
961  result = host()->name_space();
962 
963  // Postconditions:
964 
965  // Exit
966 
967  return result;
968 }
969 
970 bool
973 {
974  bool result;
975 
976  // Preconditions:
977 
978  require(xother != 0);
979 
980  // Body:
981 
982  // Given the signature, the following is always true:
983  // result = dynamic_cast<namespace_poset*>(xother) != 0;
984  // Intended to be redefined in descendants.
985 
986  result = true;
987 
988  // Postconditions:
989 
990  // Exit
991 
992  return result;
993 }
994 
995 bool
997 same_namespace(const poset_component* xother) const
998 {
999  bool result;
1000 
1001  // Preconditions:
1002 
1003  // Body:
1004 
1005  if(is_attached() && xother->is_attached())
1006  {
1007  // both attached, so true if in same namespace
1008  result = host()->host()->is_same_state(xother->host()->host());
1009  }
1010  else
1011  {
1012  // not both attached, so true if both unattached
1013  result = (!is_attached()) && (!xother->is_attached());
1014  }
1015 
1016  // Postconditions:
1017 
1018  ensure(unexecutable(true if hosts of this and xother are in same namespace or if this and xother both unattached));
1019 
1020  // Exit
1021 
1022  return result;
1023 }
1024 
1025 bool
1028 {
1029  bool result;
1030 
1031  // Preconditions:
1032 
1033  // Body:
1034 
1035  if(is_attached() && xother->is_attached())
1036  {
1037  // both attached, so true if in same namespace
1038  result = host()->host()->is_same_state(xother->host());
1039  }
1040  else
1041  {
1042  // not both attached, so true if both unattached
1043  result = (!is_attached()) && (!xother->is_attached());
1044  }
1045 
1046  // Postconditions:
1047 
1048  ensure(unexecutable("true if hosts of this and xother are in same namespace or if this and xother both unattached"));
1049 
1050  // Exit
1051 
1052  return result;
1053 }
1054 
1055 // PROTECTED MEMBER FUNCTIONS
1056 
1057 // PRIVATE MEMBER FUNCTIONS
1058 
1059 
1060 // ===========================================================
1061 // STATE FACET
1062 // ===========================================================
1063 
1064 // PUBLIC MEMBER FUNCTIONS
1065 
1066 void
1069 {
1070  // Preconditions:
1071 
1072  require(xhost != 0);
1073  require(host_is_ancestor_of(xhost));
1074  require(xhost->state_is_read_accessible());
1075  require(is_valid_index(xhost, xhub_id));
1076 
1079 
1082 
1083  // Body:
1084 
1085  // Attach to the new or different host.
1086 
1087  _host = const_cast<poset_state_handle*>(xhost);
1088  _index = hub_id();
1089 
1090  // The following does not work because the standard members
1091  // must be attached before the poset is attached to the namespace.
1092 
1093  // Use the host pointer held by the namespace to avoid
1094  // holding a dangling reference if xhost deleted.
1095 
1096  // _host = xhost->name_space()->member_poset(xhost->index());
1097 
1098 
1099  // Initialize the handle data members, if any;
1100  // does not attach them.
1101 
1102  init_handle_data_members();
1103 
1104  // Initialize the version to the current version of the host.
1105 
1106  _version = CURRENT_HOST_VERSION;
1107 
1108  // Attach to the new or different member;
1109  // attaches the handle data members, if any.
1110 
1111  attach_to_state(xhub_id);
1112 
1113  // Postconditions:
1114 
1115  ensure(is_attached());
1116  ensure(host()->is_same_state(xhost));
1117  ensure(index().is_hub_scope());
1118  ensure(index() == xhub_id);
1119  ensure(version() == xhost->version());
1120  ensure(postcondition_of(attach_handle_data_members()));
1121 
1122  // Exit:
1123 
1124  return;
1125 }
1126 
1127 void
1130 {
1131  // Preconditions:
1132 
1133  require(xhost != 0);
1134  require(host_is_ancestor_of(xhost));
1135  require(xhost->state_is_read_accessible());
1136  require(is_valid_index(xhost, xid));
1137 
1138  // Body:
1139 
1140  attach_to_state(xhost, xid.hub_pod());
1141 
1142  // Postconditions:
1143 
1144  ensure(is_attached());
1145  ensure(host()->is_same_state(xhost));
1146  ensure(index().is_hub_scope());
1147  ensure(index() ==~ xid);
1148  ensure(version() == xhost->version());
1149  ensure(postcondition_of(attach_handle_data_members()));
1150 
1151  // Exit:
1152 
1153  return;
1154 }
1155 
1156 void
1158 attach_to_state(const poset_state_handle* xhost, const std::string& xname)
1159 {
1160  // Preconditions:
1161 
1162  require(xhost != 0);
1163  require(host_is_ancestor_of(xhost));
1164  require(xhost->state_is_read_accessible());
1165  require(is_valid_name(xhost, xname));
1166 
1167  // Body:
1168 
1169  pod_index_type lindex = get_index_from_name(xhost, xname);
1170 
1171  attach_to_state(xhost, lindex);
1172 
1173  // Postconditions:
1174 
1175  ensure(is_attached());
1176  ensure(host() == xhost);
1177  ensure(has_name(xname));
1178  ensure(postcondition_of(attach_handle_data_members()));
1179 }
1180 
1181 void
1183 attach_to_state(const std::string& xname)
1184 {
1185  // Preconditions:
1186 
1187  require(state_is_read_accessible());
1188  require(!xname.empty());
1189  require(is_valid_name(host(), xname));
1190  require(precondition_of(attach_to_state(get_index_from_name(host(), xname))));
1191 
1192  // Body:
1193 
1194  attach_to_state(get_index_from_name(host(), xname));
1195 
1196  // Postconditions:
1197 
1198  ensure(postcondition_of(attach_to_state(get_index_from_name(host(), xname))));
1199 
1200  // Exit:
1201 
1202  return;
1203 }
1204 
1205 void
1208 {
1209  // preconditions:
1210 
1211  require(state_is_read_accessible());
1212  require(is_valid_index(host(), xhub_id, version(false)));
1213 
1214  // Body:
1215 
1216  define_old_variable(poset_state_handle* old_host = _host);
1217  define_old_variable(int old_version = _version);
1218 
1219  // Attach to the new or different member;
1220 
1221  _index = xhub_id;
1222 
1223  // Leave version unchanged.
1224 
1225  // Attach the data members, if any, to the new or different member.
1226 
1227  attach_handle_data_members();
1228 
1229  // postconditions:
1230 
1231  ensure(is_attached());
1232  ensure(host() == old_host);
1233  ensure(index().is_hub_scope());
1234  ensure(index() == xhub_id);
1235  ensure(version(false) == old_version);
1236  ensure(postcondition_of(attach_handle_data_members()));
1237 }
1238 
1239 void
1242 {
1243  // preconditions:
1244 
1245  require(state_is_read_accessible());
1246  require(is_valid_index(host(), xid, version(false)));
1247 
1248  // Body:
1249 
1250  define_old_variable(poset_state_handle* old_host = _host);
1251  define_old_variable(int old_version = _version);
1252 
1253  attach_to_state(xid.hub_pod());
1254 
1255  // postconditions:
1256 
1257  ensure(is_attached());
1258  ensure(host() == old_host);
1259  ensure(index().is_hub_scope());
1260  ensure(index() ==~ xid);
1261  ensure(version(false) == old_version);
1262  ensure(postcondition_of(attach_handle_data_members()));
1263 }
1264 
1265 void
1268 {
1269  // Preconditions:
1270 
1271  require(xother != 0);
1272 
1277 
1278  // require(is_ancestor_of(xother));
1279  require(xother->is_attached() ? xother->state_is_read_accessible() : true);
1280 
1281  // Body:
1282 
1283  if(is_attached())
1284  {
1285  if(xother->is_attached())
1286  {
1287  // Both this and other are already attached.
1288 
1289  if(!_host->is_same_state(xother->host()))
1290  {
1291  // We're attaching to a different host;
1292  // have to initialize the handle data members.
1293 
1294  _host = xother->host();
1295  init_handle_data_members();
1296  }
1297 
1298  _index = xother->index();
1299 
1300  // Want version data members to be identical,
1301  // without binding to current version number
1302  // See poset_component::version()
1303 
1304  _version = xother->_version;
1305  attach_handle_data_members();
1306  }
1307  else
1308  {
1309  // This is attached, but not other;
1310  // detach this.
1311 
1312  detach_from_state();
1313  }
1314  }
1315  else
1316  {
1317  // This is not already attached;
1318 
1319  if(xother->is_attached())
1320  {
1321  _host = xother->host();
1322  _index = xother->index();
1323 
1324  // Want version data members to be identical,
1325  // without binding to current version number.
1326  // See poset_component::version()
1327 
1328  _version = xother->_version;
1329  init_handle_data_members();
1330  attach_handle_data_members();
1331  }
1332  }
1333 
1334  // Postconditions:
1335 
1336  ensure(is_same_state(xother));
1337  // ensure(is_attached() ? version() == xother->version(): true);
1338  ensure(version(false) == xother->version(false));
1339  // ensure(!is_restricted()); // True in abstract_poset_member but not defined here.
1340 
1341  // Exit:
1342 
1343  return;
1344 }
1345 
1346 void
1348 attach_to_state(const poset_component* xother, bool xauto_access)
1349 {
1350 
1351  // Preconditions:
1352 
1353  require(xother != 0);
1354  require(xother->is_attached() ?
1355  (xauto_access || xother->state_is_read_accessible()) :
1356  true);
1357 
1358  // Body:
1359 
1360  if(xauto_access && xother->is_attached())
1361  {
1362  xother->get_read_access();
1363  }
1364 
1365  attach_to_state(xother);
1366 
1367  if(xauto_access && xother->is_attached())
1368  {
1369  xother->release_access();
1370  }
1371 
1372  // Postconditions:
1373 
1374  ensure(postcondition_of(attach_to_state(xother)));
1375 
1376  // Exit:
1377 
1378  return;
1379 }
1380 
1381 void
1384 {
1385 
1386  // Preconditions:
1387 
1388  // Body:
1389 
1390  _host = 0;
1391 
1392  _index.invalidate();
1393 
1394  _version = NOT_A_STANDARD_VERSION_INDEX;
1395 
1396  // Postconditions:
1397 
1398  // Both detach_from_state and invariant may be redefined in
1399  // descendants. We can only be responsible for maintaining
1400  // poset_component's invariant.
1401 
1402  ensure(poset_component::invariant());
1403  ensure(!is_attached());
1404 }
1405 
1406 
1407 bool
1410 {
1411  bool result;
1412 
1413  // Preconditions:
1414 
1415  // Body:
1416 
1417  result = (_host != 0) && (_index.is_positive());
1418 
1419  // Postconditions:
1420 
1421  ensure(result == ((host() != 0) && (index().is_positive())));
1422 
1423  // Exit
1424 
1425  return result;
1426 }
1427 
1428 bool
1431 {
1432  bool result;
1433 
1434  // Preconditions:
1435 
1436  require(xhost != 0 ? host_is_ancestor_of(xhost) : true);
1437 
1438  // Body:
1439 
1440  // "is_same_state" is state equality - a.is_same_state(b) if both a and b
1441  // refer to the same poset member state.If both are attached, they must have
1442  // the same poset state and same index. If neither are attached,
1443  // they are both considered to be attached to the (unique) void object,
1444  // and hence must have the same host and index.
1445  // If one is attached and the other not, they will have different
1446  // host and index.
1447 
1448  result = ( (xhost != 0) && (xhost->state_obj() == state_obj()) && (index() == xhub_id) );
1449 
1450  // Postconditions:
1451 
1452  // Exit
1453 
1454  return result;
1455 }
1456 
1457 bool
1459 is_same_state(const poset_state_handle* xhost, const scoped_index& xid) const
1460 {
1461  bool result;
1462 
1463  // Preconditions:
1464 
1465  require(xhost != 0 ? host_is_ancestor_of(xhost) : true);
1466 
1467  // Body:
1468 
1469  return is_same_state(xhost, xid.hub_pod());
1470 }
1471 
1472 bool
1474 is_same_state(const poset_component* xother) const
1475 {
1476  bool result = true;
1477 
1478  // Preconditions:
1479 
1480  // Body:
1481 
1482  // "is_same_state" is state equality - a.is_same_state(b) if both a and b
1483  // refer to the same component state. If both are attached, they must have
1484  // the same poset state and same index. If neither are attached,
1485  // they are both considered to be attached to the (unique) void object,
1486  // and hence must have the same host and index.
1487  // If one is attached and the other not, they will have different
1488  // host and index. Both must be the same type of component.
1489 
1490  result = result && (xother != 0);
1491  result = result && (xother->state_obj() == state_obj());
1492  result = result && (xother->index() == index());
1493 
1498 
1499  // Postconditions:
1500 
1501  // Exit
1502 
1503  return result;
1504 }
1505 
1506 // PROTECTED MEMBER FUNCTIONS
1507 
1508 // PRIVATE MEMBER FUNCTIONS
1509 
1510 
1511 // ===========================================================
1512 // STATE ACCESS CONTROL FACET
1513 // ===========================================================
1514 
1515 // PUBLIC MEMBER FUNCTIONS
1516 
1517 void
1520 {
1521  // Preconditions:
1522 
1523  require(is_attached());
1524 
1525  // Body:
1526 
1527  int old_access_request_depth = host()->access_request_depth();
1528 
1529  host()->get_read_access();
1530 
1531  // Postconditions:
1532 
1533  ensure(state_is_read_accessible());
1534  ensure(access_request_depth() == old_access_request_depth + 1);
1535 }
1536 
1537 void
1539 get_read_write_access(bool xrelease_read_only_access)
1540 {
1541  // Preconditions:
1542 
1543  require(is_attached());
1544  require(!xrelease_read_only_access ? state_is_not_read_only_accessible() : true);
1545 
1546 
1547  // Body:
1548 
1549  int old_access_request_depth = host()->access_request_depth();
1550 
1551  host()->get_read_write_access(xrelease_read_only_access);
1552 
1553  // Postconditions:
1554 
1555  ensure(state_is_read_write_accessible());
1556  ensure(access_request_depth() == old_access_request_depth + 1);
1557 }
1558 
1559 void
1561 release_access(bool xall) const
1562 {
1563  // Preconditions:
1564 
1565  require(state_is_read_accessible());
1566 
1567  // Body:
1568 
1569  int old_access_request_depth = host()->access_request_depth();
1570 
1571  host()->release_access(xall);
1572 
1573  // Postconditions:
1574 
1575  ensure(xall ?
1576  access_request_depth() == 0 :
1577  access_request_depth() == old_access_request_depth - 1);
1578  ensure(access_request_depth() == 0 ? state_is_not_read_accessible() : true);
1579 }
1580 
1581 // PROTECTED MEMBER FUNCTIONS
1582 
1583 // PRIVATE MEMBER FUNCTIONS
1584 
1585 
1586 // ===========================================================
1587 // ANY FACET
1588 // ===========================================================
1589 
1590 // PUBLIC MEMBER FUNCTIONS
1591 
1592 bool
1594 is_ancestor_of(const any* xother) const
1595 {
1596  bool result;
1597 
1598  // Preconditions:
1599 
1600  // Body:
1601 
1602  result = dynamic_cast<const poset_component*>(xother) != 0;
1603 
1604  // Postconditions:
1605 
1606  // Exit
1607 
1608  return result;
1609 }
1610 
1611 bool
1613 invariant() const
1614 {
1615  bool result = true;
1616 
1617  // Preconditions:
1618 
1619  // Body:
1620 
1621  // Must satisfy base class invariant
1622 
1623  result = result && read_write_monitor_handle::invariant();
1624 
1625  if(invariant_check())
1626  {
1627  // Prevent recursive calls to invariant
1628 
1629  disable_invariant_check();
1630 
1631  // Invariants for this class:
1632 
1633  result = result && ((_host == 0) ? (!_index.is_valid()) : (_index.is_hub_scope()));
1634 
1635  result = result && (_version != CURRENT_MEMBER_VERSION);
1636 
1637  // Finished, turn invariant checking back on.
1638 
1639  enable_invariant_check();
1640  }
1641 
1642  // Postconditions:
1643 
1644  // Exit
1645 
1646  return result;
1647 }
1648 
1649 // PROTECTED MEMBER FUNCTIONS
1650 
1651 // PRIVATE MEMBER FUNCTIONS
1652 
1653 
1654 // ===========================================================
1655 // NON-MEMBER FUNCTIONS
1656 // ===========================================================
1657 
1658 size_t
1659 sheaf::deep_size(const poset_component& xp, bool xinclude_shallow)
1660 
1661 {
1662  size_t result;
1663 
1664  // Preconditions:
1665 
1666  // Body:
1667 
1668  result = xinclude_shallow ? sizeof(xp) : 0;
1669 
1670  // Postconditions:
1671 
1672  ensure(result >= 0);
1673 
1674  // Exit
1675 
1676  return result;
1677 }
virtual void put_version(int xversion, bool xunalias=false)
Sets version to (possibly aliased) xversion. If unalias == true, set version to the actual version al...
virtual pod_index_type get_index_from_name(const poset_state_handle *xhost, const std::string &xname) const =0
Gets the index of the component in xhost with name xname.
poset_state_handle * host() const
The poset which this is a handle to a component of.
poset_component()
Default constructor.
bool has_path(const poset_path &xpath, bool xauto_access) const
True if and only if xpath refers to this component.
virtual ~poset_component()
Destructor.
int unaliased_version(int xversion) const
The actual version associated with (possibly aliased) version xversion in this.
The data structure representing the cover relation graph of a poset.
poset_dof_map * row_dof_tuple(const scoped_index &xindex) const
The row dof tuple associated with xindex.
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
size_type ct() const
The number of items currently in use.
poset_crg_state * crg() const
The cover relation graph of host().
The private state of a partially ordered set.
Definition: poset_state.h:49
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
virtual bool has_name(const std::string &xname, bool xauto_access=false) const =0
True if xname is a name for this.
virtual poset_state * state_obj() const
State object for this poset.
pod_index_type version_index() const
The subposet index for the filter associated with version().
poset_path path(bool xauto_access=true) const
A path to this component.
The default name space; a poset which contains other posets as members.
virtual subposet_state * powerset_member(const scoped_index &xindex) const
The hidden state of the subposet asocciated with index xindex.
virtual void delete_name(const std::string &xname, bool xauto_access=false)=0
Delete all names for this.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual bool is_ancestor_of(const any *other) const
True if other conforms to current.
The data structure representing the state of a subposet.
virtual void all_names(block< std::string > &xresult, bool xauto_access=false) const =0
All the names for this.
A client handle for a general, abstract partially order set.
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
bool is_same_state(const poset_state_handle *xhost, pod_index_type xhub_id) const
True is this is attached to state with hub id xhub_id in host xhost.
virtual int version() const
The current version.
virtual void get_read_access() const
Get read access to the state associated with this.
virtual void put_name(const std::string &xname, bool xunique, bool xauto_access)=0
Make xname a name for this; if xunique, make xname the only name.
virtual namespace_poset * name_space() const
The namespace of host()
Features shared by poset_member and subposet. Subposet and poset_member objects can be attached...
const scoped_index & index() const
The index of the component state this handle is attached to.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
namespace_poset * host() const
The namespace this poset resides in. Obsolete; use name_space() instead.
An implementation of class sum_index_space_handle that has a primary sum id space state...
void attach_to_state(const poset_state_handle *xhost, pod_index_type xhub_id)
Attach this handle to the state with hub id xhub_id in the current version of host xhost...
bool is_hub_scope() const
True if and only if the id space of this is the hub id space.
Definition: scoped_index.h:575
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
virtual const scoped_index & hub_id() const =0
A id in the hub id space for components of this type; intended for copying to initialize ids to the h...
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual void attach_handle_data_members()
Initializes handle data members when attaching to a different member of the same host; intended to be...
bool has_same_host(const poset_component *xother) const
True if xother is attached to the same host as this or if both are unattached.
virtual bool host_is_ancestor_of(const poset_state_handle *xther) const
True if xother conforms to host.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual const hub_index_space_handle & hub_id_space() const =0
The hub id space; const version.
virtual bool is_attached() const
True if this handle is attached to a non-void state.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
std::string poset_name() const
The poset name part of the path.
Definition: poset_path.cc:473
virtual size_type name_ct(bool xauto_access) const =0
The number of names for this.
int _version
The version of this component. The version of the host used when evaluating properties of this compon...
bool same_namespace(const poset_component *xother) const
True if the host of xother resides in the same namespace as this or if both are unattached.
virtual void detach_from_state()
Detach this handle from its state, if any.
namespace_poset * name_space() const
The namespace this poset resides in.
virtual bool is_attached() const
True if this is attached to a state.
virtual void get_read_write_access(bool xrelease_read_only_access=false)
Get read write access to the state associated with this. If release_read_only_access is requested...
poset_powerset_state * powerset() const
The set of subposets of host().
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
std::string name() const
OBSOLETE: use name(bool xauto_access). A name for this.
std::string member_name() const
The member name part of the path.
Definition: poset_path.cc:511
virtual void delete_all_names(bool xauto_access=false)=0
Delete all the names for this.
virtual bool is_valid_index(const poset_state_handle *xhost, pod_index_type xhub_id, int xversion=CURRENT_HOST_VERSION) const =0
True if there exists a component of the same type as this with hub id xhub_id in version xversion of ...
bool is_same_state(const poset_state_handle *xother) const
True if this is attached to the same state as xother.
poset_state * state_obj() const
The state this component handle is attached to.
virtual bool invariant() const
Class invariant.
virtual void init_handle_data_members()
Initializes handle data members when attaching to a different member in a different host; intended to...
bool is_valid_name(const poset_state_handle *xhost, const std::string &xname) const
True if there exists a component as the same type as this in xhost with name xname.
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
std::string version_name() const
The subposet name for the filter associated with version().
The set of subsets of a poset.
bool has_version(int xversion) const
True if xversion is a valid version for this.
virtual bool namespace_is_ancestor_of(const namespace_poset *xother) const
True if xother conforms to name_space().
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710