SheafSystem  0.0.0.0
subposet_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 subposet_member_iterator
19 
20 #include "SheafSystem/subposet_member_iterator.h"
21 #include "SheafSystem/assert_contract.h"
22 
23 #include "SheafSystem/poset_state_handle.h"
24 #include "SheafSystem/subposet.h"
25 
29 {
30 
31  // Preconditions:
32 
33  require(xdomain.state_is_read_accessible());
34 
35  // Body:
36 
37  _filter = 0;
38  _new_filter = false;
39 
40  reset(&xdomain);
41 
42  // Postconditions:
43 
44  ensure(invariant());
45 }
46 
47 
49 bool
51 invariant() const
52 {
53  bool result = true;
54 
55  // Body:
56 
57  invariance(domain() != 0);
58  invariance(!is_done() ? domain()->contains_member(this) : true);
59 
60  // Exit:
61 
62  return result;
63 
64 }
65 
66 
70 {
71  // Preconditions:
72 
73  // Body:
74 
75  if ((_filter != 0) && _new_filter)
76  {
77  delete _filter;
78  }
79 
80  // Necessary to prevent poset_member::~poset_member from deleting state
81 
83 
84  // Postconditions:
85 
86  ensure(!is_attached());
87 
88  // Exit:
89 
90  return;
91 }
92 
93 
94 
95 
97 bool
99 is_done() const
100 {
101  // Preconditions:
102 
103  // Body:
104 
105  // Postconditions:
106 
107  // Exit
108 
109  return _itr.is_done();
110 }
111 
112 
113 
114 
116 bool
118 is_last() const
119 {
120  // Preconditions:
121 
122  // Body:
123 
124  // Postconditions:
125 
126  // Exit
127 
128  return _itr.is_last();
129 }
130 
131 
133 void
136 {
137  // Preconditions:
138 
139  require(!is_done());
140  require(state_is_read_accessible());
141 
142 
143  // Body:
144 
145  _itr.next();
146 
147  if (!_itr.is_done())
148  {
149  //attach_to_state(_domain->host(), _itr.item());
151  }
152  else
153  {
155  }
156 
157  // Postconditions:
158 
159  ensure(invariant());
160 
161  // Exit
162 
163  return;
164 }
165 
166 
168 void
171 {
172  // Preconditions:
173 
174  require(domain() != 0);
175  require(domain()->state_is_read_accessible());
176 
177 
178  // Body:
179 
180  _itr.reset();
181 
182  if (!_itr.is_done())
183  {
184  //attach_to_state(_domain->host(), _itr.item());
186  }
187  else
188  {
190  }
191 
192 
193  // Postconditions:
194 
195  ensure(invariant());
196 
197  // Exit
198 
199  return;
200 }
201 
202 
204 void
206 reset(const subposet* xdomain)
207 {
208 
209  // Preconditions:
210 
211  require(xdomain != 0);
212  require(xdomain->state_is_read_accessible());
213 
214  // Body:
215 
216  _domain = const_cast<subposet*>(xdomain);
217 
219 
220  _itr.reset(_filter, _domain->host()->member_hub_id_space(false));
221 
222  if (!_itr.is_done())
223  {
224  attach_to_state(_domain->host(), _itr.index());
225  }
226  else
227  {
229  }
230 
231  // Postconditions:
232 
233  ensure(domain() == xdomain);
234  ensure(invariant());
235 }
236 
237 
238 
242 domain() const
243 {
244  subposet* result;
245 
246  // Preconditions:
247 
248  // Body:
249 
250  result = _domain;
251 
252  // Postconditions:
253 
254  ensure(result != 0);
255 
256  // Exit
257 
258  return result;
259 }
260 
261 void
264 {
265  // Preconditions:
266 
267  require(domain() != 0);
268  require(domain()->state_is_read_accessible());
269 
270  // Body:
271 
272 
273  // First clean up any existing filter.
274 
275  if ((_filter != 0) && _new_filter)
276  {
277  // `this' allocated filter, delete it.
278  delete _filter;
279  _new_filter = false;
280  }
281 
282  // Initialize the new filter.
283 
284  if (_domain->host()->is_version())
285  {
286  // filter is intersection of whole() and _domain.
287 
288  _filter = new zn_to_bool(*(_domain->members()));
289  _new_filter = true;
291  }
292  else
293  {
294  // use _domain itself as the filter.
295 
296  _filter = _domain->members();
297  _new_filter = false;
298  }
299 
300  // Postconditions:
301 
302  ensure(invariant());
303 
304  // Exit
305 
306  return;
307 }
308 
313 {
314 
315  // Preconditions:
316 
317  require(is_ancestor_of(&xother));
318 
319  //Body:
320 
321  not_implemented();
322 
323  //Postconditions:
324 
325  ensure(invariant());
326 
327  //Exit:
328 
329  return *this;
330 }
331 
336 {
337 
338  // Preconditions:
339 
340  require(is_ancestor_of(&xother));
341 
342  //Body:
343 
344  not_implemented();
345 
346  //Postconditions:
347 
348  ensure(invariant());
349 
350  //Exit:
351 
352  return *this;
353 }
354 
poset_state_handle * host() const
The poset which this is a handle to a component of.
A client handle for a subposet.
Definition: subposet.h:86
index_iterator _itr
Index iterator for characteristic function of domain.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
~subposet_member_iterator()
Destroys this iterator.
subposet * _domain
Subposet being iterated over.
const scoped_index & index() const
The current item in the subset.
bool is_done() const
True if iteration finished.
void next()
Makes item the next member of the subset.
void next()
Makes this the next member of the subset.
zn_to_bool * _filter
The filter; defined by what it passes, not what it blocks, that is, the iterator will only return mem...
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
Definition: zn_to_bool.h:52
bool invariant() const
The canonical class invariant.
bool is_last() const
True if is_done() will be true after next call to next.
virtual bool is_attached() const
True if this handle is attached to a non-void state.
virtual const subposet & whole() const
The "improper" subset containing all members of this poset.
subposet * domain() const
The subposet being iterated over. Note that only the members also belonging to the domain&#39;s host&#39;s cu...
zn_to_bool * members() const
The characteristic function for the members of this.
Definition: subposet.cc:1277
void reset()
Restarts the iteration, makes this the first member of domain() also belonging to domain()&#39;s host()&#39;s...
subposet_member_iterator(const subposet &xsubposet)
Creates an iterator for the members of xsubposet; makes this the first member.
virtual void detach_from_state()
Detach this handle from its state, if any.
bool is_version() const
True if this poset is a version.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
bool is_done() const
True if iteration finished.
void b_and_sa(const zn_to_bool *other)
This AND other, self-allocated.
Definition: zn_to_bool.cc:1181
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 subposet_member_iterator & operator=(const abstract_poset_member &xother)
Assignment operator.
An abstract client handle for a member of a poset.
void reset()
Restarts the iteration, makes item the first member of the subset.
bool _new_filter
True if `this&#39; allocated a new filter.
void initialize_filter()
Initialize the filter.
bool is_last() const
True if iteration finished after next call to next()