SheafSystem  0.0.0.0
primitives_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/primitives_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/primitives_index_space_state.h"
25 
26 // ===========================================================
27 // PRIMITIVES_INDEX_SPACE_HANDLE FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  // Postconditions:
41 
42  ensure(invariant());
43 
44  // Exit:
45 
46  return;
47 }
48 
51 {
52  // Preconditions:
53 
54  // Body:
55 
56  (*this) = xother;
57 
58  // Postconditions:
59 
60  ensure(invariant());
61  ensure((*this) == xother);
62 
63  // Exit:
64 
65  return;
66 }
67 
70  pod_type xindex)
71 {
72  // Preconditions:
73 
74  require(xid_spaces.contains(xindex));
75  require(conforms_to_state(xid_spaces, xindex));
76 
77  // Body:
78 
79  attach_to(xid_spaces, xindex);
80 
81  // Postconditions:
82 
83  ensure(invariant());
84  ensure(is_attached());
85  ensure(&id_spaces() == &xid_spaces);
86  ensure(index() == xindex);
87 
88  // Exit:
89 
90  return;
91 }
92 
95  const std::string& xname)
96 {
97  // Preconditions:
98 
99  require(xid_spaces.contains(xname));
100  require(conforms_to_state(xid_spaces, xname));
101 
102  // Body:
103 
104  attach_to(xid_spaces, xname);
105 
106  // Postconditions:
107 
108  ensure(invariant());
109  ensure(is_attached());
110  ensure(&id_spaces() == &xid_spaces);
111  ensure(name() == xname);
112 
113  // Exit:
114 
115  return;
116 }
117 
121 {
122  // Preconditions:
123 
124  require(xother.is_attached() ? conforms_to_state(xother) : true);
125 
126  // Body:
127 
128  attach_to(xother);
129 
130  // Postconditions:
131 
132  ensure(invariant());
133  ensure((*this) == xother);
134 
135  // Exit:
136 
137  return *this;
138 }
139 
142 {
143  // Preconditions:
144 
145  // Body:
146 
147  // nothing to do.
148 
149  // Postconditions:
150 
151  // Exit:
152 
153  return;
154 }
155 
156 // PROTECTED MEMBER FUNCTIONS
157 
160 {
161  // Preconditions:
162 
163  // Body:
164 
165  attach_to(&xstate);
166 
167  // Postconditions:
168 
169  ensure(invariant());
170  ensure(is_attached());
171  ensure(&state() == &xstate);
172 
173  // Exit:
174 
175  return;
176 }
177 
181 {
182  // Preconditions:
183 
184  require(is_attached());
185 
186  // Body:
187 
189  reinterpret_cast<primitives_index_space_state&>(*_state);
190 
191  // Postconditions:
192 
193  ensure(is_basic_query);
194 
195  // Exit:
196 
197  return result;
198 }
199 
202 state() const
203 {
204  // Preconditions:
205 
206  require(is_attached());
207 
208  // Body:
209 
210  const primitives_index_space_state& result =
211  reinterpret_cast<const primitives_index_space_state&>(*_state);
212 
213  // Postconditions:
214 
215  ensure(is_basic_query);
216 
217  // Exit:
218 
219  return result;
220 }
221 
222 // PRIVATE MEMBER FUNCTIONS
223 
224 
225 // ===========================================================
226 // INDEX_SPACE_HANDLE FACET
227 // ===========================================================
228 
229 // PUBLIC MEMBER FUNCTIONS
230 
234 {
235  // Preconditions:
236 
237  require(xother.is_attached() ? conforms_to_state(xother) : true);
238 
239  // Body:
240 
241  attach_to(xother);
242 
243  // Postconditions:
244 
245  ensure(invariant());
246  ensure((*this) == xother);
247 
248  // Exit:
249 
250  return *this;
251 }
252 
255 clone() const
256 {
257  // Preconditions:
258 
259  // Body:
260 
262 
263  // Postconditions:
264 
265  ensure(result != 0);
266  ensure(is_same_type(result));
267  ensure(*result == *this);
268 
269  // Exit:
270 
271  return result;
272 }
273 
274 // PROTECTED MEMBER FUNCTIONS
275 
276 // PRIVATE MEMBER FUNCTIONS
277 
278 
279 // ===========================================================
280 // HANDLE FACET
281 // ===========================================================
282 
283 // PUBLIC MEMBER FUNCTIONS
284 
285 bool
288  pod_type xlocal_id) const
289 {
290  // Preconditions:
291 
292  require(xhost.contains(xlocal_id));
293 
294  // Body:
295 
296  bool result =
297  (dynamic_cast<primitives_index_space_state*>(state(xhost, xlocal_id)) != 0);
298 
299  // Postconditions:
300 
301  ensure(is_basic_query);
302 
303  // Exit:
304 
305  return result;
306 }
307 
308 // PROTECTED MEMBER FUNCTIONS
309 
310 // PRIVATE MEMBER FUNCTIONS
311 
312 
313 // ===========================================================
314 // ANY FACET
315 // ===========================================================
316 
317 // PUBLIC MEMBER FUNCTIONS
318 
319 bool
321 is_ancestor_of(const any *other) const
322 {
323  // Preconditions:
324 
325  require(other != 0);
326 
327  // Body:
328 
329  // True if other conforms to this
330 
331  bool result = dynamic_cast<const primitives_index_space_handle*>(other) != 0;
332 
333  // Postconditions:
334 
335  // Exit:
336 
337  return result;
338 }
339 
340 bool
342 invariant() const
343 {
344  bool result = true;
345 
346  if(invariant_check())
347  {
348  // Prevent recursive calls to invariant
349 
351 
352  // Must satisfy base class invariant
353 
355 
356  // Invariances for this class:
357 
358  // Finished, turn invariant checking back on.
359 
361  }
362 
363  // Exit
364 
365  return result;
366 }
367 
368 // PROTECTED MEMBER FUNCTIONS
369 
370 // PRIVATE MEMBER FUNCTIONS
371 
372 
373 // ===========================================================
374 // NON-MEMBER FUNCTIONS
375 // ===========================================================
376 
377 
378 
379 
380 
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 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.
primitives_index_space_state & state()
The primitives id space 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...
An implementation of class index_space_handle for an explicit_index_space_state.
std::string name() const
Name of this space.
pod_index_type pod_type
The "plain old data" index type for this.
virtual bool is_attached() const
True if this handle is attached to a state.
virtual bool invariant() const
Class invariant.
virtual bool invariant() const
Class invariant.
primitives_index_space_handle & operator=(const primitives_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
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.
An implementation of class explicit_index_space_handle that has a primitives id space state...
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
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 is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
virtual primitives_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
Factory and container for a family of id spaces.
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