SheafSystem  0.0.0.0
at1.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/at1.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/at0.h"
26 #include "SheafSystem/at1_space.h"
27 #include "SheafSystem/fiber_bundles_namespace.h"
28 #include "SheafSystem/schema_poset_member.h"
29 #include "SheafSystem/wsv_block.h"
30 
31 using namespace std;
32 using namespace fiber_bundle; // Workaround for MS C++ bug.
33 
34 //==============================================================================
35 // CLASS AT1_LITE
36 //==============================================================================
37 
38 //==============================================================================
39 // AT1 FACET OF CLASS AT1_LITE
40 //==============================================================================
41 
42 // PUBLIC MEMBER FUNCTIONS
43 
46 {
47 
48  // Preconditions:
49 
50  // Body:
51 
52  // Postconditions:
53 
54  ensure(invariant());
55 
56  // Exit:
57 }
58 
60 at1_lite(const at1_lite& xother)
61 {
62  // Preconditions:
63 
64  // Body:
65 
66  *this = xother;
67 
68  // Postconditions:
69 
70  ensure(invariant());
71 
72  // Exit:
73 }
74 
77 operator=(const at1_lite& xother)
78 {
79 
80  // Preconditions:
81 
82 
83  // Body:
84 
85 
86  // Postconditions:
87 
88  ensure(invariant());
89 
90  // Exit:
91 
92  return *this;
93 }
94 
97 {
98  // Preconditions:
99 
100  // Body:
101 
102  // Postconditions:
103 
104  // Exit:
105 
106 }
107 
109 at1_lite(const row_dofs_type& xrow_dofs)
110 {
111  // Preconditions:
112 
113  // Body:
114 
115  *this = xrow_dofs;
116 
117  // Postconditions:
118 
119  ensure(invariant());
120 
121  // Exit:
122 }
123 
126 operator=(const row_dofs_type& xrow_dofs)
127 {
128  // Preconditions:
129 
130  // Body:
131 
132  vd_lite::operator=(xrow_dofs);
133 
134  // Postconditions:
135 
136  postcondition_of(vd_lite::operator=(xrow_dofs));
137 
138  // Exit:
139 
140  return *this;
141 
142 }
143 
144 // PROTECTED MEMBER FUNCTIONS
145 
146 // PRIVATE MEMBER FUNCTIONS
147 
148 //==============================================================================
149 // EXTERIOR ALGEBRA (ATP) FACET OF CLASS AT1_LITE
150 //==============================================================================
151 
152 // PUBLIC MEMBER FUNCTIONS
153 
154 int
156 p() const
157 {
158  // Preconditions:
159 
160  // Body:
161 
162  int result = 1;
163 
164  // Postconditions:
165 
166  ensure(invariant());
167  ensure(result == 1);
168 
169  // Exit:
170 
171  return result;
172 }
173 
174 // PROTECTED MEMBER FUNCTIONS
175 
176 // PRIVATE MEMBER FUNCTIONS
177 
178 
179 //==============================================================================
180 // TENSOR ALGEBRA (TP) FACET OF CLASS AT1_LITE
181 //==============================================================================
182 
183 // PUBLIC MEMBER FUNCTIONS
184 
185 // PROTECTED MEMBER FUNCTIONS
186 
187 // PRIVATE MEMBER FUNCTIONS
188 
189 
190 //==============================================================================
191 // VECTOR ALGEBRA (VD) FACET OF CLASS AT1_LITE
192 //==============================================================================
193 
194 // PUBLIC MEMBER FUNCTIONS
195 
196 // PROTECTED MEMBER FUNCTIONS
197 
198 // PRIVATE MEMBER FUNCTIONS
199 
200 
201 //==============================================================================
202 // CARTESIAN ALGEBRA (TUPLE) FACET OF CLASS AT1_LITE
203 //==============================================================================
204 
205 // PUBLIC MEMBER FUNCTIONS
206 
207 // PROTECTED MEMBER FUNCTIONS
208 
209 // PRIVATE MEMBER FUNCTIONS
210 
211 
212 //==============================================================================
213 // ABSTRACT POSET MEMBER FACET OF CLASS AT1_LITE
214 //==============================================================================
215 
216 // PUBLIC MEMBER FUNCTIONS
217 
218 const std::string&
220 class_name() const
221 {
222  // Preconditions:
223 
224  // Body:
225 
226  const string& result = static_class_name();
227 
228  // Postconditions:
229 
230  ensure(!result.empty());
231 
232  // Exit:
233 
234  return result;
235 }
236 
237 const std::string&
240 {
241  // Preconditions:
242 
243  // Body:
244 
245  static const string result("at1_lite");
246 
247  // Postconditions:
248 
249  ensure(!result.empty());
250 
251  // Exit:
252 
253  return result;
254 }
255 
258 clone() const
259 {
260  at1_lite* result = 0;
261 
262  // Preconditions:
263 
264  // Body:
265 
266  result = new at1_lite();
267 
268  // Postconditions:
269 
270  ensure(result != 0);
271  ensure(is_same_type(*result));
272 
273  // Exit:
274 
275  return result;
276 }
277 
278 // PROTECTED MEMBER FUNCTIONS
279 
280 // PRIVATE MEMBER FUNCTIONS
281 
282 
283 //==============================================================================
284 // ANY FACET OF CLASS AT1_LITE
285 //==============================================================================
286 
287 // PUBLIC MEMBER FUNCTIONS
288 
289 bool
291 is_ancestor_of(const any_lite& xother) const
292 {
293  // Preconditions:
294 
295  require(&xother != 0);
296 
297  // Body:
298 
299  // True if other conforms to this.
300 
301  bool result = dynamic_cast<const at1_lite*>(&xother) != 0;
302 
303  // Postconditions:
304 
305  return result;
306 }
307 
308 bool
310 invariant() const
311 {
312  bool result = true;
313 
314  if(invariant_check())
315  {
316  // Prevent recursive calls to invariant.
317 
318  disable_invariant_check();
319 
320  // Must satisfy base class invariant.
321 
322  invariance(atp_lite::invariant());
323 
324  // Invariances for this class:
325 
326  // Finished, turn invariant checking back on.
327 
328  enable_invariant_check();
329  }
330 
331  // Exit
332 
333  return result;
334 }
335 
336 // PROTECTED MEMBER FUNCTIONS
337 
338 // PRIVATE MEMBER FUNCTIONS
339 
340 
341 //==============================================================================
342 // CLASS AT1
343 //==============================================================================
344 
345 // ===========================================================
346 // HOST FACTORY FACET OF CLASS AT1
347 // ===========================================================
348 
349 // PUBLIC MEMBER FUNCTIONS
350 
351 const sheaf::poset_path&
354 {
355  // Preconditions:
356 
357 
358  // Body:
359 
360  static const poset_path result(standard_schema_poset_name(), "at1_schema");
361 
362  // Postconditions:
363 
364  // Exit:
365 
366  return result;
367 }
368 
369 void
372 {
373  // Preconditions:
374 
375  require(xns.state_is_read_write_accessible());
376  require(xns.contains_poset(standard_schema_poset_name()));
377  require(!xns.contains_poset_member(standard_schema_path()));
378 
379 
380  // Body:
381 
382  schema_poset_member lschema(xns,
383  standard_schema_path().member_name(),
384  atp::standard_schema_path(),
385  "",
386  false);
387 
388  lschema.detach_from_state();
389 
390  // Postconditions:
391 
392  ensure(xns.contains_poset_member(standard_schema_path()));
393 
394  // Exit:
395 
396  return;
397 }
398 
402  const poset_path& xhost_path,
403  const poset_path& xschema_path,
404  const poset_path& xscalar_space_path,
405  bool xauto_access)
406 {
407  // cout << endl << "Entering at1::new_host." << endl;
408 
409  // Preconditions:
410 
411  require(xns.state_is_auto_read_write_accessible(xauto_access));
412 
413  require(!xhost_path.empty());
414  require(!xns.contains_path(xhost_path, xauto_access));
415 
416  require(xschema_path.full());
417  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
418  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path()));
419 
420  require(xns.path_is_auto_read_accessible(xscalar_space_path, xauto_access));
421  require(xns.contains_poset<scalar_type::host_type>(xscalar_space_path, xauto_access));
422 
423  // Body:
424 
425  host_type& result =
426  host_type::new_table(xns, xhost_path, xschema_path, xscalar_space_path, xauto_access);
427 
428  // Postconditions:
429 
430  ensure(xns.owns(result, xauto_access));
431  ensure(result.path(true) == xhost_path);
432  ensure(result.state_is_not_read_accessible());
433  ensure(result.schema(true).path(xauto_access) == xschema_path);
434 
435  ensure(result.factor_ct(true) == result.d(true));
436  ensure(result.d(true) == schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access));
437  ensure(result.scalar_space_path(true) == xscalar_space_path );
438  ensure(result.p(true) == 1);
439  ensure(result.dd(true) == result.d(true));
440  ensure(result.vector_space_path(true) == xhost_path);
441 
442  // Exit:
443 
444  // cout << "Leaving at1::new_host." << endl;
445  return result;
446 }
447 
448 // PROTECTED MEMBER FUNCTIONS
449 
450 // PRIVATE MEMBER FUNCTIONS
451 
452 
453 //==============================================================================
454 // AT1 FACET OF CLASS AT1
455 //==============================================================================
456 
457 // PUBLIC MEMBER FUNCTIONS
458 
461 {
462 
463  // Preconditions:
464 
465  // Body:
466 
467  // Postconditions:
468 
469  ensure(invariant());
470 }
471 
473 at1(const poset_state_handle* xhost, pod_index_type xhub_id)
474 {
475  // Preconditions:
476 
477  require(xhost != 0);
478  require(xhost->state_is_read_accessible());
479  require(xhost->contains_member(xhub_id));
480 
481  // Body:
482 
483  attach_to_state(xhost, xhub_id);
484 
485  // Postconditions:
486 
487  ensure(invariant());
488  // ensure(host() == xhost);
489  ensure(index() == xhub_id);
490  ensure(is_attached());
491 }
492 
494 at1(const poset_state_handle* xhost, const scoped_index& xid)
495 {
496  // Preconditions:
497 
498  require(xhost != 0);
499  require(xhost->state_is_read_accessible());
500  require(xhost->contains_member(xid));
501 
502  // Body:
503 
504  attach_to_state(xhost, xid.hub_pod());
505 
506  // Postconditions:
507 
508  ensure(invariant());
509  // ensure(host() == xhost);
510  ensure(index() ==~ xid);
511  ensure(is_attached());
512 }
513 
515 at1(const poset_state_handle* xhost, const std::string& xname)
516 {
517 
518  // Preconditions:
519 
520  require(xhost != 0);
521  require(xhost->state_is_read_accessible());
522  require(!xname.empty());
523  require(xhost->contains_member(xname));
524 
525  // Body:
526 
527  attach_to_state(xhost, xname);
528 
529  // Postconditions:
530 
531  ensure(invariant());
532  // ensure(host() == xhost);
533  ensure(name() == xname);
534  ensure(is_attached());
535 
536 }
537 
540 {
541 
542  // Preconditions:
543 
544  require(xother != 0);
545 
546  // Body:
547 
548  attach_to_state(xother);
549 
550  // Postconditions:
551 
552  ensure(invariant());
553  ensure(is_attached());
554  ensure(is_same_state(xother));
555 }
556 
558 at1(poset_state_handle* xhost, bool xauto_access)
559 {
560 
561  // Preconditions:
562 
563  require(precondition_of(new_jim_state(xhost, 0, false, xauto_access)));
564 
565  // Body:
566 
567  new_jim_state(xhost, 0, false, xauto_access);
568 
569  // Postconditions:
570 
571  ensure(postcondition_of(new_jim_state(xhost, 0, false, xauto_access)));
572 
573  // Exit:
574 
575  return;
576 }
577 
582 {
583  // Preconditions:
584 
585  require(is_ancestor_of(&xother));
586  require(precondition_of(attach_to_state(&xother)));
587 
588  // Body:
589 
590  attach_to_state(&xother);
591 
592  // Postconditions:
593 
594  ensure(postcondition_of(attach_to_state(&xother)));
595 
596  // Exit:
597 
598  return *this;
599 }
600 
604 operator=(const at1& xother)
605 {
606  // Preconditions:
607 
608  require(precondition_of(attach_to_state(&xother)));
609 
610  // Body:
611 
612  attach_to_state(&xother);
613 
614  // Postconditions:
615 
616  ensure(postcondition_of(attach_to_state(&xother)));
617 
618  // Exit:
619 
620  return *this;
621 }
622 
625 {
626 
627  // Preconditions:
628 
629  // Body:
630 
631  // Postconditions:
632 
633 }
634 
638 {
639  // Preconditions:
640 
641  // Body:
642 
643  static const volatile_type result;
644 
645  // Postconditions:
646 
647  // Exit:
648 
649  return result;
650 }
651 
655 lite_type() const
656 {
657  // Preconditions:
658 
659  // Body:
660 
661  volatile_type* result = new volatile_type(sheaf::row_dofs(*this));
662 
663  // Postconditions:
664 
665  // Exit:
666 
667  return result;
668 }
669 
670 
671 //==============================================================================
672 // EXTERIOR ALGEBRA (ATP) FACET OF CLASS AT1
673 //==============================================================================
674 
675 // PUBLIC MEMBER FUNCTIONS
676 
677 // PROTECTED MEMBER FUNCTIONS
678 
679 // PRIVATE MEMBER FUNCTIONS
680 
681 
682 //==============================================================================
683 // TENSOR ALGEBRA (TP) FACET OF CLASS AT1
684 //==============================================================================
685 
686 // PUBLIC MEMBER FUNCTIONS
687 
688 // PROTECTED MEMBER FUNCTIONS
689 
690 // PRIVATE MEMBER FUNCTIONS
691 
692 
693 //==============================================================================
694 // VECTOR ALGEBRA (VD) FACET OF CLASS AT1
695 //==============================================================================
696 
697 // PUBLIC MEMBER FUNCTIONS
698 
699 // PROTECTED MEMBER FUNCTIONS
700 
701 // PRIVATE MEMBER FUNCTIONS
702 
703 
704 //==============================================================================
705 // ABSTRACT POSET MEMBER FACET OF CLASS AT1
706 //==============================================================================
707 
708 // PUBLIC MEMBER FUNCTIONS
709 
710 const std::string&
712 class_name() const
713 {
714  // Preconditions:
715 
716  // Body:
717 
718  const string& result = static_class_name();
719 
720  // Postconditions:
721 
722  ensure(!result.empty());
723 
724  // Exit:
725 
726  return result;
727 }
728 
729 const std::string&
732 {
733  // Preconditions:
734 
735  // Body:
736 
737  static const string result("at1");
738 
739  // Postconditions:
740 
741  ensure(!result.empty());
742 
743  // Exit:
744 
745  return result;
746 }
747 
748 // PROTECTED MEMBER FUNCTIONS
749 
750 // PRIVATE MEMBER FUNCTIONS
751 
752 
753 // ===========================================================
754 // POSET_COMPONENT FACET OF CLASS AT1
755 // ===========================================================
756 
757 // PUBLIC MEMBER FUNCTIONS
758 
761 host() const
762 {
763  return reinterpret_cast<host_type*>(_host);
764 }
765 
766 bool
769 {
770  return dynamic_cast<const host_type*>(xother) != 0;
771 }
772 
773 // PROTECTED MEMBER FUNCTIONS
774 
775 // PRIVATE MEMBER FUNCTIONS
776 
777 
778 //==============================================================================
779 // ANY FACET OF CLASS AT1
780 //==============================================================================
781 
782 // PUBLIC MEMBER FUNCTIONS
783 
784 bool
786 is_ancestor_of(const any* xother) const
787 {
788 
789  // Preconditions:
790 
791  require(xother != 0);
792 
793  // Body:
794 
795  // If other may be dynamically cast to the type of this then this is an
796  // ancestor of other.
797 
798  bool result = dynamic_cast<const at1*>(xother) != 0;
799 
800  // Postconditions:
801 
802  //ensure(invariant());
803  //ensure(xother->invariant());
804 
805  // Exit:
806 
807  return result;
808 }
809 
812 clone() const
813 {
814 
815  // Preconditions:
816 
817  // Body:
818 
819  // Create new handle of the current class.
820 
821  at1 *result = new at1();
822 
823  // Postconditions:
824 
825  ensure(result != 0);
826  ensure(result->invariant());
827 
828  // Exit:
829 
830  return result;
831 
832 }
833 
834 bool
836 invariant() const
837 {
838  bool result = true;
839 
840  // Preconditions:
841 
842  // Body:
843 
844  // Must satisfy base class invariant.
845 
846  invariance(atp::invariant());
847 
848  if (invariant_check())
849  {
850  // Prevent recursive calls to invariant.
851 
852  disable_invariant_check();
853 
854  invariance((is_attached() ? p() == 1 : true));
855 
856  // Finished, turn invariant checking back on.
857 
858  enable_invariant_check();
859  }
860 
861  // Postconditions:
862 
863  ensure(is_derived_query);
864 
865  // Exit:
866 
867  return result;
868 }
869 
bool is_ancestor_of(const any *xother) const
True if other conforms to current.
Definition: at1.cc:786
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 ...
at1_lite()
Default constructor.
Definition: at1.cc:45
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
static int d(const namespace_poset &xns, int xp, const poset_path &xvector_space_path, bool xauto_access)
The tensor dimension implied by tensor degree xp and the dimension of the domain vector space specifi...
Definition: atp_space.cc:86
virtual bool host_is_ancestor_of(const poset_state_handle *other) const
True if other conforms to host.
Definition: at1.cc:768
poset_path path(bool xauto_access=true) const
A path to this component.
The default name space; a poset which contains other posets as members.
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.
A general antisymmetric tensor of degree 1 over an abstract vector space (persistent version)...
Definition: at1.h:211
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
poset_path vector_space_path() const
The path of the underlying vector space.
Definition: tp_space.cc:365
at1_lite & operator=(const at1_lite &xother)
Assignment operator.
Definition: at1.cc:77
A general antisymmetric tensor of degree 1 over an abstract vector space (volatile version)...
Definition: at1.h:44
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...
A client handle for a general, abstract partially order set.
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
virtual ~at1()
Destructor.
Definition: at1.cc:624
T::row_dofs_type & row_dofs(T &x0)
The row dofs pod type for x0 (mutable version).
at1()
Default constructor.
Definition: at1.cc:460
virtual ~at1_lite()
Destructor.
Definition: at1.cc:96
Abstract base class with useful features for all volatile objects.
Definition: any_lite.h:48
Abstract base class with useful features for all objects.
Definition: any.h:39
static const std::string & static_class_name()
The name of this class.
Definition: at1.cc:239
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
host_type * host() const
The poset this is a member of.
Definition: at1.cc:761
A space of scalars viewed as an antisymmetric tensor space of degree 0.
Definition: at0_space.h:42
virtual const std::string & class_name() const
The name of this class.
Definition: at1.cc:220
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...
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 contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
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. ...
int p(int xd, int xdd) const
Tensor degree as a function of tensor dimension xd and domain dimension xdd.
Definition: tp_space.cc:235
bool invariant() const
Class invariant.
Definition: at1.cc:836
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
poset_path scalar_space_path() const
The path of the underlying space of scalars.
Definition: vd_space.cc:250
An abstract vector space viewed as an antisymmetric tensor space of degree 1.
Definition: at1_space.h:42
virtual at1 * clone() const
Make a new handle, no state instance of current.
Definition: at1.cc:812
static int factor_ct(int xd)
Factor_ct() as a function of dimension xd.
Definition: vd_space.cc:167
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual const volatile_type & lite_prototype() const
Virtual constructor for the associated volatile type.
Definition: at1.cc:637
int dd() const
The dimension of the underlying ("domain") vector space.
Definition: tp_space.cc:317
bool invariant() const
Class invariant.
Definition: at1.cc:310
virtual volatile_type * lite_type() const
Virtual conversion to the associated volatile type.
Definition: at1.cc:655
virtual at1 & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: at1.cc:581
virtual at1_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: at1.cc:258
An abstract client handle for a member of a poset.
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: at1.cc:353
virtual bool is_ancestor_of(const any_lite &xother) const
Conformance test; true if other conforms to this.
Definition: at1.cc:291
static void make_standard_schema(namespace_poset &xns)
Creates the standard schema for this class in namespace xns.
Definition: at1.cc:371
Namespace for the fiber_bundles component of the sheaf system.
Row dofs type for class vd.
Definition: vd.h:61
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...
A client handle for a poset member which has been prepared for use as a schema.
static const std::string & static_class_name()
The name of this class.
Definition: at1.cc:731
virtual const std::string & class_name() const
The name of this class.
Definition: at1.cc:712
virtual int p() const
Degree of this as an antisymmetric tensor space.
Definition: at1.cc:156
static host_type & new_host(namespace_type &xns, const poset_path &xhost_path, const poset_path &xschema_path, const poset_path &xscalar_space_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: at1.cc:401
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710