SheafSystem  0.0.0.0
dof_tuple_types_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_types_record
19 
20 #include "SheafSystem/dof_tuple_types_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 {
36  dof_tuple_types_record* result;
37 
38  // Preconditions:
39 
40  // Body:
41 
42  result = new dof_tuple_types_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_types_record*>(other) != 0;
103 
104  // Postconditions:
105 
106  return result;
107 
108 }
109 
110 
111 // =============================================================================
112 // DOF_TUPLE_TYPES_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 names into the scaffold name map.
199 
200  typedef poset_scaffold::dof_tuple_types_type map_type;
201  map_type& lmap = scaffold().dof_tuple_types();
202 
203  pod_index_type ltuple_id_pod;
204  dof_tuple_type ltype_id;
205  string ltype_name;
206  while(lstream >> ltuple_id_pod)
207  {
208  // Skip the space before the name
209 
210  lstream.ignore();
211 
212  // The name is the rest of the line,
213  // including possible leading or embedded white space.
214 
215  getline(lstream, ltype_name);
216 
217  // Get the type id from the name.
218 
219  ltype_id = dof_tuple_type_from_name(ltype_name);
220 
221  // Create the value and insert it into the dof tuple types.
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, ltype_id);
226  lmap.insert(lval);
227  }
228 
229  // Postconditions:
230 
231  // Exit
232 
233  return;
234 }
235 
237 void
240 {
241  // Preconditions:
242 
243  require(scaffold().structure().state_is_read_accessible());
244 
245  // Body:
246 
247  stringstream lstream;
248 
249  lstream << "Dof tuple types:" << endl;
250 
251  poset_scaffold::dof_tuple_types_type::const_iterator itr;
252 
253  for(itr = scaffold().dof_tuple_types().begin();
254  itr != scaffold().dof_tuple_types().end();
255  itr++)
256  {
257  lstream << itr->first << " " << itr->second << endl;
258  }
259 
260  // Have to copy stringstream to string
261  // because can't get C string from stringstream.
262 
263  _str_buf = lstream.str();
264 
265  put_is_internal(true);
266  put_is_external(false);
267 
268  // Postconditions:
269 
270  ensure(is_internal());
271  ensure(!is_external());
272 
273  // Exit
274 
275  return;
276 }
277 
278 
279 
280 
dof_tuple_types_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
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
dof_tuple_types_type & dof_tuple_types()
Dof tuple type ids (mutable version).
SHEAF_DLL_SPEC dof_tuple_type dof_tuple_type_from_name(const std::string &xname)
The enumerator with name xname.
virtual dof_tuple_types_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
STL namespace.
A wrapper/adapter for the dof type types record. Intended for transferring dof tuple type id data bet...
unordered::unordered_map< pod_index_type, dof_tuple_type > dof_tuple_types_type
Type of dof tuple types map.
virtual ~dof_tuple_types_record()
Destructor.
Abstract base class with useful features for all objects.
Definition: any.h:39
std::string _str_buf
The internal/external buffer.
virtual bool invariant() const
Class invariant.
bool is_internal() const
True if the internal buffer has been initialized.
dof_tuple_type
Identifiers for dof tuple types.
void transfer_internal_buffer_to_poset()
Initializes the poset from the internal buffer.
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
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.
void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the poset.
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.