SheafSystem  0.0.0.0
member_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_names_record
19 
20 #include "SheafSystem/member_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 {
36  member_names_record* result;
37 
38  // Preconditions:
39 
40  // Body:
41 
42  result = new member_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 member_names_record*>(other) != 0;
103 
104  // Postconditions:
105 
106  return result;
107 
108 }
109 
110 
111 // =============================================================================
112 // MEMBER_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  record_index::pod_type lmbr_id_pod;
202  string lname;
203  while(lstream >> lmbr_id_pod)
204  {
205  // Skip the space before the name
206 
207  lstream.ignore();
208 
209  // The name is the rest of the line,
210  // including possible leading or embedded white space.
211 
212  getline(lstream, lname);
213 
214  // Put the result in the map.
215 
216  lname_map.put_entry(lmbr_id_pod, lname, false);
217  }
218 
219  // Postconditions:
220 
221  // Exit
222 
223  return;
224 }
225 
227 void
230 {
231  // Preconditions:
232 
233  require(scaffold().structure().state_is_read_accessible());
234 
235  // Body:
236 
237  stringstream lstream;
238 
239  lstream << "Member names:" << endl;
240 
241 
244 
245  for(itr = lname_map.begin();
246  itr != lname_map.end();
247  itr++)
248  {
249  const poset_scaffold::member_name_map_type::name_list_type& lnames = itr->second;
251  while(lname_itr != lnames.end())
252  {
253  lstream << itr->first << " " << *lname_itr << endl;
254  ++lname_itr;
255  }
256  }
257 
258  // Have to copy stringstream to string
259  // because can't get C string from stringstream.
260 
261  _str_buf = lstream.str();
262 
263  put_is_internal(true);
264  put_is_external(false);
265 
266  // Postconditions:
267 
268  ensure(is_internal());
269  ensure(!is_external());
270 
271  // Exit
272 
273  return;
274 }
275 
276 
277 
278 
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the poset.
const_iterator begin() const
The initial value for iterators over this map.
virtual ~member_names_record()
Destructor.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
name_list_type::const_iterator const_name_iterator
The const iterator type for names.
Definition: name_multimap.h:97
std::list< std::string > name_list_type
The type of name list for this map.
Definition: name_multimap.h:87
A partial multi-valued relation with total injective inverse between names and indices of type index_...
Definition: name_multimap.h:63
STL namespace.
const_iterator end() const
The final value for iterators over this map.
Abstract base class with useful features for all objects.
Definition: any.h:39
std::string _str_buf
The internal/external buffer.
void transfer_internal_buffer_to_poset()
Initializes the poset from the internal buffer.
A wrapper/adapter for the member names record. Intended for transferring index-name map data between ...
bool is_internal() const
True if the internal buffer has been initialized.
member_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
virtual member_names_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
member_name_map_type & member_name_map()
External index to member name map (mutable version).
pod_index_type pod_type
The "plain old data" storage type for this.
Definition: scoped_index.h:128
void put_entry(const entry_type &xentry, bool xunique)
Sets (xindex, xname) as an entry in the map. If xunique, deletes all other entries for xindex...
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...
std::map< index_type, name_list_type >::const_iterator const_iterator
The const iterator type for this map.
virtual bool invariant() const
Class invariant.
void put_is_external(bool xis_external)
Sets is_external to xis_external.