SheafSystem  0.0.0.0
offset_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/offset_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/offset_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 xoffset,
37  size_type xct)
38 {
39  // Preconditions:
40 
41  require(!xname.empty());
42  require(!xid_spaces.contains(xname));
43  require(xoffset >= 0);
44  require(xct > 0);
45 
46  // Body:
47 
50  xname,
51  xoffset,
52  xct);
53 
54  // Postconditions:
55 
56  ensure(&result.id_spaces() == &xid_spaces);
57  ensure(xid_spaces.contains(xname));
58  ensure(result.conforms_to_state(xname));
59 
60  ensure(result.name() == xname);
61  ensure(!result.is_persistent());
62 
63  ensure(result.offset() == xoffset);
64  ensure(result.ct() == xct);
65  ensure(result.is_gathered());
66 
67  // Exit:
68 
69  return result;
70 }
71 
72 // PROTECTED MEMBER FUNCTIONS
73 
74 // PRIVATE MEMBER FUNCTIONS
75 
76 
77 // ===========================================================
78 // OFFSET_INDEX_SPACE_HANDLE FACET
79 // ===========================================================
80 
81 // PUBLIC MEMBER FUNCTIONS
82 
86 {
87  // Preconditions:
88 
89  // Body:
90 
91  // Postconditions:
92 
93  ensure(invariant());
94 
95  // Exit:
96 
97  return;
98 }
99 
102 {
103  // Preconditions:
104 
105  // Body:
106 
107  (*this) = xother;
108 
109  // Postconditions:
110 
111  ensure(invariant());
112  ensure((*this) == xother);
113 
114  // Exit:
115 
116  return;
117 }
118 
121  pod_type xindex)
122 {
123  // Preconditions:
124 
125  require(xid_spaces.contains(xindex));
126  require(conforms_to_state(xid_spaces, xindex));
127 
128  // Body:
129 
130  attach_to(xid_spaces, xindex);
131 
132  // Postconditions:
133 
134  ensure(invariant());
135  ensure(is_attached());
136  ensure(&id_spaces() == &xid_spaces);
137  ensure(index() == xindex);
138 
139  // Exit:
140 
141  return;
142 }
143 
146  const std::string& xname)
147 {
148  // Preconditions:
149 
150  require(xid_spaces.contains(xname));
151  require(conforms_to_state(xid_spaces, xname));
152 
153  // Body:
154 
155  attach_to(xid_spaces, xname);
156 
157  // Postconditions:
158 
159  ensure(invariant());
160  ensure(is_attached());
161  ensure(&id_spaces() == &xid_spaces);
162  ensure(name() == xname);
163 
164  // Exit:
165 
166  return;
167 }
168 
172 {
173  // Preconditions:
174 
175  require(xother.is_attached() ? conforms_to_state(xother) : true);
176 
177  // Body:
178 
179  attach_to(xother);
180 
181  // Postconditions:
182 
183  ensure(invariant());
184  ensure((*this) == xother);
185 
186  // Exit:
187 
188  return *this;
189 }
190 
193 {
194  // Preconditions:
195 
196  // Body:
197 
198  // nothing to do.
199 
200  // Postconditions:
201 
202  // Exit:
203 
204  return;
205 }
206 
207 // PROTECTED MEMBER FUNCTIONS
208 
211 {
212  // Preconditions:
213 
214  // Body:
215 
216  attach_to(&xstate);
217 
218  // Postconditions:
219 
220  ensure(invariant());
221  ensure(is_attached());
222  ensure(&state() == &xstate);
223 
224  // Exit:
225 
226  return;
227 }
228 
232 {
233  // Preconditions:
234 
235  require(is_attached());
236 
237  // Body:
238 
239  offset_index_space_state& result =
240  reinterpret_cast<offset_index_space_state&>(*_state);
241 
242  // Postconditions:
243 
244  ensure(is_basic_query);
245 
246  // Exit:
247 
248  return result;
249 }
250 
253 state() const
254 {
255  // Preconditions:
256 
257  require(is_attached());
258 
259  // Body:
260 
261  const offset_index_space_state& result =
262  reinterpret_cast<const offset_index_space_state&>(*_state);
263 
264  // Postconditions:
265 
266  ensure(is_basic_query);
267 
268  // Exit:
269 
270  return result;
271 }
272 
273 // PRIVATE MEMBER FUNCTIONS
274 
275 
276 // ===========================================================
277 // OFFSET INDEX SPACE FACET
278 // ===========================================================
279 
280 // PUBLIC MEMBER FUNCTIONS
281 
284 offset() const
285 {
286  // Preconditions:
287 
288  require(is_attached());
289 
290  // Body:
291 
292  pod_type result = state().offset();
293 
294  // Postconditions:
295 
296  ensure(is_basic_query);
297 
298  // Exit:
299 
300  return result;
301 }
302 
303 // PROTECTED MEMBER FUNCTIONS
304 
305 // PRIVATE MEMBER FUNCTIONS
306 
307 
308 // ===========================================================
309 // INDEX_SPACE_HANDLE FACET
310 // ===========================================================
311 
312 // PUBLIC MEMBER FUNCTIONS
313 
317 {
318  // Preconditions:
319 
320  require(xother.is_attached() ? conforms_to_state(xother) : true);
321 
322  // Body:
323 
324  attach_to(xother);
325 
326  // Postconditions:
327 
328  ensure(invariant());
329  ensure((*this) == xother);
330 
331  // Exit:
332 
333  return *this;
334 }
335 
338 clone() const
339 {
340  // Preconditions:
341 
342  // Body:
343 
345 
346  // Postconditions:
347 
348  ensure(result != 0);
349  ensure(is_same_type(result));
350  ensure(*result == *this);
351 
352  // Exit:
353 
354  return result;
355 }
356 
357 // PROTECTED MEMBER FUNCTIONS
358 
359 // PRIVATE MEMBER FUNCTIONS
360 
361 
362 // ===========================================================
363 // HANDLE FACET
364 // ===========================================================
365 
366 // PUBLIC MEMBER FUNCTIONS
367 
368 bool
371  pod_type xlocal_id) const
372 {
373  // Preconditions:
374 
375  require(xhost.contains(xlocal_id));
376 
377  // Body:
378 
379  bool result =
380  (dynamic_cast<offset_index_space_state*>(state(xhost, xlocal_id)) != 0);
381 
382  // Postconditions:
383 
384  ensure(is_basic_query);
385 
386  // Exit:
387 
388  return result;
389 }
390 
391 // PROTECTED MEMBER FUNCTIONS
392 
393 // PRIVATE MEMBER FUNCTIONS
394 
395 
396 // ===========================================================
397 // ANY FACET
398 // ===========================================================
399 
400 // PUBLIC MEMBER FUNCTIONS
401 
402 bool
404 is_ancestor_of(const any *other) const
405 {
406  // Preconditions:
407 
408  require(other != 0);
409 
410  // Body:
411 
412  // True if other conforms to this
413 
414  bool result = dynamic_cast<const offset_index_space_handle*>(other) != 0;
415 
416  // Postconditions:
417 
418  // Exit:
419 
420  return result;
421 }
422 
423 bool
425 invariant() const
426 {
427  bool result = true;
428 
429  if(invariant_check())
430  {
431  // Prevent recursive calls to invariant
432 
434 
435  // Must satisfy base class invariant
436 
438 
439  // Invariances for this class:
440 
441  // Finished, turn invariant checking back on.
442 
444  }
445 
446  // Exit
447 
448  return result;
449 }
450 
451 // PROTECTED MEMBER FUNCTIONS
452 
453 // PRIVATE MEMBER FUNCTIONS
454 
455 
456 // ===========================================================
457 // NON-MEMBER FUNCTIONS
458 // ===========================================================
459 
460 
461 
462 
463 
static offset_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, pod_type xoffset, size_type xct)
Create a new offset id space in the id space family xid_space at the next available id space index wi...
pod_type offset() const
The offset into the hub id space.
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.
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_persistent() const
True if this id space should be written to disk.
An implementation of class explicit_index_space_handle that has a offset id space state...
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
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 offset_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
bool is_gathered() const
True if begin() == 0 and end() == ct().
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 computed implementation of abstract class explicit_index_space_state. This representation assumes t...
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
offset_index_space_state & state()
The offset id space state (mutable version).
virtual bool contains(pod_type xlocal_id) const =0
True if this collection contains the id space with local id xlocal_id.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
offset_index_space_handle & operator=(const offset_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual bool invariant() const
Class invariant.
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.
static offset_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, pod_type xoffset, size_type xct)
Create a new offset id space in the id space family xid_space with name xname, offset xoffset and cou...
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 offset() const
The offset into the hub id space.
offset_index_space_handle()
Default constructor.