SheafSystem  0.0.0.0
array_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/array_index_space_handle.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/array_index_space_state.h"
25 
26 // ===========================================================
27 // SPACE FACTORY FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
35  const std::string& xname,
36  bool xis_persistent,
37  size_type xcapacity)
38 {
39  // Preconditions:
40 
41  require(!xname.empty());
42  require(!xid_spaces.contains(xname));
43  require(xcapacity >= 0);
44 
45  // Body:
46 
49  xname,
50  xis_persistent,
51  xcapacity);
52 
53  // Postconditions:
54 
55  ensure(&result.id_spaces() == &xid_spaces);
56  ensure(xid_spaces.contains(xname));
57  ensure(result.conforms_to_state(xname));
58 
59  ensure(result.is_persistent() == xis_persistent);
60  ensure(result.name() == xname);
61 
62  ensure(result.capacity() >= xcapacity);
63 
64  // Exit:
65 
66  return result;
67 }
68 
69 // PROTECTED MEMBER FUNCTIONS
70 
71 // PRIVATE MEMBER FUNCTIONS
72 
73 
74 // ===========================================================
75 // ARRAY_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 
236  array_index_space_state& result =
237  reinterpret_cast<array_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 array_index_space_state& result =
259  reinterpret_cast<const array_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 // MUTABLE INDEX SPACE FACET
275 // ===========================================================
276 
277 // PUBLIC MEMBER FUNCTIONS
278 
279 // PROTECTED MEMBER FUNCTIONS
280 
281 // PRIVATE MEMBER FUNCTIONS
282 
283 
284 // ===========================================================
285 // INDEX_SPACE_HANDLE FACET
286 // ===========================================================
287 
288 // PUBLIC MEMBER FUNCTIONS
289 
293 {
294  // Preconditions:
295 
296  require(xother.is_attached() ? conforms_to_state(xother) : true);
297 
298  // Body:
299 
300  attach_to(xother);
301 
302  // Postconditions:
303 
304  ensure(invariant());
305  ensure((*this) == xother);
306 
307  // Exit:
308 
309  return *this;
310 }
311 
314 clone() const
315 {
316  // Preconditions:
317 
318  // Body:
319 
321 
322  // Postconditions:
323 
324  ensure(result != 0);
325  ensure(is_same_type(result));
326  ensure(*result == *this);
327 
328  // Exit:
329 
330  return result;
331 }
332 
333 // PROTECTED MEMBER FUNCTIONS
334 
335 // PRIVATE MEMBER FUNCTIONS
336 
337 
338 // ===========================================================
339 // HANDLE FACET
340 // ===========================================================
341 
342 // PUBLIC MEMBER FUNCTIONS
343 
344 bool
347  pod_type xlocal_id) const
348 {
349  // Preconditions:
350 
351  require(xhost.contains(xlocal_id));
352 
353  // Body:
354 
355  bool result =
356  (dynamic_cast<array_index_space_state*>(state(xhost, xlocal_id)) != 0);
357 
358  // Postconditions:
359 
360  ensure(is_basic_query);
361 
362  // Exit:
363 
364  return result;
365 }
366 
367 // PROTECTED MEMBER FUNCTIONS
368 
369 // PRIVATE MEMBER FUNCTIONS
370 
371 
372 // ===========================================================
373 // ANY FACET
374 // ===========================================================
375 
376 // PUBLIC MEMBER FUNCTIONS
377 
378 bool
380 is_ancestor_of(const any *other) const
381 {
382  // Preconditions:
383 
384  require(other != 0);
385 
386  // Body:
387 
388  // True if other conforms to this
389 
390  bool result = dynamic_cast<const array_index_space_handle*>(other) != 0;
391 
392  // Postconditions:
393 
394  // Exit:
395 
396  return result;
397 }
398 
399 bool
401 invariant() const
402 {
403  bool result = true;
404 
405  if(invariant_check())
406  {
407  // Prevent recursive calls to invariant
408 
410 
411  // Must satisfy base class invariant
412 
414 
415  // Invariances for this class:
416 
417  // Finished, turn invariant checking back on.
418 
420  }
421 
422  // Exit
423 
424  return result;
425 }
426 
427 // PROTECTED MEMBER FUNCTIONS
428 
429 // PRIVATE MEMBER FUNCTIONS
430 
431 
432 // ===========================================================
433 // NON-MEMBER FUNCTIONS
434 // ===========================================================
435 
436 
437 
438 
439 
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 is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual bool is_persistent() const
True if this id space should be written to disk.
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...
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).
An array implementation of class scattered_insertion_index_space_state. This representation is intend...
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
std::string name() const
Name of this space.
pod_index_type pod_type
The "plain old data" index type for this.
array_index_space_handle & operator=(const array_index_space_handle &xother)
Assignment operator; attach this handle to the state of xother. synonym for attach_to(xother).
virtual bool is_attached() const
True if this handle is attached to a state.
An array implementation of class scattered_insertion_index_space_handle. This representation is inten...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
array_index_space_state & state()
The array id space state (mutable version).
virtual bool invariant() const
Class invariant.
virtual array_index_space_handle * clone() const
Virtual constructor, makes a new instance of the same type as this. If the handle is attached...
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.
size_type capacity() const
The number of ids reserved in memory.
static array_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent, size_type xcapacity)
Create a new array id space in the id space family xid_space with name xname, persistence xis_persist...
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
A handle for a scattered_insertion_index_space_state.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
static array_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent, size_type xcapacity)
Create a new array id space in the id space family xid_spaces at the next available id space index wi...
Factory and container for a family of id spaces.
array_index_space_handle()
Default constructor.
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