SheafSystem  0.0.0.0
primitives_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/primitives_poset.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/primitive_attributes.h"
28 #include "SheafSystem/primitives_poset_dof_map.h"
29 #include "SheafSystem/primitives_poset_schema.h"
30 #include "SheafSystem/poset_type.h"
31 #include "SheafSystem/primitive_type.h"
32 #include "SheafSystem/std_iomanip.h"
33 #include "SheafSystem/total_poset_member.h"
34 
35 using namespace std;
36 
37 // ===========================================================
38 // PRIMITIVES_POSET FACET
39 // ===========================================================
40 
41 // PUBLIC FUNCTIONS
42 
43 const std::string&
46 {
47  // Preconditions:
48 
49 
50  // Body:
51 
52  static const string result("primitives");
53 
54  // Postconditions:
55 
56  ensure(result == "primitives");
57 
58  // Exit:
59 
60  return result;
61 }
62 
63 bool
66 {
67  bool result = true;
68 
69  // Preconditions:
70 
71  // Body:
72 
73  result = result && bool_type().is_attached();
74  result = result && (bool_type().index() == BOOL);
75 
76  result = result && char_type().is_attached() ;
77  result = result && (char_type().index() == CHAR);
78 
79  result = result && signed_char_type().is_attached();
80  result = result && (signed_char_type().index() == SIGNED_CHAR);
81 
82  result = result && short_int_type().is_attached();
83  result = result && (short_int_type().index() == SHORT_INT);
84 
85  result = result && int_type().is_attached();
86  result = result && (int_type().index() == INT);
87 
88  result = result && long_int_type().is_attached();
89  result = result && (long_int_type().index() == LONG_INT);
90 
91  result = result && long_long_int_type().is_attached();
92  result = result && (long_long_int_type().index() == LONG_LONG_INT);
93 
94  result = result && unsigned_char_type().is_attached();
95  result = result && (unsigned_char_type().index() == UNSIGNED_CHAR);
96 
97  result = result && unsigned_short_int_type().is_attached();
98  result = result && (unsigned_short_int_type().index() == UNSIGNED_SHORT_INT);
99 
100  result = result && unsigned_int_type().is_attached();
101  result = result && (unsigned_int_type().index() == UNSIGNED_INT);
102 
103  result = result && unsigned_long_int_type().is_attached();
104  result = result && (unsigned_long_int_type().index() == UNSIGNED_LONG_INT);
105 
106  result = result && unsigned_long_long_int_type().is_attached();
107  result = result && (unsigned_long_long_int_type().index() == UNSIGNED_LONG_LONG_INT);
108 
109  result = result && float_type().is_attached();
110  result = result && (float_type().index() == FLOAT);
111 
112  result = result && double_type().is_attached();
113  result = result && (double_type().index() == DOUBLE);
114 
115  result = result && long_double_type().is_attached();
116  result = result && (long_double_type().index() == LONG_DOUBLE);
117 
118  result = result && void_star_type().is_attached();
119  result = result && (void_star_type().index() == VOID_STAR);
120 
121  result = result && c_string_type().is_attached();
122  result = result && (c_string_type().index() == C_STRING);
123 
124  result = result && namespace_relative_member_index_type().is_attached();
125  result = result && (namespace_relative_member_index_type().index() == NAMESPACE_RELATIVE_MEMBER_INDEX);
126 
127  result = result && namespace_relative_subposet_index_type().is_attached();
128  result = result && (namespace_relative_subposet_index_type().index() == NAMESPACE_RELATIVE_SUBPOSET_INDEX);
129 
130  // Postconditions:
131 
132  // Exit
133 
134  return result;
135 }
136 
137 // PROTECTED FUNCTIONS
138 
139 // PRIVATE FUNCTIONS
140 
141 sheaf::primitives_poset::
142 primitives_poset()
143 {
144  // Preconditions:
145 
146  // Body:
147 
148  // Nothing to do; poset_state_handle constructor
149  // does what needs to be done
150 
151  // Postconditions:
152 
153  ensure(!is_attached());
154 
155  return;
156 }
157 
158 sheaf::primitives_poset::
159 ~primitives_poset()
160 {
161 
162  // Preconditions:
163 
164  // Body:
165 
166  // Deleted by namespace destructor; nothing to do.
167 
168  // Postconditions:
169 
170  // Exit
171 
172  return;
173 }
174 
175 void
176 sheaf::primitives_poset::
177 initialize_primitive_member(total_poset_member& xmbr, primitive_type xtype)
178 {
179  // Preconditions:
180 
181  require(!xmbr.is_attached());
182 
183  // Body:
184 
186  new primitives_poset_dof_map(this, xtype);
187 
188  xmbr.new_jim_state(this, lmap, false, false);
189 
190  string lname = primitive_attributes::name(xtype);
191  xmbr.put_name(lname, true, false);
192 
193  _row_dof_subposet->insert_member(&xmbr);
194 
195  // Postconditions:
196 
197  ensure(xmbr.is_attached());
198  ensure(xmbr.index() == xtype);
199  ensure(xmbr.name() == primitive_attributes::name(xtype));
200 
201  // Exit:
202 
203  return;
204 }
205 
206 bool
207 sheaf::primitives_poset::
208 make_prototype()
209 {
210  // Preconditions:
211 
212 
213  // Body:
214 
215  poset_type ltype = PRIMITIVES_POSET_ID;
216 
217  primitives_poset* lproto = new primitives_poset;
218 
219  factory().insert_prototype(lproto);
220  factory().insert_prototype(ltype, lproto);
221 
222  // Postconditions:
223 
224 
225  // Exit:
226 
227  return true;
228 }
229 
230 
231 // ===========================================================
232 // POSET_STATE_HANDLE FACET
233 // ===========================================================
234 
235 // PUBLIC FUNCTIONS
236 
239 type_id() const
240 {
241  return PRIMITIVES_POSET_ID;
242 }
243 
244 const char*
246 class_name() const
247 {
248  // Preconditions:
249 
250  // Body:
251 
252  static const char* result = "primitives_poset";
253 
254  // Postconditions:
255 
256  // Exit:
257 
258  return result;
259 }
260 
261 bool
263 row_dof_map_conforms(const poset_dof_map* xdof_map) const
264 {
265  bool result;
266 
267  // Preconditions:
268 
269  require(xdof_map != 0);
270 
271  // Body:
272 
273  // Row dofs must be primitives_poset_dof_map
274 
275  result = (dynamic_cast<const primitives_poset_dof_map*>(xdof_map) != 0);
276 
277  // Postconditions:
278 
279  ensure(result ? (dynamic_cast<const primitives_poset_dof_map*>(xdof_map) != 0) : true);
280 
281  // Exit
282 
283  return result;
284 }
285 
286 // PROTECTED FUNCTIONS
287 
288 // PRIVATE FUNCTIONS
289 
290 void
291 sheaf::primitives_poset::
292 attach_to_state(const namespace_poset* xhost, pod_index_type xindex)
293 {
294  // Preconditions:
295 
296  require(xhost != 0);
297  require(xhost->state_is_read_accessible());
298  require(xhost->contains_member(xindex, false));
299 
300  // Body:
301 
302 
303  disable_invariant_check();
304 
305  poset_state_handle::attach_to_state(xhost, xindex);
306 
307  define_old_variable(int old_access_request_depth = access_request_depth());
308 
309  // Get read access
310 
311  get_read_access();
312 
313  // Attach primitives
314 
315  bool_type().attach_to_state(this, BOOL);
316  char_type().attach_to_state(this, CHAR);
317 
318  signed_char_type().attach_to_state(this, SIGNED_CHAR);
319  short_int_type().attach_to_state(this, SHORT_INT);
320  int_type().attach_to_state(this, INT);
321  long_int_type().attach_to_state(this, LONG_INT);
322  long_long_int_type().attach_to_state(this, LONG_LONG_INT);
323 
324  unsigned_char_type().attach_to_state(this, UNSIGNED_CHAR);
325  unsigned_short_int_type().attach_to_state(this, UNSIGNED_SHORT_INT);
326  unsigned_int_type().attach_to_state(this, UNSIGNED_INT);
327  unsigned_long_int_type().attach_to_state(this, UNSIGNED_LONG_INT);
328  unsigned_long_long_int_type().attach_to_state(this, UNSIGNED_LONG_LONG_INT);
329 
330  float_type().attach_to_state(this, FLOAT);
331  double_type().attach_to_state(this, DOUBLE);
332  long_double_type().attach_to_state(this, LONG_DOUBLE);
333 
334  void_star_type().attach_to_state(this, VOID_STAR);
335  c_string_type().attach_to_state(this, C_STRING);
336 
337  namespace_relative_member_index_type().
338  attach_to_state(this, NAMESPACE_RELATIVE_MEMBER_INDEX);
339 
340  namespace_relative_subposet_index_type().
341  attach_to_state(this, NAMESPACE_RELATIVE_SUBPOSET_INDEX);
342 
343  enable_invariant_check();
344 
345  // Postconditions:
346 
347  ensure(poset_state_handle::invariant());
348  ensure(is_attached());
349  ensure(primitive_members_attached());
350  ensure(host() == xhost);
351  ensure(index() == xindex);
352 
353  // release access to poset state
354 
355  release_access();
356 
357  ensure(access_request_depth() == old_access_request_depth);
358 
359  return;
360 }
361 
362 void
363 sheaf::primitives_poset::
364 detach_from_state()
365 {
366 
367  // Preconditions:
368 
369  // Body:
370 
371  // Detach the primitives
372 
373  bool_type().detach_from_state();
374  char_type().detach_from_state();
375 
376  signed_char_type().detach_from_state();
377  short_int_type().detach_from_state();
378  int_type().detach_from_state();
379  long_int_type().detach_from_state();
380  long_long_int_type().detach_from_state();
381 
382  unsigned_char_type().detach_from_state();
383  unsigned_short_int_type().detach_from_state();
384  unsigned_int_type().detach_from_state();
385  unsigned_long_int_type().detach_from_state();
386  unsigned_long_long_int_type().detach_from_state();
387 
388  float_type().detach_from_state();
389  double_type().detach_from_state();
390  long_double_type().detach_from_state();
391 
392  void_star_type().detach_from_state();;
393  c_string_type().detach_from_state();;
394 
395  namespace_relative_member_index_type().detach_from_state();
396  namespace_relative_subposet_index_type().detach_from_state();
397 
398  // Detach from the standard subposets, members, and state
399 
400  poset_state_handle::detach_from_state();
401 
402  // Postconditions:
403 
404  ensure(!is_attached());
405  ensure(!primitive_members_attached());
406 
407  // Exit
408 
409  return;
410 }
411 
412 void
413 sheaf::primitives_poset::
414 new_state(const abstract_poset_member* xschema)
415 {
416  // Preconditions:
417 
418  require(xschema != 0);
419  require(unexecutable("schema is primitives schema"));
420 
421  // Body:
422 
423  // Disable invariant checking in
424  // member functions until construction finished
425 
426  disable_invariant_check();
427 
428  // Create the poset state object; without a schema because we don't have one yet.
429  // Initial space for 16 members, 32 links, 4 subposets.
430 
431  // _state = new poset_state(xschema, PRIMITIVES_POSET_ID, 16, 32, 4);
432  _state = new poset_state(xschema, PRIMITIVES_POSET_ID, standard_name());
433 
434  // Get write access
435 
436  get_read_write_access();
437 
438  // Initialize the table dof map.
439  // This class has no table dofs, but we want a non-null dof map anyway.
440 
441  initialize_table_dofs(0,0);
442 
443  // Create subposets for jims and whole, and schema subposets for top
444 
445  initialize_standard_subposets(standard_name());
446 
447  // Create bottom, top, and primitives.
448 
449  initialize_standard_members();
450 
451  // Schematize all members of this so it can be used as schema
452 
453  schematize(_table_dof_subposet, _row_dof_subposet, true);
454 
455  // Schematize has created new subposets, reset the standard subposet count.
456  // Every subposet is a standard subposet.
457 
458  put_standard_subposet_ct(subposet_ct());
459 
460  // Set the standard id spaces.
461 
462  update_standard_member_id_spaces();
463 
464  // We won't use the two subposet handles again;
465  // detach and delete them
466 
467  _table_dof_subposet->detach_from_state();
468  delete _table_dof_subposet;
469  _table_dof_subposet = 0;
470 
471  _row_dof_subposet->detach_from_state();
472  delete _row_dof_subposet;
473  _row_dof_subposet = 0;
474 
475  enable_invariant_check();
476 
477  // Postconditions:
478 
479  ensure(invariant());
480  ensure(primitive_members_attached());
481  ensure(!in_jim_edit_mode());
482  // ensure(host() == xhost);
483  ensure(has_standard_member_ct());
484  ensure(has_standard_row_dof_tuple_ct());
485  ensure(has_standard_subposet_ct());
486 
487  // release thread access to poset state
488 
489  release_access();
490 
491  ensure(state_is_not_read_accessible());
492 }
493 
494 void
495 sheaf::primitives_poset::
496 initialize_standard_members()
497 {
498  // Preconditions:
499 
500  // Body:
501 
502  // First create the standard members of the base class
503 
504  poset_state_handle::initialize_standard_members();
505 
506  // All jims will be members of the row dof subposet;
507  // the table dof subposet is empty
508 
509  // Enter edit mode
510 
511  begin_jim_edit_mode();
512 
513  // Create members for the standard primitive types
514 
515  initialize_primitive_member(_bool_type, BOOL); // 2
516  initialize_primitive_member(_char_type, CHAR); // 3
517 
518  initialize_primitive_member(_signed_char_type, SIGNED_CHAR); // 4
519  initialize_primitive_member(_short_int_type, SHORT_INT); // 5
520  initialize_primitive_member(_int_type, INT); // 6
521  initialize_primitive_member(_long_int_type, LONG_INT); // 7
522  initialize_primitive_member(_long_long_int_type, LONG_LONG_INT); // 8
523 
524  initialize_primitive_member(_unsigned_char_type, UNSIGNED_CHAR); // 9
525  initialize_primitive_member(_unsigned_short_int_type, UNSIGNED_SHORT_INT); // 10
526  initialize_primitive_member(_unsigned_int_type, UNSIGNED_INT); // 11
527  initialize_primitive_member(_unsigned_long_int_type, UNSIGNED_LONG_INT); // 12
528  initialize_primitive_member(_unsigned_long_long_int_type, UNSIGNED_LONG_LONG_INT); // 13
529 
530  initialize_primitive_member(_float_type, FLOAT); // 14
531  initialize_primitive_member(_double_type, DOUBLE); // 15
532  initialize_primitive_member(_long_double_type, LONG_DOUBLE); // 16
533 
534  initialize_primitive_member(_void_star_type, VOID_STAR); // 17
535  initialize_primitive_member(_c_string_type, C_STRING); // 18
536 
537  initialize_primitive_member(_namespace_relative_member_index_type, NAMESPACE_RELATIVE_MEMBER_INDEX); // 19
538  initialize_primitive_member(_namespace_relative_subposet_index_type, NAMESPACE_RELATIVE_SUBPOSET_INDEX); // 20
539 
540  // Exit edit mode
541 
542  end_jim_edit_mode();
543 
544  // Now there's 21 standard members and 19 standard dof tuples,
545  // top, bottom, and the 19 primitive types.
546 
547  // All the members and dof tuples are standard.
548 
549  put_standard_member_ct(member_ct());
550  put_standard_row_dof_tuple_ct(row_dof_tuple_ct());
551 
552  // Postconditions:
553 
554  ensure(primitive_members_attached());
555  ensure(has_standard_member_ct());
556  ensure(has_standard_row_dof_tuple_ct());
557 
558  // Exit:
559 
560  return;
561 }
562 
563 void
564 sheaf::primitives_poset::
565 initialize_standard_subposets(const std::string& xname)
566 {
567 
568  // Preconditions:
569 
570  require(poset_path::is_valid_name(xname));
571  require(state_is_read_write_accessible());
572 
573  // Body:
574 
575  // Initialize the subposets common to all posets:
576 
577  poset_state_handle::initialize_standard_subposets(xname);
578 
579  // Create empty table and row dof subposets;
580  // Standard names will be given in member function schematize.
581 
582  _table_dof_subposet = new subposet(this);
583  _row_dof_subposet = new subposet(this);
584 
585  put_standard_subposet_ct(subposet_ct());
586 
587  // Standard subposet count will be reset in new_state
588  // after schematizing, since that creates new subposets.
589 
590  // Postconditions:
591 
592  ensure(has_standard_subposet_ct());
593 
594  // Exit:
595 
596  return;
597 }
598 
599 
600 // ===========================================================
601 // ANY FACET
602 // ===========================================================
603 
604 // PUBLIC FUNCTIONS
605 
606 bool
608 is_ancestor_of(const any* xother) const
609 {
610  bool result;
611 
612  // Preconditions:
613 
614  // Body:
615 
616  result = dynamic_cast<const primitives_poset*>(xother) != 0;
617 
618  // Postconditions:
619 
620  // Exit
621 
622  return result;
623 }
624 
625 bool
627 invariant() const
628 {
629  bool result = true;
630 
631  // Preconditions:
632 
633  // Body:
634 
635  if(invariant_check())
636  {
637  result = result && poset_state_handle::invariant();
638 
639  disable_invariant_check();
640 
641  if(is_attached())
642  {
643  result = result && primitive_members_attached();
645  }
646 
647  enable_invariant_check();
648  }
649 
650 
651  // Postconditions:
652 
653  // Exit
654 
655  return result;
656 }
657 
658 // PROTECTED FUNCTIONS
659 
660 // PRIVATE FUNCTIONS
661 
663 sheaf::primitives_poset::
664 clone() const
665 {
666  primitives_poset* result;
667 
668  // Preconditions:
669 
670  // Body:
671 
672  result = new primitives_poset();
673 
674  // Postconditions:
675 
676  ensure(result != 0);
677  ensure(is_same_type(result));
678 
679  // Exit
680 
681  return result;
682 }
683 
684 
A client handle for a subposet.
Definition: subposet.h:86
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 bool is_ancestor_of(const any *other) const
True if other conforms to this.
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...
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
static const std::string & standard_name()
The standard name for an instance of this class.
STL namespace.
const scoped_index & index() const
The index of the component state this handle is attached to.
std::string name() const
A name for this.
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
The poset containing the primitive type definitions.
Abstract base class with useful features for all objects.
Definition: any.h:39
bool invariant() const
Class invariant.
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...
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
Definition: eval_family.h:49
primitive_type
Type ids for sheaf primitives.
A map from schema poset member ids to dof values for primitives_poset members.
virtual bool is_attached() const
True if this handle is attached to a non-void state.
bool primitive_members_attached() const
True if the primitive members are all attached.
virtual bool contains_member(pod_index_type xmbr_hub_id, bool xauto_access=true) const
True if some version of this poset contains poset member with hub id xmbr_hub_id. ...
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.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual poset_type type_id() const
Identifier for the type of this poset.
void insert_prototype(T *xprototype)
Sets xprototype as the prototype for its client class.
Definition: factory.impl.h:144
virtual const char * class_name() const
The name of this class.
An abstract client handle for a member of a poset.
int int_type
The preferred integer type.
Definition: sheaf.h:41
A client handle for an unrestricted member of a poset. A total_poset_member is guaranteed not to be r...