SheafSystem  0.0.0.0
member_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 member_class_names_record
19 
20 #include "SheafSystem/member_class_names_record.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/std_sstream.h"
24 
25 using namespace std;
26 
27 //#define DIAGNOSTIC_OUTPUT
28 
29 // =============================================================================
30 // ANY FACET
31 // =============================================================================
32 
36 clone() const
37 {
39 
40  // Preconditions:
41 
42  // Body:
43 
44  result = new member_class_names_record(*this);
45 
46  // Postconditions:
47 
48  ensure(result != 0);
49  ensure(is_same_type(result));
50 
51  // Exit:
52 
53  return result;
54 }
55 
57 bool
59 invariant() const
60 {
61  bool result = true;
62 
63  // Preconditions:
64 
65  // Body:
66 
67  // Must satisfy base class invariant
68 
69  result = result && attributes_record::invariant();
70 
71  if(invariant_check())
72  {
73  // Prevent recursive calls to invariant
74 
75  disable_invariant_check();
76 
77  // Finished, turn invariant checking back on.
78 
79  enable_invariant_check();
80  }
81 
82  // Postconditions:
83 
84  // Exit
85 
86  return result;
87 }
88 
90 bool
92 is_ancestor_of(const any* other) const
93 {
94 
95  // Preconditions:
96 
97  require(other != 0);
98 
99  // Body:
100 
101  // True if other conforms to this
102 
103  bool result = dynamic_cast<const member_class_names_record*>(other) != 0;
104 
105  // Postconditions:
106 
107  return result;
108 
109 }
110 
111 // =============================================================================
112 // MEMBER_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 
155 {
156 
157  // Preconditions:
158 
159  // Body:
160 
161  // Nothing specific to do.
163 
164  // Postconditions:
165 
166  // Exit:
167 
168  return;
169 }
170 
171 // =============================================================================
172 // PROTECTED MEMBER FUNCTIONS
173 // =============================================================================
174 
176 void
179 {
180  // Preconditions:
181 
182  require(is_internal());
183  require(scaffold().structure().state_is_read_write_accessible());
184 
185  // Body:
186 
187  // Initialize the stream.
188 
189  stringstream lstream(_str_buf);
190 
191  // Skip the header line:
192 
193  lstream.ignore(numeric_limits<streamsize>::max(), '\n');
194 
195  // Transfer the names into the scaffold name map.
196 
198  typedef map_type::mapped_type mapped_type;
199 
200  map_type& lclass_name_map = scaffold().member_class_names();
201 
202  pod_index_type lmbr_id_pod;
203 
204  while(lstream >> lmbr_id_pod)
205  {
206  mapped_type lmapped;
207 
208  // Skip the space before the name
209 
210  lstream.ignore();
211 
212  // Get the class name.
213 
214  lstream >> lmapped.first;
215 
216  // Get the size
217 
218  lstream >> lmapped.second;
219 
220  // Put the result in the map.
221 
222  lclass_name_map[lmbr_id_pod] = lmapped;
223  }
224 
225  // Postconditions:
226 
227  // Exit
228 
229  return;
230 }
231 
233 void
236 {
237  // Preconditions:
238 
239  require(scaffold().structure().state_is_read_accessible());
240 
241  // Body:
242 
243 #ifdef DIAGNOSTIC_OUTPUT
244  cout << "member_class_names_record::transfer_poset_to_internal_buffer" << endl;
245 #endif
246 
247  stringstream lstream;
248 
249 #ifdef DIAGNOSTIC_OUTPUT
250  cout << "Member class names:" << endl;
251 #endif
252 
253 
254  lstream << "Member class names:" << endl;
255 
257  poset_scaffold::member_class_names_type::iterator itr;
258 
259  for(itr = lclass_names_map.begin();
260  itr != lclass_names_map.end();
261  itr++)
262  {
263 #ifdef DIAGNOSTIC_OUTPUT
264  cout << itr->first << " " << itr->second.first << " " << itr->second.second << endl;
265 #endif
266 
267  lstream << itr->first << " " << itr->second.first << " " << itr->second.second << endl;
268  }
269 
270  // Have to copy stringstream to string
271  // because can't get C string from stringstream.
272 
273  _str_buf = lstream.str();
274 
275  put_is_internal(true);
276  put_is_external(false);
277 
278  // Postconditions:
279 
280  ensure(is_internal());
281  ensure(!is_external());
282 
283  // Exit
284 
285  return;
286 }
287 
288 
289 
290 
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
STL namespace.
member_class_names_record(poset_scaffold &xscaffold)
Creates an instance with type map xtype_map.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
std::string _str_buf
The internal/external buffer.
void transfer_internal_buffer_to_poset()
Initializes the poset from the internal buffer.
bool is_internal() const
True if the internal buffer has been initialized.
virtual member_class_names_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
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
member_class_names_type & member_class_names()
Member class names (mutable version).
A wrapper/adapter for the member class names record. Intended for transferring index-name map data be...
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.
unordered::unordered_map< pod_index_type, std::pair< std::string, size_type > > member_class_names_type
Type of member class names map.
An abstract wrapper/adapter for attributes records. Intended for transferring data between the kernel...
virtual bool invariant() const
Class invariant.
void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the poset.
void put_is_external(bool xis_external)
Sets is_external to xis_external.