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