SheafSystem  0.0.0.0
variable_length_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 variable_length_record
19 
20 #include "SheafSystem/variable_length_record.h"
21 
22 #include "SheafSystem/record_index.h"
23 #include "SheafSystem/assert_contract.h"
24 
25 // PUBLIC MEMBER FUNCTIONS
26 
27 // CANONICAL MEMBERS
28 
29 // Copy constructor
33  : record(xother),
34  _buf(xother._buf),
35  _buf_ub(xother._buf_ub),
36  _delete_buffer(xother._delete_buffer)
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  variable_length_record* result;
59 
60  // Preconditions:
61 
62  // Body:
63 
64  result = new variable_length_record(*this);
65 
66  // Postconditions:
67 
68  ensure(result != 0);
69  ensure(is_same_type(result));
70 
71  // Exit:
72 
73  return result;
74 }
75 
76 
77 // Destructor
81 {
82 
83  // Preconditions:
84 
85  // Body:
86 
87  if(_delete_buffer)
88  {
89  delete[] static_cast<char*>(_buf);
90  }
91 
92 
93  // Postconditions:
94 
95  // Exit:
96 
97  return;
98 }
99 
100 
101 // Class invariant
103 bool
105 invariant() const
106 {
107  bool result = true;
108 
109  // Preconditions:
110 
111  // Body:
112 
113  // Must satisfy base class invariant
114 
115  result = result && record::invariant();
116 
117  if(invariant_check())
118  {
119  // Prevent recursive calls to invariant
120 
122 
123  // Finished, turn invariant checking back on.
124 
126  }
127 
128  // Postconditions:
129 
130  // Exit
131 
132  return result;
133 }
134 
135 // Conformance test
137 bool
139 is_ancestor_of(const any* other) const
140 {
141 
142  // Preconditions:
143 
144  require(other != 0);
145 
146  // Body:
147 
148  // True if other conforms to this
149 
150  bool result = dynamic_cast<const variable_length_record*>(other) != 0;
151 
152  // Postconditions:
153 
154  return result;
155 
156 }
157 
158 
159 
160 // VARIABLE_LENGTH_RECORD INTERFACE
161 
162 
163 
167  : record(xscaffold)
168 {
169  // Preconditions:
170 
171  // Body:
172 
173  _buf = 0;
174  _buf_ub = 0;
175  _delete_buffer = false;
176  _is_internal = false;
177  _is_external = false;
178 
179  // Postconditions:
180 
181  ensure(invariant());
182 
183  ensure(!external_index().is_valid());
184  ensure(&(scaffold()) == &xscaffold);
185  ensure(buf() == 0);
186  ensure(buf_ub() == 0);
187  ensure(!delete_buffer());
188  ensure(!is_internal());
189  ensure(!is_external());
190 
191  // Exit
192 
193  return;
194 }
195 
196 
197 
199 void*
201 buf() const
202 {
203  void* result;
204 
205  // Preconditions:
206 
207  // Body:
208 
209  result = _buf;
210 
211  // Postconditions:
212 
213  // Exit:
214 
215  return result;
216 }
217 
218 
219 
221 size_t
223 buf_ub() const
224 {
225  size_t result;
226 
227  // Preconditions:
228 
229  // Body:
230 
231  result = _buf_ub;
232 
233  // Postconditions:
234 
235  // Exit:
236 
237  return result;
238 }
239 
241 void
243 put_buf(const void* xbuf, size_t xbuf_ub)
244 {
245  // Preconditions:
246 
247  require((xbuf == 0) == (xbuf_ub == 0));
248  require(unexecutable(xuf_ub == allocated size of xbuf));
249 
250  // Body:
251 
252  _buf = const_cast<void *>(xbuf);
253  _buf_ub = xbuf_ub;
254 
255  // Postconditions:
256 
257  ensure(buf() == xbuf);
258  ensure(buf_ub() == xbuf_ub);
259 
260  // Exit
261 
262  return;
263 }
264 
virtual bool invariant() const
Class invariant.
virtual ~variable_length_record()
Destructor.
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
virtual bool invariant() const
Class invariant.
Definition: record.cc:95
void * buf() const
The buffer.
bool delete_buffer()
True if this allocated the buffer and the dtor should delete it.
The general variable length record wrapper/adapter for transferring data between the kernel and the i...
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
record_index external_index() const
The external index of this record.
Definition: record.h:94
void put_buf(const void *xbuf, size_t xub)
Sets the buffer to xbuf.
Abstract base class with useful features for all objects.
Definition: any.h:39
variable_length_record(const variable_length_record &xother)
Copy constructor.
size_t buf_ub() const
The size of the buffer, in bytes.
bool is_internal() const
True if the internal buffer has been initialized.
The general variable length record wrapper/adapter for transferring data between the kernel and the i...
Definition: record.h:48
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual variable_length_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
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.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
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