SheafSystem  0.0.0.0
namespace_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/namespace_poset_member.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/namespace_poset.h"
25 #include "SheafSystem/postorder_iterator.h"
26 #include "SheafSystem/tern.h"
27 
28 // ===========================================================
29 // NAMESPACE_POSET_MEMBER FACET
30 // ===========================================================
31 
32 // PUBLIC MEMBER FUNCTIONS
33 
36 {
37  // Preconditions:
38 
39  // Body:
40 
41  // Postconditions:
42 
43  ensure(invariant());
44  ensure(!is_attached());
45 }
46 
48 namespace_poset_member(const namespace_poset_member& xother, bool xnew_jem)
49 {
50  // Preconditions:
51 
52  require(xnew_jem ? xother.is_attached() : true);
53 
54  // Body:
55 
56  if(xnew_jem)
57  {
58  new_jem_state(const_cast<namespace_poset_member*>(&xother), true, true);
59  }
60  else
61  {
62  attach_to_state(&xother);
63  }
64 
65  // Postconditions:
66 
67  ensure(invariant());
68  ensure(is_attached() == xother.is_attached());
69 }
70 
74 {
75  // Preconditions:
76 
77  // Body:
78 
79  attach_to_state(&xother);
80 
81  // Postconditions:
82 
83  ensure(is_same_state(&xother));
84 
85  // Exit
86 
87  return *this;
88 }
89 
93 {
94  // Preconditions:
95 
96  require(is_ancestor_of(&xother));
97 
98  // Body:
99 
100  not_implemented();
101 
102  // Postconditions:
103 
104  ensure(invariant());
105 
106  // Exit:
107 
108  return *this;
109 }
110 
113 {
114  // Preconditions:
115 
116  // Body:
117 
118  // Postconditions:
119 
120  // Exit
121 
122  return;
123 }
124 
125 // NEW HANDLE, NEW STATE CONSTRUCTORS
126 
129  const scoped_index* xexpansion,
130  int xexpansion_ct,
131  const tern& xnew_jem,
132  bool xauto_access)
133 {
134  // Preconditions:
135 
136  require(precondition_of(new_jrm_state(same args)));
137 
138  // Body:
139 
140  new_jrm_state(xhost, xexpansion, xexpansion_ct, xnew_jem);
141 
142  // Postconditions:
143 
144  ensure(invariant());
145  ensure(postcondition_of(new_jrm_state(same args)));
146 }
147 
148 // NEW HANDLE, EXISTING STATE CONSTRUCTORS
149 
152 {
153  // Preconditions:
154 
155  require(xhost->state_is_read_accessible());
156  require(xhost->contains_member(xhub_id));
157 
158  // Body:
159 
160  attach_to_state(xhost, xhub_id);
161 
162  // Postconditions:
163 
164  ensure(invariant());
165  ensure(host() == xhost);
166  ensure(index() == xhub_id);
167  ensure(is_attached());
168 }
169 
172 {
173  // Preconditions:
174 
175  require(xhost->state_is_read_accessible());
176  require(xhost->contains_member(xid));
177 
178  // Body:
179 
180  attach_to_state(xhost, xid.hub_pod());
181 
182  // Postconditions:
183 
184  ensure(invariant());
185  ensure(host() == xhost);
186  ensure(index() ==~ xid);
187  ensure(is_attached());
188 }
189 
191 namespace_poset_member(const namespace_poset* xhost, const std::string& xname)
192 {
193  // Preconditions:
194 
195  require(xhost != 0);
196  require(xhost->state_is_read_accessible());
197  require(!xname.empty());
198  require(xhost->contains_member(xname));
199 
200  // Body:
201 
202  attach_to_state(xhost, xname);
203 
204  // Postconditions:
205 
206  ensure(invariant());
207  ensure(host() == xhost);
208  ensure(name() == xname);
209  ensure(is_attached());
210 }
211 
214 {
215  // Preconditions:
216 
217  require(xmember_poset.is_attached() || xmember_poset.is_external());
218  require(xmember_poset.name_space()->state_is_read_accessible());
219  require(xmember_poset.name_space()->contains_member(xmember_poset.index()));
220 
221  // Body:
222 
223  attach_to_state(xmember_poset.name_space(), xmember_poset.index());
224 
225  // Postconditions:
226 
227  ensure(invariant());
228  ensure(is_attached());
229  ensure(index() ==~ xmember_poset.index());
230 }
231 
235 {
236  poset_state_handle* result;
237 
238  // Preconditions:
239 
240  require(state_is_read_accessible());
241  require(is_jim());
242 
243  // Body:
244 
245  result = dof_map().poset_pointer();
246 
247  // Postconditions:
248 
249  // Exit
250 
251  return result;
252 }
253 
257 {
258  poset_type result;
259 
260  // Preconditions:
261 
262  require(state_is_read_accessible());
263  require(is_jim());
264 
265  // Body:
266 
267  result = dof_map().poset_type_id();
268 
269  // Postconditions:
270 
271  // Exit
272 
273  return result;
274 }
275 
276 const char*
278 poset_class() const
279 {
280  const char* result;
281 
282  // Preconditions:
283 
284  require(state_is_read_accessible());
285  require(is_jim());
286 
287  // Body:
288 
289  result = dof_map().poset_class();
290 
291  // Postconditions:
292 
293  // Exit
294 
295  return result;
296 }
297 
300 poset_prereq_id(int xi) const
301 {
302  // Preconditions:
303 
304  require(state_is_read_accessible());
305  require(is_jim());
306  require((0 <= xi) && (xi < PREREQ_IDS_UB));
307 
308  // Body:
309 
310  pod_index_type result = dof_map().poset_prereq_id(xi);
311 
312  // Postconditions:
313 
314  // Exit:
315 
316  return result;
317 }
318 
319 bool
322 {
323  bool result;
324 
325  // Preconditions:
326 
327  require(state_is_read_accessible());
328  require(is_jim());
329 
330  // Body:
331 
332  result = poset_pointer()->is_external();
333 
334  // Postconditions:
335 
336  // Exit
337 
338  return result;
339 }
340 
341 // PROTECTED MEMBER FUNCTIONS
342 
345  namespace_poset_dof_map* xdof_map,
346  bool xcopy_dof_map,
347  bool xauto_access)
348 {
349  // Preconditions:
350 
351  require(precondition_of(new_jim_state(same args)));
352 
353  // Body:
354 
355  new_jim_state(xhost, xdof_map, xcopy_dof_map, xauto_access);
356 
357  // Postconditions:
358 
359  ensure(invariant());
360  ensure(postcondition_of(new_jim_state(same args)));
361 
362 }
363 
364 void
367 {
368  // Preconditions:
369 
371  require(is_jim());
372 
373  // Body:
374 
378 
379  dof_map().put_poset_pointer(xposet);
380 
381  // Postconditions:
382 
383  ensure(poset_pointer() == xposet);
384 
385  // Exit
386 
387  return;
388 }
389 
390 void
393 {
394  // Preconditions:
395 
397  require(is_jim());
398 
399  // Body:
400 
401  dof_map().put_poset_type_id(xtype_id);
402 
403  // Postconditions:
404 
405  ensure(poset_type_id() == xtype_id);
406 
407  // Exit
408 
409  return;
410 }
411 
412 void
414 put_poset_class(const char* xclass)
415 {
416  // Preconditions:
417 
419  require(is_jim());
420 
421  // Body:
422 
423  dof_map().put_poset_class(xclass);
424 
425  // Postconditions:
426 
427  ensure(poset_class() == xclass);
428 
429  // Exit
430 
431  return;
432 }
433 
434 void
437 {
438  // Preconditions:
439 
441  require(is_jim());
442  require((0 <= xi) && (xi < PREREQ_IDS_UB));
443 
444  // Body:
445 
446  dof_map().put_poset_prereq_id(xi, xid);
447 
448  // Postconditions:
449 
450  ensure(poset_prereq_id(xi) == xid);
451 
452  // Exit:
453 
454  return;
455 }
456 
457 void
460 {
461  // Preconditions:
462 
464  require(is_jim());
465 
466  // Body:
467 
468  put_poset_pointer(&xposet);
469  put_poset_type_id(xposet.type_id());
470  put_poset_class(xposet.class_name());
471  for(int i=0; i<PREREQ_IDS_UB; ++i)
472  {
473  put_poset_prereq_id(i, xposet.prereq_id(i));
474  }
475 
476  // Postconditions:
477 
478  ensure(poset_pointer() == &xposet);
479  ensure(poset_type_id() == xposet.type_id());
480  ensure(poset_class() == xposet.class_name());
481 
482  // Exit:
483 
484  return;
485 }
486 
487 // PRIVATE MEMBER FUNCTIONS
488 
489 
490 // ===========================================================
491 // DEGREE OF FREEDOM (DOF) TUPLE FACET
492 // ===========================================================
493 
494 // PUBLIC MEMBER FUNCTIONS
495 
498 dof_map(bool xrequire_write_access)
499 {
500  // Preconditions:
501 
502  require(xrequire_write_access ?
505  require(is_jim(false));
506 
507  // Body:
508 
509  // Invariant ensures dof maps are of type namespace_poset_dof_map.
510 
511  namespace_poset_dof_map& result =
512  reinterpret_cast<namespace_poset_dof_map&>(total_poset_member::dof_map(xrequire_write_access));
513 
514  // Postconditions:
515 
516  // Exit:
517 
518  return result;
519 }
520 
523 dof_map(bool xrequire_write_access) const
524 {
525  // Preconditions:
526 
527  require(xrequire_write_access ?
530  require(is_jim(false));
531 
532  // Body:
533 
534  // Invariant ensures dof maps are of type namespace_poset_dof_map.
535 
536  const namespace_poset_dof_map& result =
537  reinterpret_cast<const namespace_poset_dof_map&>(total_poset_member::dof_map(xrequire_write_access));
538 
539  // Postconditions:
540 
541  // Exit:
542 
543  return result;
544 }
545 
546 bool
548 dof_map_is_ancestor_of(const poset_dof_map* xdof_map) const
549 {
550  bool result;
551 
552  // Preconditions:
553 
554  require(xdof_map != 0);
555 
556  // Body:
557 
558  result = dynamic_cast<const namespace_poset_dof_map*>(xdof_map) != 0;
559 
560  // Postconditions:
561 
562  // Exit
563 
564  return result;
565 }
566 
567 // PROTECTED MEMBER FUNCTIONS
568 
569 // PRIVATE MEMBER FUNCTIONS
570 
571 
572 // ===========================================================
573 // HOST POSET FACET
574 // ===========================================================
575 
576 // PUBLIC MEMBER FUNCTIONS
577 
580 host() const
581 {
582  namespace_poset* result;
583 
584  // Preconditions:
585 
586  // Body:
587 
588  result = dynamic_cast<namespace_poset*>(_host);
589 
590  // Postconditions:
591 
592  ensure( (_host != 0) == (result != 0) );
593 
594  // Exit
595 
596  return result;
597 }
598 
599 bool
602 {
603  bool result;
604 
605  // Preconditions:
606 
607  // Body:
608 
609  result = (dynamic_cast<const namespace_poset*>(xother) != 0);
610 
611  // Postconditions:
612 
613  ensure(result == (dynamic_cast<const namespace_poset*>(xother) != 0));
614 
615  // Exit
616 
617  return result;
618 }
619 
620 // PROTECTED MEMBER FUNCTIONS
621 
622 // PRIVATE MEMBER FUNCTIONS
623 
624 
625 // ===========================================================
626 // ANY FACET
627 // ===========================================================
628 
629 // PUBLIC MEMBER FUNCTIONS
630 
631 bool
633 is_ancestor_of(const any* xother) const
634 {
635  bool result;
636 
637  // Preconditions:
638 
639  // Body:
640 
641  result = dynamic_cast<const namespace_poset_member*>(xother) != 0;
642 
643  // Postconditions:
644 
645  // Exit
646 
647  return result;
648 }
649 
652 clone() const
653 {
654  // Preconditions:
655 
656  // Body:
657 
658  // create new handle of the current class.
659 
661 
662  // Postconditions:
663 
664  ensure(result != 0);
665  ensure(result->invariant());
666 
667  // Exit:
668 
669  return result;
670 }
671 
672 bool
674 invariant() const
675 {
676  bool result = true;
677 
678  // Preconditions:
679 
680  // Body:
681 
682  // Must satisfy base class invariant
683 
684  result = result && total_poset_member::invariant();
685 
686  if(invariant_check())
687  {
688  // Prevent recursive calls to invariant
689 
691 
692  // Invariants for this class:
693 
694  // Dof map is of type primitives_poset_dof_map
695  result = result &&
696  (is_attached() && is_jim() ?
697  (dynamic_cast<const namespace_poset_dof_map*>(&total_poset_member::dof_map()) !=0) :
698  true);
699 
702 
703  // Finished, turn invariant checking back on.
704 
706  }
707 
708  // Postconditions:
709 
710  // Exit
711 
712  return result;
713 }
714 
715 // PROTECTED MEMBER FUNCTIONS
716 
717 // PRIVATE MEMBER FUNCTIONS
718 
719 
720 // ===========================================================
721 // NON-MEMBER FUNCTIONS FACET
722 // ===========================================================
723 
virtual bool invariant() const
Class invariant.
const char * poset_class() const
The class of the poset associated with this namespace member.
virtual bool is_jim(bool xin_current_version=true) const
True if this member is join irreducible in the current version of the host (xin_current_version == tr...
virtual bool invariant() const
Class invariant.
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.
const scoped_index & index() const
The member index of this poset within the namespace host()
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...
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
poset_type poset_type_id() const
The type id of the poset associated with this namespace member.
poset_state_handle * _host
The host poset for this component.
A client handle for a general, abstract partially order set.
A three state "bool". Does not provide the operations of ternary logic and is intended for use mostly...
Definition: tern.h:45
void put_poset_type_id(poset_type xtype_id)
Set the type id of the poset associated with this namespace member to xtype_id.
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.
poset_state_handle * poset_pointer() const
The pointer to the poset associated with this namespace member.
virtual namespace_poset_dof_map & dof_map(bool xrequire_write_access=false)
The map from client_ids to dof values for this poset member (mutable version)
const scoped_index & index() const
The index of the component state this handle is attached to.
virtual ~namespace_poset_member()
Destructor; deletes a poset member and its attached state, if any.
std::string name() const
A name for this.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
int poset_prereq_id(int xi) const
The id of the xi-th prerequisite poset for the poset associated with this namespace member...
void put_poset_class(const char *xclass)
Set the class of the poset associated with this namespace member to xclass.
A client handle for a member of a namespace poset.
virtual poset_type type_id() const
Identifier for the type of this poset.
void put_poset_class(const char *xclass)
Set the class of the poset associated with this namespace member to xclass.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
void put_poset_pointer(const poset_state_handle *xposet)
Set the pointer to the poset associated with this namespace member to xposet.
pod_index_type poset_prereq_id(int xi) const
The id of the xi-th prerequisite poset for the poset associated with this namespace member...
const char * poset_class() const
The class of the poset associated with this namespace member.
bool is_external() const
True if this has a corresponding member in a name space, but is not yet attached to a state...
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...
void put_poset_prereq_id(int xi, int xid)
Set the id of the xi-th prerequisite poset for the poset associated with this namespace member...
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.
poset_state_handle * poset_pointer() const
The pointer to the poset associated with this namespace member.
virtual bool host_is_ancestor_of(const poset_state_handle *xther) const
True if xother conforms to host.
namespace_poset_member()
Default constructor; creates a new, unattached namespace_poset_member handle.
virtual const char * class_name() const
The name of this class.
void put_poset(const poset_state_handle &xposet)
Sets the poset_pointer, poset_type_id, and poset_class to the corresponding values of xposet...
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. ...
void put_poset_type_id(poset_type xtype_id)
Set the type id of the poset associated with this namespace member to xtype_id.
virtual namespace_poset_member * clone() const
Make a new handle, no state instance of current.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
namespace_poset * name_space() const
The namespace this poset resides in.
virtual bool is_attached() const
True if this is attached to a state.
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...
void put_poset_prereq_id(int xi, pod_index_type xid)
Sets the xi-th poset_prereq_ids to xid.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
poset_type poset_type_id() const
The type id of the poset associated with this namespace member.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
namespace_poset * host() const
The name space poset this is a member of.
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.
A map from schema poset member ids to dof values for namespace_poset members.
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 namespace_poset_member & operator=(const abstract_poset_member &xother)
Assignment operator; attaches this to the same state as xother.
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 ...
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
void put_poset_pointer(const poset_state_handle *xposet)
Set the pointer to the poset associated with this namespace member to xposet.
bool poset_is_external() const
True if the poset associated with this member is external.
virtual void new_jrm_state(bool xauto_access=true)
Creates a new jrm (join-reducible member) state in host() and attaches this to it.
const int PREREQ_IDS_UB
Number of prerequisites ids. Must be consistent with PREREQ_ID_*_INDEX below.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710