SheafSystem  0.0.0.0
attributes_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 attributes_record
19 
20 #include "SheafSystem/attributes_record.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/namespace_poset.h"
24 #include "SheafSystem/poset.h"
25 
26 using namespace std;
27 
28 // PUBLIC MEMBER FUNCTIONS
29 
30 // CANONICAL MEMBERS
31 
32 // Copy constructor
36  : variable_length_record(xother)
37 {
38 
39  // Preconditions:
40 
41  // Body:
42 
43  not_implemented();
44 
45  // Postconditions:
46 
47  ensure(invariant());
48 }
49 
50 
51 
52 // Virtual constructor
56 clone() const
57 {
58  attributes_record* result = 0;
59 
60  // Preconditions:
61 
62  // Body:
63 
64  is_abstract();
65 
66 
67  // Postconditions:
68 
69  ensure(result != 0);
70  ensure(is_same_type(result));
71 
72  // Exit:
73 
74  return result;
75 }
76 
77 
78 // Destructor
82 {
83 
84  // Preconditions:
85 
86  // Body:
87 
88  // Postconditions:
89 
90  // Exit:
91 
92  return;
93 }
94 
95 
96 // Class invariant
98 bool
100 invariant() const
101 {
102  bool result = true;
103 
104  // Preconditions:
105 
106  // Body:
107 
108  // Must satisfy base class invariant
109 
110  invariance(variable_length_record::invariant());
111 
112  if(invariant_check())
113  {
114  // Prevent recursive calls to invariant
115 
117 
118  // Finished, turn invariant checking back on.
119 
121  }
122 
123  // Postconditions:
124 
125  // Exit
126 
127  return result;
128 }
129 
130 // Conformance test
132 bool
134 is_ancestor_of(const any* other) const
135 {
136 
137  // Preconditions:
138 
139  require(other != 0);
140 
141  // Body:
142 
143  // True if other conforms to this
144 
145  bool result = dynamic_cast<const attributes_record*>(other) != 0;
146 
147  // Postconditions:
148 
149  return result;
150 
151 }
152 
153 
154 
155 // ATTRIBUTES_RECORD INTERFACE
156 
157 
161  : variable_length_record(xscaffold)
162 {
163 
164  // Preconditions:
165 
166 
167  // Body:
168 
169  // Postconditions:
170 
171  ensure(invariant());
172 
173  // Exit:
174 
175  return;
176 }
177 
178 
180 void
183 {
184 
185  // Preconditions:
186 
187  require(!scaffold().structure().is_external() ? scaffold().structure().state_is_read_write_accessible() : true);
188 
189  // Body:
190 
191  // Initialize the external buffer from the HDF buffer.
192 
193  transfer_HDF_to_external_buffer(xhdf_buffer);
194 
195  // Convert the external buffer to internal format
196  // and place the result in the internal buffer
197 
199 
200  // Transfer the internal buffer to the poset scaffold.
201 
203 
204  // Postconditions:
205 
206  ensure(is_internal());
207 
208  // Exit
209 
210  return ;
211 }
212 
213 
215 void
218 {
219 
220  // Preconditions:
221 
222  require(scaffold().structure().state_is_read_accessible());
223 
224  // Body:
225 
226  // Initialize the internal buffer.
227 
229 
230  // Convert the internal buffer to external form
231  // and place the result in the external buffer.
232 
234 
235  // Transfer the external buffer to HDF
236 
237  transfer_external_buffer_to_HDF(xhdf_buffer);
238 
239  // Postconditions:
240 
241  ensure(is_external());
242 
243  // Exit
244 
245  return;
246 }
247 
248 
249 
251 void
254 {
255  // Preconditions:
256 
257  require(xbuf != 0);
258 
259  // Body:
260 
265 
266  put_buf(*xbuf, strlen(*xbuf));
267 
268  put_is_external(true);
269  put_is_internal(false);
270 
271  // Postconditions:
272 
273  ensure(buf() == *xbuf);
274  ensure(buf_ub() == strlen(*xbuf));
275  ensure(is_external());
276  ensure(!is_internal());
277 
278  // Exit
279 
280  return;
281 }
282 
283 
285 void
288 {
289  // Preconditions:
290 
291  require(xbuf != 0);
292  require(is_external());
293 
294  // Body:
295 
300 
301  *xbuf = reinterpret_cast<hdf_buf_type>(buf());
302 
303  // Postconditions:
304 
305  ensure(*xbuf == buf());
306 
307  // Exit
308 
309  return;
310 }
311 
312 
314 void
317 {
318  // Preconditions:
319 
320  require(is_internal());
321  require(!scaffold().structure().is_external() ?
322  scaffold().structure().state_is_read_write_accessible() :
323  true);
324  require(scaffold().name_space()->state_is_read_accessible());
325 
326 
327  // Body:
328 
329  is_abstract();
330 
331  // Postconditions:
332 
333  ensure(scaffold().internal_schema().is_attached());
334  ensure(scaffold().transfer_schema().is_attached());
335  ensure(scaffold().external_schema().is_attached());
336 
337  // Exit
338 
339  return;
340 }
341 
342 
343 
345 void
348 {
349  // Preconditions:
350 
351  require(scaffold().structure().state_is_read_accessible());
352 
353  // Body:
354 
355  is_abstract();
356 
357  // Postconditions:
358 
359  ensure(is_internal());
360  ensure(!is_external());
361 
362  // Exit
363 
364  return;
365 }
366 
368 void
371 {
372  // Preconditions:
373 
374  require(is_external());
375 
376  // Body:
377 
378 
379  _str_buf.append(static_cast<char *>(buf()), buf_ub());
380 
381  put_is_internal(true);
382 
383  // Postconditions:
384 
385  ensure(invariant());
386  ensure(is_internal());
387 
388  // Exit
389 
390  return;
391 }
392 
393 
395 void
398 {
399  // Preconditions:
400 
401  require(is_internal());
402 
403  // Body:
404 
405  // "External" buffer is C string of internal buffer.
406 
407  put_buf(_str_buf.c_str(), _str_buf.size());
408  put_delete_buffer(false);
409  put_is_external(true);
410 
411  // Postconditions:
412 
413  ensure(invariant());
414  ensure(is_external());
415 
416  // Exit
417 
418  return;
419 }
420 
421 // PRIVATE MEMBER FUNCTIONS
virtual attributes_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
virtual bool invariant() const
Class invariant.
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
void externalize(hdf_buf_type *xhdf_buffer)
Converts the record from internal to external form.
void * buf() const
The buffer.
void convert_internal_buffer_to_external_buffer()
Converts the internal buffer to external form and places the result in the external buffer...
virtual bool invariant() const
Class invariant.
virtual void transfer_internal_buffer_to_poset()=0
Initializes scaffold from the internal buffer.
virtual void transfer_poset_to_internal_buffer()=0
Initializes the internal buffer from the scaffold.
STL namespace.
The general variable length record wrapper/adapter for transferring data between the kernel and the i...
void put_delete_buffer(bool xval)
Sets delete_buffer to value xval.
void put_buf(const void *xbuf, size_t xub)
Sets the buffer to xbuf.
void internalize(hdf_buf_type *xhdf_buffer)
Converts the record from external to internal form.
Abstract base class with useful features for all objects.
Definition: any.h:39
std::string _str_buf
The internal/external buffer.
size_t buf_ub() const
The size of the buffer, in bytes.
char * hdf_buf_type
The type of hdf buffer.
bool is_internal() const
True if the internal buffer has been initialized.
void transfer_HDF_to_external_buffer(hdf_buf_type *xbuf)
Initializes the external buffer from xbuf.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void convert_external_buffer_to_internal_buffer()
Converts the external buffer to internal form and places the result in the internal buffer...
void put_is_internal(bool xis_internal)
Sets is_internal to xis_internal.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
attributes_record(const attributes_record &xother)
Copy constructor.
virtual ~attributes_record()
Destructor.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
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...
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
void transfer_external_buffer_to_HDF(hdf_buf_type *xbuf)
Initializes the HDF buffer xbuf from the external buffer.
void put_is_external(bool xis_external)
Sets is_external to xis_external.