SheafSystem  0.0.0.0
poset_dof_map.cc
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 
18 // Implementation for class poset_dof_map
19 
20 #include "SheafSystem/poset_dof_map.h"
21 
22 #include "SheafSystem/arg_list.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/dof_descriptor_array.h"
25 #include "SheafSystem/dof_map_factory.h"
26 #include "SheafSystem/poset_dof_iterator.h"
27 #include "SheafSystem/poset_state_handle.h"
28 #include "SheafSystem/primitive_value.h"
29 
30 using namespace std;
31 
32 //#define DIAGNOSTIC_OUTPUT
33 
34 // PUBLIC MEMBER FUNCTIONS
35 
36 const std::string&
38 class_name() const
39 {
40  // Preconditions:
41 
42  // Body:
43 
44  const string& result = static_class_name();
45 
46  // Postconditions:
47 
48  ensure(!result.empty());
49 
50  // Exit:
51 
52  return result;
53 }
54 
55 const std::string&
58 {
59  // Preconditions:
60 
61  // Body:
62 
63  static const string result("poset_dof_map");
64 
65  // Postconditions:
66 
67  ensure(!result.empty());
68  ensure(result == "poset_dof_map");
69 
70  // Exit:
71 
72  return result;
73 }
74 
77 new_dof_map(const std::string& xclass_name, dof_tuple_type xsheaf_base_class_id)
78 {
79  poset_dof_map* result;
80 
81  // Preconditions:
82 
83  // Body:
84 
85  result = factory().new_dof_map(xclass_name, xsheaf_base_class_id);
86 
87  // Postconditions:
88 
89  ensure(result != 0);
90  ensure(!result->is_initialized());
91 
92  // Exit:
93 
94  return result;
95 }
96 
97 
98 
99 
100 // CANONICAL MEMBERS
101 
104 clone() const
105 {
106  poset_dof_map* result = 0; // To silence compiler warnings.
107 
108  // Preconditions:
109 
110 
111  // Body:
112 
113  is_abstract();
114 
115  // Postconditions:
116 
117  ensure(result != 0);
118  ensure(result->is_same_type(this));
119  ensure(postcondition_of(poset_dof_map()));
120 
121  // Exit:
122 
123  return result;
124 }
125 
128 copy() const
129 {
130  poset_dof_map* result = 0; // Just to silece compiler warnings.
131 
132  // Preconditions:
133 
134 
135  // Body:
136 
137  is_abstract();
138 
139  // Postconditions:
140 
141  ensure(result != 0);
142  ensure(result->is_same_type(this));
143  ensure(postcondition_of(poset_dof_map(*this)));
144 
145  // Exit:
146 
147  return result;
148 }
149 
152 operator=(const poset_dof_map& xother)
153 {
154 
155  // Preconditions:
156 
157  require(xother.is_initialized());
158 
159  // Need ref_ct == 0 to ensure no poset members
160  // have a pointer to the schema, which may be deleted.
161 
162  require(ref_ct() == 0);
163 
164  // Body:
165 
166  _host = xother._host;
167  _index = xother._index;
168 
169  if(_schema != 0)
170  {
171  _schema->detach_from_state();
172  delete _schema;
173  }
174  _schema = xother._schema->clone();
175  _schema->attach_to_state(xother._schema);
176 
177  _is_table_dof_map = xother._is_table_dof_map;
178  _dof_ct = xother._dof_ct;
179  _dof_tuple_ub = xother._dof_tuple_ub;
180  _ref_ct = 0;
181 
182 
183  // Postconditions:
184 
185  ensure(host() == xother.host());
186  ensure(index() == xother.index());
187  ensure(schema().is_same_state(&xother.schema()));
188  ensure(is_table_dof_map() == xother.is_table_dof_map());
189  ensure(dof_ct() == xother.dof_ct());
190  ensure(dof_tuple_ub() == xother.dof_tuple_ub());
191  ensure(ref_ct() == 0);
192 
193  // Exit
194 
195  return *this;
196 }
197 
198 
201 {
202 
203  // Preconditions:
204 
205  require(ref_ct() == 0);
206 
207  // Body:
208 
209  if(_schema != 0)
210  {
211  _schema->detach_from_state();
212  delete _schema;
213  }
214 
215  // Postconditions:
216 
217  // Exit
218 
219  return;
220 }
221 
222 
223 bool
225 invariant() const
226 {
227  bool result = true;
228 
229  // Preconditions:
230 
231  // Body:
232 
233  if(invariant_check())
234  {
235  // Prevent recursive calls to invariant
236 
237  disable_invariant_check();
238 
239  // Invariants for this class:
240 
242 
244 
245  invariance(unexecutable("is_initialized() ? version() == schema().version(true) : true"));
246 
247 
248  // Finished, turn invariant checking back on.
249 
250  enable_invariant_check();
251  }
252 
253  // Postconditions:
254 
255  // Exit
256 
257  return result;
258 }
259 
260 
261 // MAP INTERFACE
262 
263 void
266  pod_index_type xschema_mbr_id,
267  int xschema_version)
268 {
269 
270  // Preconditions:
271 
272  require(!is_initialized());
273  require(xhost != 0);
274  require(xhost->state_is_read_accessible());
275 
276  // Note that we do not require the schema to <= the host schema.
277  // Although usually the case, is not actually a requirement for
278  // this routine and there is at least one application where it is violated.
279  // See dof_tuple_record_set::read_records, the external dof map
280  // may be allocated on a schema greater than the host, if the host
281  // has been restricted.
282 
283  require(xhost->schema().host()->contains_member(xschema_mbr_id));
284  require(xhost->schema().host()->has_version(xschema_version));
285 
286  // Body:
287 
288  _host = const_cast<poset_state_handle*>(xhost);
289 
290  _index.invalidate();
291  _index.put_scope(_host->dof_tuple_hub_id_space(false));
292 
293  _schema = xhost->schema().clone();
294  _schema->attach_to_state(xhost->schema().host(), xschema_mbr_id);
295 
296  // Force the version to be unaliased.
297 
298  _schema->put_version(xschema_version, true);
299 
300  _is_table_dof_map = false;
301  _dof_ct = _schema->row_dof_ct();
302  _dof_tuple_ub = _schema->row_dof_tuple_ub();
303 
304  _ref_ct = 0;
305 
306  allocate_dofs();
307 
308  // Postconditions:
309 
310  ensure(is_initialized());
311  ensure(host() == xhost);
312  ensure(!index().is_valid());
313  ensure(index().same_scope(host()->dof_tuple_hub_id_space(false)));
314  ensure(is_table_dof_map() == false);
315  ensure(dof_ct() == schema().row_dof_ct());
316  ensure(dof_tuple_ub() == schema().row_dof_tuple_ub());
317  ensure(version() == schema().version(true));
318  ensure(ref_ct() == 0);
319  ensure(schema().index() == xschema_mbr_id);
320  ensure(version() == schema().unaliased_version(xschema_version));
321 
322  // Exit
323 
324  return;
325 }
326 
327 void
330  const scoped_index& xschema_mbr_id,
331  int xschema_version)
332 {
333 
334  // Preconditions:
335 
336  require(!is_initialized());
337  require(xhost != 0);
338  require(xhost->state_is_read_accessible());
339 
340  // Note that we do not require the schema to <= the host schema.
341  // Although usually the case, is not actually a requirement for
342  // this routine and there is at least one application where it is violated.
343  // See dof_tuple_record_set::read_records, the external dof map
344  // may be allocated on a schema greater than the host, if the host
345  // has been restricted.
346 
347  require(xhost->schema().host()->contains_member(xschema_mbr_id));
348  require(xhost->schema().host()->has_version(xschema_version));
349 
350  // Body:
351 
352  init_row_dof_map(xhost, xschema_mbr_id.hub_pod(), xschema_version);
353 
354  // Postconditions:
355 
356  ensure(is_initialized());
357  ensure(host() == xhost);
358 
359  ensure(!index().is_valid());
360 
361  ensure(is_table_dof_map() == false);
362  ensure(dof_ct() == schema().row_dof_ct());
363  ensure(dof_tuple_ub() == schema().row_dof_tuple_ub());
364  ensure(version() == schema().version(true));
365  ensure(ref_ct() == 0);
366  ensure(schema().index() ==~ xschema_mbr_id);
367  ensure(version() == schema().unaliased_version(xschema_version));
368 
369  // Exit
370 
371  return;
372 }
373 
374 bool
377 {
378  bool result;
379 
380  // Preconditions:
381 
382  // Body:
383 
384  result = (_schema != 0);
385 
386  // Postconditions:
387 
388  // Exit
389 
390  return result;
391 }
392 
393 
394 
395 
398 host() const
399 {
400  poset_state_handle* result;
401 
402  // Preconditions:
403 
404  // Body:
405 
406  result = _host;
407 
408  // Postconditions:
409 
410  // Exit
411 
412  return result;
413 }
414 
415 const sheaf::scoped_index&
417 index() const
418 {
419  // Preconditions:
420 
421  // Body:
422 
423  // Postconditions:
424 
425  // Exit
426 
427  return _index;
428 }
429 
433 {
434  // Preconditions:
435 
436  require(is_initialized());
437 
438  // Body:
439 
440  schema_poset_member& result = *_schema;
441 
442  // Postconditions:
443 
444  // Exit
445 
446  return result;
447 }
448 
451 schema() const
452 {
453  // Preconditions:
454 
455  require(is_initialized());
456 
457  // Body:
458 
459  schema_poset_member& result = *_schema;
460 
461  // Postconditions:
462 
463  // Exit
464 
465  return result;
466 }
467 
468 bool
471 {
472  bool result;
473 
474  // Preconditions:
475 
476 
477  // Body:
478 
479  result = _is_table_dof_map;
480 
481  // Postconditions:
482 
483 
484  // Exit:
485 
486  return result;
487 }
488 
489 
490 
491 int
493 dof_ct() const
494 {
495  int result;
496 
497  // Preconditions:
498 
499  // Body:
500 
501  result = _dof_ct;
502 
503  // Postconditions:
504 
505  ensure(result >= 0);
506 
507  // Exit:
508 
509  return result;
510 }
511 
512 
513 
514 // ===========================================================
515 // NEW DOF ACCESS FACET
516 // ===========================================================
517 
520 dof(pod_index_type xdof_id) const
521 {
522  // Preconditions:
523 
524  require(schema().state_is_read_accessible());
525  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
526 
527  // Body:
528 
529  primitive_value result;
530 
531  get_dof(xdof_id, &(result.value()), sizeof(primitive_buffer_type));
532 
533  result.id() = schema().type(xdof_id, _is_table_dof_map);
534 
535  // Postconditions:
536 
537 
538  // Exit:
539 
540  return result;
541 }
542 
545 dof(const scoped_index& xdof_id) const
546 {
547  // Preconditions:
548 
549  require(schema().state_is_read_accessible());
550  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
551 
552  // Body:
553 
554  pod_index_type lindex =
555  schema().dof_id_space(_is_table_dof_map).pod(xdof_id);
556  primitive_value result = dof(lindex);
557 
558  // Postconditions:
559 
560  // Exit:
561 
562  return result;
563 }
564 
567 dof(const std::string& xname) const
568 {
569  // Preconditions:
570 
571  require(schema().state_is_read_accessible());
572  require(!xname.empty());
573  require(schema().contains_dof(xname, is_table_dof_map()));
574 
575  // Body:
576 
577  pod_index_type lhub_id = schema().host()->member_id(xname, false);
578  pod_index_type lindex = schema().dof_id_space(_is_table_dof_map).pod(lhub_id);
579  primitive_value result = dof(lindex);
580 
581  // Postconditions:
582 
583  // Exit:
584 
585  return result;
586 }
587 
588 void
591 {
592  // Preconditions:
593 
594  require(schema().state_is_read_accessible());
595  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
596  require(xdof.id() == schema().type(xdof_id, is_table_dof_map()));
597 
598  // Body:
599 
600  put_dof(xdof_id, &(xdof.value()), sizeof(primitive_buffer_type));
601 
602  // Postconditions:
603 
604  ensure(dof(xdof_id) == xdof);
605 
606  // Exit:
607 
608  return;
609 }
610 
611 void
613 put_dof(const scoped_index& xdof_id, const primitive_value& xdof)
614 {
615  // Preconditions:
616 
617  require(schema().state_is_read_accessible());
618  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
619  //require(xdof.id() == schema().type(schema().dof_id_space(is_table_dof_map()).pod(xdof_id), is_table_dof_map()));
620  require(xdof.id() == schema().type(xdof_id, is_table_dof_map(), false));
621 
622  // Body:
623 
624  pod_index_type lindex = schema().dof_id_space(_is_table_dof_map).pod(xdof_id);
625  put_dof(lindex, xdof);
626 
627  // Postconditions:
628 
629  ensure(dof(xdof_id) == xdof);
630 
631  // Exit:
632 
633  return;
634 }
635 
636 void
638 put_dof(const std::string& xname, const primitive_value& xdof)
639 {
640  // Preconditions:
641 
642  require(schema().state_is_read_accessible());
643  require(schema().contains_dof(xname, is_table_dof_map()));
644  require(xdof.id() == schema().type(xname, is_table_dof_map(), false));
645 
646  // Body:
647 
648  pod_index_type lhub_id = schema().host()->member_id(xname, false);
649  pod_index_type lindex = schema().dof_id_space(_is_table_dof_map).pod(lhub_id);
650  put_dof(lindex, xdof);
651 
652  // Postconditions:
653 
654  ensure(dof(xname) == xdof);
655 
656  // Exit:
657 
658  return;
659 }
660 
661 void
663 get_dof(pod_index_type xdof_id, void* xdof, size_type xdof_size) const
664 {
665  // Preconditions:
666 
667  require(schema().state_is_read_accessible());
668  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
669  require(unexecutable("xdof points to buffer of size xdof_size"));
670  require(xdof_size >= schema().size(xdof_id, is_table_dof_map()));
671 
672  // Body:
673 
674  is_abstract();
675 
676  // Postconditions:
677 
678 
679  // Exit:
680 
681  return;
682 }
683 
684 void
686 get_dof(const scoped_index& xdof_id, void* xdof, size_type xdof_size) const
687 {
688  // Preconditions:
689 
690  require(schema().state_is_read_accessible());
691  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
692  require(unexecutable("xdof points to buffer of size xdof_size"));
693  require(xdof_size >= schema().size(xdof_id, is_table_dof_map(), false));
694 
695  // Body:
696 
697  pod_index_type lindex =
698  schema().dof_id_space(_is_table_dof_map).pod(xdof_id);
699  get_dof(lindex, xdof, xdof_size);
700 
701  // Postconditions:
702 
703 
704  // Exit:
705 
706  return;
707 }
708 
709 void
711 put_dof(pod_index_type xdof_id, const void* xdof, size_type xdof_size)
712 {
713  // Preconditions:
714 
715  require(schema().state_is_read_accessible());
716  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
717  require(unexecutable("xdof points to buffer of size xdof_size"));
718  require(xdof_size >= schema().size(xdof_id, is_table_dof_map()));
719 
720  // Body:
721 
722  is_abstract();
723 
724  // Postconditions:
725 
726 
727  // Exit:
728 
729  return;
730 }
731 
732 void
734 put_dof(const scoped_index& xdof_id, const void* xdof, size_type xdof_size)
735 {
736  // Preconditions:
737 
738  require(schema().state_is_read_accessible());
739  require(schema().dof_id_space(is_table_dof_map()).contains(xdof_id));
740  require(unexecutable("xdof points to buffer of size xdof_size"));
741  require(xdof_size >= schema().size(xdof_id, is_table_dof_map(), false));
742 
743  // Body:
744 
745  pod_index_type lindex =
746  schema().dof_id_space(_is_table_dof_map).pod(xdof_id);
747 
748  put_dof(lindex, xdof, xdof_size);
749 
750  // Postconditions:
751 
752  // Exit:
753 
754  return;
755 }
756 
757 // ===========================================================
758 // END NEW DOF ACCESS FACET
759 // ===========================================================
760 
761 size_t
764 {
765  size_t result;
766 
767  // Preconditions:
768 
769 
770  // Body:
771 
772  result = _dof_tuple_ub;
773 
774  // Postconditions:
775 
776 
777  // Exit:
778 
779  return result;
780 }
781 
782 
783 
784 void
786 get_dof_tuple(arg_list& xargs) const
787 {
788  // Preconditions:
789 
790  require(schema().state_is_read_accessible());
791 
792  // Body:
793 
794  poset_dof_iterator* litr = schema().dof_iterator(is_table_dof_map());
795  while(!litr->is_done())
796  {
797  schema_poset_member& litem = litr->item();
798 
799  arg_list::arg_type larg;
800  larg.name = litem.name();
801  larg.put_type(litem.type());
802  primitive_value& lvalue = larg.value;
803  larg.value = dof(litem.index());
804 
805  xargs.push_back(larg);
806 
807  litr->next();
808  }
809  delete litr;
810 
811 #ifdef DIAGNOSTIC_OUTPUT
812  cout << "poset_dof_map::get_dof_tuple: " << endl;
813  cout << "\thost name: " << host()->name() << endl;
814  cout << "\tschema name: " << schema().name() << endl << endl;
815  cout << xargs << endl;
816 #endif
817 
818  // Postconditions:
819 
820  ensure(invariant());
821  ensure(xargs.ct() == dof_ct());
822  ensure(xargs.conforms_to(schema(), is_table_dof_map(), false));
823 
826 
827  // Exit
828 
829  return;
830 }
831 
832 void
834 put_dof_tuple(const arg_list& xargs)
835 {
836  // Preconditions:
837 
838  require(dof_ct() == xargs.ct());
839  require(schema().state_is_read_accessible());
840  require(xargs.conforms_to(schema(), is_table_dof_map(), false));
841 
842  // Body:
843 
844 #ifdef DIAGNOSTIC_OUTPUT
845  cout << "poset_dof_map::put_dof_tuple: schema:: " << schema().name()
846  << " table_dof_descriptors: " << *(schema().table_dof_descriptors()) << endl;
847 #endif
848 
849  poset_dof_iterator* litr = schema().dof_iterator(is_table_dof_map());
850  while(!litr->is_done())
851  {
852  schema_poset_member& litem = litr->item();
853 
854  int i = xargs.index(litem.name());
855 
856  // Precondition ensures i is valid.
857 
858  assertion(i != -1);
859 
860  put_dof(litem.index(), xargs.value(i));
861  litr->next();
862  }
863  delete litr;
864 
865 #ifdef DIAGNOSTIC_OUTPUT
866  cout << *this << endl;
867 #endif
868 
869  // Postconditions:
870 
871  ensure(invariant());
872 
875  ensure(unexecutable("xargs copied to dof tuple"));
876 
877  // Exit
878 
879  return ;
880 }
881 
882 
883 void
886 {
887  // cout << endl << "Entering poset_dof_map::copy_dof_tuple." << endl;
888 
889  // Preconditions:
890 
891  require(dof_ct() == xother.dof_ct());
892  require(schema().state_is_read_accessible());
893  require(xother.schema().state_is_read_accessible());
894  // require(schema().conforms_to(xother.schema(), is_table_dof_map()));
895  // require(xother.schema().conforms_to(schema(), is_table_dof_map()));
896 
897  // Body:
898 
899  arg_list largs;
900  xother.get_dof_tuple(largs);
901  put_dof_tuple(largs);
902 
903  // Postconditions:
904 
905 
906  // Exit:
907 
908  // cout << "Leaving poset_dof_map::copy_dof_tuple." << endl;
909  return;
910 }
911 
912 
913 void
916 {
917  // Preconditions:
918 
919  require(schema().state_is_read_accessible());
920 
921  // Body:
922 
923  poset_dof_iterator* ldof_itr = schema().dof_iterator(is_table_dof_map());
924 
925  while(!ldof_itr->is_done())
926  {
927  schema_poset_member& lmember = ldof_itr->item();
928 
929  put_dof(lmember.index(), primitive_value(lmember.type()));
930 
931  ldof_itr->next();
932  }
933 
934  delete ldof_itr;
935 
936  // Postconditions:
937 
938  ensure(invariant());
939  ensure(unexecutable(xargs copied to dof tuple));
940 
941  // Exit
942 
943  return ;
944 }
945 
946 
947 
948 unsigned int
950 ref_ct() const
951 {
952  unsigned int result;
953 
954  // Preconditions:
955 
956 
957  // Body:
958 
959  result = _ref_ct;
960 
961  // Postconditions:
962 
963 
964  // Exit:
965 
966  return result;
967 }
968 
969 void
972 {
973  // Preconditions:
974 
975 
976  // Body:
977 
978  define_old_variable(unsigned int old_ref_ct = _ref_ct);
979 
980  _ref_ct++;
981 
982  // Postconditions:
983 
984  ensure(ref_ct() == old_ref_ct + 1);
985 
986  // Exit:
987 
988  return;
989 }
990 
991 void
994 {
995  // Preconditions:
996 
997 
998  // Body:
999 
1000  define_old_variable(unsigned int old_ref_ct = _ref_ct);
1001 
1002  _ref_ct--;
1003 
1004  // Postconditions:
1005 
1006  ensure(ref_ct() == old_ref_ct - 1);
1007 
1008  // Exit:
1009 
1010  return;
1011 }
1012 
1013 
1014 
1015 int
1017 version() const
1018 {
1019  int result;
1020 
1021  // Preconditions:
1022 
1023  require(is_initialized());
1024 
1025  // Body:
1026 
1027  result = _schema->version();
1028 
1029  // Postconditions:
1030 
1031  // $$TCP ensure(result == schema().version());
1032 
1033  // Exit
1034 
1035  return result;
1036 }
1037 
1041 {
1042  // Preconditions:
1043 
1044  require(is_initialized());
1045 
1046  // Body:
1047 
1048  const index_space_handle& result =
1049  _schema->dof_id_space(_is_table_dof_map);
1050 
1051  // Postconditions:
1052 
1053  ensure(result.is_attached());
1054 
1055  // Exit
1056 
1057  return result;
1058 }
1059 
1060 bool
1063 {
1065 
1066  return false;
1067 }
1068 
1069 
1070 // PROTECTED MEMBER FUNCTIONS
1071 
1075 {
1076 
1077  // Preconditions:
1078 
1079 
1080  // Body:
1081 
1082  static dof_map_factory result;
1083 
1084  // Postconditions:
1085 
1086 
1087  // Exit:
1088 
1089  return result;
1090 }
1091 
1092 
1093 
1094 // CANONICAL MEMBERS
1095 
1096 
1099 {
1100 
1101  // Preconditions:
1102 
1103 
1104  // Body:
1105 
1106  _host = 0;
1107 
1108  _index.invalidate();
1109 
1110  _schema = 0;
1111  _is_table_dof_map = false;
1112  _dof_ct = 0;
1113  _dof_tuple_ub = 0;
1114  _ref_ct = 0;
1115 
1116  // Postconditions:
1117 
1118  ensure(!is_initialized());
1119  ensure(host() == 0);
1120 
1121  ensure(!index().is_valid());
1122 
1123  ensure(is_table_dof_map() == false);
1124  ensure(dof_ct() == 0);
1125  ensure(dof_tuple_ub() == 0);
1126  ensure(ref_ct() == 0);
1127 
1128  // Exit
1129 
1130  return;
1131 }
1132 
1133 
1136 {
1137 
1138  // Preconditions:
1139 
1140  require(xother.is_initialized());
1141 
1142  // Body:
1143 
1144  _host = const_cast<poset_dof_map&>(xother).host();
1145  _index = const_cast<poset_dof_map&>(xother).index();
1146 
1147  _schema = xother._schema->clone();
1148  _schema->attach_to_state(xother._schema);
1149 
1150  _is_table_dof_map = xother._is_table_dof_map;
1151  _dof_ct = const_cast<poset_dof_map&>(xother).dof_ct();
1152  _dof_tuple_ub = const_cast<poset_dof_map&>(xother).dof_tuple_ub();
1153  _ref_ct = 0;
1154 
1155  // Postconditions:
1156 
1157  ensure(is_initialized());
1158  ensure(host() == xother.host());
1159  ensure(index() == xother.index());
1160  ensure(schema().is_same_state(&xother.schema()));
1161  ensure(is_table_dof_map() == xother.is_table_dof_map());
1162  ensure(dof_ct() == xother.dof_ct());
1163  ensure(dof_tuple_ub() == xother.dof_tuple_ub());
1164  ensure(ref_ct() == 0);
1165 
1166  // Exit
1167 
1168  return;
1169 }
1170 
1171 // OTHER CONSTRUCTORS
1172 
1174 poset_dof_map(const poset_state_handle* xhost, bool xis_table_dof_map)
1175 {
1176 
1177  // Preconditions:
1178 
1179  require(xhost != 0);
1180  require(xhost->state_is_read_accessible());
1181 
1182  // Body:
1183 
1184  _host = const_cast<poset_state_handle*>(xhost);
1185 
1186  _index.invalidate();
1187  _index.put_scope(_host->dof_tuple_hub_id_space(false));
1188 
1189  _schema = xhost->schema().clone();
1190  _schema->attach_to_state(&xhost->schema());
1191 
1192  // Force the version to be unaliased.
1193 
1194  _schema->put_version(_schema->version(), true);
1195 
1196  _is_table_dof_map = xis_table_dof_map;
1197 
1198  _dof_ct = _schema->dof_ct(_is_table_dof_map);
1199  _dof_tuple_ub = _schema->dof_tuple_ub(_is_table_dof_map);
1200 
1201  _ref_ct = 0;
1202 
1203  // Postconditions:
1204 
1205  ensure(is_initialized());
1206  ensure(host() == xhost);
1207 
1208  ensure(!index().is_valid());
1209  ensure(index().same_scope(host()->dof_tuple_hub_id_space(false)));
1210  ensure(schema().is_same_state(&xhost->schema()));
1211  ensure(is_table_dof_map() == xis_table_dof_map);
1212  ensure(dof_ct() == schema().dof_ct(is_table_dof_map()));
1213  ensure(dof_tuple_ub() == schema().dof_tuple_ub(is_table_dof_map()));
1214  ensure(version() == schema().version(true));
1215 
1216  // Exit
1217 
1218  return;
1219 }
1220 
1222 poset_dof_map(const schema_poset_member* xschema, bool xis_table_dof_map)
1223 {
1224 
1225  // Preconditions:
1226 
1227  require(xschema != 0);
1228  require(xschema->state_is_read_accessible());
1229 
1230  // Body:
1231 
1232  _host = 0;
1233 
1234  _index.invalidate();
1235  _index.put_scope(xschema->host()->dof_tuple_hub_id_space(false));
1236 
1237  _schema = xschema->clone();
1238  _schema->attach_to_state(xschema);
1239 
1240  // Force the version to be unaliased.
1241 
1242  _schema->put_version(_schema->version(), true);
1243 
1244  _is_table_dof_map = xis_table_dof_map;
1245 
1246  _dof_ct = _schema->dof_ct(_is_table_dof_map);
1247  _dof_tuple_ub = _schema->dof_tuple_ub(_is_table_dof_map);
1248 
1249  _ref_ct = 0;
1250 
1251  // Postconditions:
1252 
1253  ensure(is_initialized());
1254  ensure(host() == 0);
1255  ensure(!index().is_valid());
1256  ensure(index().same_scope(schema().host()->dof_tuple_hub_id_space(false)));
1257  ensure(schema().is_same_state(xschema));
1258  ensure(is_table_dof_map() == xis_table_dof_map);
1259  ensure(dof_ct() == schema().dof_ct(is_table_dof_map()));
1260  ensure(dof_tuple_ub() == schema().dof_tuple_ub(is_table_dof_map()));
1261  ensure(version() == schema().version(true));
1262 
1263  // Exit
1264 
1265  return;
1266 }
1267 
1268 void
1271 {
1272  // Preconditions:
1273 
1274  require(is_initialized());
1275  require(xhost->state_is_read_accessible());
1276  require(xhost->schema().is_same_state(&(schema())));
1277 
1278  // Body:
1279 
1280  _host = const_cast<poset_state_handle*>(xhost);
1281 
1282  // Postconditions:
1283 
1284  ensure(host() == xhost);
1285 
1286  // Exit
1287 
1288  return;
1289 }
1290 
1291 void
1293 put_index(const scoped_index& xindex)
1294 {
1295  // Preconditions:
1296 
1297  require(xindex.is_positive() || !xindex.is_valid());
1298 
1299  // Body:
1300 
1301  _index = xindex;
1302 
1303  // Postconditions:
1304 
1305  ensure(index() == xindex);
1306 
1307  // Exit
1308 
1309  return;
1310 }
1311 
1312 void
1314 put_dof_ct(int xdof_ct)
1315 {
1316  // Preconditions:
1317 
1318 
1319  // Body:
1320 
1321  _dof_ct = xdof_ct;
1322 
1323  // Postconditions:
1324 
1325  ensure(dof_ct() == xdof_ct);
1326 
1327  // Exit:
1328 
1329  return;
1330 }
1331 
1332 void
1334 put_dof_tuple_ub(size_t xub)
1335 {
1336  // Preconditions:
1337 
1338 
1339  // Body:
1340 
1341  _dof_tuple_ub = xub;
1342 
1343  // Postconditions:
1344 
1345  ensure(dof_tuple_ub() == xub);
1346 
1347  // Exit:
1348 
1349  return;
1350 }
1351 
1352 void
1354 put_ref_ct(int xref_ct)
1355 {
1356  // Preconditions:
1357 
1358  require(xref_ct >= 0);
1359 
1360  // Body:
1361 
1362  _ref_ct = xref_ct;
1363 
1364  // Postconditions:
1365 
1366  ensure(ref_ct() == xref_ct);
1367 
1368  // Exit:
1369 
1370  return;
1371 }
1372 
1373 std::string
1375 to_string(const schema_poset_member& xschema) const
1376 {
1377  // Preconditions:
1378 
1379  // Body:
1380 
1381  string result;
1382  if(schema().contains_dof(xschema, _is_table_dof_map))
1383  {
1384  result = xschema.name() + "=" + dof(xschema.index()).to_string();
1385  }
1386 
1387  // Postconditions:
1388 
1389  // Exit:
1390 
1391  return result;
1392 }
1393 
1394 std::string
1396 to_string() const
1397 {
1398  // Preconditions:
1399 
1400  // Body:
1401 
1402  string result;
1403 
1404  poset_dof_iterator* ldof_itr = schema().dof_iterator(is_table_dof_map());
1405 
1406  if(!ldof_itr->is_done())
1407  {
1408  // Output first dof without leading white space.
1409 
1410  schema_poset_member& lschema = ldof_itr->item();
1411 
1412  result += to_string(lschema);
1413 
1414  ldof_itr->next();
1415 
1416  while(!ldof_itr->is_done())
1417  {
1418  // Output additional dofs preceded by white space.
1419 
1420  schema_poset_member& lschema = ldof_itr->item();
1421 
1422  result += "\t";
1423  result += to_string(lschema);
1424 
1425  ldof_itr->next();
1426  }
1427  }
1428  delete ldof_itr;
1429 
1430  // Postconditions:
1431 
1432  // Exit:
1433 
1434  return result;
1435 }
1436 
1437 // ===========================================================
1438 // NONMEMBER FUNCTIONS
1439 // ===========================================================
1440 SHEAF_DLL_SPEC
1441 std::ostream& sheaf::
1442 operator<<(std::ostream& os, const poset_dof_map& xmap )
1443 {
1444  // Preconditions:
1445 
1446  // Body:
1447 
1448  poset_dof_map& lmap = const_cast<poset_dof_map&>(xmap);
1449 
1450  os << lmap.to_string();
1451 
1452  // Postconditions:
1453 
1454  // Exit:
1455 
1456  return os;
1457 }
1458 
1459 SHEAF_DLL_SPEC
1460 size_t
1461 sheaf::
1462 deep_size(const poset_dof_map& xp, bool xinclude_shallow)
1463 {
1464  size_t result;
1465 
1466  // Preconditions:
1467 
1468  // Body:
1469 
1470  result = xinclude_shallow ? sizeof(xp) : 0;
1471 
1472  if(xp.is_initialized())
1473  {
1474  poset_dof_map& lxp = const_cast<poset_dof_map&>(xp);
1475 
1476  // _schema is cloned, so calculate the contribution.
1477 
1478  result += deep_size(*xp._schema, true);
1479 
1480  // Add the size of all of the dofs.
1481 
1482  result += lxp.dof_tuple_ub();
1483  }
1484 
1485  // Postconditions:
1486 
1487  ensure(result >= 0);
1488 
1489  // Exit
1490 
1491  return result;
1492 }
1493 
virtual const index_space_handle & client_id_space() const
The map from library ids to clients ids for the schema this is defined on.
primitive_value value
The value of the argument.
Definition: arg_list.h:107
poset_state_handle * host() const
The poset which this is a handle to a component of.
bool is_table_dof_map() const
True if this is a table dof map.
bool is_valid() const
True if this is a valid id.
Definition: scoped_index.h:832
virtual void next()
Makes this the next member of the subset.
virtual bool supports_xfr_opt() const
True if this dof map type supports dof tuple transfer optimization. /.
virtual void put_host(const poset_state_handle *xhost)
Sets host() to xhost.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
schema_poset_member & item()
The current member of the iteration (mutable version).
virtual schema_poset_member & schema()
The schema on which this is allocated (mutable version).
primitive_value dof(pod_index_type xdof_id) const
The dof referred to by xdof_id.
int version() const
The version of the host of the schema this is defined on.
A client handle for a general, abstract partially order set.
virtual void get_dof(pod_index_type xdof_id, void *xdof, size_type xdof_size) const
Copies the dof referred to by xdof_id into xdof.
static poset_dof_map * new_dof_map(const std::string &xclass_name, dof_tuple_type xsheaf_base_class_id)
Creates an uninitialized dof map of type xclass_name, if a prototype of that name exists...
bool _is_table_dof_map
True if this is a table dof map.
bool is_initialized() const
True if this has been initialized, that is, if the schema has been set and the dof map storage alloca...
STL namespace.
bool is_same_state(const poset_state_handle *xhost, pod_index_type xhub_id) const
True is this is attached to state with hub id xhub_id in host xhost.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
void put_index(const scoped_index &xindex)
Sets the index of the member for which this provides the dofs.
virtual ~poset_dof_map()
Destructor.
virtual bool is_done() const
True if iteration finished.
poset_dof_map & operator=(const poset_dof_map &xother)
Assignment operator.
virtual void get_dof_tuple(void *xbuf, size_t xbuflen) const =0
Copies the entire dof tuple from internal storage into xbuf.
const scoped_index & index() const
The index of the component state this handle is attached to.
void put_dof_tuple_ub(size_t xub)
Sets dof_tuple_ub() to xub.
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.
The internal argument type.
Definition: arg_list.h:76
virtual primitive_type type() const
The primitive type index of the dof defined by this.
void copy_dof_tuple(const poset_dof_map &xother)
Copies the dof tuple of xother into this.
bool has_version(int xversion) const
True if xversion is a valid version.
const hub_index_space_handle & dof_tuple_hub_id_space(bool xauto_access) const
The dof tuple hub id space.
size_t _dof_tuple_ub
The size of the dof tuple.
virtual void put_defaults()
Sets all dofs to defualt values.
schema_poset_member * clone(bool xnew_state, bool xauto_access=true) const
Make a new handle instance of current. Attach the new instance to a new state if xnew_state is true...
std::string name
The name of the argument.
Definition: arg_list.h:81
void put_ref_ct(int xref_ct)
Sets ref_ct() to xref_ct).
A whitespace separated list of arguments. Insertion operaters are used to insert arguments into the l...
Definition: arg_list.h:63
static dof_map_factory & factory()
The dof map factory.
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
Definition: eval_family.h:49
virtual bool invariant() const
The class invariant.
primitive_value & value(int xi)
The value of the xi-th argument.
Definition: arg_list.cc:267
Type of buffer large enough to hold any primitive type.
size_t dof_tuple_ub() const
The size of the dof tuple in bytes.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
virtual poset_dof_map * copy() const =0
Virtual copy constructor.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
void inc_ref_ct()
Increase the number of references to this map by one;.
void put_dof_ct(int xdof_ct)
Sets dof_ct() to xdof_ct.
virtual void init_row_dof_map(const poset_state_handle *xhost, pod_index_type xschema_mbr_id, int xschema_version)
Initializes this as a map for row dofs in host xhost, with schema member specified by xschema_mbr_id ...
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. ...
std::string name(pod_index_type xdof_id, bool xis_table_dof) const
The name of the table dof (xis_table_dof true) or row dof referred to by xdof_id in the schema define...
unsigned int ct() const
The number of arguments.
Definition: arg_list.cc:139
scoped_index _index
The poset member for which this stores the dofs.
dof_tuple_type
Identifiers for dof tuple types.
int _dof_ct
The number of dofs in this map.
static const std::string & static_class_name()
The name of this class.
int dof_ct() const
The number of dofs in this map.
primitive_buffer_type & value()
The value of this.
void dec_ref_ct()
Decrease the number of references to this map by one.
bool conforms_to(const namespace_poset &xns, const poset_path &xschema_path, bool xuse_table_schema, bool xauto_access) const
True if the values in this conform to the table schema (xuse_table_schema true) or row schema (xuse_t...
Definition: arg_list.cc:529
virtual poset_state_handle * host() const
The poset which owns this.
primitive_type & id()
Type id of the primitive type.
int index(const std::string &xname) const
The index of the argument with name xname.
Definition: arg_list.cc:168
Iterates in postorder over dofs of a schema member anchor. Attaches a handle of type schema_poset_mem...
schema_poset_member * _schema
The schema on which this is instantiated.
void put_dof(pod_index_type xdof_id, const primitive_value &xdof)
Sets the dof referred to by xdof_id to xdof.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
void put_type(primitive_type xid)
Sets the type of the argument to xid.
Definition: arg_list.h:94
virtual void put_dof_tuple(const void *xbuf, size_t xbuflen)=0
Copies the entire dof tuple from xbuf into internal storage.
std::string to_string(const schema_poset_member &xschema) const
Return schema member dof value as a string.
void tuple(pod_index_type x, size_type xj_ub, pod_index_type &xi, pod_index_type &xj)
Ordinal to 2-tuple conversion.
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.
Abstract object wrapper for an instance of a primitive type.
poset_state_handle * _host
The host of the poset member for which this stores the dofs.
poset_dof_map()
Default constructor;.
void push_back(const arg_type &xarg)
Definition: arg_list.cc:1176
A factory for creating dof maps.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
virtual const std::string & class_name() const
The name of the actual (possibly derived) class of this instance.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
bool is_positive() const
True if this is greater than or equal to ZERO.
virtual poset_dof_map * clone() const =0
Virtual default constructor.
unsigned int ref_ct() const
The number of references to this map.
A client handle for a poset member which has been prepared for use as a schema.
const scoped_index & index() const
The index of this in host() dof tuple table.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
std::string to_string() const
Return dof values as a formated string.