SheafSystem  0.0.0.0
ij_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/ij_connectivity_implicit_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/ij_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 // IJ_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  _j_vertex_size = xother._j_vertex_size;
131 
132  (void) implicit_index_space_iterator::operator=(xother);
133  }
134  else
135  {
136  detach();
137  }
138 
139  // Postconditions:
140 
141  ensure(invariant());
142  ensure((*this) == xother);
143 
144  // Exit
145 
146  return *this;
147 }
148 
151 {
152  // Preconditions:
153 
154  // Body:
155 
156  // Nothing to do;
157 
158  // Postconditions:
159 
160  // Exit:
161 
162  return;
163 }
164 
167 hub_begin() const
168 {
169  // Preconditions:
170 
171  // Body:
172 
173  // Postconditions:
174 
175  ensure(is_basic_query);
176 
177  // Exit:
178 
179  return _hub_begin;
180 }
181 
185 {
186  // Preconditions:
187 
188  // Body:
189 
190  // Postconditions:
191 
192  ensure(is_basic_query);
193 
194  // Exit:
195 
196  return _j_vertex_size;
197 }
198 
199 // PROTECTED MEMBER FUNCTIONS
200 
201 // PRIVATE MEMBER FUNCTIONS
202 
203 
204 // ===========================================================
205 // IMPLICIT_INDEX_SPACE_ITERATOR FACET
206 // ===========================================================
207 
208 // PUBLIC MEMBER FUNCTIONS
209 
210 // PROTECTED MEMBER FUNCTIONS
211 
212 // PRIVATE MAMBER FUNCTIONS
213 
214 
215 // ===========================================================
216 // INDEX_SPACE_ITERATOR FACET
217 // ===========================================================
218 
219 // PUBLIC MEMBER FUNCTIONS
220 
224 {
225  // Preconditions:
226 
227  require(is_ancestor_of(&xother));
228 
229  // Body:
230 
232  dynamic_cast<const ij_connectivity_implicit_index_space_iterator&>(xother);
233 
234  (void) this->operator=(lother);
235 
236  // Postconditions:
237 
238  ensure(invariant());
239  ensure((*this) == xother);
240 
241  // Exit
242 
243  return *this;
244 }
245 
246 bool
248 operator==(const index_space_iterator& xother) const
249 {
250  // Preconditions:
251 
252  require(is_ancestor_of(&xother));
253 
254  // Body:
255 
256  bool result = implicit_index_space_iterator::operator==(xother);
257  if(result && is_attached())
258  {
260  dynamic_cast<const ij_connectivity_implicit_index_space_iterator&>(xother);
261 
262  result = result && (_hub_begin == lother._hub_begin);
263  result = result && (_j_vertex_size == lother._j_vertex_size);
264  }
265 
266  // Postconditions:
267 
268  ensure(invariant());
269 
270  // Exit
271 
272  return result;
273 }
274 
277 clone() const
278 {
280 
281  // Preconditions:
282 
283  // Body:
284 
286 
287  // Postconditions:
288 
289  ensure(result != 0);
290  ensure(is_same_type(result));
291  ensure(*result == *this);
292 
293  // Exit:
294 
295  return result;
296 }
297 
298 // PROTECTED MEMBER FUNCTIONS
299 
300 // PRIVATE MAMBER FUNCTIONS
301 
302 
303 // ===========================================================
304 // ITERATOR FACET
305 // ===========================================================
306 
307 // PUBLIC MEMBER FUNCTIONS
308 
309 void
312 {
313  // Preconditions:
314 
315  require(is_attached());
316  require(!is_done());
317 
318  // Body:
319 
320  define_old_variable(pod_type old_pod = pod());
321  define_old_variable(pod_type old_hub_pod = hub_pod());
322 
323  switch(_pod)
324  {
325  case 0:
326  {
327  // Increment to vertex (i+1, j) = _hub_pod + _j_vertex_size
328 
329  _pod++;
330  _hub_pod += _j_vertex_size;
331  break;
332  }
333  case 1:
334  {
335  // Increment to vertex (i+1, j+1) = _hub_pod + 1
336 
337  _pod++;
338  _hub_pod += 1;
339  break;
340  }
341  case 2:
342  {
343  // Increment to vertex (i, j+1) = _hub_pod - _j_vertex_size
344 
345  _pod++;
346  _hub_pod -= _j_vertex_size;
347  break;
348  }
349  default:
350  {
351  // The iteration is done.
352 
353  assertion(pod() == 3);
354 
355  invalidate_ids();
356  break;
357  }
358  }
359 
360  // Postconditions:
361 
362  ensure(invariant());
363  ensure(is_done() || pod() != old_pod);
364  ensure(is_done() || hub_pod() != old_hub_pod);
365 
366  // Exit:
367 
368  return;
369 }
370 
371 void
374 {
375  // Preconditions:
376 
377  require(is_attached());
378 
379  // Body:
380 
381  _is_done = false;
382 
383  // Reset to vertex (i, j)
384 
385  _pod = 0;
386  _hub_pod = _hub_begin;
387 
388  // Postconditions:
389 
390  ensure(invariant());
391 
392  // Exit:
393 
394  return;
395 }
396 
397 // PROTECTED MEMBER FUNCTIONS
398 
399 // PRIVATE MEMBER FUNCTIONS
400 
401 
402 // ===========================================================
403 // HANDLE FACET
404 // ===========================================================
405 
406 // PUBLIC MEMBER FUNCTIONS
407 
408 void
410 attach_to(const index_space_collection& xhost, pod_type xlocal_id)
411 {
412  // Preconditions:
413 
414  require(xhost.contains(xlocal_id));
415  require(conforms_to_state(xhost, xlocal_id));
416 
417  // Body:
418 
419  // Assign the state information.
420 
421  _host = &xhost;
422  _local_id = xlocal_id;
423 
424  // Find the section of the ij_connectivity that represents this id space.
425 
427  reinterpret_cast<const ij_connectivity_index_space_interval*>(_host);
428 
429  _hub_begin = lhost->vertex_hub_begin(xlocal_id);
430  _j_vertex_size = lhost->j_vertex_size();
431 
432  // Reset the iterator.
433 
434  reset();
435 
436  // Postconditions:
437 
438  ensure(invariant());
439  ensure(is_attached());
440  ensure(&host() == &xhost);
441  ensure(index() == xhost.family_scope(xlocal_id));
442 
443  // Exit:
444 
445  return;
446 }
447 
448 bool
451  pod_type xlocal_id) const
452 {
453  // Preconditions:
454 
455  // Body:
456 
457  bool result = (dynamic_cast<const ij_connectivity_index_space_interval*>(&xhost) != 0);
458 
459  // Postconditions:
460 
461  ensure(is_basic_query);
462 
463  // Exit:
464 
465  return result;
466 }
467 
468 // PROTECTED MEMBER FUNCTIONS
469 
470 // PRIVATE MAMBER FUNCTIONS
471 
472 
473 // ===========================================================
474 // ANY FACET
475 // ===========================================================
476 
477 // PUBLIC MEMBER FUNCTIONS
478 
479 bool
481 is_ancestor_of(const any *other) const
482 {
483  // Preconditions:
484 
485  require(other != 0);
486 
487  // Body:
488 
489  // True if other conforms to this
490 
491  bool result = dynamic_cast<const ij_connectivity_implicit_index_space_iterator*>(other) != 0;
492 
493  // Postconditions:
494 
495  // Exit:
496 
497  return result;
498 }
499 
500 bool
502 invariant() const
503 {
504  bool result = true;
505 
506  if(invariant_check())
507  {
508  // Must satisfy base class invariant
509 
511 
512  // Prevent recursive calls to invariant
513 
514  disable_invariant_check();
515 
516  // Invariances for this class:
517 
518  // Finished, turn invariant checking back on.
519 
520  enable_invariant_check();
521  }
522 
523  // Exit
524 
525  return result;
526 }
527 
528 // PROTECTED MEMBER FUNCTIONS
529 
530 // PRIVATE MEMBER FUNCTIONS
531 
532 
533 // ===========================================================
534 // NON-MEMBER FUNCTIONS
535 // ===========================================================
536 
ij_connectivity_implicit_index_space_iterator & operator=(const ij_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.
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.
size_type j_vertex_size() const
The number of vertices in the j direction.
size_type j_vertex_size() const
The number of vertices in the j direction.
Abstract base class with useful features for all objects.
Definition: any.h:39
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
An implementation of index_space_interval for an interval of implicit id spaces for the connectivity ...
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...
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 bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
virtual bool invariant() const
Class invariant.
virtual ij_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 is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual bool is_attached() const
True if this iterator is attached to a state.
An implementation of implicit_index_space_iterator for an implicit id space in an ij_connectivity_ind...
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.
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...