SheafSystem  0.0.0.0
section_space_schema_jims_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/section_space_schema_jims_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/explicit_index_space_handle.h"
25 #include "SheafSystem/ij_product_structure.h"
26 #include "SheafSystem/index_space_family.h"
27 #include "SheafSystem/section_space_schema_jims_index_space_state.h"
28 
29 using namespace fiber_bundle; // Workaround for MS C++ bug.
30 
31 // ===========================================================
32 // SECTION_SPACE_SCHEMA_JIMS_INDEX_SPACE_ITERATOR FACET
33 // ===========================================================
34 
35 // PUBLIC MEMBER FUNCTIONS
36 
39 {
40  // Preconditions:
41 
42  // Body:
43 
44  // Postconditions:
45 
46  ensure(invariant());
47  ensure(!is_attached());
48 
49  // Exit:
50 
51  return;
52 }
53 
56 {
57  // Preconditions:
58 
59  // Body:
60 
61  *this = xother;
62 
63  // Postconditions:
64 
65  ensure(invariant());
66  ensure((*this) == xother);
67 
68  // Exit:
69 
70  return;
71 }
72 
75  pod_type xindex)
76 {
77  // Preconditions:
78 
79  require(conforms_to_state(xid_spaces, xindex));
80 
81  // Body:
82 
83  attach_to(xid_spaces, xindex);
84 
85  // Postconditions:
86 
87  ensure(invariant());
88  ensure(is_attached());
89  ensure(&id_spaces() == &xid_spaces);
90  ensure(index() == xindex);
91 
92  // Exit:
93 
94  return;
95 }
96 
99  const std::string& xname)
100 {
101  // Preconditions:
102 
103  require(conforms_to_state(xid_spaces, xname));
104 
105  // Body:
106 
107  attach_to(xid_spaces, xname);
108 
109  // Postconditions:
110 
111  ensure(invariant());
112  ensure(is_attached());
113  ensure(&id_spaces() == &xid_spaces);
114  ensure(name() == xname);
115 
116  // Exit:
117 
118  return;
119 }
120 
124 {
125  // Preconditions:
126 
127  // Body:
128 
129  if(xother.is_attached())
130  {
131  _base_space_itr = &xother.state().base_space().get_iterator();
132  *_base_space_itr = *xother._base_space_itr;
133 
134  _fiber_schema_itr = &xother.state().fiber_schema().get_iterator();
135  *_fiber_schema_itr = *xother._fiber_schema_itr;
136 
137  _section_space_schema_jims_product = new ij_product_structure(*xother._section_space_schema_jims_product);
138  _section_space_schema_product = new ij_product_structure(*xother._section_space_schema_product);
139 
140  (void) explicit_index_space_iterator::operator=(xother);
141  }
142  else
143  {
144  detach();
145  }
146 
147  // Postconditions:
148 
149  ensure(invariant());
150  ensure((*this) == xother);
151 
152  // Exit
153 
154  return *this;
155 }
156 
159 {
160  // Preconditions:
161 
162  // Body:
163 
164  // nothing to do.
165 
166  // Postconditions:
167 
168  // Exit:
169 
170  return;
171 }
172 
173 // PROTECTED MEMBER FUNCTIONS
174 
175 // PRIVATE MEMBER FUNCTIONS
176 
177 
178 // ===========================================================
179 // EXPLICIT_INDEX_SPACE_ITERATOR FACET
180 // ===========================================================
181 
182 // PUBLIC MEMBER FUNCTIONS
183 
184 // PROTECTED MEMBER FUNCTIONS
185 
189 {
190  // Preconditions:
191 
192  // Body:
193 
195  reinterpret_cast<section_space_schema_jims_index_space_state&>(*_state);
196 
197  // Postconditions:
198 
199  ensure(is_basic_query);
200 
201  // Exit:
202 
203  return result;
204 }
205 
208 state() const
209 {
210  // Preconditions:
211 
212  // Body:
213 
215  reinterpret_cast<const section_space_schema_jims_index_space_state&>(*_state);
216 
217  // Postconditions:
218 
219  ensure(is_basic_query);
220 
221  // Exit:
222 
223  return result;
224 }
225 
226 // PRIVATE MAMBER FUNCTIONS
227 
228 
229 // ===========================================================
230 // INDEX_SPACE_ITERATOR FACET
231 // ===========================================================
232 
233 // PUBLIC MEMBER FUNCTIONS
234 
238 {
239  // Preconditions:
240 
241  require(is_ancestor_of(&xother));
242 
243  // Body:
244 
246  dynamic_cast<const section_space_schema_jims_index_space_iterator&>(xother);
247 
248  (void) this->operator=(lother);
249 
250  // Postconditions:
251 
252  ensure(invariant());
253  ensure((*this) == xother);
254 
255  // Exit
256 
257  return *this;
258 }
259 
260 bool
262 operator==(const index_space_iterator& xother) const
263 {
264  // Preconditions:
265 
266  require(is_ancestor_of(&xother));
267 
268  // Body:
269 
270  bool result = explicit_index_space_iterator::operator==(xother);
271  if(result && is_attached())
272  {
274  dynamic_cast<const section_space_schema_jims_index_space_iterator&>(xother);
275 
276  result = result && (*_base_space_itr == *lother._base_space_itr);
277  result = result && (*_fiber_schema_itr == *lother._fiber_schema_itr);
278  result = result && (*_section_space_schema_jims_product == *lother._section_space_schema_jims_product);
279  result = result && (*_section_space_schema_product == *lother._section_space_schema_product);
280  }
281 
282  // Postconditions:
283 
284  ensure(invariant());
285 
286  // Exit
287 
288  return result;
289 }
290 
293 clone() const
294 {
296 
297  // Preconditions:
298 
299  // Body:
300 
302 
303  // Postconditions:
304 
305  ensure(result != 0);
306  ensure(is_same_type(result));
307  ensure(*result == *this);
308 
309  // Exit:
310 
311  return result;
312 }
313 
314 // PROTECTED MEMBER FUNCTIONS
315 
319 {
320  // Preconditions:
321 
322  // Body:
323 
324  // Postconditions:
325 
326  ensure(is_basic_query);
327 
328  // Exit:
329 
330  return *_base_space_itr;
331 }
332 
336 {
337  // Preconditions:
338 
339  // Body:
340 
341  // Postconditions:
342 
343  ensure(is_basic_query);
344 
345  // Exit:
346 
347  return *_fiber_schema_itr;
348 }
349 
350 void
353 {
354  // Preconditions:
355 
356  require(!base_space_iterator().is_done());
357  require(!fiber_schema_iterator().is_done());
358 
359  // Body:
360 
361  _section_space_schema_jims_product->ordinal(_base_space_itr->pod(),
362  _fiber_schema_itr->pod(),
363  _pod);
364 
365  _section_space_schema_product->ordinal(_base_space_itr->hub_pod(),
366  _fiber_schema_itr->hub_pod(),
367  _hub_pod);
368 
369  // Postconditions:
370 
371  ensure(!is_done());
372 
373  // Exit:
374 
375  return;
376 }
377 
378 // PRIVATE MAMBER FUNCTIONS
379 
380 
381 // ===========================================================
382 // ITERATOR FACET
383 // ===========================================================
384 
385 // PUBLIC MEMBER FUNCTIONS
386 
387 void
390 {
391  // Preconditions:
392 
393  require(is_attached());
394  require(!is_done());
395 
396  // Body:
397 
398  define_old_variable(pod_type old_pod = pod());
399  define_old_variable(pod_type old_hub_pod = hub_pod());
400 
401  // Increment fiber schema iterator.
402 
403  _fiber_schema_itr->next();
404 
405  if(_fiber_schema_itr->is_done())
406  {
407  // Fiber schema iteration is done,
408  // increment base space iterator.
409 
410  _base_space_itr->next();
411 
412  if(_base_space_itr->is_done())
413  {
414  // Base space iterator is done,
415  // the iteration is finished.
416 
417  invalidate_ids();
418  }
419  else
420  {
421  // Base space iterator is not done.
422  // Reset fiber schema iterator and update the ids.
423 
424  _fiber_schema_itr->reset();
425  update_ids();
426  }
427  }
428  else
429  {
430  // Fiber schema iterator is not done, update the ids.
431 
432  update_ids();
433  }
434 
435  // Postconditions:
436 
437  ensure(invariant());
438  ensure(is_done() || pod() != old_pod);
439  ensure(is_done() || hub_pod() != old_hub_pod);
440 
441  // Exit:
442 
443  return;
444 }
445 
446 void
449 {
450  // Preconditions:
451 
452  require(is_attached());
453 
454  // Body:
455 
456  _is_done = false;
457 
458  _base_space_itr->reset();
459  _fiber_schema_itr->reset();
460 
461  if(_base_space_itr->is_done() || _fiber_schema_itr->is_done())
462  {
463  // Nothing to iterator over, iteration is done.
464 
465  invalidate_ids();
466  }
467  else
468  {
469  // Update the ids.
470 
471  update_ids();
472  }
473 
474  // Postconditions:
475 
476  ensure(invariant());
477 
478  // Exit:
479 
480  return;
481 }
482 
483 // PROTECTED MEMBER FUNCTIONS
484 
485 // PRIVATE MEMBER FUNCTIONS
486 
487 
488 // ===========================================================
489 // HANDLE FACET
490 // ===========================================================
491 
492 // PUBLIC MEMBER FUNCTIONS
493 
494 // PROTECTED MEMBER FUNCTIONS
495 
496 void
499 {
500  // Preconditions:
501 
502  require(xstate != 0);
503  require(conforms_to_state(xstate));
504 
505  // Body:
506 
507  // Assign the state information.
508 
509  _state = xstate;
510  _base_space_itr = &state().base_space().get_iterator();
511  _fiber_schema_itr = &state().fiber_schema().get_iterator();
512  _section_space_schema_jims_product = state().product_structure().clone();
513  _section_space_schema_product = state().section_space_schema_product_structure().clone();
514 
515  // Reset the iterator.
516 
517  reset();
518 
519  // Postconditions:
520 
521  ensure(invariant());
522  ensure(is_attached());
523  ensure(&state() == xstate);
524  ensure(!is_done() ? pod() >= 0 : true);
525  ensure(!is_done() ? is_valid(hub_pod()) : true);
526 
527  // Exit:
528 
529  return;
530 }
531 
532 void
535 {
536  // Preconditions:
537 
538  // Body:
539 
540  state().base_space().release_iterator(*_base_space_itr);
541  state().fiber_schema().release_iterator(*_fiber_schema_itr);
542  delete _section_space_schema_jims_product;
543  delete _section_space_schema_product;
544 
545  _state = 0;
546 
547  // Postconditions:
548 
549  ensure(!is_attached());
550 
551  // Exit:
552 
553  return;
554 }
555 
556 bool
559 {
560  // Preconditions:
561 
562  // Body:
563 
564  bool result = (dynamic_cast<section_space_schema_jims_index_space_state*>(xstate) != 0);
565 
566  // Postconditions:
567 
568  ensure(is_basic_query);
569 
570  // Exit:
571 
572  return result;
573 }
574 
575 // PRIVATE MAMBER FUNCTIONS
576 
577 
578 // ===========================================================
579 // ANY FACET
580 // ===========================================================
581 
582 // PUBLIC MEMBER FUNCTIONS
583 
584 bool
586 is_ancestor_of(const any *other) const
587 {
588  // Preconditions:
589 
590  require(other != 0);
591 
592  // Body:
593 
594  // True if other conforms to this
595 
596  bool result = dynamic_cast<const section_space_schema_jims_index_space_iterator*>(other) != 0;
597 
598  // Postconditions:
599 
600  // Exit:
601 
602  return result;
603 }
604 
605 bool
607 invariant() const
608 {
609  bool result = true;
610 
611  if(invariant_check())
612  {
613  // Must satisfy base class invariant
614 
616 
617  // Prevent recursive calls to invariant
618 
619  disable_invariant_check();
620 
621  // Invariances for this class:
622 
623  // Finished, turn invariant checking back on.
624 
625  enable_invariant_check();
626  }
627 
628  // Exit
629 
630  return result;
631 }
632 
633 // PROTECTED MEMBER FUNCTIONS
634 
635 // PRIVATE MEMBER FUNCTIONS
636 
637 
638 // ===========================================================
639 // NON-MEMBER FUNCTIONS
640 // ===========================================================
index_space_iterator * _fiber_schema_itr
The fiber schema jims id space iterator.
virtual void attach_to(explicit_index_space_state *xstate)
Attach to the explicit id space state xstate.
An abstract iterator over the ids of an id space.
index_space_iterator & base_space_iterator()
The base space jims id space iterator.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
ij_product_structure * _section_space_schema_jims_product
The product structure of the section space schema jims id space.
ij_product_structure * _section_space_schema_product
The product structure of the section space schema id space.
Abstract base class with useful features for all objects.
Definition: any.h:39
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
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...
index_space_iterator * _base_space_itr
The base space jims id space iterator.
const index_space_handle & base_space() const
The base space jims id space.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
virtual index_space_iterator & get_iterator() const =0
Allocates an id space iterator from the iterator pool.
virtual index_space_iterator & get_iterator() const =0
Allocates an id space iterator from the iterator pool.
section_space_schema_jims_index_space_state & state()
The explicit state (mutable version).
A 2D implementation of abstract_product_structure.
virtual bool invariant() const
Class invariant.
An implementation class explicit_index_space_state for the jims id space of the section space schema...
virtual section_space_schema_jims_index_space_iterator * clone() const
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
Factory and container for a family of id spaces.
An iterator over an id space in which the equivalence between the ids in the space and the hub id spa...
pod_index_type pod_type
The "plain old data" index type for this.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
index_space_iterator & fiber_schema_iterator()
The fiber schema jims id space iterator.
Namespace for the fiber_bundles component of the sheaf system.
virtual index_space_iterator * clone() const =0
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
virtual bool is_attached() const
True if this iterator is attached to a state.
section_space_schema_jims_index_space_iterator & operator=(const section_space_schema_jims_index_space_iterator &xother)
Assignment operator.
const index_space_handle & fiber_schema() const
The fiber schema jims id space.