SheafSystem  0.0.0.0
postorder_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 postorder_member_iterator
19 
20 #include "SheafSystem/postorder_member_iterator.h"
21 
22 #include "SheafSystem/poset_state_handle.h"
23 #include "SheafSystem/postorder_iterator.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/total_poset_member.h"
26 
27 
32 {
33 
34  // Preconditions:
35 
36 
37  // Body:
38 
39  // Postconditions:
40 
41  ensure(invariant());
42  ensure(!is_initialized());
43 
44  // Exit
45 
46  return;
47 }
48 
49 
53 {
54 
55  // Preconditions:
56 
57  // Body:
58 
59  // Postconditions:
60 
61  ensure(invariant());
62  ensure(is_initialized() == xother.is_initialized());
63  ensure(is_initialized() ? anchor().is_same_state(&xother.anchor()) : true);
64  ensure(is_initialized() ? filter().is_same_state(&(const_cast<postorder_member_iterator&>(xother).filter())) : true);
65  ensure(is_initialized() ? descending() == xother.descending() : true);
66  ensure(is_initialized() ? strict() == xother.strict() : true);
67  ensure(is_initialized() ? item().is_same_type(&xother.item()) : true);
68  ensure(unexecutable(this is first member of iteration or is_done()));
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(&(const_cast<filtered_depth_first_member_iterator&>(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 
101  // Exit
102 
103  return *this;
104 }
105 
109 {
110 
111  // Preconditions:
112 
113  require(is_ancestor_of(&xother));
114 
115  // Body:
116 
117  not_implemented();
118 
119  // Postconditions:
120 
121  ensure(invariant());
122 
123  // Exit:
124 
125  return *this;
126 }
127 
128 
131 {
132 
133  // Preconditions:
134 
135  // Body:
136 
137  // Postconditions:
138 
139  // Exit:
140 
141  return;
142 }
143 
144 
145 
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 postorder_member_iterator*>(xother) != 0;
157 
158  // Postconditions:
159 
160  // Exit
161 
162  return result;
163 }
164 
165 
168 clone() const
169 {
171 
172  // Preconditions:
173 
174  // Body:
175 
176  result = new postorder_member_iterator;
177 
178  // Postconditions:
179 
180  ensure(result != 0);
181 
182  // Exit
183 
184  return result;
185 }
186 
187 bool
189 invariant() const
190 {
191  bool result = true;
192 
193  // Preconditions:
194 
195  // Body:
196 
198 
199  if(invariant_check())
200  {
202 
203  // Finished, turn invariant checking back on.
204 
206  }
207 
208  // Postconditions:
209 
210  // Exit
211 
212  return result;
213 }
214 
217  bool xdown,
218  bool xstrict)
220  xdown,
221  xstrict),
222  xanchor.clone())
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  // Postconditions:
234 
235  ensure(invariant());
236  ensure(is_initialized());
237  ensure(anchor().is_same_state(&xanchor));
238  ensure(anchor().is_same_type(&xanchor));
239  ensure(filter().index() == anchor().version_index());
240  ensure(descending() == xdown);
241  ensure(strict() == xstrict);
242  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
243  ensure(unexecutable(postorder - have visited all children of this));
244  ensure(unexecutable(!is_done() implies this is first member));
245  ensure(item().is_attached() == !is_done());
246 
247  return;
248 }
249 
252  const subposet& xfilter,
253  bool xdown,
254  bool xstrict)
256  xfilter,
257  xdown,
258  xstrict),
259  xanchor.clone())
260 {
261 
262  // Preconditions:
263 
264  require(item_is_ancestor_of(xanchor));
265  require(xanchor.state_is_read_accessible());
266  require(xanchor.host()->includes_subposet(&xfilter));
267 
268 
269  // Body:
270 
271  // Postconditions:
272 
273  ensure(invariant());
274  ensure(is_initialized());
275  ensure(anchor().is_same_state(&xanchor));
276  ensure(anchor().is_same_type(&xanchor));
277  ensure(filter().is_same_state(&xfilter));
278  ensure(descending() == xdown);
279  ensure(strict() == xstrict);
280  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
281  ensure(unexecutable(postorder - have visited all children of this));
282  ensure(unexecutable(!is_done() implies this is first member));
283  ensure(item().is_attached() == !is_done());
284 
285  return;
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(postorder - 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(postorder - 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 
366  const std::string& xfilter_name,
367  bool xdown,
368  bool xstrict)
370  xfilter_name,
371  xdown,
372  xstrict),
373  xanchor.clone())
374 {
375 
376  // Preconditions:
377 
378  require(item_is_ancestor_of(xanchor));
379  require(xanchor.state_is_read_accessible());
380  require(!xfilter_name.empty() ? xanchor.host()->includes_subposet(xfilter_name) : true);
381 
382 
383  // Body:
384 
385  // Postconditions:
386 
387  ensure(invariant());
388  ensure(is_initialized());
389  ensure(anchor().is_same_state(&xanchor));
390  ensure(anchor().is_same_type(&xanchor));
391  ensure(!xfilter_name.empty() ?
392  filter().name() == xfilter_name :
393  filter().name() == anchor().version_name());
394  ensure(descending() == xdown);
395  ensure(strict() == xstrict);
396  ensure(strict() && !is_done() ? item().index() !=~ anchor().index() : true);
397  ensure(unexecutable(postorder - have visited all children of this));
398  ensure(unexecutable(!is_done() implies this is first member));
399  ensure(item().is_attached() == !is_done());
400 
401  return;
402 }
403 
406  abstract_poset_member* xitem)
408 {
409  // Preconditions:
410 
411  // Body:
412 
413  // Postconditions:
414 
415  // Exit
416 
417  return;
418 }
virtual abstract_poset_member & anchor()
The poset member whose downset is being iterated over; the top member of the domain of iteration (mut...
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
abstract_poset_member & item()
The the current member of the iteration (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...
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 filtered_depth_first_member_iterator & operator=(const filtered_depth_first_member_iterator &xother)
Assignment operator.
Dperecated. Use postorder_itr. Specialization of the filtered depth-first iterator which exposes the ...
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 descending() const
True if iterating over down set of anchor.
postorder_member_iterator()
Default constructor; creates an unattached iterator, with and all-pass filter.
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.
virtual postorder_member_iterator & operator=(const filtered_depth_first_member_iterator &xother)
Assignment operator.
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.
virtual postorder_member_iterator * clone() const
Make a new instance of the same type as this.
bool invariant() const
The class invariant.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
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.
A client handle for an unrestricted member of a poset. A total_poset_member is guaranteed not to be r...