SheafSystem  0.0.0.0
d_bin_coordinates.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/d_bin_coordinates.impl.h"
22 
23 #include "SheafSystem/std_iostream.h"
24 
25 using namespace std;
26 using namespace geometry; // Workaround for MS C++ bug.
27 
28 //==============================================================================
29 // SPECIALIZATIONS
30 //==============================================================================
31 
32 template<>
36 {
38 
39  // Preconditions:
40 
41  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
42 
43  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
44 
45  result = (_int_value[0] & lbranch_mask) ? 1 : 0;
46 
47  // Postconditions:
48 
49  ensure(result < degree());
50 
51  // Exit:
52 
53  return result;
54 }
55 
56 template<>
57 void
60 {
61  // Preconditions:
62 
63  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
64  require(xbranch < degree());
65 
66  // Body:
67 
68  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
69  int_type lnot_branch_mask = ~lbranch_mask;
70 
71  _int_value[0] =
72  (xbranch & 1) ? _int_value[0] | lbranch_mask : _int_value[0] & lnot_branch_mask;
73 
74  // Postconditions:
75 
76  ensure(branch(xbit) == xbranch);
77 
78  // Exit:
79 
80  return;
81 }
82 
83 template<>
87 {
89 
90  // Preconditions:
91 
92  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
93 
94  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
95 
96  result = (_int_value[0] & lbranch_mask) ? 2 : 0;
97  result = (_int_value[1] & lbranch_mask) ? result + 1 : result;
98 
99  // Postconditions:
100 
101  ensure(result < degree());
102 
103  // Exit:
104 
105  return result;
106 }
107 
108 template<>
109 void
112 {
113  // Preconditions:
114 
115  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
116  require(xbranch < degree());
117 
118  // Body:
119 
120  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
121  int_type lnot_branch_mask = ~lbranch_mask;
122 
123  _int_value[0] =
124  (xbranch & 2) ? _int_value[0] | lbranch_mask : _int_value[0] & lnot_branch_mask;
125  _int_value[1] =
126  (xbranch & 1) ? _int_value[1] | lbranch_mask : _int_value[1] & lnot_branch_mask;
127 
128  // Postconditions:
129 
130  ensure(branch(xbit) == xbranch);
131 
132  // Exit:
133 
134  return;
135 }
136 
137 template<>
141 {
143 
144  // Preconditions:
145 
146  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
147 
148  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
149 
150  result = (_int_value[0] & lbranch_mask) ? 4 : 0;
151  result = (_int_value[1] & lbranch_mask) ? result + 2 : result;
152  result = (_int_value[2] & lbranch_mask) ? result + 1 : result;
153 
154  // Postconditions:
155 
156  ensure(result < degree());
157 
158  // Exit:
159 
160  return result;
161 }
162 
163 template<>
164 void
167 {
168  // Preconditions:
169 
170  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
171  require(xbranch < degree());
172 
173  // Body:
174 
175  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
176  int_type lnot_branch_mask = ~lbranch_mask;
177 
178  _int_value[0] =
179  (xbranch & 4) ? _int_value[0] | lbranch_mask : _int_value[0] & lnot_branch_mask;
180  _int_value[1] =
181  (xbranch & 2) ? _int_value[1] | lbranch_mask : _int_value[1] & lnot_branch_mask;
182  _int_value[2] =
183  (xbranch & 1) ? _int_value[2] | lbranch_mask : _int_value[2] & lnot_branch_mask;
184 
185  // Postconditions:
186 
187  ensure(branch(xbit) == xbranch);
188 
189  // Exit:
190 
191  return;
192 }
193 
194 template<>
198 {
200 
201  // Preconditions:
202 
203  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
204 
205  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
206 
207  result = (_int_value[0] & lbranch_mask) ? 8 : 0;
208  result = (_int_value[1] & lbranch_mask) ? result +4 : result;
209  result = (_int_value[2] & lbranch_mask) ? result + 2 : result;
210  result = (_int_value[3] & lbranch_mask) ? result + 1 : result;
211 
212  // Postconditions:
213 
214  ensure(result < degree());
215 
216  // Exit:
217 
218  return result;
219 }
220 
221 template<>
222 void
225 {
226  // Preconditions:
227 
228  require((rightmost_bit_id() <= xbit) && (xbit <= leftmost_bit_id()));
229  require(xbranch < degree());
230 
231  // Body:
232 
233  int_type lbranch_mask = static_cast<int_type>(1) << xbit;
234  int_type lnot_branch_mask = ~lbranch_mask;
235 
236  _int_value[0] =
237  (xbranch & 8) ? _int_value[0] | lbranch_mask : _int_value[0] & lnot_branch_mask;
238  _int_value[1] =
239  (xbranch & 4) ? _int_value[1] | lbranch_mask : _int_value[1] & lnot_branch_mask;
240  _int_value[2] =
241  (xbranch & 2) ? _int_value[2] | lbranch_mask : _int_value[2] & lnot_branch_mask;
242  _int_value[3] =
243  (xbranch & 1) ? _int_value[3] | lbranch_mask : _int_value[3] & lnot_branch_mask;
244 
245  // Postconditions:
246 
247  ensure(branch(xbit) == xbranch);
248 
249  // Exit:
250 
251  return;
252 }
unsigned long long int_type
The type used for integer coordinates.
void put_branch(size_type xbit, size_type xbranch)
Set the branch index at bit position xbit to xbranch.
STL namespace.
size_type branch(size_type xbit) const
The branch index at bit position xbit.
sheaf::size_type size_type
An unsigned integral type used to represent sizes and capacities.
Namespace for geometry component of sheaf system.
Definition: field_vd.h:54