SheafSystem  0.0.0.0
namespace_poset.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/namespace_poset.h"
22 
23 #include "SheafSystem/array_index_space_handle.h"
24 #include "SheafSystem/array_index_space_state.h" // for intialize_prototypes
25 #include "SheafSystem/array_index_space_interval.h" // for initialize_prototypes
26 #include "SheafSystem/array_poset_dof_map.h"
27 #include "SheafSystem/assert_contract.h"
28 #include "SheafSystem/constant_index_space_interval.h" // for initialize_prototypes
29 #include "SheafSystem/error_message.h"
30 #include "SheafSystem/explicit_crg_interval.h" // for initialize_prototypes
31 #include "SheafSystem/explicit_index_space_interval.h" // for initialize_prototypes
32 #include "SheafSystem/hash_index_space_state.h" // for intialize_prototypes
33 #include "SheafSystem/index_space_iterator.h"
34 #include "SheafSystem/interval_index_space_state.h" // for intialize_prototypes
35 #include "SheafSystem/list_index_space_state.h" // for initialize_prototypes
36 #include "SheafSystem/namespace_poset_dof_map.h"
37 #include "SheafSystem/namespace_poset_member.h"
38 #include "SheafSystem/scattered_insertion_index_space_handle.h"
39 #include "SheafSystem/offset_index_space_state.h" // for intialize_prototypes
40 #include "SheafSystem/poset_handle_factory.h"
41 #include "SheafSystem/poset_path.h"
42 #include "SheafSystem/poset_type.h"
43 #include "SheafSystem/postorder_member_iterator.h"
44 #include "SheafSystem/postorder_iterator.h"
45 #include "SheafSystem/primary_index_space_state.h" // for initialize_prototypes
46 #include "SheafSystem/primary_sum_index_space_state.h" // for initialize_prototypes
47 #include "SheafSystem/primitives_index_space_state.h" // for initialize_prototypes
48 #include "SheafSystem/ragged_array_index_space_interval.h" // for initialize_prototypes
49 #include "SheafSystem/refinable_poset.h" // for intialize_prototypes
50 #include "SheafSystem/reserved_primary_index_space_state.h" // for initialize_prototypes
51 #include "SheafSystem/singleton_index_space_state.h" // for initalize_prototypes
52 #include "SheafSystem/singleton_index_space_interval.h" // for initialize_prototypes
53 #include "SheafSystem/standard_member_hack_crg_interval.h" // for initialize_prototypes
54 #include "SheafSystem/std_list.h"
55 #include "SheafSystem/std_set.h"
56 #include "SheafSystem/std_sstream.h"
57 #include "SheafSystem/subposet_member_iterator.h"
58 #include "SheafSystem/tern.h"
59 #include "SheafSystem/total_poset_member.h"
60 
61 using namespace std;
62 
63 //#define DIAGNOSTIC_OUTPUT
64 
65 namespace
66 {
67 
71 void
72 traverse_prereqs(const sheaf::namespace_poset* xns,
73  const sheaf::pod_index_type xid,
74  list<sheaf::pod_index_type>& xrev_post,
75  sheaf::zn_to_bool& xvisited)
76 {
77  // Preconditions:
78 
79  require(xns != 0);
80  require(xns->state_is_read_accessible());
81 
82  // Body:
83 
84  sheaf::namespace_poset_member lns_mbr(xns, xid);
85  for(int i=0; i<sheaf::PREREQ_IDS_UB; ++i)
86  {
87  sheaf::pod_index_type lprereq_id = lns_mbr.poset_prereq_id(i);
88 
89  if(sheaf::is_valid(lprereq_id) &&
90  (lprereq_id >= xns->standard_member_ct()))
91  {
92  if(!xvisited[lprereq_id])
93  {
94  xvisited.put(lprereq_id, true);
95  traverse_prereqs(xns, lprereq_id, xrev_post, xvisited);
96  }
97  }
98  }
99  xrev_post.push_front(xid);
100 
101  lns_mbr.detach_from_state();
102 
103  // Postconditions:
104 
105 
106  // Exit:
107 
108  return;
109 }
110 
111 }
112 
113 // ===========================================================
114 // NAMESPACE_POSET FACET
115 // ===========================================================
116 
117 // PUBLIC MEMBER FUNCTIONS
118 
120 namespace_poset(const std::string& xname)
122 {
123  // Preconditions:
124 
125  require(precondition_of(new_state(xname)));
126 
127  // Body:
128 
129  // Create the state.
130 
131  new_state(xname);
132 
133  // Postconditions:
134 
135  ensure(postcondition_of(new_state(xname)));
136 
137  // Exit:
138 
139  return;
140 }
141 
144 {
145  // Preconditions:
146 
147  require(is_attached() ? state_is_read_write_accessible() : true);
148 
149  // Body:
150 
151  if(is_attached())
152  {
153  // Remove all the non-standard members
154 
155  clear();
156 
157  // Remove the standard members;
158  // requires special treatment to avoid contract violations.
159 
161 
163 
164  // Delete the members.
165 
166  poset_state* lposet_state;
167  namespace_poset_member lstd_mbr;
168 
169  lstd_mbr.attach_to_state(this, _primitives.index());
170  lstd_mbr.delete_state();
171 
172  lstd_mbr.attach_to_state(this, _namespace_schema.index());
173  lstd_mbr.delete_state();
174 
175  lstd_mbr.attach_to_state(this, _primitives_schema.index());
176  lstd_mbr.delete_state();
177 
178  // Detach the schema for the table state and dof maps
179  // before deleting the namespace schema poset so that the
180  // dof id space handles can be released.
181 
184 
185  for(pod_index_type i = 0; i < row_dof_tuple_ct(); ++i)
186  {
187  row_dof_map(i, false).schema().detach_from_state();
188  }
189 
190  // Detach handles and delete the associated poset states,
191  // handles will be deleted automatically as data members of this.
192 
193  _primitives.get_read_write_access(true);
194  lposet_state = _primitives.state_obj();
195  _primitives.release_access();
196  _primitives.detach_from_state();
197  delete lposet_state;
198 
200  lposet_state = _namespace_schema.state_obj();
203  delete lposet_state;
204 
205  _primitives_schema.get_read_write_access(true);
206  lposet_state = _primitives_schema.state_obj();
207  _primitives_schema.release_access();
208  _primitives_schema.detach_from_state();
209  delete lposet_state;
210 
211  // Detach and delete the state.
212  // Can't let ~poset_state_handle do this because
213  // it assumes this still has a schema.
214 
215  poset_state* lstate = _state;
217  delete lstate;
218  }
219 
220  // Postconditions:
221 
222  // Exit
223 
224  return;
225 }
226 
227 // PROTECTED MEMBER FUNCTIONS
228 
229 
233 {
234  // Nothing to do.
235 }
236 
239  : poset_state_handle(xtop, xbottom)
240 {
241  // Preconditions:
242 
243  require(precondition_of(poset_state_handle(xtop, xbottom)));
244 
245  // Body:
246 
247  // Nothing to do.
248 
249  // Postconditions:
250 
251  ensure(postcondition_of(poset_state_handle(xtop, xbottom)));
252 
253  // Exit:
254 
255  return;
256 }
257 
258 // PRIVATE MEMBER FUNCTIONS
259 
260 
261 bool
262 sheaf::namespace_poset::
263 make_prototype()
264 {
265  // Preconditions:
266 
267  // Body:
268 
269  poset_type ltype = NAMESPACE_POSET_ID;
270 
271  namespace_poset* lproto = new namespace_poset;
272 
273  factory().insert_prototype(lproto);
274  factory().insert_prototype(ltype, lproto);
275 
276  // Postconditions:
277 
278  // Exit:
279 
280  return true;
281 }
282 
283 // ===========================================================
284 // PRIMTIVES FACET
285 // ===========================================================
286 
287 // PUBLIC MEMBER FUNCTIONS
288 
289 
293 {
294  // cout << endl << "Entering namespace_poset::primitives_schema_path." << endl;
295 
296  // Preconditions:
297 
298 
299  // Body:
300 
302 
303  // Postconditions:
304 
305  ensure(result.full());
306 
307  // Exit:
308 
309  // cout << "Leaving namespace_poset::primitives_schema_path." << endl;
310  return result;
311 }
312 
313 // PROTECTED MEMBER FUNCTIONS
314 
315 // PRIVATE MEMBER FUNCTIONS
316 
317 // ===========================================================
318 // MEMBER POSET FACET
319 // ===========================================================
320 
321 // PUBLIC MEMBER FUNCTIONS
322 
323 
324 bool
326 contains_poset(pod_index_type xhub_id, bool xauto_access) const
327 {
328  bool result;
329 
330  // Preconditions:
331 
332  require(xauto_access || state_is_read_accessible());
333 
334  if(xauto_access)
335  {
336  get_read_access();
337  }
338 
339  // Body:
340 
341  result = contains_member(xhub_id, false) && is_jim(xhub_id);
342 
343  // Postconditions:
344 
345  if(xauto_access)
346  {
347  release_access();
348  }
349 
350  // Exit
351 
352  return result;
353 }
354 
355 bool
357 contains_poset(const scoped_index& xid, bool xauto_access) const
358 {
359  bool result;
360 
361  // Preconditions:
362 
363  require(xauto_access || state_is_read_accessible());
364 
365  // Body:
366 
367  return contains_poset(xid.hub_pod(), xauto_access);
368 }
369 
370 bool
372 contains_poset(const poset_path& xpath, bool xauto_access) const
373 {
374  bool result;
375 
376  // Preconditions:
377 
378  require(xauto_access || state_is_read_accessible());
379 
380  // Body:
381 
382  if(xauto_access)
383  {
384  get_read_access();
385  }
386 
387  result =
388  !xpath.poset_name().empty() && contains_member(xpath.poset_name(), false) && is_jim(xpath.poset_name());
389 
390  if(xauto_access)
391  {
392  release_access();
393  }
394 
395  // Postconditions:
396 
397  // Exit
398 
399  return result;
400 }
401 
402 bool
404 owns(const poset_state_handle& xposet, bool xauto_access) const
405 {
406  bool result;
407 
408  // Preconditions:
409 
410  require(xauto_access || state_is_read_accessible());
411 
412  // Body:
413 
414  result = contains_poset(xposet.path(true), xauto_access);
415 
416  // Postconditions:
417 
418  // Exit
419 
420  return result;
421 }
422 
423 bool
426  pod_index_type xmember_hub_id,
427  bool xauto_access) const
428 {
429  bool result;
430 
431  // Preconditions:
432 
433  require(xauto_access || state_is_read_accessible());
434  require(xauto_access ||
435  (contains_poset(xposet_hub_id) ?
436  member_poset(xposet_hub_id).state_is_read_accessible() :
437  true));
438 
439  // Body:
440 
441  if(xauto_access)
442  {
443  get_read_access();
444  }
445 
446  result =
447  contains_poset(xposet_hub_id, false) &&
448  member_poset(xposet_hub_id, false).contains_member(xmember_hub_id, xauto_access);
449 
450  if(xauto_access)
451  {
452  release_access();
453  }
454 
455  // Postconditions:
456 
457  // Exit
458 
459  return result;
460 }
461 
462 bool
465  const scoped_index& xmember_id,
466  bool xauto_access) const
467 {
468  bool result;
469 
470  // Preconditions:
471 
472  require(xauto_access || state_is_read_accessible());
473  require(xauto_access ||
474  (contains_poset(xposet_id) ?
476  true));
477 
478  // Body:
479 
480  return contains_poset_member(xposet_id.hub_pod(),
481  xmember_id.hub_pod(),
482  xauto_access);
483 }
484 
485 bool
487 contains_poset_member(const poset_path& xpath, bool xauto_access) const
488 {
489  bool result;
490 
491  // Preconditions:
492 
493  require(xpath.full());
494  require(xauto_access || state_is_read_accessible());
495  require(xauto_access ||
496  (contains_poset(xpath, false) ?
497  poset_state_is_read_accessible(xpath, false) :
498  true));
499 
500 
501  // Body:
502 
503  if(xauto_access)
504  {
505  get_read_access();
506  }
507 
508  result =
509  xpath.full() &&
510  contains_poset(xpath, false) &&
511  member_poset(xpath, false).contains_member(xpath.member_name(), xauto_access);
512 
513  if(xauto_access)
514  {
515  release_access();
516  }
517 
518  // Postconditions:
519 
520  // Exit
521 
522  return result;
523 }
524 
525 bool
527 contains_poset_members(const std::string& xposet_name,
528  const std::string xmember_names[],
529  int xmember_names_ct,
530  bool xauto_access) const
531 {
532  bool result = true;
533 
534  // Preconditions:
535 
536  require(!xposet_name.empty());
537  require(xmember_names != 0);
538  require_for_all(i, 0, xmember_names_ct, !xmember_names[i].empty());
539  require(xauto_access || state_is_read_accessible());
540  require(xauto_access ||
541  (contains_poset(xposet_name) ?
542  member_poset(xposet_name).state_is_read_accessible() :
543  true));
544 
545  // Body:
546 
547  result =
548  contains_member(xposet_name) &&
549  member_poset(xposet_name, false).contains_members(xmember_names,
550  xmember_names_ct,
551  xauto_access);
552 
553  // Postconditions:
554 
555  // Exit
556 
557  return result;
558 }
559 
560 bool
562 contains_poset_subposet(const poset_path& xpath, bool xauto_access) const
563 {
564  bool result;
565 
566  // Preconditions:
567 
568  require(xpath.full());
569  require(xauto_access || state_is_read_accessible());
570  require(xauto_access ||
571  ( contains_poset(xpath) ?
573  true));
574 
575  // Body:
576 
577  if(xauto_access)
578  {
579  get_read_access();
580  }
581 
582  result =
583  contains_member(xpath.poset_name(), false) &&
584  member_poset(xpath.poset_name(), false).includes_subposet(xpath.member_name(),
585  xauto_access);
586 
587  if(xauto_access)
588  {
589  release_access();
590  }
591 
592  // Postconditions:
593 
594  // Exit
595 
596  return result;
597 }
598 
601 member_poset(pod_index_type xhub_id, bool xauto_access) const
602 {
603  // Preconditions:
604 
605  require(xauto_access || state_is_read_accessible());
606  require(contains_member(xhub_id, xauto_access));
607 
608  if(xauto_access)
609  {
610  get_read_access();
611  }
612 
613  require(is_jim(xhub_id));
614 
615  // Body:
616 
617  namespace_poset_dof_map& ldof_map =
618  row_dof_map(member_dof_tuple_id(xhub_id, false));
619 
620  poset_state_handle& result = *ldof_map.poset_pointer();
621 
622  if(xauto_access)
623  {
624  release_access();
625  }
626 
627  return result;
628 }
629 
632 member_poset(const scoped_index& xid, bool xauto_access) const
633 {
634  // Preconditions:
635 
636  require(xauto_access || state_is_read_accessible());
637  require(contains_member(xid, xauto_access));
638 
639  if(xauto_access)
640  {
641  get_read_access();
642  }
643 
644  require(is_jim(xid));
645 
646  // Body:
647 
648  poset_state_handle& result = member_poset(xid.hub_pod(), false);
649 
650  if(xauto_access)
651  {
652  release_access();
653  }
654 
655  return result;
656 }
657 
660 member_poset(const poset_path& xpath, bool xauto_access) const
661 {
662  // Preconditions:
663 
664  require(xauto_access || state_is_read_accessible());
665  require(contains_member(xpath.poset_name(), xauto_access));
666 
667  if(xauto_access)
668  {
669  get_read_access();
670  }
671 
672  require(is_jim(xpath.poset_name()));
673 
674  // Body:
675 
676  poset_state_handle& result = member_poset(member_id(xpath.poset_name(), false), false);
677 
678  // Postconditions:
679 
680  if(xauto_access)
681  {
682  release_access();
683  }
684 
685  // Exit:
686 
687  return result;
688 }
689 
692 member_poset_schema_id(const scoped_index& xindex, bool xauto_access) const
693 {
694  // Preconditions:
695 
696  require(is_attached());
697  require(state_is_auto_read_accessible(xauto_access));
698  require(contains_poset(xindex));
699 
700  // Body:
701 
702  if(xauto_access)
703  {
704  get_read_access();
705  }
706 
707  namespace_poset_member lmbr(this, xindex);
708  pod_index_type result = lmbr.poset_prereq_id(0);
709  lmbr.detach_from_state();
710 
711  if(xauto_access)
712  {
713  release_access();
714  }
715 
716  // Postconditions:
717 
718  // Exit:
719 
720  return result;
721 }
722 
723 void
725 delete_poset(pod_index_type xhub_id, bool xauto_access)
726 {
727  // Preconditions:
728 
729  require(contains_poset(xhub_id, xauto_access));
730  require(member_poset(xhub_id, xauto_access).state_is_auto_read_write_accessible(true));
731  require(xauto_access || in_jim_edit_mode());
732 
733  // Body:
734 
735  if(xauto_access)
736  {
737  begin_jim_edit_mode(true);
738  }
739 
740  namespace_poset_member lmbr(this, xhub_id);
741 
742  delete_poset(lmbr);
743 
744  if(xauto_access)
745  {
746  end_jim_edit_mode(true, true);
747  }
748 
749  // Postconditions:
750 
751  ensure(!contains_poset(xhub_id, xauto_access));
752 
753  // Exit:
754 
755  return;
756 }
757 
758 void
760 delete_poset(scoped_index xid, bool xauto_access)
761 {
762  // Argument xid must be passed by value, otherwise
763  // since poset_state_handle::index returns a reference,
764  // it is possible to pass a reference to the index
765  // member of the poset handle itself, which has just
766  // been deleted, causing the usage of xid in postcondition
767  // to fail.
768 
769 
770  // Preconditions:
771 
772  require(contains_poset(xid, xauto_access));
773  require(member_poset(xid, xauto_access).state_is_auto_read_write_accessible(true));
774  require(xauto_access || in_jim_edit_mode());
775 
776  // Body:
777 
778  delete_poset(xid.hub_pod(), xauto_access);
779 
780  // Postconditions:
781 
782  ensure(!contains_poset(xid, xauto_access));
783 
784  // Exit:
785 
786  return;
787 }
788 
789 void
791 delete_poset(std::string xname, bool xauto_access)
792 {
793  // Argument xname passed by value as opposed to ref
794  // to avoid any possibility of it being a reference
795  // to something in the poset being deleted, which
796  // would cause usage in postcondition to fail.
797 
798  // Preconditions:
799 
800  require(contains_poset(xname, xauto_access));
801  require(member_poset(xname, xauto_access).state_is_auto_read_write_accessible(true));
802  require(xauto_access || in_jim_edit_mode())
803 ;
804  // Body:
805 
806  delete_poset(member_id(xname, xauto_access), xauto_access);
807 
808  // Postconditions:
809 
810  ensure(!contains_poset(xname, xauto_access));
811 
812  // Exit:
813 
814  return;
815 }
816 
817 void
819 delete_poset(poset_path xpath, bool xauto_access)
820 {
821  // Argument xpath passed by value as opposed to ref
822  // to avoid any possibility of it being a reference
823  // to something in the poset being deleted, which
824  // would cause usage in postcondition to fail.
825 
826  // Preconditions:
827 
828  require(contains_poset(xpath, xauto_access));
829  require(member_poset(xpath, xauto_access).state_is_auto_read_write_accessible(true));
830  require(xauto_access || in_jim_edit_mode());
831 
832  // Body:
833 
834  delete_poset(member_id(xpath.poset_name(), xauto_access), xauto_access);
835 
836  // Postconditions:
837 
838  ensure(!contains_poset(xpath, xauto_access));
839 
840  // Exit:
841 
842  return;
843 }
844 
845 void
848 {
849  // Preconditions:
850 
851  require(in_jim_edit_mode());
852  require(xmbr.is_jim());
853  require(xmbr.poset_pointer()->state_is_auto_read_write_accessible(true));
854 
855  // Body:
856 
857  define_old_variable(scoped_index old_xmbr_index = xmbr.index());
858 
859  // Get the poset handle.
860 
861  poset_state_handle* lposet = xmbr.poset_pointer();
862 
863  // Detach the handle from its state and delete the state;
864  // requires write access. One of the few places there's no matching release!
865 
866  lposet->get_read_write_access(true);
867  lposet->terminate_access();
868 
869  // Delete the handle.
870 
871  delete lposet;
872 
873  // Clean up the member dof tuple.
874 
875  xmbr.put_poset_pointer(0);
876  xmbr.put_poset_type_id(NOT_A_POSET_TYPE);
877  xmbr.put_poset_class("");
878 
879  // Delete the member.
880 
881  xmbr.delete_state(false);
882 
883  // Postconditions:
884 
885  ensure(!contains_poset(old_xmbr_index, false));
886  ensure(!xmbr.is_attached());
887 
888  // Exit:
889 
890  return;
891 }
892 
893 // PROTECTED MEMBER FUNCTIONS
894 
897 insert_poset(const poset_state_handle& xposet, const std::string& xposet_name, bool xauto_link)
898 {
899  // Preconditions:
900 
905 
906 
907  // require(xns.contains_member(name()) ?
908  // xns.state_is_read_write_accessible() :
909  // xns.in_jim_edit_mode());
910 
912  require(xposet.state_is_read_accessible());
913 
914  // Body:
915 
916  namespace_poset_member lns_mbr;
917 
918  if(contains_member(xposet_name, false))
919  {
920  // Namespace member with same name already exists;
921  // attach to it.
922 
923  lns_mbr.attach_to_state(this, xposet_name);
924 
925  // Set the name space member dofs:
926 
927  lns_mbr.put_poset(xposet);
928  }
929  else
930  {
931  // Member corresponding to xposet has not yet been created;
932  // Create it with same name as xposet.
933 
934  begin_jim_edit_mode(false);
935 
936  lns_mbr.new_jim_state(this, 0, false, false);
937  lns_mbr.put_name(xposet_name, true, false);
938 
939  // Add member poset to sequence id space.
940 
943  lid_space.push_back(lns_mbr.index());
944  release_member_poset_id_space(lid_space, false);
945 
946  // Set the name space member dofs:
947 
948  lns_mbr.put_poset(xposet);
949 
950  // Link the member into the appropriate group.
951 
952  if(xauto_link)
953  {
954  link_poset(lns_mbr);
955  }
956 
957  end_jim_edit_mode(true, false);
958  }
959 
960  scoped_index result = lns_mbr.index();
961 
962  lns_mbr.detach_from_state();
963 
964  // Postconditions:
965 
966  ensure(contains_member(result));
967  ensure(&member_poset(result) == &xposet);
968 
969  // Exit:
970 
971  return result;
972 }
973 
976 insert_poset(const poset_state_handle& xposet, const std::string& xposet_name, bool xauto_link, bool xauto_access)
977 {
978  // Preconditions:
979 
980  require(!contains_member(xposet_name));
981  require(xauto_access || in_jim_edit_mode());
982  require(xposet.state_is_auto_read_accessible(xauto_access));
983 
984  // Body:
985 
986  namespace_poset_member lns_mbr;
987 
988  // Member corresponding to xposet has not yet been created;
989  // Create it with same name as xposet.
990 
991  if(xauto_access)
992  {
993  begin_jim_edit_mode(true);
994  xposet.get_read_access();
995  }
996 
997 
998  lns_mbr.new_jim_state(this, 0, false, false);
999  lns_mbr.put_name(xposet_name, true, false);
1000 
1001  // Add member poset to sequence id space.
1002 
1004  member_id_spaces(false).get_id_space<scattered_insertion_index_space_handle>("member_poset_id_space");
1005  lid_space.push_back(lns_mbr.index());
1006  release_member_poset_id_space(lid_space, false);
1007 
1008  // Set the name space member dofs:
1009 
1010  lns_mbr.put_poset(xposet);
1011 
1012  // Link the member into the appropriate group.
1013 
1014  if(xauto_link)
1015  {
1016  link_poset(lns_mbr);
1017  }
1018 
1019 
1020  if(xauto_access)
1021  {
1022  end_jim_edit_mode(true, true);
1023  xposet.release_access();
1024  }
1025 
1026  scoped_index result = lns_mbr.index();
1027 
1028  // Postconditions:
1029 
1030  ensure(contains_member(result));
1031  ensure(&member_poset(result) == &xposet);
1032 
1033  // Exit:
1034 
1035  return result;
1036 }
1037 
1038 void
1041 {
1042  // Preconditions:
1043 
1044  require(contains_member(&xmbr));
1045  require(in_jim_edit_mode());
1046 
1047  // Body:
1048 
1049  pod_index_type lmbr_id = xmbr.index().pod();
1050  pod_index_type lmbr_schema_id = xmbr.poset_prereq_id(0);
1051 
1052  if(lmbr_schema_id == PRIMITIVES_SCHEMA_INDEX)
1053  {
1054  // This is a schema poset; link it under the schema defintions group.
1055 
1056  new_link(SCHEMA_DEFINITIONS_INDEX, lmbr_id);
1057  new_link(lmbr_id, BOTTOM_INDEX);
1058  }
1059  else
1060  {
1061  // Default is xmbr is in general spaces group.
1062 
1063  pod_index_type lgeneral_sets_id = member_id("general_sets", false);
1064 
1065  if(!is_valid(lgeneral_sets_id))
1066  {
1067  // general sets member not created yet; create it now.
1068 
1069  lgeneral_sets_id = new_member(false);
1070  put_member_name(lgeneral_sets_id, "general_sets", true, false);
1071  new_link(TOP_INDEX, lgeneral_sets_id);
1072  }
1073  new_link(lgeneral_sets_id, xmbr.index().pod());
1074  new_link(xmbr.index().pod(), BOTTOM_INDEX);
1075  }
1076 
1077  // Postconditions:
1078 
1079  // Exit:
1080 
1081  return;
1082 }
1083 
1084 // PRIVATE MEMBER FUNCTIONS
1085 
1086 
1087 // ===========================================================
1088 // PATH QUERY FACET
1089 // ===========================================================
1090 
1091 // PUBLIC MEMBER FUNCTIONS
1092 
1093 bool
1095 contains_path(const poset_path& xpath, bool xauto_access) const
1096 {
1097  bool result;
1098 
1099  // Preconditions:
1100 
1101  require(xauto_access || state_is_read_accessible());
1102 
1103  // Body:
1104 
1105  result = !xpath.poset_name().empty();
1106  if(result)
1107  {
1108  if(!xpath.member_name().empty())
1109  {
1110  result = contains_poset_member(xpath, xauto_access);
1111  }
1112  else
1113  {
1114  result = contains_poset(xpath, xauto_access);
1115  }
1116  }
1117 
1118  // Postconditions:
1119 
1120  // Exit:
1121 
1122  return result;
1123 }
1124 
1125 bool
1127 path_is_auto_read_accessible(const poset_path& xpath, bool xauto_access) const
1128 {
1129  bool result;
1130 
1131  // Preconditions:
1132 
1133  require(state_is_auto_read_accessible(xauto_access));
1134 
1135  // Body:
1136 
1137  result =
1138  contains_path(xpath, xauto_access) &&
1139  member_poset(xpath, xauto_access).state_is_auto_read_accessible(xauto_access);
1140 
1141  // Postconditions:
1142 
1143 
1144  // Exit:
1145 
1146  return result;
1147 }
1148 
1149 bool
1151 path_is_auto_read_write_accessible(const poset_path& xpath, bool xauto_access) const
1152 {
1153  bool result;
1154 
1155  // Preconditions:
1156 
1157  require(state_is_auto_read_accessible(xauto_access));
1158 
1159  // Body:
1160 
1161  result =
1162  contains_path(xpath, xauto_access) &&
1163  member_poset(xpath, xauto_access).state_is_auto_read_write_accessible(xauto_access);
1164 
1165  // Postconditions:
1166 
1167  // Exit:
1168 
1169  return result;
1170 }
1171 
1172 bool
1174 path_is_auto_read_available(const poset_path& xpath, bool xauto_access) const
1175 {
1176  bool result;
1177 
1178  // Preconditions:
1179 
1180  require(state_is_auto_read_accessible(xauto_access));
1181 
1182  // Body:
1183 
1184  result =
1185  !contains_path(xpath, xauto_access) ||
1186  member_poset(xpath, xauto_access).state_is_auto_read_accessible(xauto_access);
1187 
1188  // Postconditions:
1189 
1190  // Exit:
1191 
1192  return result;
1193 }
1194 
1195 bool
1197 path_is_auto_read_write_available(const poset_path& xpath, bool xauto_access) const
1198 {
1199  bool result;
1200 
1201  // Preconditions:
1202 
1203  require(state_is_auto_read_accessible(xauto_access));
1204 
1205  // Body:
1206 
1207  result =
1208  !contains_path(xpath, xauto_access) ||
1209  member_poset(xpath, xauto_access).state_is_auto_read_write_accessible(xauto_access);
1210 
1211  // Postconditions:
1212 
1213  // Exit:
1214 
1215  return result;
1216 }
1217 
1218 bool
1220 poset_state_is_read_accessible(const poset_path& xpath, bool xauto_access) const
1221 {
1222  bool result;
1223 
1224  // Preconditions:
1225 
1226  require(xauto_access || state_is_read_accessible());
1227 
1228  // Body:
1229 
1230  result =
1231  contains_poset(xpath, xauto_access) &&
1232  member_poset(xpath, xauto_access).state_is_read_accessible();
1233 
1234  // Postconditions:
1235 
1236  // Exit:
1237 
1238  return result;
1239 }
1240 
1241 bool
1243 poset_state_is_read_write_accessible(const poset_path& xpath, bool xauto_access) const
1244 {
1245  bool result;
1246 
1247  // Preconditions:
1248 
1249  require(xauto_access || state_is_read_accessible());
1250 
1251  // Body:
1252 
1253  result =
1254  contains_poset(xpath, xauto_access) &&
1255  member_poset(xpath, xauto_access).state_is_read_write_accessible();
1256 
1257  // Postconditions:
1258 
1259  // Exit:
1260 
1261  return result;
1262 }
1263 
1264 // PROTECTED MEMBER FUNCTIONS
1265 
1266 // PRIVATE MEMBER FUNCTIONS
1267 
1268 // ===========================================================
1269 // CURRENT NAMESPACE FACET
1270 // ===========================================================
1271 
1272 // PUBLIC MEMBER FUNCTIONS
1273 
1277 {
1278  // Preconditions:
1279 
1280  // Body:
1281 
1282  // Postconditions:
1283 
1284 
1285  // Exit:
1286 
1287  return _current_namespace;
1288 }
1289 
1290 void
1293 {
1294  // Preconditions:
1295 
1296  // Body:
1297 
1298  _current_namespace = xns;
1299 
1300  // Postconditions:
1301 
1302  ensure(current_namespace() == xns);
1303 
1304  // Exit:
1305 
1306  return;
1307 }
1308 
1309 // PROTECTED MEMBER FUNCTIONS
1310 
1311 // PRIVATE MEMBER FUNCTIONS
1312 
1314 sheaf::namespace_poset::
1315 _current_namespace = 0;
1316 
1317 
1318 // ===========================================================
1319 // FACTORY INITIALIZATION FACET
1320 // ===========================================================
1321 
1322 // PUBLIC MEMBER FUNCTIONS
1323 
1324 void
1327 {
1328  // Preconditions:
1329 
1330  // Body:
1331 
1336 
1337  // Postconditions:
1338 
1339  // Exit:
1340 
1341  return;
1342 }
1343 
1344 void
1347 {
1348  // Preconditions:
1349 
1350  // Body:
1351 
1352  static bool lposet_prototypes_initialized = false;
1353 
1354  if(!lposet_prototypes_initialized)
1355  {
1356  // Initialize the prototypes
1357 
1358  namespace_poset::make_prototype();
1359  namespace_poset_schema::make_prototype();
1360  poset::make_prototype();
1361  primitives_poset::make_prototype();
1362  primitives_poset_schema::make_prototype();
1363  refinable_poset::make_prototype();
1364 
1365  // Done with prototype initializations.
1366 
1367  lposet_prototypes_initialized = true;
1368 
1369 #ifdef DIAGNOSTIC_OUTPUT
1370  cout << "Initialized sheaves poset prototypes" << endl;
1371 #endif
1372 
1373  }
1374 
1375  // Postconditions:
1376 
1377  // Exit:
1378 
1379  return;
1380 }
1381 
1382 void
1385 {
1386  // Preconditions:
1387 
1388  // Body:
1389 
1390  static bool lcrg_interval_prototypes_initialized = false;
1391 
1392  if(!lcrg_interval_prototypes_initialized)
1393  {
1394  // Initialize the prototypes
1395 
1396  explicit_crg_interval::make_prototype();
1397  standard_member_hack_crg_interval::make_prototype();
1398 
1399  // Done with prototype initializations.
1400 
1401  lcrg_interval_prototypes_initialized = true;
1402 
1403 #ifdef DIAGNOSTIC_OUTPUT
1404  cout << "Initialized sheaves crg interval prototypes" << endl;
1405 #endif
1406  }
1407 
1408  // Postconditions:
1409 
1410  // Exit:
1411 
1412  return;
1413 }
1414 
1415 void
1418 {
1419  // Preconditions:
1420 
1421  // Body:
1422 
1423  static bool ldof_map_prototypes_initialized = false;
1424 
1425  if(!ldof_map_prototypes_initialized)
1426  {
1427  // Initialize the prototypes
1428 
1429  array_poset_dof_map::make_prototype();
1430  namespace_poset_dof_map::make_prototype();
1431  primitives_poset_dof_map::make_prototype();
1432 
1433  // Done with prototype initializations.
1434 
1435  ldof_map_prototypes_initialized = true;
1436 
1437 #ifdef DIAGNOSTIC_OUTPUT
1438  cout << "Initialized sheaves dof map prototypes" << endl;
1439 #endif
1440  }
1441 
1442  // Postconditions:
1443 
1444  // Exit:
1445 
1446  return;
1447 }
1448 
1449 void
1452 {
1453  // Preconditions:
1454 
1455  // Body:
1456 
1457  static bool lid_space_prototypes_initialized = false;
1458 
1459  if(!lid_space_prototypes_initialized)
1460  {
1461  // Initialize the prototypes
1462 
1463  array_index_space_state::make_prototype();
1464  hash_index_space_state::make_prototype();
1465  interval_index_space_state::make_prototype();
1466  list_index_space_state::make_prototype();
1467  offset_index_space_state::make_prototype();
1468  primary_index_space_state::make_prototype();
1469  primary_sum_index_space_state::make_prototype();
1470  primitives_index_space_state::make_prototype();
1471  reserved_primary_index_space_state::make_prototype();
1472  singleton_index_space_state::make_prototype();
1473 
1474  array_index_space_interval::make_prototype();
1475  constant_index_space_interval::make_prototype();
1476  explicit_index_space_interval::make_prototype();
1477  ragged_array_index_space_interval::make_prototype();
1478  singleton_index_space_interval::make_prototype();
1479 
1480  // Done with prototype initializations.
1481 
1482  lid_space_prototypes_initialized = true;
1483 
1484 #ifdef DIAGNOSTIC_OUTPUT
1485  cout << "Initialized sheaves id space prototypes" << endl;
1486 #endif
1487  }
1488 
1489  // Postconditions:
1490 
1491  // Exit:
1492 
1493  return;
1494 }
1495 
1496 // PROTECTED MEMBER FUNCTIONS
1497 
1498 void
1501 {
1502  // cout << endl << "Entering namespace_poset::virutal_initialize_prototypes." << endl;
1503 
1504  // Preconditions:
1505 
1506 
1507  // Body:
1508 
1509  // Call static version defined in this class.
1510 
1512 
1513  // Postconditions:
1514 
1515 
1516  // Exit:
1517 
1518  // cout << "Leaving namespace_poset::virutal_initialize_prototypes." << endl;
1519  return;
1520 }
1521 
1522 // PRIVATE MEMBER FUNCTIONS
1523 
1524 // ===========================================================
1525 // STATE FACET
1526 // ===========================================================
1527 
1528 // PUBLIC MEMBER FUNCTIONS
1529 
1532 type_id() const
1533 {
1534  return NAMESPACE_POSET_ID;
1535 }
1536 
1537 const char*
1539 class_name() const
1540 {
1541  // Preconditions:
1542 
1543  // Body:
1544 
1545  static const char* result = "namespace_poset";
1546 
1547  // Postconditions:
1548 
1549  // Exit:
1550 
1551  return result;
1552 }
1553 
1554 void
1556 begin_jim_edit_mode(bool xauto_access)
1557 {
1558  // Preconditions:
1559 
1560  // Body:
1561 
1563 
1564  // Postconditions:
1565 
1566  // Exit
1567 
1568  return;
1569 }
1570 
1571 void
1573 end_jim_edit_mode(bool xensure_lattice_invariant, bool xauto_access)
1574 {
1575  // Preconditions:
1576 
1577  // Body:
1578 
1579  poset_state_handle::end_jim_edit_mode(xensure_lattice_invariant, xauto_access);
1580 
1581  // Postconditions:
1582 
1583  // Exit
1584 
1585  return;
1586 }
1587 
1588 void
1591 {
1592  // Preconditions:
1593 
1594  require(is_attached());
1595 
1596  // Body:
1597 
1598  define_old_variable(int old_access_request_depth =
1600  define_old_variable(int old_primitives_access_request_depth =
1602 
1603  // Get read access to this:
1604 
1606 
1607  // Get read access to the primitives poset.
1608 
1610 
1611  // Postconditions:
1612 
1613  ensure(state_is_read_accessible());
1614  ensure(access_request_depth() ==
1615  old_access_request_depth + 1);
1616 
1618  ensure(primitives().access_request_depth() ==
1619  old_primitives_access_request_depth + 1);
1620 
1621  // Exit
1622 
1623  return;
1624 }
1625 
1626 void
1628 get_read_write_access(bool xrelease_read_only_access)
1629 {
1630  // Preconditions:
1631 
1632  require(is_attached());
1633  require(!xrelease_read_only_access ? state_is_not_read_only_accessible() : true);
1634 
1635  // Body:
1636 
1637  define_old_variable(int old_access_request_depth = access_request_depth());
1638  define_old_variable(int old_primitives_access_request_depth =
1640 
1641  // Get read access to this:
1642 
1643  poset_state_handle::get_read_write_access(xrelease_read_only_access);
1644 
1645  // Get read access to the primitives poset.
1646 
1648 
1649  // Postconditions:
1650 
1651  ensure(state_is_read_accessible());
1652  ensure(access_request_depth() == old_access_request_depth + 1);
1654  ensure(primitives().access_request_depth() ==
1655  old_primitives_access_request_depth + 1);
1656 
1657  // Exit
1658 
1659  return;
1660 }
1661 
1662 void
1664 release_access(bool xall) const
1665 {
1666  // Preconditions:
1667 
1668  require(state_is_read_accessible());
1669 
1670  // Body:
1671 
1672  int old_access_request_depth = access_request_depth();
1673  int old_primitives_access_request_depth = primitives().access_request_depth();
1674 
1675  // Release at least one level of access for this..
1676  // If xall, release all levels of access for this.
1677  // Since each level of access to this also
1678  // acquired a level of access to the primitives,
1679  // release the same number of levels of access to the primitives.
1680  // Note that this may not be all the levels of access of the primitives.
1681  // Also note that poset_state_handle::release_Access takes care of the schema.
1682 
1683  do
1684  {
1685  // Release one level of access.
1686 
1687  primitives().release_access(false);
1689  }
1690  while(xall && state_is_read_accessible());
1691 
1692 
1693  // Postconditions:
1694 
1695  ensure(!xall ?
1696  access_request_depth() == old_access_request_depth - 1 :
1697  access_request_depth() == 0);
1698  ensure(access_request_depth() == 0 ? state_is_not_read_accessible() : true);
1699  ensure(!xall ?
1700  primitives().access_request_depth() == old_primitives_access_request_depth - 1 :
1701  primitives().access_request_depth() == 0);
1702  ensure(primitives().access_request_depth() == 0 ?
1704  true);
1705 
1706  // Exit
1707 
1708  return;
1709 }
1710 
1711 void
1714 {
1715 
1716  // Preconditions:
1717 
1718  // Body:
1719 
1720  // Detach the primitives and schema
1721 
1722  primitives().detach_from_state();
1725 
1726  // Detach from the standard subposets, members, and state
1727 
1729 
1730  // Postconditions:
1731 
1732  ensure(!is_attached());
1733  ensure(!is_external());
1734  ensure(!primitives().is_attached());
1735  ensure(!primitives_schema().is_attached());
1736 
1737  // Exit
1738 
1739  return;
1740 }
1741 
1742 // PROTECTED MEMBER FUNCTIONS
1743 
1744 void
1746 new_state(const std::string& xname)
1747 {
1748  // Preconditions:
1749 
1750  require(poset_path::is_valid_name(xname));
1751 
1752  // Body:
1753 
1754  // Detach from the current state, if any.
1755 
1757 
1758  // Disable invariant checking in
1759  // member functions until construction finished
1760 
1762 
1763  // Initialize the prototypes; use the virtual method
1764  // to ensure the prototypes for actual namespace type
1765  // being created are initialized.
1766 
1768 
1769  // The bootstrap problem:
1770  //
1771  // The basic issue is that we need the primitives_poset_schema
1772  // to create the namespace and we need the namespace to create
1773  // the primitives_poset_schema.
1774  //
1775  // The precise mechanism of dependency is that the primitives_poset_schema
1776  // provides the schema for itself and the namespace_poset_schema which
1777  // provides the schema for the namespace. We can't instantiate
1778  // primitives_poset_schema without instantiating primitive_poset_dof_maps as
1779  // dof tuples for it members and, since primitives_poset_schema is its own schema,
1780  // we can't instantiate the dof tuples without instantiating the poset. In addition,
1781  // the standard poset constructors insert the poset into a namespace, so we also
1782  // can't create the two schema posets or the primtives poset until we have a
1783  // namespace. Furthermore, the various member functions invoked by the constructor
1784  // require state_is_read_write_accessible(), which it turn ensures
1785  // primitives().state_is_read_accessible(), but the primitives haven't been
1786  // created yet.
1787  //
1788  // The bootstrap thus requires three conditions:
1789  //
1790  // 1) primitives_poset_dof_map must be instantiatable without a schema;
1791  // 2) primitives_poset_schema must be instantiated with itself as schema;
1792  // 3) primitives_poset must be instantiated before we get access to the namespace
1793  // state; and
1794  // 3) primitives_poset_schema, namespace_poset_schema, and primitives_poset
1795  // must not insert themselves into the namespace.
1796  //
1797  // So also the discussion in primitives_poset_dof_map.
1798 
1799  // Create the primitives schema. Creates dof tuples of type
1800  // primitives_poset_dof_map and uses itself as schema.
1801  // Inserted in the namespace in routine initialize_standard_members.
1802 
1803  _primitives_schema.new_state();
1804  _primitives_schema.get_read_access();
1805 
1806  // Create the namespace schema using the primitives schema.
1807  // Inserted in the namespace in routine initialize_standard_members.
1808 
1809  _namespace_schema.new_state(&(_primitives_schema.top()));
1811 
1812  // Now we have a schema, create the poset state object.
1813 
1814  _state = new poset_state(&(_namespace_schema.top()), NAMESPACE_POSET_ID, xname);
1815 
1816  // Create the primitives poset using the primitives schema
1817  // Inserted in the namespace in routine initialize_standard_members.
1818 
1819  _primitives.new_state(&(_primitives_schema.top()));
1820 
1821  // Need to get read-write access to continue construction.
1822 
1824 
1825  // Initialize the table dof map.
1826  // This class has no table dofs, but we want a non-null dof map anyway.
1827 
1828  initialize_table_dofs(0,0);
1829 
1830  // Initialize additional row structure.
1831  // Want the primary term for bottom and top in the top id space
1832  // allocated before the member poset id space which
1833  // must be allocated before the other standard namespace members
1834  // are initialized. So do it like this:
1835 
1837 
1839 
1840  // Initialize the namespace features
1841 
1842  initialize_namespace(*this);
1843 
1844  // Make this the current namespace.
1845 
1846  put_current_namespace(this);
1847 
1848  // Set the standard id spaces.
1849 
1851 
1852  // Construct additional members, if any.
1853 
1855 
1856  // Now the invariant is satisfied
1857 
1859 
1860  // Postconditions:
1861 
1862  ensure(invariant());
1863  ensure(name() == xname);
1864  ensure(!in_jim_edit_mode());
1865 // ensure(host() == 0);
1866 // ensure(!index().is_valid());
1867  ensure(index().same_scope(member_hub_id_space(false)));
1868  ensure(has_standard_subposet_ct());
1869  ensure(current_namespace() == this);
1870 
1871  // release access
1872 
1873  release_access();
1874 
1875  ensure(state_is_not_read_accessible());
1876 }
1877 
1878 void
1881 {
1882  // Preconditions:
1883 
1884  require(state_is_read_accessible());
1885 
1886  // Body:
1887 
1889 
1893 
1895 
1896  primitives().attach_to_state(this, PRIMITIVES_INDEX);
1897  primitives_schema().attach_to_state(this, PRIMITIVES_SCHEMA_INDEX);
1898  namespace_schema().attach_to_state(this, NAMESPACE_SCHEMA_INDEX);
1899 
1901 
1902  // Postconditions:
1903 
1904  ensure(postcondition_of(poset_state_handle::attach_handle_data_members()));
1905  ensure(primitives().is_attached());
1906  ensure(primitives_schema().is_attached());
1907  ensure(namespace_schema().is_attached());
1908 
1909  // Exit
1910 
1911  return;
1912 }
1913 
1914 // PRIVATE MEMBER FUNCTIONS
1915 
1916 
1917 // ===========================================================
1918 // GLOBAL ATTRIBUTES FACET
1919 // ===========================================================
1920 
1921 // PUBLIC MEMBER FUNCTIONS
1922 
1923 std::string
1925 name() const
1926 {
1927  string result;
1928 
1929  // Preconditions:
1930 
1931  // is_external is always false for namespace_poset, so
1932  // precondition is simpler than in parent.
1933 
1934  require(state_is_read_accessible());
1935 
1936  // Body:
1937 
1938  // Redefined just to change precondition;
1939  // makes presentation clearer in Prog Guide.
1940 
1941  // Postconditions:
1942 
1943  // Exit
1944 
1945  return poset_state_handle::name();
1946 }
1947 
1948 std::string
1950 name(bool xauto_access) const
1951 {
1952  string result;
1953 
1954  // Preconditions:
1955 
1956  // is_external is always false for namespace_poset, so
1957  // precondition is simpler than in parent.
1958 
1959  require(state_is_auto_read_accessible(xauto_access));
1960 
1961  // Body:
1962 
1963  // Redefined just to change precondition;
1964  // makes presentation clearer in Prog Guide.
1965 
1966  // Postconditions:
1967 
1968  // Exit
1969 
1970  return poset_state_handle::name(xauto_access);
1971 }
1972 
1975 path(bool xauto_access) const
1976 {
1977 
1978  // Preconditions:
1979 
1980  // is_external is always false for namespace_poset, so
1981  // precondition is simpler than in parent.
1982 
1983  require(state_is_auto_read_accessible(xauto_access));
1984 
1985  // Body:
1986 
1987  // Redefined just to change precondition;
1988  // makes presentation clearer in Prog Guide.
1989 
1991 
1992  // Postconditions:
1993 
1994  ensure(!result.empty());
1995  ensure(!result.full());
1996 
1997  // Exit:
1998 
1999  return result;
2000 }
2001 
2002 // PROTECTED MEMBER FUNCTIONS
2003 
2004 void
2007 {
2008  // Preconditions:
2009 
2010  require(state_is_read_accessible());
2011 
2012  // Body:
2013 
2014  // Set the host and index features of the poset.
2015 
2016  _name_space = 0;
2017 
2018  _index.invalidate();
2020 
2021  // Postconditions:
2022 
2023  // Exit
2024 
2025  return;
2026 }
2027 
2028 // PRIVATE MEMBER FUNCTIONS
2029 
2030 
2031 // ===========================================================
2032 // SCHEMA FACET
2033 // ===========================================================
2034 
2035 // PUBLIC MEMBER FUNCTIONS
2036 
2037 bool
2039 row_dof_map_conforms(const poset_dof_map* xdof_map) const
2040 {
2041  bool result;
2042 
2043  // Preconditions:
2044 
2045  require(xdof_map != 0);
2046 
2047  // Body:
2048 
2049  // Row dofs must be namespace_poset_dof_map
2050 
2051  result = (dynamic_cast<const namespace_poset_dof_map*>(xdof_map) != 0);
2052 
2053  // Postconditions:
2054 
2055  ensure(result ? (dynamic_cast<const namespace_poset_dof_map*>(xdof_map) != 0) : true);
2056 
2057  // Exit
2058 
2059  return result;
2060 }
2061 
2064 row_dof_map(pod_index_type xtuple_hub_id, bool xrequire_write_access) const
2065 {
2066  namespace_poset_dof_map* result_ptr;
2067 
2068  // Preconditions:
2069 
2070  require(xrequire_write_access ? state_is_read_write_accessible() : state_is_read_accessible());
2071  require(contains_row_dof_tuple(xtuple_hub_id));
2072 
2073  // Body:
2074 
2075  result_ptr = dynamic_cast<namespace_poset_dof_map*>(table().row_dof_tuple(xtuple_hub_id));
2076 
2077  // Pointer should not be null
2078 
2079  assertion(result_ptr != 0);
2080 
2081  // Postconditions:
2082 
2083  // Exit
2084 
2085  return *result_ptr;
2086 }
2087 
2088 const sheaf::scoped_index&
2091 {
2092  // Preconditions:
2093 
2094  require(state_is_read_write_accessible());
2095 
2096  // Body:
2097 
2098  define_old_variable(int old_row_dof_tuple_ct = row_dof_tuple_ct());
2099 
2100  // Create a new namespace poset dof map
2101 
2102  poset_dof_map* lmap = new namespace_poset_dof_map(this);
2103  table().put_row_dof_tuple(lmap);
2104  const scoped_index& result = lmap->index();
2105 
2106  // Postconditions:
2107 
2108  ensure(row_dof_tuple_ct() == old_row_dof_tuple_ct+1);
2109  ensure(contains_row_dof_tuple(result));
2110 
2111  // Exit
2112 
2113  return result;
2114 }
2115 
2116 // PROTECTED MEMBER FUNCTIONS
2117 
2118 // PRIVATE MEMBER FUNCTIONS
2119 
2120 
2121 // ===========================================================
2122 // MEMBERSHIP FACET
2123 // ===========================================================
2124 
2125 // PUBLIC MEMBER FUNCTIONS
2126 
2130 {
2131  // Preconditions:
2132 
2133  // Body:
2134 
2135  namespace_poset_member& result = *(reinterpret_cast<namespace_poset_member*>(_top));
2136 
2137  // Postconditions:
2138 
2139  // Exit
2140 
2141  return result;
2142 }
2143 
2146 top() const
2147 {
2148  // Preconditions:
2149 
2150  // Body:
2151 
2152  const namespace_poset_member& result = *(reinterpret_cast<const namespace_poset_member*>(_top));
2153 
2154  // Postconditions:
2155 
2156  // Exit
2157 
2158  return result;
2159 }
2160 
2164 {
2165  // Preconditions:
2166 
2167  // Body:
2168 
2169  namespace_poset_member& result = *(reinterpret_cast<namespace_poset_member*>(_bottom));
2170 
2171  // Postconditions:
2172 
2173  // Exit
2174 
2175  return result;
2176 }
2177 
2180 bottom() const
2181 {
2182  // Preconditions:
2183 
2184  // Body:
2185 
2186  const namespace_poset_member& result = *(reinterpret_cast<const namespace_poset_member*>(_bottom));
2187 
2188  // Postconditions:
2189 
2190  // Exit
2191 
2192  return result;
2193 }
2194 
2195 void
2198 {
2199  // Preconditions:
2200 
2201  require(state_is_read_write_accessible());
2202 
2203  // Body:
2204 
2205  // We have to delete the members in reverse dependency order, that is,
2206  // we can not delete a prerequisite before the posets that depend on it.
2207  // We'll do that by traversing the dependency graph in post order,
2208  // pushing the prerequisites onto a stack, then traverse the stack.
2209  // To start the dependency graph traversal, we need the maximal members.
2210 
2211  // Find the "maximal" members of the dependency graph,
2212  // that is, the members which are not a prerequisite for
2213  // some other member
2214 
2215  // First create a set containing all members, except the standard ones.
2216 
2217  typedef set<pod_index_type> lmax_mbrs_type;
2218 
2219  lmax_mbrs_type lmax_mbrs;
2221  while(!litr.is_done())
2222  {
2223  if(litr.index().hub_pod() >= standard_member_ct())
2224  {
2225  lmax_mbrs.insert(litr.index().hub_pod());
2226  }
2227  litr.next();
2228  }
2229 
2230  // Now the maximal members set contains all non-standard members.
2231  // Next, traverse the dependency graph, removing prerequisites from the set.
2232 
2233  litr.reset();
2234  namespace_poset_member lns_mbr(top());
2235  while(!litr.is_done())
2236  {
2237  if(is_jim(litr.index(), false))
2238  {
2239  // This member is a jim and has an associated poset
2240 
2241  lns_mbr.attach_to_state(litr.index());
2242 
2243  for(int i=0; i<PREREQ_IDS_UB; ++i)
2244  {
2245  pod_index_type lprereq_id = lns_mbr.poset_prereq_id(i);
2246 
2247  if(is_valid(lprereq_id))
2248  {
2249  lmax_mbrs.erase(lprereq_id);
2250  }
2251  }
2252  }
2253  litr.next();
2254  }
2255  lns_mbr.detach_from_state();
2256 
2257  // Now lmax members contains the maximal members and any non-standard jrms.
2258 
2259  // Traverse the dependency graph in post order,
2260  // pushing the members onto a stack.
2261 
2262  zn_to_bool lvisited(member_index_ub().pod());
2263  list<pod_index_type> lrev_post;
2264  lmax_mbrs_type::iterator lmax_mbrs_itr = lmax_mbrs.begin();
2265 
2266  pod_index_type lmbr_id;
2267 
2268  while(lmax_mbrs_itr != lmax_mbrs.end())
2269  {
2270  lmbr_id = *lmax_mbrs_itr;
2271  if(lmbr_id >= standard_member_ct())
2272  {
2273  if(is_jim(lmbr_id, false))
2274  {
2275  // This mbr has an associated poset; traverse its prerequisites
2276 
2277  ::traverse_prereqs(this, lmbr_id, lrev_post, lvisited);
2278  }
2279  else
2280  {
2281  // This is a jrm; just push it onto the stack.
2282 
2283  lvisited.put(lmbr_id, true);
2284  lrev_post.push_front(lmbr_id);
2285  }
2286  }
2287  ++lmax_mbrs_itr;
2288  }
2289 
2290 #ifdef DIAGNOSTIC_OUTPUT
2291  list<pod_index_type>::iterator lrev_post_itr = lrev_post.begin();
2292  while(lrev_post_itr != lrev_post.end())
2293  {
2294  cout << " " << *lrev_post_itr;
2295  ++lrev_post_itr;
2296  }
2297  cout << endl << endl;
2298 #endif
2299 
2300  // Now popping the stack will traverse the members in reverse dependency order,
2301  // any prerequisite will appear after all posets that require it.
2302  // So now we can just run the stack, deleting as we go.
2303 
2305 
2306  while(!lrev_post.empty())
2307  {
2308  lns_mbr.attach_to_state(this, lrev_post.front());
2309 
2310 #ifdef DIAGNOSTIC_OUTPUT
2311  cout << endl << "deleting ns mbr: " << lns_mbr.index()
2312  << " " << lns_mbr.name()
2313  << endl;
2314 #endif
2315 
2316  if(lns_mbr.is_jim(false))
2317  {
2318  // Delete the handle and state of the associated poset;
2319  // also deletes member state.
2320 
2321  delete_poset(lns_mbr);
2322  }
2323  else
2324  {
2325  // This is a jrm, doesn't have an associated poset.
2326  // Just delete the member state.
2327 
2328  lns_mbr.delete_state();
2329  }
2330 
2331  lrev_post.pop_front();
2332  }
2333 
2335 
2336  // Remove all non-standard id spaces in this and the remaining members.
2337 
2338  clear_member_id_spaces(false);
2342 
2343  // Postconditions:
2344 
2345  ensure(has_standard_member_ct());
2346  ensure(member_id_spaces(false).has_only_standard_id_spaces());
2347  ensure(primitives().member_id_spaces(false).has_only_standard_id_spaces());
2348  ensure(primitives_schema().member_id_spaces(false).has_only_standard_id_spaces());
2349  ensure(namespace_schema().member_id_spaces(false).has_only_standard_id_spaces());
2350 
2351  // Exit
2352 
2353  return;
2354 }
2355 
2356 // PROTECTED MEMBER FUNCTIONS
2357 
2358 void
2361 {
2362  // Preconditions:
2363 
2364  // Body:
2365 
2366  // First create the standard members of the base class,
2367  // creates the primary terrm in the top id space before
2368  // the secondary term allocated in initialize_member_poset_id_space.
2369 
2371 
2372  // Now create the standard id space; secondary terms it top id space.
2373 
2375 
2376  // Insert primitives schema poset into the namespace.
2377  // Creates primitives schema member at index 2.
2378 
2379  _primitives_schema.initialize_namespace(*this,
2381  false);
2382 
2383  // Insert namespace schema poset into the namespace.
2384  // Creates namespace schema member at index 3.
2385 
2388  false);
2389 
2390  // Insert primitives poset into the namespace.
2391  // Creates primitives member at index 4.
2392 
2393  _primitives.initialize_namespace(*this,
2395  false);
2396 
2397  // Now there should be 5 standard members: top, bottom, primitives,
2398  // primitives_schema, and namespace schema.
2399 
2400  // Make the schema definitions group
2401 
2402  scoped_index ldefn_mbrs[2];
2403  ldefn_mbrs[0] = _primitives_schema.index();
2404  ldefn_mbrs[1] = _namespace_schema.index();
2405 
2406  total_poset_member ldefn_mbr(this, ldefn_mbrs, 2, tern::TRUE, false);
2407  ldefn_mbr.put_name("schema definitions", true, false);
2408  ldefn_mbr.detach_from_state();
2409 
2410  // Now there's 6 standard members:
2411  // bottom, top, primitives, primitives_schema,
2412  // namespace_schema, and schema definitions
2413 
2414  // All the memembers and row dof tuples are standard.
2415 
2418 
2419  // Postconditions:
2420 
2421  ensure(_primitives.is_attached());
2422  ensure(_primitives.host() == this);
2423  ensure(_primitives.index() == PRIMITIVES_INDEX);
2424  ensure(_primitives_schema.is_attached());
2425  ensure(_primitives_schema.host() == this);
2426  ensure(_primitives_schema.index() == PRIMITIVES_SCHEMA_INDEX);
2427  ensure(_namespace_schema.is_attached());
2428  ensure(_namespace_schema.host() == this);
2429  ensure(_namespace_schema.index() == NAMESPACE_SCHEMA_INDEX);
2430  ensure(has_standard_member_ct());
2432 
2433  // Exit
2434 
2435  return;
2436 }
2437 
2438 void
2441 {
2442  // Preconditions:
2443 
2444  require(state_is_read_write_accessible());
2445 
2446  define_old_variable(int old_access_request_depth = access_request_depth());
2447 
2448  // Body:
2449 
2450  // Nothing to do in this class;
2451  // intended to be redefined in descendants.
2452 
2453  // Postconditions:
2454 
2455  ensure(access_request_depth() == old_access_request_depth);
2456 
2457  // Exit:
2458 
2459  return;
2460 }
2461 
2462 // PRIVATE MEMBER FUNCTIONS
2463 
2464 
2465 // ===========================================================
2466 // MEMBER ID SPACE FAMILY FACET
2467 // ===========================================================
2468 
2469 // PUBLIC MEMBER FUNCTIONS
2470 
2473 get_member_poset_id_space(bool xauto_access) const
2474 {
2475  // Preconditions:
2476 
2477  require(state_is_auto_read_accessible(xauto_access));
2478  require(member_id_spaces(xauto_access).contains("member_poset_id_space"));
2479 
2480  // Body:
2481 
2482  if(xauto_access)
2483  {
2484  get_read_access();
2485  }
2486 
2487  const index_space_handle& result = member_id_spaces(false).get_id_space("member_poset_id_space");
2488 
2489  if(xauto_access)
2490  {
2491  release_access();
2492  }
2493 
2494  // Postconditions:
2495 
2496  ensure(result.is_attached());
2497  ensure(result.name() == "member_poset_id_space");
2498 
2499  // Exit:
2500 
2501  return result;
2502 }
2503 
2504 void
2506 release_member_poset_id_space(index_space_handle& xid_space, bool xauto_access) const
2507 {
2508  // Preconditions:
2509 
2510  require(state_is_auto_read_accessible(xauto_access));
2511 
2512  // Body:
2513 
2514  if(xauto_access)
2515  {
2516  get_read_access();
2517  }
2518 
2519  member_id_spaces(false).release_id_space(xid_space);
2520 
2521  if(xauto_access)
2522  {
2523  release_access();
2524  }
2525 
2526  // Postconditions:
2527 
2528  // Exit:
2529 
2530  return;
2531 }
2532 
2535 get_member_poset_id_space_iterator(bool xauto_access) const
2536 {
2537  // Preconditions:
2538 
2539  require(state_is_auto_read_accessible(xauto_access));
2540  require(member_id_spaces(xauto_access).contains("member_poset_id_space"));
2541 
2542  // Body:
2543 
2544  if(xauto_access)
2545  {
2546  get_read_access();
2547  }
2548 
2549  index_space_iterator& result =
2550  member_id_spaces(false).get_id_space_iterator("member_poset_id_space");
2551 
2552  if(xauto_access)
2553  {
2554  release_access();
2555  }
2556 
2557  // Postconditions:
2558 
2559  ensure(result.is_attached());
2560  ensure(result.name() == "member_poset_id_space");
2561 
2562  // Exit:
2563 
2564  return result;
2565 }
2566 
2567 void
2570 {
2571  // Preconditions:
2572 
2573  require(state_is_auto_read_accessible(xauto_access));
2574 
2575  // Body:
2576 
2577  if(xauto_access)
2578  {
2579  get_read_access();
2580  }
2581 
2583 
2584  if(xauto_access)
2585  {
2586  release_access();
2587  }
2588 
2589  // Postconditions:
2590 
2591  // Exit:
2592 
2593  return;
2594 }
2595 
2596 // PROTECTED MEMBER FUNCTIONS
2597 
2598 
2599 void
2602 {
2603  // Preconditions:
2604 
2605  require(state_is_read_write_accessible());
2606  require(!member_id_spaces(false).contains("member_poset_id_space"));
2607 
2608  // Body:
2609 
2610  array_index_space_state::new_space(member_id_spaces(false), "member_poset_id_space", false, 0);
2611 
2612  // Postconditions:
2613 
2614  ensure(member_id_spaces(false).contains("member_poset_id_space"));
2615 
2616  // Exit:
2617 
2618  return;
2619 }
2620 
2621 // PRIVATE MEMBER FUNCTIONS
2622 
2623 
2624 // ===========================================================
2625 // I/O SUPPORT FACET
2626 // ===========================================================
2627 
2628 // PUBLIC MEMBER FUNCTIONS
2629 
2632 prereq_id(int xi) const
2633 {
2634  // The namespace_poset has no prerequisites and
2635  // this routine should never be called.
2636 
2637  return invalid_pod_index();
2638 }
2639 
2640 // PROTECTED MEMBER FUNCTIONS
2641 
2642 void
2644 put_name(const std::string& xname)
2645 {
2646  // cout << endl << "Entering namespace_poset::put_name." << endl;
2647 
2648  // Preconditions:
2649 
2650  require(state_is_read_write_accessible());
2651  require(poset_path::is_valid_name(xname));
2652 
2653  // Body:
2654 
2655  state_obj()->put_name(xname);
2656 
2657  // Postconditions:
2658 
2659  ensure(name() == xname);
2660 
2661  // Exit:
2662 
2663  // cout << "Leaving namespace_poset::put_name." << endl;
2664  return;
2665 }
2666 
2667 
2668 // PRIVATE MEMBER FUNCTIONS
2669 
2670 
2671 // ===========================================================
2672 // DEBUGGING FACET
2673 // ===========================================================
2674 
2675 // PUBLIC MEMBER FUNCTIONS
2676 
2677 void
2679 to_stream(std::ostream& xos)
2680 {
2681  xos << *this;
2682 }
2683 
2684 std::string
2687 {
2688  ostringstream oss;
2689  oss << *this;
2690  return oss.str();
2691 }
2692 
2693 // PROTECTED MEMBER FUNCTIONS
2694 
2695 // PRIVATE MEMBER FUNCTIONS
2696 
2697 
2698 // ===========================================================
2699 // ANY FACET
2700 // ===========================================================
2701 
2702 // PUBLIC MEMBER FUNCTIONS
2703 
2704 bool
2706 is_ancestor_of(const any* xother) const
2707 {
2708  bool result;
2709 
2710  // Preconditions:
2711 
2712  // Body:
2713 
2714  result = dynamic_cast<const namespace_poset*>(xother) != 0;
2715 
2716  // Postconditions:
2717 
2718  // Exit
2719 
2720  return result;
2721 }
2722 
2725 clone() const
2726 {
2727  namespace_poset* result;
2728 
2729  // Preconditions:
2730 
2731  // Body:
2732 
2733  result = new namespace_poset;
2734 
2735  // Postconditions:
2736 
2737  ensure(result != 0);
2738  ensure(is_same_type(result));
2739 
2740  // Exit
2741 
2742  return result;
2743 }
2744 
2745 bool
2747 invariant() const
2748 {
2749  bool result = true;
2750 
2751  // Preconditions:
2752 
2753  // Body:
2754 
2755  if(invariant_check())
2756  {
2757  invariance(poset_state_handle::invariant());
2758 
2760 
2761  invariance(host() == 0);
2762  invariance(!index().is_valid());
2763  invariance(!is_external());
2764 
2765  invariance(is_attached() ? primitives().is_attached() : true);
2766  invariance(is_attached() ?
2767  (primitives().index() == PRIMITIVES_INDEX) :
2768  true);
2769  invariance(state_is_read_accessible() ?
2771  true);
2772 
2773  invariance(is_attached() ? primitives_schema().is_attached() : true);
2774  invariance(is_attached() ?
2775  (primitives_schema().index() == PRIMITIVES_SCHEMA_INDEX) :
2776  true);
2777  invariance(state_is_read_accessible() ?
2779  true);
2780 
2782  }
2783 
2784  // Postconditions:
2785 
2786  // Exit
2787 
2788  return result;
2789 }
2790 
2791 // PROTECTED MEMBER FUNCTIONS
2792 
2793 // PRIVATE MEMBER FUNCTIONS
2794 
2795 
2796 // =============================================================================
2797 // NON-MEMBER FUNCTIONS
2798 // =============================================================================
2799 
2800 std::ostream &
2801 sheaf::
2802 operator << (std::ostream &os, const namespace_poset& ns)
2803 {
2804 
2805  // Preconditions:
2806 
2807  require(unexecutable(acquires and releases read access));
2808 
2809  // Body:
2810 
2811  ns.get_read_access(); // also gets access to schema
2812 
2813  os << endl << endl << "#### BEGIN NAMESPACE " << ns.name() << " ###################" << endl;
2814 
2815 
2816 
2817  os << static_cast<const poset_state_handle&>(ns) << endl;
2818 
2819  subposet_member_iterator itr(const_cast<namespace_poset&>(ns).whole());
2820 
2821  while(!itr.is_done())
2822  {
2823  if(itr.is_jim())
2824  {
2825  // Member_poset returns a handle of the proper specialized type,
2826  // as opposed to attaching a general poset_state_handle.
2827 
2828  poset_state_handle& lpsh = ns.member_poset(itr.index());
2829  if(lpsh.is_attached())
2830  {
2831  lpsh.get_read_access();
2832  os << lpsh << endl;
2833  lpsh.release_access();
2834  }
2835  }
2836  itr.next();
2837  }
2838 
2839  os << "#### END NAMESPACE " << ns.name() << " ###################" << endl << endl;
2840 
2841  ns.release_access(); // also releases access to schema
2842 
2843  // Postconditions:
2844 
2845  ensure(unexecutable(access request depth == old access request depth));
2846 
2847  // Exit
2848 
2849  return os;
2850 }
2851 
2852 size_t
2853 sheaf::
2854 deep_size(const namespace_poset& xp, bool xinclude_shallow, size_t xresults[4])
2855 {
2856  size_t result;
2857  size_t lmemory_parts[4];
2858 
2859  // Preconditions:
2860 
2861  // Body:
2862 
2863  // Class data members:
2864 
2865  result = xinclude_shallow ? sizeof(xp) : 0;
2866 
2867  if (xresults != 0)
2868  for (int i=0; i<4; i++)
2869  xresults[i] = 0;
2870 
2871  // @issue Do we need to add in the schemas or is the calculation below
2872  // taking care of it?
2873 
2874  // Add the constributes of the poset members.
2875 
2876  namespace_poset& lxp = const_cast<namespace_poset&>(xp);
2877  poset_state_handle* lpsh = reinterpret_cast<poset_state_handle*>(&lxp);
2878 
2879  // xresults gets initialized in the first call to deep_size
2880 
2881  result += deep_size(*lpsh, xinclude_shallow, xresults);
2882 
2883  subposet_member_iterator litr(lxp.whole());
2884 
2885  while(!litr.is_done())
2886  {
2887  if(litr.is_jim())
2888  {
2889  // Member_poset returns a handle of the proper specialized type,
2890  // as opposed to attaching a general poset_state_handle.
2891 
2892  lpsh = &lxp.member_poset(litr.index());
2893  if(lpsh->is_attached())
2894  {
2895  lpsh->get_read_access();
2896  result += deep_size(*lpsh, xinclude_shallow, lmemory_parts);
2897 
2898  // Increment the 4 memory parts
2899 
2900  if (xresults != 0)
2901  for (int i=0; i<4; i++)
2902  xresults[i] += lmemory_parts[i];
2903 
2904  lpsh->release_access();
2905  }
2906  }
2907  litr.next();
2908  }
2909 
2910  // Postconditions:
2911 
2912  ensure(result >= 0);
2913 
2914  // Exit
2915 
2916  return result;
2917 }
poset_table_state & table() const
The table of dof tuples of this poset.
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...
void to_stream(std::ostream &xos=std::cout)
Write instance information to an ostream (default = stdout).
virtual poset_path path(bool xauto_access=true) const
The path of this poset.
bool state_is_auto_read_write_accessible(bool xauto_access) const
True if state is auto accessible for read and write, that is, if the state is already accessible for ...
virtual bool is_jim(bool xin_current_version=true) const
True if this member is join irreducible in the current version of the host (xin_current_version == tr...
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
virtual const char * class_name() const
The name of this class.
const index_space_handle & get_member_poset_id_space(bool xauto_access) const
Allocates a handle for the id space for member posets from the pool of id space handles.
bool state_is_not_read_only_accessible() const
True if this is attached and the state is not accessible for read only access.
bool has_standard_member_ct() const
True if poset is in its initial state, that is, it contains just the standard members.
scoped_index insert_poset(const poset_state_handle &xposet, const std::string &xposet_name, bool xauto_link)
Inserts xposet into this namespace with member name xposet_name.
bool path_is_auto_read_write_available(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath does not exist or exists and is auto read-write accessible...
virtual void new_link(pod_index_type xgreater, pod_index_type xlesser)
Insert a cover link from greater to lesser (that is, hub id xgreater covers hub id xlesser)...
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
virtual int member_ct() const
The number of members of this poset.
abstract_poset_member & top()
The top member of the poset (mutable version)
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
void put_name(const std::string &xname)
Sets name() to xname. Intended for use only by storage_agent::begin_read_transaction(namespace_poset&...
An abstract iterator over the ids of an id space.
void release_id_space(index_space_handle &xid_space) const
Returns the id space handle xid_space to the handle pool.
virtual poset_path path(bool xauto_access=true) const
The path of this poset.
virtual poset_state * state_obj() const
State object for this poset.
namespace_poset_schema & namespace_schema()
The namespace poset schema within this namespace (mutable version)
const scoped_index & index() const
The member index of this poset within the namespace host()
virtual void get_read_access() const
Get read access to the state associated with this.
void put_row_dof_tuple(poset_dof_map *xdof_tuple)
Sets the dof tuple at index xindex to xdof_tuple.
pod_index_type member_poset_schema_id(const scoped_index &xindex, bool xauto_access) const
The index of the schema of the member poset with index xindex.
namespace_poset * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
bool contains_members(const scoped_index *xmbrs, int xmbrs_ct, bool xauto_access=true) const
True if this poset contains poset member(s) with indices in xmbrs.
bool path_is_auto_read_accessible(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath exists and is auto read accessible.
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
pod_index_type member_dof_tuple_id(pod_index_type xmbr_hub_id, bool xauto_access) const
The dof tuple hub id of the member with hub id xmbr_hub_id.
virtual schema_poset_member & schema()
The schema on which this is allocated (mutable version).
bool contains_poset_subposet(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset and subposet specified by xpath.
virtual void initialize_standard_members()
Creates the members common to every poset, for instance, top() and bottom().
void release_member_poset_id_space(index_space_handle &xid_space, bool xauto_access) const
Returns the handle for the id space for member posets to the pool of id space handles.
bool contains_poset_member(pod_index_type xposet_hub_id, pod_index_type xmember_hub_id, bool xauto_access=true) const
True if this contains a poset with hub id xposet_hub_id which contains a member with hub id xmember_h...
bool state_is_auto_read_accessible(bool xauto_access) const
True if the state is auto accessible for read, that is, if the state is already accessible for read o...
static const std::string & standard_name()
The standard name for an instance of this class.
A client handle for a general, abstract partially order set.
virtual bool includes_subposet(pod_index_type xsubposet_hub_id, bool xauto_access=true) const
True if this poset includes subposet with hub id xsubposet_hub_id.
index_space_handle & get_id_space(const std::string &xname) const
Allocates an id space handle from the handle pool attached to state with name xname.
primitives_poset & primitives()
The poset of primitives for this namespace (mutable version)
const scoped_index & index() const
The current item in the subset.
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
void initialize_table_dofs(void *xtable_dofs, size_t xtable_dof_ub)
Initializes the table dofs ("class variables")
const index_space_family & member_id_spaces(bool xauto_access) const
Collection of member id spaces for this (const version).
virtual void initialize_standard_subposets(const std::string &xname)
Creates the subposets common to every poset (e.g. whole() and jims()).
void put_standard_row_dof_tuple_ct(int xct)
Sets the number of standard row dof tuples automatically allocated by the constructor.
STL namespace.
abstract_poset_member * _top
Top member of poset.
void put(int i, bool value)
Sets i-th member to value.
Definition: zn_to_bool.cc:537
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...
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
poset_state_handle * poset_pointer() const
The pointer to the poset associated with this namespace member.
virtual void attach_handle_data_members()
Initializes the handle data members when this handle is attached to a state. Intended to be redefined...
index_space_iterator & get_member_poset_id_space_iterator(bool xauto_access) const
Allocates a iterator for the id space for member posets. from the pool of id space iterators...
poset_state_handle & member_poset(pod_index_type xhub_id, bool xauto_access=true) const
The poset_state_handle object referred to by hub id xhub_id.
void invalidate()
Make this id invalid.
Definition: scoped_index.h:852
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...
const scoped_index & index() const
The index of the component state this handle is attached to.
namespace_poset * _name_space
The namespace this poset resides in.
virtual void virtual_initialize_prototypes()
Initialize all the prototypes needed by various factory methods; virtual version. ...
std::string name() const
A name for this.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
virtual bool is_attached() const =0
True if this handle is attached to a state.
void clear_member_id_spaces(bool xauto_access)
Deletes all non-standard id spaces.
namespace_poset * host() const
The namespace this poset resides in. Obsolete; use name_space() instead.
virtual void put_member_name(pod_index_type xmbr_hub_id, const std::string &xname, bool xunique, bool xauto_access=false)
Make xname a name for the member with hub id xmbr_hub_id. if xunique, make xname the only name...
static namespace_poset * current_namespace()
The current default namespace.
virtual const scoped_index & new_row_dof_map()
Creates a new row dof map appropriate for jims of this.
index_space_iterator & get_id_space_iterator(const std::string &xname) const
Allocates an id space iterator from the iterator pool attached to state with name xname...
virtual void attach_handle_data_members()
Initializes the handle data members when this handle is attached to a state.
abstract_poset_member * _bottom
Bottom members of poset.
primitives_poset_schema & primitives_schema()
The schema poset for the primitives poset (mutable version)
virtual pod_index_type new_member(bool xis_jim, pod_index_type xtuple_hub_id)
Create a disconnected member with is_jim == xis_jim and the dof tuple identified by hub id xtuple_hub...
static void initialize_dof_map_prototypes()
Initialize the prototypes needed by dof map factory method,.
static void initialize_poset_prototypes()
Initialize the prototypes needed by poset factory method,.
void next()
Makes item the next member of the subset.
A client handle for a member of a namespace poset.
virtual void detach_from_state()
Detach this handle from its state.
void put_name(const std::string &xname)
Sets name() to xname.
Definition: poset_state.cc:175
void initialize_member_poset_id_space()
Creates the member poset id space.
static void initialize_prototypes()
Initialize all the prototypes needed by various factory methods,.
virtual void delete_state(bool xauto_access=false)
Detachs this from its state and then deletes the state.
bool poset_state_is_read_write_accessible(const poset_path &xpath, bool xauto_access=true) const
True if the poset referred to by xpath is read-write accessible.
std::string to_string()
Get instance information as a string.
void put_poset_class(const char *xclass)
Set the class of the poset associated with this namespace member to xclass.
Abstract base class with useful features for all objects.
Definition: any.h:39
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
Definition: zn_to_bool.h:52
std::string name() const
Name of this space.
void put_scope(const index_space_handle &xid_space)
Sets the scope to xid_space.
Definition: scoped_index.h:441
virtual void initialize_namespace(namespace_poset &xns, const std::string &xposet_name, bool xauto_link=true)
Installs this as a member of xns. If xauto_link, automatically links the member into an appropriate g...
virtual int standard_member_ct() const
The number of standard members automatically allocated by the constructor.
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
pod_index_type poset_prereq_id(int xi) const
The id of the xi-th prerequisite poset for the poset associated with this namespace member...
namespace_poset_member & top()
The top member of the poset (mutable version)
void new_state(const std::string &xname)
Creates a new namespace state with name xname and attaches this to it.
virtual namespace_poset_dof_map & row_dof_map(pod_index_type xtuple_hub_id, bool xrequire_write_access=false) const
The map from row dof client_ids to row dof values for dof tuple hub id xtuple_hub_id.
bool has_standard_subposet_ct() const
True if poset is in its initial state, that is, it contains just the standard subposets.
void update_standard_member_id_spaces()
Update the initially allocated id spaces.
bool is_external() const
True if this has a corresponding member in a name space, but is not yet attached to a state...
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
static void initialize_crg_interval_prototypes()
Initialize the prototypes needed by crg interval factory method,.
bool has_standard_row_dof_tuple_ct() const
True if poset is in its initial state, that is, it contains just the standard row_dof_tuples.
std::string name() const
Name of this space.
bool owns(const poset_state_handle &xposet, bool xauto_access) const
True if and only if this contains the poset xposet. synonym for contains_poset(xposet.poset_path(true), xauto_access)
void release_id_space_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
virtual void detach_from_state()
Detach this handle from its state, if any.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
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.
poset_state_handle * poset_pointer() const
The pointer to the poset associated with this namespace member.
virtual void get_read_access() const
Get read access to the state associated with this.
std::string poset_name() const
The poset name part of the path.
Definition: poset_path.cc:473
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
size_type row_dof_tuple_ct() const
The number of row_dof_tuples of this poset.
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...
poset_dof_map * row_dof_tuple(pod_index_type xindex)
The row dof tuple with index xindex.
virtual bool contains_member(pod_index_type xmbr_hub_id, bool xauto_access=true) const
True if some version of this poset contains poset member with hub id xmbr_hub_id. ...
void put_poset_type_id(poset_type xtype_id)
Set the type id of the poset associated with this namespace member to xtype_id.
virtual poset_type type_id() const
Identifier for the type of this poset.
virtual const subposet & whole() const
The "improper" subset containing all members of this poset.
void clear()
Removes all members except the standard members.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
virtual void put_name(const std::string &xname, bool xunique, bool xauto_access)
Make xname a name for this; if xunique, make xname the only name.
void put_standard_member_ct(int xct)
Sets the number of standard members automatically allocated by the constructor.
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
scoped_index _index
The member index of this poset in the namespace.
void attach_to_state(const poset_state_handle *xother)
Attach this handle to the same state as xother.
virtual std::string name() const
The name of this poset.
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
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 pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
void delete_poset(pod_index_type xhub_id, bool xauto_access)
Delete the poset with hub id xhub_id.
poset_state_handle()
Default constructor.
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
static void initialize_id_space_prototypes()
Initialize the prototypes needed by id space factory method,.
bool path_is_auto_read_available(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath does not exist or exists and is auto read accessible.
const hub_index_space_handle & member_hub_id_space(bool xauto_access) const
The member hub id space.
bool path_is_auto_read_write_accessible(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath exists and is auto read-write accessible.
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
prevent editing of jims and jim order relation
Iterates over the subset of Zn defined by the characteristic function host().
static poset_handle_factory & factory()
The poset handle factory.
bool poset_state_is_read_accessible(const poset_path &xpath, bool xauto_access=true) const
True if the poset referred to by xpath is read accessible.
virtual void detach_from_state()
Detach this handle from its state, if any.
virtual bool is_attached() const
True if this is attached to a state.
namespace_poset_member & bottom()
The bottom member of the poset (mutable version)
int access_request_depth() const
The number of times access has been requested and granted without being released. ...
poset_state * _state
State object for this poset.
bool invariant() const
Class invariant.
virtual bool is_attached() const =0
True if this iterator is attached to a state.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual std::string name() const
The name of this poset.
virtual ~namespace_poset()
Destructor.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
std::string member_name() const
The member name part of the path.
Definition: poset_path.cc:511
virtual scoped_index member_index_ub() const
The upper bound on the member_index;.
bool is_done() const
True if iteration finished.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
A handle for a scattered_insertion_index_space_state.
virtual void link_poset(const namespace_poset_member &xmbr)
Links xmbr into the appropriate group.
static array_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent, size_type xcapacity)
Create a new array id space in the id space family xid_spaces at the next available id space index wi...
virtual bool is_jim(pod_index_type xmbr_hub_id, bool xin_current_version=true) const
True if the member with hub id xmbr_hub_id is a jim in the current version (xin_current_version == tr...
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_...
virtual void detach_from_state()
Detaches this from its state.
static poset_path primitives_schema_path()
The path for the primitives schema.
static const std::string & standard_name()
The standard name for an instance of this class.
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
Prevent editing of jims and jim order relation.
bool contains_poset_members(const std::string &xposet_name, const std::string xmember_names[], int xmember_names_ct, bool xauto_access=true) const
True if this contains a poset with name xposet_name which contains all members with names in array xm...
virtual void initialize_additional_members()
Creates additional members for this namespace.
void attach_to_state(const namespace_poset *xns, const poset_path &xpath, bool xauto_access=true)
Attach to the state specified by path xpath in the namespace xns.
static bool is_valid_name(const std::string &xname)
True if xname is not empty and contains only name legal characters.
Definition: poset_path.cc:331
A map from schema poset member ids to dof values for namespace_poset members.
virtual void get_read_access() const
Get read access to the state associated with this.
virtual void initialize_namespace(namespace_poset &xns, bool xauto_link=true)
Installs this as a member of xns.
void put_current_namespace(namespace_poset *xns)
Sets the current default namespace to xns.
bool in_jim_edit_mode() const
True if editing jims and jim order relation is allowed.
static const std::string & standard_name()
The standard name for an instance of this class.
virtual void initialize_standard_members()
Creates the standard members for this namespace.
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
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
namespace_poset_schema _namespace_schema
The schema poset for this namespace.
void reset()
Restarts the iteration, makes item the first member of the subset.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
void release_member_poset_id_space_iterator(index_space_iterator &xid_space, bool xauto_access) const
Returns the iterator for the id space for member posets to the pool of id space iterators.
bool contains_row_dof_tuple(pod_index_type xtuple_hub_id) const
True if this contains a tuple with hub id xtuple_hub_id.
void put_poset_pointer(const poset_state_handle *xposet)
Set the pointer to the poset associated with this namespace member to xposet.
bool state_is_not_read_accessible() const
True if this is attached and if the state is accessible for read or if access control is disabled...
virtual bool invariant() const
Class invariant.
namespace_poset()
Default constructor; creates an unattached namespace handle.
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 bool row_dof_map_conforms(const poset_dof_map *xdof_map) const
True if xdof_map conforms to (is derived from) the type of row dof map required by this poset...
const scoped_index & index() const
The index of this in host() dof tuple table.
virtual index_iterator indexed_member_iterator() const
An iterator for members of this poset; index version.
Definition: subposet.cc:934
A client handle for an unrestricted member of a poset. A total_poset_member is guaranteed not to be r...
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
const int PREREQ_IDS_UB
Number of prerequisites ids. Must be consistent with PREREQ_ID_*_INDEX below.
virtual array_poset_dof_map & table_dof_map(bool xrequire_write_access=false)
The map from table dof client_ids to table dof values for this poset (mutable version) ...
virtual const scoped_index & member_id(bool xauto_access) const
An id in the member hub id space; intended for copying to initialize ids to the member id space...
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710