SheafSystem  0.0.0.0
sec_rep_descriptor_poset.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_rep_descriptor_poset.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/base_space_poset.h"
25 #include "SheafSystem/array_poset_dof_map.h"
26 #include "SheafSystem/fiber_bundles_namespace.h"
27 #include "SheafSystem/namespace_poset.impl.h"
28 #include "SheafSystem/poset_handle_factory.h"
29 #include "SheafSystem/sec_rep_descriptor.h"
30 #include "SheafSystem/wsv_block.h"
31 
32 using namespace std;
33 using namespace fiber_bundle; // Workaround for MS C++ bug.
34 
35 // ===========================================================
36 // SEC_REP_DESCRIPTOR_POSET FACET
37 // ===========================================================
38 
39 // PUBLIC MEMBER FUNCTIONS
40 
41 const sheaf::poset_path&
44 {
45  // Preconditions:
46 
47  // Body:
48 
49  const poset_path& result = sec_rep_descriptor::standard_schema_path();
50 
51  // Postconditions:
52 
53  ensure(result.full());
54 
55  // Exit:
56 
57  return result;
58 }
59 
60 
64  const poset_path& xpath,
65  const poset_path& xschema_path,
66  const poset_path& xprototypes_path,
67  bool xauto_access)
68 {
69  // cout << endl << "Entering sec_rep_descriptor_poset::new_table." << endl;
70 
71  // Preconditions:
72 
73  require(xns.state_is_auto_read_write_accessible(xauto_access));
74 
75  require(!xpath.empty());
76  require(!xns.contains_path(xpath, xauto_access));
77 
78  require(xschema_path.full());
79  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
80  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
81 
82  require(!xprototypes_path.empty());
83  require(xns.path_is_auto_read_accessible(xprototypes_path, xauto_access));
84 
85  // Body:
86 
87  // Create the table; have to new it because namespace keeps a pointer.
88 
89  typedef sec_rep_descriptor_poset table_type;
90 
91  table_type* ltable = new table_type();
92 
93  // Create a handle of the right type for the schema member.
94 
95  schema_poset_member lschema(&xns, xschema_path, xauto_access);
96 
97  if(xauto_access)
98  {
99  lschema.get_read_access();
100  }
101 
102  // Create the table dof map and set dof values;
103  // must be newed because poset_state::_table keep a pointer to it.
104 
105  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
106  lmap->put_dof("prototypes_path", xprototypes_path);
107 
108  // Create the state.
109 
110  ltable->new_state(xns, xpath, lschema, *lmap);
111 
112  if(xauto_access)
113  {
114  lschema.release_access();
115  }
116 
117  sec_rep_descriptor_poset& result = *ltable;
118 
119  // Postconditions:
120 
121  ensure(xns.owns(result, xauto_access));
122  ensure(result.path(true) == xpath);
123  ensure(result.state_is_not_read_accessible());
124  ensure(result.schema(true).path(xauto_access) == xschema_path);
125 
126  ensure(result.prototypes().path(xauto_access) == xprototypes_path);
127 
128  // Exit:
129 
130  // cout << "Leaving sec_rep_descriptor_poset::new_table." << endl;
131  return result;
132 }
133 
136 prototypes() const
137 {
138  // Preconditions:
139 
140  // Body:
141 
142  const base_space_poset& result = *_prototypes;
143 
144  // Postconditions:
145 
146  // Exit:
147 
148  return result;
149 }
150 
154 {
155  // Preconditions:
156 
157  // Body:
158 
159  base_space_poset& result = *_prototypes;
160 
161  // Postconditions:
162 
163  // Exit:
164 
165  return result;
166 }
167 
168 // PROTECTED MEMBER FUNCTIONS
169 
172 {
173  // Preconditions:
174 
175  // Body:
176 
177  _prototypes = 0;
178 
179  // Postconditions:
180 
181  ensure(!is_attached());
182 
183  // Exit:
184 
185  return;
186 }
187 
190 {
191 
192  // Preconditions:
193 
194  // Body:
195 
196  // Postconditions:
197 
198  // Exit
199 
200  return;
201 }
202 
203 bool
206 {
207  // Preconditions:
208 
209  // Body:
210 
211  poset_type ltype = SEC_REP_DESCRIPTOR_POSET_ID;
212 
213  sec_rep_descriptor_poset* lproto =
215 
216  factory().insert_prototype(lproto);
217  factory().insert_prototype(ltype, lproto);
218 
219  // Postconditions:
220 
221  // Exit:
222 
223  return true;
224 }
225 
226 // PRIVATE MEMBER FUNCTIONS
227 
228 
229 // ===========================================================
230 // POSET FACET
231 // ===========================================================
232 
233 // PUBLIC MEMBER FUNCTIONS
234 
235 // PROTECTED MEMBER FUNCTIONS
236 
237 // PRIVATE MEMBER FUNCTIONS
238 
239 
240 // ===========================================================
241 // STATE FACET
242 // ===========================================================
243 
244 // PUBLIC MEMBER FUNCTIONS
245 
248 type_id() const
249 {
250  return SEC_REP_DESCRIPTOR_POSET_ID;
251 }
252 
253 const char*
255 class_name() const
256 {
257  // Preconditions:
258 
259  // Body:
260 
261  static const char* result = "sec_rep_descriptor_poset";
262 
263  // Postconditions:
264 
265  // Exit:
266 
267  return result;
268 }
269 
270 void
273 {
274  // Preconditions:
275 
276  require(is_attached());
277 
278  // Body:
279 
280  define_old_variable(int old_access_request_depth = access_request_depth());
281 
282  _prototypes->get_read_access();
283 
284  poset::get_read_access();
285 
286  // Postconditions:
287 
288  ensure(state_is_read_accessible());
289  ensure(access_request_depth() == old_access_request_depth + 1);
290  ensure(prototypes().state_is_read_accessible());
291 
292  // Exit
293 
294  return;
295 }
296 
297 void
299 get_read_write_access(bool xrelease_read_only_access)
300 {
301  // Preconditions:
302 
303  require(is_attached());
304  require(!xrelease_read_only_access ? state_is_not_read_only_accessible() : true);
305 
306 
307  // Body:
308 
309  define_old_variable(int old_access_request_depth = access_request_depth());
310 
311  _prototypes->get_read_access();
312 
313  poset::get_read_write_access(xrelease_read_only_access);
314 
315  // Postconditions:
316 
317  ensure(state_is_read_write_accessible());
318  ensure(access_request_depth() == old_access_request_depth + 1);
319  ensure(prototypes().state_is_read_accessible());
320 
321  // Exit
322 
323  return;
324 }
325 
326 void
328 release_access(bool xall) const
329 {
330  // Preconditions:
331 
332  require(state_is_read_accessible());
333 
334  // Body:
335 
336  define_old_variable(int old_access_request_depth = access_request_depth());
337 
338  // Release at least one level of access for this. If xall, release all levels
339  // of access for this. Since each level of access to this also
340  // acquired a level of access to the rep, the base space, and the fiber space,
341  // release the same number of levels of access to each of these.
342  // Note that this may not be all the levels of access of these.
343 
344  do
345  {
346  // Release one level of access.
347 
348  _prototypes->release_access(false);
349 
350  poset::release_access(false);
351  }
352  while(xall && state_is_read_accessible());
353 
354 
355  // Postconditions:
356 
357  ensure(!xall ? access_request_depth() == old_access_request_depth - 1 :
358  access_request_depth() == 0);
359  ensure(access_request_depth() == 0 ? state_is_not_read_accessible() : true);
360  ensure(unexecutable("schema, and prototypes access released"));
361 
362  // Exit
363 
364  return;
365 }
366 
367 // PROTECTED MEMBER FUNCTIONS
368 
369 void
372 {
373  // Preconditions:
374 
375  require(state_is_read_accessible());
376  require(xns.state_is_read_accessible());
377 
378  // Body:
379 
380  // Attach the handle data members that depend on the table dofs
381  // and are required to get access.
382 
383  table_dofs_type& ldofs = sheaf::table_dofs(*this);
384 
385  poset_path lprototypes_path(ldofs.prototypes_path);
386  _prototypes = &xns.member_poset<base_space_poset>(lprototypes_path, false);
387 
388  // Postconditions:
389 
390  ensure(prototypes().is_attached());
391 
392  // Postconditions:
393 
394 
395  // Exit
396 
397  return;
398 }
399 
400 void
403 {
404  // Preconditions:
405 
406  require(state_is_read_accessible());
407  require(name_space()->state_is_read_accessible());
408 
409  // Body:
410 
411  poset::attach_handle_data_members();
412 
413  // Attach the base space members prototypes poset to the current state.
414 
415  table_dofs_type& ldofs = sheaf::table_dofs(*this);
416  namespace_poset* lns = name_space();
417 
418  poset_path lprototypes_path(ldofs.prototypes_path);
419  _prototypes = &lns->member_poset<base_space_poset>(lprototypes_path, false);
420 
421  // Postconditions:
422 
423  ensure(prototypes().is_attached());
424 
425  // Exit
426 
427  return;
428 }
429 
430 void
433 {
434  // Preconditions:
435 
436  require(state_is_read_write_accessible());
437 
438  // Body:
439 
440  define_old_variable(int old_prototypes_access_request_depth = prototypes().access_request_depth());
441 
442  // Release all levels of access this poset has to its various parts,
443  // but do not release access to the state of this because
444  // we are going to delete the state and don't want another
445  // client able to sneak in and get access before we do.
446 
450 
451  string prototypes_name(prototypes().name());
452 
453 #ifdef DIAGNOSTIC_OUTPUT
454  cout << "poset: " << name() << endl
455  << "\trep: " << prototypes_name
456  << " old lvl:" << old_prototypes_access_request_depth << endl
457 #endif
458 
459  int old_access_request_depth = access_request_depth();
460  for(size_type i=0; i<old_access_request_depth; ++i)
461  {
462  prototypes().release_access(false);
463  }
464 
465  define_old_variable(int prototypes_access_request_depth = prototypes().access_request_depth());
466 
467 #ifdef DIAGNOSTIC_OUTPUT
468  cout << " \tprototypes lvl:" << prototypes_access_request_depth << endl;
469 #endif
470 
471  // Detach and delete the state.
472 
473  poset::terminate_access();
474 
475  // Postconditions:
476 
477  ensure(!is_attached());
478  ensure(unexecutable("state has been deleted"));
479  ensure(prototypes_access_request_depth ==
480  (old_prototypes_access_request_depth - old_access_request_depth));
481 
482  // Exit
483 
484  return;
485 }
486 
487 // PRIVATE MEMBER FUNCTIONS
488 
489 
490 // ===========================================================
491 // I/O SUPPORT FACET
492 // ===========================================================
493 
494 // PUBLIC MEMBER FUNCTIONS
495 
498 prereq_id(int xi) const
499 {
500  pod_index_type result;
501 
502  // Preconditions:
503 
504  // Body:
505 
506  switch(xi)
507  {
508  case 0: // schema
509  result = schema().host()->index().pod();
510  break;
511  case 1: // base space prototypes
512  result = _prototypes->index().pod();
513  break;
514  default:
515  result = invalid_pod_index();
516  break;
517  }
518 
519  // Postconditions:
520 
521  // Exit:
522 
523  return result;
524 }
525 
526 // PROTECTED MEMBER FUNCTIONS
527 
528 // PRIVATE MEMBER FUNCTIONS
529 
530 
531 // ===========================================================
532 // ANY FACET
533 // ===========================================================
534 
535 // PUBLIC MEMBER FUNCTIONS
536 
537 bool
539 is_ancestor_of(const any *other) const
540 {
541 
542  // Preconditions:
543 
544  require(other != 0);
545 
546  // Body:
547 
548  // True if other conforms to this
549 
550  bool result = dynamic_cast<const sec_rep_descriptor_poset*>(other) != 0;
551 
552  // Postconditions:
553 
554  return result;
555 }
556 
559 clone() const
560 {
561  sec_rep_descriptor_poset* result;
562 
563  // Preconditions:
564 
565  // Body:
566 
567  result = new sec_rep_descriptor_poset();
568 
569  // Postconditions:
570 
571  ensure(result != 0);
572  ensure(is_same_type(result));
573 
574  // Exit:
575 
576  return result;
577 }
578 
579 bool
581 invariant() const
582 {
583  bool result = true;
584 
585  if(invariant_check())
586  {
587  // Prevent recursive calls to invariant
588 
589  disable_invariant_check();
590 
591  // Must satisfy base class invariant
592 
593  invariance(poset::invariant());
594 
595  // Invariances for this class:
596 
597  // Finished, turn invariant checking back on.
598 
599  enable_invariant_check();
600  }
601 
602  // Exit
603 
604  return result;
605 }
606 
607 // PROTECTED MEMBER FUNCTIONS
608 
609 // PRIVATE MEMBER FUNCTIONS
610 
611 
612 // ===========================================================
613 // NON-MEMBER FUNCTIONS
614 // ===========================================================
615 
616 
sec_rep_descriptor_poset()
Creates an unattached handle.
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 ...
Table dofs type for class sec_rep_descriptor_poset.
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
poset_path path(bool xauto_access=true) const
A path to this component.
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
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.
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
virtual void terminate_access()
Release all access to posets this depends on, then detach and delete the state.
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 void initialize_handle_data_members(const namespace_poset &xns)
Initializes the handle data members that depend on the table dofs and are required to get access when...
STL namespace.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
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.
virtual sec_rep_descriptor_poset * clone() const
Virtual constructor, makes a new instance of the same type as this.
The poset for sec_rep_descriptors.
virtual bool invariant() const
Class invariant.
virtual poset_type type_id() const
Identifier for the type of this poset.
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
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
const base_space_poset & prototypes() const
The base space members prototypes poset.
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
Definition: eval_family.h:49
virtual const char * class_name() const
The name of this class.
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)
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
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 sec_rep_descriptor_poset & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, const poset_path &xprototypes_path, bool xauto_access)
Creates a new sec_rep_descriptor_poset in namespace xns with path xpath, schema specified by xschema_...
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
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...
static bool make_prototype()
Creates prototype for this class and enters in in factory.
virtual void get_read_write_access(bool xrelease_read_only_access=false)
Get read write access to the state associated with this. If release_read_only_access is requested...
virtual void get_read_access() const
Get read access to the state associated with this.
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.
T::table_dofs_type & table_dofs(T &x0)
The table dofs pod type for x0 (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
void insert_prototype(T *xprototype)
Sets xprototype as the prototype for its client class.
Definition: factory.impl.h:144
An array representation of abstract class poset_dof_map.
virtual void attach_handle_data_members()
Initializes the handle data members when this handle is attached to a state.
Namespace for the fiber_bundles component of the sheaf system.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
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.