SheafSystem  0.0.0.0
sec_jcb.impl.h
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 
18 // Implementation for sec_jcb facet function templates.
19 
20 #ifndef SEC_JCB_IMPL_H
21 #define SEC_JCB_IMPL_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef ASSERT_CONTRACT_H
28 #include "SheafSystem/assert_contract.h"
29 #endif
30 
31 #ifndef SEC_JCB_H
32 #include "SheafSystem/sec_jcb.h"
33 #endif
34 
35 namespace fiber_bundle
36 {
37 
38 //==============================================================================
39 // NON-MEMBER FUNCTIONS
40 //==============================================================================
41 
42 //==============================================================================
43 
45 template <typename VJCB, typename VCOVECTOR, typename VR>
46 void
47 pull_functor<VJCB, VCOVECTOR, VR>::
48 operator()(const VJCB& xjcb, const VCOVECTOR& xcovector, VR& xresult)
49 {
50  // Preconditions:
51 
52  require(precondition_of(pull(xjcb, xcovector, xresult)));
53 
54  // Body:
55 
56  pull(xjcb, xcovector, xresult);
57 
58  // Postconditions:
59 
60  ensure(postcondition_of(pull(xjcb, xcovector, xresult)));
61 
62  // Exit:
63 
64  return;
65 }
66 
68 template <typename VJCB, typename VVECTOR, typename VR>
69 void
70 push_functor<VJCB, VVECTOR, VR>::
71 operator()(const VJCB& xjcb, const VVECTOR& xvector, VR& xresult)
72 {
73  // Preconditions:
74 
75  require(precondition_of( push(xjcb, xvector, xresult)));
76 
77  // Body:
78 
79  push(xjcb, xvector, xresult);
80 
81  // Postconditions:
82 
83  ensure(postcondition_of( push(xjcb, xvector, xresult)));
84 
85  // Exit:
86 
87  return;
88 }
89 
90 
91 //==============================================================================
92 
94 template <typename SJCB, typename SCOVECTOR, typename SR>
95 void pull(const SJCB& xjcb, const SCOVECTOR& xcovector, SR& xresult,
96  bool xauto_access)
97 {
98  // Preconditions:
99 
100  require(xjcb.state_is_auto_read_accessible(xauto_access));
101  require(xcovector.state_is_auto_read_accessible(xauto_access));
102  require(xresult.state_is_auto_read_write_accessible(xauto_access));
103  require(xcovector.is_p_form(xauto_access));
104 
105  // Body:
106 
107  if(xauto_access)
108  {
109  xjcb.get_read_access();
110  xcovector.get_read_access();
111  xresult.get_read_write_access(true);
112  }
113 
114  typedef typename SJCB::fiber_type::volatile_type VJCB;
115  typedef typename SCOVECTOR::fiber_type::volatile_type VCOVECTOR;
116  typedef typename SR::fiber_type::volatile_type VR;
117  pull_functor<VJCB, VCOVECTOR, VR> f;
118  binary_op(xjcb, xcovector, xresult, f, xauto_access);
119 
120  // Make sure the result is covariant/p_form.
121 
122  xresult.put_is_p_form(false);
123 
124 
125  if(xauto_access)
126  {
127  xjcb.release_access();
128  xcovector.release_access();
129  xresult.release_access();
130  }
131 
132  // Postconditions:
133 
134  ensure(xresult.is_p_form(xauto_access));
135 
136  // Exit:
137 
138  return;
139 }
140 
142 template <typename SJCB, typename SVECTOR, typename SR>
143 void push(const SJCB& xjcb, const SVECTOR& xvector, SR& xresult,
144  bool xauto_access)
145 {
146  // Preconditions:
147 
148  require(xjcb.state_is_auto_read_accessible(xauto_access));
149  require(xvector.state_is_auto_read_accessible(xauto_access));
150  require(xresult.state_is_auto_read_write_accessible(xauto_access));
151  require(xvector.is_p_vector(xauto_access));
152 
153  // Body:
154 
155  if(xauto_access)
156  {
157  xjcb.get_read_access();
158  xvector.get_read_access();
159  xresult.get_read_write_access(true);
160  }
161 
162  typedef typename SJCB::fiber_type::volatile_type VJCB;
163  typedef typename SVECTOR::fiber_type::volatile_type VVECTOR;
164  typedef typename SR::fiber_type::volatile_type VR;
165  push_functor<VJCB, VVECTOR, VR> f;
166  binary_op(xjcb, xvector, xresult, f, xauto_access);
167 
168  // Make sure the result is p_vector.
169 
170  xresult.put_is_p_vector(false);
171 
172  if(xauto_access)
173  {
174  xjcb.release_access();
175  xvector.release_access();
176  xresult.release_access();
177  }
178 
179  // Postconditions:
180 
181  ensure(xresult.is_p_vector(xauto_access));
182 
183  // Exit:
184 
185  return;
186 }
187 
188 } // namespace fiber_bundle
189 
190 #endif // ifndef SEC_JCB_IMPL_H
void pull(const SJCB &xjcb, const SCOVECTOR &xcovector, SR &xresult, bool xauto_access)
Definition: sec_jcb.impl.h:95
void push(const SJCB &xjcb, const SVECTOR &xvector, SR &xresult, bool xauto_access)
Definition: sec_jcb.impl.h:143
void binary_op(const S0 &x0, const S1 &x1, SR &xresult, F xfunctor, bool xauto_access)
Binary operator.
Definition: sec_vd.impl.h:48
Namespace for the fiber_bundles component of the sheaf system.