SheafSystem  0.0.0.0
i_connectivity_implicit_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/i_connectivity_implicit_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/i_connectivity_index_space_interval.h"
25 #include "SheafSystem/index_space_family.h"
26 
27 using namespace fiber_bundle; // Workaround for MS C++ bug.
28 
29 // ===========================================================
30 // I_CONNECTIVITY_IMPLICIT_INDEX_SPACE_ITERATOR FACET
31 // ===========================================================
32 
33 // PUBLIC MEMBER FUNCTIONS
34 
37 {
38  // Preconditions:
39 
40  // Body:
41 
42  // Postconditions:
43 
44  ensure(invariant());
45  ensure(!is_attached());
46 
47  // Exit:
48 
49  return;
50 }
51 
54 {
55  // Preconditions:
56 
57  // Body:
58 
59  *this = xother;
60 
61  // Postconditions:
62 
63  ensure(invariant());
64  ensure((*this) == xother);
65 
66  // Exit:
67 
68  return;
69 }
70 
73  pod_type xindex)
74 {
75  // Preconditions:
76 
77  require(conforms_to_state(xid_spaces, xindex));
78 
79  // Body:
80 
81  attach_to(xid_spaces, xindex);
82 
83  // Postconditions:
84 
85  ensure(invariant());
86  ensure(is_attached());
87  ensure(&id_spaces() == &xid_spaces);
88  ensure(index() == xindex);
89 
90  // Exit:
91 
92  return;
93 }
94 
97  const std::string& xname)
98 {
99  // Preconditions:
100 
101  require(conforms_to_state(xid_spaces, xname));
102 
103  // Body:
104 
105  attach_to(xid_spaces, xname);
106 
107  // Postconditions:
108 
109  ensure(invariant());
110  ensure(is_attached());
111  ensure(&id_spaces() == &xid_spaces);
112  ensure(name() == xname);
113 
114  // Exit:
115 
116  return;
117 }
118 
122 {
123  // Preconditions:
124 
125  // Body:
126 
127  if(xother.is_attached())
128  {
129  _hub_begin = xother._hub_begin;
130 
131  (void) implicit_index_space_iterator::operator=(xother);
132  }
133  else
134  {
135  detach();
136  }
137 
138  // Postconditions:
139 
140  ensure(invariant());
141  ensure((*this) == xother);
142 
143  // Exit
144 
145  return *this;
146 }
147 
150 {
151  // Preconditions:
152 
153  // Body:
154 
155  // Nothing to do;
156 
157  // Postconditions:
158 
159  // Exit:
160 
161  return;
162 }
163 
166 hub_begin() const
167 {
168  // Preconditions:
169 
170  // Body:
171 
172  // Postconditions:
173 
174  ensure(is_basic_query);
175 
176  // Exit:
177 
178  return _hub_begin;
179 }
180 
181 // PROTECTED MEMBER FUNCTIONS
182 
183 // PRIVATE MEMBER FUNCTIONS
184 
185 
186 // ===========================================================
187 // IMPLICIT_INDEX_SPACE_ITERATOR FACET
188 // ===========================================================
189 
190 // PUBLIC MEMBER FUNCTIONS
191 
192 // PROTECTED MEMBER FUNCTIONS
193 
194 // PRIVATE MAMBER FUNCTIONS
195 
196 
197 // ===========================================================
198 // INDEX_SPACE_ITERATOR FACET
199 // ===========================================================
200 
201 // PUBLIC MEMBER FUNCTIONS
202 
206 {
207  // Preconditions:
208 
209  require(is_ancestor_of(&xother));
210 
211  // Body:
212 
214  dynamic_cast<const i_connectivity_implicit_index_space_iterator&>(xother);
215 
216  (void) this->operator=(lother);
217 
218  // Postconditions:
219 
220  ensure(invariant());
221  ensure((*this) == xother);
222 
223  // Exit
224 
225  return *this;
226 }
227 
228 bool
230 operator==(const index_space_iterator& xother) const
231 {
232  // Preconditions:
233 
234  require(is_ancestor_of(&xother));
235 
236  // Body:
237 
238  bool result = implicit_index_space_iterator::operator==(xother);
239  if(result && is_attached())
240  {
242  dynamic_cast<const i_connectivity_implicit_index_space_iterator&>(xother);
243 
244  result = result && (_hub_begin == lother._hub_begin);
245  }
246 
247  // Postconditions:
248 
249  ensure(invariant());
250 
251  // Exit
252 
253  return result;
254 }
255 
258 clone() const
259 {
261 
262  // Preconditions:
263 
264  // Body:
265 
267 
268  // Postconditions:
269 
270  ensure(result != 0);
271  ensure(is_same_type(result));
272  ensure(*result == *this);
273 
274  // Exit:
275 
276  return result;
277 }
278 
279 // PROTECTED MEMBER FUNCTIONS
280 
281 // PRIVATE MAMBER FUNCTIONS
282 
283 
284 // ===========================================================
285 // ITERATOR FACET
286 // ===========================================================
287 
288 // PUBLIC MEMBER FUNCTIONS
289 
290 void
293 {
294  // Preconditions:
295 
296  require(is_attached());
297  require(!is_done());
298 
299  // Body:
300 
301  define_old_variable(pod_type old_pod = pod());
302  define_old_variable(pod_type old_hub_pod = hub_pod());
303 
304  switch(_pod)
305  {
306  case 0:
307  {
308  // Increment to vertex (i+1) = _hub_pod + 1
309 
310  _pod++;
311  _hub_pod += 1;
312  break;
313  }
314  default:
315  {
316  // The iteration is done.
317 
318  assertion(pod() == 1);
319 
320  invalidate_ids();
321  break;
322  }
323  }
324 
325  // Postconditions:
326 
327  ensure(invariant());
328  ensure(is_done() || pod() != old_pod);
329  ensure(is_done() || hub_pod() != old_hub_pod);
330 
331  // Exit:
332 
333  return;
334 }
335 
336 void
339 {
340  // Preconditions:
341 
342  require(is_attached());
343 
344  // Body:
345 
346  _is_done = false;
347 
348  // Reset to vertex (i)
349 
350  _pod = 0;
351  _hub_pod = _hub_begin;
352 
353  // Postconditions:
354 
355  ensure(invariant());
356 
357  // Exit:
358 
359  return;
360 }
361 
362 // PROTECTED MEMBER FUNCTIONS
363 
364 // PRIVATE MEMBER FUNCTIONS
365 
366 
367 // ===========================================================
368 // HANDLE FACET
369 // ===========================================================
370 
371 // PUBLIC MEMBER FUNCTIONS
372 
373 void
375 attach_to(const index_space_collection& xhost, pod_type xlocal_id)
376 {
377  // Preconditions:
378 
379  require(xhost.contains(xlocal_id));
380  require(conforms_to_state(xhost, xlocal_id));
381 
382  // Body:
383 
384  // Assign the state information.
385 
386  _host = &xhost;
387  _local_id = xlocal_id;
388 
389  // Find the section of the i_connectivity that represents this id space.
390 
392  reinterpret_cast<const i_connectivity_index_space_interval*>(_host);
393 
394  _hub_begin = lhost->vertex_hub_begin(xlocal_id);
395 
396  // Reset the iterator.
397 
398  reset();
399 
400  // Postconditions:
401 
402  ensure(invariant());
403  ensure(is_attached());
404  ensure(&host() == &xhost);
405  ensure(index() == xhost.family_scope(xlocal_id));
406 
407  // Exit:
408 
409  return;
410 }
411 
412 bool
415  pod_type xlocal_id) const
416 {
417  // Preconditions:
418 
419  // Body:
420 
421  bool result = (dynamic_cast<const i_connectivity_index_space_interval*>(&xhost) != 0);
422 
423  // Postconditions:
424 
425  ensure(is_basic_query);
426 
427  // Exit:
428 
429  return result;
430 }
431 
432 // PROTECTED MEMBER FUNCTIONS
433 
434 // PRIVATE MAMBER FUNCTIONS
435 
436 
437 // ===========================================================
438 // ANY FACET
439 // ===========================================================
440 
441 // PUBLIC MEMBER FUNCTIONS
442 
443 bool
445 is_ancestor_of(const any *other) const
446 {
447  // Preconditions:
448 
449  require(other != 0);
450 
451  // Body:
452 
453  // True if other conforms to this
454 
455  bool result = dynamic_cast<const i_connectivity_implicit_index_space_iterator*>(other) != 0;
456 
457  // Postconditions:
458 
459  // Exit:
460 
461  return result;
462 }
463 
464 bool
466 invariant() const
467 {
468  bool result = true;
469 
470  if(invariant_check())
471  {
472  // Must satisfy base class invariant
473 
475 
476  // Prevent recursive calls to invariant
477 
478  disable_invariant_check();
479 
480  // Invariances for this class:
481 
482  // Finished, turn invariant checking back on.
483 
484  enable_invariant_check();
485  }
486 
487  // Exit
488 
489  return result;
490 }
491 
492 // PROTECTED MEMBER FUNCTIONS
493 
494 // PRIVATE MEMBER FUNCTIONS
495 
496 
497 // ===========================================================
498 // NON-MEMBER FUNCTIONS
499 // ===========================================================
An abstract iterator over the ids of an id space.
virtual bool conforms_to_state(const index_space_collection &xhost, pod_type xlocal_id) const
True if this conforms to the handle type required by the state with local scope id xlocal_id in the h...
virtual pod_type family_scope(pod_type xlocal_id) const =0
Id relative to the id space family equivalent to the local id xlocal_id.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
An implementation of index_space_interval for an interval of implicit id spaces for the connectivity ...
Abstract base class with useful features for all objects.
Definition: any.h:39
i_connectivity_implicit_index_space_iterator & operator=(const i_connectivity_implicit_index_space_iterator &xother)
Assignment operator.
pod_type vertex_hub_begin() const
The hub id of the beginning of the vertex id space.
A collection of id space states. This is a virtual class with provides an interface for accessing the...
virtual bool contains(pod_type xlocal_id) const =0
True if this collection contains the id space with local id xlocal_id.
An implementation of implicit_index_space_iterator for an implicit id space in an i_connectivity_inde...
virtual bool invariant() const
Class invariant.
virtual bool is_attached() const
True if this iterator is attached to a state.
virtual void attach_to(const index_space_collection &xhost, pod_type xlocal_id)
Attach to the state with local scope id, xlocal_id in the host id space collection xhost...
virtual i_connectivity_implicit_index_space_iterator * clone() const
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
Factory and container for a family of id spaces.
pod_index_type pod_type
The "plain old data" index type for this.
Namespace for the fiber_bundles component of the sheaf system.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.