SheafSystem  0.0.0.0
stl_scoped_index.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/stl_scoped_index.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 using namespace sheaf;
25 
26 // ===========================================================
27 // LEXOGRAPHICAL_COMPARE_POLICY
28 // ===========================================================
29 
30 bool
32 less_than(const scoped_index& xindex1, const scoped_index& xindex2)
33 {
34  // Preconditions:
35 
36  require(xindex1.is_scoped());
37  require(xindex2.is_scoped());
38 
39  // Body:
40 
41  bool result;
42 
43  if(xindex1.scope_id() == xindex2.scope_id())
44  result = (xindex1.pod() < xindex2.pod());
45  else
46  result = (xindex1.scope_id() < xindex2.scope_id());
47 
48  // Postconditions:
49 
50  ensure((xindex1.scope_id() == xindex2.scope_id()) ?
51  result == xindex1.pod() < xindex2.pod() :
52  (xindex1.scope_id() < xindex2.scope_id()));
53 
54  // Exit:
55 
56  return result;
57 }
58 
59 bool
61 equal(const scoped_index& xindex1, const scoped_index& xindex2)
62 {
63  // Preconditions:
64 
65  // Body:
66 
67  bool result = (xindex1 == xindex2);
68 
69  // Postconditions:
70 
71  ensure(result == (xindex1 == xindex2));
72 
73  // Exit:
74 
75  return result;
76 }
77 
78 // ===========================================================
79 // EQUIVALENCE_COMPARE_POLICY
80 // ===========================================================
81 
82 bool
84 less_than(const scoped_index& xindex1, const scoped_index& xindex2)
85 {
86  // Preconditions:
87 
88  require(xindex1.is_scoped());
89  require(xindex2.is_scoped());
90 
91  // Body:
92 
93  bool result = (xindex1 <~ xindex2);
94 
95  // Postconditions:
96 
97  ensure(result == (xindex1 <~ xindex2));
98 
99  // Exit:
100 
101  return result;
102 }
103 
104 bool
106 equal(const scoped_index& xindex1, const scoped_index& xindex2)
107 {
108  // Preconditions:
109 
110  require(xindex1.is_scoped());
111  require(xindex2.is_scoped());
112 
113  // Body:
114 
115  bool result = (xindex1 ==~ xindex2);
116 
117  // Postconditions:
118 
119  ensure(result == (xindex1 ==~ xindex2));
120 
121  // Exit:
122 
123  return result;
124 }
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
static bool less_than(const scoped_index &xindex1, const scoped_index &xindex2)
True, if xindex1 is less than xindex2.
pod_type scope_id() const
The index of the scope id space.
Definition: scoped_index.h:516
bool is_scoped() const
True if and only if scope() is attached.
Definition: scoped_index.h:592
static bool equal(const scoped_index &xindex1, const scoped_index &xindex2)
True, if xindex1 is equal to xindex2.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
static bool less_than(const scoped_index &xindex1, const scoped_index &xindex2)
True, if xindex1 is less than xindex2.
static bool equal(const scoped_index &xindex1, const scoped_index &xindex2)
True, if xindex1 is equal to xindex2.
Namespace for the sheaves component of the sheaf system.