SheafSystem  0.0.0.0
poset_crg_state.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #include "SheafSystem/poset_crg_state.impl.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/deep_size.h"
25 #include "SheafSystem/explicit_crg_interval.h"
26 #include "SheafSystem/factory.h"
27 #include "SheafSystem/implicit_crg_interval.h"
28 #include "SheafSystem/interval_index_space_handle.h"
29 #include "SheafSystem/interval_index_space_state.h"
30 #include "SheafSystem/list_index_space_handle.h"
31 #include "SheafSystem/list_index_space_state.h"
32 #include "SheafSystem/primary_index_space_handle.h"
33 #include "SheafSystem/poset_path.h"
34 #include "SheafSystem/std_iomanip.h"
35 #include "SheafSystem/std_iostream.h"
36 #include "SheafSystem/std_set.h"
37 #include "SheafSystem/std_string.h"
38 
39 using namespace std;
40 using namespace unordered;
41 
42 // ===========================================================
43 // POSET_CRG_STATE FACET
44 // ===========================================================
45 
46 // PUBLIC MEMBER FUNCTIONS
47 
50 {
51  // Preconditions:
52 
53  // Body:
54 
55  // Set _begin to 0 in the hub id space.
56 
57  _begin.put(hub_id_space(), 0);
58 
59  // Set _end to 0 in the hub id space.
60 
61  _end.put(hub_id_space(), 0);
62 
63  // Set counts to 0.
64 
65  _member_ct = 0;
66  _standard_member_ct = 0;
67  _jim_edit_depth = 0;
68 
69  // Postconditions:
70 
71  ensure(begin().is_hub_scope());
72  ensure(begin() == 0);
73  ensure(end().is_hub_scope());
74  ensure(standard_member_ct() == 0);
75  ensure(member_ct() == 0);
76  ensure(jim_edit_depth() == 0);
77 }
78 
81 {
82  // Preconditions:
83 
84  // Body:
85 
86  // Delete the intervals.
87 
88  interval_map_type::iterator li_itr;
89 
90  for(li_itr = _interval_map.begin();
91  li_itr != _interval_map.end();
92  ++li_itr)
93  {
94  if(li_itr->second != 0)
95  {
96  delete li_itr->second;
97  }
98  }
99 
100  // Dof tuple ids will be deleted automatically.
101 
102  // Postconditions:
103 
104  // Exit:
105 
106  return;
107 }
108 
109 // PROTECTED MEMBER FUNCTIONS
110 
111 // PRIVATE MEMBER FUNCTIONS
112 
113 
114 // ===========================================================
115 // MEMBERSHIP (NODES) FACET
116 // ===========================================================
117 
118 // PUBLIC MEMBER FUNCTIONS
119 
123 {
124  // Preconditions:
125 
126  // Body:
127 
128  define_old_variable(scoped_index old_end = _end);
129  define_old_variable(size_type old_member_ct = _member_ct);
130 
131  pod_index_type result = _id_spaces.new_id();
132 
133  // Update the upper bound on the member index.
134 
135  _end = hub_id_space().end();
136 
137  // Increment the member counter.
138 
139  ++_member_ct;
140 
141  // Initialize the upper and lower cover of the member.
142 
143  initialize_member_covers(result);
144 
145  // No entry in dof tuple map or name map to start with.
146 
147  // Postconditions:
148 
149  ensure(end() >= old_end);
150  ensure(member_ct() == old_member_ct + 1);
151  ensure(contains_explicit_member(result));
152  ensure(cover_is_empty(LOWER, result));
153  ensure(cover_is_empty(UPPER, result));
154 
155  // Exit:
156 
157  return result;
158 }
159 
160 void
163 {
164  // Preconditions:
165 
166  require(!contains_member(xid));
167  require(id_spaces().is_valid_reserved_id(xid));
168 
169  // Body:
170 
171  define_old_variable(scoped_index old_end = end());
172  define_old_variable(size_type old_member_ct = _member_ct);
173 
174  _id_spaces.new_id(xid);
175 
176  // Update the upper bound on the member index.
177 
178  _end = hub_id_space().end();
179 
180  // Increment the member counter.
181 
182  ++_member_ct;
183 
184  // Initialize the upper and lower cover of the member.
185 
186  initialize_member_covers(xid);
187 
188  // No entry in dof tuple map or name map to start with.
189 
190  // Postconditions:
191 
192  ensure(end() >= old_end);
193  ensure(member_ct() == old_member_ct + 1);
194  ensure(contains_explicit_member(xid));
195  ensure(cover_is_empty(LOWER, xid));
196  ensure(cover_is_empty(UPPER, xid));
197 
198  return;
199 }
200 
201 
202 void
205 {
206  // Preconditions:
207 
208  require((xid == BOTTOM_INDEX) || (xid == TOP_INDEX));
209 
210  // Body:
211 
212  define_old_variable(size_type old_member_ct = _member_ct);
213 
214  // Update the upper bound on the member index.
215 
216  _end = xid + 1;
217 
218  // Increment the member counter.
219 
220  ++_member_ct;
221 
222  // Initialize the upper and lower cover of the member.
223 
224  initialize_member_covers(xid, true);
225 
226  // No entry in dof tuple map or name map to start with.
227 
228  // Postconditions:
229 
230  ensure(end() >= xid + 1);
231  ensure(member_ct() == old_member_ct + 1);
232  ensure(contains_explicit_member(xid));
233  ensure(cover_is_empty(LOWER, xid));
234  ensure(cover_is_empty(UPPER, xid));
235 
236  return;
237 }
238 
241 new_member_interval(const std::string& xinterval_type, size_type xsize)
242 {
243  // Preconditions:
244 
245  require(crg_interval::interval_factory().contains_prototype(xinterval_type));
246  require(xsize > 0);
247 
248  // Body:
249 
250  define_old_variable(scoped_index old_end = end());
251  define_old_variable(size_type old_member_ct = _member_ct);
252 
253  // Allocate a interval of ids.
254 
255  pod_index_type lspace_id = _id_spaces.new_primary_state(xsize);
256  primary_index_space_handle lid_space(_id_spaces, lspace_id);
257 
258  pod_index_type result = lid_space.offset();
259 
260  // Update the upper bound on the member index.
261 
262  _end = hub_id_space().end();
263 
264  // Increment the member counter.
265 
266  _member_ct += xsize;
267 
268  // Create the interval emulator and set its size and local id map.
269  // The local id map for the interval is the term id map from the hub id space.
270 
271  crg_interval* linterval = crg_interval::new_interval(xinterval_type);
272 
273  linterval->initialize_id_spaces(_id_spaces);
274  linterval->initialize_local_id_space(lid_space);
275 
276  // Put the emulator in the implicit member map.
277 
278  // The entire index interval of the emulator is mapped to the emulator
279  // by making a single entry for the end of the interval and using the
280  // upper_bound query on the map. See member function interval().
281  // Maps use internal (poset) id space.
282 
283  _interval_map[hub_id_space().end()] = linterval;
284 
285  // Make sure that ids below begin() do not map to this member by making sure
286  // there's an entry at the end of the preceeding interval == begin of this interval.
287 
288  if(_interval_map.find(result) == _interval_map.end())
289  {
290  _interval_map[result] = 0;
291  }
292 
293  interval_map_type::const_iterator itr = _interval_map.begin();
294  while(itr != _interval_map.end())
295  {
296  ++itr;
297  }
298 
299  // Postconditions:
300 
301  ensure(end() >= old_end + xsize);
302  ensure(member_ct() == old_member_ct + xsize);
303  ensure(interval(result).id_spaces_initialized());
304  ensure(interval(result).local_id_space_initialized());
305  ensure_for_range(pod_index_type i = result, i < end().pod(), ++i, contains_member(i));
306  ensure(unexecutable("atoms not in upper cover of bottom"));
307 
308  return result;
309 }
310 
311 void
313 new_member_interval(pod_index_type xid, const std::string& xinterval_type, size_type xsize)
314 {
315  // Preconditions:
316 
317  require(is_valid(xid));
318  require_for_range(pod_index_type i=0, i<xsize, ++i, !contains_member(xid + i));
319  require(crg_interval::interval_factory().contains_prototype(xinterval_type));
320  require(xsize > 0);
321 
322  // Body:
323 
324  define_old_variable(scoped_index old_end = end());
325  define_old_variable(size_type old_member_ct = _member_ct);
326 
327  // Allocate a interval of ids, if needed.
328 
329  _id_spaces.new_primary_state(xid, xsize);
330 
331  // Update the upper bound on the member index.
332 
333  _end = hub_id_space().end();
334 
335  // Increment the member counter.
336 
337  _member_ct += xsize;
338 
339  // Create the interval emulator and set its size and local id map.
340  // The local id map for the interval is the term id map from the hub id space.
341 
342  crg_interval* linterval = crg_interval::new_interval(xinterval_type);
343  linterval->initialize_id_spaces(_id_spaces);
344  linterval->initialize_local_id_space(_id_spaces.term_of(xid));
345 
346  // Put the emulator in the implicit member map.
347 
348  // The entire index interval of the emulator is mapped to the emulator
349  // by making a single entry for the end of the interval and using the
350  // upper_bound query on the map. See member function interval().
351  // Maps use internal (poset) id space.
352 
353  _interval_map[xid + xsize] = linterval;
354 
355  // Make sure that ids below begin() do not map to this member by making sure
356  // there's an entry at the end of the preceeding interval == begin of this interval.
357 
358  if(_interval_map.find(xid) == _interval_map.end())
359  {
360  _interval_map[xid] = 0;
361  }
362 
363  // Postconditions:
364 
365  ensure(end() >= old_end);
366  ensure(member_ct() == old_member_ct + xsize);
367  ensure(interval(xid).id_spaces_initialized());
368  ensure(interval(xid).local_id_space_initialized());
369  ensure_for_range(pod_index_type i=0, i<xsize, ++i, contains_member(xid + i));
370  ensure(unexecutable("atoms not in upper cover of bottom"));
371 
372  return;
373 }
374 
375 void
378 {
379  // Preconditions:
380 
381  require(contains_member(xid)); // equivalent to hub_id_space().contains(xid);
382 
383  // Body:
384 
385  define_old_variable(size_type old_member_ct = _member_ct);
386 
387  // Delete cover id spaces.
388 
389  crg_interval& linterval = interval(xid);
390 
391  if(linterval.cover_is_explicit(LOWER, xid))
392  {
393  _id_spaces.delete_space(linterval.cover_id_space_id(LOWER, xid));
394  }
395 
396  if(linterval.cover_is_explicit(UPPER, xid))
397  {
398  _id_spaces.delete_space(linterval.cover_id_space_id(UPPER, xid));
399  }
400 
401  // Remove from dof tuple map.
402 
403  _explicit_dof_tuple_map.erase(xid);
404 
405  // Remove from name map.
406 
407  _member_name_map.delete_index(xid);
408 
409  // Remove member from the id space family.
410 
411  _id_spaces.delete_id(xid);
412 
413  // Update the upper bound on the member index.
414 
415  _end = !hub_id_space().is_empty() ? hub_id_space().end() : 0;
416 
417  --_member_ct;
418 
419  // $$SCRIBBLE: what about links to member?
420  // Review abstract_poset_member::delete_state().
421 
422  // Postconditions:
423 
424  ensure(member_ct() == old_member_ct - 1);
425  ensure(!contains_member(xid));
426 
427  // Exit:
428 
429  return;
430 }
431 
432 void
435 {
436  // Preconditions:
437 
438  require(contains_member(xid));
439 
440  // Body:
441 
442  define_old_variable(size_type old_member_ct = _member_ct);
443 
444  // Get interval emulator.
445 
446  crg_interval& linterval = interval(xid);
447 
448  pod_index_type linterval_begin = linterval.begin();
449  pod_index_type linterval_end = linterval.end();
450 
451  pod_index_type llower_cover_begin = linterval.cover_id_space_id(LOWER, linterval_begin);
452  pod_index_type lupper_cover_begin = linterval.cover_id_space_id(UPPER, linterval_begin);
453 
454  define_old_variable(size_type old_interval_size = linterval.size());
455  define_old_variable(pod_index_type old_interval_begin = linterval.begin());
456  define_old_variable(pod_index_type old_interval_end = linterval.end());
457 
458  // Delete the primary id space for the id interval being deleted.
459 
460  _id_spaces.delete_primary_state(hub_id_space().term_id(xid));
461 
462  // Update the upper bound on the member index.
463 
464  _end = !hub_id_space().is_empty() ? hub_id_space().end() : 0;
465 
466  // Decrement the member count.
467 
468  _member_ct -= linterval.size();
469 
470  // Remove the emulator from the map and delete it.
471 
472  _interval_map.erase(linterval_end);
473  delete &linterval;
474 
475  // Postconditions:
476 
477  ensure(member_ct() == old_member_ct - old_interval_size);
478  ensure_for_range(pod_index_type i = old_interval_begin, i < old_interval_end, ++i, !contains_member(i));
479 
480  // Exit:
481 
482  return;
483 }
484 
487 member_ct() const
488 {
489  return _member_ct;
490 }
491 
495 {
496  return _standard_member_ct;
497 }
498 
502 {
503  return _standard_member_ct;
504 }
505 
506 void
509 {
510  // Preconditions:
511 
512  // Body:
513 
514  _standard_member_ct = xct;
515 
516  // Postconditions:
517 
518  ensure(standard_member_ct() == xct);
519 
520  // Exit:
521 
522  return;
523 }
524 
525 const sheaf::scoped_index&
527 begin() const
528 {
529  return _begin;
530 }
531 
532 const sheaf::scoped_index&
534 end() const
535 {
536  return _end;
537 }
538 
539 bool
542 {
543  // Preconditions:
544 
545  // Body:
546 
547  bool result = hub_id_space().contains(xid);
548 
549  // Postconditions:
550 
551  // Exit:
552 
553  return result;
554 }
555 
556 bool
559 {
560  return contains_member(xid) && (implicit_member(xid) != 0);
561 }
562 
563 bool
566 {
567  // A member is fully explicit if it exists and is not implicit.
568 
569  return contains_member(xid) && (implicit_member(xid) == 0);
570 }
571 
572 const sheaf::crg_interval&
575 {
576  // Preconditions:
577 
578  require(contains_member(xid));
579 
580  // Body:
581 
582  // All the member ids in the interval of an implicit member emulator
583  // map to the emulator by maintaining a single entry for the
584  // end (upper bound) of the interval.
585  // Map uses hub id space.
586 
587  return *_interval_map.upper_bound(xid)->second;
588 }
589 
593 {
594  // Preconditions:
595 
596  require(contains_member(xid));
597 
598  // Body:
599 
600  // All the member ids in the interval of an implicit member emulator
601  // map to the emulator by maintaining a single entry for the
602  // end (upper bound) of the interval.
603  // Map uses hub id space.
604 
605  return *_interval_map.upper_bound(xid)->second;
606 }
607 
611 {
612  // Preconditions:
613 
614  require(contains_member(xid));
615 
616  // Body:
617 
618  implicit_crg_interval* result = 0;
619 
620  crg_interval* linterval = _interval_map.upper_bound(xid)->second;
621  if(dynamic_cast<implicit_crg_interval*>(linterval) != 0)
622  {
623  result = reinterpret_cast<implicit_crg_interval*>(linterval);
624  }
625 
626  // Postconditions:
627 
628  // Exit:
629 
630  return result;
631 }
632 
633 // PROTECTED MEMBER FUNCTIONS
634 
635 void
637 initialize_member_covers(pod_index_type xid, bool xstandard_member_hack)
638 {
639  // Preconditions:
640 
641  require(contains_member(xid));
642 
643  // Body:
644 
645  // Find the explicit cover interval.
646 
647  explicit_crg_interval* linterval;
648 
649  interval_map_type::iterator litr = _interval_map.upper_bound(xid);
650 
651  if((litr == _interval_map.end()) || (litr->second == 0))
652  {
656 
657  string lclass_name = xstandard_member_hack ?
658  "standard_member_hack_crg_interval" : "explicit_crg_interval";
659 
660  // No cover interval found, create one.
661 
662  linterval =
663  reinterpret_cast<explicit_crg_interval*>
664  (crg_interval::new_interval(lclass_name));
665 
666  linterval->initialize_id_spaces(_id_spaces);
667  linterval->initialize_local_id_space(_id_spaces.term_of(xid));
668  linterval->initialize_covers();
669 
670  // The entire index interval of the emulator is mapped to the emulator
671  // by making a single entry for the end of the interval and using the
672  // upper_bound query on the map. See member function interval().
673  // Maps use internal (poset) id space.
674 
675  _interval_map[linterval->end()] = linterval;
676 
677  // Make sure that ids below begin() do not map to this member by making sure
678  // there's an entry at the end of the preceeding interval == begin of this interval.
679 
680  if(_interval_map.find(linterval->begin()) == _interval_map.end())
681  {
682  _interval_map[linterval->begin()] = 0;
683  }
684  }
685  else
686  {
687  // Cpver interval was found, cast it to an explicit cover interval.
688 
689  assertion(dynamic_cast<explicit_crg_interval*>(litr->second));
690 
691  linterval = reinterpret_cast<explicit_crg_interval*>(litr->second);
692  }
693 
694  // Create explicit lower cover id space.
695 
696  pod_index_type llower_cover_id = linterval->cover_id_space_id(LOWER, xid);
697  list_index_space_state::new_space(_id_spaces, llower_cover_id,
698  crg_interval::explicit_cover_name(LOWER, xid), false);
699 
700 
701  // Create explicit upper cover id space.
702 
703  pod_index_type lupper_cover_id = linterval->cover_id_space_id(UPPER, xid);
704  list_index_space_state::new_space(_id_spaces, lupper_cover_id,
705  crg_interval::explicit_cover_name(UPPER, xid), false);
706 
707  // Postconditions:
708 
709  ensure(cover_is_empty(LOWER, xid));
710  ensure(cover_is_empty(UPPER, xid));
711 
712  // Exit:
713 
714  return;
715 }
716 
717 // PRIVATE MEMBER FUNCTIONS
718 
719 
720 // ===========================================================
721 // ID SPACE FACET
722 // ===========================================================
723 
724 // PUBLIC MEMBER FUNCTIONS
725 
728 id_spaces() const
729 {
730  return _id_spaces;
731 }
732 
736 {
737  return _id_spaces.hub_id_space();
738 }
739 
740 const sheaf::scoped_index&
742 hub_id() const
743 {
744  // Preconditions:
745 
746  // Body:
747 
748  const scoped_index& result = begin();
749 
750  // Postconditions:
751 
752  ensure(result.is_hub_scope());
753 
754  // Exit:
755 
756  return result;
757 }
758 
762 {
763  // Preconditions:
764 
765  // Body:
766 
767  scoped_index result(hub_id());
768  result = xid;
769 
770  // Postconditions:
771 
772  ensure(result.is_hub_scope());
773  ensure(result.pod() == xid);
774 
775  // Exit:
776 
777  return result;
778 }
779 
782 new_gathered_hub_id_space(bool xexclude_bottom)
783 {
784  // Preconditions:
785 
786  require(!has_gathered_hub_id_space());
787 
788  // Body:
789 
790  const index_space_handle& result =
791  _id_spaces.new_gathered_hub_id_space(xexclude_bottom);
792 
793  // Postconditions:
794 
795  ensure(has_gathered_hub_id_space());
796  ensure(gathered_hub_id_space().is_gathered());
797  ensure(xexclude_bottom == gathered_hub_id_space_excludes_bottom());
798 
799  // Exit:
800 
801  return result;
802 }
803 
804 void
807 {
808  // Preconditions:
809 
810  require(has_gathered_hub_id_space());
811 
812  // Body:
813 
814  _id_spaces.update_gathered_hub_id_space();
815 
816  // Postconditions:
817 
818  ensure(gathered_hub_id_space().is_gathered());
819 
820  // Exit:
821 
822  return;
823 }
824 
828 {
829  // Preconditions:
830 
831  require(has_gathered_hub_id_space());
832 
833  // Body:
834 
835  const index_space_handle& result = _id_spaces.gathered_hub_id_space();
836 
837  // Postconditions:
838 
839  ensure(is_basic_query);
840 
841  // Exit:
842 
843  return result;
844 }
845 
846 bool
849 {
850  // Preconditions:
851 
852  // Body:
853 
854  bool result = _id_spaces.has_gathered_hub_id_space();
855 
856  // Postconditions:
857 
858  ensure(is_basic_query);
859 
860  // Exit:
861 
862  return result;
863 }
864 
865 bool
868 {
869  // Preconditions:
870 
871  // Body:
872 
873  bool result = _id_spaces.gathered_hub_id_space_excludes_bottom();
874 
875  // Postconditions:
876 
877  ensure(is_basic_query);
878 
879  // Exit:
880 
881  return result;
882 }
883 
884 // PROTECTED MEMBER FUNCTIONS
885 
886 // PRIVATE MEMBER FUNCTIONS
887 
888 
889 // ===========================================================
890 // MEMBER NAME FACET
891 // ===========================================================
892 
893 // PUBLIC MEMBER FUNCTIONS
894 
898 {
899  return _member_name_map;
900 }
901 
905 {
906  return _member_name_map;
907 }
908 
909 // PROTECTED MEMBER FUNCTIONS
910 
911 // PRIVATE MEMBER FUNCTIONS
912 
913 
914 // ===========================================================
915 // EDIT MODE FACET
916 // ===========================================================
917 
918 // PUBLIC MEMBER FUNCTIONS
919 
920 bool
923 {
924  return _jim_edit_depth > 0;
925 }
926 
927 void
930 {
931  // Preconditions:
932 
933 
934  // Body:
935 
936  define_old_variable(int old_jim_edit_depth = _jim_edit_depth);
937 
938  _jim_edit_depth++;
939 
940  // Postconditions:
941 
942  ensure(jim_edit_depth() == old_jim_edit_depth + 1);
943 
944  // Exit:
945 
946  return;
947 }
948 
949 void
952 {
953  // Preconditions:
954 
955  require(jim_edit_mode());
956 
957  // Body:
958 
959  define_old_variable(int old_jim_edit_depth = _jim_edit_depth);
960 
961  _jim_edit_depth--;
962 
963  // Postconditions:
964 
965  ensure(jim_edit_depth() == old_jim_edit_depth - 1);
966  ensure(jim_edit_depth() >= 0);
967 
968  // Exit:
969 
970  return;
971 }
972 
973 
974 
975 int
978 {
979  return _jim_edit_depth;
980 }
981 
982 // PROTECTED MEMBER FUNCTIONS
983 
984 // PRIVATE MEMBER FUNCTIONS
985 
986 
987 // ===========================================================
988 // COVER SET (LINKS) FACET
989 // ===========================================================
990 
991 // PUBLIC MEMBER FUNCTIONS
992 
993 bool
995 cover_is_explicit(bool xlower, pod_index_type xmbr_index) const
996 {
997  // Preconditions:
998 
999  require(contains_member(xmbr_index));
1000 
1001  // Body:
1002 
1003  return interval(xmbr_index).cover_is_explicit(xlower, xmbr_index);
1004 }
1005 
1006 bool
1008 cover_is_implicit(bool xlower, pod_index_type xmbr_index) const
1009 {
1010  // A cover set for a member is implicit if the member is implicit.
1011  // Note that a cover set can be both implict and explicit at the same time.
1012 
1013  return contains_implicit_member(xmbr_index);
1014 }
1015 
1018 get_cover_id_space(bool xlower, pod_index_type xmbr_index) const
1019 {
1020  // Preconditions:
1021 
1022  require(contains_member(xmbr_index));
1023 
1024  // Body:
1025 
1026  pod_index_type lid = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1027 
1028  index_space_handle& result = _id_spaces.get_id_space(lid);
1029 
1030  // Postconditions:
1031 
1032  ensure(result.is_attached());
1033 
1034  // Exit:
1035 
1036  return result;
1037 }
1038 
1039 void
1042 {
1043  // Preconditions:
1044 
1045  // Body:
1046 
1047  _id_spaces.release_id_space(xcover_id_space);
1048 
1049  // Postconditions:
1050 
1051  ensure(!xcover_id_space.is_attached());
1052 
1053  // Exit:
1054 
1055  return;
1056 }
1057 
1060 cover_id_space_id(bool xlower, pod_index_type xmbr_index) const
1061 {
1062  // Preconditions:
1063 
1064  require(contains_member(xmbr_index));
1065 
1066  // Body:
1067 
1068  pod_index_type result = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1069 
1070  // Postconditions:
1071 
1072  ensure(is_valid(result));
1073 
1074  // Exit:
1075 
1076  return result;
1077 }
1078 
1081 get_cover_id_space_iterator(bool xlower, pod_index_type xmbr_index) const
1082 {
1083  // Preconditions:
1084 
1085  require(contains_member(xmbr_index));
1086 
1087  // Body:
1088 
1089  pod_index_type lid = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1090  index_space_iterator& result = _id_spaces.get_id_space_iterator(lid);
1091 
1092  // Postconditions:
1093 
1094  ensure(result.is_attached());
1095 
1096  // Exit:
1097 
1098  return result;
1099 }
1100 
1101 void
1104 {
1105  // Preconditions:
1106 
1107  // Body:
1108 
1109  _id_spaces.release_id_space_iterator(xcover_itr);
1110 
1111  // Postconditions:
1112 
1113  ensure(!xcover_itr.is_attached());
1114 
1115  // Exit:
1116 
1117  return;
1118 }
1119 
1120 bool
1123  pod_index_type xmbr_index,
1124  const index_space_iterator& xitr) const
1125 {
1126  // Preconditions:
1127 
1128  require(contains_member(xmbr_index));
1129 
1130  // Body:
1131 
1132  index_space_handle& lcover = get_cover_id_space(xlower, xmbr_index);
1133 
1134  bool result = lcover.allocated_iterator(xitr);
1135 
1136  release_cover_id_space(lcover);
1137 
1138  // Postconditions:
1139 
1140  // Exit:
1141 
1142  return result;
1143 }
1144 
1145 bool
1147 cover_is_empty(bool xlower, pod_index_type xmbr_index) const
1148 {
1149  // Preconditions:
1150 
1151  require(contains_member(xmbr_index));
1152 
1153  // Body:
1154 
1155  pod_index_type lid = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1156 
1157  bool result = _id_spaces.is_empty(lid);
1158 
1159  // Postconditions:
1160 
1161  // Exit:
1162 
1163  return result;
1164 }
1165 
1166 bool
1168 cover_is_singleton(bool xlower, pod_index_type xmbr_index) const
1169 {
1170  // Preconditions:
1171 
1172  require(contains_member(xmbr_index));
1173 
1174  // Body:
1175 
1176  pod_index_type lid = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1177 
1178  bool result = (_id_spaces.ct(lid) == 1);
1179 
1180  // Postconditions:
1181 
1182  // Exit:
1183 
1184  return result;
1185 }
1186 
1189 cover_ct(bool xlower, pod_index_type xmbr_index) const
1190 {
1191  // Preconditions:
1192 
1193  require(contains_member(xmbr_index));
1194 
1195  // Body:
1196 
1197  pod_index_type lid = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1198 
1199  size_type result = _id_spaces.ct(lid);
1200 
1201  // Postconditions:
1202 
1203  // Exit:
1204 
1205  return result;
1206 }
1207 
1208 bool
1211  pod_index_type xmbr_index,
1212  pod_index_type xother_mbr_index) const
1213 {
1214  // Preconditions:
1215 
1216  require(contains_member(xmbr_index));
1217 
1218  // Body:
1219 
1220  pod_index_type lid = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1221 
1222  bool result = _id_spaces.contains_hub(lid, xother_mbr_index);
1223 
1224  // Postconditions:
1225 
1226  // Exit:
1227 
1228  return result;
1229 }
1230 
1231 bool
1233 cover_is_equal(bool xlower,
1234  pod_index_type xmbr_index,
1235  pod_index_type xother_mbr_index) const
1236 {
1237  // Preconditions:
1238 
1239  require(contains_member(xmbr_index));
1240  require(contains_member(xother_mbr_index));
1241 
1242  // Body:
1243 
1244  // Gather the cover of xmbr_index into a set.
1245 
1246  index_space_iterator& litr = get_cover_id_space_iterator(xlower, xmbr_index);
1247 
1248  set< pod_index_type > lmbr_set;
1249  while(!litr.is_done())
1250  {
1251  lmbr_set.insert(litr.hub_pod());
1252  litr.next();
1253  }
1254 
1255  release_cover_id_space_iterator(litr);
1256 
1257  // Gather the cover of xother_member_index into a set.
1258 
1259  index_space_iterator& lother_itr = get_cover_id_space_iterator(xlower, xother_mbr_index);
1260 
1261  set< pod_index_type > lother_set;
1262  while(!lother_itr.is_done())
1263  {
1264  lother_set.insert(lother_itr.hub_pod());
1265  lother_itr.next();
1266  }
1267 
1268  release_cover_id_space_iterator(lother_itr);
1269 
1270  // Compare the sets.
1271 
1272  bool result = (lmbr_set == lother_set);
1273 
1274  // Postconditions:
1275 
1276  // Exit:
1277 
1278  return result;
1279 }
1280 
1283 first_cover_member(bool xlower, pod_index_type xmbr_index) const
1284 {
1285  // Preconditions:
1286 
1287  require(contains_member(xmbr_index));
1288  require(!cover_is_empty(xlower, xmbr_index));
1289 
1290  // Body:
1291 
1292  pod_index_type lid = interval(xmbr_index).cover_id_space_id(xlower, xmbr_index);
1293 
1294  pod_index_type result = _id_spaces.hub_begin(lid);
1295 
1296  // Postconditions:
1297 
1298  // Exit:
1299 
1300  return result;
1301 }
1302 
1303 void
1306  bool xlower,
1307  pod_index_type xmbr_index)
1308 {
1309  // Preconditions:
1310 
1311  require(contains_member(xmbr_index));
1312  require(!cover_contains_member(xlower, xmbr_index, xother_mbr_index));
1313 
1314  // Body:
1315 
1316  pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1317  list_index_space_handle& lcover =
1318  _id_spaces.get_id_space<list_index_space_handle>(lid);
1319 
1320  lcover.push_back(xother_mbr_index);
1321 
1322  _id_spaces.release_id_space(lcover);
1323 
1324  // Postconditions:
1325 
1326  ensure(cover_contains_member(xlower, xmbr_index, xother_mbr_index));
1327 
1328  // Exit:
1329 
1330  return;
1331 }
1332 
1333 void
1336  bool xlower,
1337  pod_index_type xmbr_index,
1338  index_space_iterator& xitr)
1339 {
1340  // Preconditions:
1341 
1342  require(!xitr.is_done());
1343  require(contains_member(xmbr_index));
1344  require(!cover_contains_member(xlower, xmbr_index, xother_mbr_index));
1345 
1346  // Body:
1347 
1348  define_old_variable(pod_index_type old_itr_pod = xitr.pod());
1349  define_old_variable(pod_index_type old_itr_hub_pod = xitr.hub_pod());
1350 
1351  pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1352  list_index_space_handle& lcover =
1353  _id_spaces.get_id_space<list_index_space_handle>(lid);
1354 
1355  lcover.push(xitr, xother_mbr_index);
1356 
1357  _id_spaces.release_id_space(lcover);
1358 
1359  // Postconditions:
1360 
1361  ensure(cover_contains_member(xlower, xmbr_index, xother_mbr_index));
1362  ensure(xitr.pod() == old_itr_pod + 1);
1363  ensure(xitr.hub_pod() == old_itr_hub_pod);
1364 
1365  // Exit:
1366 
1367  return;
1368 }
1369 
1370 void
1373  bool xlower,
1374  pod_index_type xmbr_index)
1375 {
1376  // Preconditions:
1377 
1378  require(contains_member(xmbr_index));
1379 
1380  // Body:
1381 
1382  pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1383  list_index_space_handle& lcover =
1384  _id_spaces.get_id_space<list_index_space_handle>(lid);
1385 
1386  lcover.remove_hub(xother_mbr_index, true);
1387 
1388  _id_spaces.release_id_space(lcover);
1389 
1390  // Postconditions:
1391 
1392  ensure(!cover_contains_member(xlower, xmbr_index, xother_mbr_index));
1393 
1394  // Exit:
1395 
1396  return;
1397 }
1398 
1399 void
1402  bool xlower,
1403  pod_index_type xmbr_index)
1404 {
1405  // Preconditions:
1406 
1407  require(!xitr.is_done());
1408  require(contains_member(xmbr_index));
1409 
1410  // Body:
1411 
1412  define_old_variable(pod_index_type old_itr_pod = xitr.pod());
1413  define_old_variable(pod_index_type old_itr_hub_pod = xitr.hub_pod());
1414 
1415  pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1416  list_index_space_handle& lcover =
1417  _id_spaces.get_id_space<list_index_space_handle>(lid);
1418 
1419  lcover.remove(xitr, true);
1420 
1421  _id_spaces.release_id_space(lcover);
1422 
1423  // Postconditions:
1424 
1425  ensure(!cover_contains_member(xlower, xmbr_index, old_itr_hub_pod));
1426 
1427  // Because the underlying representation is a list,
1428  // the xitr.pod() now actually == old_itr_pod, but that
1429  // is not part of the specification. The specified behavior
1430  // is however difficult to implement, since we would have to
1431  // get and release an iterator to find the old_next_hub_id.
1432 
1433  // ensure(xitr.is_done() || xitr.pod() > old_itr_pod);
1434  ensure(unexecutable("xitr.hub_pod() == old_next_itr_hub_pod"));
1435 
1436 
1437  // Exit:
1438 
1439  return;
1440 }
1441 
1442 void
1445  pod_index_type xnew_other_mbr_index,
1446  bool xlower,
1447  pod_index_type xmbr_index)
1448 {
1449  // Preconditions:
1450 
1451  require(contains_member(xmbr_index));
1452  require((xnew_other_mbr_index != xold_other_mbr_index) ? !cover_contains_member(xlower, xmbr_index, xnew_other_mbr_index) : true);
1453 
1454  // Body:
1455 
1456  define_old_variable(bool old_cover_contains_old_other_mbr_index = cover_contains_member(xlower, xmbr_index, xold_other_mbr_index));
1457 
1458 // pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1459 // scattered_insertion_index_space_handle& lcover =
1460 // _id_spaces.get_id_space<scattered_insertion_index_space_handle>(lid);
1461 
1462 // pod_index_type lold_pod = lcover.pod(xold_other_mbr_index);
1463 
1464 // /// @todo Add a replace function to mutable id space or loosen the
1465 // /// preconditions allowing for the pod value to exist.
1466 
1467 // lcover.remove(lold_pod, true);
1468 // lcover.insert(lold_pod, xnew_other_mbr_index);
1469 
1470 // _id_spaces.release_id_space(lcover);
1471 
1472  if(cover_contains_member(xlower, xmbr_index, xold_other_mbr_index))
1473  {
1474  pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1475  list_index_space_handle& lcover =
1476  _id_spaces.get_id_space<list_index_space_handle>(lid);
1477 
1478 
1479  lcover.replace_range_id(xold_other_mbr_index, xnew_other_mbr_index);
1480 
1481  _id_spaces.release_id_space(lcover);
1482  }
1483 
1484 
1485  // Postconditions:
1486 
1487  ensure((xnew_other_mbr_index != xold_other_mbr_index) ? !cover_contains_member(xlower, xmbr_index, xold_other_mbr_index) : true);
1488  ensure(old_cover_contains_old_other_mbr_index ? cover_contains_member(xlower, xmbr_index, xnew_other_mbr_index) : true);
1489 
1490  // Exit:
1491 
1492  return;
1493 }
1494 
1495 void
1497 clear_cover(bool xlower, pod_index_type xmbr_index)
1498 {
1499  // Preconditions:+
1500 
1501  require(contains_member(xmbr_index));
1502 
1503  // Body:
1504 
1505  pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1506  list_index_space_handle& lcover =
1507  _id_spaces.get_id_space<list_index_space_handle>(lid);
1508 
1509  lcover.clear();
1510 
1511  _id_spaces.release_id_space(lcover);
1512 
1513  // Postconditions:
1514 
1515  ensure(cover_is_empty(xlower, xmbr_index));
1516 
1517  // Exit:
1518 
1519  return;
1520 }
1521 
1522 void
1524 copy_cover(bool xlower, pod_index_type xmbr_index, pod_index_type xother_mbr_index)
1525 {
1526  // Preconditions:
1527 
1528  require(contains_member(xmbr_index));
1529  require(contains_member(xother_mbr_index));
1530 
1531  // Body:
1532 
1533  pod_index_type lid = force_explicit_cover(xlower, xmbr_index);
1534  list_index_space_handle& lcover =
1535  _id_spaces.get_id_space<list_index_space_handle>(lid);
1536 
1537  lcover.clear();
1538 
1539  index_space_iterator& litr = get_cover_id_space_iterator(xlower, xother_mbr_index);
1540  while(!litr.is_done())
1541  {
1542  lcover.push_back(litr.hub_pod());
1543 
1544  litr.next();
1545  }
1546  release_cover_id_space_iterator(litr);
1547 
1548  _id_spaces.release_id_space(lcover);
1549 
1550  // Postconditions
1551 
1552  ensure(cover_is_equal(xlower, xmbr_index, xother_mbr_index));
1553 
1554  return;
1555 }
1556 
1557 void
1560  pod_index_type xmbr_end)
1561 {
1562  // Preconditions:
1563 
1564  require(xmbr_end > xmbr_begin);
1565  require(cover_is_empty(UPPER, BOTTOM_INDEX) || id_spaces().handle_conforms_to_state<interval_index_space_handle>(cover_id_space_id(UPPER, BOTTOM_INDEX)));
1566  require_for_range(pod_index_type i=xmbr_begin, i<xmbr_end, ++i, contains_member(i));
1567 
1568  // Body:
1569 
1570  pod_index_type lspace_id = cover_id_space_id(UPPER, BOTTOM_INDEX);
1571 
1572  if(cover_is_empty(UPPER, BOTTOM_INDEX))
1573  {
1574  // This is the first time this function has been called. The cover id
1575  // space was initialized to a list id space. It needs to be replaced
1576  // with an interval id space so that the block can efficiently store
1577  // the upper cover of bottom.
1578 
1584 
1585  // Delete the current id space state.
1586 
1587  _id_spaces.delete_space(lspace_id);
1588 
1589  // Make a new interval id space state.
1590 
1591  interval_index_space_state::new_space(_id_spaces, lspace_id,
1592  crg_interval::explicit_cover_name(UPPER, BOTTOM_INDEX),
1593  false, true);
1594  }
1595 
1596  // Add the interval to the cover. Since the interval id space takes a
1597  // closed interval but this function takes a half open interval, one
1598  // needs subtracted from xmbr_end.
1599 
1600  assertion(id_spaces().handle_conforms_to_state<interval_index_space_handle>(lspace_id));
1601 
1602  interval_index_space_handle& lcover = id_spaces().get_id_space<interval_index_space_handle>(lspace_id);
1603  lcover.push_interval(xmbr_begin, xmbr_end-1);
1604  id_spaces().release_id_space(lcover);
1605 
1606  // Postconditions:
1607 
1608  ensure(id_spaces().handle_conforms_to_state<interval_index_space_handle>(cover_id_space_id(UPPER, BOTTOM_INDEX)));
1609  ensure_for_range(pod_index_type i=xmbr_begin, i<xmbr_end, ++i, cover_contains_member(UPPER, BOTTOM_INDEX, i));
1610 
1611  // Exit:
1612 
1613  return;
1614 }
1615 
1616 // PROTECTED MEMBER FUNCTIONS
1617 
1620 force_explicit_cover(bool xlower, pod_index_type xmbr_index, bool xinitialize)
1621 {
1622  // Preconditions:
1623 
1624  require(contains_member(xmbr_index));
1625 
1626  // Body:
1627 
1628  pod_index_type result =
1629  interval(xmbr_index).force_explicit_cover(xlower, xmbr_index, xinitialize);
1630 
1631  // Postconditions:
1632 
1633  ensure(id_spaces().contains(result));
1634  ensure(id_spaces().handle_conforms_to_state<list_index_space_handle>(result));
1635 
1636  // Exit:
1637 
1638  return result;
1639 }
1640 
1641 // PRIVATE MEMBER FUNCTIONS
1642 
1643 
1644 // ===========================================================
1645 // DOF_TUPLE_ID FACET
1646 // ===========================================================
1647 
1648 // PUBLIC MEMBER FUNCTIONS
1649 
1653 {
1654  // Preconditions:
1655 
1656  require(contains_member(xmbr_index));
1657 
1658  // Body:
1659 
1660  explicit_dof_tuple_map_type::const_iterator le_itr =
1661  _explicit_dof_tuple_map.find(xmbr_index);
1662  if(le_itr != _explicit_dof_tuple_map.end())
1663  {
1664  return le_itr->second;
1665  }
1666  else
1667  {
1668  implicit_crg_interval* lmbr = implicit_member(xmbr_index);
1669 
1670  if(lmbr != 0)
1671  {
1672  return lmbr->dof_tuple_id(xmbr_index);
1673  }
1674  else
1675  {
1676  return invalid_pod_index();
1677  }
1678  }
1679 }
1680 
1681 void
1684  pod_index_type xdof_tuple_id)
1685 {
1686  // Preconditions:
1687 
1688  require(contains_member(xmbr_index));
1689 
1690  // Body:
1691 
1692  _explicit_dof_tuple_map[xmbr_index] = xdof_tuple_id;
1693 
1694  // Postconditions:
1695 
1696  ensure(member_dof_tuple_id(xmbr_index) == xdof_tuple_id);
1697 }
1698 
1699 // PROTECTED MEMBER FUNCTIONS
1700 
1701 // PRIVATE MEMBER FUNCTIONS
1702 
1703 
1704 // ===========================================================
1705 // I/O SUPPORT FACET
1706 // ===========================================================
1707 
1708 // PUBLIC DATA MEMBERS
1709 
1710 void
1712 clean_cover(bool xlower, pod_index_type xmbr_index)
1713 {
1714  // Preconditions:
1715 
1716  require(contains_member(xmbr_index));
1717 
1718  // Body:
1719 
1721 
1722  // Postconditions:
1723 
1724  // Exit:
1725 
1726  return;
1727 }
1728 
1729 void
1732  set<pod_index_type>& result) const
1733 {
1734  // Preconditions:
1735 
1736  // Body:
1737 
1738  const crg_interval::explicit_cover_map_type& lcover_map = xinterval.explicit_cover_map(LOWER);
1739  crg_interval::explicit_cover_map_type::const_iterator lcover_map_itr;
1740  for(lcover_map_itr = lcover_map.begin();
1741  lcover_map_itr != lcover_map.end();
1742  ++lcover_map_itr)
1743  {
1744  index_space_iterator& lcover_itr =
1745  _id_spaces.get_id_space_iterator(lcover_map_itr->second);
1746 
1747  while(!lcover_itr.is_done())
1748  {
1749  pod_index_type lmbr_id = lcover_itr.hub_pod();
1750 
1751  const crg_interval& linterval = interval(lmbr_id);
1752 
1753  if(linterval.cover_is_explicit(LOWER, lmbr_id))
1754  {
1755  // Member is explicit, insert it into the result.
1756 
1757  result.insert(lmbr_id);
1758 
1759  // Insert the explicit members in the down set.
1760 
1761  explicit_down_set_members(lmbr_id, result);
1762  }
1763 
1764  lcover_itr.next();
1765  }
1766 
1767  _id_spaces.release_id_space_iterator(lcover_itr);
1768  }
1769 
1770  // Postconditions:
1771 
1772  // Exit:
1773 
1774  return;
1775 }
1776 
1777 // PROTECTED DATA MEMBERS
1778 
1779 void
1782  set<pod_index_type>& result) const
1783 {
1784  // Preconditions:
1785 
1786  require(contains_member(xmbr_index));
1787 
1788  // Body:
1789 
1790  index_space_iterator& itr = get_cover_id_space_iterator(LOWER, xmbr_index);
1791  while(!itr.is_done())
1792  {
1793  pod_index_type lmbr_id = itr.hub_pod();
1794 
1795  const crg_interval& linterval = interval(lmbr_id);
1796 
1797  if(linterval.cover_is_explicit(LOWER, lmbr_id))
1798  {
1799  // Member is explicit, insert it into the result.
1800 
1801  result.insert(lmbr_id);
1802 
1803  // Insert the explicit members in the down set.
1804 
1805  explicit_down_set_members(lmbr_id, result);
1806  }
1807 
1808  itr.next();
1809  }
1810  release_cover_id_space_iterator(itr);
1811 
1812  // Postconditions:
1813 
1814  // Exit:
1815 
1816  return;
1817 }
1818 
1819 // PRIVATE DATA MEMBERS
1820 
1821 
1822 // ===========================================================
1823 // ANY FACET
1824 // ===========================================================
1825 
1826 // PUBLIC MEMBER FUNCTIONS
1827 
1828 bool
1830 is_ancestor_of(const any* xother) const
1831 {
1832  bool result;
1833 
1834  // Preconditions:
1835 
1836  // Body:
1837 
1838  result = dynamic_cast<const poset_crg_state*>(xother) != 0;
1839 
1840  // Postconditions:
1841 
1842  // Exit
1843 
1844  return result;
1845 }
1846 
1849 clone() const
1850 {
1851  poset_crg_state* result = 0;
1852 
1853  // Preconditions:
1854 
1855  // Body:
1856 
1857  not_implemented();
1858 
1859  // Postconditions:
1860 
1861  ensure(result != 0);
1862 
1863  // Exit
1864 
1865  return result;
1866 }
1867 
1868 bool
1870 invariant() const
1871 {
1872  bool result = true;
1873 
1874  // Preconditions:
1875 
1876  // Body:
1877 
1878  if(invariant_check())
1879  {
1880  disable_invariant_check();
1881 
1882  invariance(begin().is_hub_scope());
1883  invariance(begin() == BOTTOM_INDEX);
1884  invariance(end().is_hub_scope());
1885 
1886  invariance(member_ct() >= standard_member_ct());
1887  invariance(standard_member_ct() >= 0);
1888  invariance(jim_edit_depth() >= 0);
1889 
1890  enable_invariant_check();
1891  }
1892 
1893  // Postconditions:
1894 
1895  // Exit
1896 
1897  return result;
1898 }
1899 
1900 // PROTECTED MEMBER FUNCTIONS
1901 
1902 // PRIVATE MEMBER FUNCTIONS
1903 
1904 
1905 // ===========================================================
1906 // NON MEMBER FUNCTIONS
1907 // ===========================================================
1908 
1909 std::ostream &
1910 sheaf::
1911 operator<<(std::ostream &os, const poset_crg_state& p)
1912 {
1913 
1914  // Preconditions:
1915 
1916  // Body:
1917 
1918  os << endl
1919  << "ROW GRAPH" << endl
1920  << "---------" << endl
1921  << endl;
1922 
1923  os << "Members and Covering Relation" << endl
1924  << "-----------------------------" << endl
1925  << endl;
1926 
1927  os << " member_ct = "
1928  << p.member_ct()
1929  << endl
1930  << endl;
1931 
1932  // Some convenient typedefs.
1933 
1934  typedef poset_crg_state::member_name_map_type name_map_type;
1935  typedef name_map_type::name_list_type name_list_type;
1936  typedef name_map_type::const_name_iterator name_itr_type;
1937 
1938  // Find the length of the longest name to set width of name column.
1939 
1940  int lname_width = 0;
1941  for(scoped_index i = p.begin(); i < p.end(); ++i)
1942  {
1943  if(p.contains_member(i.hub_pod()))
1944  {
1945  const name_list_type lname_list = p.member_name_map().all_names(i.hub_pod());
1946  for(name_itr_type lname_itr = lname_list.begin(); lname_itr != lname_list.end(); ++lname_itr)
1947  {
1948  int lname_len = lname_itr->size();
1949  lname_width = (lname_width >= lname_len) ? lname_width : lname_len;
1950  }
1951  }
1952  }
1953 
1954  // Add a little extra.
1955 
1956  lname_width += 2;
1957 
1958  // Now write the member lines.
1959 
1960  for(scoped_index i = p.begin(); i < p.end(); ++i)
1961  {
1962  if(p.contains_member(i.hub_pod()))
1963  {
1964  os << "index: " << setw(5) << i.hub_pod();
1965 
1966  typedef poset_crg_state::member_name_map_type name_map_type;
1967  typedef name_map_type::name_list_type name_list_type;
1968  typedef name_map_type::const_name_iterator name_itr_type;
1969 
1970  const name_list_type lname_list =
1971  p.member_name_map().all_names(i.hub_pod());
1972  name_itr_type lname_itr = lname_list.begin();
1973 
1974  string lfirst_name;
1975  if(lname_itr != lname_list.end())
1976  {
1977  lfirst_name = *lname_itr;
1978  ++lname_itr;
1979  }
1980 
1981  os << " " << setw(lname_width) << left << lfirst_name << right;
1982 
1983  os << "dof_map: "
1984  << setw(2*sizeof(int)+3)
1985  << p.member_dof_tuple_id(i.hub_pod());
1986 
1987  os << " upper_cover:";
1988  index_space_iterator& uc_itr = p.get_cover_id_space_iterator(UPPER, i.hub_pod());
1989  while(!uc_itr.is_done())
1990  {
1991  os << " " << uc_itr.hub_pod();
1992  uc_itr.next();
1993  }
1995 
1996  // Note set::size() returns an unsigned integer.
1997 
1998  int ltab_ct = 3 - (3*static_cast<int>(p.cover_ct(UPPER, i.hub_pod())))/8;
1999 
2000  for(int ltab = 0; ltab < ltab_ct; ltab++)
2001  {
2002  os << "\t";
2003  }
2004 
2005  os << "lower_cover:";
2006  index_space_iterator& lc_itr = p.get_cover_id_space_iterator(LOWER, i.hub_pod());
2007  while(!lc_itr.is_done())
2008  {
2009  os << " " << lc_itr.hub_pod();
2010  lc_itr.next();
2011  }
2013 
2014  os << endl;
2015 
2016  while(lname_itr != lname_list.end())
2017  {
2018  os << " ";
2019  os << " " << setw(lname_width) << left << *lname_itr << right << endl;
2020  ++lname_itr;
2021  }
2022  } // end if contains_member
2023 
2024  } // end for all members
2025 
2026  // Memeber id space family.
2027 
2028  os << endl
2029  << "Member Id Space Family" << endl
2030  << "----------------------" << endl
2031  << endl;
2032 
2033  os << p.id_spaces() << endl;
2034 
2035  // Postconditions:
2036 
2037  // Exit
2038 
2039  return os;
2040 }
2041 
2042 size_t
2043 sheaf::
2044 deep_size(const poset_crg_state& xp, bool xinclude_shallow, size_t xresults[2])
2045 {
2046  size_t result;
2047  size_t crg_result;
2048  size_t id_space_result;
2049 
2050  // Preconditions:
2051 
2052  // Body:
2053 
2054  result = xinclude_shallow ? sizeof(xp) : 0;
2055 
2056  typedef unordered_map<pod_index_type, pod_index_type> implicit_member_map_type;
2057  typedef no_deep_size_policy<implicit_member_map_type> implicit_member_map_policy_type;
2058 
2059  typedef map<pod_index_type, crg_interval*> crg_interval_map_type;
2060  typedef value_ptr_deep_size_policy<crg_interval_map_type> crg_interval_map_policy_type;
2061 
2062  // Add the deep size of the data members.
2063 
2064  id_space_result = deep_size(xp._id_spaces, false);
2065 
2066  crg_result = deep_size<pod_index_type, pod_index_type, implicit_member_map_policy_type>(xp._explicit_dof_tuple_map, false);
2067  crg_result += deep_size<pod_index_type, crg_interval*, crg_interval_map_policy_type>(xp._interval_map, false);
2068  crg_result += deep_size(xp._member_name_map, false);
2069 
2070  xresults[0] = crg_result;
2071  xresults[1] = id_space_result;
2072  result = id_space_result + crg_result;
2073 
2074  // Postconditions:
2075 
2076  ensure(result >= 0);
2077 
2078  // Exit
2079 
2080  return result;
2081 }
An implementation of class scattered_insertion_index_space_handle that has a interval id space state...
virtual pod_index_type dof_tuple_id(pod_index_type xmbr_index) const =0
The dof tuple id of the member with index xmbr_index.
pod_index_type new_member_interval(const std::string &xinterval_type, size_type xsize)
Create an implicit interval of type xinterval_type with size xsize.
pod_index_type member_dof_tuple_id(pod_index_type xmbr_index) const
The dof tuple index of the member with index xmbr_index; invalid if xmbr_index has not dof tuple...
The data structure representing the cover relation graph of a poset.
index_space_handle & get_cover_id_space(bool xlower, pod_index_type xmbr_index) const
Allocates an handle for the lower (xlower true) or upper (xlower false) cover of member with index xm...
const scoped_index & hub_id() const
A id in the hub id space; intended for copying to initialize ids to the hub id space.
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
poset_crg_state()
Creates an instance.
An abstract iterator over the ids of an id space.
bool contains_member(pod_index_type xid) const
True if and only if there exists a member with index xid.
implicit_crg_interval * implicit_member(pod_index_type xid) const
The implicit interval for the member with index xid. Returns null, if no implicit interval exists...
pod_type pod() const
The current id in the iteration.
standard_member_index
Ids for standard poset members.
void delete_interval(pod_index_type xid)
Delete the entire implicit interval that contains the implicit member with index xid.
bool cover_contains_member(bool xlower, pod_index_type xmbr_index, pod_index_type xother_mbr_index) const
True if and only if the lower (xlower true) or upper (xlower false) cover of the member with index xm...
virtual poset_crg_state * clone() const
Make a new instance of the same type as this.
const index_space_handle & gathered_hub_id_space() const
The gathered hub id space.
const name_list_type & all_names(index_type xindex) const
All names associated with index xindex.
size_type remove(const scoped_index &xid, bool update_extrema)
Removes the equivalence associated with xid.hub_pod(). synonym for remove_hub(xid.hub_pod(), xupdate_extrema). Returns the number of entries actually removed, either 0 or 1.
member_name_map_type & member_name_map()
Bi-directional map between member names and indices.
void explicit_down_set_members(const implicit_crg_interval &xinterval, std::set< pod_index_type > &result) const
The explicit members in the downset of the interval xinterval.
explicit_cover_map_type & explicit_cover_map(bool xlower)
The lower (xlower true) or upper (xlower false) map to explicit cover id spaces.
Definition: crg_interval.h:359
void initialize_covers()
Initialize the upper and lower covers for this interval.
An map implementation of class scattered_insertion_index_space_handle. This representation is intende...
void release_cover_id_space(index_space_handle &xcover_id_space) const
Returns cover handle xcover_id_space to the pool of id spaces.
A partial multi-valued relation with total injective inverse between names and indices of type index_...
Definition: name_multimap.h:63
STL namespace.
Call deep_size on the dereferenced pointer of the value.
Definition: deep_size.h:68
pod_index_type new_member()
Create a new member with explicit lower and upper cover.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
void initialize_member_covers(pod_index_type xid, bool xstandard_member_hack=false)
Initialize the upper and lower covers for member with index xid.
pod_index_type begin() const
The beginning of the member interval; this emulates members in the interval [begin(), end()), includes interval member.
const index_space_handle & new_gathered_hub_id_space(bool xexclude_bottom)
Create a new gathered id space from the hub id space. If xexclude_bottom, construct the id space with...
virtual bool invariant() const
Class invariant.
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 void next()=0
Makes id() the next id in the iteration.
void delete_member(pod_index_type xid)
Delete member with index xid.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to current.
virtual bool is_attached() const =0
True if this handle is attached to a state.
void copy_cover(bool xlower, pod_index_type xmbr_index, pod_index_type xother_mbr_index)
Copies the lower (xlower true) or upper (xlower false) cover from the member with index xmbr_index to...
void initialize_local_id_space(const index_space_handle &xlocal_id_space)
Sets the local id space to xlocal_id_space and initializes local ids.
An implementation of class sum_index_space_handle that has a primary sum id space state...
pod_index_type cover_id_space_id(bool xlower, pod_index_type xmbr_index) const
The id for the lower (xlower true) or upper (xlower false) cover id space with index xmbr_index...
const hub_index_space_handle & hub_id_space() const
The hub id space.
const hub_index_space_handle & hub_id_space() const
Hub id space for this poset.
void initialize_id_spaces(index_space_family &xid_spaces)
Set the index space family to xid_spaces.
Abstract implementation of crg_interval for an interval of implicit cover relation graph members...
An implementation of class explicit_index_space_handle that has a primary id space state...
const scoped_index & begin() const
The beginning of the member interval; members have indices in the interval [begin(), end()).
void new_standard_member_hack(standard_member_index xid)
Create a new bottom or top member.
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
pod_index_type force_explicit_cover(bool xlower, pod_index_type xmbr_index, bool xinitialize=true)
The explicit lower (xlower true) or upper (xlower false) cover id space of the member with index xmbr...
Abstract base class with useful features for all objects.
Definition: any.h:39
pod_index_type first_cover_member(bool xlower, pod_index_type xmbr_index) const
The first member of the lower (xlower true) or upper (xlower false) cover of the member with index xm...
bool contains_implicit_member(pod_index_type xid) const
True if and only if there exists an implicit member with index xid. A member is implicit if it has im...
Abstract emulator for an interval of cover relation graph members.
Definition: crg_interval.h:70
Struct representing the closed interval [_begin, _end].
Definition: interval_set.h:48
bool is_done() const
True if iteration is finished.
pod_index_type end() const
The end of the member interval.
virtual index_space_handle & get_id_space() const
Allocates an id space handle from the handle pool.
void append_upper_cover_of_bottom(pod_index_type xmbr_begin, pod_index_type xmbr_end)
Appends the interval of ids [xbegin, xend) to the upper cover of bottom. This function is intended to...
Do not call deep_size on either the key or value.
Definition: deep_size.h:54
bool cover_is_implicit(bool xlower, pod_index_type xmbr_index) const
True if and only if the lower (xlower true) or upper (xlower false) cover of the member with index xm...
pod_index_type cover_id_space_id(bool xlower, pod_index_type xmbr_index) const
The id for the lower (xlower true) or upper (xlower false) cover id space with index xmbr_index...
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
bool contains_explicit_member(pod_index_type xid) const
True if and only if there exists an fully explicit member with index xid. A member is fully explicit ...
const scoped_index & end() const
The end of the member interval; members have indices in the interval [begin(), end()).
bool has_gathered_hub_id_space() const
True if there is a gathered hub id space.
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
bool cover_is_empty(bool xlower, pod_index_type xmbr_index) const
True if and only if the lower (xlower true) or upper (xlower false) cover of the member with index xm...
~poset_crg_state()
Destructor.
void request_jim_edit_mode()
Request jim editing be enabled.
bool gathered_hub_id_space_excludes_bottom() const
True, if the gathered hub id space excludes BOTTOM_INDEX.
size_type member_ct() const
The number of members.
const bool UPPER
Selector for upper cover.
Definition: sheaf.h:72
size_type remove_hub(pod_type xhub_id, bool update_extrema)
Removes the equivalence associated with hub id xhub_id. Returns the number of entries actually remove...
size_type cover_ct(bool xlower, pod_index_type xmbr_index) const
The number of members in the lower (xlower true) or upper (xlower false) cover of the member with ind...
void push_interval(const scoped_index &xhub_begin, const scoped_index &xhub_end)
Push the closed interval [xhub_begin.hub_pod(), xhub_end.hub_pod()] to the end of this space...
void insert_cover_member(pod_index_type xother_mbr_index, bool xlower, pod_index_type xmbr_index)
Inserts xother_mbr_index in the lower (xlower true) or upper (xlower false) cover of the member with ...
void update_gathered_hub_id_space()
Updates the gathered hub id space.
bool cover_is_equal(bool xlower, pod_index_type xmbr_index, pod_index_type xother_mbr_index) const
True if and only if the lower (xlower true) or upper (xlower false) cover of the member with index xm...
const index_space_family & id_spaces() const
Collection of id spaces for this poset.
index_space_iterator & get_cover_id_space_iterator(bool xlower, pod_index_type xmbr_index) const
Allocates an iterator for for the lower (xlower true) or upper (xlower false) cover of member with in...
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.
const bool LOWER
Selector for lower cover.
Definition: sheaf.h:67
void remove_cover_member(pod_index_type xother_mbr_index, bool xlower, pod_index_type xmbr_index)
Removes xother_mbr_index from the lower (xlower true) or upper (xlower false) cover of the member wit...
size_type size() const
The number of members in the member interval.
virtual bool is_attached() const =0
True if this iterator is attached to a state.
size_type standard_member_ct()
The number of standard members automatically allocated by the poset handle constructor (mutable versi...
void release_jim_edit_mode()
Request jim editing be disabled.
bool cover_is_singleton(bool xlower, pod_index_type xmbr_index) const
True if and only if the lower (xlower true) or upper (xlower false) cover of the member with index xm...
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
bool cover_contains_iterator(bool xlower, pod_index_type xmbr_index, const index_space_iterator &xitr) const
True if and only if the lower (xlower true) or upper (xlower false) cover of the member with index xm...
void put_standard_member_ct(size_type xct)
Put the number of standard members automatically allocated by the poset handle constructor.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
bool cover_is_explicit(bool xlower, pod_index_type xmbr_index) const
True if and only if the lower (xlower true) or upper (xlower false) cover of the member with index xm...
void push_back(const scoped_index &xhub_id)
Make the next id in this space equivalent to xhub_id in the hub id space. synonym for push_back(xhub_...
void clear_cover(bool xlower, pod_index_type xmbr_index)
Clears the lower (xlower true) or upper (xlower false) cover of the member with index xmbr_index...
void replace_cover_member(pod_index_type xold_other_mbr_index, pod_index_type xnew_other_mbr_index, bool xlower, pod_index_type xmbr_index)
Replaces xold_other_mbr_index with xnew_other_mbr_index in the lower (xlower true) or upper (xlower f...
void replace_range_id(pod_type xold_range_id, pod_type xnew_range_id)
Replaces xold_range_id with xnew_range_id.
Factory and container for a family of id spaces.
void put_member_dof_tuple_id(pod_index_type xmbr_index, pod_index_type xdof_tuple_id)
Sets the dof tuple index of the member with index xmbr_index to xdof_tuple_id.
bool cover_is_explicit(bool xlower, pod_index_type xmbr_index) const
True if and only if the lower (xlower true) or upper (xlower false) cover with index xmbr_index is ex...
unordered::unordered_map< pod_index_type, pod_index_type > explicit_cover_map_type
The type of the explicit cover maps..
Definition: crg_interval.h:344
int jim_edit_depth() const
Jim edit mode depth counter.
pod_type offset() const
The offset into the hub id space.
void clean_cover(bool xlower, pod_index_type xmbr_index)
Removes members of the cover that are no longer members of the crg.
const crg_interval & interval(pod_index_type xid) const
The interval for the member with index xid (const version).
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
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
void push(index_space_iterator &xitr, const scoped_index &xhub_id)
Makes id xitr.id() in this id space equivalent to xhub_id in the hub id space. Increments all ids gre...
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().
bool jim_edit_mode() const
True if jim editing is enabled.
Implementation of crg_interval for explicit members of the poset.
void release_cover_id_space_iterator(index_space_iterator &xcover_itr) const
Returns cover iterator xcover_itr to the pool of id spaces.