SheafSystem  0.0.0.0
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/abstract_poset_member.h"
22 #include "SheafSystem/array_poset_dof_map.h"
23 class index_iterator;
24 #include "SheafSystem/namespace_poset.impl.h"
25 #include "SheafSystem/poset.h"
26 #include "SheafSystem/poset_handle_factory.h"
27 #include "SheafSystem/poset_member_iterator.h"
28 #include "SheafSystem/poset_state.h"
29 #include "SheafSystem/poset_type.h"
30 #include "SheafSystem/schema_poset_member.h"
31 #include "SheafSystem/subposet.h"
32 
33 // ===========================================================
34 // POSET FACET
35 // ===========================================================
36 
37 // PUBLIC FUNCTIONS
38 
39 
42 new_table(namespace_type& xns, const poset_path& xpath, const poset_path& xschema_path, bool xauto_access)
43 {
44  // cout << endl << "Entering poset::new_table." << endl;
45 
46  // Preconditions:
47 
48  require(xns.state_is_auto_read_write_accessible(xauto_access));
49 
50  require(!xpath.empty());
51  require(!xns.contains_poset(xpath, xauto_access));
52 
53  require(xschema_path.full());
54  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
55 
56  // Body:
57 
58  // Create the table; have to new it because namespace keeps a pointer.
59 
60  typedef poset table_type;
61 
62  table_type* ltable = new table_type();
63 
64  // Create a handle of the right type for the schema member.
65 
66  schema_poset_member lschema(&xns, xschema_path, xauto_access);
67 
68  if(xauto_access)
69  {
70  lschema.get_read_access();
71  }
72 
73  // Create the table dof map; must be newed
74  // because poset_state::_table keeps a pointer to it.
75  // No table dofs to set.
76 
77  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
78 
79  // Create the state.
80 
81  ltable->new_state(xns, xpath, lschema, *lmap);
82 
83  if(xauto_access)
84  {
85  lschema.release_access();
86  }
87 
88  poset& result = *ltable;
89 
90  // Postconditions:
91 
92  ensure(xns.owns(result, xauto_access));
93  ensure(result.path(true).poset_name() == xpath.poset_name());
94  ensure(result.state_is_not_read_accessible());
95  ensure(result.schema(true).path(xauto_access) == xschema_path);
96 
97  // Exit:
98 
99  // cout << "Leaving poset::new_table." << endl;
100  return result;
101 }
102 
103 
104 // PROTECTED FUNCTIONS
105 
108 {
109  // Preconditions:
110 
111  // Body:
112 
113  // Nothing to do, handled by base class
114 
115  // Postconditions:
116 
117  ensure(postcondition_of(poset_state_handle::poset_state_handle()));
118 }
119 
122 {
123  // Preconditions:
124 
125  require(is_attached() ? state_is_read_write_accessible() : true);
126 
127  // Body:
128 
129  // Nothing to do; base class does it all.
130  // Currently, this routine exists mostly for the precondition,
131  // which is the same as poset_state_handle::~poset_state_handle.
132  // With this precondition in place, the source of a precondition
133  // violation will be clearer to the client.
134 
135  // Postconditions:
136 
137  // Exit
138 
139  return;
140 }
141 
144  : poset_state_handle(xtop, xbottom)
145 {
146  // Preconditions:
147 
148  require(xtop != 0);
149  require(xbottom != 0);
150 
151  // Body:
152 
153  // Nothing to do.
154 
155  // Postconditions:
156 
157  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
158 
159  // Exit:
160 
161  return;
162 }
163 
164 // PRIVATE FUNCTIONS
165 
166 bool
167 sheaf::poset::
168 make_prototype()
169 {
170  // Preconditions:
171 
172  // Body:
173 
174  poset* lproto = new poset;
175 
176  factory().insert_prototype(lproto);
177  factory().insert_prototype(lproto->type_id(), lproto);
178 
179  // Postconditions:
180 
181  // Exit:
182 
183  return true;
184 }
185 
186 
187 // ===========================================================
188 // STATE FACET
189 // ===========================================================
190 
191 // PUBLIC FUNCTIONS
192 
193 // PROTECTED FUNCTIONS
194 
195 // PRIVATE FUNCTIONS
196 
197 
198 // ===========================================================
199 // POSET_STATE_HANDLE FACET
200 // ===========================================================
201 
202 // PUBLIC FUNCTIONS
203 
206 type_id() const
207 {
208  return POSET_ID;
209 }
210 
211 const char*
213 class_name() const
214 {
215  // Preconditions:
216 
217  // Body:
218 
219  static const char* result = "poset";
220 
221  // Postconditions:
222 
223  // Exit:
224 
225  return result;
226 }
227 
228 void
230 begin_jim_edit_mode(bool xauto_access)
231 {
232  // Preconditions:
233 
234  require(!xauto_access ? state_is_read_write_accessible() : true);
235 
236  // Body:
237 
238  // Redefinition here is only to change visibility.
239 
241 
242  // Postconditions:
243 
244  ensure(in_jim_edit_mode());
245 
246  // Exit
247 
248  return;
249 }
250 
251 void
253 end_jim_edit_mode(bool xensure_lattice_invariant,
254  bool xauto_access)
255 {
256  // Preconditions:
257 
258  require(in_jim_edit_mode());
260 
261  // Body:
262 
263  // Redefinition here is only to change visibility
264 
265  poset_state_handle::end_jim_edit_mode(xensure_lattice_invariant, xauto_access);
266 
267  // Postconditions:
268 
269  // Exit
270 
271  return;
272 }
273 
274 // PROTECTED FUNCTIONS
275 
276 void
278 new_state(const poset_path& xpath, const schema_poset_member& xschema, array_poset_dof_map& xdof_map)
279 {
280 
281  // Preconditions:
282 
283  require(schema_is_ancestor_of(&xschema));
284  require(xschema.state_is_read_accessible());
285 
288 
290 
291  require(unexecutable("xschema.is_same_state(xdof_map.schema())"));
292 
293  // Body:
294 
295  // Disable invariant checking in
296  // member functions until construction finished
297 
299 
300  // Create the poset state object;
301  // Allocates the data structures but does not (fully) initialize them
302 
303  _state = new poset_state(&xschema, type_id(), xpath.poset_name());
304 
305  // Get write access.
306  // Descendants may have data members, which aren't attached yet,
307  // Derived get access routines will try to get access to data members,
308  // so force current scope.
309 
311 
312  // Initialize the table dofs ("class variables");
313  // must be done before row structure since row structure
314  // may depend on table dofs.
315 
316  initialize_table_dof_tuple(&xdof_map);
317 
318  // Initialize the row structure
319 
322 
337 
344 
348 
349  put_version(COARSEST_COMMON_REFINEMENT_VERSION);
350 
351  // Set the standard id spaces.
352 
354 
355  // Initialize any additional handle data members.
356 
358 
359  // Release and regain access;
360  // will get access to handle data members.
361 
364 
365  // Now invariant should be satisfied
366 
368 
369  // Postconditions:
370 
371  ensure(invariant());
372  ensure(is_attached());
373  ensure(!in_jim_edit_mode());
374  ensure(schema().is_same_state(&xschema));
375  ensure(has_standard_member_ct());
377  ensure(version() == COARSEST_COMMON_REFINEMENT_VERSION);
378 
379  // Now we're finished, release all access
380 
381  release_access();
382 
383  // One final postcondition
384 
386 }
387 
388 // PRIVATE FUNCTIONS
389 
390 
391 // ===========================================================
392 // ANY FACET
393 // ===========================================================
394 
395 // PUBLIC FUNCTIONS
396 
397 bool
399 is_ancestor_of(const any* xother) const
400 {
401  bool result;
402 
403  // Preconditions:
404 
405  // Body:
406 
407  result = dynamic_cast<const poset*>(xother) != 0;
408 
409  // Postconditions:
410 
411  // Exit
412 
413  return result;
414 }
415 
418 clone() const
419 {
420  poset* result;
421 
422  // Preconditions:
423 
424  // Body:
425 
426  result = new poset;
427 
428  // Postconditions:
429 
430  ensure(result != 0);
431  ensure(!result->is_attached());
432 
433  // Exit
434 
435  return result;
436 }
437 
438 bool
440 invariant() const
441 {
442  bool result = true;
443 
444  result = result && poset_state_handle::invariant();
445 
446  if(invariant_check())
447  {
449 
452 
454  }
455 
456  return result;
457 }
458 
459 // PROTECTED FUNCTIONS
460 
461 // PRIVATE FUNCTIONS
462 
void put_version(int xversion)
Set the current level to xversion.
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 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 bool invariant() const
Class invariant.
Definition: poset.cc:440
bool has_standard_member_ct() const
True if poset is in its initial state, that is, it contains just the standard members.
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
The private state of a partially ordered set.
Definition: poset_state.h:49
static poset & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, bool xauto_access)
Creates a new poset in namespace xns with path xpath and schema specified by xschema_path.
Definition: poset.cc:42
virtual poset * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: poset.cc:418
void initialize_table_dof_tuple(array_poset_dof_map *xdof_tuple)
Installs xdof_tuple as the table dof tuple.
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 initialize_standard_members()
Creates the members common to every poset, for instance, top() and bottom().
A client handle for a general, abstract partially order set.
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_standard_subposets(const std::string &xname)
Creates the subposets common to every poset (e.g. whole() and jims()).
virtual int version() const
The current version.
virtual void get_read_access() const
Get read access to the state associated with this.
virtual namespace_poset * name_space() const
The namespace of host()
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 schema_poset_member & schema()
The schema for this poset (mutable version).
virtual ~poset()
Destructor.
Definition: poset.cc:121
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...
A client handle for a mutable partially ordered set.
Definition: poset.h:40
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.
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)
std::string poset_name() const
The poset name part of the path.
Definition: poset_path.cc:473
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
Definition: poset.cc:399
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
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
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...
poset_state_handle()
Default constructor.
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
static poset_handle_factory & factory()
The poset handle factory.
virtual bool is_attached() const
True if this is attached to a state.
virtual const char * class_name() const
The name of this class.
Definition: poset.cc:213
virtual void new_state(const poset_path &xpath, const schema_poset_member &xschema, array_poset_dof_map &xdof_map)
Creates a new poset state with path xpath, schema xschema and table dof map xdof_map, attaches this to the state.
Definition: poset.cc:278
poset_state * _state
State object for this poset.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
Prevent editing of jims and jim order relation.
Definition: poset.cc:253
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
Prevent editing of jims and jim order relation.
bool is_same_state(const poset_state_handle *xother) const
True if this is attached to the same state as xother.
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.
An array representation of abstract class poset_dof_map.
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...
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.
A client handle for a poset member which has been prepared for use as a schema.
virtual poset_type type_id() const
Identifier for the type of this poset.
Definition: poset.cc:206
virtual bool schema_is_ancestor_of(const schema_poset_member *xother_schema) const
True if xother_schema conforms to the type of schema required by this.
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
Definition: poset.cc:230