GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_streams.cpp
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 412 498 82.7%
Functions: 114 136 83.8%
Branches: 103 296 34.8%

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