SheafSystem  0.0.0.0
poset_general_record.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_general_record
19 
20 #include "SheafSystem/poset_general_record.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/namespace_poset.h"
24 #include "SheafSystem/poset.h"
25 #include "SheafSystem/poset_bounds.h"
26 #include "SheafSystem/std_sstream.h"
27 
28 using namespace std;
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
32 // CANONICAL MEMBERS
33 
34 // Copy constructor
38  : attributes_record(xother)
39 {
40 
41  // Preconditions:
42 
43  // Body:
44 
45  not_implemented();
46 
47  // Postconditions:
48 
49  ensure(invariant());
50 }
51 
52 // Virtual constructor
56 clone() const
57 {
58  poset_general_record* result;
59 
60  // Preconditions:
61 
62  // Body:
63 
64  result = new poset_general_record(*this);
65 
66 
67  // Postconditions:
68 
69  ensure(result != 0);
70  ensure(is_same_type(result));
71 
72  // Exit:
73 
74  return result;
75 }
76 
77 // Destructor
81 {
82 
83  // Preconditions:
84 
85  // Body:
86 
87  // Postconditions:
88 
89  // Exit:
90 
91  return;
92 }
93 
94 // Class invariant
96 bool
98 invariant() const
99 {
100  bool result = true;
101 
102  // Preconditions:
103 
104  // Body:
105 
106  // Must satisfy base class invariant
107 
108  invariance(attributes_record::invariant());
109 
110  if(invariant_check())
111  {
112  // Prevent recursive calls to invariant
113 
115 
116  // Finished, turn invariant checking back on.
117 
119  }
120 
121  // Postconditions:
122 
123  // Exit
124 
125  return result;
126 }
127 
128 // Conformance test
130 bool
132 is_ancestor_of(const any* other) const
133 {
134 
135  // Preconditions:
136 
137  require(other != 0);
138 
139  // Body:
140 
141  // True if other conforms to this
142 
143  bool result = dynamic_cast<const poset_general_record*>(other) != 0;
144 
145  // Postconditions:
146 
147  return result;
148 
149 }
150 
151 // POSET_GENERAL_RECORD INTERFACE
152 
156  : attributes_record(xscaffold)
157 {
158 
159  // Preconditions:
160 
161 
162  // Body:
163 
164  // Get the data converters
165 
166  // Postconditions:
167 
168  ensure(invariant());
169 
170  // Exit:
171 
172  return;
173 }
174 
176 void
179 {
180  // Preconditions:
181 
182  require(is_internal());
183  require(!scaffold().structure().is_external() ?
184  scaffold().structure().state_is_read_write_accessible() :
185  true);
186  require(scaffold().name_space()->state_is_read_accessible());
187 
188 
189  // Body:
190 
191  // Initialize the stream.
192 
193  stringstream lstream(_str_buf);
194 
195  lstream << boolalpha;
196 
197  // Skip the header line:
198 
199  lstream.ignore(numeric_limits<streamsize>::max(), '\n');
200 
201  // Read each attribute; skipping the name in front and the newline at the end.
202 
203  string lskip_name;
204  char lend;
205 
206  // General attributes
207 
208  int ltype_id;
209  lstream >> lskip_name >> ltype_id;
210 
211  int lmember_ct;
212  lstream >> lskip_name >> lmember_ct;
213 
214  int ldof_tuple_ct;
215  lstream >> lskip_name >> ldof_tuple_ct;
216 
217  primitive_type lrow_dof_tuple_type;
218  lstream >> lskip_name >> lrow_dof_tuple_type;
219 
220  bool lis_versioned;
221  lstream >> lskip_name >> lis_versioned;
222 
223  // Subposet attributes
224 
225  int lsubposet_ct;
226  lstream >> lskip_name >> lsubposet_ct;
227 
228  // Type attributes
229 
230  int ltoc_type;
231  lstream >> lskip_name >> ltoc_type;
232 
233  int ldof_tuple_id_type;
234  lstream >> lskip_name >> ldof_tuple_id_type;
235 
236  int loffset_type;
237  lstream >> lskip_name >> loffset_type;
238 
239  // Schema attributes
240 
241  scoped_index::pod_type lschema_poset_ext_id_pod;
242  lstream >> lskip_name >> lschema_poset_ext_id_pod;
243 
244  scoped_index::pod_type lschema_member_ext_id_pod;
245  lstream >> lskip_name >> lschema_member_ext_id_pod;
246 
247  scoped_index::pod_type lbase_space_ext_id_pod;
248  lstream >> lskip_name >> lbase_space_ext_id_pod;
249 
250  scoped_index::pod_type lfiber_schema_ext_id_pod;
251  lstream >> lskip_name >> lfiber_schema_ext_id_pod;
252 
253  scoped_index::pod_type llocal_schema_ext_id_pod;
254  lstream >> lskip_name >> llocal_schema_ext_id_pod;
255 
256  int lschema_version;
257  lstream >> lskip_name >> lschema_version;
258 
259  // Table of contents attributes.
260 
261  bool llb_is_singleton;
262  lstream >> lskip_name >> llb_is_singleton;
263 
264  int llb_id;
265  lstream >> lskip_name >> llb_id;
266 
267  int lub_id;
268  lstream >> lskip_name >> lub_id;
269 
270  // Translate the schema poset external id to internal.
271 
273 
274  pod_index_type lschema_poset_int_id =
275  lns->get_int_id(lschema_poset_ext_id_pod,
276  scaffold().file_id_space_name(),
277  false);
278 
279  // Get a handle to the schema poset.
280 
281  poset_state_handle& lschema_poset = lns->member_poset(lschema_poset_int_id, false);
282 
283  // Get a handle to the external schema.
284 
285  schema_poset_member* lext_schema =
286  lschema_poset.new_schema_handle(scaffold().file_id_space_name(),
287  lschema_member_ext_id_pod,
288  lbase_space_ext_id_pod,
289  lfiber_schema_ext_id_pod,
290  llocal_schema_ext_id_pod);
291 
292  scaffold().initialize_schema_for_read(lext_schema, lschema_version);
293 
294  // Set is_versioned in the scaffold for use in subposet_names_record.
295 
296  scaffold().is_versioned() = lis_versioned;
297 
302 
303  // We know how many subposet there are now, but we can't
304  // create the subposets and load the scaffold subposet vector
305  // yet because we can't create the poset state until we've read the table dofs
306  // in table_dof_tuple_record::internalize.
307  // So just set the size of the scaffold subposet vector now.
308  // We'll create and name the subposets in
309  // subposet_names_record::transfer_internal_buffer_to_poset.
310 
311  scaffold().subposets().reserve(lsubposet_ct);
312  scaffold().subposets().resize(lsubposet_ct);
313 
314  // Initialize the member record type aliases.
315 
317  ldof_tuple_id_type,
318  loffset_type);
319 
320 
321  // Postconditions:
322 
323  ensure(scaffold().internal_schema().is_attached());
324  ensure(scaffold().transfer_schema().is_attached());
325  ensure(scaffold().external_schema().is_attached());
326 
327  // Exit
328 
329  return;
330 }
331 
333 void
336 {
337  // Preconditions:
338 
339  require(scaffold().structure().state_is_read_accessible());
340 
341  // Body:
342 
343  stringstream lstream;
344 
345  lstream << boolalpha;
346 
347  lstream << "General attributes:" << endl;
348 
349 
350  // General attributes
351 
352  lstream << "type_id: "
353  << scaffold().structure().type_id()
354  << endl;
355 
356  lstream << "member_ct: "
357  << scaffold().structure().member_ct()
358  << endl;
359  lstream << "row_dof_tuple_ct: "
361  << endl;
362 
363  lstream << "row_dof_tuple_type: "
365  << endl;
366 
367  lstream << "is_versioned: "
368  << (scaffold().structure().version_ct() > 1)
369  << endl;
370 
371  // Subposet attributes
372 
373  lstream << "subposet_ct: "
374  << scaffold().subposets().size()
375  << endl;
376 
377  // Type attributes
378 
379  lstream << "toc_converter: "
381  << endl;
382 
383  lstream << "dof_tuple_id_converter: "
385  << endl;
386 
387  lstream << "offset_converter: "
389  << endl;
390 
391  // Schema attributes.
392 
393  // Get external ids for schema poset and schema member:
395 
396  pod_index_type lschema_poset_ext_id;
397  pod_index_type lschema_member_ext_id;
398  pod_index_type lbase_space_ext_id;
399  pod_index_type lfiber_schema_ext_id;
400  pod_index_type llocal_schema_ext_id;
401 
402  scaffold().external_schema().get_ext_ids(scaffold().file_id_space_name(),
403  lschema_poset_ext_id,
404  lschema_member_ext_id,
405  lbase_space_ext_id,
406  lfiber_schema_ext_id,
407  llocal_schema_ext_id);
408 
409  lstream << "schema_poset_ext_id: " << lschema_poset_ext_id << endl;
410  lstream << "schema_member_ext_id: " << lschema_member_ext_id << endl;
411  lstream << "base_space_ext_id: " << lbase_space_ext_id << endl;
412  lstream << "fiber_schema_ext_id: " << lfiber_schema_ext_id << endl;
413  lstream << "local_schema_ext_id: " << llocal_schema_ext_id << endl;
414 
415  lstream << "xfr_schema_version: " << scaffold().transfer_schema().version() << endl;
416 
417  // Table of contents attributes
418 
419  bool lb_is_singleton = scaffold().row_bounds().lb_is_singleton();
420 
421  lstream << "lb_is_singleton: " << lb_is_singleton << endl;
422 
423 
424  pod_index_type lint_lb_id = scaffold().row_bounds().lb_id();
425 
426  if(lb_is_singleton)
427  {
428  // lb_id is a member index
429 
430  lstream << "lb_id: "
431  << scaffold().member_id_space().pod(lint_lb_id)
432  << endl;
433  }
434  else
435  {
436  // lb_id is a subpose_id.
437 
438  lstream << "lb_id: "
439  << scaffold().subposet_id_space().pod(lint_lb_id)
440  << endl;
441  }
442 
443  // Upper bound of toc may not have been written out yet and so may not
444  // have an entry in the index map. But the upper bound is top by definition
445  // and the external id of top is the same as the internal id.
448 
449  lstream << "ub_id: " << TOP_INDEX << endl;
450 
451  // Have to copy stringstream to string
452  // because can't get C string from stringstream.
453 
454  _str_buf = lstream.str();
455 
456  put_is_internal(true);
457  put_is_external(false);
458 
459  // Postconditions:
460 
461  ensure(is_internal());
462  ensure(!is_external());
463 
464  // Exit
465 
466  return;
467 }
468 
469 
primitive_type row_dof_tuple_type() const
The type of row dofs defined by this. Synonym for dof_tuple_type(false).
virtual ~poset_general_record()
Destructor.
virtual schema_poset_member * new_schema_handle(const std::string &xid_space_name, pod_index_type xschema_member_ext_id, pod_index_type xbase_space_ext_id, pod_index_type xfiber_schema_ext_id, pod_index_type xlocal_schema_ext_id)
Creates a member handle of the type appropriate for members of this when used as a schema...
namespace_poset * name_space() const
The name space of this poset.
void put_member_record_type_aliases(int xtoc_index, int xdof_tuple_id_index, int xoffset_index)
Sets the member record specific data types.
bool lb_is_singleton() const
True if the lower bound contains a single member.
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
virtual int member_ct() const
The number of members of this poset.
virtual bool invariant() const
Class invariant.
poset_data_type_map & type_map()
The data type map used to convert data for this record (mutable version).
Definition: record.h:130
The default name space; a poset which contains other posets as members.
virtual bool invariant() const
Class invariant.
A client handle for a general, abstract partially order set.
virtual poset_general_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
std::vector< subposet * > & subposets()
Buffer for subposet handles (mutable version).
STL namespace.
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.
bool & is_versioned()
True if poset has more than one version (mutable version).
poset_general_record(const poset_general_record &xother)
Copy constructor.
virtual pod_type pod(pod_type xid) const
The pod index in this space equivalent to xid in the hub id space.
virtual poset_type type_id() const
Identifier for the type of this poset.
Abstract base class with useful features for all objects.
Definition: any.h:39
pod_index_type get_int_id(pod_index_type xext_id, const std::string &xid_space_name, bool xauto_access) const
Translates xext_id to an internal id using the equivalence map with name xid_space_name.
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
hid_t internal_index() const
The primitives poset member index for the internal type.
std::string _str_buf
The internal/external buffer.
virtual void transfer_internal_buffer_to_poset()
Initializes member with index xmbr_id from the internal buffer.
primitive_type
Type ids for sheaf primitives.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
data_converter * offset_converter() const
The data converter for implementation type offset.
bool is_internal() const
True if the internal buffer has been initialized.
size_type row_dof_tuple_ct() const
The number of row_dof_tuples of this poset.
A wrapper/adapter for the poset general attributes record. Intended for transferring data between the...
schema_poset_member & external_schema()
The schema of the poset in external namespace (mutable version).
poset_bounds & row_bounds()
The bounds for the rows in this transaction (mutable version).
void put_is_internal(bool xis_internal)
Sets is_internal to xis_internal.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
SHEAF_DLL_SPEC void max(const vd &x0, vd_value_type &xresult, bool xauto_access)
Maximum component of x0, pre-allocated version.
Definition: vd.cc:2097
void initialize_schema_for_read(schema_poset_member *xext_schema, int xschema_version)
Initialize internal, transfer, and external schema for read transactions.
poset_state_handle & structure()
The handle for the poset being transferred. (Name chosen to void name conflict with class poset...
virtual void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the member with index xmbr_id.
member_index_space_type & member_id_space()
External to internal member index space for structure() (mutable version).
subposet_index_space_type & subposet_id_space()
External to internal subposet index map for powerset() (mutable version).
data_converter * toc_converter() const
The data converter for implementation type toc.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
pod_index_type pod_type
The "plain old data" storage type for this.
Definition: scoped_index.h:128
virtual void get_ext_ids(const std::string &xid_space_name, pod_index_type &xschema_poset_ext_id, pod_index_type &xschema_member_ext_id, pod_index_type &xbase_space_ext_id, pod_index_type &xfiber_schema_ext_id, pod_index_type &xlocal_schema_ext_id) const
Gets the external ids of this in the id space with name xid_space_name.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
data_converter * dof_tuple_id_converter() const
The data converter for implementation type dof_tuple_id.
A poset specific collection of data converters, various buffers and other data used while transferrin...
schema_poset_member & transfer_schema()
The schema for the restriction that is being read or written (mutable version)
pod_index_type lb_id() const
The index of the lower bound member, if the lower bound contains a single member. ...
bool is_external() const
True if the external buffer has been initialized.
An abstract wrapper/adapter for attributes records. Intended for transferring data between the kernel...
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
A client handle for a poset member which has been prepared for use as a schema.
virtual int version_ct() const
The number of versions currently defined.
void put_is_external(bool xis_external)
Sets is_external to xis_external.