Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | |||
29 | #include "gate/streams.hpp" | ||
30 | #include "gate/memalloc.hpp" | ||
31 | #include "gate/results.hpp" | ||
32 | #include "gate/exceptions.hpp" | ||
33 | #include "gate/synchronization.h" | ||
34 | |||
35 | namespace gate | ||
36 | { | ||
37 | |||
38 | ✗ | IStream::~IStream() | |
39 | { | ||
40 | |||
41 | ✗ | } | |
42 | |||
43 | ✗ | IStreamBuilder::~IStreamBuilder() | |
44 | { | ||
45 | ✗ | } | |
46 | |||
47 | |||
48 | ✗ | result_t IStreamBuilder::stream_read(void* this_ptr, char* buffer, gate_size_t bufferlength, gate_size_t* returned) | |
49 | { | ||
50 | ✗ | cpp_object* obj = static_cast<cpp_object*>(this_ptr); | |
51 | ✗ | IStreamBuilder* builder = static_cast<IStreamBuilder*>(obj->parent); | |
52 | try | ||
53 | { | ||
54 | ✗ | size_t bytes_returned = builder->read(buffer, bufferlength); | |
55 | ✗ | if (returned) | |
56 | { | ||
57 | ✗ | *returned = bytes_returned; | |
58 | } | ||
59 | ✗ | return results::Ok; | |
60 | } | ||
61 | ✗ | catch (Throwable const& th) | |
62 | { | ||
63 | ✗ | return th.getResult(); | |
64 | } | ||
65 | ✗ | catch (...) | |
66 | { | ||
67 | ✗ | return results::UnknownException; | |
68 | } | ||
69 | } | ||
70 | ✗ | result_t IStreamBuilder::stream_peek(void* this_ptr, char* buffer, gate_size_t bufferlength, gate_size_t* returned) | |
71 | { | ||
72 | ✗ | cpp_object* obj = static_cast<cpp_object*>(this_ptr); | |
73 | ✗ | IStreamBuilder* builder = static_cast<IStreamBuilder*>(obj->parent); | |
74 | try | ||
75 | { | ||
76 | ✗ | size_t bytes_returned = builder->peek(buffer, bufferlength); | |
77 | ✗ | if (returned) | |
78 | { | ||
79 | ✗ | *returned = bytes_returned; | |
80 | } | ||
81 | ✗ | return results::Ok; | |
82 | } | ||
83 | ✗ | catch (Throwable const& th) | |
84 | { | ||
85 | ✗ | return th.getResult(); | |
86 | } | ||
87 | ✗ | catch (...) | |
88 | { | ||
89 | ✗ | return results::UnknownException; | |
90 | } | ||
91 | } | ||
92 | ✗ | result_t IStreamBuilder::stream_write(void* this_ptr, char const* buffer, gate_size_t bufferlength, gate_size_t* written) | |
93 | { | ||
94 | ✗ | cpp_object* obj = static_cast<cpp_object*>(this_ptr); | |
95 | ✗ | IStreamBuilder* builder = static_cast<IStreamBuilder*>(obj->parent); | |
96 | try | ||
97 | { | ||
98 | ✗ | size_t bytes_written = builder->write(buffer, bufferlength); | |
99 | ✗ | if (written) | |
100 | { | ||
101 | ✗ | *written = bytes_written; | |
102 | } | ||
103 | ✗ | return results::Ok; | |
104 | } | ||
105 | ✗ | catch (Throwable const& th) | |
106 | { | ||
107 | ✗ | return th.getResult(); | |
108 | } | ||
109 | ✗ | catch (...) | |
110 | { | ||
111 | ✗ | return results::UnknownException; | |
112 | } | ||
113 | } | ||
114 | ✗ | result_t IStreamBuilder::stream_flush(void* this_ptr) | |
115 | { | ||
116 | ✗ | cpp_object* obj = static_cast<cpp_object*>(this_ptr); | |
117 | ✗ | IStreamBuilder* builder = static_cast<IStreamBuilder*>(obj->parent); | |
118 | try | ||
119 | { | ||
120 | ✗ | builder->flush(); | |
121 | ✗ | return results::Ok; | |
122 | } | ||
123 | ✗ | catch (Throwable const& th) | |
124 | { | ||
125 | ✗ | return th.getResult(); | |
126 | } | ||
127 | ✗ | catch (...) | |
128 | { | ||
129 | ✗ | return results::UnknownException; | |
130 | } | ||
131 | } | ||
132 | |||
133 | 8 | IStreamBuilder::VtblStream::VtblStream() | |
134 | { | ||
135 | 8 | GATE_INTERFACE_VTBL(gate_stream)* this_ptr = reinterpret_cast<GATE_INTERFACE_VTBL(gate_stream)*>(this); | |
136 | 8 | this_ptr->read = &IStreamBuilder::stream_read; | |
137 | 8 | this_ptr->peek = &IStreamBuilder::stream_peek; | |
138 | 8 | this_ptr->write = &IStreamBuilder::stream_write; | |
139 | 8 | this_ptr->flush = &IStreamBuilder::stream_flush; | |
140 | 8 | } | |
141 | |||
142 | IStreamBuilder::VtblStream IStreamBuilder::cpp_vtbl_stream; | ||
143 | |||
144 | ✗ | IStreamBuilder::IStreamBuilder(GATE_INTERFACE_VTBL(gate_stream) const* vtbl_ptr, char const* name) | |
145 | ✗ | : object_builder_t(vtbl_ptr, name) | |
146 | { | ||
147 | ✗ | } | |
148 | |||
149 | ✗ | IStreamBuilder::IStreamBuilder() | |
150 | ✗ | : object_builder_t(&cpp_vtbl_stream, GATE_INTERFACE_NAME_STREAM) | |
151 | { | ||
152 | ✗ | } | |
153 | |||
154 | |||
155 | |||
156 | |||
157 | |||
158 | enumint_t const Stream::Open_Read = GATE_STREAM_OPEN_READ; | ||
159 | enumint_t const Stream::Open_Write = GATE_STREAM_OPEN_WRITE; | ||
160 | enumint_t const Stream::Open_ReadWrite = GATE_STREAM_OPEN_READWRITE; | ||
161 | enumint_t const Stream::Open_Append = GATE_STREAM_OPEN_APPEND; | ||
162 | enumint_t const Stream::Open_AppendWrite = GATE_STREAM_OPEN_APPENDWRITE; | ||
163 | enumint_t const Stream::Open_AppendReadWrite = GATE_STREAM_OPEN_APPENDREADWRITE; | ||
164 | |||
165 | |||
166 | ///////////////////////////// | ||
167 | // Stream implementation // | ||
168 | ///////////////////////////// | ||
169 | |||
170 | 119 | Stream::Stream(gate_stream_t* strm) | |
171 | 119 | : object_impl_t(strm) | |
172 | { | ||
173 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 119 times.
|
119 | if (this->impl_ptr == NULL) |
174 | { | ||
175 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
176 | } | ||
177 | 119 | } | |
178 | 6 | Stream::Stream(Stream const& src) noexcept | |
179 | 6 | : object_impl_t(src) | |
180 | { | ||
181 | |||
182 | 6 | } | |
183 | |||
184 | ✗ | Result<size_t> Stream::tryRead(char* buffer, size_t bufferlen) noexcept | |
185 | { | ||
186 | ✗ | size_t ret = 0; | |
187 | ✗ | result_t result = gate_stream_read(this->impl_ptr, buffer, bufferlen, &ret); | |
188 | ✗ | return makeResult(result, ret); | |
189 | } | ||
190 | ✗ | Result<size_t> Stream::tryPeek(char* buffer, size_t bufferlen) noexcept | |
191 | { | ||
192 | ✗ | size_t ret = 0; | |
193 | ✗ | result_t result = gate_stream_peek(this->impl_ptr, buffer, bufferlen, &ret); | |
194 | ✗ | return makeResult(result, ret); | |
195 | } | ||
196 | 4 | Result<size_t> Stream::tryWrite(char const* buffer, size_t bufferlen) noexcept | |
197 | { | ||
198 | 4 | size_t ret = 0; | |
199 | 4 | result_t result = gate_stream_write(this->impl_ptr, buffer, bufferlen, &ret); | |
200 | 4 | return makeResult(result, ret); | |
201 | } | ||
202 | 4 | Result<Void> Stream::tryFlush() noexcept | |
203 | { | ||
204 | 4 | result_t result = gate_stream_flush(this->impl_ptr); | |
205 | 4 | return makeResult(result); | |
206 | } | ||
207 | ✗ | Result<size_t> Stream::tryReadBlock(char* buffer, size_t bufferlen) noexcept | |
208 | { | ||
209 | size_t ret; | ||
210 | ✗ | result_t result = gate_stream_read_block(this->impl_ptr, buffer, bufferlen, &ret); | |
211 | ✗ | return makeResult(result, ret); | |
212 | } | ||
213 | 4 | Result<size_t> Stream::tryWriteBlock(char const* buffer, size_t bufferlen) noexcept | |
214 | { | ||
215 | size_t ret; | ||
216 | 4 | result_t result = gate_stream_write_block(this->impl_ptr, buffer, bufferlen, &ret); | |
217 | 4 | return makeResult(result, ret); | |
218 | } | ||
219 | |||
220 | |||
221 | |||
222 | 27 | size_t Stream::read(char* buffer, size_t bufferlen) | |
223 | { | ||
224 | 27 | size_t ret = 0; | |
225 |
1/2✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
|
27 | result_t result = gate_stream_read(this->impl_ptr, buffer, bufferlen, &ret); |
226 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
27 | GATEXX_CHECK_EXCEPTION(result); |
227 | 27 | return ret; | |
228 | } | ||
229 | 502 | size_t Stream::peek(char* buffer, size_t bufferlen) | |
230 | { | ||
231 | 502 | size_t ret = 0; | |
232 |
1/2✓ Branch 1 taken 502 times.
✗ Branch 2 not taken.
|
502 | result_t result = gate_stream_peek(this->impl_ptr, buffer, bufferlen, &ret); |
233 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 501 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
502 | GATEXX_CHECK_EXCEPTION(result); |
234 | 501 | return ret; | |
235 | } | ||
236 | 1 | size_t Stream::write(char const* buffer, size_t bufferlen) | |
237 | { | ||
238 | 1 | size_t ret = 0; | |
239 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_stream_write(this->impl_ptr, buffer, bufferlen, &ret); |
240 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
241 | 1 | return ret; | |
242 | } | ||
243 | 510 | void Stream::flush() | |
244 | { | ||
245 | 510 | result_t result = gate_stream_flush(this->impl_ptr); | |
246 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 510 times.
|
510 | GATEXX_CHECK_EXCEPTION(result); |
247 | 510 | } | |
248 | |||
249 | 506 | size_t Stream::readBlock(char* buffer, size_t bufferlen) | |
250 | { | ||
251 | 506 | size_t ret = 0; | |
252 |
1/2✓ Branch 1 taken 506 times.
✗ Branch 2 not taken.
|
506 | result_t result = gate_stream_read_block(this->impl_ptr, buffer, bufferlen, &ret); |
253 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 505 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
506 | GATEXX_CHECK_EXCEPTION(result); |
254 | 505 | return ret; | |
255 | } | ||
256 | 506 | size_t Stream::writeBlock(char const* buffer, size_t bufferlen) | |
257 | { | ||
258 | 506 | size_t ret = 0; | |
259 |
1/2✓ Branch 1 taken 506 times.
✗ Branch 2 not taken.
|
506 | result_t result = gate_stream_write_block(this->impl_ptr, buffer, bufferlen, &ret); |
260 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 506 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
506 | GATEXX_CHECK_EXCEPTION(result); |
261 | 506 | return ret; | |
262 | } | ||
263 | |||
264 | 3 | void Stream::transfer(Stream& src, Stream& dst) | |
265 | { | ||
266 | 3 | result_t result = gate_stream_transfer(src.impl_ptr, dst.impl_ptr); | |
267 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_EXCEPTION(result); |
268 | 3 | } | |
269 | ✗ | void Stream::transfer(gate_stream_t& src, gate_stream_t& dst) | |
270 | { | ||
271 | ✗ | result_t result = gate_stream_transfer(&src, &dst); | |
272 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
273 | ✗ | } | |
274 | |||
275 | ✗ | Result<Void> Stream::tryTransfer(Stream& src, Stream& dst) | |
276 | { | ||
277 | ✗ | result_t result = gate_stream_transfer(src.impl_ptr, dst.impl_ptr); | |
278 | ✗ | return makeResult(result); | |
279 | } | ||
280 | ✗ | Result<Void> Stream::tryTransfer(gate_stream_t& src, gate_stream_t& dst) | |
281 | { | ||
282 | ✗ | result_t result = gate_stream_transfer(&src, &dst); | |
283 | ✗ | return makeResult(result); | |
284 | } | ||
285 | |||
286 | 6 | void Stream::transferViaBuffer(Stream& src, Stream& dst, char* buffer, size_t buffersize) | |
287 | { | ||
288 | 6 | result_t result = gate_stream_transfer_buffer(src.impl_ptr, dst.impl_ptr, buffer, buffersize); | |
289 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | GATEXX_CHECK_EXCEPTION(result); |
290 | 6 | } | |
291 | ✗ | void Stream::transferViaBuffer(gate_stream_t& src, gate_stream_t& dst, char* buffer, size_t buffersize) | |
292 | { | ||
293 | ✗ | result_t result = gate_stream_transfer_buffer(&src, &dst, buffer, buffersize); | |
294 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
295 | ✗ | } | |
296 | |||
297 | ✗ | Result<Void> Stream::tryTransferViaBuffer(Stream& src, Stream& dst, char* buffer, size_t buffersize) | |
298 | { | ||
299 | ✗ | result_t result = gate_stream_transfer_buffer(src.impl_ptr, dst.impl_ptr, buffer, buffersize); | |
300 | ✗ | return makeResult(result); | |
301 | } | ||
302 | ✗ | Result<Void> Stream::tryTransferViaBuffer(gate_stream_t& src, gate_stream_t& dst, char* buffer, size_t buffersize) | |
303 | { | ||
304 | ✗ | result_t result = gate_stream_transfer_buffer(&src, &dst, buffer, buffersize); | |
305 | ✗ | return makeResult(result); | |
306 | } | ||
307 | |||
308 | |||
309 | |||
310 | ✗ | uint64_t Stream::transferLimit(Stream& src, uint64_t limit, Stream& dst) | |
311 | { | ||
312 | ✗ | uint64_t ret = 0; | |
313 | ✗ | result_t result = gate_stream_transfer_limit(src.impl_ptr, limit, dst.impl_ptr, &ret); | |
314 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
315 | ✗ | return ret; | |
316 | } | ||
317 | ✗ | uint64_t Stream::transferLimit(gate_stream_t& src, uint64_t limit, gate_stream_t& dst) | |
318 | { | ||
319 | ✗ | uint64_t ret = 0; | |
320 | ✗ | result_t result = gate_stream_transfer_limit(&src, limit, &dst, &ret); | |
321 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
322 | ✗ | return ret; | |
323 | } | ||
324 | |||
325 | ✗ | Result<uint64_t> Stream::tryTransferLimit(Stream& src, uint64_t limit, Stream& dst) | |
326 | { | ||
327 | ✗ | uint64_t ret = 0; | |
328 | ✗ | result_t result = gate_stream_transfer_limit(src.impl_ptr, limit, dst.impl_ptr, &ret); | |
329 | ✗ | return makeResult(result, ret); | |
330 | } | ||
331 | ✗ | Result<uint64_t> Stream::tryTransferLimit(gate_stream_t& src, uint64_t limit, gate_stream_t& dst) | |
332 | { | ||
333 | ✗ | uint64_t ret = 0; | |
334 | ✗ | result_t result = gate_stream_transfer_limit(&src, limit, &dst, &ret); | |
335 | ✗ | return makeResult(result, ret); | |
336 | } | ||
337 | |||
338 | 1 | uint64_t Stream::skip(Stream& src, uint64_t count) | |
339 | { | ||
340 | 1 | uint64_t ret = 0; | |
341 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_stream_skip(src.impl_ptr, count, &ret); |
342 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
343 | 1 | return ret; | |
344 | } | ||
345 | ✗ | uint64_t Stream::skip(gate_stream_t& src, uint64_t count) | |
346 | { | ||
347 | ✗ | uint64_t ret = 0; | |
348 | ✗ | result_t result = gate_stream_skip(&src, count, &ret); | |
349 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
350 | ✗ | return ret; | |
351 | } | ||
352 | |||
353 | ✗ | Result<uint64_t> Stream::trySkip(Stream& src, uint64_t count) | |
354 | { | ||
355 | ✗ | uint64_t ret = 0; | |
356 | ✗ | result_t result = gate_stream_skip(src.impl_ptr, count, &ret); | |
357 | ✗ | return makeResult(result, ret); | |
358 | } | ||
359 | ✗ | Result<uint64_t> Stream::trySkip(gate_stream_t& src, uint64_t count) | |
360 | { | ||
361 | ✗ | uint64_t ret = 0; | |
362 | ✗ | result_t result = gate_stream_skip(&src, count, &ret); | |
363 | ✗ | return makeResult(result, ret); | |
364 | } | ||
365 | |||
366 | |||
367 | |||
368 | 36 | void Stream::print(char const* buffer, size_t bufferlen) | |
369 | { | ||
370 | 36 | size_t ret = 0; | |
371 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | result_t result = gate_stream_write_block(this->impl_ptr, buffer, bufferlen, &ret); |
372 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
36 | GATEXX_CHECK_EXCEPTION(result); |
373 | 36 | } | |
374 | 12 | void Stream::print(int32_t num) | |
375 | { | ||
376 | 12 | result_t result = gate_stream_print_int(this->impl_ptr, num); | |
377 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | GATEXX_CHECK_EXCEPTION(result); |
378 | 12 | } | |
379 | 8 | void Stream::print(uint32_t num) | |
380 | { | ||
381 | 8 | result_t result = gate_stream_print_uint(this->impl_ptr, num); | |
382 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | GATEXX_CHECK_EXCEPTION(result); |
383 | 8 | } | |
384 | 4 | void Stream::print(int64_t num) | |
385 | { | ||
386 | 4 | result_t result = gate_stream_print_int64(this->impl_ptr, num); | |
387 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
388 | 4 | } | |
389 | 4 | void Stream::print(uint64_t num) | |
390 | { | ||
391 | 4 | result_t result = gate_stream_print_uint64(this->impl_ptr, num); | |
392 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
393 | 4 | } | |
394 | 9 | void Stream::print(real64_t num, unsigned intlen, unsigned decimallen, unsigned grouplen) | |
395 | { | ||
396 | 9 | result_t result = gate_stream_print_real(this->impl_ptr, num, intlen, decimallen, grouplen); | |
397 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | GATEXX_CHECK_EXCEPTION(result); |
398 | 9 | } | |
399 | ✗ | void Stream::println(String const& str) | |
400 | { | ||
401 | ✗ | this->print(str.c_str(), str.length()); | |
402 | ✗ | gate_stream_println_cstr(this->impl_ptr, NULL); | |
403 | ✗ | } | |
404 | 3 | void Stream::println(char const* str) | |
405 | { | ||
406 | 3 | this->print(str, gate_str_length(str)); | |
407 | 3 | gate_stream_println_cstr(this->impl_ptr, NULL); | |
408 | 3 | } | |
409 | ✗ | void Stream::println(char const* buffer, size_t bufferlen) | |
410 | { | ||
411 | ✗ | this->print(buffer, bufferlen); | |
412 | ✗ | gate_stream_println_cstr(this->impl_ptr, NULL); | |
413 | ✗ | } | |
414 | |||
415 | ✗ | void Stream::read(StringBuilder& strbuilder) | |
416 | { | ||
417 | char buffer[GATE_MAX_COPYBUFFER_LENGTH]; | ||
418 | ✗ | size_t received = this->read(buffer, sizeof(buffer)); | |
419 | ✗ | strbuilder.append(buffer, received); | |
420 | ✗ | } | |
421 | |||
422 | |||
423 | 8 | Stream& Stream::operator<<(String const& str) | |
424 | { | ||
425 | 8 | this->print(str.c_str(), str.length()); | |
426 | 8 | return *this; | |
427 | } | ||
428 | 4 | Stream& Stream::operator<<(gate_string_t const* str) | |
429 | { | ||
430 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (str != NULL) |
431 | { | ||
432 | 4 | this->print(str->str, str->length); | |
433 | } | ||
434 | 4 | return *this; | |
435 | } | ||
436 | 17 | Stream& Stream::operator<<(char const* str) | |
437 | { | ||
438 | 17 | this->print(str, gate_str_length(str)); | |
439 | 17 | return *this; | |
440 | } | ||
441 | 4 | Stream& Stream::operator<<(bool_t b) | |
442 | { | ||
443 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (b) |
444 | { | ||
445 | 4 | this->print("true", 4); | |
446 | } | ||
447 | else | ||
448 | { | ||
449 | ✗ | this->print("false", 5); | |
450 | } | ||
451 | 4 | return *this; | |
452 | } | ||
453 | ✗ | Stream& Stream::operator<<(int8_t num) | |
454 | { | ||
455 | ✗ | this->print(int32_t(num)); | |
456 | ✗ | return *this; | |
457 | } | ||
458 | /* | ||
459 | Stream& Stream::operator<<(uint8_t num) | ||
460 | { | ||
461 | this->print(uint32_t(num)); | ||
462 | return *this; | ||
463 | } | ||
464 | */ | ||
465 | 4 | Stream& Stream::operator<<(int16_t num) | |
466 | { | ||
467 | 4 | this->print(int32_t(num)); | |
468 | 4 | return *this; | |
469 | } | ||
470 | 4 | Stream& Stream::operator<<(uint16_t num) | |
471 | { | ||
472 | 4 | this->print(uint32_t(num)); | |
473 | 4 | return *this; | |
474 | } | ||
475 | 4 | Stream& Stream::operator<<(int32_t num) | |
476 | { | ||
477 | 4 | this->print(num); | |
478 | 4 | return *this; | |
479 | } | ||
480 | 4 | Stream& Stream::operator<<(uint32_t num) | |
481 | { | ||
482 | 4 | this->print(num); | |
483 | 4 | return *this; | |
484 | } | ||
485 | 4 | Stream& Stream::operator<<(int64_t num) | |
486 | { | ||
487 | 4 | this->print(num); | |
488 | 4 | return *this; | |
489 | } | ||
490 | 4 | Stream& Stream::operator<<(uint64_t num) | |
491 | { | ||
492 | 4 | this->print(num); | |
493 | 4 | return *this; | |
494 | } | ||
495 | 4 | Stream& Stream::operator<<(real32_t num) | |
496 | { | ||
497 | 4 | this->print(real64_t(num)); | |
498 | 4 | return *this; | |
499 | } | ||
500 | 4 | Stream& Stream::operator<<(real64_t num) | |
501 | { | ||
502 | 4 | this->print(num); | |
503 | 4 | return *this; | |
504 | } | ||
505 | /* | ||
506 | #if !defined(GATE_TYPE_NATIVE_UINT_INTEGRATED) | ||
507 | Stream& Stream::operator<<(unsigned int num) | ||
508 | { | ||
509 | this->print(static_cast<uint32_t>(num)); | ||
510 | return *this; | ||
511 | } | ||
512 | #endif | ||
513 | #if !defined(GATE_TYPE_NATIVE_INT_INTEGRATED) | ||
514 | Stream& Stream::operator<<(int num) | ||
515 | { | ||
516 | this->print(static_cast<int32_t>(num)); | ||
517 | return *this; | ||
518 | } | ||
519 | #endif | ||
520 | #if !defined(GATE_TYPE_NATIVE_ULONG_INTEGRATED) | ||
521 | Stream& Stream::operator<<(unsigned long num) | ||
522 | { | ||
523 | this->print(static_cast<uint64_t>(num)); | ||
524 | return *this; | ||
525 | } | ||
526 | #endif | ||
527 | #if !defined(GATE_TYPE_NATIVE_LONG_INTEGRATED) | ||
528 | Stream& Stream::operator<<(long num) | ||
529 | { | ||
530 | this->print(static_cast<int64_t>(num)); | ||
531 | return *this; | ||
532 | } | ||
533 | #endif | ||
534 | */ | ||
535 | |||
536 | ✗ | Stream& Stream::operator>>(String& str) | |
537 | { | ||
538 | ✗ | StringBuilder strbuilder; | |
539 | ✗ | this->read(strbuilder); | |
540 | ✗ | String newInput = strbuilder.toString(); | |
541 | ✗ | str.swap(newInput); | |
542 | ✗ | return *this; | |
543 | } | ||
544 | |||
545 | |||
546 | |||
547 | ///////////////////////////////// | ||
548 | // NullStream implementation // | ||
549 | ///////////////////////////////// | ||
550 | |||
551 | 2 | NullStream::NullStream() noexcept | |
552 | 2 | : Stream(gate_nullstream()) | |
553 | { | ||
554 | 2 | } | |
555 | ✗ | NullStream::NullStream(NullStream const& src) noexcept | |
556 | ✗ | : Stream(gate_nullstream()) | |
557 | { | ||
558 | ✗ | } | |
559 | ✗ | NullStream& NullStream::operator=(NullStream const& src) noexcept | |
560 | { | ||
561 | (void)src; | ||
562 | ✗ | return *this; | |
563 | } | ||
564 | 2 | NullStream::~NullStream() noexcept | |
565 | { | ||
566 | 2 | } | |
567 | |||
568 | |||
569 | |||
570 | //////////////////////////////// | ||
571 | // MemStream implementation // | ||
572 | //////////////////////////////// | ||
573 | |||
574 | 1 | MemStream::MemStream(gate_memstream_t* implptr) | |
575 | 1 | : Stream((gate_stream_t*)implptr) | |
576 | { | ||
577 | 1 | this->memimpl = (gate_memstream_t*)this->impl_ptr; | |
578 | 1 | } | |
579 | |||
580 | 12 | MemStream::MemStream(size_t capacity) | |
581 | 12 | : Stream((gate_stream_t*)gate_memstream_create(capacity)) | |
582 | { | ||
583 | 12 | this->memimpl = (gate_memstream_t*)this->impl_ptr; | |
584 | 12 | } | |
585 | ✗ | MemStream::MemStream(MemStream const& src) | |
586 | ✗ | : Stream(src), memimpl(src.memimpl) | |
587 | { | ||
588 | ✗ | } | |
589 | ✗ | MemStream& MemStream::operator=(MemStream const& src) | |
590 | { | ||
591 | ✗ | MemStream that(src); | |
592 | ✗ | this->swap(that); | |
593 | ✗ | return *this; | |
594 | } | ||
595 | 13 | MemStream::~MemStream() noexcept | |
596 | { | ||
597 | 13 | } | |
598 | |||
599 | ✗ | gate_memstream_t* MemStream::c_impl() const noexcept | |
600 | { | ||
601 | ✗ | return this->memimpl; | |
602 | } | ||
603 | |||
604 | |||
605 | ✗ | void MemStream::swap(MemStream& that) noexcept | |
606 | { | ||
607 | ✗ | Stream::swap(that); | |
608 | ✗ | gate::swapRefs(this->memimpl, that.memimpl); | |
609 | ✗ | } | |
610 | |||
611 | 4 | char const* MemStream::getData() | |
612 | { | ||
613 | 4 | return gate_memstream_get_data(this->memimpl); | |
614 | } | ||
615 | 7 | size_t MemStream::size() | |
616 | { | ||
617 | 7 | return gate_memstream_size(this->memimpl); | |
618 | } | ||
619 | ✗ | void MemStream::reserve(size_t space) | |
620 | { | ||
621 | ✗ | result_t result = gate_memstream_reserve(this->memimpl, space); | |
622 | ✗ | GATEXX_CHECK_ERROR(result); | |
623 | ✗ | } | |
624 | 1 | void MemStream::fill(char fillitem, size_t count) | |
625 | { | ||
626 | 1 | result_t result = gate_memstream_fill(this->memimpl, fillitem, count); | |
627 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
628 | 1 | } | |
629 | 1 | size_t MemStream::discard(size_t bytecount) | |
630 | { | ||
631 | 1 | return gate_memstream_discard(this->memimpl, bytecount); | |
632 | } | ||
633 | 1 | size_t MemStream::discardBack(size_t bytecount) | |
634 | { | ||
635 | 1 | return gate_memstream_discard_back(this->memimpl, bytecount); | |
636 | } | ||
637 | |||
638 | |||
639 | /////////////////////// | ||
640 | // StaticMemStream // | ||
641 | /////////////////////// | ||
642 | |||
643 | 1 | StaticMemStream::StaticMemStream(void* ptrData, size_t dataLength, size_t dataLengthUsed) | |
644 | 1 | : MemStream(gate_memstream_create_static(ptrData, dataLength, dataLengthUsed)) | |
645 | { | ||
646 | 1 | } | |
647 | ✗ | StaticMemStream::StaticMemStream(StaticMemStream const& src) | |
648 | ✗ | : MemStream(src) | |
649 | { | ||
650 | ✗ | } | |
651 | ✗ | StaticMemStream& StaticMemStream::operator=(StaticMemStream const& src) | |
652 | { | ||
653 | ✗ | MemStream::operator=(src); | |
654 | ✗ | return *this; | |
655 | } | ||
656 | 1 | StaticMemStream::~StaticMemStream() noexcept | |
657 | { | ||
658 | 1 | } | |
659 | |||
660 | |||
661 | |||
662 | ////////////////////// | ||
663 | // LocalMemStream // | ||
664 | ////////////////////// | ||
665 | |||
666 | |||
667 | 1 | LocalMemStream::LocalMemStream(void* ptrWritableData, gate_size_t dataLength) | |
668 | 1 | : Stream((gate_stream_t*)&memimpl) | |
669 | { | ||
670 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_memstream_create_static_unmanaged(&this->memimpl, ptrWritableData, dataLength, 0); |
671 | 1 | } | |
672 | ✗ | LocalMemStream::LocalMemStream(void const* ptrReadOnlyData, gate_size_t dataLength) | |
673 | ✗ | : Stream((gate_stream_t*)&memimpl) | |
674 | { | ||
675 | ✗ | gate_memstream_create_static_unmanaged_readonly(&this->memimpl, ptrReadOnlyData, dataLength, dataLength); | |
676 | ✗ | } | |
677 | 1 | LocalMemStream::~LocalMemStream() noexcept | |
678 | { | ||
679 | 1 | } | |
680 | |||
681 | ✗ | char const* LocalMemStream::getData() | |
682 | { | ||
683 | ✗ | return gate_memstream_get_data(&this->memimpl); | |
684 | } | ||
685 | ✗ | size_t LocalMemStream::size() | |
686 | { | ||
687 | ✗ | return gate_memstream_size(&this->memimpl); | |
688 | } | ||
689 | ✗ | size_t LocalMemStream::discard(size_t bytecount) | |
690 | { | ||
691 | ✗ | return gate_memstream_discard(&this->memimpl, bytecount); | |
692 | } | ||
693 | ✗ | size_t LocalMemStream::discardBack(size_t bytecount) | |
694 | { | ||
695 | ✗ | return gate_memstream_discard_back(&this->memimpl, bytecount); | |
696 | } | ||
697 | |||
698 | |||
699 | |||
700 | //////////////////////////////////// | ||
701 | // SyncMemStream implementation // | ||
702 | //////////////////////////////////// | ||
703 | |||
704 | 1 | static gate_stream_t* initSyncMemStream(size_t prealloc, uint32_t timeoutms) | |
705 | { | ||
706 | 1 | gate_stream_t* ret = NULL; | |
707 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_result_t result = gate_syncmemstream_create(prealloc, timeoutms, &ret); |
708 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
709 | 1 | return ret; | |
710 | } | ||
711 | |||
712 | 1 | SyncMemStream::SyncMemStream(size_t prealloc, uint32_t timeoutms) | |
713 | 1 | : Stream(initSyncMemStream(prealloc, timeoutms)) | |
714 | { | ||
715 | 1 | } | |
716 | |||
717 | ✗ | SyncMemStream::SyncMemStream(SyncMemStream const& src) | |
718 | ✗ | : Stream(src) | |
719 | { | ||
720 | ✗ | } | |
721 | |||
722 | ✗ | SyncMemStream& SyncMemStream::operator=(SyncMemStream const& src) | |
723 | { | ||
724 | ✗ | if (this != &src) | |
725 | { | ||
726 | ✗ | Stream::operator=(src); | |
727 | } | ||
728 | ✗ | return *this; | |
729 | } | ||
730 | |||
731 | 1 | SyncMemStream::~SyncMemStream() noexcept | |
732 | { | ||
733 | 1 | } | |
734 | |||
735 | |||
736 | |||
737 | |||
738 | /////////////////////////////////// | ||
739 | // StringStream implementation // | ||
740 | /////////////////////////////////// | ||
741 | |||
742 | 22 | StringStream::StringStream(size_t capacity) | |
743 | 22 | : Stream((gate_stream_t*)gate_stringstream_create(capacity)) | |
744 | { | ||
745 | 22 | this->builderimpl = (gate_stringstream_t*)this->impl_ptr; | |
746 | 22 | } | |
747 | ✗ | StringStream::StringStream(StringStream const& src) | |
748 | ✗ | : Stream((gate_stream_t*)gate_stringstream_create(0)) | |
749 | { | ||
750 | ✗ | this->builderimpl = (gate_stringstream_t*)this->impl_ptr; | |
751 | ✗ | this->write(gate_stringstream_get_data(src.builderimpl), gate_stringstream_size(src.builderimpl)); | |
752 | ✗ | } | |
753 | 21 | StringStream::StringStream(String const& text) | |
754 | 21 | : Stream((gate_stream_t*)gate_stringstream_create(0)) | |
755 | { | ||
756 | 21 | this->builderimpl = (gate_stringstream_t*)this->impl_ptr; | |
757 | 21 | size_t written = 0; | |
758 |
1/2✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
|
21 | result_t result = gate_stream_write_block(this->impl_ptr, text.c_str(), text.length(), &written); |
759 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
21 | GATEXX_CHECK_ERROR(result); |
760 | 21 | } | |
761 | |||
762 | ✗ | StringStream& StringStream::operator=(StringStream const& src) | |
763 | { | ||
764 | ✗ | StringStream that(src); | |
765 | ✗ | this->swap(that); | |
766 | ✗ | return *this; | |
767 | } | ||
768 | 129 | StringStream::~StringStream() | |
769 | { | ||
770 | 43 | this->builderimpl = NULL; | |
771 | 43 | } | |
772 | |||
773 | ✗ | void StringStream::swap(StringStream& that) noexcept | |
774 | { | ||
775 | ✗ | Stream::swap(that); | |
776 | ✗ | gate::swapRefs(this->builderimpl, that.builderimpl); | |
777 | ✗ | } | |
778 | |||
779 | 9 | String StringStream::toString() | |
780 | { | ||
781 | gate_string_t str; | ||
782 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | result_t result = gate_stringstream_to_string(this->builderimpl, &str); |
783 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
9 | GATEXX_CHECK_ERROR(result); |
784 | 18 | return String::createFrom(str); | |
785 | } | ||
786 | |||
787 | 8 | String StringStream::toView() | |
788 | { | ||
789 | gate_string_t str; | ||
790 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | result_t result = gate_stringstream_get_current_view(this->builderimpl, &str); |
791 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
8 | GATEXX_CHECK_ERROR(result); |
792 | 16 | return String::createFrom(str); | |
793 | } | ||
794 | |||
795 | |||
796 | |||
797 | enumint_t const ResourceStream::Resource_Default = GATE_STREAM_RESOURCE_DEFAULT; | ||
798 | enumint_t const ResourceStream::Resource_Input = GATE_STREAM_RESOURCE_INPUT; | ||
799 | enumint_t const ResourceStream::Resource_Output = GATE_STREAM_RESOURCE_OUTPUT; | ||
800 | enumint_t const ResourceStream::Resource_Error = GATE_STREAM_RESOURCE_ERROR; | ||
801 | |||
802 | 9 | ResourceStream::ResourceStream(gate_resourcestream_t* stream) | |
803 | 9 | : Stream((gate_stream_t*)stream) | |
804 | { | ||
805 | 9 | } | |
806 | 1 | ResourceStream::ResourceStream(ResourceStream const& src) | |
807 | 1 | : Stream(src) | |
808 | { | ||
809 | 1 | } | |
810 | |||
811 | 10 | ResourceStream::~ResourceStream() noexcept | |
812 | { | ||
813 | 10 | } | |
814 | ✗ | uintptr_t ResourceStream::getResource(enumint_t resourceType) | |
815 | { | ||
816 | ✗ | uintptr_t ret = 0; | |
817 | ✗ | gate_resourcestream_t* resstream = (gate_resourcestream_t*)this->impl_ptr; | |
818 | ✗ | result_t result = gate_stream_get_resource(resstream, resourceType, &ret); | |
819 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
820 | ✗ | return ret; | |
821 | } | ||
822 | |||
823 | ✗ | gate_resourcestream_t* ResourceStream::c_impl() const noexcept | |
824 | { | ||
825 | ✗ | return (gate_resourcestream_t*)Stream::c_impl(); | |
826 | } | ||
827 | |||
828 | |||
829 | |||
830 | |||
831 | enumint_t const ControlStream::Seek_Begin = GATE_STREAM_SEEK_BEGIN; | ||
832 | enumint_t const ControlStream::Seek_End = GATE_STREAM_SEEK_END; | ||
833 | enumint_t const ControlStream::Seek_Current = GATE_STREAM_SEEK_CURRENT; | ||
834 | |||
835 | enumint_t const ControlStream::Close_Default = GATE_STREAM_CLOSE_DEFAULT; | ||
836 | enumint_t const ControlStream::Close_Input = GATE_STREAM_CLOSE_INPUT; | ||
837 | enumint_t const ControlStream::Close_Output = GATE_STREAM_CLOSE_OUTPUT; | ||
838 | enumint_t const ControlStream::Close_Error = GATE_STREAM_CLOSE_ERROR; | ||
839 | |||
840 | 9 | ControlStream::ControlStream(gate_controlstream_t* stream) | |
841 | 9 | : ResourceStream((gate_resourcestream_t*)stream) | |
842 | { | ||
843 | 9 | } | |
844 | 1 | ControlStream::ControlStream(ControlStream const& src) | |
845 | 1 | : ResourceStream(src) | |
846 | { | ||
847 | 1 | } | |
848 | |||
849 | |||
850 | 10 | ControlStream::~ControlStream() noexcept | |
851 | { | ||
852 | 10 | } | |
853 | |||
854 | 1 | bool ControlStream::canRead() | |
855 | { | ||
856 | 1 | gate_bool_t ret = false; | |
857 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_stream_can_read(((gate_controlstream_t*)this->impl_ptr), &ret); |
858 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
859 | 1 | return ret; | |
860 | } | ||
861 | 1 | bool ControlStream::canWrite() | |
862 | { | ||
863 | 1 | gate_bool_t ret = false; | |
864 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_stream_can_write(((gate_controlstream_t*)this->impl_ptr), &ret); |
865 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
866 | 1 | return ret; | |
867 | } | ||
868 | 1 | int64_t ControlStream::getSize() | |
869 | { | ||
870 | 1 | int64_t ret = 0; | |
871 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_stream_get_size(((gate_controlstream_t*)this->impl_ptr), &ret); |
872 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
873 | 1 | return ret; | |
874 | } | ||
875 | 1 | int64_t ControlStream::getAvailable() | |
876 | { | ||
877 | 1 | int64_t ret = 0; | |
878 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_stream_get_available(((gate_controlstream_t*)this->impl_ptr), &ret); |
879 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
880 | 1 | return ret; | |
881 | } | ||
882 | 1 | int64_t ControlStream::seek(int64_t position, enumint_t origin) | |
883 | { | ||
884 | 1 | int64_t ret = 0; | |
885 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_stream_seek(((gate_controlstream_t*)this->impl_ptr), position, origin, &ret); |
886 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
887 | 1 | return ret; | |
888 | } | ||
889 | 1 | void ControlStream::reset() | |
890 | { | ||
891 | 1 | result_t result = gate_stream_reset(((gate_controlstream_t*)this->impl_ptr)); | |
892 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
893 | 1 | } | |
894 | ✗ | void ControlStream::close(enumint_t closeType) | |
895 | { | ||
896 | ✗ | result_t result = gate_stream_close(((gate_controlstream_t*)this->impl_ptr), closeType); | |
897 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
898 | ✗ | } | |
899 | |||
900 | 4 | gate_controlstream_t* ControlStream::c_impl() const noexcept | |
901 | { | ||
902 | 4 | return (gate_controlstream_t*)Stream::c_impl(); | |
903 | } | ||
904 | |||
905 | |||
906 | ✗ | static gate_controlstream_t* constructMemViewStream(void const* ptrData, size_t dataLength, size_t offset, gate_object_t* ptr_container) | |
907 | { | ||
908 | ✗ | gate_controlstream_t* ptr = gate_memstream_create_view(ptrData, dataLength, offset, ptr_container); | |
909 | ✗ | if (ptr == NULL) | |
910 | { | ||
911 | ✗ | GATEXX_RAISE_ERROR(GATE_RESULT_OUTOFMEMORY); | |
912 | } | ||
913 | ✗ | return ptr; | |
914 | } | ||
915 | |||
916 | ✗ | MemViewStream::MemViewStream(void const* ptrData, size_t dataLength, size_t offset) | |
917 | ✗ | : ControlStream(constructMemViewStream(ptrData, dataLength, offset, NULL)) | |
918 | { | ||
919 | |||
920 | ✗ | } | |
921 | ✗ | MemViewStream::MemViewStream(void const* ptrData, size_t dataLength, size_t offset, Object& container) | |
922 | ✗ | : ControlStream(constructMemViewStream(ptrData, dataLength, offset, container.c_impl())) | |
923 | { | ||
924 | ✗ | } | |
925 | |||
926 | ✗ | MemViewStream::MemViewStream(MemViewStream const& src) | |
927 | ✗ | : ControlStream(src) | |
928 | { | ||
929 | ✗ | } | |
930 | ✗ | MemViewStream& MemViewStream::operator=(MemViewStream const& src) | |
931 | { | ||
932 | ✗ | ControlStream::operator=(src); | |
933 | ✗ | return *this; | |
934 | } | ||
935 | ✗ | MemViewStream::~MemViewStream() noexcept | |
936 | { | ||
937 | ✗ | } | |
938 | |||
939 | |||
940 | |||
941 | 2 | static gate_controlstream_t* constructMemFileStream(size_t prealloc) | |
942 | { | ||
943 | 2 | gate_controlstream_t* ptr = gate_memfilestream_create(prealloc); | |
944 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ptr == NULL) |
945 | { | ||
946 | ✗ | GATEXX_RAISE_ERROR(GATE_RESULT_OUTOFMEMORY); | |
947 | } | ||
948 | 2 | return ptr; | |
949 | } | ||
950 | 4 | static gate_controlstream_t* constructSharedMemFileStream(gate_controlstream_t* memfile) | |
951 | { | ||
952 | 4 | gate_controlstream_t* ptr = gate_memfilestream_share(memfile); | |
953 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ptr == NULL) |
954 | { | ||
955 | ✗ | GATEXX_RAISE_ERROR(GATE_RESULT_OUTOFMEMORY); | |
956 | } | ||
957 | 4 | return ptr; | |
958 | } | ||
959 | |||
960 | 2 | MemFileStream::MemFileStream(gate_size_t prealloc) | |
961 | 2 | : ControlStream(constructMemFileStream(prealloc)) | |
962 | { | ||
963 | 2 | } | |
964 | 4 | MemFileStream::MemFileStream(gate_controlstream_t* ptr_stream) | |
965 | 4 | : ControlStream(constructSharedMemFileStream(ptr_stream)) | |
966 | { | ||
967 | |||
968 | 4 | } | |
969 | ✗ | MemFileStream::MemFileStream(MemFileStream const& src) | |
970 | ✗ | : ControlStream(src) | |
971 | { | ||
972 | ✗ | } | |
973 | ✗ | MemFileStream& MemFileStream::operator=(MemFileStream const& src) | |
974 | { | ||
975 | ✗ | ControlStream::operator=(src); | |
976 | ✗ | return *this; | |
977 | } | ||
978 | 6 | MemFileStream::~MemFileStream() noexcept | |
979 | { | ||
980 | 6 | } | |
981 | |||
982 | 4 | MemFileStream MemFileStream::share() | |
983 | { | ||
984 | 4 | gate_controlstream_t* ctrlstream = reinterpret_cast<gate_controlstream_t*>(this->c_impl()); | |
985 | 4 | MemFileStream ret(ctrlstream); | |
986 | 4 | return ret; | |
987 | } | ||
988 | |||
989 | |||
990 | } // end of namespace gate | ||
991 |