SheafSystem  0.0.0.0
dof_tuple_class_names_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_class_names_record
19 
20 #include "SheafSystem/dof_tuple_class_names_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_class_names_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_class_names_record*>(other) != 0;
103 
104  // Postconditions:
105 
106  return result;
107 
108 }
109 
110 
111 // =============================================================================
112 // DOF_TUPLE_CLASS_NAMES_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 
201  map_type& lmap = scaffold().dof_tuple_class_names();
202 
203  pod_index_type ltuple_id_pod;
204  string lclass_name;
205  while(lstream >> ltuple_id_pod)
206  {
207  // Skip the space before the name
208 
209  lstream.ignore();
210 
211  // The name is the rest of the line,
212  // including possible leading or embedded white space.
213 
214  getline(lstream, lclass_name);
215 
216  // Put the result in the map.
217  // Implicitly converts ltuple_id_pod to unscoped scoped_index,
218  // which is what we want, for now.
219 
220  map_type::value_type lval(ltuple_id_pod, lclass_name);
221  lmap.insert(lval);
222  }
223 
224  // Postconditions:
225 
226  // Exit
227 
228  return;
229 }
230 
232 void
235 {
236  // Preconditions:
237 
238  require(scaffold().structure().state_is_read_accessible());
239 
240  // Body:
241 
242  stringstream lstream;
243 
244  lstream << "Dof tuple class names:" << endl;
245 
248  poset_scaffold::dof_tuple_class_names_type::iterator itr;
249 
250  for(itr = lclass_names_map.begin();
251  itr != lclass_names_map.end();
252  itr++)
253  {
254  lstream << itr->first << " " << itr->second << endl;
255  }
256 
257  // Have to copy stringstream to string
258  // because can't get C string from stringstream.
259 
260  _str_buf = lstream.str();
261 
262  put_is_internal(true);
263  put_is_external(false);
264 
265  // Postconditions:
266 
267  ensure(is_internal());
268  ensure(!is_external());
269 
270  // Exit
271 
272  return;
273 }
274 
275 
276 
277 
virtual dof_tuple_class_names_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
A wrapper/adapter for the dof tuple class names record. Intended for transferring index-name map data...
unordered::unordered_map< pod_index_type, std::string > dof_tuple_class_names_type
Type of dof tuple class names map.
STL namespace.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual bool invariant() const
Class invariant.
dof_tuple_class_names_type & dof_tuple_class_names()
Dof tuple class names (mutable version).
Abstract base class with useful features for all objects.
Definition: any.h:39
std::string _str_buf
The internal/external buffer.
bool is_internal() const
True if the internal buffer has been initialized.
dof_tuple_class_names_record(poset_scaffold &xscaffold)
Creates an instance with type map xtype_map.
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
void transfer_internal_buffer_to_poset()
Initializes the poset from the internal buffer.
void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the poset.
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.