SheafSystem  0.0.0.0
sec_tuple.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/sec_tuple.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/binary_section_space_schema_member.impl.h"
25 #include "SheafSystem/binary_section_space_schema_poset.h"
26 #include "SheafSystem/fiber_bundles_namespace.h"
27 #include "SheafSystem/section_space_schema_member.impl.h"
28 #include "SheafSystem/section_space_schema_poset.h"
29 #include "SheafSystem/sec_tuple_space.impl.h"
30 #include "SheafSystem/tuple.h"
31 #include "SheafSystem/tuple_space.h"
32 
33 
34 
35 using namespace std;
36 using namespace fiber_bundle; // Workaround for MS C++ bug.
37 
38 //==============================================================================
39 // CLASS SEC_TUPLE
40 //==============================================================================
41 
42 // ===========================================================
43 // HOST FACTORY FACET
44 // ===========================================================
45 
46 // PUBLIC MEMBER FUNCTIONS
47 
48 const sheaf::poset_path&
51 {
52  // Preconditions:
53 
54 
55  // Body:
56 
57  static const poset_path result("sec_rep_descriptors", "vertex_element_dlinear");
58 
59  // Postconditions:
60 
61  ensure(result.full());
62 
63  // Exit:
64 
65  return result;
66 }
67 
70 new_host(namespace_type& xns, const poset_path& xhost_path, const poset_path& xschema_path, bool xauto_access)
71 {
72  // cout << endl << "Entering sec_tuple::new_host." << endl;
73 
74  // Preconditions:
75 
76  require(xns.state_is_auto_read_write_accessible(xauto_access));
77 
78  require(!xhost_path.empty());
79  require(!xns.contains_path(xhost_path, xauto_access));
80 
81  require(xschema_path.full());
82  require(xns.path_is_auto_read_accessible<schema_type::host_type>(xschema_path, xauto_access));
83  require(host_type::fiber_space_conforms<fiber_type::host_type>(xns, xschema_path, xauto_access));
84 
85 
86  // Body:
87 
88  host_type& result = host_type::new_table(xns, xhost_path, xschema_path, xauto_access);
89 
90  // Postconditions:
91 
92  ensure(xns.owns(result, xauto_access));
93  ensure(result.path(true) == xhost_path);
94  ensure(result.state_is_not_read_accessible());
95  ensure(result.schema(true).path(xauto_access) == xschema_path);
96 
97  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
98 
99  // Exit:
100 
101  // cout << "Leaving sec_tuple::new_host." << endl;
102  return result;
103 }
104 
105 // PROTECTED MEMBER FUNCTIONS
106 
107 // PRIVATE MEMBER FUNCTIONS
108 
109 
110 //==============================================================================
111 // TUPLE FACET OF CLASS SEC_TUPLE
112 //==============================================================================
113 
114 // PUBLIC MEMBER FUNCTIONS
115 
116 
119 {
120  // Preconditions:
121 
122  // Body:
123 
124  // Postconditions:
125 
126  ensure(invariant());
127 }
128 
130 sec_tuple(const sec_rep_space* xhost, pod_index_type xhub_id)
131 {
132  // Preconditions:
133 
134  require(xhost != 0);
135  require(xhost->state_is_read_accessible());
136  require(xhost->contains_member(xhub_id));
137 
138  // Body:
139 
140  attach_to_state(xhost, xhub_id);
141 
142  // Postconditions:
143 
144  ensure(invariant());
145  //ensure(host() == xhost);
146  ensure(index() == xhub_id);
147  ensure(is_attached());
148  ensure(!is_restricted());
149 }
150 
152 sec_tuple(const sec_rep_space* xhost, const scoped_index& xid)
153 {
154  // Preconditions:
155 
156  require(xhost != 0);
157  require(xhost->state_is_read_accessible());
158  require(xhost->contains_member(xid));
159 
160  // Body:
161 
162  attach_to_state(xhost, xid.hub_pod());
163 
164  // Postconditions:
165 
166  ensure(invariant());
167  //ensure(host() == xhost);
168  ensure(index() ==~ xid);
169  ensure(is_attached());
170  ensure(!is_restricted());
171 }
172 
174 sec_tuple(const sec_rep_space* xhost, const std::string& xname)
175 {
176  // Preconditions:
177 
178  require(xhost != 0);
179  require(xhost->state_is_read_accessible());
180  require(!xname.empty());
181  require(xhost->contains_member(xname));
182 
183  // Body:
184 
185  attach_to_state(xhost, xname);
186 
187  // Postconditions:
188 
189  ensure(invariant());
190  //ensure(host() == xhost);
191  ensure(name() == xname);
192  ensure(is_attached());
193  ensure(!is_restricted());
194 
195  // Exit:
196 
197 }
198 
199 
201 sec_tuple(const namespace_poset* xnamespace,
202  const poset_path& xpath,
203  bool xauto_access)
204 {
205  // Preconditions:
206 
207  require(precondition_of(attach_to_state(same args)));
208 
209  // Body:
210 
211  attach_to_state(xnamespace, xpath, xauto_access);
212 
213  // Postconditions:
214 
215  ensure(postcondition_of(attach_to_state(same args)));
216 
217  // Exit:
218 
219  return;
220 }
221 
224 {
225  // Preconditions:
226 
227  require(xother != 0);
228 
229  // Body:
230 
231  attach_to_state(xother);
232 
233  // Postconditions:
234 
235  ensure(invariant());
236  ensure(is_attached());
237  ensure(is_same_state(xother));
238  ensure(is_same_restriction(xother));
239 
240 }
241 
243 sec_tuple(sec_rep_space* xhost, section_dof_map* xdof_map, bool xauto_access)
244 {
245  // Preconditions:
246 
247  require(precondition_of(new_jim_state(xhost, xdof_map, false, xauto_access)));
248 
249  // Body:
250 
251  new_jim_state(xhost, xdof_map, false, xauto_access);
252 
253  // Postconditions:
254 
255  ensure(postcondition_of(new_jim_state(xhost, xdof_map, false, xauto_access)));
256 
257  // Exit:
258 
259  return;
260 }
261 
264  abstract_poset_member& xbase_mbr,
265  int xbase_version, bool xauto_access)
266 {
267  // Preconditions:
268 
269  require(precondition_of(\
270  new_jim_state(xhost, xbase_mbr, xbase_version, xauto_access)));
271 
272  // Body:
273 
274  new_jim_state(xhost, xbase_mbr, xbase_version, xauto_access);
275 
276  // Postconditions:
277 
278  ensure(postcondition_of(\
279  new_jim_state(xhost, xbase_mbr, xbase_version, xauto_access)));
280 
281  // Exit:
282 
283  return;
284 }
285 
289 {
290  // Preconditions:
291 
292  require(is_ancestor_of(&xother));
293  require(precondition_of(attach_to_state(&xother)));
294 
295  // Body:
296 
297  attach_to_state(&xother);
298 
299  // Postconditions:
300 
301  ensure(postcondition_of(attach_to_state(&xother)));
302 
303  // Exit:
304 
305  return *this;
306 }
307 
310 operator=(const sec_tuple& xother)
311 {
312  // Preconditions:
313 
314  require(precondition_of(attach_to_state(&xother)));
315 
316  // Body:
317 
318  attach_to_state(&xother);
319 
320  // Postconditions:
321 
322  ensure(postcondition_of(attach_to_state(&xother)));
323 
324  // Exit:
325 
326  return *this;
327 }
328 
331 {
332  // Preconditions:
333 
334  // Body:
335 
336  // Postconditions:
337 
338 }
339 
340 int
342 factor_ct() const
343 {
344  // Preconditions:
345 
346  require(state_is_read_accessible());
347 
348  // Body:
349 
350  int result = host()->factor_ct();
351 
352  // Postconditions:
353 
354  // Exit:
355 
356  return result;
357 }
358 
359 int
361 factor_ct(bool xauto_access) const
362 {
363  // Preconditions:
364 
365  require(state_is_auto_read_accessible(xauto_access));
366 
367  // Body:
368 
369  int result = host()->factor_ct();
370 
371  // Postconditions:
372 
373  // Exit:
374 
375  return result;
376 }
377 
378 // PROTECTED MEMBER FUNCTIONS
379 
380 // PRIVATE MEMBER FUNCTIONS
381 
382 
383 //==============================================================================
384 // ABSTRACT POSET MEMBER FACET OF CLASS SEC_TUPLE
385 //==============================================================================
386 
387 // PUBLIC MEMBER FUNCTIONS
388 
389 const std::string&
391 class_name() const
392 {
393  // Preconditions:
394 
395  // Body:
396 
397  const string& result = static_class_name();
398 
399  // Postconditions:
400 
401  ensure(!result.empty());
402 
403  // Exit:
404 
405  return result;
406 }
407 
408 const std::string&
411 {
412  // Preconditions:
413 
414  // Body:
415 
416  static const string result("sec_tuple");
417 
418  // Postconditions:
419 
420  ensure(!result.empty());
421 
422  // Exit:
423 
424  return result;
425 }
426 
429 clone() const
430 {
431  // Preconditions:
432 
433  // Body:
434 
435  // Create new handle of the current class.
436 
437  sec_tuple *result = new sec_tuple();
438 
439  // Postconditions:
440 
441  ensure(result != 0);
442  ensure(result->invariant());
443 
444  // Exit:
445 
446  return result;
447 
448 }
449 
450 // PROTECTED MEMBER FUNCTIONS
451 
452 // PRIVATE MEMBER FUNCTIONS
453 
454 
455 // ===========================================================
456 // POSET_COMPONENT FACET
457 // ===========================================================
458 
459 // PUBLIC MEMBER FUNCTIONS
460 
463 host() const
464 {
465  return reinterpret_cast<host_type*>(_host);
466 }
467 
468 bool
471 {
472  return dynamic_cast<const host_type*>(xother) != 0;
473 }
474 
475 // PROTECTED MEMBER FUNCTIONS
476 
477 // PRIVATE MEMBER FUNCTIONS
478 
479 
480 //==============================================================================
481 // ANY FACET OF CLASS SEC_TUPLE
482 //==============================================================================
483 
484 // PUBLIC MEMBER FUNCTIONS
485 
486 bool
488 fiber_is_ancestor_of(const any* xother) const
489 {
490  // Preconditions:
491 
492  require(xother != 0);
493 
494  // Body:
495 
496  // If xother may be dynamically cast to the type of this fiber then this
497  // fiber is an ancestor of xother.
498 
499  bool result = dynamic_cast<const tuple*>(xother) != 0;
500 
501  // Postconditions:
502 
503  ensure(invariant());
504  ensure(xother->invariant());
505 
506  // Exit:
507 
508  return result;
509 
510 }
511 
512 bool
514 is_ancestor_of(const any* xother) const
515 {
516  // Preconditions:
517 
518  require(xother != 0);
519 
520  // Body:
521 
522  // If other may be dynamically cast to the type of this then this is an
523  // ancestor of other.
524 
525  bool result = dynamic_cast<const sec_tuple*>(xother) != 0;
526 
527  // Postconditions:
528 
529  //ensure(invariant());
530 
531  // Exit:
532 
533  return result;
534 
535 }
536 
537 bool
539 invariant() const
540 {
541  bool result = true;
542 
543  // Preconditions:
544 
545  // Body:
546 
547  // Must satisfy base class invariant.
548 
549  invariance(sec_rep_space_member::invariant());
550 
551  if (invariant_check())
552  {
553  // Prevent recursive calls to invariant.
554 
555  disable_invariant_check();
556 
557 
558  // Finished, turn invariant checking back on.
559 
560  enable_invariant_check();
561  }
562 
563  // Postconditions:
564 
565  ensure(is_derived_query);
566 
567  // Exit:
568 
569  return result;
570 }
571 
572 // PROTECTED MEMBER FUNCTIONS
573 
574 // PRIVATE MEMBER FUNCTIONS
575 
576 
577 //==============================================================================
578 
579 void
582 {
583  // Preconditions:
584 
585  require(state_is_read_accessible());
586  // required by intialize_handle_data_members
587 
588  // Body:
589 
590  sec_rep_space_member::attach_handle_data_members();
591 
592  // Postconditions:
593 
594  ensure(!is_restricted());
595 
596  // Exit:
597 
598  return;
599 }
600 
601 void
604 {
605  // Preconditions:
606 
607  // Body:
608 
609  sec_rep_space_member::detach_from_state();
610 
611  // Postconditions:
612 
613  ensure(!is_attached());
614  ensure(invariant());
615 
616  // Exit:
617 }
618 
621 comp(int i) const
622 {
623  // Preconditions:
624 
625  require(0 <= i && i < df());
626 
627  // Body:
628 
629  // Retrieve the requested component from storage.
630 
631  scalar_type* result = 0;
632 
633  not_implemented();
634 
635  // Postconditions:
636 
637  ensure(invariant());
638  ensure(result != 0);
639 
640  // Exit:
641 
642  return result;
643 }
644 
645 void
647 set_comp(int i, scalar_type* component)
648 {
649  // Preconditions:
650 
651  require(0 <= i && i < df());
652  require(component != 0);
653 
654  // Body:
655 
656  // Set the ith component in storage to component.
657 
658  not_implemented();
659 
660  // Postconditions:
661 
662  ensure(comp(i) == component);
663  ensure(invariant());
664 
665 }
666 
667 void
670 {
671  // Preconditions:
672 
673  require(state_is_read_accessible());
674  require(xschema != 0);
675  require(schema().is_ancestor_of(xschema));
676  require(xschema != 0);
677  require(xschema->le(&(host()->schema())));
678 
679  // Body:
680 
681  // Restrict this...
682 
683  sec_rep_space_member::restrict_to(xschema);
684 
685  // Postconditions:
686 
687  ensure(schema().is_same_state(xschema));
688  ensure(unexecutable("base().is_same_state(old base())"));
689  ensure(invariant());
690 
691  // Exit:
692 }
693 
694 void
696 restrict_to(pod_index_type xbase_id, pod_index_type xfiber_schema_id)
697 {
698  // Preconditions:
699 
700  require(state_is_read_accessible());
701 
707 
708  // Body:
709 
710  // Restrict this...
711 
712  sec_rep_space_member::restrict_to(xbase_id, xfiber_schema_id);
713 
714  // Postconditions:
715 
716  // ensure(base().is_same_state(xbase));
717  // ensure(fiber_schema().is_same_state(xfiber_schema));
718  // ensure(invariant());
719 
720  // Exit:
721 }
722 
723 void
725 restrict_to(const abstract_poset_member* xbase, const abstract_poset_member* xfiber_schema)
726 {
727  // Preconditions:
728 
729  require(state_is_read_accessible());
730  require(xbase != 0);
731  require(xbase->le(&(host()->base())));
732  require(xfiber_schema != 0);
733  require(xfiber_schema->le(&(host()->fiber_schema())));
734 
735  // Body:
736 
737  // Restrict this...
738 
739  sec_rep_space_member::restrict_to(xbase, xfiber_schema);
740 
741  // Postconditions:
742 
743  ensure(base().is_same_state(xbase));
744  ensure(fiber_schema().is_same_state(xfiber_schema));
745  ensure(invariant());
746 
747  // Exit:
748 }
749 
750 void
753 {
754  // Preconditions:
755 
756  require(state_is_read_accessible());
757  require(xother != 0);
758  require(xother->state_is_read_accessible());
759  require(is_ancestor_of(xother));
760  require(has_same_host(xother));
761 
762  // Body:
763 
764  // Restrict this...
765 
766  sec_rep_space_member::restrict_to_same(xother);
767 
768  // Postconditions:
769 
770  ensure(is_same_restriction(xother));
771  ensure(invariant());
772 
773  // Exit:
774 }
775 
776 void
779 {
780  // Preconditions:
781 
782  require(state_is_read_accessible());
783 
784  // Body:
785 
786  // Restrict this...
787 
788  sec_rep_space_member::unrestrict();
789 
790  // Postconditions:
791 
792  ensure(!is_restricted());
793  ensure(invariant());
794 
795  // Exit:
796 }
797 
798 
799 //==============================================================================
800 // NON-MEMBER FUNCTIONS
801 //==============================================================================
802 
803 size_t
804 fiber_bundle::
805 deep_size(const sec_tuple& x0, bool xinclude_shallow)
806 {
807  size_t result;
808 
809  // Preconditions:
810 
811  // Body:
812 
815 
816  result = 0;
817 
818  // Postconditions:
819 
820  ensure(result == 0);
821  //ensure(result >= 0);
822 
823  // Exit
824 
825  return result;
826 }
827 
828 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
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 sec_tuple * clone() const
Make a new handle, no state instance of current.
Definition: sec_tuple.cc:429
void unrestrict()
Removes any restriction to this handle and its components; restores base and fiber to the base and fi...
Definition: sec_tuple.cc:778
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
virtual sec_tuple & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: sec_tuple.cc:288
A Cartesian product section space.
~sec_tuple()
Destructor.
Definition: sec_tuple.cc:330
The abstract map from section dof ids to section dof values of heterogeneous type.
poset_path path(bool xauto_access=true) const
A path to this component.
virtual const std::string & class_name() const
The name of this class.
Definition: sec_tuple.cc:391
A section of a bundle with fiber type tuple.
Definition: sec_tuple.h:53
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 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.
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
A client handle for a general, abstract partially order set.
host_type * host() const
The poset this is a member of.
Definition: sec_tuple.cc:463
static host_type & new_host(namespace_type &xns, const poset_path &xhost_path, const poset_path &xschema_path, bool xauto_access)
Creates a new host table for members of this type. The poset is created in namespace xns with path xh...
Definition: sec_tuple.cc:70
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
A member of a sec_rep_space; a section.
STL namespace.
A schema poset for a section space. A binary Cartesian product subspace of the binary tensor product ...
virtual bool host_is_ancestor_of(const poset_state_handle *other) const
True if other conforms to host.
Definition: sec_tuple.cc:470
A Cartesian product space.
Definition: tuple_space.h:52
Abstract base class with useful features for all objects.
Definition: any.h:39
scalar_type * comp(int i) const
The ith component of section.
Definition: sec_tuple.cc:621
virtual section_space_schema_member & schema()
The schema for this poset (mutable version)
bool fiber_is_ancestor_of(const any *xother) const
Definition: sec_tuple.cc:488
static const std::string & static_class_name()
The name of this class.
Definition: sec_tuple.cc:410
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)
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
bool invariant() const
Class invariant.
Definition: sec_tuple.cc:539
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
void set_comp(int i, scalar_type *component)
Sets ith comp of section.
Definition: sec_tuple.cc:647
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. ...
bool le(pod_index_type xother_index) const
True if this is less than or equal to the member with index xother_index.
virtual void restrict_to_same(const abstract_poset_member *xother)
Restricts this handle and its components to the same restriction as xother.
Definition: sec_tuple.cc:752
A member of a Cartesian product space; a tuple of attributes (persistent version).
Definition: tuple.h:191
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
static const poset_path & standard_rep_path()
The path to the standard rep for sections of this type.
Definition: sec_tuple.cc:50
void detach_from_state()
Detaches field from state it is currently attached to.
Definition: sec_tuple.cc:603
int factor_ct() const
The number of factors in this product.
bool is_ancestor_of(const any *xother) const
True if xother conforms to current.
Definition: sec_tuple.cc:514
virtual int factor_ct() const
Number of factors (components) in tuple.
Definition: sec_tuple.cc:342
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
poset & fiber_space()
The fiber space for section spaces on this schema (mutable version).
An abstract client handle for a member of a poset.
sec_tuple()
Default constructor.
Definition: sec_tuple.cc:118
Namespace for the fiber_bundles component of the sheaf system.
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 void restrict_to(const abstract_poset_member *xschema)
Restricts this section and its components to schema member xschema.
Definition: sec_tuple.cc:669
void attach_handle_data_members()
Initializes data members introduced by this handle.
Definition: sec_tuple.cc:581
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
A handle for a poset whose members are numerical representations of sections of a fiber bundle...
Definition: sec_rep_space.h:61