SheafSystem  0.0.0.0
binary_section_component_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 
19 // Implementation for class binary_section_component_iterator
20 
21 #include "SheafSystem/binary_section_component_iterator.h"
22 
23 #include "SheafSystem/binary_section_space_schema_member.h"
24 #include "SheafSystem/poset_state_handle.h"
25 #include "SheafSystem/assert_contract.h"
26 
31 {
32 
33  // Preconditions:
34 
35 
36  // Body:
37 
38  // Postconditions:
39 
40  ensure(invariant());
41  ensure(!is_initialized());
42 
43  // Exit
44 
45  return;
46 }
47 
48 
53 {
54 
55  // Preconditions:
56 
57  // Body:
58 
59  // Nothing to do.
60 
61  // Postconditions:
62 
63  ensure(invariant());
64  ensure(is_initialized() == xother.is_initialized());
65  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
66  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
67  ensure(unexecutable(this is first member of iteration or is_done()));
68 
69  // Exit
70 
71  return;
72 }
73 
78 {
79 
80  // Preconditions:
81 
82  require(is_ancestor_of(&xother));
83 
84  // Body:
85 
86  (void) section_component_iterator::operator=(xother);
87 
88  // Postconditions:
89 
90  ensure(invariant());
91  ensure(is_initialized() == xother.is_initialized());
92  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
93  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
94  ensure(unexecutable(this is first member of iteration or is_done()));
95 
96  // Exit
97 
98  return *this;
99 }
100 
105 {
106 
107  // Preconditions:
108 
109  require(is_ancestor_of(&xother));
110 
111  // Body:
112 
113  not_implemented();
114 
115  // Postconditions:
116 
117  ensure(invariant());
118 
119  // Exit:
120 
121  return *this;
122 }
123 
124 
128 {
129 
130  // Preconditions:
131 
132  // Body:
133 
134  // Nothing to do - base class does it all.
135 
136  // Postconditions:
137 
138  // Exit:
139 
140  return;
141 }
142 
143 
145 
147 bool
149 is_ancestor_of(const any* xother) const
150 {
151  bool result;
152 
153  // Preconditions:
154 
155  // Body:
156 
157  result = dynamic_cast<const binary_section_component_iterator*>(xother) != 0;
158 
159  // Postconditions:
160 
161  // Exit
162 
163  return result;
164 }
165 
169 clone() const
170 {
172 
173  // Preconditions:
174 
175  // Body:
176 
178 
179  // Postconditions:
180 
181  ensure(result != 0);
182 
183  // Exit
184 
185  return result;
186 }
187 
188 
189 bool
191 invariant() const
192 {
193  bool result = true;
194 
195  // Preconditions:
196 
197  // Body:
198 
199  result = result && section_component_iterator::invariant();
200 
201  if(invariant_check())
202  {
204 
205  result = result && (dynamic_cast<binary_section_space_schema_member*>(_anchor) != 0);
206 
207  // Finished, turn invariant checking back on.
208 
210  }
211 
212  // Postconditions:
213 
214  // Exit
215 
216  return result;
217 }
218 
223 {
224 
225  // Preconditions:
226 
227  require(item_is_ancestor_of(xanchor));
228  require(xanchor.state_is_read_accessible());
229 
230 
231  // Body:
232 
233  // Base constructor ensures !is_initialized, so set the anchor and reset.
234 
235  put_anchor(&xanchor);
236  reset();
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(unexecutable(postorder - have visited all children of this));
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 
257 anchor() const
258 {
259  // Preconditions:
260 
261  require(is_initialized());
262 
263  // Body:
264 
265  // Invariant ensures cast is appropriate.
266 
267  const binary_section_space_schema_member& result =
268  reinterpret_cast<binary_section_space_schema_member&>(*_anchor);
269 
270  // Postconditions:
271 
272  // Exit
273 
274  return result;
275 }
276 
277 // MEMBER ITERATOR FACET
278 
282 item() const
283 {
284  // Preconditions:
285 
286  require(is_initialized());
287 
288  // Body:
289 
290  const binary_section_space_schema_member& result =
291  reinterpret_cast<binary_section_space_schema_member&>(*_item);
292 
293  // Postconditions:
294 
295  // Exit
296 
297  return result;
298 }
299 
300 
301 
303 bool
306 {
307  bool result;
308 
309  // Preconditions:
310 
311  // Body:
312 
313  // Always true in this class;
314  // intended to be redefined in descendants.
315 
316  result = dynamic_cast<const binary_section_space_schema_member*>(&xmbr) != 0;
317 
318  // Postconditions:
319 
320  // Exit
321 
322  return result;
323 }
324 
325 
326 
327 // PROTECTED MEMBER FUNCTIONS
328 
329 
331 void
334 {
335  // Preconditions:
336 
337  // Body:
338 
339  if(_item == 0)
340  {
341  // Create the item handle.
342 
344  }
345 
346  assertion(is_initialized());
347 
348  // Attach the handle.
349 
350  update_item();
351 
352  // Postconditions:
353 
354  ensure(is_initialized());
355  ensure(!is_done() == item().is_attached());
356 
357  // Exit
358 
359  return;
360 }
361 
virtual void update_item()
Attaches the item handle to the current index, or detaches the item handle if is_done.
bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
A client handle for a poset member which has been prepared for use as a schema for a section space...
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
section_space_schema_member * _item
The member handle for the current item in the iteration.
void put_anchor(const section_space_schema_member *xanchor)
Sets anchor to member xanchor.
section_space_schema_member & item()
The the current member of the iteration (mutable version).
section_space_schema_member & anchor()
The schema member whose downset is being iterated over; the top member of the domain of iteration (mu...
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
const binary_section_space_schema_member & item() const
The the current member of the iteration.
Iterates in postorder over components of a section_space_schema_member anchor. The components of a se...
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
bool is_done() const
True if iteration finished.
virtual void reset_item()
Creates item if needed and attaches it to the current index. Abstract in this class; intended to be r...
virtual bool item_is_ancestor_of(const section_space_schema_member &xmbr) const
True if xmbr conforms to the type of item of this.
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 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...
virtual binary_section_component_iterator * clone() const
Make a new instance of the same type as this.
const binary_section_space_schema_member & anchor() const
The schema member whose downset is being iterated over; the top member of the domain of iteration...
virtual binary_section_component_iterator & operator=(const section_component_iterator &xother)
Assignment operator.
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...
binary_section_component_iterator()
Default constructor; creates an unattached iterator. Protected because this class is abstract...
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
section_space_schema_member * _anchor
The schema member whose downset is being iterated over; the top member of the domain of iteration...