SheafSystem  0.0.0.0
ijk_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/ijk_connectivity_implicit_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/ijk_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 // IJK_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  _k_vertex_size = xother._k_vertex_size;
131  _jk_vertex_size = xother._jk_vertex_size;
132 
133  (void) implicit_index_space_iterator::operator=(xother);
134  }
135  else
136  {
137  detach();
138  }
139 
140  // Postconditions:
141 
142  ensure(invariant());
143  ensure((*this) == xother);
144 
145  // Exit
146 
147  return *this;
148 }
149 
152 {
153  // Preconditions:
154 
155  // Body:
156 
157  // Nothing to do;
158 
159  // Postconditions:
160 
161  // Exit:
162 
163  return;
164 }
165 
168 hub_begin() const
169 {
170  // Preconditions:
171 
172  // Body:
173 
174  // Postconditions:
175 
176  ensure(is_basic_query);
177 
178  // Exit:
179 
180  return _hub_begin;
181 }
182 
186 {
187  // Preconditions:
188 
189  // Body:
190 
191  // Postconditions:
192 
193  ensure(is_basic_query);
194 
195  // Exit:
196 
197  return _k_vertex_size;
198 }
199 
203 {
204  // Preconditions:
205 
206  // Body:
207 
208  // Postconditions:
209 
210  ensure(is_basic_query);
211 
212  // Exit:
213 
214  return _jk_vertex_size;
215 }
216 
217 // PROTECTED MEMBER FUNCTIONS
218 
219 // PRIVATE MEMBER FUNCTIONS
220 
221 
222 // ===========================================================
223 // IMPLICIT_INDEX_SPACE_ITERATOR FACET
224 // ===========================================================
225 
226 // PUBLIC MEMBER FUNCTIONS
227 
228 // PROTECTED MEMBER FUNCTIONS
229 
230 // PRIVATE MAMBER FUNCTIONS
231 
232 
233 // ===========================================================
234 // INDEX_SPACE_ITERATOR FACET
235 // ===========================================================
236 
237 // PUBLIC MEMBER FUNCTIONS
238 
242 {
243  // Preconditions:
244 
245  require(is_ancestor_of(&xother));
246 
247  // Body:
248 
250  dynamic_cast<const ijk_connectivity_implicit_index_space_iterator&>(xother);
251 
252  (void) this->operator=(lother);
253 
254  // Postconditions:
255 
256  ensure(invariant());
257  ensure((*this) == xother);
258 
259  // Exit
260 
261  return *this;
262 }
263 
264 bool
266 operator==(const index_space_iterator& xother) const
267 {
268  // Preconditions:
269 
270  require(is_ancestor_of(&xother));
271 
272  // Body:
273 
274  bool result = implicit_index_space_iterator::operator==(xother);
275  if(result && is_attached())
276  {
278  dynamic_cast<const ijk_connectivity_implicit_index_space_iterator&>(xother);
279 
280  result = result && (_hub_begin == lother._hub_begin);
281  result = result && (_k_vertex_size == lother._k_vertex_size);
282  result = result && (_jk_vertex_size == lother._jk_vertex_size);
283  }
284 
285  // Postconditions:
286 
287  ensure(invariant());
288 
289  // Exit
290 
291  return result;
292 }
293 
296 clone() const
297 {
299 
300  // Preconditions:
301 
302  // Body:
303 
305 
306  // Postconditions:
307 
308  ensure(result != 0);
309  ensure(is_same_type(result));
310  ensure(*result == *this);
311 
312  // Exit:
313 
314  return result;
315 }
316 
317 // PROTECTED MEMBER FUNCTIONS
318 
319 // PRIVATE MAMBER FUNCTIONS
320 
321 
322 // ===========================================================
323 // ITERATOR FACET
324 // ===========================================================
325 
326 // PUBLIC MEMBER FUNCTIONS
327 
328 void
331 {
332  // Preconditions:
333 
334  require(is_attached());
335  require(!is_done());
336 
337  // Body:
338 
339  define_old_variable(pod_type old_pod = pod());
340  define_old_variable(pod_type old_hub_pod = hub_pod());
341 
342  switch(_pod)
343  {
344  case 0:
345  {
346  // Increment to vertex (i+1, j, k) = _hub_pod + _jk_vertex_size
347 
348  _pod++;
349  _hub_pod += _jk_vertex_size;
350  break;
351  }
352  case 1:
353  {
354  // Increment to vertex (i+1, j+1, k) = _hub_pod + _k_vertex_size
355 
356  _pod++;
357  _hub_pod += _k_vertex_size;
358  break;
359  }
360  case 2:
361  {
362  // Increment to vertex (i, j+1, k) = _hub_pod - _jk_vertex_size
363 
364  _pod++;
365  _hub_pod -= _jk_vertex_size;
366  break;
367  }
368  case 3:
369  {
370  // Increment to vertex (i, j, k+1) = _hub_begin + 1
371 
372  _pod++;
373  _hub_pod = _hub_begin + 1;
374  break;
375  }
376  case 4:
377  {
378  // Increment to vertex (i+1, j, k+1) = _hub_pod + _jk_vertex_size
379 
380  _pod++;
381  _hub_pod += _jk_vertex_size;
382  break;
383  }
384  case 5:
385  {
386  // Increment to vertex (i+1, j+1, k+1) = _hub_pod + _k_vertex_size
387 
388  _pod++;
389  _hub_pod += _k_vertex_size;
390  break;
391  }
392  case 6:
393  {
394  // Increment to vertex (i, j+1, k+1) = _hub_pod - _jk_vertex_size
395 
396  _pod++;
397  _hub_pod -= _jk_vertex_size;
398  break;
399  }
400  default:
401  {
402  // The iteration is done.
403 
404  assertion(pod() == 7);
405 
406  invalidate_ids();
407  break;
408  }
409  }
410 
411  // Postconditions:
412 
413  ensure(invariant());
414  ensure(is_done() || pod() != old_pod);
415  ensure(is_done() || hub_pod() != old_hub_pod);
416 
417  // Exit:
418 
419  return;
420 }
421 
422 void
425 {
426  // Preconditions:
427 
428  require(is_attached());
429 
430  // Body:
431 
432  _is_done = false;
433 
434  // Reset to vertex (i, j, k)
435 
436  _pod = 0;
437  _hub_pod = _hub_begin;
438 
439  // Postconditions:
440 
441  ensure(invariant());
442 
443  // Exit:
444 
445  return;
446 }
447 
448 // PROTECTED MEMBER FUNCTIONS
449 
450 // PRIVATE MEMBER FUNCTIONS
451 
452 
453 // ===========================================================
454 // HANDLE FACET
455 // ===========================================================
456 
457 // PUBLIC MEMBER FUNCTIONS
458 
459 void
461 attach_to(const index_space_collection& xhost, pod_type xlocal_id)
462 {
463  // Preconditions:
464 
465  require(xhost.contains(xlocal_id));
466  require(conforms_to_state(xhost, xlocal_id));
467 
468  // Body:
469 
470  // Assign the state information.
471 
472  _host = &xhost;
473  _local_id = xlocal_id;
474 
475  // Find the section of the ijk_connectivity that represents this id space.
476 
478  reinterpret_cast<const ijk_connectivity_index_space_interval*>(_host);
479 
480  _hub_begin = lhost->vertex_hub_begin(xlocal_id);
481  _k_vertex_size = lhost->k_vertex_size();
482  _jk_vertex_size = lhost->jk_vertex_size();
483 
484  // Reset the iterator.
485 
486  reset();
487 
488  // Postconditions:
489 
490  ensure(invariant());
491  ensure(is_attached());
492  ensure(&host() == &xhost);
493  ensure(index() == xhost.family_scope(xlocal_id));
494 
495  // Exit:
496 
497  return;
498 }
499 
500 bool
503  pod_type xlocal_id) const
504 {
505  // Preconditions:
506 
507  // Body:
508 
509  bool result = (dynamic_cast<const ijk_connectivity_index_space_interval*>(&xhost) != 0);
510 
511  // Postconditions:
512 
513  ensure(is_basic_query);
514 
515  // Exit:
516 
517  return result;
518 }
519 
520 // PROTECTED MEMBER FUNCTIONS
521 
522 // PRIVATE MAMBER FUNCTIONS
523 
524 
525 // ===========================================================
526 // ANY FACET
527 // ===========================================================
528 
529 // PUBLIC MEMBER FUNCTIONS
530 
531 bool
533 is_ancestor_of(const any *other) const
534 {
535  // Preconditions:
536 
537  require(other != 0);
538 
539  // Body:
540 
541  // True if other conforms to this
542 
543  bool result = dynamic_cast<const ijk_connectivity_implicit_index_space_iterator*>(other) != 0;
544 
545  // Postconditions:
546 
547  // Exit:
548 
549  return result;
550 }
551 
552 bool
554 invariant() const
555 {
556  bool result = true;
557 
558  if(invariant_check())
559  {
560  // Must satisfy base class invariant
561 
563 
564  // Prevent recursive calls to invariant
565 
566  disable_invariant_check();
567 
568  // Invariances for this class:
569 
570  // Finished, turn invariant checking back on.
571 
572  enable_invariant_check();
573  }
574 
575  // Exit
576 
577  return result;
578 }
579 
580 // PROTECTED MEMBER FUNCTIONS
581 
582 // PRIVATE MEMBER FUNCTIONS
583 
584 
585 // ===========================================================
586 // NON-MEMBER FUNCTIONS
587 // ===========================================================
588 
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
size_type k_vertex_size() const
The number of vertices in the k direction.
An abstract iterator over the ids of an id space.
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.
ijk_connectivity_implicit_index_space_iterator & operator=(const ijk_connectivity_implicit_index_space_iterator &xother)
Assignment operator.
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
virtual ijk_connectivity_implicit_index_space_iterator * clone() const
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
size_type k_vertex_size() const
The number of vertices in the k direction.
size_type jk_vertex_size() const
The number of vertices in the j*k direction.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
An implementation of implicit_index_space_iterator for an implicit id space in an ijk_connectivity_in...
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.
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...
pod_type vertex_hub_begin() const
The hub id of the beginning of the vertex id space.
virtual bool invariant() const
Class invariant.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
virtual bool is_attached() const
True if this iterator is attached to a state.
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...
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.
size_type jk_vertex_size() const
The number of vertices in the j*k direction.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.