SheafSystem  0.0.0.0
binary_section_dof_iterator.cc
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 
18 // Implementation for class binary_section_dof_iterator
19 
20 #include "SheafSystem/binary_section_dof_iterator.h"
21 
22 #include "SheafSystem/binary_section_space_schema_member.h"
23 #include "SheafSystem/binary_section_space_schema_poset.h"
24 #include "SheafSystem/poset_state_handle.h"
25 #include "SheafSystem/assert_contract.h"
26 #include "SheafSystem/discretization_iterator.h"
27 
28 using namespace fiber_bundle; // Workaround for MS C++ bug.
29 
34 {
35 
36  // Preconditions:
37 
38 
39  // Body:
40 
41  // Postconditions:
42 
43  ensure(invariant());
44  ensure(!is_initialized());
45 
46  // Exit
47 
48  return;
49 }
50 
51 
55  : section_dof_iterator(xother)
56 {
57 
58  // Preconditions:
59 
60  // Body:
61 
62  // Nothing to do.
63 
64  // Postconditions:
65 
66  ensure(invariant());
67  ensure(is_initialized() == xother.is_initialized());
68  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
69  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
70  ensure(unexecutable(this is first member of iteration or is_done()));
71 
72  // Exit
73 
74  return;
75 }
76 
81 {
82 
83  // Preconditions:
84 
85  require(is_ancestor_of(&xother));
86 
87  // Body:
88 
89  (void) section_dof_iterator::operator=(xother);
90 
91  // Postconditions:
92 
93  ensure(invariant());
94  ensure(is_initialized() == xother.is_initialized());
95  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
96  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
97  ensure(unexecutable(this is first member of iteration or is_done()));
98  // Exit
99 
100  return *this;
101 }
102 
107 {
108 
109  // Preconditions:
110 
111  require(is_ancestor_of(&xother));
112 
113  // Body:
114 
115  not_implemented();
116 
117  // Postconditions:
118 
119  ensure(invariant());
120 
121  // Exit:
122 
123  return *this;
124 }
125 
126 
130 {
131 
132  // Preconditions:
133 
134  // Body:
135 
136  // Nothing to do - base class does it all.
137 
138  // Postconditions:
139 
140  // Exit:
141 
142  return;
143 }
144 
146 bool
148 is_ancestor_of(const any* xother) const
149 {
150  bool result;
151 
152  // Preconditions:
153 
154  // Body:
155 
156  result = dynamic_cast<const binary_section_dof_iterator*>(xother) != 0;
157 
158  // Postconditions:
159 
160  // Exit
161 
162  return result;
163 }
164 
168 clone() const
169 {
171 
172  // Preconditions:
173 
174  // Body:
175 
176  result = new binary_section_dof_iterator;
177 
178  // Postconditions:
179 
180  ensure(result != 0);
181 
182  // Exit
183 
184  return result;
185 }
186 
188 bool
190 invariant() const
191 {
192  bool result = true;
193 
194  // Preconditions:
195 
196  // Body:
197 
198  result = result && section_dof_iterator::invariant();
199 
200  if(invariant_check())
201  {
203 
204  invariance(dynamic_cast<binary_section_space_schema_member*>(_anchor) != 0);
205 
206  // Finished, turn invariant checking back on.
207 
209  }
210 
211  // Postconditions:
212 
213  // Exit
214 
215  return result;
216 }
217 
221  bool xis_table_dof,
222  int xversion)
224 {
225 
226  // Preconditions:
227 
228  require(item_is_ancestor_of(xanchor));
229  require(xanchor.state_is_read_accessible());
230  require(xanchor.host()->is_schematized(false));
231  require(xanchor.has_version(xversion));
232 
233 
234  // Body:
235 
236  initialize(xanchor, xis_table_dof, xversion);
237 
238  // Postconditions:
239 
240  ensure(invariant());
241  ensure(is_initialized());
242  ensure(anchor().is_same_state(&xanchor));
243  ensure(anchor().is_same_type(&xanchor));
244  ensure(anchor().version() == xanchor.unaliased_version(xversion));
245  ensure(unexecutable(!is_done() implies this is first member));
246  ensure(item().is_attached() == !is_done());
247 
248  return;
249 }
250 
251 
252 // ITERATOR FACET
253 
258 {
259  // Preconditions:
260 
261  require(is_initialized());
262 
263  // Body:
264 
265  // Invariant ensures cast is appropriate.
266 
268  reinterpret_cast<binary_section_space_schema_member&>(*_anchor);
269 
270  // Postconditions:
271 
272  // Exit
273 
274  return result;
275 }
276 
280 anchor() const
281 {
282  // Preconditions:
283 
284  require(is_initialized());
285 
286  // Body:
287 
288  // Invariant ensures cast is appropriate.
289 
291  reinterpret_cast<binary_section_space_schema_member&>(*_anchor);
292 
293  // Postconditions:
294 
295  // Exit
296 
297  return result;
298 }
299 
300 // MEMBER ITERATOR FACET
301 
306 {
307  // Preconditions:
308 
309  require(is_initialized());
310 
311  // Body:
312 
314  reinterpret_cast<binary_section_space_schema_member&>(*_item);
315 
316  // Postconditions:
317 
318  // Exit
319 
320  return result;
321 }
322 
326 item() const
327 {
328  // Preconditions:
329 
330  require(is_initialized());
331 
332  // Body:
333 
335  reinterpret_cast<binary_section_space_schema_member&>(*_item);
336 
337  // Postconditions:
338 
339  // Exit
340 
341  return result;
342 }
343 
344 
346 bool
349 {
350  bool result;
351 
352  // Preconditions:
353 
354  // Body:
355 
356  // Always true in this class;
357  // intended to be redefined in descendants.
358 
359  result = dynamic_cast<const binary_section_space_schema_member*>(&xmbr) != 0;
360 
361  // Postconditions:
362 
363  // Exit
364 
365  return result;
366 }
367 
368 
369 // PROTECTED MEMBER FUNCTIONS
370 
371 
373 void
376 {
377  // Preconditions:
378 
379  // Body:
380 
381  if(_item == 0)
382  {
383  // Create the item handle.
384 
386  }
387 
388  assertion(is_initialized());
389 
390  // Attach the handle.
391 
392  update_item();
393 
394  // Postconditions:
395 
396  ensure(is_initialized());
397  ensure(!is_done() == item().is_attached());
398 
399  // Exit
400 
401  return;
402 }
403 
405 void
408 {
409  // Preconditions:
410 
411  require(is_initialized());
412 
413  // Body:
414 
416  {
418  }
419  else
420  {
424 
426  }
427 
428  // Postconditions:
429 
430  ensure(!is_done() == item().is_attached());
431 
432  // Exit
433 
434  return;
435 }
436 
438 void
441  bool xis_table_dof,
442  int xversion)
443 {
444 
445  // Preconditions:
446 
447  require(item_is_ancestor_of(xanchor));
448  require(xanchor.state_is_read_accessible());
449  require(xanchor.host()->is_schematized(false));
450  require(xanchor.has_version(xversion));
451 
452 
453  // Body:
454 
455  // Initialize the discretization iterator.
456 
457  _is_table_dof = xis_table_dof;
458  if(_is_table_dof)
459  {
460  // Iterating over table dofs.
461  // Table dofs are {base.bottom()} x {fiber schema table dofs}.
462  // Bottom is in every version, so it doesn't matter what version.
463 
465  }
466  else
467  {
469  }
470 
471  // Set the anchor
472 
473  put_anchor(&xanchor, xversion);
474 
475  // Reset the iterator.
476 
477  reset();
478 
479  // Postconditions:
480 
481  ensure(invariant());
482  ensure(is_initialized());
483  ensure(anchor().is_same_state(&xanchor));
484  ensure(anchor().is_same_type(&xanchor));
485  ensure(anchor().version() == xanchor.unaliased_version(xversion));
486  ensure(unexecutable(!is_done() implies this is first member));
487  ensure(item().is_attached() == !is_done());
488 
489  return;
490 }
491 
492 
virtual void reset_item()
Creates item if needed and attaches it to the current index. Abstract in this class; intended to be r...
int unaliased_version(int xversion) const
The actual version associated with (possibly aliased) version xversion in this.
Iterates in postorder over dofs of a schema member anchor. Attaches an a handle of type section_space...
A client handle for a poset member which has been prepared for use as a schema for a section space...
binary_section_space_schema_poset * host() const
The poset which this is a handle to a component of.
virtual bool invariant() const
The class invariant.
virtual binary_section_dof_iterator & operator=(const poset_dof_iterator &xother)
Assignment operator.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
binary_section_space_schema_member & anchor()
The schema member whose downset is being iterated over; the top member of the domain of iteration (mu...
schema_poset_member & item()
The current member of the iteration (mutable version).
virtual bool is_schematized(bool xauto_access) const
True if this poset has been prepared for use as a schema, that is, if the top member has been schemat...
virtual bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
Iterates in postorder over dofs of a schema member anchor. Attaches an a handle of type section_space...
virtual void reset(bool xreset_markers=RESET)
Restarts the iteration over the down set of anchor() If xreset_markers, set !has_visited for all memb...
virtual bool item_is_ancestor_of(const schema_poset_member &xmbr) const
True if xmbr conforms to the type of item of this.
Dperecated. Use postorder_itr. Specialization of the filtered depth-first iterator which exposes the ...
virtual void attach_to_state(pod_index_type xbase_space_id, pod_index_type xfiber_schema_id)
Attach to the state in host() with component ids xbase_id and xfiber_schema_id.
virtual void put_anchor(const schema_poset_member *xanchor, int xversion)
Set anchor() to xversion of *xanchor.
Abstract base class with useful features for all objects.
Definition: any.h:39
binary_section_dof_iterator()
Default constructor; creates an unattached iterator. Protected because this class is abstract...
virtual binary_section_dof_iterator * clone() const
Make a new instance of the same type as this.
virtual bool is_done() const
True if iteration finished.
binary_section_space_schema_member & item()
The the current member of the iteration (mutable version).
Iterator over the discretization subposet associated with a section_space_schema_member anchor...
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
bool is_done() const
True if iteration finished.
virtual void update_item()
Attaches the item handle to the current index, or detaches the item handle if is_done.
schema_poset_member & anchor()
The schema member whose downset is being iterated over; the top member of the domain of iteration (mu...
virtual bool invariant() const
The class invariant.
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
Iterates in postorder over dofs of a schema member anchor. Attaches a handle of type schema_poset_mem...
postorder_iterator _itr
The index iterator used to implement the iteration.
bool _is_table_dof
True if iterating over table dofs.
schema_poset_member * _anchor
The schema member whose downset is being iterated over; the top member of the domain of iteration...
depth_first_iterator * _discretization_itr
The discretization iterator.
void initialize(const binary_section_space_schema_member &xanchor, bool xis_table_dof, int xversion)
Initializes the iteration.
schema_poset_member * _item
The member handle for the current item in the iteration.
Namespace for the fiber_bundles component of the sheaf system.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
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.
bool has_version(int xversion) const
True if xversion is a valid version for this.
const scoped_index & index() const
The index of the current member of the iteration.