SheafSystem  0.0.0.0
singleton_index_space_iterator.cc
Go to the documentation of this file.
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 
20 
21 #include "SheafSystem/singleton_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/explicit_index_space_handle.h"
25 #include "SheafSystem/index_space_family.h"
26 #include "SheafSystem/singleton_index_space_state.h"
27 
28 // ===========================================================
29 // SINGLETON_INDEX_SPACE_ITERATOR FACET
30 // ===========================================================
31 
32 // PUBLIC MEMBER FUNCTIONS
33 
36 {
37  // Preconditions:
38 
39  // Body:
40 
41  // Postconditions:
42 
43  ensure(invariant());
44  ensure(!is_attached());
45 
46  // Exit:
47 
48  return;
49 }
50 
53 {
54  // Preconditions:
55 
56  // Body:
57 
58  *this = xother;
59 
60  // Postconditions:
61 
62  ensure(invariant());
63  ensure((*this) == xother);
64 
65  // Exit:
66 
67  return;
68 }
69 
72  pod_type xindex)
73 {
74  // Preconditions:
75 
76  require(conforms_to_state(xid_spaces, xindex));
77 
78  // Body:
79 
80  attach_to(xid_spaces, xindex);
81 
82  // Postconditions:
83 
84  ensure(invariant());
85  ensure(is_attached());
86  ensure(&id_spaces() == &xid_spaces);
87  ensure(index() == xindex);
88 
89  // Exit:
90 
91  return;
92 }
93 
96  const std::string& xname)
97 {
98  // Preconditions:
99 
100  require(conforms_to_state(xid_spaces, xname));
101 
102  // Body:
103 
104  attach_to(xid_spaces, xname);
105 
106  // Postconditions:
107 
108  ensure(invariant());
109  ensure(is_attached());
110  ensure(&id_spaces() == &xid_spaces);
111  ensure(name() == xname);
112 
113  // Exit:
114 
115  return;
116 }
117 
121 {
122  // Preconditions:
123 
124  // Body:
125 
126  if(xother.is_attached())
127  {
128  _hub_begin = xother._hub_begin;
129 
130  (void) explicit_index_space_iterator::operator=(xother);
131  }
132  else
133  {
134  detach();
135  }
136 
137  // Postconditions:
138 
139  ensure(invariant());
140  ensure((*this) == xother);
141 
142  // Exit
143 
144  return *this;
145 }
146 
149 {
150  // Preconditions:
151 
152  // Body:
153 
154  // No action required.
155 
156  // Postconditions:
157 
158  // Exit:
159 
160  return;
161 }
162 
165 hub_begin() const
166 {
167  // Preconditions:
168 
169  require(is_attached());
170 
171  // Body:
172 
173  pod_type result = _hub_begin;
174 
175  // Postconditions:
176 
177  ensure(is_basic_query);
178 
179  // Exit:
180 
181  return result;
182 }
183 
184 // PROTECTED MEMBER FUNCTIONS
185 
186 // PRIVATE MEMBER FUNCTIONS
187 
188 
189 // ===========================================================
190 // EXPLICIT_INDEX_SPACE_ITERATOR FACET
191 // ===========================================================
192 
193 // PUBLIC MEMBER FUNCTIONS
194 
195 // PROTECTED MEMBER FUNCTIONS
196 
197 // PRIVATE MAMBER FUNCTIONS
198 
199 
200 // ===========================================================
201 // INDEX_SPACE_ITERATOR FACET
202 // ===========================================================
203 
204 // PUBLIC MEMBER FUNCTIONS
205 
209 {
210  // Preconditions:
211 
212  require(is_ancestor_of(&xother));
213 
214  // Body:
215 
216  const singleton_index_space_iterator& lother =
217  dynamic_cast<const singleton_index_space_iterator&>(xother);
218 
219  (void) this->operator=(lother);
220 
221  // Postconditions:
222 
223  ensure(invariant());
224  ensure((*this) == xother);
225 
226  // Exit
227 
228  return *this;
229 }
230 
231 bool
233 operator==(const index_space_iterator& xother) const
234 {
235  // Preconditions:
236 
237  require(is_ancestor_of(&xother));
238 
239  // Body:
240 
241  bool result = explicit_index_space_iterator::operator==(xother);
242  if(result && is_attached())
243  {
244  const singleton_index_space_iterator& lother =
245  dynamic_cast<const singleton_index_space_iterator&>(xother);
246 
247  result = result && (_hub_begin == lother._hub_begin);
248  }
249 
250  // Postconditions:
251 
252  ensure(invariant());
253 
254  // Exit
255 
256  return result;
257 }
258 
261 clone() const
262 {
264 
265  // Preconditions:
266 
267  // Body:
268 
269  result = new singleton_index_space_iterator(*this);
270 
271  // Postconditions:
272 
273  ensure(result != 0);
274  ensure(is_same_type(result));
275  ensure(*result == *this);
276 
277  // Exit:
278 
279  return result;
280 }
281 
282 // PROTECTED MEMBER FUNCTIONS
283 
284 // PRIVATE MAMBER FUNCTIONS
285 
286 
287 // ===========================================================
288 // ITERATOR FACET
289 // ===========================================================
290 
291 // PUBLIC MEMBER FUNCTIONS
292 
293 void
296 {
297  // Preconditions:
298 
299  require(is_attached());
300  require(!is_done());
301 
302  // Body:
303 
304  define_old_variable(pod_type old_pod = pod());
305  define_old_variable(pod_type old_hub_pod = hub_pod());
306 
307  // Only one id, the iteration is done.
308 
309  invalidate_ids();
310 
311  // Postconditions:
312 
313  ensure(invariant());
314  ensure(is_done());
315 
316  // Exit:
317 
318  return;
319 }
320 
321 void
324 {
325  // Preconditions:
326 
327  require(is_attached());
328 
329  // Body:
330 
331  _is_done = false;
332 
333  _pod = 0;
335 
336  // Postconditions:
337 
338  ensure(invariant());
339 
340  // Exit:
341 
342  return;
343 }
344 
345 // PROTECTED MEMBER FUNCTIONS
346 
347 // PRIVATE MAMBER FUNCTIONS
348 
349 
350 // ===========================================================
351 // HANDLE FACET
352 // ===========================================================
353 
354 // PUBLIC MEMBER FUNCTIONS
355 
356 void
359 {
360  // Preconditions:
361 
362  require(xstate != 0);
363  require(conforms_to_state(xstate));
364 
365  // Body:
366 
367  // Assign the state information.
368 
369  _state = xstate;
370  _hub_begin = reinterpret_cast<singleton_index_space_state*>(_state)->hub_id();
371 
372  // Reset the iterator.
373 
374  reset();
375 
376  // Postconditions:
377 
378  ensure(invariant());
379  ensure(is_attached());
380  ensure(&state() == xstate);
381 
382  // Exit:
383 
384  return;
385 }
386 
387 bool
390 {
391  // Preconditions:
392 
393  // Body:
394 
395  bool result = (dynamic_cast<singleton_index_space_state*>(xstate) != 0);
396 
397  // Postconditions:
398 
399  ensure(is_basic_query);
400 
401  // Exit:
402 
403  return result;
404 }
405 
406 // PROTECTED MEMBER FUNCTIONS
407 
408 // PRIVATE MAMBER FUNCTIONS
409 
410 
411 // ===========================================================
412 // ANY FACET
413 // ===========================================================
414 
415 // PUBLIC MEMBER FUNCTIONS
416 
417 bool
419 is_ancestor_of(const any *other) const
420 {
421  // Preconditions:
422 
423  require(other != 0);
424 
425  // Body:
426 
427  // True if other conforms to this
428 
429  bool result = dynamic_cast<const singleton_index_space_iterator*>(other) != 0;
430 
431  // Postconditions:
432 
433  // Exit:
434 
435  return result;
436 }
437 
438 bool
440 invariant() const
441 {
442  bool result = true;
443 
444  if(invariant_check())
445  {
446  // Must satisfy base class invariant
447 
449 
450  // Prevent recursive calls to invariant
451 
453 
454  // Invariances for this class:
455 
456  // Finished, turn invariant checking back on.
457 
459  }
460 
461  // Exit
462 
463  return result;
464 }
465 
466 // PROTECTED MEMBER FUNCTIONS
467 
468 // PRIVATE MEMBER FUNCTIONS
469 
470 
471 // ===========================================================
472 // NON-MEMBER FUNCTIONS
473 // ===========================================================
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
An iterator over an id space in which contains only one id.
virtual pod_type index() const
Index of this space.
singleton_index_space_iterator & operator=(const singleton_index_space_iterator &xother)
Assignment operator.
An abstract iterator over the ids of an id space.
virtual void next()
Makes item() the next id in the iteration.
bool _is_done
True if the iteration is finished.
virtual singleton_index_space_iterator * clone() const
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
pod_type pod() const
The current id in the iteration.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
void invalidate_ids()
Set is_done() and invalidate pod() and hub_pod().
virtual void reset()
Restarts the iteration.
virtual void attach_to(explicit_index_space_state *xstate)
Attach to the explicit id space state xstate.
explicit_index_space_state & state()
The explicit state (mutable version).
Abstract base class with useful features for all objects.
Definition: any.h:39
std::string name() const
Name of this space.
bool is_done() const
True if iteration is finished.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
const index_space_family & id_spaces() const
The id space family for this (const version).
virtual bool invariant() const
Class invariant.
pod_type _hub_pod
The current hub id in the iteration.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual bool conforms_to_state(explicit_index_space_state *xstate) const
True if this conforms to the iterator type required by the explicit id space state xstate...
pod_type _hub_begin
The hub id of the singleton id.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
explicit_index_space_state * _state
The explicit state.
virtual bool invariant() const
Class invariant.
virtual void detach()
Detach this iterator form its state, if any.
An implementation of explicit_index_space_state for an id space containing a single id...
pod_type _pod
The current id in the iteration.
Factory and container for a family of id spaces.
pod_index_type pod_type
The "plain old data" index type for this.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
pod_type hub_begin() const
The hub id of the singleton id.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual bool is_attached() const
True if this iterator is attached to a state.
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().