SheafSystem  0.0.0.0
singleton_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/singleton_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/singleton_index_space_state.h"
25 
26 // ===========================================================
27 // SPACE FACTORY FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
35  const std::string& xname,
36  pod_type xhub_id)
37 {
38  // Preconditions:
39 
40  require(!xname.empty());
41  require(!xid_spaces.contains(xname));
42  require(xid_spaces.hub_id_space().contains(xhub_id));
43 
44  // Body:
45 
48  xname,
49  xhub_id);
50 
51  // Postconditions:
52 
53  ensure(&result.id_spaces() == &xid_spaces);
54  ensure(xid_spaces.contains(xname));
55  ensure(result.conforms_to_state(xname));
56 
57  ensure(result.name() == xname);
58  ensure(!result.is_persistent());
59 
60  ensure(result.hub_id() == xhub_id);
61  ensure(result.ct() == 1);
62  ensure(result.is_gathered());
63 
64  // Exit:
65 
66  return result;
67 }
68 
69 // PROTECTED MEMBER FUNCTIONS
70 
71 // PRIVATE MEMBER FUNCTIONS
72 
73 
74 // ===========================================================
75 // SINGLETON_INDEX_SPACE_HANDLE FACET
76 // ===========================================================
77 
78 // PUBLIC MEMBER FUNCTIONS
79 
83 {
84  // Preconditions:
85 
86  // Body:
87 
88  // Postconditions:
89 
90  ensure(invariant());
91 
92  // Exit:
93 
94  return;
95 }
96 
99 {
100  // Preconditions:
101 
102  // Body:
103 
104  (*this) = xother;
105 
106  // Postconditions:
107 
108  ensure(invariant());
109  ensure((*this) == xother);
110 
111  // Exit:
112 
113  return;
114 }
115 
118  pod_type xindex)
119 {
120  // Preconditions:
121 
122  require(xid_spaces.contains(xindex));
123  require(conforms_to_state(xid_spaces, xindex));
124 
125  // Body:
126 
127  attach_to(xid_spaces, xindex);
128 
129  // Postconditions:
130 
131  ensure(invariant());
132  ensure(is_attached());
133  ensure(&id_spaces() == &xid_spaces);
134  ensure(index() == xindex);
135 
136  // Exit:
137 
138  return;
139 }
140 
143  const std::string& xname)
144 {
145  // Preconditions:
146 
147  require(xid_spaces.contains(xname));
148  require(conforms_to_state(xid_spaces, xname));
149 
150  // Body:
151 
152  attach_to(xid_spaces, xname);
153 
154  // Postconditions:
155 
156  ensure(invariant());
157  ensure(is_attached());
158  ensure(&id_spaces() == &xid_spaces);
159  ensure(name() == xname);
160 
161  // Exit:
162 
163  return;
164 }
165 
169 {
170  // Preconditions:
171 
172  require(xother.is_attached() ? conforms_to_state(xother) : true);
173 
174  // Body:
175 
176  attach_to(xother);
177 
178  // Postconditions:
179 
180  ensure(invariant());
181  ensure((*this) == xother);
182 
183  // Exit:
184 
185  return *this;
186 }
187 
190 {
191  // Preconditions:
192 
193  // Body:
194 
195  // nothing to do.
196 
197  // Postconditions:
198 
199  // Exit:
200 
201  return;
202 }
203 
204 // PROTECTED MEMBER FUNCTIONS
205 
208 {
209  // Preconditions:
210 
211  // Body:
212 
213  attach_to(&xstate);
214 
215  // Postconditions:
216 
217  ensure(invariant());
218  ensure(is_attached());
219  ensure(&state() == &xstate);
220 
221  // Exit:
222 
223  return;
224 }
225 
229 {
230  // Preconditions:
231 
232  require(is_attached());
233 
234  // Body:
235 
237  reinterpret_cast<singleton_index_space_state&>(*_state);
238 
239  // Postconditions:
240 
241  ensure(is_basic_query);
242 
243  // Exit:
244 
245  return result;
246 }
247 
250 state() const
251 {
252  // Preconditions:
253 
254  require(is_attached());
255 
256  // Body:
257 
258  const singleton_index_space_state& result =
259  reinterpret_cast<const singleton_index_space_state&>(*_state);
260 
261  // Postconditions:
262 
263  ensure(is_basic_query);
264 
265  // Exit:
266 
267  return result;
268 }
269 
270 // PRIVATE MEMBER FUNCTIONS
271 
272 
273 // ===========================================================
274 // SINGLETON INDEX SPACE FACET
275 // ===========================================================
276 
277 // PUBLIC MEMBER FUNCTIONS
278 
281 hub_id() const
282 {
283  // Preconditions:
284 
285  require(is_attached());
286 
287  // Body:
288 
289  pod_type result = state().hub_id();
290 
291  // Postconditions:
292 
293  ensure(is_basic_query);
294 
295  // Exit:
296 
297  return result;
298 }
299 
300 // PROTECTED MEMBER FUNCTIONS
301 
302 // PRIVATE MEMBER FUNCTIONS
303 
304 
305 // ===========================================================
306 // EXPLICIT_INDEX_SPACE_HANDLE FACET
307 // ===========================================================
308 
309 // PUBLIC MEMBER FUNCTIONS
310 
311 // PROTECTED MEMBER FUNCTIONS
312 
313 // PRIVATE MEMBER FUNCTIONS
314 
315 
316 // ===========================================================
317 // INDEX_SPACE_HANDLE FACET
318 // ===========================================================
319 
320 // PUBLIC MEMBER FUNCTIONS
321 
325 {
326  // Preconditions:
327 
328  require(xother.is_attached() ? conforms_to_state(xother) : true);
329 
330  // Body:
331 
332  attach_to(xother);
333 
334  // Postconditions:
335 
336  ensure(invariant());
337  ensure((*this) == xother);
338 
339  // Exit:
340 
341  return *this;
342 }
343 
346 clone() const
347 {
348  // Preconditions:
349 
350  // Body:
351 
353 
354  // Postconditions:
355 
356  ensure(result != 0);
357  ensure(is_same_type(result));
358  ensure(*result == *this);
359 
360  // Exit:
361 
362  return result;
363 }
364 
365 // PROTECTED MEMBER FUNCTIONS
366 
367 // PRIVATE MEMBER FUNCTIONS
368 
369 
370 // ===========================================================
371 // HANDLE FACET
372 // ===========================================================
373 
374 // PUBLIC MEMBER FUNCTIONS
375 
376 bool
379  pod_type xlocal_id) const
380 {
381  // Preconditions:
382 
383  require(xhost.contains(xlocal_id));
384 
385  // Body:
386 
387  bool result =
388  (dynamic_cast<singleton_index_space_state*>(state(xhost, xlocal_id)) != 0);
389 
390  // Postconditions:
391 
392  ensure(is_basic_query);
393 
394  // Exit:
395 
396  return result;
397 }
398 
399 // PROTECTED MEMBER FUNCTIONS
400 
401 // PRIVATE MEMBER FUNCTIONS
402 
403 
404 // ===========================================================
405 // ANY FACET
406 // ===========================================================
407 
408 // PUBLIC MEMBER FUNCTIONS
409 
410 bool
412 is_ancestor_of(const any *other) const
413 {
414  // Preconditions:
415 
416  require(other != 0);
417 
418  // Body:
419 
420  // True if other conforms to this
421 
422  bool result = dynamic_cast<const singleton_index_space_handle*>(other) != 0;
423 
424  // Postconditions:
425 
426  // Exit:
427 
428  return result;
429 }
430 
431 bool
433 invariant() const
434 {
435  bool result = true;
436 
437  if(invariant_check())
438  {
439  // Prevent recursive calls to invariant
440 
442 
443  // Must satisfy base class invariant
444 
446 
447  // Invariances for this class:
448 
449  // Finished, turn invariant checking back on.
450 
452  }
453 
454  // Exit
455 
456  return result;
457 }
458 
459 // PROTECTED MEMBER FUNCTIONS
460 
461 // PRIVATE MEMBER FUNCTIONS
462 
463 
464 // ===========================================================
465 // NON-MEMBER FUNCTIONS
466 // ===========================================================
467 
468 
469 
470 
virtual singleton_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
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 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.
static singleton_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, pod_type xhub_id)
Create a new singleton id space in the id space family xid_space at the next available id space index...
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
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.
Abstract base class with useful features for all objects.
Definition: any.h:39
static singleton_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, pod_type xhub_id)
Create a new singleton id space in the id space family xid_space with name xname and hub id xhub_id...
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.
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.
pod_type hub_id() const
The hub id of the singleton id.
singleton_index_space_handle & operator=(const singleton_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_handle that has a singleton id space state...
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
pod_type hub_id() const
The hub id of the singleton id.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
An implementation of explicit_index_space_state for an id space containing a single id...
Factory and container for a family of id spaces.
singleton_index_space_state & state()
The singleton id space state (mutable version).
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
const hub_index_space_handle & hub_id_space() const
The hub id space of this family.
virtual bool contains(pod_type xid) const
True if this space contains id xid.