| 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 | ✗ | Stream::Stream() | |
| 143 | ✗ | : object_impl_t(gate_nullstream()) | |
| 144 | { | ||
| 145 | ✗ | } | |
| 146 | |||
| 147 | 333 | Stream::Stream(gate_stream_t* strm) | |
| 148 | 333 | : object_impl_t(strm) | |
| 149 | { | ||
| 150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 333 times.
|
333 | if (this->impl_ptr == NULL) |
| 151 | { | ||
| 152 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 153 | } | ||
| 154 | 333 | } | |
| 155 | 25 | Stream::Stream(Stream const& src) noexcept | |
| 156 | 25 | : object_impl_t(src) | |
| 157 | { | ||
| 158 | 25 | } | |
| 159 | |||
| 160 | 29 | Stream& Stream::operator=(Stream const& src) noexcept | |
| 161 | { | ||
| 162 | 29 | object_impl_t::operator=(src); | |
| 163 | 29 | return *this; | |
| 164 | } | ||
| 165 | |||
| 166 | |||
| 167 | 1 | Result<size_t> Stream::tryRead(char* buffer, size_t bufferlen) noexcept | |
| 168 | { | ||
| 169 | 1 | size_t ret = 0; | |
| 170 | 1 | result_t result = gate_stream_read(this->impl_ptr, buffer, bufferlen, &ret); | |
| 171 | 1 | 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 | 4 | Result<size_t> Stream::tryWrite(char const* buffer, size_t bufferlen) noexcept | |
| 180 | { | ||
| 181 | 4 | size_t ret = 0; | |
| 182 | 4 | result_t result = gate_stream_write(this->impl_ptr, buffer, bufferlen, &ret); | |
| 183 | 4 | 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 | 46 | size_t Stream::read(char* buffer, size_t bufferlen) | |
| 206 | { | ||
| 207 | 46 | size_t ret = 0; | |
| 208 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | result_t result = gate_stream_read(this->impl_ptr, buffer, bufferlen, &ret); |
| 209 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 41 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
|
46 | GATEXX_CHECK_EXCEPTION(result); |
| 210 | 41 | return ret; | |
| 211 | } | ||
| 212 | 511 | size_t Stream::peek(char* buffer, size_t bufferlen) | |
| 213 | { | ||
| 214 | 511 | size_t ret = 0; | |
| 215 |
1/2✓ Branch 1 taken 511 times.
✗ Branch 2 not taken.
|
511 | result_t result = gate_stream_peek(this->impl_ptr, buffer, bufferlen, &ret); |
| 216 |
3/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 504 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
|
511 | GATEXX_CHECK_EXCEPTION(result); |
| 217 | 504 | return ret; | |
| 218 | } | ||
| 219 | 10 | size_t Stream::write(char const* buffer, size_t bufferlen) | |
| 220 | { | ||
| 221 | 10 | size_t ret = 0; | |
| 222 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | result_t result = gate_stream_write(this->impl_ptr, buffer, bufferlen, &ret); |
| 223 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
10 | GATEXX_CHECK_EXCEPTION(result); |
| 224 | 6 | return ret; | |
| 225 | } | ||
| 226 | 525 | void Stream::flush() | |
| 227 | { | ||
| 228 | 525 | result_t result = gate_stream_flush(this->impl_ptr); | |
| 229 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 521 times.
|
525 | GATEXX_CHECK_EXCEPTION(result); |
| 230 | 521 | } | |
| 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 | 520 | size_t Stream::writeBlock(char const* buffer, size_t bufferlen) | |
| 240 | { | ||
| 241 | 520 | size_t ret = 0; | |
| 242 |
1/2✓ Branch 1 taken 520 times.
✗ Branch 2 not taken.
|
520 | result_t result = gate_stream_write_block(this->impl_ptr, buffer, bufferlen, &ret); |
| 243 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 520 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
520 | GATEXX_CHECK_EXCEPTION(result); |
| 244 | 520 | 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 | ✗ | uint64_t Stream::skip(gate_stream_t& src, uint64_t count) | |
| 328 | { | ||
| 329 | ✗ | uint64_t ret = 0; | |
| 330 | ✗ | result_t result = gate_stream_skip(&src, count, &ret); | |
| 331 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 332 | ✗ | return ret; | |
| 333 | } | ||
| 334 | |||
| 335 | ✗ | Result<uint64_t> Stream::trySkip(Stream& src, uint64_t count) | |
| 336 | { | ||
| 337 | ✗ | uint64_t ret = 0; | |
| 338 | ✗ | result_t result = gate_stream_skip(src.impl_ptr, count, &ret); | |
| 339 | ✗ | return makeResult(result, ret); | |
| 340 | } | ||
| 341 | ✗ | Result<uint64_t> Stream::trySkip(gate_stream_t& src, uint64_t count) | |
| 342 | { | ||
| 343 | ✗ | uint64_t ret = 0; | |
| 344 | ✗ | result_t result = gate_stream_skip(&src, count, &ret); | |
| 345 | ✗ | return makeResult(result, ret); | |
| 346 | } | ||
| 347 | |||
| 348 | |||
| 349 | |||
| 350 | 1159 | void Stream::print(char const* buffer, size_t bufferlen) | |
| 351 | { | ||
| 352 | 1159 | size_t ret = 0; | |
| 353 |
1/2✓ Branch 1 taken 1159 times.
✗ Branch 2 not taken.
|
1159 | result_t result = gate_stream_write_block(this->impl_ptr, buffer, bufferlen, &ret); |
| 354 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1159 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1159 | GATEXX_CHECK_EXCEPTION(result); |
| 355 | 1159 | } | |
| 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 | ✗ | void Stream::println(String const& str) | |
| 382 | { | ||
| 383 | ✗ | this->print(str.c_str(), str.length()); | |
| 384 | ✗ | gate_stream_println_cstr(this->impl_ptr, NULL); | |
| 385 | ✗ | } | |
| 386 | 1007 | void Stream::println(char const* str) | |
| 387 | { | ||
| 388 | 1007 | this->print(str, gate_str_length(str)); | |
| 389 | 1007 | gate_stream_println_cstr(this->impl_ptr, NULL); | |
| 390 | 1007 | } | |
| 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 | |||
| 438 | ✗ | void Stream::read(StringBuilder& strbuilder) | |
| 439 | { | ||
| 440 | char buffer[GATE_MAX_COPYBUFFER_LENGTH]; | ||
| 441 | ✗ | size_t received = this->read(buffer, sizeof(buffer)); | |
| 442 | ✗ | strbuilder.append(buffer, received); | |
| 443 | ✗ | } | |
| 444 | |||
| 445 | ✗ | String Stream::readLine() | |
| 446 | { | ||
| 447 | char buffer[GATE_MAX_COPYBUFFER_LENGTH]; | ||
| 448 | ✗ | size_t returned = 0; | |
| 449 | ✗ | result_t readLineResult = gate_stream_read_line(this->impl_ptr, buffer, sizeof(buffer), &returned); | |
| 450 | ✗ | GATEXX_CHECK_EXCEPTION(readLineResult); | |
| 451 | ✗ | return String(buffer, returned); | |
| 452 | } | ||
| 453 | |||
| 454 | 61 | Stream& Stream::operator<<(String const& str) | |
| 455 | { | ||
| 456 | 61 | this->print(str.c_str(), str.length()); | |
| 457 | 61 | return *this; | |
| 458 | } | ||
| 459 | 4 | Stream& Stream::operator<<(gate_string_t const* str) | |
| 460 | { | ||
| 461 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (str != NULL) |
| 462 | { | ||
| 463 | 4 | this->print(str->str, str->length); | |
| 464 | } | ||
| 465 | 4 | return *this; | |
| 466 | } | ||
| 467 | 78 | Stream& Stream::operator<<(char const* str) | |
| 468 | { | ||
| 469 | 78 | this->print(str, gate_str_length(str)); | |
| 470 | 78 | return *this; | |
| 471 | } | ||
| 472 | 4 | Stream& Stream::operator<<(bool_t b) | |
| 473 | { | ||
| 474 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (b) |
| 475 | { | ||
| 476 | 4 | this->print("true", 4); | |
| 477 | } | ||
| 478 | else | ||
| 479 | { | ||
| 480 | ✗ | this->print("false", 5); | |
| 481 | } | ||
| 482 | 4 | return *this; | |
| 483 | } | ||
| 484 | ✗ | Stream& Stream::operator<<(int8_t num) | |
| 485 | { | ||
| 486 | ✗ | this->print(int32_t(num)); | |
| 487 | ✗ | return *this; | |
| 488 | } | ||
| 489 | /* | ||
| 490 | Stream& Stream::operator<<(uint8_t num) | ||
| 491 | { | ||
| 492 | this->print(uint32_t(num)); | ||
| 493 | return *this; | ||
| 494 | } | ||
| 495 | */ | ||
| 496 | 4 | Stream& Stream::operator<<(int16_t num) | |
| 497 | { | ||
| 498 | 4 | this->print(int32_t(num)); | |
| 499 | 4 | return *this; | |
| 500 | } | ||
| 501 | 4 | Stream& Stream::operator<<(uint16_t num) | |
| 502 | { | ||
| 503 | 4 | this->print(uint32_t(num)); | |
| 504 | 4 | return *this; | |
| 505 | } | ||
| 506 | 6 | Stream& Stream::operator<<(int32_t num) | |
| 507 | { | ||
| 508 | 6 | this->print(num); | |
| 509 | 5 | return *this; | |
| 510 | } | ||
| 511 | 5 | Stream& Stream::operator<<(uint32_t num) | |
| 512 | { | ||
| 513 | 5 | this->print(num); | |
| 514 | 5 | return *this; | |
| 515 | } | ||
| 516 | 5 | Stream& Stream::operator<<(int64_t num) | |
| 517 | { | ||
| 518 | 5 | this->print(num); | |
| 519 | 5 | return *this; | |
| 520 | } | ||
| 521 | 5 | Stream& Stream::operator<<(uint64_t num) | |
| 522 | { | ||
| 523 | 5 | this->print(num); | |
| 524 | 5 | return *this; | |
| 525 | } | ||
| 526 | 4 | Stream& Stream::operator<<(real32_t num) | |
| 527 | { | ||
| 528 | 4 | this->print(real64_t(num)); | |
| 529 | 4 | return *this; | |
| 530 | } | ||
| 531 | 5 | Stream& Stream::operator<<(real64_t num) | |
| 532 | { | ||
| 533 | 5 | this->print(num); | |
| 534 | 5 | return *this; | |
| 535 | } | ||
| 536 | /* | ||
| 537 | #if !defined(GATE_TYPE_NATIVE_UINT_INTEGRATED) | ||
| 538 | Stream& Stream::operator<<(unsigned int num) | ||
| 539 | { | ||
| 540 | this->print(static_cast<uint32_t>(num)); | ||
| 541 | return *this; | ||
| 542 | } | ||
| 543 | #endif | ||
| 544 | #if !defined(GATE_TYPE_NATIVE_INT_INTEGRATED) | ||
| 545 | Stream& Stream::operator<<(int num) | ||
| 546 | { | ||
| 547 | this->print(static_cast<int32_t>(num)); | ||
| 548 | return *this; | ||
| 549 | } | ||
| 550 | #endif | ||
| 551 | #if !defined(GATE_TYPE_NATIVE_ULONG_INTEGRATED) | ||
| 552 | Stream& Stream::operator<<(unsigned long num) | ||
| 553 | { | ||
| 554 | this->print(static_cast<uint64_t>(num)); | ||
| 555 | return *this; | ||
| 556 | } | ||
| 557 | #endif | ||
| 558 | #if !defined(GATE_TYPE_NATIVE_LONG_INTEGRATED) | ||
| 559 | Stream& Stream::operator<<(long num) | ||
| 560 | { | ||
| 561 | this->print(static_cast<int64_t>(num)); | ||
| 562 | return *this; | ||
| 563 | } | ||
| 564 | #endif | ||
| 565 | */ | ||
| 566 | |||
| 567 | ✗ | Stream& Stream::operator>>(StringBuilder& strbuilder) | |
| 568 | { | ||
| 569 | ✗ | this->read(strbuilder); | |
| 570 | ✗ | return *this; | |
| 571 | } | ||
| 572 | |||
| 573 | 1 | Stream& Stream::operator>>(int32_t& num) { this->scan(num); return *this; } | |
| 574 | 1 | Stream& Stream::operator>>(uint32_t& num) { this->scan(num); return *this; } | |
| 575 | 1 | Stream& Stream::operator>>(int64_t& num) { this->scan(num); return *this; } | |
| 576 | 1 | Stream& Stream::operator>>(uint64_t& num) { this->scan(num); return *this; } | |
| 577 | 1 | Stream& Stream::operator>>(real64_t& num) { this->scan(num); return *this; } | |
| 578 | 1 | Stream& Stream::operator>>(String& text) { this->scan(text); return *this; } | |
| 579 | |||
| 580 | |||
| 581 | ///////////////////////////////// | ||
| 582 | // NullStream implementation // | ||
| 583 | ///////////////////////////////// | ||
| 584 | |||
| 585 | 13 | NullStream::NullStream() noexcept | |
| 586 | 13 | : Stream(gate_nullstream()) | |
| 587 | { | ||
| 588 | 13 | } | |
| 589 | ✗ | NullStream::NullStream(NullStream const& src) noexcept | |
| 590 | ✗ | : Stream(gate_nullstream()) | |
| 591 | { | ||
| 592 | ✗ | } | |
| 593 | ✗ | NullStream& NullStream::operator=(NullStream const& src) noexcept | |
| 594 | { | ||
| 595 | (void)src; | ||
| 596 | ✗ | return *this; | |
| 597 | } | ||
| 598 | 13 | NullStream::~NullStream() noexcept | |
| 599 | { | ||
| 600 | 13 | } | |
| 601 | |||
| 602 | |||
| 603 | |||
| 604 | //////////////////////////////// | ||
| 605 | // MemStream implementation // | ||
| 606 | //////////////////////////////// | ||
| 607 | |||
| 608 | 3 | MemStream::MemStream(gate_memstream_t* implptr) | |
| 609 | 3 | : Stream((gate_stream_t*)implptr) | |
| 610 | { | ||
| 611 | 3 | this->memimpl = (gate_memstream_t*)this->impl_ptr; | |
| 612 | 3 | } | |
| 613 | |||
| 614 | 84 | MemStream::MemStream(size_t capacity) | |
| 615 | 84 | : Stream((gate_stream_t*)gate_memstream_create(capacity)) | |
| 616 | { | ||
| 617 | 84 | this->memimpl = (gate_memstream_t*)this->impl_ptr; | |
| 618 | 84 | } | |
| 619 | 2 | MemStream::MemStream(MemStream const& src) | |
| 620 | 2 | : Stream(src), memimpl(src.memimpl) | |
| 621 | { | ||
| 622 | 2 | } | |
| 623 | 1 | MemStream& MemStream::operator=(MemStream const& src) | |
| 624 | { | ||
| 625 | 1 | MemStream that(src); | |
| 626 | 1 | this->swap(that); | |
| 627 | 1 | return *this; | |
| 628 | } | ||
| 629 | 89 | MemStream::~MemStream() noexcept | |
| 630 | { | ||
| 631 | 89 | } | |
| 632 | |||
| 633 | 10 | gate_memstream_t* MemStream::c_impl() const noexcept | |
| 634 | { | ||
| 635 | 10 | return this->memimpl; | |
| 636 | } | ||
| 637 | |||
| 638 | |||
| 639 | 3 | void MemStream::swap(MemStream& that) noexcept | |
| 640 | { | ||
| 641 | 3 | Stream::swap(that); | |
| 642 | 3 | gate::swapRefs(this->memimpl, that.memimpl); | |
| 643 | 3 | } | |
| 644 | |||
| 645 | 9 | char const* MemStream::getData() | |
| 646 | { | ||
| 647 | 9 | return gate_memstream_get_data(this->memimpl); | |
| 648 | } | ||
| 649 | 12 | size_t MemStream::size() | |
| 650 | { | ||
| 651 | 12 | return gate_memstream_size(this->memimpl); | |
| 652 | } | ||
| 653 | 1 | void MemStream::reserve(size_t space) | |
| 654 | { | ||
| 655 | 1 | result_t result = gate_memstream_reserve(this->memimpl, space); | |
| 656 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 657 | 1 | } | |
| 658 | 1 | void MemStream::fill(char fillitem, size_t count) | |
| 659 | { | ||
| 660 | 1 | result_t result = gate_memstream_fill(this->memimpl, fillitem, count); | |
| 661 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 662 | 1 | } | |
| 663 | 1 | size_t MemStream::discard(size_t bytecount) | |
| 664 | { | ||
| 665 | 1 | return gate_memstream_discard(this->memimpl, bytecount); | |
| 666 | } | ||
| 667 | 1 | size_t MemStream::discardBack(size_t bytecount) | |
| 668 | { | ||
| 669 | 1 | return gate_memstream_discard_back(this->memimpl, bytecount); | |
| 670 | } | ||
| 671 | |||
| 672 | |||
| 673 | /////////////////////// | ||
| 674 | // StaticMemStream // | ||
| 675 | /////////////////////// | ||
| 676 | |||
| 677 | 3 | StaticMemStream::StaticMemStream(void* ptrData, size_t dataLength, size_t dataLengthUsed) | |
| 678 | 3 | : MemStream(gate_memstream_create_static(ptrData, dataLength, dataLengthUsed)) | |
| 679 | { | ||
| 680 | 3 | } | |
| 681 | 1 | StaticMemStream::StaticMemStream(StaticMemStream const& src) | |
| 682 | 1 | : MemStream(src) | |
| 683 | { | ||
| 684 | 1 | } | |
| 685 | 1 | StaticMemStream& StaticMemStream::operator=(StaticMemStream const& src) | |
| 686 | { | ||
| 687 | 1 | MemStream::operator=(src); | |
| 688 | 1 | return *this; | |
| 689 | } | ||
| 690 | 4 | StaticMemStream::~StaticMemStream() noexcept | |
| 691 | { | ||
| 692 | 4 | } | |
| 693 | |||
| 694 | |||
| 695 | |||
| 696 | ////////////////////// | ||
| 697 | // LocalMemStream // | ||
| 698 | ////////////////////// | ||
| 699 | |||
| 700 | |||
| 701 | 1 | LocalMemStream::LocalMemStream(void* ptrWritableData, gate_size_t dataLength) | |
| 702 | 1 | : Stream((gate_stream_t*)&memimpl) | |
| 703 | { | ||
| 704 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_memstream_create_static_unmanaged(&this->memimpl, ptrWritableData, dataLength, 0); |
| 705 | 1 | } | |
| 706 | 5 | LocalMemStream::LocalMemStream(void const* ptrReadOnlyData, gate_size_t dataLength) | |
| 707 | 5 | : Stream((gate_stream_t*)&memimpl) | |
| 708 | { | ||
| 709 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | gate_memstream_create_static_unmanaged_readonly(&this->memimpl, ptrReadOnlyData, dataLength, dataLength); |
| 710 | 5 | } | |
| 711 | 6 | LocalMemStream::~LocalMemStream() noexcept | |
| 712 | { | ||
| 713 | 6 | } | |
| 714 | |||
| 715 | 1 | char const* LocalMemStream::getData() | |
| 716 | { | ||
| 717 | 1 | return gate_memstream_get_data(&this->memimpl); | |
| 718 | } | ||
| 719 | 1 | size_t LocalMemStream::size() | |
| 720 | { | ||
| 721 | 1 | return gate_memstream_size(&this->memimpl); | |
| 722 | } | ||
| 723 | 2 | size_t LocalMemStream::discard(size_t bytecount) | |
| 724 | { | ||
| 725 | 2 | return gate_memstream_discard(&this->memimpl, bytecount); | |
| 726 | } | ||
| 727 | 2 | size_t LocalMemStream::discardBack(size_t bytecount) | |
| 728 | { | ||
| 729 | 2 | return gate_memstream_discard_back(&this->memimpl, bytecount); | |
| 730 | } | ||
| 731 | 1 | void LocalMemStream::reserve(size_t space) | |
| 732 | { | ||
| 733 | 1 | gate_result_t result = gate_memstream_reserve(&this->memimpl, space); | |
| 734 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 735 | ✗ | } | |
| 736 | 2 | void LocalMemStream::fill(char fillitem, size_t count) | |
| 737 | { | ||
| 738 | 2 | gate_result_t result = gate_memstream_fill(&this->memimpl, fillitem, count); | |
| 739 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | GATEXX_CHECK_ERROR(result); |
| 740 | 1 | } | |
| 741 | |||
| 742 | |||
| 743 | |||
| 744 | //////////////////////////////////// | ||
| 745 | // SyncMemStream implementation // | ||
| 746 | //////////////////////////////////// | ||
| 747 | |||
| 748 | 2 | static gate_stream_t* initSyncMemStream(size_t prealloc, uint32_t timeoutms) | |
| 749 | { | ||
| 750 | 2 | gate_stream_t* ret = NULL; | |
| 751 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_result_t result = gate_syncmemstream_create(prealloc, timeoutms, &ret); |
| 752 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_ERROR(result); |
| 753 | 2 | return ret; | |
| 754 | } | ||
| 755 | |||
| 756 | 2 | SyncMemStream::SyncMemStream(size_t prealloc, uint32_t timeoutms) | |
| 757 | 2 | : Stream(initSyncMemStream(prealloc, timeoutms)) | |
| 758 | { | ||
| 759 | 2 | } | |
| 760 | |||
| 761 | 1 | SyncMemStream::SyncMemStream(SyncMemStream const& src) | |
| 762 | 1 | : Stream(src) | |
| 763 | { | ||
| 764 | 1 | } | |
| 765 | |||
| 766 | 1 | SyncMemStream& SyncMemStream::operator=(SyncMemStream const& src) | |
| 767 | { | ||
| 768 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (this != &src) |
| 769 | { | ||
| 770 | 1 | Stream::operator=(src); | |
| 771 | } | ||
| 772 | 1 | return *this; | |
| 773 | } | ||
| 774 | |||
| 775 | 3 | SyncMemStream::~SyncMemStream() noexcept | |
| 776 | { | ||
| 777 | 3 | } | |
| 778 | |||
| 779 | |||
| 780 | |||
| 781 | |||
| 782 | /////////////////////////////////// | ||
| 783 | // StringStream implementation // | ||
| 784 | /////////////////////////////////// | ||
| 785 | |||
| 786 | 62 | StringStream::StringStream(size_t capacity) | |
| 787 | 62 | : Stream((gate_stream_t*)gate_stringstream_create(capacity)) | |
| 788 | { | ||
| 789 | 62 | this->builderimpl = (gate_stringstream_t*)this->impl_ptr; | |
| 790 | 62 | } | |
| 791 | 2 | StringStream::StringStream(StringStream const& src) | |
| 792 | 2 | : Stream((gate_stream_t*)gate_stringstream_create(0)) | |
| 793 | { | ||
| 794 | 2 | this->builderimpl = (gate_stringstream_t*)this->impl_ptr; | |
| 795 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | size_t const src_len = gate_stringstream_size(src.builderimpl); |
| 796 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if(src_len > 0) |
| 797 | { | ||
| 798 |
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); |
| 799 | } | ||
| 800 | 2 | } | |
| 801 | 31 | StringStream::StringStream(String const& text) | |
| 802 | 31 | : Stream((gate_stream_t*)gate_stringstream_create(0)) | |
| 803 | { | ||
| 804 | 31 | this->builderimpl = (gate_stringstream_t*)this->impl_ptr; | |
| 805 | 31 | size_t written = 0; | |
| 806 |
1/2✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
|
31 | result_t result = gate_stream_write_block(this->impl_ptr, text.c_str(), text.length(), &written); |
| 807 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
31 | GATEXX_CHECK_ERROR(result); |
| 808 | 31 | } | |
| 809 | |||
| 810 | 1 | StringStream& StringStream::operator=(StringStream const& src) | |
| 811 | { | ||
| 812 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | StringStream that(src); |
| 813 | 1 | this->swap(that); | |
| 814 | 2 | return *this; | |
| 815 | } | ||
| 816 | 285 | StringStream::~StringStream() | |
| 817 | { | ||
| 818 | 95 | this->builderimpl = NULL; | |
| 819 | 95 | } | |
| 820 | |||
| 821 | 2 | void StringStream::swap(StringStream& that) noexcept | |
| 822 | { | ||
| 823 | 2 | Stream::swap(that); | |
| 824 | 2 | gate::swapRefs(this->builderimpl, that.builderimpl); | |
| 825 | 2 | } | |
| 826 | |||
| 827 | 33 | String StringStream::toString() | |
| 828 | { | ||
| 829 | gate_string_t str; | ||
| 830 |
1/2✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
|
33 | result_t result = gate_stringstream_to_string(this->builderimpl, &str); |
| 831 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
33 | GATEXX_CHECK_ERROR(result); |
| 832 | 66 | return String::createFrom(str); | |
| 833 | } | ||
| 834 | |||
| 835 | 19 | String StringStream::toView() | |
| 836 | { | ||
| 837 | gate_string_t str; | ||
| 838 |
1/2✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
|
19 | result_t result = gate_stringstream_get_current_view(this->builderimpl, &str); |
| 839 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
19 | GATEXX_CHECK_ERROR(result); |
| 840 | 38 | return String::createFrom(str); | |
| 841 | } | ||
| 842 | |||
| 843 | |||
| 844 | |||
| 845 | enumint_t const ResourceStream::Resource_Default = GATE_STREAM_RESOURCE_DEFAULT; | ||
| 846 | enumint_t const ResourceStream::Resource_Input = GATE_STREAM_RESOURCE_INPUT; | ||
| 847 | enumint_t const ResourceStream::Resource_Output = GATE_STREAM_RESOURCE_OUTPUT; | ||
| 848 | enumint_t const ResourceStream::Resource_Error = GATE_STREAM_RESOURCE_ERROR; | ||
| 849 | |||
| 850 | 36 | ResourceStream::ResourceStream(gate_resourcestream_t* stream) | |
| 851 | 36 | : Stream((gate_stream_t*)stream) | |
| 852 | { | ||
| 853 | 36 | } | |
| 854 | 1 | ResourceStream::ResourceStream(ResourceStream const& src) | |
| 855 | 1 | : Stream(src) | |
| 856 | { | ||
| 857 | 1 | } | |
| 858 | |||
| 859 | 37 | ResourceStream::~ResourceStream() noexcept | |
| 860 | { | ||
| 861 | 37 | } | |
| 862 | 8 | uintptr_t ResourceStream::getResource(enumint_t resourceType) | |
| 863 | { | ||
| 864 | 8 | uintptr_t ret = 0; | |
| 865 | 8 | gate_resourcestream_t* resstream = (gate_resourcestream_t*)this->impl_ptr; | |
| 866 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | result_t result = gate_stream_get_resource(resstream, resourceType, &ret); |
| 867 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
8 | GATEXX_CHECK_EXCEPTION(result); |
| 868 | 8 | return ret; | |
| 869 | } | ||
| 870 | |||
| 871 | ✗ | gate_resourcestream_t* ResourceStream::c_impl() const noexcept | |
| 872 | { | ||
| 873 | ✗ | return (gate_resourcestream_t*)Stream::c_impl(); | |
| 874 | } | ||
| 875 | |||
| 876 | |||
| 877 | |||
| 878 | |||
| 879 | enumint_t const ControlStream::Seek_Begin = GATE_STREAM_SEEK_BEGIN; | ||
| 880 | enumint_t const ControlStream::Seek_End = GATE_STREAM_SEEK_END; | ||
| 881 | enumint_t const ControlStream::Seek_Current = GATE_STREAM_SEEK_CURRENT; | ||
| 882 | |||
| 883 | enumint_t const ControlStream::Close_Default = GATE_STREAM_CLOSE_DEFAULT; | ||
| 884 | enumint_t const ControlStream::Close_Input = GATE_STREAM_CLOSE_INPUT; | ||
| 885 | enumint_t const ControlStream::Close_Output = GATE_STREAM_CLOSE_OUTPUT; | ||
| 886 | enumint_t const ControlStream::Close_Error = GATE_STREAM_CLOSE_ERROR; | ||
| 887 | |||
| 888 | 36 | ControlStream::ControlStream(gate_controlstream_t* stream) | |
| 889 | 36 | : ResourceStream((gate_resourcestream_t*)stream) | |
| 890 | { | ||
| 891 | 36 | } | |
| 892 | 1 | ControlStream::ControlStream(ControlStream const& src) | |
| 893 | 1 | : ResourceStream(src) | |
| 894 | { | ||
| 895 | 1 | } | |
| 896 | |||
| 897 | |||
| 898 | 37 | ControlStream::~ControlStream() noexcept | |
| 899 | { | ||
| 900 | 37 | } | |
| 901 | |||
| 902 | 6 | bool ControlStream::canRead() | |
| 903 | { | ||
| 904 | 6 | gate_bool_t ret = false; | |
| 905 |
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); |
| 906 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6 | GATEXX_CHECK_EXCEPTION(result); |
| 907 | 6 | return ret; | |
| 908 | } | ||
| 909 | 6 | bool ControlStream::canWrite() | |
| 910 | { | ||
| 911 | 6 | gate_bool_t ret = false; | |
| 912 |
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); |
| 913 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6 | GATEXX_CHECK_EXCEPTION(result); |
| 914 | 6 | return ret; | |
| 915 | } | ||
| 916 | 5 | int64_t ControlStream::getSize() | |
| 917 | { | ||
| 918 | 5 | int64_t ret = 0; | |
| 919 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | result_t result = gate_stream_get_size(((gate_controlstream_t*)this->impl_ptr), &ret); |
| 920 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
5 | GATEXX_CHECK_EXCEPTION(result); |
| 921 | 5 | return ret; | |
| 922 | } | ||
| 923 | 5 | int64_t ControlStream::getAvailable() | |
| 924 | { | ||
| 925 | 5 | int64_t ret = 0; | |
| 926 |
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); |
| 927 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
5 | GATEXX_CHECK_EXCEPTION(result); |
| 928 | 5 | return ret; | |
| 929 | } | ||
| 930 | 11 | int64_t ControlStream::seek(int64_t position, enumint_t origin) | |
| 931 | { | ||
| 932 | 11 | int64_t ret = 0; | |
| 933 |
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); |
| 934 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
11 | GATEXX_CHECK_EXCEPTION(result); |
| 935 | 11 | return ret; | |
| 936 | } | ||
| 937 | 2 | void ControlStream::reset() | |
| 938 | { | ||
| 939 | 2 | result_t result = gate_stream_reset(((gate_controlstream_t*)this->impl_ptr)); | |
| 940 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 941 | 2 | } | |
| 942 | 4 | void ControlStream::close(enumint_t closeType) | |
| 943 | { | ||
| 944 | 4 | result_t result = gate_stream_close(((gate_controlstream_t*)this->impl_ptr), closeType); | |
| 945 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
| 946 | 3 | } | |
| 947 | |||
| 948 | 4 | gate_controlstream_t* ControlStream::c_impl() const noexcept | |
| 949 | { | ||
| 950 | 4 | return (gate_controlstream_t*)Stream::c_impl(); | |
| 951 | } | ||
| 952 | |||
| 953 | |||
| 954 | 1 | static gate_controlstream_t* constructMemViewStream(void const* ptrData, size_t dataLength, size_t offset, gate_object_t* ptr_container) | |
| 955 | { | ||
| 956 | 1 | gate_controlstream_t* ptr = gate_memstream_create_view(ptrData, dataLength, offset, ptr_container); | |
| 957 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ptr == NULL) |
| 958 | { | ||
| 959 | ✗ | GATEXX_RAISE_ERROR(GATE_RESULT_OUTOFMEMORY); | |
| 960 | } | ||
| 961 | 1 | return ptr; | |
| 962 | } | ||
| 963 | |||
| 964 | 1 | MemViewStream::MemViewStream(void const* ptrData, size_t dataLength, size_t offset) | |
| 965 | 1 | : ControlStream(constructMemViewStream(ptrData, dataLength, offset, NULL)) | |
| 966 | { | ||
| 967 | |||
| 968 | 1 | } | |
| 969 | ✗ | MemViewStream::MemViewStream(void const* ptrData, size_t dataLength, size_t offset, Object& container) | |
| 970 | ✗ | : ControlStream(constructMemViewStream(ptrData, dataLength, offset, container.c_impl())) | |
| 971 | { | ||
| 972 | ✗ | } | |
| 973 | |||
| 974 | ✗ | MemViewStream::MemViewStream(MemViewStream const& src) | |
| 975 | ✗ | : ControlStream(src) | |
| 976 | { | ||
| 977 | ✗ | } | |
| 978 | ✗ | MemViewStream& MemViewStream::operator=(MemViewStream const& src) | |
| 979 | { | ||
| 980 | ✗ | ControlStream::operator=(src); | |
| 981 | ✗ | return *this; | |
| 982 | } | ||
| 983 | 1 | MemViewStream::~MemViewStream() noexcept | |
| 984 | { | ||
| 985 | 1 | } | |
| 986 | |||
| 987 | |||
| 988 | |||
| 989 | 7 | static gate_controlstream_t* constructMemFileStream(size_t prealloc) | |
| 990 | { | ||
| 991 | 7 | gate_controlstream_t* ptr = gate_memfilestream_create(prealloc); | |
| 992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (ptr == NULL) |
| 993 | { | ||
| 994 | ✗ | GATEXX_RAISE_ERROR(GATE_RESULT_OUTOFMEMORY); | |
| 995 | } | ||
| 996 | 7 | return ptr; | |
| 997 | } | ||
| 998 | 4 | static gate_controlstream_t* constructSharedMemFileStream(gate_controlstream_t* memfile) | |
| 999 | { | ||
| 1000 | 4 | gate_controlstream_t* ptr = gate_memfilestream_share(memfile); | |
| 1001 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ptr == NULL) |
| 1002 | { | ||
| 1003 | ✗ | GATEXX_RAISE_ERROR(GATE_RESULT_OUTOFMEMORY); | |
| 1004 | } | ||
| 1005 | 4 | return ptr; | |
| 1006 | } | ||
| 1007 | |||
| 1008 | 7 | MemFileStream::MemFileStream(gate_size_t prealloc) | |
| 1009 | 7 | : ControlStream(constructMemFileStream(prealloc)) | |
| 1010 | { | ||
| 1011 | 7 | } | |
| 1012 | 4 | MemFileStream::MemFileStream(gate_controlstream_t* ptr_stream) | |
| 1013 | 4 | : ControlStream(constructSharedMemFileStream(ptr_stream)) | |
| 1014 | { | ||
| 1015 | |||
| 1016 | 4 | } | |
| 1017 | ✗ | MemFileStream::MemFileStream(MemFileStream const& src) | |
| 1018 | ✗ | : ControlStream(src) | |
| 1019 | { | ||
| 1020 | ✗ | } | |
| 1021 | ✗ | MemFileStream& MemFileStream::operator=(MemFileStream const& src) | |
| 1022 | { | ||
| 1023 | ✗ | ControlStream::operator=(src); | |
| 1024 | ✗ | return *this; | |
| 1025 | } | ||
| 1026 | 11 | MemFileStream::~MemFileStream() noexcept | |
| 1027 | { | ||
| 1028 | 11 | } | |
| 1029 | |||
| 1030 | 4 | MemFileStream MemFileStream::share() | |
| 1031 | { | ||
| 1032 | 4 | gate_controlstream_t* ctrlstream = reinterpret_cast<gate_controlstream_t*>(this->c_impl()); | |
| 1033 | 4 | MemFileStream ret(ctrlstream); | |
| 1034 | 4 | return ret; | |
| 1035 | } | ||
| 1036 | |||
| 1037 | |||
| 1038 | } // end of namespace gate | ||
| 1039 |