SheafSystem  0.0.0.0
poset_state.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 poset_state
19 
20 #include "SheafSystem/poset_state.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/poset_crg_state.h"
24 #include "SheafSystem/poset_powerset_state.h"
25 #include "SheafSystem/poset_table_state.h"
26 #include "SheafSystem/schema_poset_member.h"
27 #include "SheafSystem/subposet.h"
28 
29 // ===========================================================
30 // POSET_STATE FACET
31 // ===========================================================
32 
33 // PUBLIC MEMBER FUNCTIONS
34 
36 poset_state(const abstract_poset_member* xschema, poset_type xtype_id, const std::string& xname)
37 {
38  // Preconditions:
39 
40  require(xschema != 0 ? xschema->is_attached() : true);
41 
42  // Body:
43 
44  // Prevent recursive calls to invariant
45 
47 
48  _name = xname;
49 
50  _type_id = xtype_id;
51 
52  // Create the cover relation graph data structure
53 
54  _crg = new poset_crg_state();
55 
56  // Create the powerset (set of subposets) data structure
57 
58  const size_type lsubset_ct= 4; // arbitrary
59 
60  _powerset = new poset_powerset_state(lsubset_ct, _crg->end());
61 
62  // Create the table (dof tuples) structure.
63  // Assume one dof tuple for each member as initial guess
64  // for number of row dof tuples.
65 
66  const size_type lmbr_ct = 16; // arbitrary
67 
68  _table = new poset_table_state(xschema, lmbr_ct);
69 
70  // Invariant is not satisfied until client initializes
71  // standard subsets, standard members, and schema.
72  // Leave invariant checking disabled.
73 
74  // Postconditions:
75 
76  ensure(crg() != 0);
77  ensure(!crg()->jim_edit_mode());
78  ensure(powerset() != 0);
79  ensure(powerset()->subposet_member_index_ub() >= crg()->end());
80  ensure(xschema != 0 ? table()->schema().is_same_state(xschema) : true);
81 
82  // Exit:
83 
84  return;
85 }
86 
87 // sheaf::poset_state::
88 // poset_state(const abstract_poset_member* xschema,
89 // poset_type xtype_id,
90 // size_type xmbr_ct,
91 // size_type xlink_ct,
92 // size_type xsubset_ct)
93 // {
94 // // Preconditions:
95 
96 // require(xschema != 0 ? xschema->is_attached() : true);
97 // require(xmbr_ct >= 0);
98 // require(xlink_ct >=0);
99 // require(xsubset_ct >= 0);
100 
101 // // Body:
102 
103 // // Prevent recursive calls to invariant
104 
105 // disable_invariant_check();
106 
107 // _type_id = xtype_id;
108 
109 // // Create the cover relation graph data structure
110 
111 // _crg = new poset_crg_state();
112 
113 // // Create the powerset (set of subposets) data structure
114 
115 // _powerset = new poset_powerset_state(xsubset_ct, _crg->end());
116 
117 // // Create the table (dof tuples) structure.
118 // // Assume one dof tuple for each member as initial guess
119 // // for number of row dof tuples.
120 
121 // _table = new poset_table_state(xschema, xmbr_ct);
122 
123 // // Invariant is not satisfied until client initializes
124 // // standard subsets, standard members, and schema.
125 // // Leave invariant checking disabled.
126 
127 // // Postconditions:
128 
129 // ensure(crg() != 0);
130 // ensure(!crg()->jim_edit_mode());
131 // ensure(powerset() != 0);
132 // ensure(powerset()->subposet_member_index_ub() >= crg()->end());
133 // ensure( (xschema != 0) == table()->schema().is_attached() );
134 
135 // // Exit:
136 
137 // return;
138 // }
139 
142 {
143  // Preconditions:
144 
145  // Body:
146 
147  // Deallocate powerset (set of subposets)
148 
149  delete _powerset;
150 
151  // Deallocate the table (dof tuples).
152 
153  delete _table;
154 
155  // Deallocate cover relation graph.
156 
157  delete _crg;
158 
159  // Postconditions:
160 
161  // Exit:
162 
163  return;
164 }
165 
166 const std::string&
168 name() const
169 {
170  return _name;
171 }
172 
173 void
175 put_name(const std::string& xname)
176 {
177  // cout << endl << "Entering poset_state::put_name." << endl;
178 
179  // Preconditions:
180 
181  require(poset_path::is_valid_name(xname));
182 
183  // Body:
184 
185  _name = xname;
186 
187  // Postconditions:
188 
189  ensure(name() == xname);
190 
191  // Exit:
192 
193  // cout << "Leaving poset_state::put_name." << endl;
194  return;
195 }
196 
199 type_id() const
200 {
201  poset_type result;
202 
203  // Preconditions:
204 
205  // Body:
206 
207  result = _type_id;
208 
209  // Postconditions:
210 
211  // Exit
212 
213  return result;
214 }
215 
219 {
220  poset_crg_state* result;
221 
222  // Preconditions:
223 
224  // Body:
225 
226  result = _crg;
227 
228  // Postconditions:
229 
230  ensure(result != 0);
231 
232  // Exit
233 
234  return result;
235 }
236 
240 {
241  poset_powerset_state* result;
242 
243  // Preconditions:
244 
245  // Body:
246 
247  result = _powerset;
248 
249  // Postconditions:
250 
251  ensure(result != 0);
252 
253  // Exit
254 
255  return result;
256 }
257 
260 table() const
261 {
262  poset_table_state* result;
263 
264  // Preconditions:
265 
266  // Body:
267 
268  result = _table;
269 
270  // Postconditions:
271 
272  ensure(result != 0);
273 
274  // Exit
275 
276  return result;
277 }
278 
279 // PROTECTED MEMBER FUNCTIONS
280 
281 // PRIVATE MEMBER FUNCTIONS
282 
283 
284 // ===========================================================
285 // ANY FACET
286 // ===========================================================
287 
288 // PUBLIC MEMBER FUNCTIONS
289 
290 bool
292 is_ancestor_of(const any* xother) const
293 {
294  bool result;
295 
296  // Preconditions:
297 
298  // Body:
299 
300  result = dynamic_cast<const poset_state*>(xother) != 0;
301 
302  // Postconditions:
303 
304  // Exit
305 
306  return result;
307 }
308 
311 clone() const
312 {
313  poset_state* result = 0;
314 
315  // Preconditions:
316 
317  // Body:
318 
320 
321  not_implemented();
322 
323  // Postconditions:
324 
325  ensure(result != 0);
326 
327  // Exit
328 
329  return result;
330 }
331 
332 bool
334 invariant() const
335 {
336  bool result = true;
337 
338  // Preconditions:
339 
340  // Body:
341 
342  if(invariant_check())
343  {
344  // Test invariant of base class
345 
346  result = result && read_write_monitor::invariant();
347 
348  // Prevent recursive calls to invariant();
349 
351 
352  // Test invariants of individual components
353 
354  result = result && _crg->invariant();
355  result = result && _powerset->invariant();
356  result = result && _table->invariant();
357 
358  // Check inter-component dependencies
359 
360  result = result && (_powerset->subposet_member_index_ub() == _crg->end());
361 
363  }
364 
365  // Postconditions:
366 
367  // Exit
368 
369  return result;
370 }
371 
372 // PROTECTED MEMBER FUNCTIONS
373 
374 // PRIVATE MEMBER FUNCTIONS
375 
376 
377 // ===========================================================
378 // NON-MEMBER FUNCTIONS
379 // ===========================================================
380 
381 size_t
382 sheaf::deep_size(const poset_state& xp, bool xinclude_shallow, size_t xresults[4])
383 {
384  size_t result;
385 
386  // Preconditions:
387 
388  // Body:
389 
390  result = xinclude_shallow ? sizeof(xp) : 0;
391 
392  poset_state& lxp = const_cast<poset_state&>(xp);
393 
394  if(lxp.crg() != 0)
395  {
396  size_t lmemory_parts[2];
397  size_t lcrg_result = deep_size(*lxp.crg(), true, lmemory_parts);
398  result += lcrg_result;
399 
400  if(xresults != 0)
401  {
402  xresults[0] = lmemory_parts[0];
403  xresults[1] = lmemory_parts[1];
404  }
405  }
406  else if(xresults != 0)
407  {
408  xresults[0] = 0;
409  xresults[1] = 0;
410  }
411 
412  if(lxp.powerset() != 0)
413  {
414  size_t lpowerset_result = deep_size(*lxp.powerset(), true);
415  result += lpowerset_result;
416 
417  if(xresults != 0)
418  xresults[2] = lpowerset_result;
419  }
420  else if(xresults != 0)
421  {
422  xresults[2] = 0;
423  }
424 
425  if(lxp.table() != 0)
426  {
427  size_t ltable_result = deep_size(*lxp.table());
428  result += ltable_result;
429 
430  if(xresults != 0)
431  xresults[3] = ltable_result;
432  }
433  else if(xresults != 0)
434  {
435  xresults[3] = 0;
436  }
437 
438  // Postconditions:
439 
440  ensure(result >= 0);
441 
442  // Exit
443 
444  return result;
445 }
virtual bool is_ancestor_of(const any *other) const
True if other conforms to current.
Definition: poset_state.cc:292
virtual bool invariant() const
Class invariant.
The data structure representing the cover relation graph of a poset.
The private state of a partially ordered set.
Definition: poset_state.h:49
poset_crg_state * crg()
/// The name of the type of poset.
Definition: poset_state.cc:218
virtual poset_state * clone() const
Make a new instance of the same type as this.
Definition: poset_state.cc:311
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
poset_state()
Default constructor; private to disable default construction.
Definition: poset_state.h:121
poset_type type_id() const
Identifier for the type of this poset.
Definition: poset_state.cc:199
virtual bool invariant() const
Class invariant.
poset_table_state * table() const
Table (dof tuples).
Definition: poset_state.cc:260
void put_name(const std::string &xname)
Sets name() to xname.
Definition: poset_state.cc:175
Abstract base class with useful features for all objects.
Definition: any.h:39
poset_powerset_state * powerset()
Set of subposets (powerset)
Definition: poset_state.cc:239
virtual bool invariant() const
Class invariant.
Definition: poset_state.cc:334
friend SHEAF_DLL_SPEC size_t deep_size(const poset_state &xp, bool xinclude_shallow, size_t xresults[4])
The deep size of the referenced object of type poset_state. if xinclude_shallow, add the sizeof xp to...
const scoped_index & end() const
The end of the member interval; members have indices in the interval [begin(), end()).
virtual bool is_attached() const
True if this handle is attached to a non-void state.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
const std::string & name() const
The name of this poset.
Definition: poset_state.cc:168
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
poset_crg_state * _crg
The cover relation graph for this poset.
Definition: poset_state.h:136
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
bool invariant() const
Class invariant.
poset_powerset_state * _powerset
The set of subposets for this poset .
Definition: poset_state.h:141
~poset_state()
Destructor.
Definition: poset_state.cc:141
virtual bool invariant() const
Class invariant.
std::string _name
The name of this poset.
Definition: poset_state.h:121
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
poset_type _type_id
Identifier for the type of poset.
Definition: poset_state.h:131
An abstract client handle for a member of a poset.
poset_table_state * _table
The table of dof tuples for this poset.
Definition: poset_state.h:146
The set of subsets of a poset.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
const scoped_index & subposet_member_index_ub() const
Upper bound of member index in each subposet.
The data structure representing the table containing the dof tuples of the members of a poset...