SheafSystem  0.0.0.0
namespace_poset_schema.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/namespace_poset_schema.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/array_poset_dof_map.h"
25 #include "SheafSystem/namespace_poset.impl.h"
26 #include "SheafSystem/poset_handle_factory.h"
27 #include "SheafSystem/poset_type.h"
28 #include "SheafSystem/primitives_poset_dof_map.h"
29 #include "SheafSystem/std_iomanip.h"
30 #include "SheafSystem/std_iostream.h"
31 #include "SheafSystem/total_poset_member.h"
32 #include "SheafSystem/tern.h"
33 
34 // ===========================================================
35 // NAMESPACE_POSET_SCHEMA FACET
36 // ===========================================================
37 
38 // PUBLIC FUNCTIONS
39 
40 const std::string&
43 {
44  // Preconditions:
45 
46  // Body:
47 
48  static const std::string result("namespace_poset_schema");
49 
50  // Postconditions:
51 
52  ensure(result == "namespace_poset_schema");
53 
54  // Exit:
55 
56  return result;
57 }
58 
59 // PROTECTED FUNCTIONS
60 
61 // PRIVATE FUNCTIONS
62 
63 sheaf::namespace_poset_schema::
64 namespace_poset_schema()
65 {
66  // Preconditions:
67 
68  // Body:
69 
70  // Nothing to do; poset_state_handle constructor
71  // does what needs to be done
72 
73  // Postconditions:
74 
75  ensure(!is_attached());
76 
77  return;
78 }
79 
80 sheaf::namespace_poset_schema::
81 namespace_poset_schema(abstract_poset_member* xschema, bool xauto_access)
82 {
83  // Preconditions:
84 
85  require(precondition_of(new state(same args)));
86 
87  // Body:
88 
89  new_state(xschema, xauto_access);
90 
91  // Postconditions:
92 
93  ensure(postcondition_of(new_state(same args)));
94 
95  // Exit:
96 
97  return;
98 }
99 
100 sheaf::namespace_poset_schema::
101 ~namespace_poset_schema()
102 {
103 
104  // Preconditions:
105 
106  // Body:
107 
108  // Deleted by namespace_poset destructor; nothing to do.
109 
110  // Exit
111 
112  return;
113 }
114 
115 bool
116 sheaf::namespace_poset_schema::
117 make_prototype()
118 {
119  bool result = false;
120 
121  // Preconditions:
122 
123 
124  // Body:
125 
126  poset_type ltype = NAMESPACE_POSET_SCHEMA_ID;
127 
129 
130  factory().insert_prototype(lproto);
131  factory().insert_prototype(ltype, lproto);
132 
133  // Postconditions:
134 
135  // Exit:
136 
137  return result;
138 }
139 
140 
141 // ===========================================================
142 // POSET_STATE_HANDLE FACET
143 // ===========================================================
144 
145 // PUBLIC FUNCTIONS
146 
149 type_id() const
150 {
151  return NAMESPACE_POSET_SCHEMA_ID;
152 }
153 
154 const char*
156 class_name() const
157 {
158  // Preconditions:
159 
160  // Body:
161 
162  static const char* result = "namespace_poset_schema";
163 
164  // Postconditions:
165 
166  // Exit:
167 
168  return result;
169 }
170 
171 bool
173 row_dof_map_conforms(const poset_dof_map* xdof_map) const
174 {
175  bool result;
176 
177  // Preconditions:
178 
179  require(xdof_map != 0);
180 
181  // Body:
182 
183  // Row dofs must be primitives_poset_dof_map
184 
185  result = dynamic_cast<const primitives_poset_dof_map*>(xdof_map) != 0;
186 
187  // Postconditions:
188 
189  ensure(result ? (dynamic_cast<const primitives_poset_dof_map*>(xdof_map) != 0) : true);
190 
191  // Exit
192 
193  return result;
194 }
195 
196 // PROTECTED FUNCTIONS
197 
198 void
201 {
202  // Preconditions:
203 
204  // Body:
205 
206  // First create the standard members of the base class
207 
209 
210  // All jims will be members of "row_dofs" subposet;
211  // there are no table dofs
212 
213  // Must be created in order specified by enum namespace_member_index.
214 
215  // Enter edit mode
216 
218 
219  total_poset_member lmbr;
220  poset_dof_map* lmap;
221 
222  block<scoped_index> lio_dofs(7);
223 
224  // Create jim for pointer to member poset.
225 
226  lmap = new primitives_poset_dof_map(this, VOID_STAR);
227  lmbr.new_jim_state(this, lmap, false, false);
228  lmbr.put_name("pointer", true, false);
229  _row_dof_subposet->insert_member(&lmbr);
230  // Pointer is not included in i/o dofs.
231 
232  // Create jim for type id of member poset
233 
234  lmap = new primitives_poset_dof_map(this, INT);
235  lmbr.new_jim_state(this, lmap, false, false);
236  lmbr.put_name("type_id", true, false);
237  _row_dof_subposet->insert_member(&lmbr);
238  lio_dofs.push_back(lmbr.index());
239 
240  // Create jim for class of member poset
241 
242  lmap = new primitives_poset_dof_map(this, C_STRING);
243  lmbr.new_jim_state(this, lmap, false, false);
244  lmbr.put_name("class", true, false);
245  _row_dof_subposet->insert_member(&lmbr);
246  lio_dofs.push_back(lmbr.index());
247 
248  // Create jim for schema poset seq id.
249 
250  lmap = new primitives_poset_dof_map(this, INT);
251  lmbr.new_jim_state(this, lmap, false, false);
252  lmbr.put_name("prereq_id_0", true, false);
253  _row_dof_subposet->insert_member(&lmbr);
254  lio_dofs.push_back(lmbr.index());
255 
256  // Create jim for other prerequisite seq id 1.
257 
258  lmap = new primitives_poset_dof_map(this, INT);
259  lmbr.new_jim_state(this, lmap, false, false);
260  lmbr.put_name("prereq_id_1", true, false);
261  _row_dof_subposet->insert_member(&lmbr);
262  lio_dofs.push_back(lmbr.index());
263 
264  // Create jim for other prerequisite seq id 2.
265 
266  lmap = new primitives_poset_dof_map(this, INT);
267  lmbr.new_jim_state(this, lmap, false, false);
268  lmbr.put_name("prereq_id_2", true, false);
269  _row_dof_subposet->insert_member(&lmbr);
270  lio_dofs.push_back(lmbr.index());
271 
272  // Create jim for other prerequisite seq id 3.
273 
274  lmap = new primitives_poset_dof_map(this, INT);
275  lmbr.new_jim_state(this, lmap, false, false);
276  lmbr.put_name("prereq_id_3", true, false);
277  _row_dof_subposet->insert_member(&lmbr);
278  lio_dofs.push_back(lmbr.index());
279 
280  // Create jim for other prerequisite seq id 4.
281 
282  lmap = new primitives_poset_dof_map(this, INT);
283  lmbr.new_jim_state(this, lmap, false, false);
284  lmbr.put_name("prereq_id_4", true, false);
285  _row_dof_subposet->insert_member(&lmbr);
286  lio_dofs.push_back(lmbr.index());
287 
288  // Create jrm for dofs that get written to file.
289  //
290  // Manually construct lover cover to ensure order.
291  // Join constructor does not ensure any particular order
292  // to the lower cover of the join, but the layout of
293  // the namespace_poset dof tuple requires the jims
294  // of the schema appear in a particular order;
295  // see namespace_poset_dof_map.
296  //
305 
306  lmbr.new_jrm_state();
307  lmbr.put_name("io", true, false);
308 
309  // Manually construct lover cover to ensure order.
310 
311  for(int i=0; i<lio_dofs.ct(); ++i)
312  {
313  new_link(lmbr.index(), lio_dofs[i]);
314  }
315 
316  // Finished creating jims, exit edit mode
317 
319 
320  // Detach member so state won't be deleted.
321 
322  lmbr.detach_from_state();
323 
324  // Now there's 11 standard members,
325  // top, bottom, pointer, type_id, class, prereq_id_0,1,2,3,4 and io.
326 
327  // All the members and row dof tuples are standard.
328 
331 
332  // Postconditions:
333 
334  ensure(has_standard_member_ct());
336 
337  // Exit:
338 
339  return;
340 }
341 
342 void
344 initialize_standard_subposets(const std::string& xname)
345 {
346 
347  // Preconditions:
348 
349  require(poset_path::is_valid_name(xname));
351 
352  // Body:
353 
354  // Initialize the subposets common to all posets.
355 
357 
358  // Create empty table and row dof subposets;
359  // Standard names will be given in member function schematize.
360 
361  _table_dof_subposet = new subposet(this);
362  _row_dof_subposet = new subposet(this);
363 
365 
366  // Standard subposet count will be reset in new_state
367  // after schematizing, since that creates new subposets.
368 
369  // Postconditions:
370 
371  ensure(has_standard_subposet_ct());
372 
373  // Exit:
374 
375  return;
376 }
377 
378 // PRIVATE FUNCTIONS
379 
380 void
381 sheaf::namespace_poset_schema::
382 new_state(const abstract_poset_member* xschema, bool xauto_access)
383 {
384  // Preconditions:
385 
386  require(xschema != 0);
387  require(!xauto_access ? xschema->state_is_read_accessible() : true);
388  require(dynamic_cast<primitives_poset_schema*>(xschema->host()) != 0);
389 
390 
391  // If xauto_access == true we must get read access to the schema before
392  // testing host type.
393 
394  if(xauto_access)
395  xschema->get_read_access();
396 
397  require(dynamic_cast<primitives_poset_schema*>
398  (xschema->host()) != 0);
399 
400  // Body:
401 
402  // Disable invariant checking in
403  // member functions until construction finished
404 
406 
407  // Create the poset state object.
408  // This is a schema poset, so it must have the same
409  // schema as the primitives poset.
410  // Initial space for 4 members, 8 links, 4 subposets.
411 
412  _state = new poset_state(xschema, NAMESPACE_POSET_SCHEMA_ID, standard_name());
413 
414  // Get write access
415 
417 
418  // Initialize the table dof map.
419  // This class has no table dofs, but we want a non-null dof map anyway.
420 
422 
423  // Initialize additional row structure
424 
425  // Create subposets for jims and whole, and schema subposets for top.
426 
428 
429  // Create the bottom, top, and jims.
430 
432 
433  // Now that the standard members have all been inserted in the row dofs,
434  // we can initialize the other schema info derived from the dofs subposets
435 
436  schematize(_table_dof_subposet, _row_dof_subposet, true);
437 
438  // Schematize has created new subposets, reset the standard subposet count.
439  // Every subposet is a standard subposet.
440 
442 
443  // Set the standard id spaces.
444 
446 
447  // We won't use the two subposet handles again;
448  // detach and delete them
449 
450  _table_dof_subposet->detach_from_state();
451  delete _table_dof_subposet;
452  _table_dof_subposet = 0;
453 
454  _row_dof_subposet->detach_from_state();
455  delete _row_dof_subposet;
456  _row_dof_subposet = 0;
457 
458  // Now the invariant should be satisfied
459 
461 
462  // Postconditions:
463 
464  ensure(invariant());
465  ensure(!in_jim_edit_mode());
466  ensure(has_standard_member_ct());
468  ensure(has_standard_subposet_ct());
469 
470  // release thread access to poset state
471 
472  release_access();
473 
474  // release schema access if auto access was requested
475 
476  if(xauto_access)
477  xschema->release_access();
478 
480 }
481 
482 
483 // ===========================================================
484 // ANY FACET
485 // ===========================================================
486 
487 // PUBLIC FUNCTIONS
488 
489 bool
491 is_ancestor_of(const any* xother) const
492 {
493  bool result;
494 
495  // Preconditions:
496 
497  // Body:
498 
499  result = dynamic_cast<const namespace_poset_schema*>(xother) != 0;
500 
501  // Postconditions:
502 
503  // Exit
504 
505  return result;
506 }
507 
508 bool
510 invariant() const
511 {
512  bool result = true;
513 
514  // Preconditions:
515 
516  // Body:
517 
518  result = result && poset_state_handle::invariant();
519 
520  if(invariant_check())
521  {
523 
524  if(is_attached())
525  {
527  }
528 
530  }
531 
532  // Postconditions:
533 
534  // Exit
535 
536  return result;
537 }
538 
539 // PROTECTED FUNCTIONS
540 
541 // PRIVATE FUNCTIONS
542 
544 sheaf::namespace_poset_schema::
545 clone() const
546 {
547  namespace_poset_schema* result;
548 
549  // Preconditions:
550 
551  // Body:
552 
553  result = new namespace_poset_schema();
554 
555  // Postconditions:
556 
557  ensure(result != 0);
558 
559  // Exit
560 
561  return result;
562 }
563 
564 
virtual void initialize_standard_subposets(const std::string &xname)
Creates the subposets common to every poset (i.e._whole and _jims) plus those required of a schema po...
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...
bool invariant() const
Class invariant.
poset_state_handle * host() const
The poset which this is a handle to a component of.
The schema poset for the namespace.
A client handle for a subposet.
Definition: subposet.h:86
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
virtual void schematize(subposet *xtable_dof_subposet, subposet *xrow_dof_subposet, bool xall_members=false)
Prepare this poset and its top member for use as a schema. If xall_members = true, schematize all other members as well.
bool has_standard_member_ct() const
True if poset is in its initial state, that is, it contains just the standard members.
virtual void new_link(pod_index_type xgreater, pod_index_type xlesser)
Insert a cover link from greater to lesser (that is, hub id xgreater covers hub id xlesser)...
virtual int member_ct() const
The number of members of this poset.
size_type ct() const
The number of items currently in use.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
virtual void new_jim_state(poset_dof_map *xdof_map=0, bool xcopy_dof_map=false, bool xauto_access=true)
Creates a new jim (join-irreducible member) state in host() and attaches this to it. If xdof_map == 0 a new dof map is created. If xdof_map != 0 and xcopy_dof_map == false, xdof_map is used as the dof map. If xdof_map != 0 and xcopy_dof_map is true, a copy of xdof_map is used.
The private state of a partially ordered set.
Definition: poset_state.h:49
virtual const char * class_name() const
The name of this class.
virtual bool row_dof_map_conforms(const poset_dof_map *xdof_map) const
True if xdof_map conforms to (i.e. is derived from) the type of row dof map required by this poset...
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual size_type subposet_ct() const
The number of subposets of this poset.
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
virtual void initialize_standard_members()
Creates the members common to every poset, for instance, top() and bottom().
void initialize_table_dofs(void *xtable_dofs, size_t xtable_dof_ub)
Initializes the table dofs ("class variables")
virtual void initialize_standard_subposets(const std::string &xname)
Creates the subposets common to every poset (e.g. whole() and jims()).
void put_standard_row_dof_tuple_ct(int xct)
Sets the number of standard row dof tuples automatically allocated by the constructor.
virtual void get_read_access() const
Get read access to the state associated with this.
const scoped_index & index() const
The index of the component state this handle is attached to.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
void put_standard_subposet_ct(int xct)
Sets the number of standard subposets automatically allocated by the constructor. ...
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
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
virtual poset_type type_id() const
Identifier for the type of this poset.
bool has_standard_subposet_ct() const
True if poset is in its initial state, that is, it contains just the standard subposets.
void update_standard_member_id_spaces()
Update the initially allocated id spaces.
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
bool has_standard_row_dof_tuple_ct() const
True if poset is in its initial state, that is, it contains just the standard row_dof_tuples.
A map from schema poset member ids to dof values for primitives_poset members.
virtual void insert_member(pod_index_type xmbr_hub_id)
Inserts the member of host() with hub id xmbr_hub_id.
Definition: subposet.cc:1091
size_type row_dof_tuple_ct() const
The number of row_dof_tuples of this poset.
virtual void put_name(const std::string &xname, bool xunique, bool xauto_access)
Make xname a name for this; if xunique, make xname the only name.
void put_standard_member_ct(int xct)
Sets the number of standard members automatically allocated by the constructor.
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
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 poset_handle_factory & factory()
The poset handle factory.
virtual void detach_from_state()
Detach this handle from its state, if any.
virtual bool is_attached() const
True if this is attached to a state.
poset_state * _state
State object for this poset.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual void initialize_standard_members()
Initializes the predefined members of the poset.
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
Prevent editing of jims and jim order relation.
static bool is_valid_name(const std::string &xname)
True if xname is not empty and contains only name legal characters.
Definition: poset_path.cc:331
An abstract client handle for a member of a poset.
bool in_jim_edit_mode() const
True if editing jims and jim order relation is allowed.
static const std::string & standard_name()
The standard name for an instance of this class.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
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...
virtual bool invariant() const
Class invariant.
virtual void new_jrm_state(bool xauto_access=true)
Creates a new jrm (join-reducible member) state in host() and attaches this to it.
A client handle for an unrestricted member of a poset. A total_poset_member is guaranteed not to be r...