SheafSystem  0.0.0.0
partial_poset_member.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/partial_poset_member.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 #include "SheafSystem/array_poset_dof_map.h"
25 #include "SheafSystem/namespace_poset.h"
26 #include "SheafSystem/pool.h"
27 #include "SheafSystem/poset.h"
28 #include "SheafSystem/poset_crg_state.h"
29 #include "SheafSystem/poset_dof_map.h"
30 #include "SheafSystem/poset_joiner.h"
31 #include "SheafSystem/poset_slicer.h"
32 #include "SheafSystem/poset_state.h"
33 #include "SheafSystem/poset_state_handle.h"
34 #include "SheafSystem/postorder_iterator.h"
35 #include "SheafSystem/primitives_poset.h"
36 #include "SheafSystem/primitives_poset_schema.h"
37 #include "SheafSystem/subposet.h"
38 #include "SheafSystem/subposet_member_iterator.h"
39 #include "SheafSystem/subposet_state.h"
40 #include "SheafSystem/zn_to_bool.h"
41 
42 // ===========================================================
43 // PARTIAL_POSET_MEMBER FACET
44 // ===========================================================
45 
46 // PUBLIC MEMBER FUNCTIONS
47 
50  : _schema(0)
51 {
52 
53  // Preconditions:
54 
55  // Body:
56 
57  // Postconditions:
58 
59  ensure(invariant());
60  ensure(!is_attached());
61 }
62 
64 partial_poset_member(const abstract_poset_member& xother, bool xnew_jem)
65  : _schema(0)
66 {
67  // Preconditions:
68 
69  require(xnew_jem ? xother.is_attached() : true);
70 
71  // Body:
72 
73  if(xnew_jem)
74  {
75  new_jem_state(const_cast<abstract_poset_member*>(&xother), true, true);
76  }
77  else
78  {
79  attach_to_state(&xother);
80  }
81 
82  // Postconditions:
83 
84  ensure(invariant());
85  ensure(is_attached() == const_cast<abstract_poset_member&>(xother).is_attached() );
86 }
87 
91 {
92  // Preconditions:
93 
94  // Body:
95 
96  attach_to_state(&xother);
97 
98  // Postconditions:
99 
100  ensure(is_same_state(&(const_cast<abstract_poset_member&>(xother))));
101 
102  // Exit
103 
104  return *this;
105 }
106 
110 {
111  // Preconditions:
112 
113  require(precondition_of(attach_to_state(&xother)));
114 
115  // Body:
116 
117  attach_to_state(&xother);
118 
119  // Postconditions:
120 
121  ensure(postcondition_of(attach_to_state(&xother)));
122 
123  // Exit:
124 
125  return *this;
126 }
127 
130 {
131 
132  // Preconditions:
133 
134  // Body:
135 
136  // Delete the restricted schema handle
137 
138  if(_schema != 0)
139  {
140  delete _schema;
141  }
142 
143  // Postconditions:
144 
145  // Exit
146 
147  return;
148 }
149 
150 // NEW HANDLE, NEW STATE CONSTRUCTORS
151 
154  poset_dof_map* xdof_map,
155  bool xcopy_dof_map,
156  bool xauto_access)
157  : _schema(0)
158 {
159  // Preconditions:
160 
161  require(precondition_of(new_jim_state(same args)));
162 
163  // Body:
164 
165  new_jim_state(xhost, xdof_map, xcopy_dof_map, xauto_access);
166 
167  // Postconditions:
168 
169  require(postcondition_of(new_jim_state(same args)));
170 }
171 
174  const scoped_index* xexpansion,
175  int xexpansion_ct,
176  const tern& xnew_jem,
177  bool xauto_access)
178  : _schema(0)
179 {
180 
181  // Preconditions:
182 
183  require(precondition_of(new_jrm_state(same args)));
184 
185  // Body:
186 
187  new_jrm_state(xhost, xexpansion, xexpansion_ct, xnew_jem, xauto_access);
188 
189  // Postconditions:
190 
191  require(postcondition_of(new_jrm_state(same args)));
192 }
193 
194 // NEW HANDLE, EXISTING STATE CONSTRUCTORS
195 
198  : _schema(0)
199 {
200  // Preconditions:
201 
202  require(xhost->state_is_read_accessible());
203  require(xhost->contains_member(xhub_id));
204 
205  // Body:
206 
207  attach_to_state(xhost, xhub_id);
208 
209  // Postconditions:
210 
211  ensure(invariant());
212  ensure(host() == xhost);
213  ensure(index() == xhub_id);
214  ensure(is_attached());
215 }
216 
219  : _schema(0)
220 {
221  // Preconditions:
222 
223  require(xhost->state_is_read_accessible());
224  require(xhost->contains_member(xid));
225 
226  // Body:
227 
228  attach_to_state(xhost, xid.hub_pod());
229 
230  // Postconditions:
231 
232  ensure(invariant());
233  ensure(host() == xhost);
234  ensure(index() ==~ xid);
235  ensure(is_attached());
236 }
237 
239 partial_poset_member(const poset_state_handle* xhost, const std::string& xname)
240  : _schema(0)
241 {
242 
243  // Preconditions:
244 
245  require(xhost != 0);
246  require(xhost->state_is_read_accessible());
247  require(!xname.empty());
248  require(xhost->contains_member(xname));
249 
250  // Body:
251 
252  attach_to_state(xhost, xname);
253 
254  // Postconditions:
255 
256  ensure(invariant());
257  ensure(host() == xhost);
258  ensure(name() == xname);
259  ensure(is_attached());
260 }
261 
264  const poset_path& xpath,
265  bool xauto_access)
266  : _schema(0)
267 {
268  // Preconditions:
269 
270  require(precondition_of(attach_to_state(same args)));
271 
272  // Body:
273 
274  attach_to_state(xnamespace, xpath, xauto_access);
275 
276  // Postconditions:
277 
278  ensure(postcondition_of(attach_to_state(same args)));
279 
280  // Exit:
281 
282  return;
283 }
284 
285 // PROTECTED MEMBER FUNCTIONS
286 
289  : _schema(xschema)
290 {
291  // Preconditions:
292 
293  require(xschema != 0);
294  require(!xschema->is_attached());
295 
296  // Body:
297 
298  // Postconditions:
299 
300  // Exit
301 
302  return;
303 }
304 
305 void
308 {
309  // Preconditions:
310 
311  require(state_is_read_accessible());
312 
313  // Body:
314 
315  // Have just attached to a new or different host.
316  // Initialize the handle data members for the different host.
317 
318  if(_schema != 0)
319  {
321  delete _schema;
322  }
323 
324  _schema = host()->schema().clone();
325 
326  // Postconditions:
327 
328  ensure(!_schema->is_attached());
329 
330  // Exit
331 
332  return;
333 }
334 
335 void
338 {
339  // Preconditions:
340 
341  require(state_is_read_accessible());
342 
343  // Body:
344 
345  if(is_valid(dof_tuple_id(false)))
346  {
347  // This member has a dof tuple; it is a jim in some version of the host.
348  // Schema is the same as the dof map schema.
349 
351  }
352  else
353  {
354  // This is not a jim in any version; use the host schema
356 
358  }
359 
360  // Postconditions:
361 
362  ensure(schema().is_attached() == host()->schema().is_attached());
363  ensure(!is_restricted());
364 
365  // Exit
366 
367  return;
368 }
369 
370 // PRIVATE MEMBER FUNCTIONS
371 
372 
373 // ===========================================================
374 // SCHEMA FACET
375 // ===========================================================
376 
377 // PUBLIC MEMBER FUNCTIONS
378 
382 {
383  // Preconditions:
384 
385  // The implementation of this only requires is_attached(),
386  // but both ancestors and descendants require state_is_read_accessible().
387 
388  require(state_is_read_accessible());
389 
390  // Body:
391 
392  schema_poset_member& result = *_schema;
393 
394  // Postconditions:
395 
396  ensure(result.le(&(unrestricted_schema())));
397 
398  // Exit
399 
400  return result;
401 }
402 
405 schema() const
406 {
407  // Preconditions:
408 
409  // The implementation of this only requires is_attached(),
410  // but both ancestors and descendants require state_is_read_accessible().
411 
412  require(state_is_read_accessible());
413 
414  // Body:
415 
416  const schema_poset_member& result = *_schema;
417 
418  // Postconditions:
419 
420  ensure(result.le(&(unrestricted_schema())));
421 
422  // Exit
423 
424  return result;
425 }
426 
427 // PROTECTED MEMBER FUNCTIONS
428 
429 // PRIVATE MEMBER FUNCTIONS
430 
431 
432 // ===========================================================
433 // RESTRICTION FACET
434 // ===========================================================
435 
436 // PUBLIC MEMBER FUNCTIONS
437 
438 // PROTECTED MEMBER FUNCTIONS
439 
440 void
443 {
444  // Preconditions:
445 
446  require(state_is_read_accessible());
447  require(xschema != 0);
448  require(xschema->state_is_read_accessible());
449  require(schema().is_ancestor_of(xschema));
450  require(xschema->le(&(unrestricted_schema())));
451 
452  // Body:
453 
454  // Attach the handle schema to xschema
455 
456  _schema->attach_to_state(xschema);
457 
458  // Postconditions:
459 
460  ensure(schema().is_same_state(xschema));
461 
462  // Exit
463 
464  return;
465 }
466 
467 void
470 {
471  // Preconditions:
472 
473  require(state_is_read_accessible());
474  require(xother != 0);
475  require(xother->state_is_read_accessible());
476  require(has_same_host(xother));
477  require(xother->schema().le(&(unrestricted_schema())));
478 
479  // Body:
480 
481  _schema->attach_to_state(&(xother->schema()));
482 
483  // Postconditions:
484 
485  ensure(is_same_restriction(xother));
486 
487  // Exit
488 
489  return;
490 }
491 
492 void
495 {
496  // Preconditions:
497 
498  require(state_is_read_accessible());
499 
500  // Body:
501 
503 
504  // Postconditions:
505 
506  ensure(!is_restricted());
507 
508  // Exit
509 
510  return;
511 }
512 
513 // PRIVATE MEMBER FUNCTIONS
514 
515 
516 // ===========================================================
517 // DEGREE OF FREEDOM (DOF) TUPLE FACET
518 // ===========================================================
519 
520 // PUBLIC MEMBER FUNCTIONS
521 
522 int
524 dof_ct() const
525 {
526  return is_attached() ? _schema->row_dof_ct() : 0;
527 }
528 
529 // PROTECTED MEMBER FUNCTIONS
530 
531 // PRIVATE MEMBER FUNCTIONS
532 
533 
534 // ===========================================================
535 // STATE FACET
536 // ===========================================================
537 
538 // PUBLIC MEMBER FUNCTIONS
539 
540 void
543 {
544  // Preconditions:
545 
546  // Body:
547 
548  if(_schema != 0)
549  {
551  }
552 
554 
555  // Postconditions:
556 
557  ensure(invariant());
558  ensure(!is_attached());
559 }
560 
561 // PROTECTED MEMBER FUNCTIONS
562 
563 // PRIVATE MEMBER FUNCTIONS
564 
565 
566 // ===========================================================
567 // ANY FACET
568 // ===========================================================
569 
570 // PUBLIC MEMBER FUNCTIONS
571 
572 bool
574 is_ancestor_of(const any* xother) const
575 {
576  bool result;
577 
578  // Preconditions:
579 
580  // Body:
581 
582  result = dynamic_cast<const partial_poset_member*>(xother) != 0;
583 
584  // Postconditions:
585 
586  // Exit
587 
588  return result;
589 }
590 
593 clone() const
594 {
595 
596  // Preconditions:
597 
598  // Body:
599 
600  // create new handle of the current class.
601 
603 
604  // Postconditions:
605 
606  ensure(result != 0);
607  ensure(result->invariant());
608 
609  // Exit:
610 
611  return result;
612 
613 }
614 
615 bool
617 invariant() const
618 {
619  bool result = true;
620 
621  // Preconditions:
622 
623  // Body:
624 
625  // Must satisfy base class invariant
626 
627  result = result && abstract_poset_member::invariant();
628 
629  if(invariant_check())
630  {
631  // Prevent recursive calls to invariant
632 
634 
635  // Invariants for this class:
636 
637  result = result && (is_attached() ? (_schema != 0) : true);
638  result = result && (is_attached() ? _schema->is_attached() : true);
639  result = result && (is_attached() ? _schema->leqv(host()->schema().index()) : true);
640 
641  // Finished, turn invariant checking back on.
642 
644  }
645 
646  // Postconditions:
647 
648  // Exit
649 
650  return result;
651 }
652 
653 // PROTECTED MEMBER FUNCTIONS
654 
655 // PRIVATE MEMBER FUNCTIONS
656 
657 
658 // ===========================================================
659 // NON-MEMBER FUNCTIONS FACET
660 // ===========================================================
661 
662 
poset_state_handle * host() const
The poset which this is a handle to a component of.
virtual bool is_restricted() const
True if handle is a restriction of the state, that is, if schema() is not the same as host()->schema(...
pod_index_type dof_tuple_id(bool xauto_access) const
The dof tuple index of this member.
virtual void new_jim_state(poset_dof_map *xdof_map=0, bool xcopy_dof_map=false, bool xauto_access=true)
Creates a new jim (join-irreducible member) state in host() and attaches this to it. If xdof_map == 0 a new dof map is created. If xdof_map != 0 and xcopy_dof_map == false, xdof_map is used as the dof map. If xdof_map != 0 and xcopy_dof_map is true, a copy of xdof_map is used.
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...
virtual int dof_ct() const
The number of dofs in restricted schema of this poset member.
virtual partial_poset_member * clone() const
Make a new handle, no state instance of current.
A three state "bool". Does not provide the operations of ternary logic and is intended for use mostly...
Definition: tern.h:45
A client handle for a general, abstract partially order set.
virtual schema_poset_member & schema()
The restricted schema for this poset member (mutable version).
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
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.
A client handle for a possibly restricted member of a poset. A partial_poset_member is a poset_me...
const scoped_index & index() const
The index of the component state this handle is attached to.
std::string name() const
A name for this.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
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...
virtual void restrict_to(const abstract_poset_member *xschema)
Restricts this handle to the down set of xschema.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual schema_poset_member & unrestricted_schema()
The unrestricted schema for this poset member (mutable version).
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
bool has_same_host(const poset_component *xother) const
True if xother is attached to the same host as this or if both are unattached.
virtual void init_handle_data_members()
Initializes handle data members when attaching to a different member in a different host; intended to...
virtual void detach_from_state()
Detach this handle from its state, if any.
virtual partial_poset_member & operator=(const abstract_poset_member &xother)
Assignment operator; attaches this to the same state as xother.
bool leqv(pod_index_type xother_index) const
True if this is less than or equivalent to the member with index xother_index.
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.
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.
static int row_dof_ct(const namespace_poset &xns, const poset_path &xpath, bool xauto_access=true)
The number of row dofs defined by the schema specified by xns and xpath. Synonym for dof_ct(xns...
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual schema_poset_member & schema()
The schema for this poset member (mutable version).
schema_poset_member * _schema
The restricted schema of this member.
virtual void detach_from_state()
Detach this handle from its state, if any.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual void restrict_to_same(const abstract_poset_member *xother)
Restricts this handle to the same restriction as xother.
virtual bool invariant() const
Class invariant.
virtual void attach_handle_data_members()
Initializes _schema; intended to be redefined in derived classes to initialize derived data members...
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
partial_poset_member()
Default constructor; creates a new, unattached partial_poset_member handle.
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.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
An abstract client handle for a member of a poset.
virtual poset_dof_map & dof_map(bool xrequire_write_access=false)
The map from schema member ids or client ids to dof values for this poset member (mutable version) ...
virtual ~partial_poset_member()
Destructor; deletes a poset member and its attached state, if any.
virtual void new_jem_state(abstract_poset_member *xother, bool xgreatest, bool xauto_access)
Creates a new jrm state in host() which is the greatest jem (xgreatest true) or least jem (xgreatest ...
virtual void unrestrict()
Removes any restriction; schema to the schema of host.
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 bool is_same_restriction(const abstract_poset_member *xother) const
True if this is the same restriction as xother, that is, if schema().is_same_state(xother.schema()).
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
A client handle for a poset member which has been prepared for use as a schema.
virtual void new_jrm_state(bool xauto_access=true)
Creates a new jrm (join-reducible member) state in host() and attaches this to it.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710