SheafSystem  0.0.0.0
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 section_dof_iterator
19 
20 #include "SheafSystem/section_dof_iterator.h"
21 
22 #include "SheafSystem/poset_state_handle.h"
23 #include "SheafSystem/section_space_schema_member.h"
24 #include "SheafSystem/section_space_schema_poset.h"
25 #include "SheafSystem/assert_contract.h"
26 #include "SheafSystem/discretization_iterator.h"
27 #include "SheafSystem/postorder_iterator.h"
28 
29 using namespace std;
30 using namespace fiber_bundle; // Workaround for MS C++ bug.
31 
35 {
36 
37  // Preconditions:
38 
39  require(is_ancestor_of(&xother));
40  require(xother.is_done());
41 
42  // Body:
43 
44  poset_dof_iterator::operator=(xother);
45 
46  const section_dof_iterator& cother = reinterpret_cast<const section_dof_iterator&>(xother);
47  section_dof_iterator& lother = const_cast<section_dof_iterator&>(cother);
48 
49  _itr = lother._itr;
50 
51  if(lother.is_initialized())
52  {
53  _discretization_itr = lother._discretization_itr->clone();
54  }
55  else
56  {
57  _discretization_itr = 0;
58  }
59 
60  // Postconditions:
61 
62  ensure(invariant());
63  ensure(is_initialized() == xother.is_initialized());
64  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
65  ensure(is_initialized() ? anchor().version() == xother.anchor().version() : true);
66  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
67  ensure(is_table_dof() == xother.is_table_dof());
68 
69  // Exit
70 
71  return *this;
72 }
73 
77 {
78 
79  // Preconditions:
80 
81  require(is_ancestor_of(&xother));
82 
83  // Body:
84 
85  not_implemented();
86 
87  // Postconditions:
88 
89  ensure(invariant());
90 
91  // Exit:
92 
93  return *this;
94 }
95 
96 
99 {
100 
101  // Preconditions:
102 
103  // Body:
104 
105  // Delete the existing discretization iterator if it exists.
106 
107  if(is_initialized())
108  {
109  delete _discretization_itr;
110  }
111 
112  // Postconditions:
113 
114  // Exit:
115 
116  return;
117 }
118 
119 bool
121 is_ancestor_of(const any* xother) const
122 {
123  bool result;
124 
125  // Preconditions:
126 
127  // Body:
128 
129  result = dynamic_cast<const section_dof_iterator*>(xother) != 0;
130 
131  // Postconditions:
132 
133  // Exit
134 
135  return result;
136 }
137 
138 bool
140 invariant() const
141 {
142  bool result = true;
143 
144  // Preconditions:
145 
146  // Body:
147 
148  invariance( poset_dof_iterator::invariant() );
149 
150  if(invariant_check())
151  {
152  disable_invariant_check();
153 
154  // Finished, turn invariant checking back on.
155 
156  enable_invariant_check();
157  }
158 
159  // Postconditions:
160 
161  // Exit
162 
163  return result;
164 }
165 
166 // ITERATOR FACET
167 
168 bool
171 {
172  bool result;
173 
174  // Preconditions:
175 
176  // Body:
177 
178  result = poset_dof_iterator::is_initialized();
179  result = result && (_discretization_itr != 0);
180  result = result && _discretization_itr->is_initialized();
181 
182  // Postconditions:
183 
184  // Exit
185 
186  return result;
187 }
188 
192 {
193  // Preconditions:
194 
195  require(is_initialized());
196 
197  // Body:
198 
200  reinterpret_cast<section_space_schema_member&>(*_anchor);
201 
202  // Postconditions:
203 
204  // Exit
205 
206  return result;
207 }
208 
211 anchor() const
212 {
213  // Preconditions:
214 
215  require(is_initialized());
216 
217  // Body:
218 
220  reinterpret_cast<section_space_schema_member&>(*_anchor);
221 
222  // Postconditions:
223 
224  // Exit
225 
226  return result;
227 }
228 
229 void
231 put_anchor(const schema_poset_member* xanchor, int xversion)
232 {
233  // Preconditions:
234 
235  require(xanchor != 0);
236  require(item_is_ancestor_of(*xanchor));
237  require(xanchor->state_is_read_accessible());
238  require(xanchor->host()->is_schematized(false));
239  require(xanchor->has_version(xversion));
240 
241 
242  // Body:
243 
244  if(_anchor == 0)
245  {
246  // Create the anchor handle
247 
248  _anchor = xanchor->clone();
249  }
250 
251  // Attach the handle to the same state and
252  // (possibly aliased) version as xanchor.
253 
254  _anchor->attach_to_state(xanchor);
255 
256  // Set the version, making sure it is unaliased.
257 
258  _anchor->put_version(xversion, true);
259 
260  // Get the anchor of appropriate type.
261 
262  section_space_schema_member* lanchor = reinterpret_cast<section_space_schema_member*>(_anchor);
263 
264  // Reset the base component iterator
265 
266  if(_is_table_dof)
267  {
268  // Iterating over table dofs.
269  // Table dofs are {base.bottom()} x {fiber schema table dofs}.
270  // Bottom is in every version, so it doesn't matter what version.
271 
272  postorder_iterator* litr =
273  reinterpret_cast<postorder_iterator*>(_discretization_itr);
274  litr->put_anchor(&(lanchor->host()->base_space().bottom()));
275  }
276  else
277  {
279  reinterpret_cast<discretization_iterator*>(_discretization_itr);
280  litr->put_schema_anchor(*lanchor);
281  }
282 
283  // Reset the index iterator.
284 
285  string ldof_sp_name = schema_poset_member::dof_subposet_name("top", _is_table_dof);
286  _itr.put_anchor(&(lanchor->fiber_schema()));
287  _itr.put_filter(ldof_sp_name);
288 
289  // Reset the item
290 
291  reset_item();
292 
293  // Force the iterator to be done.
294 
295  force_is_done();
296 
297  // Postconditions:
298 
299  ensure(invariant());
300  ensure(is_initialized());
301  ensure(is_done());
302  ensure(anchor().is_same_state(xanchor));
303  ensure(anchor().is_same_type(xanchor));
304  ensure(anchor().version() == xanchor->unaliased_version(xversion));
305 
306  // Exit:
307 
308 }
309 
310 bool
312 is_done() const
313 {
314  bool result;
315 
316  // Preconditions:
317 
318  require(is_initialized());
319 
320  // Body:
321 
322  result = _discretization_itr->is_done();
323 
324  // Postconditions:
325 
326  // Exit
327 
328  return result;
329 }
330 
331 void
334 {
335  // Preconditions:
336 
337  require(is_initialized());
338 
339  // Body:
340 
341  // Virtual redefinition of is_done means
342  // discretization iterator must be shut down first
343  // so that is_done will will true is postcondition
344  // of poset_dof_iterator::force_is_done.
345 
351 
352  _discretization_itr->force_is_done();
353  poset_dof_iterator::force_is_done();
354 
355  // Postconditions:
356 
357  ensure(invariant());
358  ensure(is_done());
359 
360  // Exit:
361 }
362 
363 void
366 {
367 
368  // Preconditions:
369 
370  require(is_initialized());
371  require(!is_done());
372 
373  // Body:
374 
375  _itr.next();
376 
377  if(_itr.is_done())
378  {
379  // Fiber schema is done;
380  // move to next base item.
381 
382  _discretization_itr->next();
383 
384  if(!_discretization_itr->is_done())
385  {
386  // Base iteration is not done;
387  // reset the fiber schema.
388 
389  _itr.reset();
390  }
391  }
392 
393  update_item();
394 
395  // Postconditions:
396 
397  ensure(invariant());
398  ensure(!is_done() == item().is_attached());
399  ensure(unexecutable(postorder - have visited all of the members of the strict down set
400  of item()));
401 
402  // Exit
403 
404  return;
405 }
406 
407 void
409 reset(bool xreset_markers)
410 {
411  // Preconditions:
412 
413  require(is_initialized());
414  require(anchor().state_is_read_accessible());
415 
416  define_old_variable(int old_anchor_version = anchor().version());
417 
418  // Body:
419 
420  _itr.reset(xreset_markers);
421 
422  if(_itr.is_done())
423  {
424  _discretization_itr->force_is_done();
425  }
426  else
427  {
428  _discretization_itr->reset(xreset_markers);
429 
430  if(_discretization_itr->is_done())
431  _itr.force_is_done();
432  }
433 
434  update_item();
435 
436  // Postconditions:
437 
438  ensure(invariant());
439  ensure(is_initialized());
440  ensure(item().is_attached() == !is_done());
441  ensure(anchor().version() == old_anchor_version);
442 
443  // Exit
444 
445  return;
446 }
447 
448 int
450 ct(bool xreset)
451 {
452  int result = 0;
453 
454  // Preconditions:
455 
456  require(is_initialized());
457  require(xreset ? anchor().state_is_read_accessible(): true);
458 
459  // Body:
460 
461  result = _discretization_itr->ct(xreset)*_itr.ct(xreset);
462  update_item();
463 
464  // Postconditions:
465 
466  ensure(result >= 0);
467  ensure(is_done());
468 
469  // Exit
470 
471  return result;
472 }
473 
474 bool
477 {
478  bool result;
479 
480  // Preconditions:
481 
482  require(is_initialized());
483  require(anchor().state_is_read_accessible());
484  require(anchor().host()->contains_member(xhub_id));
485 
486  // Body:
487 
488  result = _discretization_itr->has_visited(anchor().host()->get_base_space_id_from_index(xhub_id)) &&
489  _itr.has_visited(anchor().host()->get_fiber_schema_id_from_index(xhub_id)) ;
490 
491  // Postconditions:
492 
493  // Exit:
494 
495  return result;
496 }
497 
498 bool
501 {
502  bool result;
503 
504  // Preconditions:
505 
506  require(is_initialized());
507  require(anchor().state_is_read_accessible());
508  require(item_is_ancestor_of(xmbr));
509  require(xmbr.is_attached());
510  require(anchor().host()->is_same_state(xmbr.host()));
511 
512  // Body:
513 
514  const section_space_schema_member& lmbr = reinterpret_cast<const section_space_schema_member&>(xmbr);
515 
516  result = _discretization_itr->has_visited(lmbr.base_space_id()) &&
517  _itr.has_visited(lmbr.fiber_schema_id());
518 
519  // Postconditions:
520 
521  // Exit:
522 
523  return result;
524 }
525 
526 void
528 put_has_visited(pod_index_type xhub_id, bool xvalue)
529 {
530 
531  // Preconditions:
532 
533  require(is_initialized());
534  require(anchor().state_is_read_accessible());
535  require(anchor().host()->contains_member(xhub_id));
536 
537  // Body:
538 
539  _discretization_itr->put_has_visited(anchor().host()->get_base_space_id_from_index(xhub_id), xvalue);
540  _itr.put_has_visited(anchor().host()->get_fiber_schema_id_from_index(xhub_id), xvalue) ;
541 
542  // Postconditions:
543 
544  ensure(has_visited(xhub_id) == xvalue);
545 
546  // Exit:
547 
548  return;
549 }
550 
551 // MEMBER ITERATOR FACET
552 
556 {
557  // Preconditions:
558 
559  require(is_initialized());
560 
561  // Body:
562 
564  reinterpret_cast<section_space_schema_member&>(*_item);
565 
566  // Postconditions:
567 
568  // Exit
569 
570  return result;
571 }
572 
575 item() const
576 {
577  // Preconditions:
578 
579  require(is_initialized());
580 
581  // Body:
582 
584  reinterpret_cast<section_space_schema_member&>(*_item);
585 
586  // Postconditions:
587 
588  // Exit
589 
590  return result;
591 }
592 
593 bool
596 {
597  bool result;
598 
599  // Preconditions:
600 
601  // Body:
602 
603  // Always true in this class;
604  // intended to be redefined in descendants.
605 
606  result = dynamic_cast<const section_space_schema_member*>(&xmbr) != 0;
607 
608  // Postconditions:
609 
610  // Exit
611 
612  return result;
613 }
614 
615 // PROTECTED MEMBER FUNCTIONS
616 
620 {
621 
622  // Preconditions:
623 
624 
625  // Body:
626 
628 
629  // Postconditions:
630 
631  ensure(invariant());
632  ensure(!is_initialized());
633 
634  // Exit
635 
636  return;
637 }
638 
641  : poset_dof_iterator(xother)
642 {
643 
644  // Preconditions:
645 
646  // Body:
647 
648  section_dof_iterator& lother = const_cast<section_dof_iterator&>(xother);
649 
650  _itr = lother._itr;
651 
652  if(lother.is_initialized())
653  {
655  }
656  else
657  {
659  }
660 
661  // Postconditions:
662 
663  ensure(invariant());
664  ensure(is_initialized() == xother.is_initialized());
665  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
666  ensure(is_initialized() ? anchor().version() == xother.anchor().version() : true);
667  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
668  ensure(is_table_dof() == xother.is_table_dof());
669  // Exit
670 
671  return;
672 }
673 
poset_state_handle * host() const
The poset which this is a handle to a component of.
virtual bool has_visited(pod_index_type xhub_id) const
True if this has already visited hub id xhub_id.
int unaliased_version(int xversion) const
The actual version associated with (possibly aliased) version xversion in this.
section_space_schema_poset * host() const
The poset which this is a handle to a component of.
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
virtual bool invariant() const
The class invariant.
schema_poset_member & fiber_schema()
The fiber schema component of this (mutable version).
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
schema_poset_member & item()
The current member of the iteration (mutable version).
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...
STL namespace.
void put_schema_anchor(const section_space_schema_member &xschema_anchor)
Set schema_anchor() to the same state as xschema_anchor.
virtual bool is_done() const
True if iteration finished.
section_dof_iterator()
Default constructor; creates an unattached iterator. Protected because this class is abstract...
abstract_poset_member & bottom()
The bottom member of the poset (mutable version)
Dperecated. Use postorder_itr. Specialization of the filtered depth-first iterator which exposes the ...
virtual section_dof_iterator & operator=(const poset_dof_iterator &xother)
Assignment operator.
virtual void put_anchor(const schema_poset_member *xanchor, int xversion)
Set anchor() to xversion of *xanchor.
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 int ct(bool xreset=false)
The number of members of the iteration set, from the current member to the end, inclusive. If xreset, reset before computing the count.
Abstract base class with useful features for all objects.
Definition: any.h:39
pod_index_type fiber_schema_id() const
The member id of the fiber schema component of this.
virtual bool is_attached() const
True if this handle is attached to a non-void state.
virtual bool is_done() const
True if iteration finished.
Iterator over the discretization subposet associated with a section_space_schema_member anchor...
virtual bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
bool is_table_dof() const
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 (mu...
virtual void put_has_visited(pod_index_type xhub_id, bool xvalue)
Set the visisted marker for hub id xhub_id to xvalue. Intended for use reseting iterator without havi...
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...
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.
depth_first_iterator * _discretization_itr
The discretization iterator.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
A client handle for a poset member which has been prepared for use as a schema for a section space...
section_space_schema_member & item()
The current member of the iteration (mutable version).
virtual bool item_is_ancestor_of(const schema_poset_member &xmbr) const
True if xmbr conforms to the type of item of this.
virtual void put_anchor(const abstract_poset_member *xanchor)
Set anchor() to xanchor.
virtual void force_is_done()
Force the iterator to be done.
virtual void next()
Makes this the next member of the subset.
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 depth_first_iterator * clone() const
Make a new instance of the same type as this.
Namespace for the fiber_bundles component of the sheaf system.
section_space_schema_member & anchor()
The schema member whose downset is being iterated over; the top member of the domain of iteration (mu...
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
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.
base_space_poset & base_space()
The base space for section spaces on this schema.
pod_index_type base_space_id() const
The member id of the base space component of this.