SheafSystem  0.0.0.0
sec_tuple_space.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/sec_tuple_space.impl.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/binary_section_space_schema_member.impl.h"
26 #include "SheafSystem/binary_section_space_schema_poset.h"
27 #include "SheafSystem/fiber_bundles_namespace.h"
28 #include "SheafSystem/namespace_poset.impl.h"
29 #include "SheafSystem/namespace_poset_member.h"
30 #include "SheafSystem/poset_handle_factory.h"
31 #include "SheafSystem/section_space_schema_member.impl.h"
32 #include "SheafSystem/section_space_schema_poset.h"
33 #include "SheafSystem/sec_tuple.h"
34 #include "SheafSystem/tuple.h"
35 #include "SheafSystem/tuple_space.h"
36 
37 using namespace std;
38 using namespace fiber_bundle; // Workaround for MS C++ bug.
39 
40 //#define DIAGNOSTIC_OUTPUT
41 
42 //==============================================================================
43 // SEC_TUPLE_SPACE FACET
44 //==============================================================================
45 
46 // PUBLIC MEMBER FUNCTIONS
47 
48 bool
51  const poset_path& xsection_schema_path,
52  const poset_path& xfiber_schema_path,
53  bool xauto_access)
54 {
55  // cout << endl << "Entering sec_tuple_space::fiber_schema_conforms." << endl;
56 
57  // Preconditions:
58 
59  require(xns.state_is_auto_read_accessible(xauto_access));
60 
61  require(!xsection_schema_path.empty());
62  require(xns.path_is_auto_read_accessible(xsection_schema_path, xauto_access));
63 
64  require(xfiber_schema_path.full());
65  require(xns.path_is_auto_read_accessible(xfiber_schema_path, xauto_access));
66 
67  // Body:
68 
69  section_space_schema_poset& lschema_host = xns.member_poset<section_space_schema_poset>(xsection_schema_path, xauto_access);
70 
71  bool result = lschema_host.fiber_space().schema(xauto_access).conforms_to(xfiber_schema_path);
72 
73  // Postconditions:
74 
75 
76  // Exit:
77 
78  // cout << "Leaving sec_tuple_space::fiber_schema_conforms." << endl;
79  return result;
80 }
81 
82 
85 new_table(namespace_type& xns, const poset_path& xpath, const poset_path& xschema_path, bool xauto_access)
86 {
87  // cout << endl << "Entering sec_tuple_space::new_table." << endl;
88 
89  // Preconditions:
90 
91  require(xns.state_is_auto_read_write_accessible(xauto_access));
92 
93  require(!xpath.empty());
94  require(!xns.contains_path(xpath, xauto_access));
95 
96  require(xschema_path.full());
97  require(xns.path_is_auto_read_accessible<schema_type::host_type>(xschema_path, xauto_access));
98  require(fiber_space_conforms<fiber_type::host_type>(xns, xschema_path, xauto_access));
99 
100  // Body:
101 
102  // Create the table; have to new it because namespace keeps a pointer.
103 
104  typedef sec_tuple_space table_type;
105 
106  table_type& result = *(new table_type());
107 
108  // Create a handle of the right type for the schema member.
109 
110  schema_type lschema(xns, xschema_path, xauto_access);
111 
112  if(xauto_access)
113  {
114  lschema.get_read_access();
115  }
116 
117  // Create the table dof map.
118 
119  array_poset_dof_map& lmap = *(new array_poset_dof_map(&lschema, true));
120 
121  // The table dofs are the samae as the fiber schema,
122  // so just copy them from the fiber schema.
123  // Can't use copy constructor because schema objects are different.
124 
125  array_poset_dof_map& lfiber_map = lschema.fiber_space().table_dof_map();
126  lmap.copy_dof_tuple(lfiber_map);
127 
128  // Create the state.
129 
130  result.new_state(xns, xpath, lschema, lmap);
131 
132  if(xauto_access)
133  {
134  lschema.release_access();
135  }
136 
137  // Postconditions:
138 
139  ensure(xns.owns(result, xauto_access));
140  ensure(result.path(true) == xpath);
141  ensure(result.state_is_not_read_accessible());
142  ensure(result.schema(true).path(xauto_access) == xschema_path);
143 
144  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
145 
146  // Exit:
147 
148  // cout << "Leaving sec_tuple_space::new_table." << endl;
149  return result;
150 }
151 
152 //==============================================================================
153 // TABLE DOFS
154 //==============================================================================
155 
156 int
158 factor_ct() const
159 {
160  // Preconditions:
161 
162  require(state_is_read_accessible());
163 
164  // Body:
165 
166  int result = sheaf::table_dofs(*this).factor_ct;
167 
168  // Postconditions:
169 
170  // Exit:
171 
172  return result;
173 }
174 
175 int
177 factor_ct(bool xauto_access) const
178 {
179  // Preconditions:
180 
181  require(state_is_auto_read_accessible(xauto_access));
182 
183  // Body:
184 
185  if(xauto_access)
186  {
187  get_read_access();
188  }
189 
190  int result = factor_ct();
191 
192  if(xauto_access)
193  {
194  release_access();
195  }
196 
197  // Postconditions:
198 
199 
200  // Exit:
201 
202  return result;
203 }
204 
205 // PROTECTED MEMBER FUNCTIONS
206 
209  : sec_rep_space(new sec_tuple, new sec_tuple)
210 {
211  // Preconditions:
212 
213  // Body:
214 
215  // Nothing to do, handled by base class
216 
217  // Postconditions:
218 
219  ensure(postcondition_of(sec_rep_space::sec_rep_space()));
220 }
221 
224 {
225  // Preconditions:
226 
227  // Body:
228 
229  // Postconditions:
230 
231  // Exit
232 
233  return;
234 }
235 
238  : sec_rep_space(xtop, xbottom)
239 {
240  // Preconditions:
241 
242  require(xtop != 0);
243  require(xbottom != 0);
244 
245  // Body:
246 
247  // Nothing to do.
248 
249  // Postconditions:
250 
251  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
252 
253  // Exit:
254 
255  return;
256 }
257 
258 // PRIVATE MEMBER FUNCTIONS
259 
260 
261 // ===========================================================
262 // SEC_REP_SPACE FACET
263 // ===========================================================
264 
265 // PUBLIC MEMBER FUNCTIONS
266 
267 // PROTECTED MEMBER FUNCTIONS
268 
269 // PRIVATE MEMBER FUNCTIONS
270 
271 bool
272 fiber_bundle::sec_tuple_space::
273 make_prototype()
274 {
275  bool result = false;
276 
277  // Preconditions:
278 
279  // Body:
280 
281  sec_tuple_space* lproto = new sec_tuple_space;
282  poset_type ltype = lproto->type_id();
283 
284  factory().insert_prototype(lproto);
285  factory().insert_prototype(ltype, lproto);
286 
287  // Postconditions:
288 
289  // Exit:
290 
291  return result;
292 }
293 
294 
295 //==============================================================================
296 // POSET_STATE_HANDLE FACET
297 //==============================================================================
298 
299 // PUBLIC MEMBER FUNCTIONS
300 
303 type_id() const
304 {
305  return SEC_TUPLE_SPACE_ID;
306 }
307 
310 
311 const char*
313 class_name() const
314 {
315  // Preconditions:
316 
317  // Body:
318 
319  static const char* result = "sec_tuple_space";
320 
321  // Postconditions:
322 
323  // Exit:
324 
325  return result;
326 }
327 
328 // PROTECTED MEMBER FUNCTIONS
329 
330 // PRIVATE MEMBER FUNCTIONS
331 
332 
333 //==============================================================================
334 // READ_WRITE_MONITOR_HANDLE FACET
335 //==============================================================================
336 
337 // PUBLIC MEMBER FUNCTIONS
338 
339 // PROTECTED MEMBER FUNCTIONS
340 
341 // PRIVATE MEMBER FUNCTIONS
342 
343 
344 //==============================================================================
345 // ANY FACET
346 //==============================================================================
347 
348 // PUBLIC MEMBER FUNCTIONS
349 
350 bool
352 is_ancestor_of(const any* xother) const
353 {
354  bool result;
355 
356  // Preconditions:
357 
358  // Body:
359 
360  result = dynamic_cast<const sec_tuple_space*>(xother) != 0;
361 
362  // Postconditions:
363 
364  // Exit
365 
366  return result;
367 }
368 
371 clone() const
372 {
373  sec_tuple_space* result;
374 
375  // Preconditions:
376 
377  // Body:
378 
379  result = new sec_tuple_space;
380 
381  // Postconditions:
382 
383  ensure(result != 0);
384  ensure(is_same_type(result));
385  ensure(!result->is_attached());
386 
387  // Exit
388 
389  return result;
390 }
391 
392 bool
394 invariant() const
395 {
396  bool result = true;
397 
398 
399  if(invariant_check())
400  {
402 
403  invariance(sec_rep_space::invariant());
404 
407 
409  }
410 
411  return result;
412 }
413 
414 // PROTECTED MEMBER FUNCTIONS
415 
416 // PRIVATE MEMBER FUNCTIONS
417 
418 
419 
bool state_is_auto_read_write_accessible(bool xauto_access) const
True if state is auto accessible for read and write, that is, if the state is already accessible for ...
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
A client handle for a poset member which has been prepared for use as a schema for a section space...
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
A Cartesian product section space.
virtual sec_tuple_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
bool conforms_to(const schema_poset_member &xother) const
True if the dofs defined by this agree in type and in order with the dofs defined by xother...
A section of a bundle with fiber type tuple.
Definition: sec_tuple.h:53
The default name space; a poset which contains other posets as members.
virtual poset_type type_id() const
Identifier for the type of this poset.
bool path_is_auto_read_accessible(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath exists and is auto read accessible.
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
bool state_is_auto_read_accessible(bool xauto_access) const
True if the state is auto accessible for read, that is, if the state is already accessible for read o...
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
A schema poset for a section space. A binary Cartesian product subspace of the binary tensor product ...
A Cartesian product space.
Definition: tuple_space.h:52
virtual void get_read_access() const
Get read access to the state associated with this.
poset_state_handle & member_poset(pod_index_type xhub_id, bool xauto_access=true) const
The poset_state_handle object referred to by hub id xhub_id.
sec_tuple_space()
Default constructor; creates a new sec_tuple_space handle not attached to any state.
void copy_dof_tuple(const poset_dof_map &xother)
Copies the dof tuple of xother into this.
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
Abstract base class with useful features for all objects.
Definition: any.h:39
bool invariant() const
The class invariant.
poset & fiber_space()
The fiber space for section spaces on this schema.
virtual ~sec_tuple_space()
Destructor.
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
bool owns(const poset_state_handle &xposet, bool xauto_access) const
True if and only if this contains the poset xposet. synonym for contains_poset(xposet.poset_path(true), xauto_access)
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
static bool fiber_schema_conforms(const namespace_poset &xns, const poset_path &xsection_schema_path, const poset_path &xfiber_schema_path, bool xauto_access)
True if and only if the schema of the fiber space of the section schema specified by xsection_schema_...
virtual const char * class_name() const
The name of this class.
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
poset_state_handle()
Default constructor.
static poset_handle_factory & factory()
The poset handle factory.
virtual bool is_attached() const
True if this is attached to a state.
int factor_ct() const
The number of factors in this product.
An abstract schema poset for a section space. A Cartesian product subspace of the tensor product of a...
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
T::table_dofs_type & table_dofs(T &x0)
The table dofs pod type for x0 (mutable version).
poset & fiber_space()
The fiber space for section spaces on this schema (mutable version).
sec_rep_space()
Default constructor; creates an unattached handle.
virtual bool invariant() const
Class invariant.
An array representation of abstract class poset_dof_map.
Namespace for the fiber_bundles component of the sheaf system.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
static sec_tuple_space & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, bool xauto_access)
Creates a new sec_tuple_space in namespace xns with path xpath and schema specified by xschema_path...
virtual array_poset_dof_map & table_dof_map(bool xrequire_write_access=false)
The map from table dof client_ids to table dof values for this poset (mutable version) ...
A handle for a poset whose members are numerical representations of sections of a fiber bundle...
Definition: sec_rep_space.h:61