SheafSystem  0.0.0.0
total_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/total_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_state.h"
31 #include "SheafSystem/poset_state_handle.h"
32 #include "SheafSystem/primitives_poset.h"
33 #include "SheafSystem/primitives_poset_schema.h"
34 #include "SheafSystem/subposet.h"
35 #include "SheafSystem/poset_member_iterator.h"
36 #include "SheafSystem/subposet_state.h"
37 #include "SheafSystem/zn_to_bool.h"
38 
39 // ===========================================================
40 // TOTAL_POSET_MEMBER FACET
41 // ===========================================================
42 
43 // PUBLIC MEMBER FUNCTIONS
44 
47 {
48  // Preconditions:
49 
50  // Body:
51 
52  // Postconditions:
53 
54  ensure(invariant());
55  ensure(!is_attached());
56 }
57 
59 total_poset_member(const abstract_poset_member& xother, bool xnew_jem)
60 {
61  // Preconditions:
62 
63  require(xnew_jem ? xother.is_attached() : true);
64 
65  // Body:
66 
67  if(xnew_jem)
68  {
69  new_jem_state(const_cast<abstract_poset_member*>(&xother), true, true);
70  }
71  else
72  {
73  attach_to_state(&xother);
74  }
75 
76  // Postconditions:
77 
78  ensure(invariant());
79  ensure(is_attached() == xother.is_attached() );
80 }
81 
85 {
86  // Preconditions:
87 
88  // Body:
89 
90  attach_to_state(&xother);
91 
92  // Postconditions:
93 
94  ensure(is_same_state(&xother));
95 
96  // Exit
97 
98  return *this;
99 }
100 
104 {
105  // Preconditions:
106 
107  require(precondition_of(attach_to_state(&xother)));
108 
109  // Body:
110 
111  attach_to_state(&xother);
112 
113  // Postconditions:
114 
115  ensure(postcondition_of(attach_to_state(&xother)));
116 
117  // Exit:
118 
119  return *this;
120 }
121 
124 {
125  // Preconditions:
126 
127  // Body:
128 
129  // Postconditions:
130 
131  // Exit
132 
133  return;
134 }
135 
136 // NEW HANDLE, NEW STATE CONSTRUCTORS
137 
140  poset_dof_map* xdof_map,
141  bool xcopy_dof_map,
142  bool xauto_access)
143 {
144  // Preconditions:
145 
146  require(precondition_of(new_jim_state(same args)));
147 
148  // Body:
149 
150  new_jim_state(xhost, xdof_map, xcopy_dof_map, xauto_access);
151 
152  // Postconditions:
153 
154  ensure(postcondition_of(new_jim_state(same args)));
155 
156 }
157 
160  const scoped_index* xexpansion,
161  int xexpansion_ct,
162  const tern& xnew_jem,
163  bool xauto_access)
164 {
165 
166  // Preconditions:
167 
168  require(precondition_of(new_jrm_state(same args)));
169 
170  // Body:
171 
172  new_jrm_state(xhost, xexpansion, xexpansion_ct, xnew_jem, xauto_access);
173 
174  // Postconditions:
175 
176  ensure(postcondition_of(new_jrm_state(same args)));
177 
178 }
179 
180 // NEW HANDLE, EXISTING STATE CONSTRUCTORS
181 
184 {
185 
186  // Preconditions:
187 
188  require(xhost->state_is_read_accessible());
189  require(xhost->contains_member(xhub_id, false));
190 
191  // Body:
192 
193  attach_to_state(xhost, xhub_id);
194 
195  // Postconditions:
196 
197  ensure(invariant());
198  ensure(host() == xhost);
199  ensure(index() == xhub_id);
200  ensure(is_attached());
201 }
202 
205 {
206 
207  // Preconditions:
208 
209  require(xhost->state_is_read_accessible());
210  require(xhost->contains_member(xid, false));
211 
212  // Body:
213 
214  attach_to_state(xhost, xid.hub_pod());
215 
216  // Postconditions:
217 
218  ensure(invariant());
219  ensure(host() == xhost);
220  ensure(index() ==~ xid);
221  ensure(is_attached());
222 }
223 
225 total_poset_member(const poset_state_handle* xhost, const std::string& xname)
226 {
227 
228  // Preconditions:
229 
230  require(xhost != 0);
231  require(xhost->state_is_read_accessible());
232  require(!xname.empty());
233  require(xhost->contains_member(xname));
234 
235  // Body:
236 
237  attach_to_state(xhost, xname);
238 
239  // Postconditions:
240 
241  ensure(invariant());
242  ensure(host() == xhost);
243  ensure(name() == xname);
244  ensure(is_attached());
245 }
246 
247 
250  const poset_path& xpath,
251  bool xauto_access)
252 {
253 
254  // Preconditions:
255 
256  require(precondition_of(attach_to_state(same args)));
257 
258  // Body:
259 
260  attach_to_state(xnamespace, xpath, xauto_access);
261 
262  // Postconditions:
263 
264  ensure(postcondition_of(attach_to_state(same args)));
265 
266  // Exit:
267 
268  return;
269 }
270 
271 // PROTECTED MEMBER FUNCTIONS
272 
273 // PRIVATE MEMBER FUNCTIONS
274 
275 
276 // ===========================================================
277 // SCHEMA FACET
278 // ===========================================================
279 
280 // PUBLIC MEMBER FUNCTIONS
281 
285 {
286  // Preconditions:
287 
288  require(state_is_read_accessible());
289 
290  // Body:
291 
292  // The defining property of a toal poset member is that
293  // it is never restricted.
294 
296 
297  // Postconditions:
298 
299  ensure(result.is_same_state(&(unrestricted_schema())));
300 
301  // Exit
302 
303  return result;
304 }
305 
308 schema() const
309 {
310  // Preconditions:
311 
312  require(state_is_read_accessible());
313 
314  // Body:
315 
316  // The defining property of a toal poset member is that
317  // it is never restricted.
318 
319  const schema_poset_member& result = unrestricted_schema();
320 
321  // Postconditions:
322 
323  ensure(result.is_same_state(&(unrestricted_schema())));
324 
325  // Exit
326 
327  return result;
328 }
329 
330 // PROTECTED MEMBER FUNCTIONS
331 
332 // PRIVATE MEMBER FUNCTIONS
333 
334 
335 // ===========================================================
336 // RESTRICTION FACET
337 // ===========================================================
338 
339 // PUBLIC MEMBER FUNCTIONS
340 
341 bool
344 {
345  bool result;
346 
347  // Preconditions:
348 
349  // Body:
350 
351  result = false;
352 
353  // Postconditions:
354 
355  ensure(!result);
356 
357  // Exit
358 
359  return result;
360 }
361 
362 // PROTECTED MEMBER FUNCTIONS
363 
364 // PRIVATE MEMBER FUNCTIONS
365 
366 
367 // ===========================================================
368 // DEGREE OF FREEDOM (DOF) TUPLE FACET
369 // ===========================================================
370 
371 // PUBLIC MEMBER FUNCTIONS
372 
373 int
375 dof_ct() const
376 {
377  return schema().row_dof_ct();
378 }
379 
380 // PROTECTED MEMBER FUNCTIONS
381 
382 // PRIVATE MEMBER FUNCTIONS
383 
384 
385 // ===========================================================
386 // ANY FACET
387 // ===========================================================
388 
389 // PUBLIC MEMBER FUNCTIONS
390 
391 bool
393 is_ancestor_of(const any* xother) const
394 {
395  bool result;
396 
397  // Preconditions:
398 
399  // Body:
400 
401  result = dynamic_cast<const total_poset_member*>(xother) != 0;
402 
403  // Postconditions:
404 
405  // Exit
406 
407  return result;
408 }
409 
412 clone() const
413 {
414  // Preconditions:
415 
416  // Body:
417 
418  // create new handle of the current class.
419 
420  total_poset_member *result = new total_poset_member();
421 
422  // Postconditions:
423 
424  ensure(result != 0);
425  ensure(result->invariant());
426 
427  // Exit:
428 
429  return result;
430 }
431 
432 bool
434 invariant() const
435 {
436  bool result = true;
437 
438  // Preconditions:
439 
440  // Body:
441 
442  // Must satisfy base class invariant
443 
444  result = result && abstract_poset_member::invariant();
445 
446  if(invariant_check())
447  {
448  // Prevent recursive calls to invariant
449 
451 
452  // Invariants for this class:
453 
456 
457  // Finished, turn invariant checking back on.
458 
460  }
461 
462  // Postconditions:
463 
464  // Exit
465 
466  return result;
467 }
468 
469 // PROTECTED MEMBER FUNCTIONS
470 
471 // PRIVATE MEMBER FUNCTIONS
472 
473 
474 // ===========================================================
475 // NON-MEMBER FUNCTIONS
476 // ===========================================================
477 
poset_state_handle * host() const
The poset which this is a handle to a component of.
virtual bool invariant() const
Class invariant.
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 total_poset_member * clone() const
Make a new handle, no state instance of current.
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.
total_poset_member()
Default constructor; creates a new, unattached total_poset_member handle.
virtual int dof_ct() const
The number of dofs in the dof tuple for jims of this poset;.
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.
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.
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 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).
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. ...
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
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
virtual ~total_poset_member()
Destructor; deletes a poset member and its attached state, if any.
virtual total_poset_member & operator=(const abstract_poset_member &xother)
Assignment operator; attaches this to the same state as xother.
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.
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 schema_poset_member & schema()
The schema for this member (mutable version).
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.
A client handle for an unrestricted member of a poset. A total_poset_member is guaranteed not to be r...
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710