SheafSystem  0.0.0.0
explicit_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/explicit_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/explicit_index_space_state.h"
25 #include "SheafSystem/index_space_family.h"
26 
27 // ===========================================================
28 // EXPLICIT_INDEX_SPACE_ITERATOR FACET
29 // ===========================================================
30 
31 // PUBLIC MEMBER FUNCTIONS
32 
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  // Nothing to do;
41 
42  // Postconditions:
43 
44  // Exit:
45 
46  return;
47 }
48 
49 // PROTECTED MEMBER FUNCTIONS
50 
53  : _state(0)
54 {
55  // Preconditions:
56 
57  // Body:
58 
59  // Postconditions:
60 
61  ensure(invariant());
62 
63  // Exit:
64 
65  return;
66 }
67 
70 {
71  // Preconditions:
72 
73  // Body:
74 
75  *this = xother;
76 
77  // Postconditions:
78 
79  ensure(invariant());
80 // ensure((*this) == xother);
81 
82  // Exit:
83 
84  return;
85 }
86 
90 {
91  // Preconditions:
92 
93  // Body:
94 
95  if(xother.is_attached())
96  {
97  _state = xother._state;
98 
99  (void) index_space_iterator::operator=(xother);
100  }
101 
102  // Postconditions:
103 
104  ensure(invariant());
105 // ensure((*this) == xother);
106 
107  // Exit
108 
109  return *this;
110 }
111 
115 {
116  // Preconditions:
117 
118  require(is_attached());
119 
120  // Body:
121 
123 
124  // Postconditions:
125 
126  ensure(is_basic_query);
127 
128  // Exit:
129 
130  return result;
131 }
132 
135 state() const
136 {
137  // Preconditions:
138 
139  require(is_attached());
140 
141  // Body:
142 
143  const explicit_index_space_state& result = *_state;
144 
145  // Postconditions:
146 
147  ensure(is_basic_query);
148 
149  // Exit:
150 
151  return result;
152 }
153 
154 // PRIVATE MEMBER FUNCTIONS
155 
156 
157 // ===========================================================
158 // INDEX_SPACE_ITERATOR FACET
159 // ===========================================================
160 
161 // PUBLIC MEMBER FUNCTIONS
162 
166 {
167  // Preconditions:
168 
169  require(is_ancestor_of(&xother));
170 
171  // Body:
172 
173  const explicit_index_space_iterator& lother =
174  dynamic_cast<const explicit_index_space_iterator&>(xother);
175 
176  (void) this->operator=(lother);
177 
178  // Postconditions:
179 
180  ensure(invariant());
181 // ensure((*this) == xother);
182 
183  // Exit
184 
185  return *this;
186 }
187 
188 bool
190 operator==(const index_space_iterator& xother) const
191 {
192  // Preconditions:
193 
194  require(is_ancestor_of(&xother));
195 
196  // Body:
197 
198  bool result = index_space_iterator::operator==(xother);
199  if(result && is_attached())
200  {
201  const explicit_index_space_iterator& lother =
202  dynamic_cast<const explicit_index_space_iterator&>(xother);
203 
204  result = result && (_state == lother._state);
205  }
206 
207  // Postconditions:
208 
209  ensure(is_basic_query);
210 
211  // Exit:
212 
213  return result;
214 }
215 
218 clone() const
219 {
221 
222  // Preconditions:
223 
224  // Body:
225 
226  result = 0; // Just to silence compiler warnings.
227 
228  is_abstract();
229 
230  // Postconditions:
231 
232  ensure(result != 0);
233  ensure(is_same_type(result));
234  ensure(*result == *this);
235 
236  // Exit:
237 
238  return result;
239 }
240 
241 // PROTECTED MEMBER FUNCTIONS
242 
243 // PRIVATE MEMBER FUNCTIONS
244 
245 
246 // ===========================================================
247 // HANDLE FACET
248 // ===========================================================
249 
250 // PUBLIC MEMBER FUNCTIONS
251 
254 host() const
255 {
256  // Preconditions:
257 
258  require(is_attached());
259 
260  // Body:
261 
262  const index_space_collection& result = _state->host();
263 
264  // Postconditions:
265 
266  ensure(is_basic_query);
267 
268  // Exit:
269 
270  return result;
271 }
272 
275 index() const
276 {
277  // Preconditions:
278 
279  require(is_attached());
280 
281  // Body:
282 
283  pod_type result = _state->index();
284 
285  // Postconditions:
286 
287  ensure(id_spaces().contains(result));
288 
289  // Exit:
290 
291  return result;
292 }
293 
294 bool
296 is_attached() const
297 {
298  // Preconditions:
299 
300  // Body:
301 
302  bool result = (_state != 0);
303 
304  // Postconditions:
305 
306  ensure(is_basic_query);
307 
308  // Exit:
309 
310  return result;
311 }
312 
313 void
316 {
317  // Preconditions:
318 
319  require(is_attached());
320  require(id_spaces().contains(xindex));
321  require(conforms_to_state(xindex));
322 
323  // Body:
324 
325  define_old_variable(const index_space_family& old_id_spaces = id_spaces());
326 
327  attach_to(state(xindex));
328 
329  // Postconditions:
330 
331  ensure(invariant());
332  ensure(is_attached());
333  ensure(&id_spaces() == &old_id_spaces);
334  ensure(index() == xindex);
335 
336  // Exit:
337 
338  return;
339 }
340 
341 void
343 attach_to(const index_space_collection& xhost, pod_type xlocal_id)
344 {
345  // Preconditions:
346 
347  require(xhost.contains(xlocal_id));
348  require(conforms_to_state(xhost, xlocal_id));
349 
350  // Body:
351 
352  attach_to(xhost.explicit_state(xlocal_id));
353 
354  // Postconditions:
355 
356  ensure(invariant());
357  ensure(is_attached());
358  ensure(&host() == &xhost);
359  ensure(index() == xhost.family_scope(xlocal_id));
360 
361  // Exit:
362 
363  return;
364 }
365 
366 void
369 {
370  // Preconditions:
371 
372  // Body:
373 
374  _state = 0;
375 
376  // Postconditions:
377 
378  ensure(!is_attached());
379 
380  // Exit:
381 
382  return;
383 }
384 
385 bool
388  pod_type xlocal_id) const
389 {
390  // Preconditions:
391 
392  require(xhost.contains(xlocal_id));
393 
394  // Body:
395 
396  bool result = (xhost.explicit_state(xlocal_id) != 0);
397 
398  // Postconditions:
399 
400  ensure(is_basic_query);
401 
402  // Exit:
403 
404  return result;
405 }
406 
407 // PROTECTED MEMBER FUNCTIONS
408 
409 void
412 {
413  // Preconditions:
414 
415  require(xstate != 0);
416  require(conforms_to_state(xstate));
417 
418  // Body:
419 
420  is_abstract();
421 
422  // Postconditions:
423 
424  ensure(invariant());
425  ensure(is_attached());
426  ensure(&state() == xstate);
427 
428  // Exit:
429 
430  return;
431 }
432 
433 bool
436 {
437  // Preconditions:
438 
439  // Body:
440 
441  bool result = false; // Just to silence compiler warnings.
442 
443  is_abstract();
444 
445  // Postconditions:
446 
447  ensure(is_basic_query);
448 
449  // Exit:
450 
451  return result;
452 }
453 
456 state(pod_type xindex) const
457 {
458  // Preconditions:
459 
460  require(is_attached());
461  require(id_spaces().contains(xindex));
462 
463  // Body:
464 
465  const index_space_collection& lhost =
466  host().contains(xindex) ? host() : *id_spaces().collection(xindex);
467 
469  lhost.explicit_state(lhost.local_scope(xindex));
470 
471  // Postconditions:
472 
473  ensure(is_basic_query);
474 
475  // Exit:
476 
477  return result;
478 }
479 
482 state(const index_space_collection& xhost, pod_type xlocal_id) const
483 {
484  // Preconditions:
485 
486  require(xhost.contains(xlocal_id));
487 
488  // Body:
489 
490  explicit_index_space_state* result = xhost.explicit_state(xlocal_id);
491 
492  // Postconditions:
493 
494  ensure(is_basic_query);
495 
496  // Exit:
497 
498  return result;
499 }
500 
501 // PRIVATE MEMBER FUNCTIONS
502 
503 
504 // ===========================================================
505 // INDEX_SPACE_ITERATOR FACET
506 // ===========================================================
507 
508 // PUBLIC MEMBER FUNCTIONS
509 
510 // PROTECTED MEMBER FUNCTIONS
511 
512 // PRIVATE MEMBER FUNCTIONS
513 
514 
515 // ===========================================================
516 // ANY FACET
517 // ===========================================================
518 
519 // PUBLIC MEMBER FUNCTIONS
520 
521 bool
523 is_ancestor_of(const any *other) const
524 {
525  // Preconditions:
526 
527  require(other != 0);
528 
529  // Body:
530 
531  // True if other conforms to this
532 
533  bool result = dynamic_cast<const explicit_index_space_iterator*>(other) != 0;
534 
535  // Postconditions:
536 
537  // Exit:
538 
539  return result;
540 }
541 
542 bool
544 invariant() const
545 {
546  bool result = true;
547 
548  if(invariant_check())
549  {
550  // Must satisfy base class invariant
551 
552  invariance(index_space_iterator::invariant());
553 
554  // Prevent recursive calls to invariant
555 
557 
558  // Invariances for this class:
559 
560  // Finished, turn invariant checking back on.
561 
563  }
564 
565  // Exit
566 
567  return result;
568 }
569 
570 // PROTECTED MEMBER FUNCTIONS
571 
572 // PRIVATE MEMBER FUNCTIONS
573 
574 
575 // ===========================================================
576 // NON-MEMBER FUNCTIONS
577 // ===========================================================
578 
const index_space_collection * collection(pod_type xid) const
Id space collection for id xid (const version).
virtual void attach_to(pod_type xindex)
Attach to the state with index xindex in the id space family id_spaces().
const index_space_collection & host() const
The host collection (const version).
virtual pod_type index() const
Index of this space.
An abstract iterator over the ids of an id space.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
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 const index_space_collection & host() const
The host collection.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual explicit_index_space_state * explicit_state(pod_type xlocal_id) const =0
The explicit id space state for id xlocal_id. Returns null if there is no explicit id space for xloca...
virtual pod_type local_scope(pod_type xspace_id) const =0
Id relative to this collection equivalent to the id space family id xspace_id.
explicit_index_space_state & state()
The explicit state (mutable version).
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...
const index_space_family & id_spaces() const
The id space family for this (const version).
virtual explicit_index_space_iterator * clone() const =0
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
A collection of id space states. This is a virtual class with provides an interface for accessing the...
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 contains(pod_type xlocal_id) const =0
True if this collection contains the id space with local id xlocal_id.
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...
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
An implementation of class index_space_iterator for an explicit_index_space_state.
pod_type index() const
The index of this id space.
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.
explicit_index_space_iterator & operator=(const explicit_index_space_iterator &xother)
Assignment operator.
Factory and container for a family of id spaces.
virtual bool invariant() const
Class invariant.
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
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.
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.