SheafSystem  0.0.0.0
record_index.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 
19 // Interface for class record_index
20 
21 #ifndef RECORD_INDEX_H
22 #define RECORD_INDEX_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef ASSERT_CONTRACT_H
29 #include "SheafSystem/assert_contract.h"
30 #endif
31 
32 #ifndef SCOPED_INDEX_H
33 #include "SheafSystem/scoped_index.h"
34 #endif
35 
36 namespace sheaf
37 {
38 
43 
48 {
49  record_index::pod_type poset_id;
50  record_index::pod_type member_id;
51 
53  {
54  return (poset_id == xother.poset_id) && (member_id == xother.member_id);
55  };
56 
57  bool is_valid()
58  {
59  return (sheaf::is_valid(poset_id) && sheaf::is_valid(member_id));
60  };
61 };
62 
67 class SHEAF_DLL_SPEC namespace_relative_record_index
68 {
69 public:
70 
75 
80  {
81  // Preconditions:
82 
83  // Body:
84 
85  // Scoped_index data members are invalid by default.
86 
87  // Postconditions:
88 
89  ensure(!is_valid());
90 
91  // Exit:
92 
93  return;
94  };
95 
99  record_index poset_id;
100 
104  record_index member_id;
105 
110  : poset_id(xother.poset_id),
111  member_id(xother.member_id)
112  {
113  // Preconditions:
114 
115  // Body:
116 
117 
118  // Postconditions:
119 
120  ensure(*this == xother);
121 
122  // Exit:
123 
124  return;
125  };
126 
131  {
132  // Preconditions:
133 
134  // Body:
135 
136  poset_id = xother.poset_id;
137  member_id = xother.member_id;
138 
139  // Postconditions:
140 
141  ensure(*this == xother);
142 
143  // Exit:
144 
145  return *this;
146  };
147 
148 
149 
153  inline bool operator==(const namespace_relative_record_index& xother) const
154  {
155  bool result;
156 
157  // Preconditions:
158 
159  // Body:
160 
161  result = ((poset_id == xother.poset_id) && (member_id == xother.member_id));
162 
163  // Postconditions:
164 
165  ensure(result == ((poset_id == xother.poset_id) && (member_id == xother.member_id)));
166 
167  // Exit:
168 
169  return result;
170  };
171 
175  inline bool is_valid() const
176  {
177  bool result;
178 
179  // Preconditions:
180 
181  // Body:
182 
183  result = (poset_id.is_valid() && member_id.is_valid());
184 
185  // Postconditions:
186 
187  // Exit:
188 
189  return result;
190  };
191 
195  void invalidate()
196  {
197  // Preconditions:
198 
199  // Body:
200 
201  poset_id.invalidate();
202  member_id.invalidate();
203 
204  // Postconditions:
205 
206  ensure(!is_valid());
207 
208  // Exit:
209 
210  return;
211  };
212 
217  {
218  // Preconditions:
219 
220  // Body:
221 
222  // Default constructor makes invalid.
223 
224  static const namespace_relative_record_index result;
225 
226  // Postconditions:
227 
228  ensure(!result.is_valid());
229 
230  // Exit:
231 
232  return result;
233  };
234 
238  inline pod_type pod() const
239  {
240  pod_type result;
241  result.poset_id = poset_id.pod();
242  result.member_id = member_id.pod();
243 
244  return result;
245  };
246 
250  inline void put_pod(pod_type xpod)
251  {
252 
253  // Preconditions:
254 
255  // Body:
256 
257  poset_id.put_pod(xpod.poset_id);
258  member_id.put_pod(xpod.member_id);
259 
260  // Postconditions:
261 
262  ensure(pod() == xpod || !is_valid());
263 
264  // Exit:
265 
266  return;
267  };
268 
269 
270 
271 };
272 
273 } // namespace sheaf
274 
275 #endif // ifndef RECORD_INDEX_H
276 
277 
278 
279 
280 
281 
bool operator==(const namespace_relative_record_index &xother) const
Equality operator.
Definition: record_index.h:153
void put_pod(pod_type xpod)
Sets pod() to xpod.
Definition: record_index.h:250
bool is_valid() const
True if this is a valid id.
Definition: scoped_index.h:832
scoped_index record_index
The type used for indexing records in a dataset.
Definition: record_index.h:42
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
namespace_relative_record_index & operator=(const namespace_relative_record_index &xother)
Assignment operator.
Definition: record_index.h:130
namespace_relative_record_index()
Default constructor.
Definition: record_index.h:79
void invalidate()
Make this id invalid.
Definition: scoped_index.h:852
pod_type pod() const
The "plain old data" storage of this.
Definition: record_index.h:238
record_index member_id
The record index of the member relative to the poset.
Definition: record_index.h:104
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
Record index equivalent to namespace_relative_member_index and namespace_relative_subposet_index.
Definition: record_index.h:67
bool operator==(const singly_linked_list< T, Alloc > &lhs, const singly_linked_list< T, Alloc > &rhs)
Checks if the contents of lhs and rhs are equal, that is, whether lhs.size() == rhs.size() and each element in lhs compares equal with the element in rhs at the same position.
void invalidate()
Make this invalid.
Definition: record_index.h:195
pod_index_type pod_type
The "plain old data" storage type for this.
Definition: scoped_index.h:128
namespace_relative_record_index(const namespace_relative_record_index &xother)
Copy constructor.
Definition: record_index.h:109
Namespace for the sheaves component of the sheaf system.
record_index poset_id
The record index of the poset relative to the namespace.
Definition: record_index.h:94
namespace_relative_record_index_pod_type pod_type
The POD (plain old data) type associated this.
Definition: record_index.h:74
The POD (plain old data) type associated with this.
Definition: record_index.h:47
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
bool is_valid() const
True if this is a valid id.
Definition: record_index.h:175
void put_pod(pod_type xpod)
Sets pod() to xpod.
Definition: scoped_index.h:680
static const namespace_relative_record_index & INVALID()
The invalid id.
Definition: record_index.h:216