SheafSystem  0.0.0.0
product_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 product_section_dof_iterator
19 
20 #include "SheafSystem/product_section_dof_iterator.h"
21 
22 #include "SheafSystem/product_section_space_schema_member.h"
23 #include "SheafSystem/product_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 
33 {
34  // Preconditions:
35 
36  // Body:
37 
38  // Postconditions:
39 
40  ensure(invariant());
41  ensure(!is_initialized());
42 
43  // Exit
44 
45  return;
46 }
47 
50  : section_dof_iterator(xother)
51 {
52  // Preconditions:
53 
54  // Body:
55 
56  // Nothing to do.
57 
58  // Postconditions:
59 
60  ensure(invariant());
61  ensure(is_initialized() == xother.is_initialized());
62  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
63  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
64  ensure(unexecutable(this is first member of iteration or is_done()));
65 
66  // Exit
67 
68  return;
69 }
70 
74 {
75 
76  // Preconditions:
77 
78  require(is_ancestor_of(&xother));
79 
80  // Body:
81 
82  (void) section_dof_iterator::operator=(xother);
83 
84  // Postconditions:
85 
86  ensure(invariant());
87  ensure(is_initialized() == xother.is_initialized());
88  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
89  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
90  ensure(unexecutable(this is first member of iteration or is_done()));
91  // Exit
92 
93  return *this;
94 }
95 
99 {
100 
101  // Preconditions:
102 
103  require(is_ancestor_of(&xother));
104 
105  // Body:
106 
107  not_implemented();
108 
109  // Postconditions:
110 
111  ensure(invariant());
112 
113  // Exit:
114 
115  return *this;
116 }
117 
120 {
121  // Preconditions:
122 
123  // Body:
124 
125  // Nothing to do - base class does it all.
126 
127  // Postconditions:
128 
129  // Exit:
130 
131  return;
132 }
133 
134 bool
136 is_ancestor_of(const any* xother) const
137 {
138  bool result;
139 
140  // Preconditions:
141 
142  // Body:
143 
144  result = dynamic_cast<const product_section_dof_iterator*>(xother) != 0;
145 
146  // Postconditions:
147 
148  // Exit
149 
150  return result;
151 }
152 
155 clone() const
156 {
158 
159  // Preconditions:
160 
161  // Body:
162 
163  result = new product_section_dof_iterator;
164 
165  // Postconditions:
166 
167  ensure(result != 0);
168 
169  // Exit
170 
171  return result;
172 }
173 
174 bool
176 invariant() const
177 {
178  bool result = true;
179 
180  // Preconditions:
181 
182  // Body:
183 
184  result = result && section_dof_iterator::invariant();
185 
186  if(invariant_check())
187  {
189 
190  invariance(dynamic_cast<product_section_space_schema_member*>(_anchor) != 0);
191 
192  // Finished, turn invariant checking back on.
193 
195  }
196 
197  // Postconditions:
198 
199  // Exit
200 
201  return result;
202 }
203 
206  bool xis_table_dof,
207  int xversion)
208 {
209 
210  // Preconditions:
211 
212  require(item_is_ancestor_of(xanchor));
213  require(xanchor.state_is_read_accessible());
214  require(xanchor.host()->is_schematized(false));
215  require(xanchor.has_version(xversion));
216 
217  // Body:
218 
219  _anchor = 0;
220  _item = 0;
221  _is_table_dof = xis_table_dof;
222  put_anchor(&xanchor, xversion);
223  reset();
224 
225  // Postconditions:
226 
227  ensure(invariant());
228  ensure(is_initialized());
229  ensure(anchor().is_same_state(&xanchor));
230  ensure(anchor().is_same_type(&xanchor));
231  ensure(anchor().version() == xanchor.unaliased_version(xversion));
232  ensure(unexecutable(!is_done() implies this is first member));
233  ensure(item().is_attached() == !is_done());
234 
235  return;
236 }
237 
238 
239 // ITERATOR FACET
240 
244 {
245  // Preconditions:
246 
247  require(is_initialized());
248 
249  // Body:
250 
251  // Invariant ensures cast is appropriate.
252 
254  reinterpret_cast<product_section_space_schema_member&>(*_anchor);
255 
256  // Postconditions:
257 
258  // Exit:
259 
260  return result;
261 }
262 
265 anchor() const
266 {
267  // Preconditions:
268 
269  require(is_initialized());
270 
271  // Body:
272 
273  // Invariant ensures cast is appropriate.
274 
276  reinterpret_cast<product_section_space_schema_member&>(*_anchor);
277 
278  // Postconditions:
279 
280  // Exit:
281 
282  return result;
283 }
284 
285 // MEMBER ITERATOR FACET
286 
290 {
291  // Preconditions:
292 
293  require(is_initialized());
294 
295  // Body:
296 
298  reinterpret_cast<product_section_space_schema_member&>(*_item);
299 
300  // Postconditions:
301 
302  // Exit
303 
304  return result;
305 }
306 
309 item() const
310 {
311  // Preconditions:
312 
313  require(is_initialized());
314 
315  // Body:
316 
318  reinterpret_cast<product_section_space_schema_member&>(*_item);
319 
320  // Postconditions:
321 
322  // Exit
323 
324  return result;
325 }
326 
327 bool
330 {
331  bool result;
332 
333  // Preconditions:
334 
335  // Body:
336 
337  // Always true in this class;
338  // intended to be redefined in descendants.
339 
340  result = dynamic_cast<const product_section_space_schema_member*>(&xmbr) != 0;
341 
342  // Postconditions:
343 
344  // Exit
345 
346  return result;
347 }
348 
349 // PROTECTED MEMBER FUNCTIONS
350 
351 void
354 {
355  // Preconditions:
356 
357  // Body:
358 
359  if(_item == 0)
360  {
361  // Create the item handle.
362 
364  }
365 
366  assertion(is_initialized());
367 
368  // Attach the handle.
369 
370  update_item();
371 
372  // Postconditions:
373 
374  ensure(is_initialized());
375  ensure(!is_done() == item().is_attached());
376 
377  // Exit
378 
379  return;
380 }
int unaliased_version(int xversion) const
The actual version associated with (possibly aliased) version xversion in this.
virtual bool invariant() const
The class invariant.
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_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 product_section_dof_iterator & operator=(const poset_dof_iterator &xother)
Assignment operator.
virtual bool invariant() const
The class invariant.
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
virtual bool is_done() const
True if iteration finished.
virtual bool item_is_ancestor_of(const schema_poset_member &xmbr) const
True if xmbr conforms to the type of item of this.
Iterates in postorder over dofs of a schema member anchor. Attaches an a handle of type section_space...
product_section_dof_iterator()
Default constructor; creates an unattached iterator. Protected because this class is abstract...
product_section_space_schema_member & anchor()
The schema member whose downset is being iterated over; the top member of the domain of iteration (mu...
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual product_section_dof_iterator * clone() const
Make a new instance of the same type as this.
virtual bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
virtual void update_item()=0
Attaches the item handle to the current index, or detaches the item handle if is_done.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
schema_poset_member & anchor()
The schema member whose downset is being iterated over; the top member of the domain of iteration (mu...
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...
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...
virtual void reset_item()
Creates item if needed and attaches it to the current index. Abstract in this class; intended to be r...
product_section_space_schema_member & item()
The the current member of the iteration (mutable version).
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.
product_section_space_schema_poset * host() const
The poset which this is a handle to a component of.
bool has_version(int xversion) const
True if xversion is a valid version for this.
A client handle for a poset member which has been prepared for use as a schema for a section space...