SheafSystem  0.0.0.0
primitives_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/primitives_index_space_iterator.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/explicit_index_space_handle.h"
25 #include "SheafSystem/index_space_family.h"
26 #include "SheafSystem/primitives_index_space_state.h"
27 #include "SheafSystem/primitives_schema_member_index.h"
28 
29 namespace
30 {
31  const sheaf::size_type CT =
32  sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_END - sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_BEGIN;
33 
35 
36  const pod_type BEGIN = 0;
37  const pod_type END = CT;
38 
39  const pod_type HUB_BEGIN = sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_BEGIN;
40  const pod_type HUB_END = sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_END;
41 }
42 
43 // ===========================================================
44 // PRIMITIVES_INDEX_SPACE_ITERATOR FACET
45 // ===========================================================
46 
47 // PUBLIC MEMBER FUNCTIONS
48 
51 {
52  // Preconditions:
53 
54  // Body:
55 
56  // Postconditions:
57 
58  ensure(invariant());
59  ensure(!is_attached());
60 
61  // Exit:
62 
63  return;
64 }
65 
69 {
70  // Preconditions:
71 
72  // Body:
73 
74  // Postconditions:
75 
76  ensure(invariant());
77  ensure((*this) == xother);
78 
79  // Exit:
80 
81  return;
82 }
83 
86  pod_type xindex)
87 {
88  // Preconditions:
89 
90  require(conforms_to_state(xid_spaces, xindex));
91 
92  // Body:
93 
94  attach_to(xid_spaces, xindex);
95 
96  // Postconditions:
97 
98  ensure(invariant());
99  ensure(is_attached());
100  ensure(&id_spaces() == &xid_spaces);
101  ensure(index() == xindex);
102 
103  // Exit:
104 
105  return;
106 }
107 
110  const std::string& xname)
111 {
112  // Preconditions:
113 
114  require(conforms_to_state(xid_spaces, xname));
115 
116  // Body:
117 
118  attach_to(xid_spaces, xname);
119 
120  // Postconditions:
121 
122  ensure(invariant());
123  ensure(is_attached());
124  ensure(&id_spaces() == &xid_spaces);
125  ensure(name() == xname);
126 
127  // Exit:
128 
129  return;
130 }
131 
135 {
136  // Preconditions:
137 
138  // Body:
139 
140  if(xother.is_attached())
141  {
142  (void) explicit_index_space_iterator::operator=(xother);
143  }
144  else
145  {
146  detach();
147  }
148 
149  // Postconditions:
150 
151  ensure(invariant());
152  ensure((*this) == xother);
153 
154  // Exit
155 
156  return *this;
157 }
158 
161 {
162  // Preconditions:
163 
164  // Body:
165 
166  // No action required.
167 
168  // Postconditions:
169 
170  // Exit:
171 
172  return;
173 }
174 
175 // PROTECTED MEMBER FUNCTIONS
176 
177 // PRIVATE MEMBER FUNCTIONS
178 
179 
180 // ===========================================================
181 // EXPLICIT_INDEX_SPACE_ITERATOR FACET
182 // ===========================================================
183 
184 // PUBLIC MEMBER FUNCTIONS
185 
186 // PROTECTED MEMBER FUNCTIONS
187 
188 // PRIVATE MAMBER FUNCTIONS
189 
190 
191 // ===========================================================
192 // INDEX_SPACE_ITERATOR FACET
193 // ===========================================================
194 
195 // PUBLIC MEMBER FUNCTIONS
196 
200 {
201  // Preconditions:
202 
203  require(is_ancestor_of(&xother));
204 
205  // Body:
206 
207  const primitives_index_space_iterator& lother =
208  dynamic_cast<const primitives_index_space_iterator&>(xother);
209 
210  (void) this->operator=(lother);
211 
212  // Postconditions:
213 
214  ensure(invariant());
215  ensure((*this) == xother);
216 
217  // Exit
218 
219  return *this;
220 }
221 
224 clone() const
225 {
227 
228  // Preconditions:
229 
230  // Body:
231 
232  result = new primitives_index_space_iterator(*this);
233 
234  // Postconditions:
235 
236  ensure(result != 0);
237  ensure(is_same_type(result));
238  ensure(*result == *this);
239 
240  // Exit:
241 
242  return result;
243 }
244 
245 // PROTECTED MEMBER FUNCTIONS
246 
247 // PRIVATE MAMBER FUNCTIONS
248 
249 
250 // ===========================================================
251 // ITERATOR FACET
252 // ===========================================================
253 
254 // PUBLIC MEMBER FUNCTIONS
255 
256 void
259 {
260  // Preconditions:
261 
262  require(is_attached());
263  require(!is_done());
264 
265  // Body:
266 
267  define_old_variable(pod_type old_pod = pod());
268  define_old_variable(pod_type old_hub_pod = hub_pod());
269 
270  // Increment to the next entry.
271 
272  ++_pod;
273  if(_pod == CT)
274  {
275  // The iteration is done.
276 
277  invalidate_ids();
278  }
279  else
280  {
281  ++_hub_pod;
282  }
283 
284  // Postconditions:
285 
286  ensure(invariant());
287  ensure(is_done() || pod() == (old_pod + 1));
288  ensure(is_done() || hub_pod() == (old_hub_pod + 1));
289 
290  // Exit:
291 
292  return;
293 }
294 
295 void
298 {
299  // Preconditions:
300 
301  require(is_attached());
302 
303  // Body:
304 
305  _is_done = false;
306 
307  _pod = BEGIN;
308  _hub_pod = HUB_BEGIN;
309 
310  // Postconditions:
311 
312  ensure(invariant());
313 
314  // Exit:
315 
316  return;
317 }
318 
319 // PROTECTED MEMBER FUNCTIONS
320 
321 // PRIVATE MAMBER FUNCTIONS
322 
323 
324 // ===========================================================
325 // HANDLE FACET
326 // ===========================================================
327 
328 // PUBLIC MEMBER FUNCTIONS
329 
330 void
333 {
334  // Preconditions:
335 
336  require(xstate != 0);
337  require(conforms_to_state(xstate));
338 
339  // Body:
340 
341  // Assign the state information.
342 
343  _state = xstate;
344 
345  // Reset the iterator.
346 
347  reset();
348 
349  // Postconditions:
350 
351  ensure(invariant());
352  ensure(is_attached());
353  ensure(&state() == xstate);
354 
355  // Exit:
356 
357  return;
358 }
359 
360 bool
363 {
364  // Preconditions:
365 
366  // Body:
367 
368  bool result = (dynamic_cast<primitives_index_space_state*>(xstate) != 0);
369 
370  // Postconditions:
371 
372  ensure(is_basic_query);
373 
374  // Exit:
375 
376  return result;
377 }
378 
379 // PROTECTED MEMBER FUNCTIONS
380 
381 // PRIVATE MAMBER FUNCTIONS
382 
383 
384 // ===========================================================
385 // ANY FACET
386 // ===========================================================
387 
388 // PUBLIC MEMBER FUNCTIONS
389 
390 bool
392 is_ancestor_of(const any *other) const
393 {
394  // Preconditions:
395 
396  require(other != 0);
397 
398  // Body:
399 
400  // True if other conforms to this
401 
402  bool result = dynamic_cast<const primitives_index_space_iterator*>(other) != 0;
403 
404  // Postconditions:
405 
406  // Exit:
407 
408  return result;
409 }
410 
411 bool
413 invariant() const
414 {
415  bool result = true;
416 
417  if(invariant_check())
418  {
419  // Must satisfy base class invariant
420 
422 
423  // Prevent recursive calls to invariant
424 
426 
427  // Invariances for this class:
428 
429  // Finished, turn invariant checking back on.
430 
432  }
433 
434  // Exit
435 
436  return result;
437 }
438 
439 // PROTECTED MEMBER FUNCTIONS
440 
441 // PRIVATE MEMBER FUNCTIONS
442 
443 
444 // ===========================================================
445 // NON-MEMBER FUNCTIONS
446 // ===========================================================
virtual void reset()
Restarts the iteration.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual pod_type index() const
Index of this space.
An abstract iterator over the ids of an id space.
bool _is_done
True if the iteration is finished.
pod_type pod() const
The current id in the iteration.
primitives_index_space_iterator & operator=(const primitives_index_space_iterator &xother)
Assignment operator.
virtual void attach_to(explicit_index_space_state *xstate)
Attach to the explicit id space state xstate.
void invalidate_ids()
Set is_done() and invalidate pod() and hub_pod().
virtual bool invariant() const
Class invariant.
explicit_index_space_state & state()
The explicit state (mutable version).
Abstract base class with useful features for all objects.
Definition: any.h:39
A implementation of abstract class explicit_index_space_state for the primitives row dof id space...
std::string name() const
Name of this space.
bool is_done() const
True if iteration is finished.
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).
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
pod_type _hub_pod
The current hub id in the iteration.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
An iterator over the id space for the primitives row dof id space.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
pod_index_type pod_type
The "plain old data" index type for this.
virtual void next()
Makes item() the next id in the iteration.
An implementation of class index_space_iterator for an explicit_index_space_state.
virtual primitives_index_space_iterator * clone() const
Virtual constructor, makes a new instance of the same type as this. If the iterator is attached...
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.
pod_type _pod
The current id in the iteration.
Factory and container for a family of id spaces.
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...
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.
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().