SheafSystem  0.0.0.0
tuple_space.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 // Implementation for class tuple_space.
19 
20 #include "SheafSystem/tuple_space.h"
21 
22 #include "SheafSystem/abstract_poset_member.impl.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/fiber_bundles_namespace.h"
25 #include "SheafSystem/namespace_poset.impl.h"
26 #include "SheafSystem/namespace_poset_member.h"
27 #include "SheafSystem/poset_handle_factory.h"
28 #include "SheafSystem/tuple.h"
29 
30 using namespace std;
31 using namespace fiber_bundle; // Workaround for MS C++ bug.
32 
33 //#define DIAGNOSTIC_OUTPUT
34 
35 //==============================================================================
36 // TUPLE_SPACE FACET
37 //==============================================================================
38 
40 const std::string&
43 {
44  // Preconditions:
45 
46 
47  // Body:
48 
49  static const string& result = tuple::standard_schema_poset_name();
50 
51  // Postconditions:
52 
53  ensure(!result.empty());
54 
55  // Exit:
56 
57  return result;
58 }
59 
61 const sheaf::poset_path&
64 {
65  // Preconditions:
66 
67 
68  // Body:
69 
70  static const poset_path& result = tuple::standard_schema_path();
71 
72  // Postconditions:
73 
74  ensure(result.full());
75  ensure(result.poset_name() == standard_schema_poset_name());
76 
77  // Exit:
78 
79  return result;
80 }
81 
84 new_table(namespace_type& xns, const poset_path& xpath, const poset_path& xschema_path, int xfactor_ct, bool xauto_access)
85 {
86  // cout << endl << "Entering tuple_space::new_table." << endl;
87 
88  // Preconditions:
89 
90  require(xns.state_is_auto_read_write_accessible(xauto_access));
91 
92  require(!xpath.empty());
93  require(!xns.contains_path(xpath, xauto_access));
94 
95  require(xschema_path.full());
96  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
97  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
98 
99  require(xfactor_ct > 0);
100 
101  // Body:
102 
103  // Create the table; have to new it because namespace keeps a pointer.
104 
105  typedef tuple_space table_type;
106 
107  table_type* ltable = new table_type();
108 
109  // Create a handle of the right type for the schema member.
110 
111  schema_poset_member lschema(&xns, xschema_path, xauto_access);
112 
113  if(xauto_access)
114  {
115  lschema.get_read_access();
116  }
117 
118  // Create the table dof map and set dof values;
119  // must be newed because poset_state::_table keep a pointer to it.
120 
121  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
122  lmap->put_dof("factor_ct", xfactor_ct);
123 
124  // Create the state.
125 
126  ltable->new_state(xns, xpath, lschema, *lmap);
127 
128  if(xauto_access)
129  {
130  lschema.release_access();
131  }
132 
133  tuple_space& result = *ltable;
134 
135  // Postconditions:
136 
137  ensure(xns.owns(result, xauto_access));
138  ensure(result.path(true) == xpath);
139  ensure(result.state_is_not_read_accessible());
140  ensure(result.schema(true).path(xauto_access) == xschema_path);
141 
142  ensure(result.factor_ct(true) == xfactor_ct);
143 
144  // Exit:
145 
146  // cout << "Leaving tuple_space::new_table." << endl;
147  return result;
148 }
149 
150 int
152 factor_ct() const
153 {
154  // Preconditions:
155 
156  require(state_is_read_accessible());
157 
158  // Body:
159 
160  int result = sheaf::table_dofs(*this).factor_ct;
161 
162 
163  // Postconditions:
164 
165 
166  // Exit:
167 
168  return result;
169 }
170 
171 int
173 factor_ct(bool xauto_access) const
174 {
175  // Preconditions:
176 
177  require(state_is_auto_read_accessible(xauto_access));
178 
179  // Body:
180 
181  if(xauto_access)
182  {
183  get_read_access();
184  }
185 
186  int result = factor_ct();
187 
188  if(xauto_access)
189  {
190  release_access();
191  }
192 
193  // Postconditions:
194 
195 
196  // Exit:
197 
198  return result;
199 }
200 
203  : poset(new tuple, new tuple)
204 {
205  // Preconditions:
206 
207  // Body:
208 
209  // Nothing to do, handled by base class
210 
211  // Postconditions:
212 
213  ensure(postcondition_of(poset::poset()));
214 }
215 
218 {
219  // Preconditions:
220 
221  // Body:
222 
223  // Postconditions:
224 
225  // Exit
226 
227  return;
228 }
229 
231 tuple_space(tuple* xtop, tuple* xbottom)
232  : poset(xtop, xbottom)
233 {
234  // Preconditions:
235 
236  require(xtop != 0);
237  require(xbottom != 0);
238 
239  // Body:
240 
241  // Nothing to do.
242 
243  // Postconditions:
244 
245  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
246 
247  // Exit:
248 
249  return;
250 }
251 
252 // ===========================================================
253 // POSET FACET
254 // ===========================================================
255 
256 bool
257 fiber_bundle::tuple_space::
258 make_prototype()
259 {
260  bool result = false;
261 
262  // Preconditions:
263 
264  // Body:
265 
266 
267  tuple_space* lproto = new tuple_space;
268  poset_type ltype = lproto->type_id();
269 
270  factory().insert_prototype(lproto);
271  factory().insert_prototype(ltype, lproto);
272 
273  // Postconditions:
274 
275  // Exit:
276 
277  return result;
278 }
279 
280 //==============================================================================
281 // POSET_STATE_HANDLE FACET
282 //==============================================================================
283 
284 
285 
288 type_id() const
289 {
290  return TUPLE_SPACE_ID;
291 }
292 
293 
294 
295 
296 
299 
300 const char*
302 class_name() const
303 {
304  // Preconditions:
305 
306 
307  // Body:
308 
309  static const char* result = "tuple_space";
310 
311  // Postconditions:
312 
313  // Exit:
314 
315  return result;
316 }
317 
318 
319 //==============================================================================
320 // ANY FACET
321 //==============================================================================
322 
323 bool
325 is_ancestor_of(const any* xother) const
326 {
327  bool result;
328 
329  // Preconditions:
330 
331  // Body:
332 
333  result = dynamic_cast<const tuple_space*>(xother) != 0;
334 
335  // Postconditions:
336 
337  // Exit
338 
339  return result;
340 }
341 
344 clone() const
345 {
346  tuple_space* result;
347 
348  // Preconditions:
349 
350  // Body:
351 
352  result = new tuple_space;
353 
354  // Postconditions:
355 
356  ensure(result != 0);
357  ensure(is_same_type(result));
358  ensure(!result->is_attached());
359 
360  // Exit
361 
362  return result;
363 }
364 
365 bool
367 invariant() const
368 {
369  bool result = true;
370 
371 
372  if(invariant_check())
373  {
375 
376  invariance(poset::invariant());
377 
380 
382  }
383 
384  return result;
385 }
386 
387 
388 
virtual poset_path path(bool xauto_access=true) const
The path of this poset.
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.
virtual tuple_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: tuple_space.cc:344
virtual bool invariant() const
Class invariant.
Definition: poset.cc:440
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
virtual const char * class_name() const
The name of this class.
Definition: tuple_space.cc:302
poset_path path(bool xauto_access=true) const
A path to this component.
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
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: tuple_space.cc:63
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
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
Definition: tuple_space.cc:325
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: tuple_space.cc:42
STL namespace.
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()
Default constructor; creates a new poset handle not attached to any state.
Definition: poset.cc:107
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
virtual ~tuple_space()
Destructor.
Definition: tuple_space.cc:217
tuple_space()
Default constructor; creates a new tuple_space handle not attached to any state.
Definition: tuple_space.cc:202
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
A client handle for a mutable partially ordered set.
Definition: poset.h:40
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)
virtual poset_type type_id() const
Identifier for the type of this poset.
Definition: tuple_space.cc:288
std::string poset_name() const
The poset name part of the path.
Definition: poset_path.cc:473
static tuple_space & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, int xfactor_ct, bool xauto_access)
Creates a new tuple_space in namespace xns with path xpath, schema specified by xschema_path, and table attribute factor_ct specified by xfactor_ct.
Definition: tuple_space.cc:84
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
A member of a Cartesian product space; a tuple of attributes (persistent version).
Definition: tuple.h:191
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.
virtual void put_dof(pod_index_type xdof_id, const void *xdof, size_type xdof_size)
Sets the dof referred to by xdof_id to the value at xdof.
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).
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
virtual bool invariant() const
Class invariant.
Definition: tuple_space.cc:367
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
int factor_ct() const
The number of factors in this product.
Definition: tuple_space.cc:152
bool state_is_not_read_accessible() const
True if this is attached and if the state is accessible for read or if access control is disabled...
A client handle for a poset member which has been prepared for use as a schema.