SheafSystem  0.0.0.0
index_space_interval.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/index_space_interval.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 
25 // ===========================================================
26 // INDEX_SPACE_INTERVAL FACET
27 // ===========================================================
28 
29 // PUBLIC MEMBER FUNCTIONS
30 
33 {
34  // Preconditions:
35 
36  // Body:
37 
38  // nothing to do.
39 
40  // Postconditions:
41 
42  // Exit:
43 
44  return;
45 }
46 
49 begin() const
50 {
51  // Preconditions:
52 
53  // Body:
54 
55  pod_type result = _begin;
56 
57  // Postconditions:
58 
59  ensure(is_basic_query);
60 
61  // Exit:
62 
63  return result;
64 }
65 
68 end() const
69 {
70  // Preconditions:
71 
72  // Body:
73 
74  pod_type result = _end;
75 
76  // Postconditions:
77 
78  ensure(is_basic_query);
79 
80  // Exit:
81 
82  return result;
83 }
84 
85 bool
87 in_bounds(pod_type xspace_id) const
88 {
89  // Preconditions:
90 
91  // Body:
92 
93  bool result = (_begin <= xspace_id) && (xspace_id < _end);
94 
95  // Postconditions:
96 
97  ensure(is_basic_query);
98 
99  // Exit:
100 
101  return result;
102 }
103 
104 // PROTECTED MEMBER FUNCTIONS
105 
111 {
112  // Preconditions:
113 
114  // Body:
115 
116  // Postconditions:
117 
118  ensure(invariant());
119 
120  // Exit:
121 
122  return;
123 }
124 
125 void
128 {
129  // Preconditions:
130 
131  // Body:
132 
133  define_old_variable(size_type old_id_spaces_end = xid_spaces.end());
134 
135  _id_spaces = &xid_spaces;
136  _begin = _id_spaces->end();
137  _end = _begin + xub;
138 
139  _id_spaces->insert_interval(*this);
140 
141  // Postconditions:
142 
143  ensure(&id_spaces() == &xid_spaces);
144  ensure(begin() == old_id_spaces_end);
145  ensure(end() == xid_spaces.end());
146  ensure(end() == begin() + xub);
147 
148  // Exit:
149 
150  return;
151 }
152 
153 bool
156 {
157  // Preconditions:
158 
159  // Body:
160 
161  // Postconditions:
162 
163  ensure(is_basic_query);
164 
165  // Exit:
166 
167  return false;
168 }
169 
170 // PRIVATE MEMBER FUNCTIONS
171 
172 
173 // ===========================================================
174 // FACTORY FACET
175 // ===========================================================
176 
177 // PUBLIC MEMBER FUNCTIONS
178 
179 const std::string&
181 class_name() const
182 {
183  static const std::string result("index_space_interval");
184  return result;
185 }
186 
190 {
191  // Preconditions:
192 
193  // Body:
194 
195  static factory<index_space_interval> result;
196 
197  // Postconditions:
198 
199  // Exit:
200 
201  return result;
202 }
203 
206 clone() const
207 {
208  // Preconditions:
209 
210  // Body:
211 
212  index_space_interval* result = 0; // Just to silence compiler warnings.
213 
214  is_abstract();
215 
216  // Postconditions:
217 
218  ensure(result != 0);
219  ensure(is_same_type(result));
220 
221  // Exit:
222 
223  return result;
224 }
225 
226 // PROTECTED MEMBER FUNCTIONS
227 
228 // PRIVATE MEMBER FUNCTIONS
229 
230 
231 // ===========================================================
232 // INDEX_SPACE_COLLECTION FACET
233 // ===========================================================
234 
235 // PUBLIC MEMBER FUNCTIONS
236 
237 bool
239 operator==(const index_space_collection& xother) const
240 {
241  // Preconditions:
242 
243  require(is_ancestor_of(&xother));
244 
245  // Body:
246 
247  const index_space_interval& lother =
248  dynamic_cast<const index_space_interval&>(xother);
249 
250  bool result = (_begin == lother._begin);
251  result = result && (_end == lother._end);
252  result = result && (_id_spaces == lother._id_spaces);
253 
254  // Postconditions:
255 
256  // Exit
257 
258  return result;
259 }
260 
261 bool
263 contains(pod_type xlocal_id) const
264 {
265  // Preconditions:
266 
267  // Body:
268 
269  bool result = in_bounds(xlocal_id + _begin);
270 
271  // Postconditions:
272 
273  ensure(is_basic_query);
274 
275  // Exit:
276 
277  return result;
278 }
279 
280 bool
282 contains_family(pod_type xspace_id) const
283 {
284  // Preconditions:
285 
286  // Body:
287 
288  bool result = in_bounds(xspace_id);
289 
290  // Postconditions:
291 
292  ensure(is_basic_query);
293 
294  // Exit:
295 
296  return result;
297 }
298 
301 local_scope(pod_type xspace_id) const
302 {
303  // Preconditions:
304 
305  // Body:
306 
307  pod_type result =
308  contains_family(xspace_id) ? xspace_id - _begin : invalid_pod_index();
309 
310  // Postconditions:
311 
312  ensure(!is_valid(result) || contains(result));
313 
314  // Exit:
315 
316  return result;
317 }
318 
321 family_scope(pod_type xlocal_id) const
322 {
323  // Preconditions:
324 
325  // Body:
326 
327  pod_type result = xlocal_id + _begin;
328 
329  if(!contains_family(result))
330  {
331  result = invalid_pod_index();
332  }
333 
334  // Postconditions:
335 
336  ensure(!is_valid(result) || contains_family(result));
337 
338  // Exit:
339 
340  return result;
341 }
342 
343 // PROTECTED MEMBER FUNCTIONS
344 
348 {
349  // Preconditions:
350 
351  require(is_ancestor_of(&xother));
352 
353  // Body:
354 
355  const index_space_interval& lother =
356  dynamic_cast<const index_space_interval&>(xother);
357 
358  _begin = lother._begin;
359  _end = lother._end;
360  _id_spaces = lother._id_spaces;
361 
362  // Postconditions:
363 
364  ensure(invariant());
365  ensure((*this) == xother);
366 
367  // Exit:
368 
369  return *this;
370 }
371 
372 // PRIVATE MEMBER FUNCTIONS
373 
374 
375 // ===========================================================
376 // INDEX SPACE FACET
377 // ===========================================================
378 
379 // PUBLIC MEMBER FUNCTIONS
380 
383 id_spaces() const
384 {
385  // Preconditions:
386 
387  // Body:
388 
389  const index_space_family& result = *_id_spaces;
390 
391  // Postconditions:
392 
393  ensure(is_basic_query);
394 
395  // Exit:
396 
397  return result;
398 }
399 
403 {
404  // Preconditions:
405 
406  // Body:
407 
408  index_space_family& result = *_id_spaces;
409 
410  // Postconditions:
411 
412  ensure(is_basic_query);
413 
414  // Exit:
415 
416  return result;
417 }
418 
419 // PROTECTED MEMBER FUNCTIONS
420 
421 // PRIVATE MEMBER FUNCTIONS
422 
423 
424 // ===========================================================
425 // ANY FACET
426 // ===========================================================
427 
428 // PUBLIC MEMBER FUNCTIONS
429 
430 bool
432 is_ancestor_of(const any *other) const
433 {
434  // Preconditions:
435 
436  require(other != 0);
437 
438  // Body:
439 
440  // True if other conforms to this
441 
442  bool result = dynamic_cast<const index_space_interval*>(other) != 0;
443 
444  // Postconditions:
445 
446  // Exit:
447 
448  return result;
449 }
450 
451 bool
453 invariant() const
454 {
455  bool result = true;
456 
457  if(invariant_check())
458  {
459  // Prevent recursive calls to invariant
460 
462 
463  // Must satisfy base class invariant
464 
465  invariance(index_space_collection::invariant());
466 
467  // Invariances for this class:
468 
469  // Finished, turn invariant checking back on.
470 
472  }
473 
474  // Exit
475 
476  return result;
477 }
478 
479 // PROTECTED MEMBER FUNCTIONS
480 
481 // PRIVATE MEMBER FUNCTIONS
482 
483 
484 // ===========================================================
485 // NON-MEMBER FUNCTIONS
486 // ===========================================================
487 
488 std::ostream&
489 sheaf::
490 operator << (std::ostream& xos, const index_space_interval& xn)
491 {
492  // Preconditions:
493 
494  // Body:
495 
496  xos << "[" << xn.begin() << ", " << xn.end() << "] "
497  << xn.class_name() << std::endl;
498 
499  // Postconditions:
500 
501  // Exit:
502 
503  return xos;
504 }
505 
virtual bool contains_family(pod_type xspace_id) const
True if this collection contains the id space with family id xspace_id.
virtual pod_type local_scope(pod_type xspace_id) const
Id relative to this collection equivalent to the id space family id xspace_id.
virtual const std::string & class_name() const
The name of this class.
pod_type end() const
The ending index of the id spaces.
virtual const index_space_family & id_spaces() const
The id space family for this (const version).
virtual ~index_space_interval()
Destructor.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual index_space_interval & operator=(const index_space_collection &xother)
Assignment operator.
virtual bool invariant() const
Class invariant.
virtual bool operator==(const index_space_collection &xother) const
True if this is equivalent to xother.
pod_index_type pod_type
The "plain old data" index type for this.
virtual pod_type family_scope(pod_type xlocal_id) const
Id relative to the id space family equivalent to the local id xlocal_id.
index_space_family * _id_spaces
The index space family of this collection.
index_space_interval()
Default constructor.
Abstract base class with useful features for all objects.
Definition: any.h:39
An implemenation of index_space_collection that adds an interface for the interval [begin()...
pod_type _begin
Beginning space id of this interval in the id space family scope.
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
Definition: eval_family.h:49
void new_state(index_space_family &xid_spaces, size_type xub)
Create a new id space interval in the id space family xid_spaces with upper bound xub...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
pod_type _end
Ending space id of this interval in the id space family scope.
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
static factory< index_space_interval > & id_space_interval_factory()
A factory for making descendants of this class.
virtual bool supports_persistent_id_spaces() const
True, if this interval supports persistent id spaces.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual index_space_interval * clone() const =0
Virtual constructor; create a new instance of the same type at thi.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
pod_type end() const
Ending space id of this interval in the id space family scope.
virtual bool contains(pod_type xlocal_id) const
True if this collection contains the id space with local id xlocal_id.
Factory and container for a family of id spaces.
virtual bool invariant() const
Class invariant.
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
pod_type begin() const
Beginning space id of this interval in the id space family scope.
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
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
bool in_bounds(pod_type xspace_id) const
True if id xspace_id is in the bounds [begin(), end()).