SheafSystem  0.0.0.0
dof_tuple_col_bounds_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 dof_tuple_col_bounds_record
19 
20 #include "SheafSystem/dof_tuple_col_bounds_record.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/std_sstream.h"
24 
25 using namespace std;
26 
27 // =============================================================================
28 // ANY FACET
29 // =============================================================================
30 
34 clone() const
35 {
37 
38  // Preconditions:
39 
40  // Body:
41 
42  result = new dof_tuple_col_bounds_record(*this);
43 
44  // Postconditions:
45 
46  ensure(result != 0);
47  ensure(is_same_type(result));
48 
49  // Exit:
50 
51  return result;
52 }
53 
54 
56 bool
58 invariant() const
59 {
60  bool result = true;
61 
62  // Preconditions:
63 
64  // Body:
65 
66  // Must satisfy base class invariant
67 
68  result = result && attributes_record::invariant();
69 
70  if(invariant_check())
71  {
72  // Prevent recursive calls to invariant
73 
74  disable_invariant_check();
75 
76  // Finished, turn invariant checking back on.
77 
78  enable_invariant_check();
79  }
80 
81  // Postconditions:
82 
83  // Exit
84 
85  return result;
86 }
87 
89 bool
91 is_ancestor_of(const any* other) const
92 {
93 
94  // Preconditions:
95 
96  require(other != 0);
97 
98  // Body:
99 
100  // True if other conforms to this
101 
102  bool result = dynamic_cast<const dof_tuple_col_bounds_record*>(other) != 0;
103 
104  // Postconditions:
105 
106  return result;
107 
108 }
109 
110 
111 // =============================================================================
112 // DOF_TUPLE_COL_BOUNDS_RECORD FACET
113 // =============================================================================
114 
118  : attributes_record(xscaffold)
119 {
120 
121  // Preconditions:
122 
123 
124  // Body:
125 
126  // Postconditions:
127 
128  ensure(invariant());
129 
130  // Exit:
131 
132  return;
133 }
134 
138  : attributes_record(xother)
139 {
140 
141  // Preconditions:
142 
143  // Body:
144 
145  not_implemented();
146 
147  // Postconditions:
148 
149  ensure(invariant());
150 }
151 
152 
153 
157 {
158 
159  // Preconditions:
160 
161  // Body:
162 
163  // Nothing specific to do.
165 
166  // Postconditions:
167 
168  // Exit:
169 
170  return;
171 }
172 
173 // =============================================================================
174 // PROTECTED MEMBER FUNCTIONS
175 // =============================================================================
176 
177 
179 void
182 {
183  // Preconditions:
184 
185  require(is_internal());
186  require(scaffold().structure().state_is_read_write_accessible());
187 
188  // Body:
189 
190  // Initialize the stream.
191 
192  stringstream lstream(_str_buf);
193 
194  // Skip the header line:
195 
196  lstream.ignore(numeric_limits<streamsize>::max(), '\n');
197 
198  // Transfer the col bounds into the scaffold.
199 
201  map_type& lmap = scaffold().dof_tuple_col_bounds();
202 
203  record_index::pod_type ltuple_id_pod;
204  record_index::pod_type lcol_bound[3];
205 
206  while(lstream >> ltuple_id_pod)
207  {
208  // Read the col bound.
209 
210  lstream >> lcol_bound[0];
211  lstream >> lcol_bound[1];
212  lstream >> lcol_bound[2];
213 
214  // Create the bounds descriptor.
215 
217  ldesc(poset_bounds_descriptor::int_to_mode(lcol_bound[0]),
218  lcol_bound[1],
219  lcol_bound[2]);
220 
221  // Insert in the bounds map.
222  // Implicitly converts ltuple_id_pod to unscoped scoped_index,
223  // which is what we want, for now.
224 
225  map_type::value_type lval(ltuple_id_pod, ldesc);
226  scaffold().dof_tuple_col_bounds().insert(lval);
227  }
228 
229  if(scaffold().is_write_transaction())
230  {
231  // We're re-reading the col bounds attribute in
232  // a multistep write protocol. The member and subposet
233  // index maps have already been created.
234 
235  // Translate the column bounds to internal ids.
236 
238  }
239  else
240  {
241  // This is a read operation. The member and subposet index maps
242  // don't exist yet. Can not translate to internal ids until
243  // the maps have been created when the members are read.
244  // Will translate to internal ids
245  // in poset_scaffold::translate_dof_tuple_col_bounds called
246  // from dof_tuple_record_set::internalize.
247  }
248 
249  // Postconditions:
250 
251  // Exit
252 
253  return;
254 }
255 
257 void
260 {
261  // Preconditions:
262 
263  require(scaffold().structure().state_is_read_accessible());
264 
265  // Body:
266 
267  poset_state_handle* lschema_host = scaffold().external_schema().host();
268 
271 
272  stringstream lstream;
273 
274  lstream << "Dof tuple col bounds:" << endl;
275 
276  poset_scaffold::dof_tuple_col_bounds_type::iterator itr;
277 
278  for(itr = scaffold().dof_tuple_col_bounds().begin();
279  itr != scaffold().dof_tuple_col_bounds().end();
280  itr++)
281  {
282  // Translate the bounds descriptor to external ids.
283 
284  poset_bounds_descriptor ldesc = itr->second;
285 
286 #ifdef DIAGNOSTIC_OUTPUT
287  cout << "before: "
288  << " mode: " << ldesc.mode()
289  << " lb: " << ldesc.lb_id()
290  << " ub: " << ldesc.ub_id()
291  << endl;
292 #endif
293 
294  pod_index_type lb_ext_id;
295  if(ldesc.lb_is_member())
296  {
297  lb_ext_id =
298  lschema_host->get_ext_id(ldesc.lb_id(),
300  false);
301  }
302  else
303  {
304  lb_ext_id = scaffold().subposet_ext_id(ldesc.lb_id()).hub_pod();
305  }
306  ldesc.put_lb_id(lb_ext_id);
307 
308  pod_index_type ub_ext_id;
309  if(ldesc.ub_is_member())
310  {
311  ub_ext_id =
312  lschema_host->get_ext_id(ldesc.ub_id(),
314  false);
315  }
316  else
317  {
318  ub_ext_id = scaffold().subposet_ext_id(ldesc.ub_id()).hub_pod();
319  }
320  ldesc.put_ub_id(ub_ext_id);
321 
322 #ifdef DIAGNOSTIC_OUTPUT
323  cout << "after: "
324  << " mode: " << ldesc.mode()
325  << " lb: " << ldesc.lb_id()
326  << " ub: " << ldesc.ub_id()
327  << endl;
328 #endif
329 
330  lstream << itr->first << " "
331  << poset_bounds_descriptor::mode_to_int(ldesc.mode()) << " "
332  << ldesc.lb_id() << " "
333  << ldesc.ub_id() << endl;
334  }
335 
336  // Have to copy stringstream to string
337  // because can't get C string from stringstream.
338 
339  _str_buf = lstream.str();
340 
341  put_is_internal(true);
342  put_is_external(false);
343 
344  // Postconditions:
345 
346  ensure(is_internal());
347  ensure(!is_external());
348 
349  // Exit
350 
351  return;
352 }
353 
354 
355 
356 
poset_state_handle * host() const
The poset which this is a handle to a component of.
static specification_mode int_to_mode(int xmode)
Converts int xmode to a mode.
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
void translate_dof_tuple_col_bounds()
Translate the dof tuple column bounds from external ids to internal ids.
bool ub_is_member() const
True if mode == MEMBER_MEMBER or SUBPOSET_MEMBER.
A client handle for a general, abstract partially order set.
dof_tuple_col_bounds_type & dof_tuple_col_bounds()
Dof tuple col bounds map (mutable version).
scoped_index subposet_ext_id(const scoped_index &xid) const
An id in the subposet external id space with pod mapped from xid.
STL namespace.
unordered::unordered_map< pod_index_type, poset_bounds_descriptor > dof_tuple_col_bounds_type
Type of dof tuple col bounds map.
pod_index_type ub_id() const
The index of the upper bound member, if the upper bound contains a single member. ...
void put_lb_id(pod_index_type xlb_id)
Sets the index of the lower bound to xlb_id.
virtual dof_tuple_col_bounds_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the poset.
static int mode_to_int(specification_mode xmode)
Converts mode xmode to an int.
std::string _str_buf
The internal/external buffer.
virtual pod_index_type get_ext_id(pod_index_type xint_id, const std::string &xid_space_name, bool xauto_access) const
Translates xint_id to an external id using the equivalence map with name xid_space_name.
bool is_internal() const
True if the internal buffer has been initialized.
pod_index_type lb_id() const
The index of the lower bound.
schema_poset_member & external_schema()
The schema of the poset in external namespace (mutable version).
void put_is_internal(bool xis_internal)
Sets is_internal to xis_internal.
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 transfer_internal_buffer_to_poset()
Initializes the poset from the internal buffer.
bool lb_is_member() const
True if mode == MEMBER_MEMBER or MEMBER_SUBPOSET.
A description of a (lower, upper) bounds pair for a poset. Specifies a portion of a poset for a bound...
A wrapper/adapter for the dof tuple column bounds record. Intended for transferring index-bounds map ...
pod_index_type pod_type
The "plain old data" storage type for this.
Definition: scoped_index.h:128
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
dof_tuple_col_bounds_record(poset_scaffold &xscaffold)
Creates an instance with type map xtype_map.
A poset specific collection of data converters, various buffers and other data used while transferrin...
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...
void put_ub_id(pod_index_type xub_id)
Sets the index of the upper bound to xub_id.
const std::string & file_id_space_name() const
The name of the id space used for the member index map.
specification_mode mode() const
Specification mode for this.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void put_is_external(bool xis_external)
Sets is_external to xis_external.