SheafSystem  0.0.0.0
reserved_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/reserved_primary_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/reserved_primary_index_space_state.h"
25 
26 // ===========================================================
27 // RESERVED_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 
189  reinterpret_cast<reserved_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 reserved_primary_index_space_state& result =
211  reinterpret_cast<const reserved_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 // RESERVED PRIMARY INDEX SPACE FACET
227 // ===========================================================
228 
229 // PUBLIC MEMBER FUNCTIONS
230 
234 {
235  // Preconditions:
236 
237  require(is_attached());
238 
239  // Body:
240 
241  define_old_variable(size_type old_ct = ct());
242  define_old_variable(pod_type old_next_hub_id = next_hub_id());
243 
244  pod_type result = state().new_id();
245 
246  // Postconditions:
247 
248  ensure(invariant());
249  ensure(next_hub_id() == old_next_hub_id + 1);
250 
251  // Exit:
252 
253  return result;
254 }
255 
259 {
260  // Preconditions:
261 
262  require(is_hub_id_available(xhub_id));
263 
264  // Body:
265 
266  define_old_variable(size_type old_ct = ct());
267  define_old_variable(pod_type old_next_hub_id = next_hub_id());
268 
269  pod_type result = state().new_hub_id(xhub_id);
270 
271  // Postconditions:
272 
273  ensure(invariant());
274  ensure(next_hub_id() >= old_next_hub_id);
275 
276  // Exit:
277 
278  return result;
279 }
280 
283 next_hub_id() const
284 {
285  // Preconditions:
286 
287  // Body:
288 
289  pod_type result = state().next_hub_id();
290 
291  // Postconditions:
292 
293  ensure(is_basic_query);
294 
295  // Exit:
296 
297  return result;
298 }
299 
300 bool
303 {
304  // Preconditions:
305 
306  // Body:
307 
308  bool result = state().is_next_id_available();
309 
310  // Postconditions:
311 
312  ensure(is_basic_query);
313 
314  // Exit:
315 
316  return result;
317 }
318 
319 bool
322 {
323  // Preconditions:
324 
325  // Body:
326 
327  bool result = state().is_hub_id_available(xhub_id);
328 
329  // Postconditions:
330 
331  ensure(is_basic_query);
332 
333  // Exit:
334 
335  return result;
336 }
337 
338 // PROTECTED MEMBER FUNCTIONS
339 
340 // PRIVATE MEMBER FUNCTIONS
341 
342 
343 // ===========================================================
344 // PRIMARY_INDEX_SPACE_HANDLE FACET
345 // ===========================================================
346 
347 // PUBLIC MEMBER FUNCTIONS
348 
349 // PROTECTED MEMBER FUNCTIONS
350 
351 // PRIVATE MEMBER FUNCTIONS
352 
353 
354 // ===========================================================
355 // INDEX_SPACE_HANDLE FACET
356 // ===========================================================
357 
358 // PUBLIC MEMBER FUNCTIONS
359 
363 {
364  // Preconditions:
365 
366  require(xother.is_attached() ? conforms_to_state(xother) : true);
367 
368  // Body:
369 
370  attach_to(xother);
371 
372  // Postconditions:
373 
374  ensure(invariant());
375  ensure((*this) == xother);
376 
377  // Exit:
378 
379  return *this;
380 }
381 
384 clone() const
385 {
386  // Preconditions:
387 
388  // Body:
389 
391 
392  // Postconditions:
393 
394  ensure(result != 0);
395  ensure(is_same_type(result));
396  ensure(*result == *this);
397 
398  // Exit:
399 
400  return result;
401 }
402 
403 // PROTECTED MEMBER FUNCTIONS
404 
405 // PRIVATE MEMBER FUNCTIONS
406 
407 
408 // ===========================================================
409 // HANDLE FACET
410 // ===========================================================
411 
412 // PUBLIC MEMBER FUNCTIONS
413 
414 bool
417  pod_type xlocal_id) const
418 {
419  // Preconditions:
420 
421  require(xhost.contains(xlocal_id));
422 
423  // Body:
424 
425  bool result =
426  (dynamic_cast<reserved_primary_index_space_state*>(state(xhost, xlocal_id)) != 0);
427 
428  // Postconditions:
429 
430  ensure(is_basic_query);
431 
432  // Exit:
433 
434  return result;
435 }
436 
437 // PROTECTED MEMBER FUNCTIONS
438 
439 // PRIVATE MEMBER FUNCTIONS
440 
441 
442 // ===========================================================
443 // ANY FACET
444 // ===========================================================
445 
446 // PUBLIC MEMBER FUNCTIONS
447 
448 bool
450 is_ancestor_of(const any *other) const
451 {
452  // Preconditions:
453 
454  require(other != 0);
455 
456  // Body:
457 
458  // True if other conforms to this
459 
460  bool result = dynamic_cast<const reserved_primary_index_space_handle*>(other) != 0;
461 
462  // Postconditions:
463 
464  // Exit:
465 
466  return result;
467 }
468 
469 bool
471 invariant() const
472 {
473  bool result = true;
474 
475  if(invariant_check())
476  {
477  // Prevent recursive calls to invariant
478 
480 
481  // Must satisfy base class invariant
482 
484 
485  // Invariances for this class:
486 
487  // Finished, turn invariant checking back on.
488 
490  }
491 
492  // Exit
493 
494  return result;
495 }
496 
497 // PROTECTED MEMBER FUNCTIONS
498 
499 // PRIVATE MEMBER FUNCTIONS
500 
501 
502 // ===========================================================
503 // NON-MEMBER FUNCTIONS
504 // ===========================================================
505 
506 
507 
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
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.
pod_type new_id()
Allocate the next available id in this space. Returns the allocated id in the hub id space...
A computed implementation of abstract class primary_index_space_state. This representation is used fo...
pod_type new_hub_id(pod_type xhub_id)
Allocate the hub id xhub_id in this space. Returns the allocated id in the hub id 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.
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
bool is_next_id_available() const
True if and only if the next id is available for allocation.
std::string name() const
Name of this space.
reserved_primary_index_space_handle & operator=(const reserved_primary_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
pod_index_type pod_type
The "plain old data" index type for this.
bool is_hub_id_available(pod_type xhub_id) const
True if and only if the hub id xhub_id is available for allocation.
reserved_primary_index_space_state & state()
The reserved primary id space state (mutable version).
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
pod_type new_id()
Allocate the next available id in this space. Returns the allocated id in the hub id space...
pod_type new_hub_id(pod_type xhub_id)
Allocate the hub id xhub_id in this space. Returns the allocated id in the hub id space...
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...
bool is_next_id_available() const
True if and only if the next id is available for allocation.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool invariant() const
Class invariant.
An implementation of class primary_index_space_handle that has a reserved primary id space state...
pod_type next_hub_id() const
The next available hub id for allocation.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
virtual reserved_primary_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
virtual size_type ct() const
The number of members.
Factory and container for a family of id spaces.
bool is_hub_id_available(pod_type xhub_id) const
True if and only if the hub id xhub_id is available for allocation.
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
pod_type next_hub_id() const
The next available hub id for allocation.