SheafSystem  0.0.0.0
code_template.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 
24 
25 #include "SheafSystem/${derived}.h"
26 
27 #include "SheafSystem/assert_contract.h"
28 #include "SheafSystem/base_space_member.h"
29 #include "SheafSystem/${coords_invertible}.h"
30 #include "SheafSystem/${property}.h"
31 
32 using namespace std;
33 using namespace fields; // Workaround for MS C++ bug.
34 
35 //=============================================================================
36 // FIELD_VD FACET OF CLASS ${DERIVED}
37 //=============================================================================
38 
40 fields::${derived}::
41 ${derived}()
42  : ${base}(new ${property}, new ${coords_invertible}, new base_space_member)
43 {
44  // Preconditions:
45 
46  // Body:
47 
48  // Postconditions:
49 
50  ensure(invariant());
51  ensure(!is_attached());
52 
53  // Exit:
54 
55  return;
56 }
57 
59 fields::${derived}::
60 ${derived}(const ${derived}& xother, bool xauto_access)
61  : ${base}(new ${property}, new ${coords_invertible}, new base_space_member)
62 {
63  // Preconditions:
64 
65  require(xauto_access || !xother.is_attached() || \
66  xother.state_is_read_accessible());
67 
68  // Body:
69 
70  _coordinates->attach_to_state(xother._coordinates, xauto_access);
71  _property->attach_to_state(xother._property, xauto_access);
72  _base_space->attach_to_state(xother._base_space, xauto_access);
73 
74  // Postconditions:
75 
76  ensure(invariant());
77  ensure(coordinates().is_same_state(&xother.coordinates()));
78  ensure(property().is_same_state(&xother.property()));
79  ensure(base_space().is_same_state(&xother.base_space()));
80 
81  // Exit:
82 
83  return;
84 }
85 
87 fields::${derived}::
88 ${derived}(const ${coords}& xcoordinates, const ${property}& xproperty, bool xauto_access)
89  : ${base}(new ${property}, new ${coords_invertible}, new base_space_member)
90 {
91  // Preconditions:
92 
93  require(xcoordinates.is_attached());
94  require(xproperty.is_attached());
95  require(xauto_access || xcoordinates.state_is_read_accessible());
96  require(xauto_access || xproperty.state_is_read_accessible());
97 
98  // Body:
99 
100  if(xauto_access)
101  {
102  xcoordinates.get_read_access();
103  xproperty.get_read_access();
104  }
105 
106  _coordinates->attach_to_state(&xcoordinates);
107  _property->attach_to_state(&xproperty);
108  _base_space->attach_to_state(&(xproperty.schema().base_space()));
109 
110  if(xauto_access)
111  {
112  xcoordinates.release_access();
113  xproperty.release_access();
114  }
115 
116  // Postconditions:
117 
118  ensure(invariant());
119  ensure(coordinates().is_same_state(&xcoordinates));
120  ensure(property().is_same_state(&xproperty));
121 
122  // Exit:
123 
124  return;
125 }
126 
128 fields::${derived}::
129 ${derived}(namespace_poset& xns,
130  const poset_path& xcoordinates_path,
131  const poset_path& xproperty_path,
132  bool xauto_access)
133  : ${base}(new ${property}, new ${coords_invertible}, new base_space_member)
134 {
135  // Preconditions:
136 
137  require(xauto_access || xns.state_is_read_accessible());
138  require(xns.contains_poset_member(xcoordinates_path));
139  require(xauto_access ||
140  xns.member_poset(xcoordinates_path).state_is_read_accessible());
141  require(xns.contains_poset_member(xproperty_path));
142  require(xauto_access ||
143  xns.member_poset(xproperty_path).state_is_read_accessible());
144 
145  // Body:
146 
147  if(xauto_access)
148  {
149  xns.get_read_access();
150  }
151 
152  _coordinates->attach_to_state(&xns, xcoordinates_path, xauto_access);
153  _property->attach_to_state(&xns, xproperty_path, xauto_access);
154 
155  if(xauto_access)
156  {
157  _coordinates->get_read_access();
158  _property->get_read_access();
159  }
160 
161  _base_space->attach_to_state(&(_property->schema().base_space()));
162 
163  if(xauto_access)
164  {
165  xns.release_access();
166  _coordinates->release_access();
167  _property->release_access();
168  }
169 
170  // Postconditions:
171 
172  ensure(invariant());
173  ensure(coordinates().path(true) == xcoordinates_path);
174  ensure(property().path(true) == xproperty_path);
175 
176  // Exit:
177 
178  return;
179 }
180 
182 fields::${derived}::
183 ${derived}(${property}* xproperty,
184  ${coords_invertible}* xcoordinates,
185  base_space_member* xbase_space)
186  : ${base}(xproperty, xcoordinates, xbase_space)
187 {
188  // Preconditions:
189 
190  // Body:
191 
192  // Postconditions:
193 
194  // Exit:
195 
196 }
197 
199 fields::${derived}&
200 fields::${derived}::
201 operator=(const ${abs_base}& xother)
202 {
203  // Preconditions:
204 
205  require(precondition_of(${abs_base}::operator=(xother)));
206 
207  // Body:
208 
209  ${abs_base}::operator=(xother);
210 
211  // Postconditions:
212 
213  ensure(postcondition_of(${abs_base}::operator=(xother)));
214 
215  // Exit:
216 
217  return *this;
218 }
219 
221 fields::${derived}&
222 fields::${derived}::
223 operator=(const ${derived}& xother)
224 {
225  // Preconditions:
226 
227  require(precondition_of(${abs_base}::operator=(xother)));
228 
229  // Body:
230 
231  ${abs_base}::operator=(xother);
232 
233  // Postconditions:
234 
235  ensure(postcondition_of(${abs_base}::operator=(xother)));
236 
237  // Exit:
238 
239  return *this;
240 }
241 
243 fields::${derived}&
244 fields::${derived}::
245 operator=(const ${property}& xsection)
246 {
247  // Preconditions:
248 
249  require(precondition_of(${abs_base}::operator=(xsection)));
250 
251  // Body:
252 
253  ${abs_base}::operator=(xsection);
254 
255  // Postconditions:
256 
257  ensure(postcondition_of(${abs_base}::operator=(xsection)));
258 
259  // Exit
260 
261  return *this;
262 
263 }
264 
266 fields::${derived}&
267 fields::${derived}::
268 operator=(const ${fiber}& xfiber)
269 {
270  // Preconditions:
271 
272  require(precondition_of(${abs_base}::operator=(xfiber)));
273 
274  // Body:
275 
276  ${abs_base}::operator=(xfiber);
277 
278  // Postconditions:
279 
280  ensure(postcondition_of(${abs_base}::operator=(xfiber)));
281 
282  // Exit
283 
284  return *this;
285 
286 }
287 
289 fields::${derived}&
290 fields::${derived}::
291 operator=(const ${volatile_fiber}& xfiber)
292 {
293  // Preconditions:
294 
295  require(precondition_of(${abs_base}::operator=(xfiber)));
296 
297  // Body:
298 
299  ${abs_base}::operator=(xfiber);
300 
301  // Postconditions:
302 
303  ensure(postcondition_of(${abs_base}::operator=(xfiber)));
304 
305  // Exit
306 
307  return *this;
308 
309 }
310 
312 fields::${derived}::
313 ~${derived}()
314 {
315  // Preconditions:
316 
317  // Body:
318 
319  // Postconditions:
320 
321  // Exit:
322 
323  return;
324 }
325 
327 fiber_bundle::${property}&
328 fields::${derived}::
329 property() const
330 {
331  // Preconditions:
332 
333  // Body:
334 
335  ${property}& result = dynamic_cast<${property}&>(*_property);
336 
337  // Postconditions:
338 
339  // Exit:
340 
341  return result;
342 }
343 
344 
346 bool
347 fields::${derived}::
348 same_property_fiber_schema(const ${derived}& xother, bool xauto_access) const
349 {
350  bool result;
351 
352  // Preconditions:
353 
354  require(xauto_access || state_is_read_accessible());
355 
356  // Body:
357 
358  if(xauto_access)
359  {
360  get_read_access();
361  xother.get_read_access();
362  }
363 
364  result = property().schema().fiber_schema().
365  is_same_state(&xother.property().schema().fiber_schema());
366 
367  if(xauto_access)
368  {
369  release_access();
370  xother.release_access();
371  }
372 
373  // Postconditions:
374 
375  // Exit:
376 
377  return result;
378 }
379 
380 //=============================================================================
381 // ANY FACET OF CLASS ${DERIVED}
382 //=============================================================================
383 
385 const std::string&
386 fields::${derived}::
387 class_name() const
388 {
389  // Preconditions:
390 
391  // Body:
392 
393  const string& result = static_class_name();
394 
395  // Postconditions:
396 
397  ensure(!result.empty());
398 
399  // Exit:
400 
401  return result;
402 }
403 
405 const std::string&
406 fields::${derived}::
407 static_class_name()
408 {
409  // Preconditions:
410 
411  // Body:
412 
413  static const string result("${derived}");
414 
415  // Postconditions:
416 
417  ensure(!result.empty());
418 
419  // Exit:
420 
421  return result;
422 }
423 
425 bool
426 fields::${derived}::
427 is_ancestor_of(const any* xother) const
428 {
429 
430  // Preconditions:
431 
432  require(xother != 0);
433 
434  // Body:
435 
436  // True if xother conforms to this.
437 
438  bool result = dynamic_cast<const ${derived}*>(xother) != 0;
439 
440  // Postconditions:
441 
442  return result;
443 }
444 
446 fields::${derived}*
447 fields::${derived}::
448 clone() const
449 {
450  ${derived}* result;
451 
452  // Preconditions:
453 
454  // Body:
455 
456  result = new ${derived}();
457 
458  // Postconditions:
459 
460  ensure(result != 0);
461  ensure(is_same_type(result));
462 
463  // Exit:
464 
465  return result;
466 }
467 
469 bool
470 fields::${derived}::
471 invariant() const
472 {
473  bool result = true;
474 
475  if(invariant_check())
476  {
477  // Prevent recursive calls to invariant.
478 
479  disable_invariant_check();
480 
481  // Must satisfy base class invariant.
482 
483  invariance(${base}::invariant());
484 
485  // Invariances for this class:
486 
487  invariance(state_is_read_accessible() ?
488  base_space().is_same_state(&property().schema().base_space()) :
489  true);
490 
491  invariance(state_is_read_accessible() ?
492  property().schema().base_space().le(&coordinates().
493  schema().base_space()) :
494  true);
495 
496  // Finished, turn invariant checking back on.
497 
498  enable_invariant_check();
499  }
500 
501  // Exit
502 
503  return result;
504 }
505 
506 //=============================================================================
507 // NON-MEMBER FUNCTIONS OF CLASS ${DERIVED}
508 //=============================================================================
509 
511 fields::${derived}&
512 fields::
513 operator>>(const ${derived}& xsrc, ${derived}& xdst)
514 {
515  // Preconditions:
516 
517  require(xsrc.is_attached());
518  require(xdst.is_attached());
519  require(xsrc.same_property_fiber_schema(xdst, true));
520 
521  // Body:
522 
523  not_implemented();
524 
525  // Postconditions:
526 
527  //Exit:
528 
529  return xdst;
530 }
531 
533 std::ostream&
534 fields::
535 operator<<(std::ostream& xos, const ${derived}& xfield)
536 {
537  // Preconditions:
538 
539  require(xfield.state_is_read_accessible());
540 
541  // Body:
542 
543  xfield.print_property_dofs(xos, 0, "", false, false);
544 
545  // Postconditions:
546 
547  // Exit:
548 
549  return xos;
550 }
551 
552 //==============================================================================
553 
555 
556 ${PLACEHOLDER}
557 
Namespace for fields component of sheaf system.
The default name space; a poset which contains other posets as members.
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
SHEAF_DLL_SPEC field_at0 & operator>>(const field_at0 &xsrc, field_at0 &xdst)
Pushes xsrc.property() to xdst.property().
Definition: field_at0.cc:513
A client handle for a member of a base space poset.
Abstract base class with useful features for all objects.
Definition: any.h:39
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &xos, const field_at0 &xfield)
Inserts field_at0 xfield into ostream xos.
Definition: field_at0.cc:535
Namespace for the fiber_bundles component of the sheaf system.