SheafSystem  0.0.0.0
index_scope.cc
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 // Implementation for class index_scope
20 
21 #include "SheafSystem/index_scope.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/scoped_index.h"
25 
26 // ===========================================================
27 // INDEX_SCOPE FACET
28 // ===========================================================
29 
31 sheaf::index_scope::
32 index_scope(const immutable_id_map* xmap)
33 {
34 
35  // Preconditions:
36 
37 
38  // Body:
39 
40  define_old_variable(const immutable_id_map*
41  old_scoped_index_default_map = scoped_index::default_map());
42 
43  _old_scope = scoped_index::default_map();
44  scoped_index::private_default_map() = xmap;
45 
46  // Postconditions:
47 
48  ensure(scope() == xmap);
49  ensure(old_scope() == old_scoped_index_default_map);
50 
51  // Exit:
52 
53  return;
54 }
55 
56 
60 {
61  // Preconditions:
62 
63 
64  // Body:
65 
66  scoped_index::private_default_map() = _old_scope;
67 
68  // Postconditions:
69 
70  ensure(scope() == old_scope());
71 
72  // Exit:
73 
74  return;
75 }
76 
77 
78 
80 const sheaf::immutable_id_map*
82 scope() const
83 {
84  // Preconditions:
85 
86 
87  // Body:
88 
89  const immutable_id_map* result = scoped_index::default_map();
90 
91  // Postconditions:
92 
93  ensure(result == scoped_index::default_map());
94 
95  // Exit:
96 
97  return result;
98 }
99 
100 
102 void
104 put_scope(const immutable_id_map* xmap)
105 {
106  // Preconditions:
107 
108 
109  // Body:
110 
111  define_old_variable(const immutable_id_map* old_old_scope = _old_scope);
112 
113  scoped_index::private_default_map() = xmap;
114 
115  // Postconditions:
116 
117  ensure(scope() == xmap);
118  ensure(old_scope() == old_old_scope);
119 
120  // Exit:
121 
122  return;
123 }
124 
125 
126 
128 const sheaf::immutable_id_map*
130 old_scope() const
131 {
132  return _old_scope;
133 }
134 
135 
136 
137 // ===========================================================
138 // NON-MEMBER FUNCTIONS
139 // ===========================================================
140 
const immutable_id_map * _old_scope
The scope before this was created.
Definition: index_scope.h:82
void put_scope(const immutable_id_map *xmap)
Sets scoped_index::default_scope() to xmap.
Definition: index_scope.cc:104
~index_scope()
Destructor; restores scoped_index::default_scope() to old_scope(). Not virtual; this class can not be...
Definition: index_scope.cc:59
const immutable_id_map * old_scope() const
The scope before this was created.
Definition: index_scope.cc:130
const immutable_id_map * scope() const
The current scope.
Definition: index_scope.cc:82