SheafSystem  0.0.0.0
abstract_product_structure.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/abstract_product_structure.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 
25 // ===========================================================
26 // ABSTRACT_PRODUCT_STRUCTURE FACET
27 // ===========================================================
28 
29 // PUBLIC MEMBER FUNCTIONS
30 
33 {
34  // Preconditions:
35 
36  // Body:
37 
38  // nothing to do.
39 
40  // Postconditions:
41 
42  // Exit:
43 
44  return;
45 }
46 
49 clone() const
50 {
51  abstract_product_structure* result = 0; // Silence compiler warnings
52 
53  // Preconditions:
54 
55  // Body:
56 
57  is_abstract();
58 
59  // Postconditions:
60 
61  ensure(result != 0);
62  ensure(is_same_type(result));
63 
64  // Exit:
65 
66  return result;
67 }
68 
72 {
73  // Preconditions:
74 
75  require(is_ancestor_of(&xother));
76 
77  // Body:
78 
79  is_abstract();
80 
81  // Postconditions:
82 
83  ensure(invariant());
84  ensure((*this) == xother);
85 
86  // Exit
87 
88  return *this;
89 }
90 
91 bool
94 {
95  // Preconditions:
96 
97  require(is_ancestor_of(&xother));
98 
99  // Body:
100 
101  bool result = false; // Just to silence compiler warnings.
102 
103  is_abstract();
104 
105  // Postconditions:
106 
107  ensure(is_basic_query);
108 
109  // Exit
110 
111  return result;
112 }
113 
114 // PROTECTED MEMBER FUNCTIONS
115 
116 // PRIVATE MEMBER FUNCTIONS
117 
118 
119 // ===========================================================
120 // PRODUCT FACET
121 // ===========================================================
122 
123 // PUBLIC MEMBER FUNCTIONS
124 
127 d() const
128 {
129  // Preconditions:
130 
131  // Body:
132 
133  size_type result = 0; // Just to silence compiler warnings.
134 
135  is_abstract();
136 
137  // Postconditions:
138 
139  ensure(result > 1);
140 
141  // Exit:
142 
143  return result;
144 }
145 
148 ub(pod_type xi) const
149 {
150  // Preconditions:
151 
152  require((0 <= xi) && (xi < d()));
153 
154  // Body:
155 
156  size_type result = 0; // Just to silence compiler warnings.
157 
158  is_abstract();
159 
160  // Postconditions:
161 
162  ensure(result > 0);
163 
164  // Exit:
165 
166  return result;
167 }
168 
169 void
171 ordinal(pod_type* xtuple, pod_type& xordinal) const
172 {
173  // Preconditions:
174 
175  require(unexecutable("length of xtuple equals d()"));
176  require_for_range(pod_type i=0, i<d(), ++i,
177  (0 <= xtuple[i]) && (xtuple[i] < ub(i)));
178 
179  // Body:
180 
181  is_abstract();
182 
183  // Postconditions:
184 
185  ensure((0 <= xordinal) && (xordinal < ordinal_ub()));
186 
187  // Exit:
188 
189  return;
190 }
191 
192 void
194 tuple(pod_type xordinal, pod_type* xtuple) const
195 {
196  // Preconditions:
197 
198  require((0 <= xordinal) && (xordinal < ordinal_ub()));
199  require(unexecutable("length of xtuple equals d()"));
200 
201  // Body:
202 
203  is_abstract();
204 
205  // Postconditions:
206 
207  ensure_for_range(pod_type i=0, i<d(), ++i,
208  (0 <= xtuple[i]) && (xtuple[i] < ub(i)));
209 
210  // Exit:
211 
212  return;
213 }
214 
217 ordinal_ub() const
218 {
219  // Preconditions:
220 
221  // Body:
222 
223  size_type result = 1;
224 
225  for(pod_type i=0; i<d(); i++)
226  {
227  result *= ub(i);
228  }
229 
230  // Postconditions:
231 
232  ensure(is_basic_query);
233 
234  // Exit:
235 
236  return result;
237 }
238 
239 void
242 {
243  // Preconditions:
244 
245  require(unexecutable("xubs.length >= d()"));
246  require_for_range(pod_type i=0, i<d(), ++i, xubs[i] > 0);
247 
248  // Body:
249 
250  is_abstract();
251 
252  // Postconditions:
253 
254  ensure_for_range(pod_type i=0, i<d(), ++i, ub(i) == xubs[i]);
255 
256  // Exit:
257 
258  return;
259 }
260 
261 // PROTECTED MEMBER FUNCTIONS
262 
263 // PRIVATE MEMBER FUNCTIONS
264 
265 
266 // ===========================================================
267 // ANY FACET
268 // ===========================================================
269 
270 // PUBLIC MEMBER FUNCTIONS
271 
272 bool
274 is_ancestor_of(const any *other) const
275 {
276  // Preconditions:
277 
278  require(other != 0);
279 
280  // Body:
281 
282  // True if other conforms to this
283 
284  bool result = dynamic_cast<const abstract_product_structure*>(other) != 0;
285 
286  // Postconditions:
287 
288  // Exit:
289 
290  return result;
291 }
292 
293 bool
295 invariant() const
296 {
297  bool result = true;
298 
299  if(invariant_check())
300  {
301  // Prevent recursive calls to invariant
302 
304 
305  // Must satisfy base class invariant
306 
307  invariance(any::invariant());
308 
309  // Invariances for this class:
310 
311  // Finished, turn invariant checking back on.
312 
314  }
315 
316  // Exit
317 
318  return result;
319 }
320 
321 // PROTECTED MEMBER FUNCTIONS
322 
323 // PRIVATE MEMBER FUNCTIONS
324 
325 
326 // ===========================================================
327 // NON-MEMBER FUNCTIONS
328 // ===========================================================
329 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
virtual size_type d() const =0
The product dimension.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
An abstract class that defines the product structure for an id space.
virtual size_type ub(pod_type xi) const =0
The upper-bound for the dimension xi.
virtual void tuple(pod_type xordinal, pod_type *xtuple) const =0
Ordinal to tuple conversion.
virtual bool operator==(const abstract_product_structure &xother) const =0
True if this is equivalent to xother.
size_type ordinal_ub() const
The upper-bound of the ordinal.
virtual abstract_product_structure & operator=(const abstract_product_structure &xother)=0
Assignment operator.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual void ordinal(pod_type *xtuple, pod_type &xordinal) const =0
Tuple to ordinal conversion.
virtual bool invariant() const
Class invariant.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
pod_index_type pod_type
The "plain old data" index type for this.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual void put_ubs(size_type *xubs)=0
Set the upper-bounds for this product structure.
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
virtual abstract_product_structure * clone() const =0
Virtual constructor, makes a new instance of the same type as this.