SheafSystem  0.0.0.0
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/tuple.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/namespace_poset.h"
26 #include "SheafSystem/schema_poset_member.h"
27 #include "SheafSystem/wsv_block.h"
28 
29 #include "SheafSystem/fiber_bundles_namespace.h"
30 #include "SheafSystem/tuple_space.h"
31 
32 using namespace std;
33 using namespace fiber_bundle; // Workaround for MS C++ bug.
34 
35 //==============================================================================
36 // CLASS TUPLE_LITE
37 //==============================================================================
38 
39 //==============================================================================
40 // CARTESIAN ALGEBRA (TUPLE) FACET
41 //==============================================================================
42 
45 {
46 
47  // Preconditions:
48 
49  // Body:
50 
51  // Postconditions:
52 
53  ensure(invariant());
54 
55  // Exit:
56 }
57 
59 tuple_lite(const tuple_lite& xother)
60 {
61  // Preconditions:
62 
63  // Body:
64 
65  // Postconditions:
66 
67  ensure(invariant());
68 
69  // Exit:
70 }
71 
74 operator=(const tuple_lite& xother)
75 {
76  // Preconditions:
77 
78  // Body:
79 
80  // Postconditions:
81 
82  ensure(invariant());
83 
84  // Exit:
85 
86  return *this;
87 }
88 
91 {
92  // Preconditions:
93 
94  // Body:
95 
96  // Postconditions:
97 
98  // Exit:
99 
100 }
101 
102 //==============================================================================
103 // ABSTRACT POSET MEMBER FACET
104 //==============================================================================
105 
106 const std::string&
108 class_name() const
109 {
110  // Preconditions:
111 
112  // Body:
113 
114  const string& result = static_class_name();
115 
116  // Postconditions:
117 
118  ensure(!result.empty());
119 
120  // Exit:
121 
122  return result;
123 }
124 
125 const std::string&
128 {
129  // Preconditions:
130 
131  // Body:
132 
133  static const string result("tuple_lite");
134 
135  // Postconditions:
136 
137  ensure(!result.empty());
138 
139  // Exit:
140 
141  return result;
142 }
143 
146 table_dofs() const
147 {
148  // Preconditions:
149 
150  // Body:
151 
152  // The order here is factor_ct, d, u, v, dd, p.
153 
154  int lfactor_ct = factor_ct();
155  table_dofs_type result = {lfactor_ct};
156 
157  // Postconditions:
158 
159  // Exit:
160 
161  return result;
162 }
163 
164 //==============================================================================
165 // ANY FACET
166 //==============================================================================
167 
168 bool
170 is_ancestor_of(const any_lite& xother) const
171 {
172  // Preconditions:
173 
174  require(&xother != 0);
175 
176  // Body:
177 
178  // True if other conforms to this.
179 
180  bool result = dynamic_cast<const tuple_lite*>(&xother) != 0;
181 
182  // Postconditions:
183 
184  return result;
185 }
186 
189 clone() const
190 {
191  tuple_lite* result = 0;
192 
193  // Preconditions:
194 
195  // Body:
196 
197  is_abstract();
198 
199  // Postconditions:
200 
201  ensure(result != 0);
202  ensure(is_same_type(*result));
203 
204  // Exit:
205 
206  return result;
207 }
208 
209 bool
211 invariant() const
212 {
213  bool result = true;
214 
215  if(invariant_check())
216  {
217  // Prevent recursive calls to invariant.
218 
219  disable_invariant_check();
220 
221  // Must satisfy base class invariant.
222 
223  invariance(any_lite::invariant());
224 
225  // Invariances for this class:
226 
227  // Finished, turn invariant checking back on.
228 
229  enable_invariant_check();
230  }
231 
232  // Exit
233 
234  return result;
235 }
236 
237 
238 //==============================================================================
239 // CLASS TUPLE
240 //==============================================================================
241 
242 // ===========================================================
243 // HOST FACTORY FACET
244 // ===========================================================
245 
246 // PUBLIC MEMBER FUNCTIONS
247 
248 const std::string&
251 {
252  // Preconditions:
253 
254 
255  // Body:
256 
257  static const string result("fiber_space_schema");
258 
259  // Postconditions:
260 
261  ensure(!result.empty());
262 
263  // Exit:
264 
265  return result;
266 }
267 
268 const sheaf::poset_path&
271 {
272  // Preconditions:
273 
274 
275  // Body:
276 
277  static const poset_path result(standard_schema_poset_name(), "tuple_schema");
278 
279  // Postconditions:
280 
281  ensure(result.full());
282  ensure(result.poset_name() == standard_schema_poset_name());
283 
284  // Exit:
285 
286  return result;
287 }
288 
289 void
292 {
293  // Preconditions:
294 
295  require(xns.state_is_read_write_accessible());
296  require(xns.contains_poset(standard_schema_poset_name(), false));
297  require(xns.member_poset(standard_schema_poset_name(), false).state_is_read_write_accessible());
298  require(!xns.contains_poset_member(standard_schema_path(), false));
299 
300  // Body:
301 
302  string lmember_names = "factor_ct INT true";
303 
304  schema_poset_member lschema(xns,
305  standard_schema_path().member_name(),
306  poset_path(standard_schema_poset_name(), "bottom"),
307  lmember_names,
308  false);
309 
310  lschema.detach_from_state();
311 
312  // Postconditions:
313 
314  ensure(xns.contains_poset_member(standard_schema_path()));
315 
316  // Exit:
317 
318  return;
319 }
320 
323 new_host(namespace_type& xns, const poset_path& xhost_path, const poset_path& xschema_path, int xfactor_ct, bool xauto_access)
324 {
325  // cout << endl << "Entering tuple::new_host." << endl;
326 
327  // Preconditions:
328 
329  require(xns.state_is_auto_read_write_accessible(xauto_access));
330 
331  require(!xhost_path.empty());
332  require(!xns.contains_path(xhost_path, xauto_access));
333 
334  require(xschema_path.full());
335  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
336  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path()));
337 
338  require(xfactor_ct > 0);
339 
340  // Body:
341 
342  host_type& result =
343  host_type::new_table(xns, xhost_path, xschema_path, xfactor_ct, xauto_access);
344 
345  // Postconditions:
346 
347  ensure(xns.owns(result, xauto_access));
348  ensure(result.path(true) == xhost_path);
349  ensure(result.state_is_not_read_accessible());
350  ensure(result.schema(true).path(xauto_access) == xschema_path);
351 
352  ensure(result.factor_ct(true) == xfactor_ct);
353 
354  // Exit:
355 
356  // cout << "Leaving tuple::new_host." << endl;
357  return result;
358 }
359 
360 
361 // PROTECTED MEMBER FUNCTIONS
362 
363 // PRIVATE MEMBER FUNCTIONS
364 
365 // ===========================================================
366 // CARTESIAN ALGEBRA (TUPLE) FACET
367 // ===========================================================
368 
369 // PUBLIC MEMBER FUNCTIONS
370 
373 {
374 
375  // Preconditions:
376 
377  // Body:
378 
379  // Postconditions:
380 
381  ensure(invariant());
382 }
383 
386 {
387  // Preconditions:
388 
389  require(xhost != 0);
390  require(xhost->state_is_read_accessible());
391  require(xhost->contains_member(xhub_id));
392 
393  // Body:
394 
395  attach_to_state(xhost, xhub_id);
396 
397  // Postconditions:
398 
399  ensure(invariant());
400  // ensure(host() == xhost);
401  ensure(index() == xhub_id);
402  ensure(is_attached());
403 }
404 
406 tuple(const poset_state_handle* xhost, const scoped_index& xid)
407 {
408  // Preconditions:
409 
410  require(xhost != 0);
411  require(xhost->state_is_read_accessible());
412  require(xhost->contains_member(xid));
413 
414  // Body:
415 
416  attach_to_state(xhost, xid.hub_pod());
417 
418  // Postconditions:
419 
420  ensure(invariant());
421  // ensure(host() == xhost);
422  ensure(index() ==~ xid);
423  ensure(is_attached());
424 }
425 
427 tuple(const poset_state_handle* xhost, const std::string& xname)
428 {
429 
430  // Preconditions:
431 
432  require(xhost != 0);
433  require(xhost->state_is_read_accessible());
434  require(!xname.empty());
435  require(xhost->contains_member(xname));
436 
437  // Body:
438 
439  attach_to_state(xhost, xname);
440 
441  // Postconditions:
442 
443  ensure(invariant());
444  // ensure(host() == xhost);
445  ensure(name() == xname);
446  ensure(is_attached());
447 
448 }
449 
452 {
453 
454  // Preconditions:
455 
456  require(xother != 0);
457  require(xother->is_attached() ? xother->state_is_read_accessible() : true);
458  require(abstract_poset_member::is_ancestor_of(xother));
459 
460  // Body:
461 
462  attach_to_state(xother);
463 
464  // Postconditions:
465 
466  ensure(invariant());
467  ensure(is_attached());
468  ensure(is_same_state(xother));
469 
470  // Exit:
471 }
472 
474 tuple(poset_state_handle* xhost, bool xauto_access)
475 {
476 
477  // Preconditions:
478 
479  require(precondition_of(new_jim_state(xhost, 0, false, xauto_access)));
480 
481  // Body:
482 
483  new_jim_state(xhost, 0, false, xauto_access);
484 
485  // Postconditions:
486 
487  ensure(postcondition_of(new_jim_state(xhost, 0, false, xauto_access)));
488 
489  // Exit:
490 
491  return;
492 }
493 
497 {
498  // Preconditions:
499 
500  require(is_ancestor_of(&xother));
501  require(precondition_of(attach_to_state(&xother)));
502 
503  // Body:
504 
505  attach_to_state(&xother);
506 
507  // Postconditions:
508 
509  ensure(postcondition_of(attach_to_state(&xother)));
510 
511  // Exit:
512 
513  return *this;
514 }
515 
518 operator=(const tuple& xother)
519 {
520  // Preconditions:
521 
522  require(precondition_of(attach_to_state(&xother)));
523 
524  // Body:
525 
526  attach_to_state(&xother);
527 
528  // Postconditions:
529 
530  ensure(postcondition_of(attach_to_state(&xother)));
531 
532  // Exit:
533 
534  return *this;
535 }
536 
539 {
540 
541  // Preconditions:
542 
543  // Body:
544 
545  // Postconditions:
546 
547 }
548 
549 int
551 factor_ct() const
552 {
553  // Preconditions:
554 
555  require(state_is_read_accessible());
556 
557  // Body:
558 
559  int result = host()->factor_ct();
560 
561  // Postconditions:
562 
563  // Exit:
564 
565  return result;
566 }
567 
568 int
570 factor_ct(bool xauto_access) const
571 {
572  // Preconditions:
573 
574  require(state_is_auto_read_accessible(xauto_access));
575 
576  // Body:
577 
578  int result = host()->factor_ct();
579 
580  // Postconditions:
581 
582  // Exit:
583 
584  return result;
585 }
586 
589 dof_map(bool xrequire_write_access)
590 {
591  // Preconditions:
592 
593  require(xrequire_write_access ?
594  state_is_read_write_accessible() :
595  state_is_read_accessible());
596  require(is_jim(false));
597 
598  // Body:
599 
600  array_poset_dof_map& result =
601  reinterpret_cast<array_poset_dof_map&>(abstract_poset_member::dof_map());
602 
603  // Postconditions:
604 
605  ensure(is_basic_query);
606 
607  // Exit:
608 
609  return result;
610 }
611 
614 dof_map(bool xrequire_write_access) const
615 {
616  // Preconditions:
617 
618  require(xrequire_write_access ?
619  state_is_read_write_accessible() :
620  state_is_read_accessible());
621  require(is_jim(false));
622 
623  // Body:
624 
625  const array_poset_dof_map& result =
626  reinterpret_cast<const array_poset_dof_map&>(abstract_poset_member::dof_map());
627 
628  // Postconditions:
629 
630  ensure(is_basic_query);
631 
632  // Exit:
633 
634  return result;
635 }
636 
637 bool
639 dof_map_is_ancestor_of(const poset_dof_map* xdof_map) const
640 {
641  bool result;
642 
643  // Preconditions:
644 
645  require(xdof_map != 0);
646 
647  // Body:
648 
649  // This handle requires xdof_map to be of type array_poset_dof_map.
650 
651  result = dynamic_cast<const array_poset_dof_map*>(xdof_map) != 0;
652 
653  // Postconditions:
654 
655  // Exit
656 
657  return result;
658 }
659 
660 // PROTECTED MEMBER FUNCTIONS
661 
662 // PRIVATE MEMBER FUNCTIONS
663 
664 //==============================================================================
665 // ABSTRACT POSET MEMBER FACET
666 //==============================================================================
667 
668 const std::string&
670 class_name() const
671 {
672  // Preconditions:
673 
674  // Body:
675 
676  const string& result = static_class_name();
677 
678  // Postconditions:
679 
680  ensure(!result.empty());
681 
682  // Exit:
683 
684  return result;
685 }
686 
687 const std::string&
690 {
691  // Preconditions:
692 
693  // Body:
694 
695  static const string result("tuple");
696 
697  // Postconditions:
698 
699  ensure(!result.empty());
700 
701  // Exit:
702 
703  return result;
704 }
705 
708 clone() const
709 {
710 
711  // Preconditions:
712 
713  // Body:
714 
715  // Create new handle of the current class.
716 
717  tuple *result = new tuple();
718 
719  // Postconditions:
720 
721  ensure(result != 0);
722  ensure(result->invariant());
723 
724  // Exit:
725 
726  return result;
727 
728 }
729 
730 // ===========================================================
731 // POSET_COMPONENT FACET
732 // ===========================================================
733 
736 host() const
737 {
738  return reinterpret_cast<host_type*>(_host);
739 }
740 
741 bool
744 {
745  return dynamic_cast<const host_type*>(xother) != 0;
746 }
747 
748 //==============================================================================
749 // ANY FACET
750 //==============================================================================
751 
752 bool
754 is_ancestor_of(const any* xother) const
755 {
756  // Preconditions:
757 
758  // Body:
759 
760  // If other may be dynamically cast to the type of this then this is an
761  // ancestor of xother.
762 
763  bool result = dynamic_cast<const tuple*>(xother) != 0;
764 
765  // Postconditions:
766 
767  ensure(invariant());
768 
769  // Exit:
770 
771  return result;
772 }
773 
774 bool
776 invariant() const
777 {
778  bool result = true;
779 
780  // Preconditions:
781 
782  // Body:
783 
784  // Must satisfy base class invariant.
785 
786  invariance(total_poset_member::invariant());
787 
788  if (invariant_check())
789  {
790  // Prevent recursive calls to invariant.
791 
792  disable_invariant_check();
793 
794  // Invariants for this class:
795 
796  // Finished, turn invariant checking back on.
797 
798  enable_invariant_check();
799  }
800 
801  // Postconditions:
802 
803  ensure(is_derived_query);
804 
805  // Exit:
806 
807  return result;
808 }
809 
810 //==============================================================================
811 // NON-MEMBER FUNCTIONS
812 //==============================================================================
813 
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 ...
static const poset_path & standard_schema_path()
The path of the schema required by this class.
Definition: tuple.cc:270
static host_type & new_host(namespace_type &xns, const poset_path &xhost_path, const poset_path &xschema_path, int xfactor_ct, bool xauto_access)
Creates a new host table for members of this type. The poset is created in namespace xns with path xh...
Definition: tuple.cc:323
virtual ~tuple()
Destructor.
Definition: tuple.cc:538
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
Table dofs type for class tuple_table_dofs_type.
virtual array_poset_dof_map & dof_map(bool xrequire_write_access=false)
The map from client_ids to dof values for this poset member (mutable version)
Definition: tuple.cc:589
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.
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
virtual bool invariant() const
Class invariant.
Definition: tuple.cc:776
virtual const std::string & class_name() const
The name of this class.
Definition: tuple.cc:670
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...
static void make_standard_schema(namespace_poset &xns)
Creates the standard schema for this class in namespace xns.
Definition: tuple.cc:291
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.
host_type * host() const
The poset this is a member of.
Definition: tuple.cc:736
A Cartesian product space.
Definition: tuple_space.h:52
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.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
virtual int factor_ct() const
Number of factors (components) in tuple.
Definition: tuple.cc:551
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
virtual const std::string & class_name() const
The name of this class.
Definition: tuple.cc:108
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: tuple.cc:250
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
tuple_lite()
Default constructor.
Definition: tuple.cc:44
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)
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.
static const std::string & static_class_name()
The name of this class.
Definition: tuple.cc:127
std::string poset_name() const
The poset name part of the path.
Definition: poset_path.cc:473
A member of a Cartesian product space; a tuple of attributes (volatile version).
Definition: tuple.h:81
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 is_ancestor_of(const any_lite &xother) const
Conformance test; true if other conforms to this.
Definition: tuple.cc:170
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. ...
A member of a Cartesian product space; a tuple of attributes (persistent version).
Definition: tuple.h:191
virtual tuple & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: tuple.cc:496
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..
bool invariant() const
Class invariant.
Definition: tuple.cc:211
virtual bool host_is_ancestor_of(const poset_state_handle *other) const
True if other conforms to host.
Definition: tuple.cc:743
virtual ~tuple_lite()
Destructor.
Definition: tuple.cc:90
table_dofs_type table_dofs() const
The table dofs.
Definition: tuple.cc:146
tuple()
Default constructor.
Definition: tuple.cc:372
static const std::string & static_class_name()
The name of this class.
Definition: tuple.cc:689
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual tuple_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: tuple.cc:189
void tuple(pod_index_type x, size_type xj_ub, pod_index_type &xi, pod_index_type &xj)
Ordinal to 2-tuple conversion.
virtual tuple * clone() const
Make a new handle, no state instance of current.
Definition: tuple.cc:708
An abstract client handle for a member of a poset.
An array representation of abstract class poset_dof_map.
Namespace for the fiber_bundles component of the sheaf system.
int factor_ct() const
The number of factors in this product.
Definition: tuple_space.cc:152
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.
tuple_lite & operator=(const tuple_lite &xother)
Assignment operator.
Definition: tuple.cc:74
bool is_ancestor_of(const any *other) const
True if other conforms to current.
Definition: tuple.cc:754
virtual bool dof_map_is_ancestor_of(const poset_dof_map *xdof_map) const
True if xdof_map conforms to (is derived from) the type of dof map required by this handle...
Definition: tuple.cc:639
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710