SheafSystem  0.0.0.0
primary_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/primary_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/primary_index_space_state.h"
25 
26 // ===========================================================
27 // PRIMARY_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 
188  primary_index_space_state& result =
189  reinterpret_cast<primary_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 primary_index_space_state& result =
211  reinterpret_cast<const primary_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 // PRIMARY INDEX SPACE FACET
227 // ===========================================================
228 
229 // PUBLIC MEMBER FUNCTIONS
230 
233 offset() const
234 {
235  // Preconditions:
236 
237  require(is_attached());
238 
239  // Body:
240 
241  pod_type result = state().offset();
242 
243  // Postconditions:
244 
245  ensure(is_basic_query);
246 
247  // Exit:
248 
249  return result;
250 }
251 
252 void
255 {
256  // Preconditions:
257 
258  require(xct > ct());
259 
260  // Body:
261 
262  state().extend(xct);
263 
264  // Postconditions:
265 
266  ensure(ct() == xct);
267 
268  // Exit:
269 
270  return;
271 }
272 
275 hub_term_id() const
276 {
277  // Preconditions:
278 
279  // Body:
280 
281  pod_type result = state().hub_term_id();
282 
283  // Postconditions:
284 
285  ensure(is_basic_query);
286 
287  // Exit:
288 
289  return result;
290 }
291 
292 // PROTECTED MEMBER FUNCTIONS
293 
294 void
297 {
298  // Preconditions:
299 
300  // Body:
301 
302  state().put_hub_term_id(xhub_term_id);
303 
304  // Postconditions:
305 
306  ensure(hub_term_id() == xhub_term_id);
307 
308  // Exit:
309 
310  return;
311 }
312 
313 // PRIVATE MEMBER FUNCTIONS
314 
315 
316 // ===========================================================
317 // EXPLICIT_INDEX_SPACE_HANDLE FACET
318 // ===========================================================
319 
320 // PUBLIC MEMBER FUNCTIONS
321 
322 // PROTECTED MEMBER FUNCTIONS
323 
324 // PRIVATE MEMBER FUNCTIONS
325 
326 
327 // ===========================================================
328 // INDEX_SPACE_HANDLE FACET
329 // ===========================================================
330 
331 // PUBLIC MEMBER FUNCTIONS
332 
336 {
337  // Preconditions:
338 
339  require(xother.is_attached() ? conforms_to_state(xother) : true);
340 
341  // Body:
342 
343  attach_to(xother);
344 
345  // Postconditions:
346 
347  ensure(invariant());
348  ensure((*this) == xother);
349 
350  // Exit:
351 
352  return *this;
353 }
354 
357 clone() const
358 {
359  // Preconditions:
360 
361  // Body:
362 
364 
365  // Postconditions:
366 
367  ensure(result != 0);
368  ensure(is_same_type(result));
369  ensure(*result == *this);
370 
371  // Exit:
372 
373  return result;
374 }
375 
376 // PROTECTED MEMBER FUNCTIONS
377 
378 // PRIVATE MEMBER FUNCTIONS
379 
380 
381 // ===========================================================
382 // HANDLE FACET
383 // ===========================================================
384 
385 // PUBLIC MEMBER FUNCTIONS
386 
387 bool
390  pod_type xlocal_id) const
391 {
392  // Preconditions:
393 
394  require(xhost.contains(xlocal_id));
395 
396  // Body:
397 
398  bool result =
399  (dynamic_cast<primary_index_space_state*>(state(xhost, xlocal_id)) != 0);
400 
401  // Postconditions:
402 
403  ensure(is_basic_query);
404 
405  // Exit:
406 
407  return result;
408 }
409 
410 // PROTECTED MEMBER FUNCTIONS
411 
412 // PRIVATE MEMBER FUNCTIONS
413 
414 
415 // ===========================================================
416 // ANY FACET
417 // ===========================================================
418 
419 // PUBLIC MEMBER FUNCTIONS
420 
421 bool
423 is_ancestor_of(const any *other) const
424 {
425  // Preconditions:
426 
427  require(other != 0);
428 
429  // Body:
430 
431  // True if other conforms to this
432 
433  bool result = dynamic_cast<const primary_index_space_handle*>(other) != 0;
434 
435  // Postconditions:
436 
437  // Exit:
438 
439  return result;
440 }
441 
442 bool
444 invariant() const
445 {
446  bool result = true;
447 
448  if(invariant_check())
449  {
450  // Prevent recursive calls to invariant
451 
453 
454  // Must satisfy base class invariant
455 
457 
458  // Invariances for this class:
459 
460  // Finished, turn invariant checking back on.
461 
463  }
464 
465  // Exit
466 
467  return result;
468 }
469 
470 // PROTECTED MEMBER FUNCTIONS
471 
472 // PRIVATE MEMBER FUNCTIONS
473 
474 
475 // ===========================================================
476 // NON-MEMBER FUNCTIONS
477 // ===========================================================
478 
479 
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.
void put_hub_term_id(pod_type xhub_term_id)
Sets hub_term_id() to xhub_term_id.
primary_index_space_state & state()
The primary id space state (mutable version).
virtual void extend(size_type xct)
Extend this id space to have ct() == xct.
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.
An implementation of class explicit_index_space_handle that has a primary id space state...
Abstract base class with useful features for all objects.
Definition: any.h:39
pod_type hub_term_id() const
The term id of this in the hub id space.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
An implementation of class index_space_handle for an explicit_index_space_state.
pod_type offset() const
The offset into the hub id space.
std::string name() const
Name of this space.
pod_index_type pod_type
The "plain old data" index type for this.
void put_hub_term_id(pod_type xhub_term_id)
Sets hub_term_id() to xhub_term_id.
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
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
A computed implementation class explicit_index_space_state that is used for the terms of the primary ...
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...
primary_index_space_handle & operator=(const primary_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool invariant() const
Class invariant.
pod_type hub_term_id() const
The term id of this in the hub id space.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
virtual size_type ct() const
The number of members.
Factory and container for a family of id spaces.
pod_type offset() const
The offset into the hub id space.
virtual primary_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
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
void extend(size_type xct)
Extend this id space to have ct() == xct.