SheafSystem  0.0.0.0
id_space_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 id_space_names_record
19 
20 #include "SheafSystem/id_space_names_record.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_space_family.h"
24 #include "SheafSystem/index_space_family_iterator.h"
25 #include "SheafSystem/index_space_interval.h"
26 #include "SheafSystem/scattered_insertion_index_space_handle.h"
27 #include "SheafSystem/scattered_insertion_index_space_state.h"
28 #include "SheafSystem/std_sstream.h"
29 
30 using namespace std;
31 
32 // =============================================================================
33 // ANY FACET
34 // =============================================================================
35 
36 
39 clone() const
40 {
41  id_space_names_record* result;
42 
43  // Preconditions:
44 
45  // Body:
46 
47  result = new id_space_names_record(*this);
48 
49  // Postconditions:
50 
51  ensure(result != 0);
52  ensure(is_same_type(result));
53 
54  // Exit:
55 
56  return result;
57 }
58 
59 
60 bool
62 invariant() const
63 {
64  bool result = true;
65 
66  // Preconditions:
67 
68  // Body:
69 
70  // Must satisfy base class invariant
71 
72  result = result && attributes_record::invariant();
73 
74  if(invariant_check())
75  {
76  // Prevent recursive calls to invariant
77 
78  disable_invariant_check();
79 
80  // Finished, turn invariant checking back on.
81 
82  enable_invariant_check();
83  }
84 
85  // Postconditions:
86 
87  // Exit
88 
89  return result;
90 }
91 
92 bool
94 is_ancestor_of(const any* other) const
95 {
96 
97  // Preconditions:
98 
99  require(other != 0);
100 
101  // Body:
102 
103  // True if other conforms to this
104 
105  bool result = dynamic_cast<const id_space_names_record*>(other) != 0;
106 
107  // Postconditions:
108 
109  return result;
110 
111 }
112 
113 // =============================================================================
114 // ID_SPACE_NAMES_RECORD FACET
115 // =============================================================================
116 
119  : attributes_record(xscaffold)
120 {
121 
122  // Preconditions:
123 
124 
125  // Body:
126 
127  // Postconditions:
128 
129  ensure(invariant());
130 
131  // Exit:
132 
133  return;
134 }
135 
138  : attributes_record(xother)
139 {
140 
141  // Preconditions:
142 
143  // Body:
144 
145  not_implemented();
146 
147  // Postconditions:
148 
149  ensure(invariant());
150 }
151 
154 {
155 
156  // Preconditions:
157 
158  // Body:
159 
160  // Nothing specific to do.
161 
162  // Postconditions:
163 
164  // Exit:
165 
166  return;
167 }
168 
169 // =============================================================================
170 // PROTECTED MEMBER FUNCTIONS
171 // =============================================================================
172 
173 void
176 {
177  // Preconditions:
178 
179  require(is_internal());
180  require(scaffold().structure().state_is_read_write_accessible());
181 
182  // Body:
183 
184  // Initialize the stream.
185 
186  stringstream lstream(_str_buf);
187 
188  // Skip the header line:
189 
190  lstream.ignore(numeric_limits<streamsize>::max(), '\n');
191 
192  // Transfer the names to the poset.
193 
194  // It is essential that the names be assigned to id spaces
195  // in the same order they appear in the file because the
196  // id equivalences in the member records use these id_space values.
197 
198  // In particular, it is important to create the id spaces before
199  // initialize the member index map, otherwise the file id space
200  // will be created out of order.
201 
206 
207  poset_state_handle& lposet = scaffold().structure();
208  size_type lid_space_ext_id;
209  string lid_space_class_name, lid_space_name;
210 
211  while(lstream >> lid_space_ext_id)
212  {
213  // Skip the space before the class name.
214 
215  lstream.ignore();
216 
217  // Get the class name.
218 
219  lstream >> lid_space_class_name;
220 
221  // Skip the space before the name
222 
223  lstream.ignore();
224 
225  // The name is the rest of the line,
226  // including possible leading or embedded white space.
227 
228  getline(lstream, lid_space_name);
229 
230  if(!lposet.member_id_spaces(false).contains(lid_space_name))
231  {
232  // Create an id space with that name.
233 
234  lposet.member_id_spaces(false).new_state(lid_space_name, lid_space_class_name);
235 
236  if(lposet.includes_subposet(lid_space_name))
237  {
238  // A subposet with same name exists, assume this is the
239  // id space for the subposet. Attach the subposet to it.
240 
241  subposet lsp(&lposet, lid_space_name);
242  if(!lsp.has_id_space())
243  {
244  lsp.attach_id_space();
245  }
246  }
247  }
248 
250 
253 
254  scaffold().id_spaces().force_item(lid_space_ext_id, lid_space);
255  }
256 
257  // Now we can initialize the member id space.
258 
260 
261  // Postconditions:
262 
263  // Exit
264 
265  return;
266 }
267 
268 void
271 {
272  // Preconditions:
273 
274  require(scaffold().structure().state_is_read_accessible());
275 
276  // Body:
277 
278  stringstream lstream;
279 
280  lstream << "Id space names:" << endl;
281 
282  // Put the names for the persistent, mutsable id spaces in the file.
283 
284  poset_state_handle& lposet = scaffold().structure();
285  index_space_family_iterator litr(lposet.member_id_spaces(false), true);
286  while(!litr.is_done())
287  {
289 
291 
294 
295  lstream << lid_space.index()
296  << " " << lid_space.state().class_name()
297  << " " << lid_space.name()
298  << endl;
299 
300  lid_space.release_id_space();
301 
302  litr.next();
303  }
304 
305  // Have to copy stringstream to string
306  // because can't get C string from stringstream.
307 
308  _str_buf = lstream.str();
309 
310  put_is_internal(true);
311  put_is_external(false);
312 
313  // Postconditions:
314 
315  ensure(is_internal());
316  ensure(!is_external());
317 
318  // Exit
319 
320  return;
321 }
322 
323 
324 
id_spaces_type & id_spaces()
Buffer for id spaces (mutable version).
scattered_insertion_index_space_state & state()
The mutable id space state (mutable version).
A client handle for a subposet.
Definition: subposet.h:86
virtual void transfer_internal_buffer_to_poset()
Initializes member with index xmbr_id from the internal buffer.
virtual pod_type index() const
Index of this space.
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
virtual id_space_names_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
virtual bool has_id_space() const
True if this already has an id space.
Definition: subposet.cc:622
id_space_names_record(poset_scaffold &xscaffold)
Creates an instance with type map xtype_map.
virtual ~id_space_names_record()
Destructor.
A client handle for a general, abstract partially order set.
virtual bool includes_subposet(pod_index_type xsubposet_hub_id, bool xauto_access=true) const
True if this poset includes subposet with hub id xsubposet_hub_id.
index_space_handle & get_id_space(const std::string &xname) const
Allocates an id space handle from the handle pool attached to state with name xname.
void force_item(index_type xindex, const_reference_type xitem)
Puts the item xitem at index xindex, resizing if necessary; any other new storage allocated is uninit...
const index_space_family & member_id_spaces(bool xauto_access) const
Collection of member id spaces for this (const version).
STL namespace.
virtual void release_id_space() const
Returns this id space handle to the handle pool.
An abstract iterator over the id spaces of a interval.
Abstract base class with useful features for all objects.
Definition: any.h:39
bool handle_conforms_to_state(const std::string &xname) const
True if handle of type T conforms to the state with name xname.
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.
std::string name() const
Name of this space.
bool is_internal() const
True if the internal buffer has been initialized.
A wrapper/adapter for the id space names record. Intended for transferring id map data between the ke...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
void new_state(const std::string &xname, const std::string &xstate_class_name)
Create a new id space with class type xstate_class_name and name xname. Used by the I/O system to rea...
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
poset_state_handle & structure()
The handle for the poset being transferred. (Name chosen to void name conflict with class poset...
void attach_id_space()
Attach the id space to the id_space_name().
Definition: subposet.cc:714
A handle for a scattered_insertion_index_space_state.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
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...
virtual void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the member with index xmbr_id.
virtual const std::string & class_name() const
The name of this class.
virtual bool invariant() const
Class invariant.
void put_is_external(bool xis_external)
Sets is_external to xis_external.
void initialize_member_id_space()
Initializes member_id_space().