SheafSystem  0.0.0.0
unary_index_space.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 #ifndef UNARY_INDEX_SPACE_H
19 #define UNARY_INDEX_SPACE_H
20 
21 #ifndef SHEAF_DLL_SPEC_H
22 #include "SheafSystem/sheaf_dll_spec.h"
23 #endif
24 
25 #ifndef UNARY_INDEX_H
26 #include "SheafSystem/unary_index.h"
27 #endif
28 
29 #ifndef ASSERT_CONTRACT_H
30 #include "SheafSystem/assert_contract.h"
31 #endif
32 
33 #ifndef RAGGED_ARRAY_H
34 #include "SheafSystem/ragged_array.h"
35 #endif
36 
37 namespace fiber_bundle
38 {
39 
40  using namespace sheaf;
41 
45 class SHEAF_DLL_SPEC unary_index_space
46 {
47 public:
51  unary_index i_size;
52 
56  unary_index size;
57 
61  bool invariant() const
62  {
63  invariance(i_size >= 0);
64  invariance(size == i_size);
65  return true;
66  }
67 
68 
73  {
74  // Preconditions:
75 
76  // Body:
77 
78  put_bounds(0);
79 
80  // Postconditions:
81 
82  ensure(invariant());
83  ensure(i_size == 0);
84 
85  // Exit:
86 
87  return;
88  };
89 
93  unary_index_space(unary_index xct)
94  {
95  // Preconditions:
96 
97  require(xct >= 0);
98 
99  // Body:
100 
101  put_bounds(xct);
102 
103  // Postconditions:
104 
105  ensure(invariant());
106  ensure(i_size == xct);
107 
108  // Exit:
109 
110  return;
111  };
112 
116  void put_bounds(unary_index xct = 0)
117  {
118  // Preconditions:
119 
120  // Body:
121 
122  i_size = xct;
123  size = xct;
124 
125  // Postconditions:
126 
127  ensure(invariant());
128  ensure(i_size == xct);
129 
130  // Exit:
131 
132  return;
133  };
134 
139  {
140  // Preconditions:
141 
142  // Body:
143 
144  unary_index_space result(i_size+xother.i_size);
145 
146  // Postconditions:
147 
148  ensure(invariant());
149  ensure(result.i_size == i_size+xother.i_size);
150 
151  // Exit:
152 
153  return result;
154  };
155 
160  {
161  // Preconditions:
162 
163  // Body:
164 
165  unary_index_space result(i_size*xother.i_size);
166 
167  // Postconditions:
168 
169  ensure(invariant());
170  ensure(result.i_size == i_size*xother.i_size);
171 
172  // Exit:
173 
174  return result;
175  };
176 
180  bool contains(const unary_index& xindex) const
181  {
182  // Preconditions:
183 
184  // Body:
185 
186  bool result = ((0 <= xindex) && (xindex < i_size));
187 
188  // Postconditions:
189 
190  ensure(result == ((0 <= xindex) && (xindex < i_size)));
191 
192  // Exit:
193 
194  return result;
195  };
196 
201  ragged_array<unary_index>* neighbor_list() const;
202 };
203 
204 
205 // ===========================================================
206 // NON-MEMBER FUNCTIONS
207 // ===========================================================
208 
209 #ifndef DOXYGEN_1_5_4_SKIP_UNKNOWN
210 
214 SHEAF_DLL_SPEC std::ostream& operator<<(std::ostream& os, const unary_index_space& xbis);
215 
216 #endif // ifndef DOXYGEN_1_5_4_SKIP_UNKNOWN
217 
218 } // namespace fiber_bundle
219 
220 
221 #endif // ifndef UNARY_INDEX_SPACE_H
unary_index_space operator*(const unary_index_space &xother) const
Cartesian product.
void put_bounds(unary_index xct=0)
Sets i_size = xct and recomputes size.
unary_index i_size
Upper bound for the i index.
bool invariant() const
Class invariant.
unary_index_space(unary_index xct)
Creates an instance with bound (xct).
A bounded domain for unary_index objects.
bool contains(const unary_index &xindex) const
True if xindex is in this space.
unary_index_space operator+(const unary_index_space &xother) const
Sum.
unary_index size
Number in the space.
Namespace for the sheaves component of the sheaf system.
A two index array with variable length rows.
unary_index_space()
Creates an instance with bound (0,0).
Namespace for the fiber_bundles component of the sheaf system.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const binary_index &xbi)
Insert binary_index& xbi into ostream& os.
Definition: binary_index.cc:35