SheafSystem  0.0.0.0
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/scoped_index.h"
22 
23 #include "SheafSystem/poset_state_handle.h"
24 #include "SheafSystem/std_iomanip.h"
25 
26 // ===========================================================
27 // SCOPED_INDEX FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
33 scoped_index(const poset_state_handle& xhost, const std::string& xname)
34  : _id_spaces(&xhost.member_id_spaces(false)),
35  _scope_id(xhost.member_id_spaces(false).index(xname)),
36  _pod(invalid_pod())
37 {
38  // Preconditions:
39 
40  require(xhost.state_is_read_accessible());
41  require(!xname.empty());
42  require(xhost.member_id_spaces(false).contains(xname));
43 
44  // Body:
45 
46  // Postconditions:
47 
48  ensure(invariant());
49  ensure(id_spaces().name(scope_id()) == xname);
50  ensure(&id_spaces() == &xhost.member_id_spaces(false));
51  ensure(!is_valid());
52 
53  // Exit:
54 
55  return;
56 }
57 
59 scoped_index(pod_type xpod, const poset_state_handle& xhost, const std::string& xname)
60  : _id_spaces(&xhost.member_id_spaces(false)),
61  _scope_id(xhost.member_id_spaces(false).index(xname)),
62  _pod(xpod)
63 {
64  // Preconditions:
65 
66  require(xhost.state_is_read_accessible());
67  require(!xname.empty());
68  require(xhost.member_id_spaces(false).contains(xname));
69 
70  // Body:
71 
72  // Postconditions:
73 
74  ensure(invariant());
75  ensure(id_spaces().name(scope_id()) == xname);
76  ensure(&id_spaces() == &xhost.member_id_spaces(false));
77  ensure(pod() == xpod);
78 
79  // Exit:
80 
81  return;
82 }
83 
85 scoped_index(const scoped_index& xother, const poset_state_handle& xhost, const std::string& xname)
86  : _id_spaces(&xhost.member_id_spaces(false)),
87  _scope_id(xhost.member_id_spaces(false).index(xname))
88 {
89  // Preconditions:
90 
91  require(xhost.state_is_read_accessible());
92  require(!xname.empty());
93  require(xhost.member_id_spaces(false).contains(xname));
94 
95  // Body:
96 
97  _pod = _id_spaces->pod(_scope_id, xother);
98 
99  // Postconditions:
100 
101  ensure(invariant());
102  ensure(id_spaces().name(scope_id()) == xname);
103  ensure(&id_spaces() == &xhost.member_id_spaces(false));
104  ensure((*this) ==~ xother);
105 
106  // Exit:
107 
108  return;
109 }
110 
111 // PROTECTED MEMBER FUNCTIONS
112 
113 // PRIVATE MEMBER FUNCTIONS
114 
115 
116 // ===========================================================
117 // NON-MEMBER FUNCTIONS
118 // ===========================================================
119 
120 std::ostream&
121 sheaf::operator<<(std::ostream& xos, const scoped_index& xid)
122 {
123  if(xid.is_scoped())
124  {
125  xos << " (" << xid.scope_id() << ", " << xid.pod()<< ")";
126  }
127  else
128  {
129  xos << " (" << invalid_pod_index() << ", " << xid.pod() << ")";
130  }
131 
132  return xos;
133 }
134 
135 std::istream&
136 sheaf::operator>>(std::istream& xis, scoped_index& xid)
137 {
139  xis >> lpod;
140  xid.put_pod(lpod);
141 
142  return xis;
143 }
144 
145 size_t
146 sheaf::deep_size(const scoped_index& xp, bool xinclude_shallow)
147 {
148  size_t result;
149 
150  // Preconditions:
151 
152  // Body:
153 
154  result = xinclude_shallow ? sizeof(xp) : 0;
155 
156  // Postconditions:
157 
158  ensure(result >= 0);
159 
160  // Exit
161 
162  return result;
163 }
164 
165 
166 // ===========================================================
167 // TEMPLATE SPECIALIZATIONS
168 // ===========================================================
169 
170 size_t
171 unordered::hash<sheaf::scoped_index>::
172 operator()(sheaf::scoped_index xindex) const
173 {
174  return xindex.hub_pod();
175 }
176 
bool is_valid() const
True if this is a valid id.
Definition: scoped_index.h:832
pod_type pod(const std::string &xname, pod_type xid) const
The pod index in the space with name xname equivalent to xid in the hub id space. ...
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
A client handle for a general, abstract partially order set.
const index_space_family & member_id_spaces(bool xauto_access) const
Collection of member id spaces for this (const version).
const index_space_family & id_spaces() const
The id space family for this scope.
Definition: scoped_index.h:498
scoped_index()
Default constructor; creates an invalid instance.
Definition: scoped_index.h:133
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
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
SHEAF_DLL_SPEC std::istream & operator>>(std::istream &is, dof_tuple_type &xdt)
Extract dof_tuple_type xdt from istream& is.
pod_index_type pod_type
The "plain old data" storage type for this.
Definition: scoped_index.h:128
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
bool invariant() const
Class invariant.
Definition: scoped_index.h:417
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
void put_pod(pod_type xpod)
Sets pod() to xpod.
Definition: scoped_index.h:680
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710