SheafSystem  0.0.0.0
index_space_family.impl.h
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 #ifndef INDEX_SPACE_FAMILY_IMPL_H
22 #define INDEX_SPACE_FAMILY_IMPL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef INDEX_SPACE_FAMILY_H
29 #include "SheafSystem/index_space_family.h"
30 #endif
31 
32 #ifndef ASSERT_CONTRACT_H
33 #include "SheafSystem/assert_contract.h"
34 #endif
35 
36 // ===========================================================
37 // PRODUCT STRUCTURE FACET
38 // ===========================================================
39 
40 template<typename T>
41 const T&
43 product_structure(const std::string& xname) const
44 {
45  // Preconditions:
46 
47  require(contains(xname));
48  require(has_product_structure(xname));
49  require(product_structure_conforms_to<T>(xname));
50 
51  // Body:
52 
53  const T& result = reinterpret_cast<const T&>(product_structure(xname));
54 
55  // Postconditions:
56 
57  ensure(is_basic_query);
58 
59  // Exit:
60 
61  return result;
62 }
63 
64 template<typename T>
65 const T&
67 product_structure(pod_type xspace_id) const
68 {
69  // Preconditions:
70 
71  require(contains(xspace_id));
72  require(has_product_structure(xspace_id));
73  require(product_structure_conforms_to<T>(xspace_id));
74 
75  // Body:
76 
77  const T& result = reinterpret_cast<const T&>(product_structure(xspace_id));
78 
79  // Postconditions:
80 
81  ensure(is_basic_query);
82 
83  // Exit:
84 
85  return result;
86 }
87 
88 template<typename T>
89 T&
91 product_structure(const std::string& xname)
92 {
93  // Preconditions:
94 
95  require(contains(xname));
96  require(has_product_structure(xname));
97  require(product_structure_conforms_to<T>(xname));
98 
99  // Body:
100 
101  T& result = reinterpret_cast<T&>(product_structure(xname));
102 
103  // Postconditions:
104 
105  ensure(is_basic_query);
106 
107  // Exit:
108 
109  return result;
110 }
111 
112 template<typename T>
113 T&
116 {
117  // Preconditions:
118 
119  require(contains(xspace_id));
120  require(has_product_structure(xspace_id));
121  require(product_structure_conforms_to<T>(xspace_id));
122 
123  // Body:
124 
125  T& result = reinterpret_cast<T&>(product_structure(xspace_id));
126 
127  // Postconditions:
128 
129  ensure(is_basic_query);
130 
131  // Exit:
132 
133  return result;
134 }
135 
136 template<typename T>
137 bool
139 product_structure_conforms_to(const std::string& xname) const
140 {
141  // Preconditions:
142 
143  require(contains(xname));
144  require(has_product_structure(xname));
145 
146  // Body:
147 
148  bool result = (dynamic_cast<const T*>(&product_structure(xname)) != 0);
149 
150  // Postconditions:
151 
152  ensure(is_basic_query);
153 
154  // Exit:
155 
156  return result;
157 }
158 
159 template<typename T>
160 bool
163 {
164  // Preconditions:
165 
166  require(contains(xspace_id));
167  require(has_product_structure(xspace_id));
168 
169  // Body:
170 
171  bool result = (dynamic_cast<const T*>(&product_structure(xspace_id)) != 0);
172 
173  // Postconditions:
174 
175  ensure(is_basic_query);
176 
177  // Exit:
178 
179  return result;
180 }
181 
182 // ===========================================================
183 // HANDLE POOL FACET
184 // ===========================================================
185 
186 template<typename T>
187 T&
189 get_id_space(const std::string& xname) const
190 {
191  // Preconditions:
192 
193  require(contains(xname));
194  require(handle_conforms_to_state<T>(xname));
195 
196  // Body:
197 
198  T& result = reinterpret_cast<T&>(get_id_space(xname));
199 
200  // Postconditions:
201 
202  ensure(result.is_attached());
203 
204  // Exit:
205 
206  return result;
207 };
208 
209 template<typename T>
210 T&
213 {
214  // Preconditions:
215 
216  require(contains(xid));
217  require(handle_conforms_to_state<T>(xid));
218 
219  // Body:
220 
221  T& result = reinterpret_cast<T&>(get_id_space(xid));
222 
223  // Postconditions:
224 
225  ensure(result.is_attached());
226 
227  // Exit:
228 
229  return result;
230 };
231 
232 template<typename T>
233 bool
235 handle_conforms_to_state(const std::string& xname) const
236 {
237  // Preconditions:
238 
239  require(contains(xname));
240 
241  // Body:
242 
243  index_space_handle& lhandle = get_id_space(xname);
244 
245  bool result = (dynamic_cast<const T*>(&lhandle) != 0);
246 
247  release_id_space(lhandle);
248 
249  // Postconditions:
250 
251  ensure(is_basic_query);
252 
253  // Exit:
254 
255  return result;
256 };
257 
258 template<typename T>
259 bool
262 {
263  // Preconditions:
264 
265  require(contains(xid));
266 
267  // Body:
268 
269  index_space_handle& lhandle = get_id_space(xid);
270 
271  bool result = (dynamic_cast<const T*>(&lhandle) != 0);
272 
273  release_id_space(lhandle);
274 
275  // Postconditions:
276 
277  ensure(is_basic_query);
278 
279  // Exit:
280 
281  return result;
282 };
283 
284 #endif // ifndef INDEX_SPACE_FAMILY_IMPL_H
void release_id_space(index_space_handle &xid_space) const
Returns the id space handle xid_space to the handle pool.
const abstract_product_structure & product_structure(const std::string &xname) const
The product structure for the id space with name xname (const version).
index_space_handle & get_id_space(const std::string &xname) const
Allocates an id space handle from the handle pool attached to state with name xname.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
bool handle_conforms_to_state(const std::string &xname) const
True if handle of type T conforms to the state with name xname.
bool has_product_structure(const std::string &xname) const
True if the id space with name xname has a product structure.
pod_index_type pod_type
The "plain old data" index type for this.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
bool product_structure_conforms_to(const std::string &xname) const
True if the product structure for the id space with name xname conforms to type T.