SheafSystem  0.0.0.0
scattered_insertion_index_space_handle.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/scattered_insertion_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/index_space_iterator.h"
25 #include "SheafSystem/scattered_insertion_index_space_state.h"
26 #include "SheafSystem/scoped_index.h"
27 
28 // ===========================================================
29 // SCATTERED_INSERTION_INDEX_SPACE_HANDLE FACET
30 // ===========================================================
31 
32 // PUBLIC MEMBER FUNCTIONS
33 
37 {
38  // Preconditions:
39 
40  // Body:
41 
42  // Postconditions:
43 
44  ensure(invariant());
45 
46  // Exit:
47 
48  return;
49 }
50 
53 {
54  // Preconditions:
55 
56  // Body:
57 
58  (*this) = xother;
59 
60  // Postconditions:
61 
62  ensure(invariant());
63  ensure((*this) == xother);
64 
65  // Exit:
66 
67  return;
68 }
69 
72  pod_type xindex)
73 {
74  // Preconditions:
75 
76  require(xid_spaces.contains(xindex));
77  require(conforms_to_state(xid_spaces, xindex));
78 
79  // Body:
80 
81  attach_to(xid_spaces, xindex);
82 
83  // Postconditions:
84 
85  ensure(invariant());
86  ensure(is_attached());
87  ensure(&id_spaces() == &xid_spaces);
88  ensure(index() == xindex);
89 
90  // Exit:
91 
92  return;
93 }
94 
96 scattered_insertion_index_space_handle(const index_space_family& xid_spaces, const std::string& xname)
97 {
98  // Preconditions:
99 
100  require(xid_spaces.contains(xname));
101  require(conforms_to_state(xid_spaces, xname));
102 
103  // Body:
104 
105  attach_to(xid_spaces, xname);
106 
107  // Postconditions:
108 
109  ensure(invariant());
110  ensure(is_attached());
111  ensure(&id_spaces() == &xid_spaces);
112  ensure(name() == xname);
113 
114  // Exit:
115 
116  return;
117 }
118 
122 {
123  // Preconditions:
124 
125  require(xother.is_attached() ? conforms_to_state(xother) : true);
126 
127  // Body:
128 
129  attach_to(xother);
130 
131  // Postconditions:
132 
133  ensure(invariant());
134  ensure((*this) == xother);
135 
136  // Exit:
137 
138  return *this;
139 }
140 
143 {
144  // Preconditions:
145 
146  // Body:
147 
148  // nothing to do.
149 
150  // Postconditions:
151 
152  // Exit:
153 
154  return;
155 }
156 
157 // PROTECTED MEMBER FUNCTIONS
158 
162 {
163  // Preconditions:
164 
165  require(is_attached());
166 
167  // Body:
168 
170  reinterpret_cast<scattered_insertion_index_space_state&>(*_state);
171 
172  // Postconditions:
173 
174  ensure(is_basic_query);
175 
176  // Exit:
177 
178  return result;
179 }
180 
183 state() const
184 {
185  // Preconditions:
186 
187  require(is_attached());
188 
189  // Body:
190 
192  reinterpret_cast<const scattered_insertion_index_space_state&>(*_state);
193 
194  // Postconditions:
195 
196  ensure(is_basic_query);
197 
198  // Exit:
199 
200  return result;
201 }
202 
203 // PRIVATE MEMBER FUNCTIONS
204 
205 
206 // ===========================================================
207 // MUTABLE INDEX SPACE FACET
208 // ===========================================================
209 
210 // PUBLIC MEMBER FUNCTIONS
211 
212 void
214 insert(pod_type xid, const scoped_index& xhub_id)
215 {
216  // Preconditions:
217 
218  require(is_attached());
219  require(xhub_id.in_scope());
220  require(precondition_of(insert(xid, xhub_id.hub_pod())));
221 
222  // Body:
223 
224  insert(xid, xhub_id.hub_pod());
225 
226  // Postconditions:
227 
228  ensure(postcondition_of(insert(xid, xhub_id.hub_pod())));
229 
230  // Exit:
231 
232  return;
233 }
234 
235 void
237 insert(pod_type xid, pod_type xhub_id)
238 {
239  // Preconditions:
240 
241  require(is_attached());
242  require(is_valid(xid));
243  require(is_valid(xhub_id));
244  require(!contains(xid));
245  require(!contains_hub(xhub_id));
246  require(hub_id_space().contains(xhub_id));
247 
248  // Body:
249 
250  define_old_variable(size_type old_ct = ct());
251  define_old_variable(pod_type old_begin = begin());
252  define_old_variable(pod_type old_end = end());
253 
254  state().insert(xid, xhub_id);
255 
256  // Postconditions:
257 
258  ensure(invariant());
259  ensure(contains(xid, xhub_id));
260  ensure(ct() == old_ct + 1);
261  ensure(ct() > 1 ? begin() <= old_begin : true);
262  ensure(begin() <= xid);
263  ensure(ct() > 1 ? end() >= old_end : true);
264  ensure(end() > xid);
265 
266  // Exit:
267 
268  return;
269 }
270 
271 // PROTECTED MEMBER FUNCTIONS
272 
273 // PRIVATE MEMBER FUNCTIONS
274 
275 // ===========================================================
276 // GATHERED_INSERTION_INDEX_SPACE_HANDLE FACET
277 // ===========================================================
278 
279 // PUBLIC MEMBER FUNCTIONS
280 
281 // PROTECTED MEMBER FUNCTIONS
282 
283 // PRIVATE MEMBER FUNCTIONS
284 
285 
286 // ===========================================================
287 // EXPLICIT_INDEX_SPACE_HANDLE FACET
288 // ===========================================================
289 
290 // PUBLIC MEMBER FUNCTIONS
291 
292 // PROTECTED MEMBER FUNCTIONS
293 
294 // PRIVATE MEMBER FUNCTIONS
295 
296 
297 // ===========================================================
298 // INDEX_SPACE_HANDLE FACET
299 // ===========================================================
300 
301 // PUBLIC MEMBER FUNCTIONS
302 
306 {
307  // Preconditions:
308 
309  require(xother.is_attached() ? conforms_to_state(xother) : true);
310 
311  // Body:
312 
313  attach_to(xother);
314 
315  // Postconditions:
316 
317  ensure(invariant());
318  ensure((*this) == xother);
319 
320  // Exit:
321 
322  return *this;
323 }
324 
327 clone() const
328 {
329  // Preconditions:
330 
331  // Body:
332 
334 
335  // Postconditions:
336 
337  ensure(result != 0);
338  ensure(is_same_type(result));
339  ensure(*result == *this);
340 
341  // Exit:
342 
343  return result;
344 }
345 
346 // PROTECTED MEMBER FUNCTIONS
347 
348 // PRIVATE MEMBER FUNCTIONS
349 
350 
351 // ===========================================================
352 // INDEX SPACE FACET
353 // ===========================================================
354 
355 // PUBLIC MEMBER FUNCTIONS
356 
357 // PROTECTED MEMBER FUNCTIONS
358 
359 // PRIVATE MEMBER FUNCTIONS
360 
361 
362 // ===========================================================
363 // HANDLE FACET
364 // ===========================================================
365 
366 // PUBLIC MEMBER FUNCTIONS
367 
368 bool
370 conforms_to_state(const index_space_collection& xhost, pod_type xlocal_id) const
371 {
372  // Preconditions:
373 
374  require(xhost.contains(xlocal_id));
375 
376  // Body:
377 
378  bool result =
379  (dynamic_cast<scattered_insertion_index_space_state*>(state(xhost, xlocal_id)) != 0);
380 
381  // Postconditions:
382 
383  ensure(is_basic_query);
384 
385  // Exit:
386 
387  return result;
388 }
389 
390 // PROTECTED MEMBER FUNCTIONS
391 
392 // PRIVATE MEMBER FUNCTIONS
393 
394 
395 // ===========================================================
396 // ANY FACET
397 // ===========================================================
398 
399 // PUBLIC MEMBER FUNCTIONS
400 
401 bool
403 is_ancestor_of(const any *other) const
404 {
405  // Preconditions:
406 
407  require(other != 0);
408 
409  // Body:
410 
411  // True if other conforms to this
412 
413  bool result = dynamic_cast<const scattered_insertion_index_space_handle*>(other) != 0;
414 
415  // Postconditions:
416 
417  // Exit:
418 
419  return result;
420 }
421 
422 bool
424 invariant() const
425 {
426  bool result = true;
427 
428  if(invariant_check())
429  {
430  // Prevent recursive calls to invariant
431 
433 
434  // Must satisfy base class invariant
435 
437 
438  // Invariances for this class:
439 
440  // Finished, turn invariant checking back on.
441 
443  }
444 
445  // Exit
446 
447  return result;
448 }
449 
450 // PROTECTED MEMBER FUNCTIONS
451 
452 // PRIVATE MEMBER FUNCTIONS
453 
454 
455 // ===========================================================
456 // NON-MEMBER FUNCTIONS
457 // ===========================================================
458 
459 size_t
460 sheaf::
461 deep_size(const scattered_insertion_index_space_handle& xn, bool xinclude_shallow)
462 {
463  // Preconditions:
464 
465  // Body:
466 
467  size_t result = xinclude_shallow ? sizeof(xn) : 0;
468 
469  // Postconditions:
470 
471  ensure(result >= 0);
472 
473  // Exit
474 
475  return result;
476 }
477 
scattered_insertion_index_space_state & state()
The mutable id space state (mutable version).
virtual void attach_to(pod_type xindex)
Attach to the state with index xindex in the id space family id_spaces().
virtual pod_type index() const
Index of this space.
bool in_scope() const
True if and only if scope() contains an entry for pod().
Definition: scoped_index.h:584
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...
scattered_insertion_index_space_handle & operator=(const scattered_insertion_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
An implementation of class explicit_index_space_state that supports either gathered or scattered inse...
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_attached() const =0
True if this handle is attached to a state.
const hub_index_space_handle & hub_id_space() const
The hub id space.
Abstract base class with useful features for all objects.
Definition: any.h:39
std::string name() const
Name of this space.
pod_index_type pod_type
The "plain old data" index type for this.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual bool is_attached() const
True if this handle is attached to a state.
A handle for a gathered_insertion_index_space_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
void insert(pod_type xid, const scoped_index &xhub_id)
Make id xid in this id space equivalent to xhub_id in the hub id space. synonym for insert(xid...
void insert(pod_type xid, const scoped_index &xhub_id)
Make id xid in this id space equivalent to xhub_id in the hub id space. synonym for insert(xid...
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...
virtual pod_type begin() const
Beginning id of this space.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
A handle for a scattered_insertion_index_space_state.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
virtual pod_type end() const
Ending id of this space.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual size_type ct() const
The number of members.
Factory and container for a family of id spaces.
virtual scattered_insertion_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
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
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 contains(pod_type xid) const
True if this space contains id xid.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710