SheafSystem  0.0.0.0
dof_tuple_schema_ids_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_schema_ids_record
19 
20 #include "SheafSystem/dof_tuple_schema_ids_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_schema_ids_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_schema_ids_record*>(other) != 0;
103 
104  // Postconditions:
105 
106  return result;
107 
108 }
109 
110 
111 // =============================================================================
112 // DOF_TUPLE_SCHEMA_IDS_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 schema ids into the scaffold name map.
199 
201  map_type& lmap = scaffold().dof_tuple_schema_ids();
202 
203  pod_index_type ltuple_id_pod;
204  pod_index_type lschema_id_pod;
205 
206  while(lstream >> ltuple_id_pod)
207  {
208  // Read the schema id.
209 
210  lstream >> lschema_id_pod;
211 
212  // Put the result in the map.
213  // Implicitly converts ltuple_id_pod to unscoped scoped_index,
214  // which is what we want, for now.
215 
216  map_type::value_type lval(ltuple_id_pod, lschema_id_pod);
217  lmap.insert(lval);
218  }
219 
220  // Postconditions:
221 
222  // Exit
223 
224  return;
225 }
226 
228 void
231 {
232  // Preconditions:
233 
234  require(scaffold().structure().state_is_read_accessible());
235 
236  // Body:
237 
238  stringstream lstream;
239 
240  lstream << "Dof tuple schema ids:" << endl;
241 
242  poset_scaffold::dof_tuple_schema_ids_type::iterator itr;
243 
244  for(itr = scaffold().dof_tuple_schema_ids().begin();
245  itr != scaffold().dof_tuple_schema_ids().end();
246  itr++)
247  {
248  lstream << itr->first << " " << itr->second << endl;
249  }
250 
251  // Have to copy stringstream to string
252  // because can't get C string from stringstream.
253 
254  _str_buf = lstream.str();
255 
256  put_is_internal(true);
257  put_is_external(false);
258 
259  // Postconditions:
260 
261  ensure(is_internal());
262  ensure(!is_external());
263 
264  // Exit
265 
266  return;
267 }
268 
269 
270 
271 
dof_tuple_schema_ids_record(poset_scaffold &xscaffold)
Creates an instance with type map xtype_map.
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
STL namespace.
void transfer_internal_buffer_to_poset()
Initializes the poset from the internal buffer.
unordered::unordered_map< pod_index_type, pod_index_type > dof_tuple_schema_ids_type
Type of dof tuple schema ids map.
virtual dof_tuple_schema_ids_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
Abstract base class with useful features for all objects.
Definition: any.h:39
A wrapper/adapter for the dof tuple schema ids record. Intended for transferring index-id map data be...
std::string _str_buf
The internal/external buffer.
bool is_internal() const
True if the internal buffer has been initialized.
virtual bool invariant() const
Class invariant.
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
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the poset.
dof_tuple_schema_ids_type & dof_tuple_schema_ids()
Dof tuple schema ids (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
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_is_external(bool xis_external)
Sets is_external to xis_external.