SheafSystem  0.0.0.0
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/poset_member.h"
22 #include "SheafSystem/assert_contract.h"
23 
25 
26 #include "SheafSystem/array_poset_dof_map.h"
27 #include "SheafSystem/namespace_poset.h"
28 #include "SheafSystem/pool.h"
29 #include "SheafSystem/poset.h"
30 #include "SheafSystem/poset_crg_state.h"
31 #include "SheafSystem/poset_dof_map.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 // POSET_MEMBER FACET
44 // ===========================================================
45 
46 // PUBLIC MEMBER FUNCTIONS
47 
50 {
51  // Preconditions:
52 
53  // Body:
54 
55  // Nothing to do - base does it all
56 
57  // Postconditions:
58 
59  ensure(invariant());
60  ensure(!is_attached());
61 }
62 
64 poset_member(const abstract_poset_member& xother, bool xnew_jem)
65 {
66  // Preconditions:
67 
68  require(xnew_jem ? xother.is_attached() : true);
69 
70  // Body:
71 
72  if(xnew_jem)
73  {
74  new_jem_state(const_cast<abstract_poset_member*>(&xother), true, true);
75  }
76  else
77  {
78  attach_to_state(&xother);
79  }
80 
81  // Postconditions:
82 
83  ensure(invariant());
84  ensure(is_attached() == xother.is_attached() );
85 }
86 
90 {
91  // Preconditions:
92 
93  // Body:
94 
95  attach_to_state(&xother);
96 
97  // Postconditions:
98 
99  ensure(is_same_state(&xother));
100 
101  // Exit
102 
103  return *this;
104 }
105 
108 operator=(const poset_member& xother)
109 {
110  // Preconditions:
111 
112  require(precondition_of(attach_to_state(&xother)));
113 
114  // Body:
115 
116  attach_to_state(&xother);
117 
118  // Postconditions:
119 
120  ensure(postcondition_of(attach_to_state(&xother)));
121 
122  // Exit:
123 
124  return *this;
125 }
126 
129 {
130  // Preconditions:
131 
132  // Body:
133 
134  // Nothing to do - base does it all
135 
136  // Postconditions:
137 
138  // Exit
139 
140  return;
141 }
142 
143 // NEW HANDLE, NEW STATE CONSTRUCTORS
144 
147  poset_dof_map* xdof_map,
148  bool xcopy_dof_map,
149  bool xauto_access)
150 {
151  // Preconditions:
152 
153  require(precondition_of(new_jim_state(same args)));
154 
155  // Body:
156 
157  new_jim_state(xhost, xdof_map, xcopy_dof_map, xauto_access);
158 
159  // Postconditions:
160 
161  ensure(invariant());
162  ensure(postcondition_of(new_jim_state(same args)));
163 }
164 
167  const scoped_index* xexpansion,
168  int xexpansion_ct,
169  const tern& xnew_jem,
170  bool xauto_access)
171 {
172  // Preconditions:
173 
174  require(precondition_of(new_jrm_state(same args)));
175 
176  // Body:
177 
178  new_jrm_state(xhost, xexpansion, xexpansion_ct, xnew_jem, xauto_access);
179 
180  // Postconditions:
181 
182  ensure(invariant());
183  ensure(postcondition_of(new_jrm_state(same args)));
184 
185 }
186 
187 // NEW HANDLE, EXISTING STATE CONSTRUCTORS
188 
191 {
192  // Preconditions:
193 
194  require(xhost->state_is_read_accessible());
195  require(xhost->contains_member(xhub_id));
196 
197  // Body:
198 
199  attach_to_state(xhost, xhub_id);
200 
201  // Postconditions:
202 
203  ensure(invariant());
204  ensure(host() == xhost);
205  ensure(index() == xhub_id);
206  ensure(is_attached());
207 }
208 
211 {
212  // Preconditions:
213 
214  require(xhost->state_is_read_accessible());
215  require(xhost->contains_member(xid));
216 
217  // Body:
218 
219  attach_to_state(xhost, xid);
220 
221  // Postconditions:
222 
223  ensure(invariant());
224  ensure(host() == xhost);
225  ensure(index() ==~ xid);
226  ensure(is_attached());
227 }
228 
230 poset_member(const poset_state_handle* xhost, const std::string& xname)
231 {
232 
233  // Preconditions:
234 
235  require(xhost != 0);
236  require(xhost->state_is_read_accessible());
237  require(!xname.empty());
238  require(xhost->contains_member(xname));
239 
240  // Body:
241 
242  attach_to_state(xhost, xname);
243 
244  // Postconditions:
245 
246  ensure(invariant());
247  ensure(host() == xhost);
248  ensure(name() == xname);
249  ensure(is_attached());
250 }
251 
253 poset_member(const namespace_poset* xnamespace,
254  const poset_path& xpath,
255  bool xauto_access)
256 {
257 
258  // Preconditions:
259 
260  require(precondition_of(attach_to_state(same args)));
261 
262  // Body:
263 
264  attach_to_state(xnamespace, xpath, xauto_access);
265 
266  // Postconditions:
267 
268  ensure(postcondition_of(attach_to_state(same args)));
269 
270  // Exit:
271 
272  return;
273 }
274 
275 // PROTECTED MEMBER FUNCTIONS
276 
277 // PRIVATE MEMBER FUNCTIONS
278 
279 
280 // ===========================================================
281 // RESTRICTION FACET
282 // ===========================================================
283 
284 // PUBLIC MEMBER FUNCTIONS
285 
286 void
289 {
290  // Preconditions:
291 
292  require(state_is_read_accessible());
293  require(xschema != 0);
294  require(xschema->state_is_read_accessible());
295  require(schema().is_ancestor_of(xschema));
296  require(xschema->le(&(unrestricted_schema())));
297 
298  // Body:
299 
300  // Redefined only to change access status from protected to public.
301 
303 
304  // Postconditions:
305 
306  ensure(schema().is_same_state(xschema));
307 
308  // Exit
309 
310  return;
311 }
312 
313 void
316 {
317  // Preconditions:
318 
319  require(state_is_read_accessible());
320  require(xother != 0);
321  require(xother->state_is_read_accessible());
322  require(has_same_host(xother));
323  require(xother->unrestricted_schema().le(&(unrestricted_schema())));
324 
325  // Body:
326 
327  // Redefined only to change access status from protected to public.
328 
330 
331  // Postconditions:
332 
333  ensure(is_same_restriction(xother));
334 
335  // Exit
336 
337  return;
338 }
339 
340 void
343 {
344  // Preconditions:
345 
346  require(state_is_read_accessible());
347 
348  // Body:
349 
350  // Redefined only to change access status from protected to public.
351 
353 
354  // Postconditions:
355 
356  ensure(!is_restricted());
357 
358  // Exit
359 
360  return;
361 }
362 
363 // PROTECTED MEMBER FUNCTIONS
364 
365 // PRIVATE MEMBER FUNCTIONS
366 
367 
368 // ===========================================================
369 // ANY FACET
370 // ===========================================================
371 
372 // PUBLIC MEMBER FUNCTIONS
373 
374 bool
376 is_ancestor_of(const any* xother) const
377 {
378  bool result;
379 
380  // Preconditions:
381 
382  // Body:
383 
384  result = dynamic_cast<const poset_member*>(xother) != 0;
385 
386  // Postconditions:
387 
388  // Exit
389 
390  return result;
391 }
392 
395 clone() const
396 {
397  // Preconditions:
398 
399  // Body:
400 
401  // create new handle of the current class.
402 
403  poset_member *result = new poset_member();
404 
405  // Postconditions:
406 
407  ensure(result != 0);
408  ensure(result->invariant());
409 
410  // Exit:
411 
412  return result;
413 
414 }
415 
416 bool
418 invariant() const
419 {
420  bool result = true;
421 
422  // Preconditions:
423 
424  // Body:
425 
426  // Must satisfy base class invariant
427 
428  result = result && partial_poset_member::invariant();
429 
430  if(invariant_check())
431  {
432  // Prevent recursive calls to invariant
433 
435 
436  // Invariants for this class:
437 
438  // Finished, turn invariant checking back on.
439 
441  }
442 
443  // Postconditions:
444 
445  // Exit
446 
447  return result;
448 }
449 
450 // PROTECTED MEMBER FUNCTIONS
451 
452 // PRIVATE MEMBER FUNCTIONS
453 
454 
455 // ===========================================================
456 // NON-MEMBER FUNCTIONS FACET
457 // ===========================================================
458 
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(...
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...
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.
virtual poset_member * clone() const
Make a new handle, no state instance of current.
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
virtual void restrict_to(const abstract_poset_member *xschema)
Restricts this handle to the down set of xschema.
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).
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.
A client handle for a restrictable member of a poset. A poset_member is a poset_member which can ...
Definition: poset_member.h:59
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.
virtual poset_member & operator=(const abstract_poset_member &xother)
Assignment operator; attaches this to the same state as xother.
Definition: poset_member.cc:89
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual ~poset_member()
Destructor; deletes a poset member and its attached 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 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 bool invariant() const
Class invariant.
virtual void unrestrict()
Removes any restriction; schema to the schema of host.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual void restrict_to(const abstract_poset_member *xschema)
Restricts this handle to the down set of xschema.
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 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.
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
poset_member()
Default constructor; creates a new, unattached poset_member handle.
Definition: poset_member.cc:49
virtual void new_jrm_state(bool xauto_access=true)
Creates a new jrm (join-reducible member) state in host() and attaches this to it.