SheafSystem  0.0.0.0
preorder_member_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 preorder_member_iterator
19 
20 #include "SheafSystem/preorder_member_iterator.h"
21 
22 #include "SheafSystem/poset_state_handle.h"
23 #include "SheafSystem/preorder_iterator.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/total_poset_member.h"
26 
27 
32 {
33  // Preconditions:
34 
35  // Body:
36 
37  // Postconditions:
38 
39  ensure(invariant());
40  ensure(!is_initialized());
41 
42  // Exit
43 
44  return;
45 }
46 
47 
51 {
52 
53  // Preconditions:
54 
55  // Body:
56 
57  // Postconditions:
58 
59  ensure(invariant());
60  ensure(is_initialized() == xother.is_initialized());
61  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
62  ensure(is_initialized() ? filter().is_same_state(&xother.filter()) : true);
63  ensure(is_initialized() ? descending() == xother.descending() : true);
64  ensure(is_initialized() ? strict() == xother.strict() : true);
65  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
66  ensure(unexecutable(this is first member of iteration or is_done()));
67 
68 
69 
70  // Exit
71 
72  return;
73 }
74 
75 
79 {
80 
81  // Preconditions:
82 
83  require(is_ancestor_of(&xother));
84 
85  // Body:
86 
88 
89  // Postconditions:
90 
91  ensure(invariant());
92  ensure(is_initialized() == xother.is_initialized());
93  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
94  ensure(is_initialized() ? filter().is_same_state(&xother.filter()) : true);
95  ensure(is_initialized() ? descending() == xother.descending() : true);
96  ensure(is_initialized() ? strict() == xother.strict() : true);
97  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
98  ensure(unexecutable(this is first member of iteration or is_done()));
99 
100  // Exit
101 
102  return *this;
103 }
104 
108 {
109 
110  // Preconditions:
111 
112  require(is_ancestor_of(&xother));
113 
114  // Body:
115 
116  not_implemented();
117 
118  // Postconditions:
119 
120  ensure(invariant());
121 
122  // Exit:
123 
124  return *this;
125 }
126 
127 
130 {
131 
132  // Preconditions:
133 
134  // Body:
135 
136  // Postconditions:
137 
138  // Exit:
139 
140  return;
141 }
142 
143 
144 
145 bool
147 is_ancestor_of(const any* xother) const
148 {
149  bool result;
150 
151  // Preconditions:
152 
153  // Body:
154 
155  result = dynamic_cast<const preorder_member_iterator*>(xother) != 0;
156 
157  // Postconditions:
158 
159  // Exit
160 
161  return result;
162 }
163 
164 
167 clone() const
168 {
169  preorder_member_iterator* result;
170 
171  // Preconditions:
172 
173  // Body:
174 
175  result = new preorder_member_iterator;
176 
177  // Postconditions:
178 
179  ensure(result != 0);
180 
181  // Exit
182 
183  return result;
184 }
185 
186 bool
188 invariant() const
189 {
190  bool result = true;
191 
192  // Preconditions:
193 
194  // Body:
195 
197 
198  if(invariant_check())
199  {
201 
202  // Finished, turn invariant checking back on.
203 
205  }
206 
207  // Postconditions:
208 
209  // Exit
210 
211  return result;
212 }
213 
216  bool xdown,
217  bool xstrict)
219  xdown,
220  xstrict),
221  xanchor.clone())
222 {
223 
224  // Preconditions:
225 
226  require(item_is_ancestor_of(xanchor));
227  require(xanchor.state_is_read_accessible());
228 
229 
230  // Body:
231 
232  // Postconditions:
233 
234  ensure(invariant());
235  ensure(is_initialized());
236  ensure(anchor().is_same_state(&xanchor));
237  ensure(anchor().is_same_type(&xanchor));
238  ensure(filter().index() == anchor().version_index());
239  ensure(descending() == xdown);
240  ensure(strict() == xstrict);
241  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
242  ensure(unexecutable(preorder - have visited all children of this));
243  ensure(unexecutable(!is_done() implies this is first member));
244  ensure(item().is_attached() == !is_done());
245 
246  return;
247 }
248 
251  const subposet& xfilter,
252  bool xdown,
253  bool xstrict)
255  xfilter,
256  xdown,
257  xstrict),
258  xanchor.clone())
259 {
260 
261  // Preconditions:
262 
263  require(item_is_ancestor_of(xanchor));
264  require(xanchor.state_is_read_accessible());
265  require( xanchor.host()->includes_subposet(&xfilter));
266 
267 
268  // Body:
269 
270  // Postconditions:
271 
272  ensure(invariant());
273  ensure(is_initialized());
274  ensure(anchor().is_same_state(&xanchor));
275  ensure(anchor().is_same_type(&xanchor));
276  ensure(filter().is_same_state(&xfilter));
277  ensure(descending() == xdown);
278  ensure(strict() == xstrict);
279  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
280  ensure(unexecutable(preorder - have visited all children of this));
281  ensure(unexecutable(!is_done() implies this is first member));
282  ensure(item().is_attached() == !is_done());
283 
284  return;
285 }
286 
287 
290  pod_index_type xfilter_index,
291  bool xdown,
292  bool xstrict)
294  xfilter_index,
295  xdown,
296  xstrict),
297  xanchor.clone())
298 {
299 
300  // Preconditions:
301 
302  require(item_is_ancestor_of(xanchor));
303  require(xanchor.state_is_read_accessible());
304  require(xanchor.host()->includes_subposet(xfilter_index));
305 
306 
307  // Body:
308 
309  // Postconditions:
310 
311  ensure(invariant());
312  ensure(is_initialized());
313  ensure(anchor().is_same_state(&xanchor));
314  ensure(anchor().is_same_type(&xanchor));
315  ensure(filter().is_attached());
316  ensure(descending() == xdown);
317  ensure(strict() == xstrict);
318  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
319  ensure(unexecutable(preorder - have visited all children of this));
320  ensure(unexecutable(!is_done() implies this is first member));
321  ensure(item().is_attached() == !is_done());
322 
323  return;
324 }
325 
328  const scoped_index& xfilter_index,
329  bool xdown,
330  bool xstrict)
332  xfilter_index,
333  xdown,
334  xstrict),
335  xanchor.clone())
336 {
337 
338  // Preconditions:
339 
340  require(item_is_ancestor_of(xanchor));
341  require(xanchor.state_is_read_accessible());
342  require(xanchor.host()->includes_subposet(xfilter_index));
343 
344 
345  // Body:
346 
347  // Postconditions:
348 
349  ensure(invariant());
350  ensure(is_initialized());
351  ensure(anchor().is_same_state(&xanchor));
352  ensure(anchor().is_same_type(&xanchor));
353  ensure(filter().is_attached());
354  ensure(descending() == xdown);
355  ensure(strict() == xstrict);
356  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
357  ensure(unexecutable(preorder - have visited all children of this));
358  ensure(unexecutable(!is_done() implies this is first member));
359  ensure(item().is_attached() == !is_done());
360 
361  return;
362 }
363 
364 
367  const std::string& xfilter_name,
368  bool xdown,
369  bool xstrict)
371  xfilter_name,
372  xdown,
373  xstrict),
374  xanchor.clone())
375 {
376 
377  // Preconditions:
378 
379  require(item_is_ancestor_of(xanchor));
380  require(xanchor.state_is_read_accessible());
381  require(!xfilter_name.empty() ? xanchor.host()->includes_subposet(xfilter_name) : true);
382 
383 
384  // Body:
385 
386  // Postconditions:
387 
388  ensure(invariant());
389  ensure(is_initialized());
390  ensure(anchor().is_same_state(&xanchor));
391  ensure(anchor().is_same_type(&xanchor));
392  ensure(!xfilter_name.empty() ?
393  filter().name() == xfilter_name :
394  filter().name() == anchor().version_name());
395  ensure(descending() == xdown);
396  ensure(strict() == xstrict);
397  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
398  ensure(unexecutable(preorder - have visited all children of this));
399  ensure(unexecutable(!is_done() implies this is first member));
400  ensure(item().is_attached() == !is_done());
401 
402  return;
403 }
404 
405 void
408 {
409  // Preconditions:
410 
411  require(is_initialized());
412  require(!is_done());
413 
414  // Body:
415 
416  _iterator->truncate();
417  update_item();
418 
419  // Postconditions:
420 
421  // Exit
422 
423  return;
424 }
425 
426 
virtual abstract_poset_member & anchor()
The poset member whose downset is being iterated over; the top member of the domain of iteration (mut...
void truncate()
Makes this the next member of the subset which is not less than old this, i.e. the depth-first descen...
poset_state_handle * host() const
The poset which this is a handle to a component of.
std::string name() const
Definition: subposet.h:796
A client handle for a subposet.
Definition: subposet.h:86
void truncate()
Makes this the next member of the subset which is not less than old this, i.e. the depth-first descen...
abstract_poset_member & item()
The the current member of the iteration (mutable version).
filtered_depth_first_iterator * _iterator
The index iterator used to implement the iteration.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual bool includes_subposet(pod_index_type xsubposet_hub_id, bool xauto_access=true) const
True if this poset includes subposet with hub id xsubposet_hub_id.
virtual void update_item()
Attaches the item handle to the current index, or detaches the item handle if is_done.
virtual filtered_depth_first_member_iterator & operator=(const filtered_depth_first_member_iterator &xother)
Assignment operator.
preorder_member_iterator()
Default constructor; creates an unattached iterator, with and all-pass filter.
virtual bool item_is_ancestor_of(const abstract_poset_member &xmbr) const
True if xmbr conforms to the type of item of this.
Abstract base class with useful features for all objects.
Definition: any.h:39
bool invariant() const
The class invariant.
bool descending() const
True if iterating over down set of anchor.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
const subposet & filter() const
The subposet which is the filter; Defines what is passed, not what is blocked.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
bool strict() const
True if iterating over xstrict up/down set of anchor.
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 preorder_member_iterator & operator=(const filtered_depth_first_member_iterator &xother)
Assignment operator.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
An abstract client handle for a member of a poset.
std::string version_name() const
The subposet name for the filter associated with version().
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
bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
virtual preorder_member_iterator * clone() const
Make a new instance of the same type as this.
A client handle for an unrestricted member of a poset. A total_poset_member is guaranteed not to be r...