SheafSystem  0.0.0.0
scattered_insertion_index_space_state.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/scattered_insertion_index_space_state.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_iterator.h"
24 #include "SheafSystem/scattered_insertion_index_space_handle.h"
25 #include "SheafSystem/scoped_index.h"
26 
27 // ===========================================================
28 // SCATTERED_INSERTION_INDEX_SPACE_STATE FACET
29 // ===========================================================
30 
31 // PUBLIC MEMBER FUNCTIONS
32 
33 // PROTECTED MEMBER FUNCTIONS
34 
38 {
39  // Preconditions:
40 
41  // Body:
42 
43  // Postconditions:
44 
45  ensure(invariant());
46  ensure(is_empty());
47 
48  // Exit:
49 
50  return;
51 }
52 
55 {
56  // Preconditions:
57 
58  // Body:
59 
60  // nothing to do.
61 
62  // Postconditions:
63 
64  // Exit:
65 
66  return;
67 }
68 
69 // PRIVATE MEMBER FUNCTIONS
70 
71 
72 // ===========================================================
73 // MUTABLE INDEX SPACE FACET
74 // ===========================================================
75 
76 // PUBLIC MEMBER FUNCTIONS
77 
78 void
80 insert(pod_type xid, const scoped_index& xhub_id)
81 {
82  // Preconditions:
83 
84  require(xhub_id.in_scope());
85  require(precondition_of(insert_entry(xid, xhub_id.hub_pod())));
86 
87  // Body:
88 
89  insert(xid, xhub_id.hub_pod());
90 
91  // Postconditions:
92 
93  ensure(postcondition_of(insert_entry(xid, xhub_id.hub_pod())));
94 
95  // Exit:
96 
97  return;
98 }
99 
100 void
102 insert(pod_type xid, pod_type xhub_id)
103 {
104  // Preconditions:
105 
106  require(is_valid(xid));
107  require(is_valid(xhub_id));
108  require(!contains(xid));
109  require(!contains_hub(xhub_id));
110  require(hub_id_space().contains(xhub_id));
111 
112  // Body:
113 
114  define_old_variable(size_type old_ct = _ct);
115  define_old_variable(pod_type old_begin = _begin);
116  define_old_variable(pod_type old_end = _end);
117 
118  // Insert the entery in the map representation.
119 
120  map_rep_insert_entry(xid, xhub_id);
121 
122  // Update the count.
123 
124  ++_ct;
125 
126  // Update the extrema.
127 
128  update_extrema(xid);
129 
130  // Postconditions:
131 
132  ensure(invariant());
133  ensure(contains(xid, xhub_id));
134  ensure(ct() == old_ct + 1);
135  ensure(ct() > 1 ? begin() <= old_begin : true);
136  ensure(begin() <= xid);
137  ensure(ct() > 1 ? end() >= old_end : true);
138  ensure(end() > xid);
139 
140  // Exit:
141 
142  return;
143 }
144 
145 // PROTECTED MEMBER FUNCTIONS
146 
147 // PRIVATE MEMBER FUNCTIONS
148 
149 // ===========================================================
150 // GATHER_INSERTION_INDEX_SPACE FACET
151 // ===========================================================
152 
153 // PUBLIC MEMBER FUNCTIONS
154 
155 // PROTECTED MEMBER FUNCTIONS
156 
157 // PRIVATE MEMBER FUNCTIONS
158 
159 
160 // ===========================================================
161 // MAP REPRESENTATION FACET
162 // ===========================================================
163 
164 // PUBLIC MEMBER FUNCTIONS
165 
166 // PROTECTED MEMBER FUNCTIONS
167 
168 void
170 map_rep_insert_entry(pod_type xdomain_id, pod_type xrange_id)
171 {
172  // Preconditions:
173 
174  require(!contains_hub(xrange_id));
175  require(!contains(xdomain_id));
176 
177  // Body:
178 
179  is_abstract();
180 
181  // Postconditions:
182 
183  // Not finished inserting entry; do not ensure invariant.
184 
185  ensure(contains(xdomain_id, xrange_id));
186 
187  // Exit
188 
189  return;
190 }
191 
192 // PRIVATE MEMBER FUNCTIONS
193 
194 
195 // ===========================================================
196 // EXPLICIT_INDEX_SPACE_STATE FACET
197 // ===========================================================
198 
199 // PUBLIC MEMBER FUNCTIONS
200 
201 bool
204 {
205  // Preconditions:
206 
207  require(is_ancestor_of(&xother));
208 
209  // Body:
210 
212  dynamic_cast<const scattered_insertion_index_space_state&>(xother);
213 
214  bool result = explicit_index_space_state::operator==(xother);
215 
216  // Postconditions:
217 
218  // Exit
219 
220  return result;
221 }
222 
223 // PROTECTED MEMBER FUNCTIONS
224 
228 {
229  // Preconditions:
230 
231  require(is_ancestor_of(&xother));
232 
233  // Body:
234 
235  (void) explicit_index_space_state::operator=(xother);
236 
237  // Postconditions:
238 
239  ensure(invariant());
240  ensure((*this) == xother);
241 
242  // Exit
243 
244  return *this;
245 }
246 
247 // PRIVATE MEMBER FUNCTIONS
248 
249 
250 // ===========================================================
251 // INDEX SPACE FACET
252 // ===========================================================
253 
254 // PUBLIC MEMBER FUNCTIONS
255 
256 // PROTECTED MEMBER FUNCTIONS
257 
258 // PRIVATE MEMBER FUNCTIONS
259 
260 
261 // ===========================================================
262 // FACTORY FACET
263 // ===========================================================
264 
265 // PUBLIC MEMBER FUNCTIONS
266 
267 const std::string&
269 class_name() const
270 {
271  static const std::string result("scattered_insertion_index_space_state");
272  return result;
273 }
274 
275 // PROTECTED MEMBER FUNCTIONS
276 
277 // PRIVATE MEMBER FUNCTIONS
278 
279 
280 // ===========================================================
281 // ANY FACET
282 // ===========================================================
283 
284 // PUBLIC MEMBER FUNCTIONS
285 
286 bool
288 is_ancestor_of(const any *other) const
289 {
290  // Preconditions:
291 
292  require(other != 0);
293 
294  // Body:
295 
296  // True if other conforms to this
297 
298  bool result = dynamic_cast<const scattered_insertion_index_space_state*>(other) != 0;
299 
300  // Postconditions:
301 
302  // Exit:
303 
304  return result;
305 }
306 
307 bool
309 invariant() const
310 {
311  bool result = true;
312 
313  if(invariant_check())
314  {
315  // Prevent recursive calls to invariant
316 
318 
319  // Must satisfy base class invariant
320 
322 
323  // Invariances for this class:
324 
325  // Finished, turn invariant checking back on.
326 
328  }
329 
330  // Exit:
331 
332  return result;
333 }
334 
335 // PROTECTED MEMBER FUNCTIONS
336 
337 // PRIVATE MEMBER FUNCTIONS
338 
339 
340 
341 // ===========================================================
342 // NON-MEMBER FUNCTIONS
343 // ===========================================================
344 
345 size_t
346 sheaf::
347 deep_size(const scattered_insertion_index_space_state& xn, bool xinclude_shallow)
348 {
349  // Preconditions:
350 
351  // Body:
352 
353  size_t result = xinclude_shallow ? sizeof(xn) : 0;
354 
355  // Add any contributions from the parent class.
356 
358  result += deep_size(ixn, false);
359 
360  // Postconditions:
361 
362  ensure(result >= 0);
363 
364  // Exit
365 
366  return result;
367 }
bool contains_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space. synonym for contains...
size_type ct() const
The number of members.
bool in_scope() const
True if and only if scope() contains an entry for pod().
Definition: scoped_index.h:584
pod_type end() const
Ending id of this space.
virtual size_type deep_size(bool xinclude_shallow) const
The deep size of this.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual void map_rep_insert_entry(pod_type xdomain_id, pod_type xrange_id)=0
Inserts entry (xdomain_id, xrange_id) into the map representation.
An implementation of class explicit_index_space_state that supports either gathered or scattered inse...
pod_type _end
Ending id of this space.
Abstract base class with useful features for all objects.
Definition: any.h:39
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
pod_type begin() const
Beginning id of this space.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
const hub_index_space_handle & hub_id_space() const
The hub id space.
void insert(pod_type xid, const scoped_index &xhub_id)
Make id xid in this id space equivalent to xhub_id in the hub id space. synonym for insert(xid...
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 operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
size_type _ct
The number of members.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool contains(pod_type xid) const =0
True if this space contains id xid.
pod_index_type pod_type
The "plain old data" index type for this.
virtual scattered_insertion_index_space_state & operator=(const explicit_index_space_state &xother)
Assignment operator.
bool is_empty() const
True if there are no ids in the space.
An implementation of class explicit_index_space_state that supports gathered insertion of new members...
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
pod_type _begin
Beginning id of this space.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual const std::string & class_name() const
The name of this class.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710