SheafSystem  0.0.0.0
list_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/list_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/list_index_space_state.h"
25 
26 // ===========================================================
27 // SPACE FACTORY FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
35  const std::string& xname,
36  bool xis_persistent)
37 {
38  // Preconditions:
39 
40  require(!xname.empty());
41  require(!xid_spaces.contains(xname));
42  // Body:
43 
46  xname,
47  xis_persistent);
48 
49  // Postconditions:
50 
51  ensure(&result.id_spaces() == &xid_spaces);
52  ensure(xid_spaces.contains(xname));
53  ensure(result.conforms_to_state(xname));
54 
55  ensure(result.is_persistent() == xis_persistent);
56  ensure(result.name() == xname);
57 
58  // Exit:
59 
60  return result;
61 }
62 
63 // PROTECTED MEMBER FUNCTIONS
64 
65 // PRIVATE MEMBER FUNCTIONS
66 
67 
68 // ===========================================================
69 // LIST_INDEX_SPACE_HANDLE FACET
70 // ===========================================================
71 
72 // PUBLIC MEMBER FUNCTIONS
73 
77 {
78  // Preconditions:
79 
80  // Body:
81 
82  // Postconditions:
83 
84  ensure(invariant());
85 
86  // Exit:
87 
88  return;
89 }
90 
93 {
94  // Preconditions:
95 
96  // Body:
97 
98  (*this) = xother;
99 
100  // Postconditions:
101 
102  ensure(invariant());
103  ensure((*this) == xother);
104 
105  // Exit:
106 
107  return;
108 }
109 
112  pod_type xindex)
113 {
114  // Preconditions:
115 
116  require(xid_spaces.contains(xindex));
117  require(conforms_to_state(xid_spaces, xindex));
118 
119  // Body:
120 
121  attach_to(xid_spaces, xindex);
122 
123  // Postconditions:
124 
125  ensure(invariant());
126  ensure(is_attached());
127  ensure(&id_spaces() == &xid_spaces);
128  ensure(index() == xindex);
129 
130  // Exit:
131 
132  return;
133 }
134 
137  const std::string& xname)
138 {
139  // Preconditions:
140 
141  require(xid_spaces.contains(xname));
142  require(conforms_to_state(xid_spaces, xname));
143 
144  // Body:
145 
146  attach_to(xid_spaces, xname);
147 
148  // Postconditions:
149 
150  ensure(invariant());
151  ensure(is_attached());
152  ensure(&id_spaces() == &xid_spaces);
153  ensure(name() == xname);
154 
155  // Exit:
156 
157  return;
158 }
159 
163 {
164  // Preconditions:
165 
166  require(xother.is_attached() ? conforms_to_state(xother) : true);
167 
168  // Body:
169 
170  attach_to(xother);
171 
172  // Postconditions:
173 
174  ensure(invariant());
175  ensure((*this) == xother);
176 
177  // Exit:
178 
179  return *this;
180 }
181 
184 {
185  // Preconditions:
186 
187  // Body:
188 
189  // nothing to do.
190 
191  // Postconditions:
192 
193  // Exit:
194 
195  return;
196 }
197 
198 void
200 reverse(bool xupdate_extrema)
201 {
202  // Preconditions:
203 
204  // Body:
205 
206  state().reverse(xupdate_extrema);
207 
208  // Postconditions:
209 
210  // Exit:
211 
212  return;
213 }
214 
217 front() const
218 {
219  return state().front();
220 }
221 
224 back() const
225 {
226  return state().back();
227 }
228 
229 void
232 {
233  // cout << endl << "Entering list_index_space_handle::push_front." << endl;
234 
235  // Preconditions:
236 
237  require(!contains_unglued_hub(xhub_id));
238 
239  // Body:
240 
241  define_old_variable(size_type old_ct = ct());
242  define_old_variable(pod_type old_begin = begin());
243  define_old_variable(pod_type old_end = end());
244 
245  state().push_front(xhub_id);
246 
247  // Postconditions:
248 
249  ensure(invariant());
250  ensure(unglued_hub_pod(0) == xhub_id);
251  ensure(ct() == old_ct + 1);
252  ensure(begin() == 0);
253  ensure(ct() > 1 ? end() == old_end+1 : end() == 1);
254 
255  // Exit:
256 
257  // cout << "Leaving list_index_space_handle::push_front." << endl;
258  return;
259 }
260 
261 void
263 replace_range_id(pod_type xold_range_id, pod_type xnew_range_id)
264 {
265  // cout << endl << "Entering list_index_space_handle::replace_range_id." << endl;
266 
267  // Preconditions:
268 
269  require((xnew_range_id != xold_range_id) ? !contains_unglued_hub(xnew_range_id) : true);
270 
271  // Body:
272 
273  define_old_variable(bool old_contains_xold_range_id = contains_unglued_hub(xold_range_id));
274  define_old_variable(pod_type old_domain_id = pod(xold_range_id));
275 
276 
277  state().replace_range_id(xold_range_id, xnew_range_id);
278 
279  // Postconditions:
280 
281  ensure(invariant());
282 
283  ensure(old_contains_xold_range_id ? contains_unglued_hub(xnew_range_id) : true);
284  ensure((xnew_range_id != xold_range_id) ? !contains_unglued_hub(xold_range_id) : true);
285  ensure(old_contains_xold_range_id ? pod(xnew_range_id) == old_domain_id : true);
286 
287  // Exit:
288 
289  // cout << "Leaving list_index_space_handle::replace_range_id." << endl;
290  return;
291 }
292 
293 // PROTECTED MEMBER FUNCTIONS
294 
297 {
298  // Preconditions:
299 
300  // Body:
301 
302  attach_to(&xstate);
303 
304  // Postconditions:
305 
306  ensure(invariant());
307  ensure(is_attached());
308  ensure(&state() == &xstate);
309 
310  // Exit:
311 
312  return;
313 }
314 
318 {
319  // Preconditions:
320 
321  require(is_attached());
322 
323  // Body:
324 
325  list_index_space_state& result =
326  reinterpret_cast<list_index_space_state&>(*_state);
327 
328  // Postconditions:
329 
330  ensure(is_basic_query);
331 
332  // Exit:
333 
334  return result;
335 }
336 
339 state() const
340 {
341  // Preconditions:
342 
343  require(is_attached());
344 
345  // Body:
346 
347  const list_index_space_state& result =
348  reinterpret_cast<const list_index_space_state&>(*_state);
349 
350  // Postconditions:
351 
352  ensure(is_basic_query);
353 
354  // Exit:
355 
356  return result;
357 }
358 
359 // PRIVATE MEMBER FUNCTIONS
360 
361 
362 // ===========================================================
363 // MUTABLE INDEX SPACE FACET
364 // ===========================================================
365 
366 // PUBLIC MEMBER FUNCTIONS
367 
368 // PROTECTED MEMBER FUNCTIONS
369 
370 // PRIVATE MEMBER FUNCTIONS
371 
372 // ===========================================================
373 // MAP REPRESENTATION FACET
374 // ===========================================================
375 
376 // PUBLIC MEMBER FUNCTIONS
377 
381 {
382  return state().to_range();
383 }
384 
387 to_range() const
388 {
389  return state().to_range();
390 }
391 
392 // PROTECTED MEMBER FUNCTIONS
393 
394 // PRIVATE MEMBER FUNCTIONS
395 
396 // ===========================================================
397 // INDEX_SPACE_HANDLE FACET
398 // ===========================================================
399 
400 // PUBLIC MEMBER FUNCTIONS
401 
405 {
406  // Preconditions:
407 
408  require(xother.is_attached() ? conforms_to_state(xother) : true);
409 
410  // Body:
411 
412  attach_to(xother);
413 
414  // Postconditions:
415 
416  ensure(invariant());
417  ensure((*this) == xother);
418 
419  // Exit:
420 
421  return *this;
422 }
423 
426 clone() const
427 {
428  // Preconditions:
429 
430  // Body:
431 
433 
434  // Postconditions:
435 
436  ensure(result != 0);
437  ensure(is_same_type(result));
438  ensure(*result == *this);
439 
440  // Exit:
441 
442  return result;
443 }
444 
445 // PROTECTED MEMBER FUNCTIONS
446 
447 // PRIVATE MEMBER FUNCTIONS
448 
449 
450 // ===========================================================
451 // HANDLE FACET
452 // ===========================================================
453 
454 // PUBLIC MEMBER FUNCTIONS
455 
456 bool
459  pod_type xlocal_id) const
460 {
461  // Preconditions:
462 
463  require(xhost.contains(xlocal_id));
464 
465  // Body:
466 
467  bool result =
468  (dynamic_cast<list_index_space_state*>(state(xhost, xlocal_id)) != 0);
469 
470  // Postconditions:
471 
472  ensure(is_basic_query);
473 
474  // Exit:
475 
476  return result;
477 }
478 
479 // PROTECTED MEMBER FUNCTIONS
480 
481 // PRIVATE MEMBER FUNCTIONS
482 
483 
484 // ===========================================================
485 // ANY FACET
486 // ===========================================================
487 
488 // PUBLIC MEMBER FUNCTIONS
489 
490 bool
492 is_ancestor_of(const any *other) const
493 {
494  // Preconditions:
495 
496  require(other != 0);
497 
498  // Body:
499 
500  // True if other conforms to this
501 
502  bool result = dynamic_cast<const list_index_space_handle*>(other) != 0;
503 
504  // Postconditions:
505 
506  // Exit:
507 
508  return result;
509 }
510 
511 bool
513 invariant() const
514 {
515  bool result = true;
516 
517  if(invariant_check())
518  {
519  // Prevent recursive calls to invariant
520 
522 
523  // Must satisfy base class invariant
524 
526 
527  // Invariances for this class:
528 
529  // Finished, turn invariant checking back on.
530 
532  }
533 
534  // Exit
535 
536  return result;
537 }
538 
539 // PROTECTED MEMBER FUNCTIONS
540 
541 // PRIVATE MEMBER FUNCTIONS
542 
543 
544 // ===========================================================
545 // NON-MEMBER FUNCTIONS
546 // ===========================================================
547 
548 
549 std::ostream&
550 sheaf::
551 operator << (std::ostream& xos, const list_index_space_handle& xi)
552 {
553  // Preconditions:
554 
555  // Body:
556 
557  using namespace std;
558 
559  if(xi.is_attached())
560  {
561  // Output the raw list.
562 
563  xos << "list: ";
565  for(to_range_type::const_iterator i = xi.state().to_range().begin(); i != xi.state().to_range().end(); ++i)
566  {
567  xos << " " << *i;
568  }
569  xos << endl << endl;
570 
571  // Output the usual id space info.
572 
573  xos << static_cast<const index_space_handle&>(xi);
574  }
575  else
576  {
577  xos << "index_space: index = -1 name = \'\'"
578  << endl;
579  }
580 
581  // Postconditions:
582 
583  // Exit:
584 
585  return xos;
586 }
587 
588 
589 
590 
to_range_type & to_range()
The representation of the domain id to range id map. Warning: direct manipulation of the to_range map...
pod_type front() const
The front of the list used to represent this id space; equivalent to hub_pod(begin()).
std::list< pod_type > to_range_type
The type of the domain id to range id map.
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.
An list implementation of class gathered_insertion_index_space_state. This representation is intended...
void reverse(bool xupdate_extrema)
Reverse the order, for instance hub_pod(new 0) = hub_pod(old last);.
static list_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent)
Create a new list id space in the id space family xid_space at the next available id space index with...
virtual list_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
An map implementation of class scattered_insertion_index_space_handle. This representation is intende...
to_range_type & to_range()
The representation of the domain id to range id map. Warning: direct manipulation of the to_range map...
STL namespace.
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.
static list_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent)
Create a new list id space in the id space family xid_space with name xname, and persistence xis_pers...
virtual bool is_attached() const =0
True if this handle is attached to a state.
pod_type back() const
The back of the list used to represent this id space; equivalent to hub_pod(last id).
virtual pod_type pod(pod_type xid) const
The pod index in this space equivalent to xid in the hub id space.
Abstract base class with useful features for all objects.
Definition: any.h:39
pod_type front() const
The front of the list used to represent this id space; equivalent to hub_pod(begin()).
std::string name() const
Name of this space.
pod_index_type pod_type
The "plain old data" index type for this.
void push_front(pod_type xhub_id)
Pushes hub id xhub_id onto the front of the list used to represent this id space; increments the doma...
virtual bool is_attached() const
True if this handle is attached to a state.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
list_index_space_handle & operator=(const list_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
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 contains_unglued_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space.
virtual ~list_index_space_handle()
Destructor.
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.
void push_front(pod_type xhub_id)
Pushes hub id xhub_id onto the front of the list used to represent this id space; increments the doma...
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.
virtual pod_type begin() const
Beginning id of this space.
list_index_space_handle()
Default constructor.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
pod_type back() const
The back of the list used to represent this id space; equivalent to hub_pod(last id).
std::list< pod_type > to_range_type
The type of the domain id to range id map.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
A handle for a scattered_insertion_index_space_state.
void replace_range_id(pod_type xold_range_id, pod_type xnew_range_id)
Replaces xold_range_id with xnew_range_id.
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.
void replace_range_id(pod_type xold_range_id, pod_type xnew_range_id)
Replaces xold_range_id with xnew_range_id.
list_index_space_state & state()
The list id space state (mutable version).
virtual size_type ct() const
The number of members.
virtual bool invariant() const
Class invariant.
Factory and container for a family of id spaces.
void reverse(bool xupdate_extrema)
Reverse the order, for instance hub_pod(new 0) = hub_pod(old last);.
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