GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_streams.cpp
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 410 511 80.2%
Functions: 113 135 83.7%
Branches: 94 256 36.7%

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