SheafSystem  0.0.0.0
primitives_index_space_state.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_state.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/deep_size.h"
24 #include "SheafSystem/index_space_family.h"
25 #include "SheafSystem/hub_index_space_handle.h"
26 #include "SheafSystem/explicit_index_space_handle.h"
27 #include "SheafSystem/primitives_index_space_handle.h"
28 #include "SheafSystem/primitives_index_space_iterator.h"
29 #include "SheafSystem/primitives_schema_member_index.h"
30 
31 namespace
32 {
33  const sheaf::size_type CT =
34  sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_END - sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_BEGIN;
35 
37 
38  const pod_type BEGIN = 0;
39  const pod_type END = CT;
40 
41  const pod_type HUB_BEGIN = sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_BEGIN;
42  const pod_type HUB_END = sheaf::PRIMITIVES_SCHEMA_MEMBER_INDEX_END;
43 }
44 
45 // ===========================================================
46 // SPACE FACTORY FACET
47 // ===========================================================
48 
49 // PUBLIC MEMBER FUNCTIONS
50 
54  const std::string& xname)
55 {
56  // Preconditions:
57 
58  require(!xname.empty());
59  require(!xid_spaces.contains(xname));
60 
61  // Body:
62 
64  lstate->new_state(xid_spaces, xname, false);
65 
66  primitives_index_space_handle result(*lstate);
67 
68  // Postconditions:
69 
70  ensure(&result.id_spaces() == &xid_spaces);
71  ensure(xid_spaces.contains(xname));
72  ensure(result.conforms_to_state(xname));
73 
74  ensure(result.name() == xname);
75  ensure(!result.is_persistent());
76 
77  // Exit:
78 
79  return result;
80 }
81 
85  pod_index_type xid,
86  const std::string& xname)
87 {
88  // Preconditions:
89 
90  require(!xid_spaces.contains(xid));
91  require(xid_spaces.is_explicit_interval(xid));
92  require(!xname.empty());
93  require(!xid_spaces.contains(xname));
94 
95  // Body:
96 
98  lstate->new_state(xid_spaces, xid, xname, false);
99 
100  primitives_index_space_handle result(*lstate);
101 
102  // Postconditions:
103 
104  ensure(&result.id_spaces() == &xid_spaces);
105  ensure(xid_spaces.contains(xname));
106  ensure(result.conforms_to_state(xname));
107 
108  ensure(result.index() == xid);
109  ensure(result.name() == xname);
110  ensure(!result.is_persistent());
111 
112  // Exit:
113 
114  return result;
115 }
116 
117 // PROTECTED MEMBER FUNCTIONS
118 
119 // PRIVATE MEMBER FUNCTIONS
120 
121 
122 // ===========================================================
123 // PRIMITIVES_INDEX_SPACE_STATE FACET
124 // ===========================================================
125 
126 // PUBLIC MEMBER FUNCTIONS
127 
128 // PROTECTED MEMBER FUNCTIONS
129 
133 {
134  // Preconditions:
135 
136  // Body:
137 
138  _ct = CT;
139  _begin = BEGIN;
140  _end = END;
141 
142  // Postconditions:
143 
144  ensure(invariant());
145 
146  // Exit:
147 
148  return;
149 }
150 
153 {
154  // Preconditions:
155 
156  // Body:
157 
158  // nothing to do.
159 
160  // Postconditions:
161 
162  // Exit:
163 
164  return;
165 }
166 
169 deep_size(bool xinclude_shallow) const
170 {
171  // Preconditions:
172 
173  // Body:
174 
175  size_type result = sheaf::deep_size(*this, xinclude_shallow);
176 
177  // Postconditions:
178 
179  ensure(result >= 0);
180 
181  // Exit:
182 
183  return result;
184 }
185 
186 // PRIVATE MEMBER FUNCTIONS
187 
188 
189 // ===========================================================
190 // EXPLICIT_INDEX_SPACE_STATE FACET
191 // ===========================================================
192 
193 // PUBLIC MEMBER FUNCTIONS
194 
195 bool
198 {
199  // Preconditions:
200 
201  require(is_ancestor_of(&xother));
202 
203  // Body:
204 
205  bool result = explicit_index_space_state::operator==(xother);
206 
207  // Postconditions:
208 
209  // Exit
210 
211  return result;
212 }
213 
214 // PROTECTED MEMBER FUNCTIONS
215 
219 {
220  // Preconditions:
221 
222  require(is_ancestor_of(&xother));
223 
224  // Body:
225 
226  (void) explicit_index_space_state::operator=(xother);
227 
228  // Postconditions:
229 
230  ensure(invariant());
231  ensure((*this) == xother);
232 
233  // Exit
234 
235  return *this;
236 }
237 
238 // PRIVATE MEMBER FUNCTIONS
239 
240 
241 // ===========================================================
242 // INDEX SPACE FACET
243 // ===========================================================
244 
245 // PUBLIC MEMBER FUNCTIONS
246 
247 bool
249 contains(pod_type xid) const
250 {
251  // Preconditions:
252 
253  // Body:
254 
255  bool result = (0 <= xid) && (xid < _end);
256 
257  // Postconditions:
258 
259  ensure(is_basic_query);
260 
261  // Exit
262 
263  return result;
264 }
265 
266 bool
269 {
270  // Preconditions:
271 
272  // Body:
273 
274  bool result = (HUB_BEGIN <= xhub_id) && (xhub_id < HUB_END);
275 
276  // Postconditions:
277 
278  ensure(is_basic_query);
279 
280  // Exit
281 
282  return result;
283 }
284 
287 pod(pod_type xhub_id) const
288 {
289  // Preconditions:
290 
291  // Body:
292 
293  pod_type result =
294  contains_hub(xhub_id) ? xhub_id - HUB_BEGIN : invalid_pod_index();
295 
296  // Postconditions:
297 
298  ensure(!is_valid(result) || contains(result));
299 
300  // Exit
301 
302  return result;
303 }
304 
308 {
309  // Preconditions:
310 
311  // Body:
312 
313  pod_type result = contains(xid) ? xid + HUB_BEGIN : invalid_pod_index();
314 
315  // Postconditions:
316 
317  ensure(!is_valid(result) || contains_unglued_hub(result));
318 
319  // Exit:
320 
321  return result;
322 }
323 
324 // PROTECTED MEMBER FUNCTIONS
325 
326 // PRIVATE MEMBER FUNCTIONS
327 
328 
329 // ===========================================================
330 // HANDLE POOL FACET
331 // ===========================================================
332 
333 // PUBLIC MEMBER FUNCTIONS
334 
338 {
339  // Preconditions:
340 
341  // Body:
342 
343  size_type result = handles().ct();
344 
345  // Postconditions:
346 
347  ensure(result >= 0);
348 
349  // Exit:
350 
351  return result;
352 }
353 
357 {
358  // Preconditions:
359 
360  // Body:
361 
362  size_type result = sheaf::deep_size(handles(), true);
363 
364  // Postconditions:
365 
366  ensure(result >= 0);
367 
368  // Exit:
369 
370  return result;
371 }
372 
376 {
377  // Preconditions:
378 
379  // Body:
380 
381  primitives_index_space_handle& result = handles().get();
382  attach(result);
383 
384  // Postconditions:
385 
386  ensure(result.is_attached());
387 
388  // Exit:
389 
390  return result;
391 }
392 
393 void
396 {
397  // Preconditions:
398 
399  require(allocated_id_space(xid_space));
400 
401  // Body:
402 
403  // Detach the handle.
404 
405  xid_space.detach();
406 
407  // Release the handle to the pool.
408 
409  handles().release(reinterpret_cast<primitives_index_space_handle&>(xid_space));
410 
411  // Postconditions:
412 
413  ensure(is_basic_query);
414 
415  // Exit:
416 
417  return;
418 }
419 
420 bool
422 allocated_id_space(const index_space_handle& xid_space) const
423 {
424  // Preconditions:
425 
426  // Body:
427 
428  const primitives_index_space_handle* lid_space =
429  dynamic_cast<const primitives_index_space_handle*>(&xid_space);
430 
431  bool result = (lid_space != 0) && handles().allocated(*lid_space);
432 
433  // Postconditions:
434 
435  ensure(is_basic_query);
436 
437  // Exit:
438 
439  return result;
440 }
441 
442 // PROTECTED MEMBER FUNCTIONS
443 
444 // PRIVATE MEMBER FUNCTIONS
445 
447 sheaf::primitives_index_space_state::
448 handles()
449 {
450  // Preconditions:
451 
452  // Body:
453 
455 
456  // Postconditions:
457 
458  ensure(is_basic_query);
459 
460  // Exit:
461 
462  return result;
463 }
464 
465 
466 // ===========================================================
467 // ITERATOR POOL FACET
468 // ===========================================================
469 
470 // PUBLIC MEMBER FUNCTIONS
471 
475 {
476  // Preconditions:
477 
478  // Body:
479 
480  size_type result = iterators().ct();
481 
482  // Postconditions:
483 
484  ensure(result >= 0);
485 
486  // Exit:
487 
488  return result;
489 }
490 
494 {
495  // Preconditions:
496 
497  // Body:
498 
499  size_type result = sheaf::deep_size(iterators(), true);
500 
501  // Postconditions:
502 
503  ensure(result >= 0);
504 
505  // Exit:
506 
507  return result;
508 }
509 
513 {
514  // Preconditions:
515 
516  // Body:
517 
518  primitives_index_space_iterator& result = iterators().get();
519  attach(result);
520 
521  // Postconditions:
522 
523  ensure(result.is_attached());
524 
525  // Exit:
526 
527  return result;
528 }
529 
530 void
533 {
534  // Preconditions:
535 
536  require(allocated_iterator(xitr));
537 
538  // Body:
539 
540  // Detach the iterator.
541 
542  xitr.detach();
543 
544  // Release the iterator to the pool.
545 
546  iterators().release(reinterpret_cast<primitives_index_space_iterator&>(xitr));
547 
548  // Postconditions:
549 
550  ensure(is_basic_query);
551 
552  // Exit:
553 
554  return;
555 }
556 
557 bool
560 {
561  // Preconditions:
562 
563  // Body:
564 
565  const primitives_index_space_iterator* litr =
566  dynamic_cast<const primitives_index_space_iterator*>(&xitr);
567 
568  bool result = (litr != 0) && iterators().allocated(*litr);
569 
570  // Postconditions:
571 
572  ensure(is_basic_query);
573 
574  // Exit:
575 
576  return result;
577 }
578 
579 // PROTECTED MEMBER FUNCTIONS
580 
581 // PRIVATE MEMBER FUNCTIONS
582 
584 sheaf::primitives_index_space_state::
585 iterators()
586 {
587  // Preconditions:
588 
589  // Body:
590 
592 
593  // Postconditions:
594 
595  ensure(is_basic_query);
596 
597  // Exit:
598 
599  return result;
600 }
601 
602 
603 // ===========================================================
604 // FACTORY FACET
605 // ===========================================================
606 
607 // PUBLIC MEMBER FUNCTIONS
608 
609 const std::string&
611 class_name() const
612 {
613  static const std::string result("primitives_index_space_state");
614  return result;
615 }
616 
619 clone() const
620 {
621  // Preconditions:
622 
623  // Body:
624 
626 
627  // Postconditions:
628 
629  ensure(result != 0);
630  ensure(is_same_type(result));
631 
632  // Exit:
633 
634  return result;
635 }
636 
637 // PROTECTED MEMBER FUNCTIONS
638 
639 // PRIVATE MEMBER FUNCTIONS
640 
641 bool
642 sheaf::primitives_index_space_state::
643 make_prototype()
644 {
645  // Preconditions:
646 
647  // Body:
648 
650 
651  id_space_factory().insert_prototype(lproto);
652 
653  // Postconditions:
654 
655  // Exit:
656 
657  return true;
658 }
659 
660 
661 // ===========================================================
662 // ANY FACET
663 // ===========================================================
664 
665 // PUBLIC MEMBER FUNCTIONS
666 
667 bool
669 is_ancestor_of(const any *other) const
670 {
671  // Preconditions:
672 
673  require(other != 0);
674 
675  // Body:
676 
677  // True if other conforms to this
678 
679  bool result = dynamic_cast<const primitives_index_space_state*>(other) != 0;
680 
681  // Postconditions:
682 
683  // Exit:
684 
685  return result;
686 }
687 
688 bool
690 invariant() const
691 {
692  bool result = true;
693 
694  if(invariant_check())
695  {
696  // Prevent recursive calls to invariant
697 
699 
700  // Must satisfy base class invariant
701 
703 
704  // Invariances for this class:
705 
706  invariance(is_gathered());
707 
708  // Finished, turn invariant checking back on.
709 
711  }
712 
713  // Exit
714 
715  return result;
716 }
717 
718 // PROTECTED MEMBER FUNCTIONS
719 
720 // PRIVATE MEMBER FUNCTIONS
721 
722 
723 // ===========================================================
724 // NON-MEMBER FUNCTIONS
725 // ===========================================================
726 
727 size_t
728 sheaf::
729 deep_size(const primitives_index_space_state& xn, bool xinclude_shallow)
730 {
731  // Preconditions:
732 
733  // Body:
734 
735  size_t result = xinclude_shallow ? sizeof(xn) : 0;
736 
737  // Add any contributions from the parent class.
738 
739  const explicit_index_space_state& ixn = static_cast<const explicit_index_space_state&>(xn);
740  result += deep_size(ixn, false);
741 
742  // Postconditions:
743 
744  ensure(result >= 0);
745 
746  // Exit
747 
748  return result;
749 }
bool contains_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space. synonym for contains...
virtual pod_type pod(pod_type xid) const
The pod index in this space equivalent to xid in the hub id space.
virtual pod_type index() const
Index of this space.
An abstract iterator over the ids of an id space.
virtual bool is_persistent() const
True if this id space should be written to disk.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual void detach()=0
Detach this handle form its state, if any.
bool is_gathered() const
True if begin() == 0 and end() == ct().
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
virtual const index_space_family & id_spaces() const
The id space family for this (const version).
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual void detach()=0
Detach this handle form its state, if any.
virtual bool contains_unglued_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space.
virtual bool allocated_iterator(const index_space_iterator &xitr) const
True if and only if id space iterator xitr was allocated by the iterator pool.
void attach(explicit_index_space_handle &xid_space) const
Attach the id space handle xid_space to this state.
pod_type _end
Ending id of this space.
virtual bool invariant() const
Class invariant.
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...
virtual bool allocated_id_space(const index_space_handle &xid_space) const
True if and only if id space handle xid_space was allocated by the handle pool.
virtual pod_type unglued_hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
virtual const std::string & class_name() const
The name of this class.
std::string name() const
Name of this space.
virtual bool is_attached() const
True if this handle is attached to a state.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual bool contains(pod_type xid) const
True if this space contains id xid.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
bool is_explicit_interval(pod_type xid)
True, if and only if the id space interval that contains index xid is an explicit interval...
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual size_type deep_size(bool xinclude_shallow) const
The deep size of this.
virtual void release_id_space(index_space_handle &xid_space) const
Returns the id space handle xid_space to the handle pool.
virtual primitives_index_space_state * clone() const
Virtual constructor; create a new instance of the same type at this.
An iterator over the id space for the primitives row dof id space.
static size_type handle_pool_deep_size()
The deep size of the handle pool.
An implementation of class explicit_index_space_handle that has a primitives id space state...
size_type _ct
The number of members.
virtual index_space_iterator & get_iterator() const
Allocates an id space iterator from the iterator pool.
static size_type iterator_pool_deep_size()
The deep size of the iterator pool.
virtual index_space_handle & get_id_space() const
Allocates an id space handle from the handle pool.
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 primitives_index_space_state & operator=(const explicit_index_space_state &xother)
Assignment operator.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
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...
virtual bool invariant() const
Class invariant.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
static size_type iterator_pool_ct()
The number of iterators in the pool.
static size_type handle_pool_ct()
The number of handles in the pool.
Factory and container for a family of id spaces.
static primitives_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname)
Create a new primitives id space in the id space family xid_space at the next available id space inde...
virtual void release_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
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
static factory< explicit_index_space_state > & id_space_factory()
A factory for making descendants of this class.
pod_type _begin
Beginning id of this space.
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
virtual bool is_attached() const
True if this iterator is attached to a state.
A reallocated pool of objects of type T. Objects in the pool are either allocated or stored in a free...
Definition: list_pool.h:42