SheafSystem  0.0.0.0
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/implicit_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/index_space_family.h"
25 
26 // ===========================================================
27 // IMPLICIT_INDEX_SPACE_ITERATOR FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
34 {
35  // Preconditions:
36 
37  // Body:
38 
39  // Nothing to do;
40 
41  // Postconditions:
42 
43  // Exit:
44 
45  return;
46 }
47 
48 // PROTECTED MEMBER FUNCTIONS
49 
52  : _host(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(host() == xother.host());
80  ensure(index() == xother.index());
81 
82  // Exit:
83 
84  return;
85 }
86 
90 {
91  // Preconditions:
92 
93  // Body:
94 
95  if(xother.is_attached())
96  {
97  _host = xother._host;
98  _local_id = xother._local_id;
99 
100  (void) index_space_iterator::operator=(xother);
101  }
102 
103  // Postconditions:
104 
105  ensure(invariant());
106  ensure((*this) == xother);
107 
108  // Exit
109 
110  return *this;
111 }
112 
113 // PRIVATE MEMBER FUNCTIONS
114 
115 
116 // ===========================================================
117 // INDEX_SPACE_ITERATOR FACET
118 // ===========================================================
119 
120 // PUBLIC MEMBER FUNCTIONS
121 
125 {
126  // Preconditions:
127 
128  require(is_ancestor_of(&xother));
129 
130  // Body:
131 
132  const implicit_index_space_iterator& lother =
133  dynamic_cast<const implicit_index_space_iterator&>(xother);
134 
135  (void) this->operator=(lother);
136 
137  // Postconditions:
138 
139  ensure(invariant());
140  ensure((*this) == xother);
141 
142  // Exit
143 
144  return *this;
145 }
146 
147 bool
149 operator==(const index_space_iterator& xother) const
150 {
151  // Preconditions:
152 
153  require(is_ancestor_of(&xother));
154 
155  // Body:
156 
157  bool result = index_space_iterator::operator==(xother);
158  if(result && is_attached())
159  {
160  const implicit_index_space_iterator& lother =
161  dynamic_cast<const implicit_index_space_iterator&>(xother);
162 
163  result = result && (_host == lother._host);
164  result = result && (_local_id == lother._local_id);
165  }
166 
167  // Postconditions:
168 
169  ensure(is_basic_query);
170 
171  // Exit:
172 
173  return result;
174 }
175 
178 clone() const
179 {
181 
182  // Preconditions:
183 
184  // Body:
185 
186  result = 0; // Just to silence compiler warnings.
187 
188  is_abstract();
189 
190  // Postconditions:
191 
192  ensure(result != 0);
193  ensure(is_same_type(result));
194  ensure(*result == *this);
195 
196  // Exit:
197 
198  return result;
199 }
200 
201 // PROTECTED MEMBER FUNCTIONS
202 
203 // PRIVATE MEMBER FUNCTIONS
204 
205 
206 // ===========================================================
207 // HANDLE FACET
208 // ===========================================================
209 
210 // PUBLIC MEMBER FUNCTIONS
211 
214 host() const
215 {
216  // Preconditions:
217 
218  require(is_attached());
219 
220  // Body:
221 
222  const index_space_collection& result = *_host;
223 
224  // Postconditions:
225 
226  ensure(is_basic_query);
227 
228  // Exit:
229 
230  return result;
231 }
232 
235 index() const
236 {
237  // Preconditions:
238 
239  require(is_attached());
240 
241  // Body:
242 
244 
245  // Postconditions:
246 
247  ensure(id_spaces().contains(result));
248 
249  // Exit:
250 
251  return result;
252 }
253 
254 bool
256 is_attached() const
257 {
258  // Preconditions:
259 
260  // Body:
261 
262  bool result = is_valid(_local_id);
263 
264  // Postconditions:
265 
266  ensure(is_basic_query);
267 
268  // Exit:
269 
270  return result;
271 }
272 
273 void
276 {
277  // Preconditions:
278 
279  require(is_attached());
280  require(id_spaces().contains(xindex));
281  require(conforms_to_state(xindex));
282 
283  // Body:
284 
285  define_old_variable(const index_space_family& old_id_spaces = id_spaces());
286 
287  const index_space_collection* lhost =
288  _host->contains(xindex) ? _host : id_spaces().collection(xindex);
289 
290  attach_to(*lhost, lhost->local_scope(xindex));
291 
292  // Postconditions:
293 
294  ensure(invariant());
295  ensure(is_attached());
296  ensure(&id_spaces() == &old_id_spaces);
297  ensure(index() == xindex);
298 
299  // Exit:
300 
301  return;
302 }
303 
304 void
307 {
308  // Preconditions:
309 
310  // Body:
311 
313 
314  // Postconditions:
315 
316  ensure(!is_attached());
317 
318  // Exit:
319 
320  return;
321 }
322 
323 // PROTECTED MEMBER FUNCTIONS
324 
325 // PRIVATE MEMBER FUNCTIONS
326 
327 
328 // ===========================================================
329 // INDEX_SPACE_ITERATOR FACET
330 // ===========================================================
331 
332 // PUBLIC MEMBER FUNCTIONS
333 
334 // PROTECTED MEMBER FUNCTIONS
335 
336 // PRIVATE MEMBER FUNCTIONS
337 
338 
339 // ===========================================================
340 // ANY FACET
341 // ===========================================================
342 
343 // PUBLIC MEMBER FUNCTIONS
344 
345 bool
347 is_ancestor_of(const any *other) const
348 {
349  // Preconditions:
350 
351  require(other != 0);
352 
353  // Body:
354 
355  // True if other conforms to this
356 
357  bool result = dynamic_cast<const implicit_index_space_iterator*>(other) != 0;
358 
359  // Postconditions:
360 
361  // Exit:
362 
363  return result;
364 }
365 
366 bool
368 invariant() const
369 {
370  bool result = true;
371 
372  if(invariant_check())
373  {
374  // Must satisfy base class invariant
375 
376  invariance(index_space_iterator::invariant());
377 
378  // Prevent recursive calls to invariant
379 
381 
382  // Invariances for this class:
383 
384  // Finished, turn invariant checking back on.
385 
387  }
388 
389  // Exit
390 
391  return result;
392 }
393 
394 // PROTECTED MEMBER FUNCTIONS
395 
396 // PRIVATE MEMBER FUNCTIONS
397 
398 
399 // ===========================================================
400 // NON-MEMBER FUNCTIONS
401 // ===========================================================
402 
const index_space_collection * collection(pod_type xid) const
Id space collection for id xid (const version).
An abstract iterator over the ids of an id space.
virtual implicit_index_space_iterator * clone() const =0
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
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 pod_type local_scope(pod_type xspace_id) const =0
Id relative to this collection equivalent to the id space family id xspace_id.
virtual pod_type index() const
Index of this space.
virtual void detach()
Detach this iterator form its state, if any.
Abstract base class with useful features for all objects.
Definition: any.h:39
const index_space_family & id_spaces() const
The id space family for this (const version).
An implementation of class index_space_iterator for id spaces that are implicitly represtented...
virtual void attach_to(pod_type xindex)
Attach to the state with index xindex in the id space family id_spaces().
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 invariant() const
Class invariant.
virtual bool is_attached() const
True if this iterator is attached to a state.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
const index_space_collection * _host
The host collection.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
pod_type _local_id
The id of this space in the local host id space.
Factory and container for a family of id spaces.
virtual bool invariant() const
Class invariant.
implicit_index_space_iterator & operator=(const implicit_index_space_iterator &xother)
Assignment operator.
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
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual bool operator==(const index_space_iterator &xother) const
True if this is equivalent to xother.
bool conforms_to_state(const index_space_family &xid_spaces, pod_type xindex) const
True if this conforms to the handle type required by the state with index xindex in the id space fami...