GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_blobs.cpp
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 154 165 93.3%
Functions: 47 47 100.0%
Branches: 32 64 50.0%

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/blobs.hpp"
30 #include "gate/exceptions.hpp"
31 #include "gate/debugging.h"
32
33 namespace gate
34 {
35
36 24 Blob::Blob()
37 {
38 24 gate_blob_create_empty(&this->impl);
39 24 }
40 33 Blob::Blob(void const* data, size_t length)
41 {
42
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
33 if (NULL == gate_blob_create(&this->impl, data, length))
43 {
44 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
45 }
46 33 }
47 4 Blob::Blob(gate_blob_t const& blob)
48 {
49
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (NULL == gate_blob_create_duplicate(&this->impl, &blob))
50 {
51 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
52 }
53 4 }
54
55 12 Blob::Blob(Blob const& src)
56 {
57
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (NULL == gate_blob_create_duplicate(&this->impl, src.c_impl()))
58 {
59 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
60 }
61 12 }
62 11 Blob& Blob::operator=(Blob const& src)
63 {
64
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (this != &src)
65 {
66
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
22 Blob that(src);
67 11 this->swap(that);
68 }
69 11 return *this;
70 }
71 146 Blob::~Blob() noexcept
72 {
73 73 gate_blob_release(&this->impl);
74 73 }
75
76 11 void Blob::swap(Blob& that) noexcept
77 {
78 11 gate::swapRefsNoExcept(this->impl, that.impl);
79 11 }
80
81
82 35 gate_blob_t const* Blob::c_impl() const noexcept
83 {
84 35 return &this->impl;
85 }
86
87 5 Blob Blob::createStatic(void const* data, size_t length)
88 {
89 5 Blob blob;
90
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 gate_blob_create_static(&blob.impl, data, length);
91 5 return blob;
92 }
93 2 Blob Blob::createFrom(gate_blob_t& blob)
94 {
95 2 Blob ret;
96 2 ret.impl = blob;
97
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 gate_blob_create_empty(&blob);
98 2 return ret;
99 }
100 1 void Blob::assign(gate_blob_t& target, gate_blob_t const& src)
101 {
102 1 gate_blob_t tmp = GATE_INIT_EMPTY;
103
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_blob_create_clone(&tmp, &src))
104 {
105 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
106 }
107
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_blob_release(&target);
108 1 target = tmp;
109 1 }
110 1 void Blob::assign(gate_blob_t& target, Blob const& src)
111 {
112 1 Blob::assign(target, *src.c_impl());
113 1 }
114
115
116 1 Blob Blob::copy() const
117 {
118 1 Blob ret;
119
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_blob_create_copy(&ret.impl, &this->impl))
120 {
121 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
122 }
123 1 return ret;
124 }
125 1 Blob Blob::clone() const
126 {
127 1 Blob ret;
128
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_blob_create_clone(&ret.impl, &this->impl))
129 {
130 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
131 }
132 1 return ret;
133 }
134
135 1 Blob Blob::subset(size_t offset, size_t length) const noexcept
136 {
137 1 Blob ret;
138
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_blob_create_subset(&ret.impl, &this->impl, offset, length))
139 {
140 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
141 }
142 1 return ret;
143 }
144
145 13 bool_t Blob::empty() const noexcept
146 {
147 13 return gate_blob_length(&this->impl) == 0;
148 }
149 40 size_t Blob::length() const noexcept
150 {
151 40 return gate_blob_length(&this->impl);
152 }
153 36 void const* Blob::data() const noexcept
154 {
155 36 return gate_blob_data(&this->impl);
156 }
157 25 uint8_t Blob::getByte(size_t index) const noexcept
158 {
159 25 return gate_blob_get_byte(&this->impl, index);
160 }
161 1 size_t Blob::getBytes(size_t index, void* buffer, size_t bufferCapacity) const noexcept
162 {
163 1 return gate_blob_get_bytes(&this->impl, index, buffer, bufferCapacity);
164 }
165 1 void Blob::setByte(size_t index, uint8_t byteValue)
166 {
167 1 result_t result = gate_blob_set_byte(&this->impl, index, byteValue);
168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
169 1 }
170 1 size_t Blob::setBytes(size_t index, void const* buffer, size_t bufferLength)
171 {
172 1 size_t count = gate_blob_set_bytes(&this->impl, index, buffer, bufferLength);
173 1 return count;
174 }
175
176 1 uint8_t Blob::operator[](size_t index) const noexcept
177 {
178 1 return this->getByte(index);
179 }
180
181 1 uint8_t& Blob::operator[](size_t index)
182 {
183
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (index >= this->length())
184 {
185 ✗ GATEXX_RAISE_ERROR(results::OutOfBounds);
186 }
187 1 uint8_t* ptr = (uint8_t*)gate_blob_databuffer(&this->impl);
188 1 return ptr[index];
189 }
190
191 1 bool_t Blob::operator!() const noexcept
192 {
193 1 return this->empty();
194 }
195 1 bool_t Blob::operator==(Blob const& that) const noexcept
196 {
197 1 return gate_blob_compare(this->c_impl(), that.c_impl()) == 0;
198 }
199 1 bool_t Blob::operator!=(Blob const& that) const noexcept
200 {
201 1 return gate_blob_compare(this->c_impl(), that.c_impl()) != 0;
202 }
203 2 bool_t Blob::operator< (Blob const& that) const noexcept
204 {
205 2 return gate_blob_compare(this->c_impl(), that.c_impl()) < 0;
206 }
207 2 bool_t Blob::operator> (Blob const& that) const noexcept
208 {
209 2 return gate_blob_compare(this->c_impl(), that.c_impl()) > 0;
210 }
211 1 bool_t Blob::operator<=(Blob const& that) const noexcept
212 {
213 1 return gate_blob_compare(this->c_impl(), that.c_impl()) <= 0;
214 }
215 1 bool_t Blob::operator>=(Blob const& that) const noexcept
216 {
217 1 return gate_blob_compare(this->c_impl(), that.c_impl()) >= 0;
218 }
219
220
221
222
223
224
225 28 bool_t BitField::isBitSet(void const* bitfield, size_t bitindex)
226 {
227 28 return gate_bit_is_set(bitfield, bitindex);
228 }
229 11 void BitField::setBit(void* bitfield, size_t bitindex)
230 {
231 11 gate_bit_set(bitfield, bitindex);
232 11 }
233 11 void BitField::clearBit(void* bitfield, size_t bitindex)
234 {
235 11 gate_bit_clear(bitfield, bitindex);
236 11 }
237
238 3 BitField::BitField(size_t bitCount)
239 3 : impl(NULL), bitlen(bitCount)
240 {
241
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (bitCount > 0)
242 {
243 1 size_t bytelen = (bitCount + 7) / 8;
244 1 impl = Mem::alloc(bytelen);
245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!impl)
246 {
247 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
248 }
249 1 Mem::clear(impl, bytelen);
250 }
251 3 }
252
253 2 BitField::BitField(BitField const& src)
254 2 : impl(NULL), bitlen(src.bitlen)
255 {
256
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (src.bitlen > 0)
257 {
258 2 size_t bytelen = (src.bitlen + 7) / 8;
259 2 impl = Mem::alloc(bytelen);
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!impl)
261 {
262 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
263 }
264 2 Mem::copy(this->impl, src.impl, bytelen);
265 }
266 2 }
267 1 BitField& BitField::operator=(BitField const& src)
268 {
269
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this != &src)
270 {
271
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 BitField that(src);
272 1 this->swap(that);
273
274 }
275 1 return *this;
276 }
277 10 BitField::~BitField() noexcept
278 {
279
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if (this->impl)
280 {
281 3 Mem::dealloc(this->impl);
282 }
283 5 }
284
285 1 void BitField::swap(BitField& that) noexcept
286 {
287 1 gate::swapRefsNoExcept(this->impl, that.impl);
288 1 gate::swapRefsNoExcept(this->bitlen, that.bitlen);
289 1 }
290
291 1 size_t BitField::length() const noexcept
292 {
293 1 return this->bitlen;
294 }
295
296 1 void const* BitField::c_impl() const noexcept
297 {
298 1 return this->impl;
299 }
300
301 2 void* BitField::c_impl() noexcept
302 {
303 2 return this->impl;
304 }
305
306 22 bool_t BitField::get(size_t bitindex) const
307 {
308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (bitindex >= this->bitlen)
309 {
310 ✗ return false;
311 }
312 22 return BitField::isBitSet(this->impl, bitindex);
313 }
314 11 void BitField::set(size_t bitindex)
315 {
316
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (bitindex < this->bitlen)
317 {
318 11 BitField::setBit(this->impl, bitindex);
319 }
320 11 }
321 11 void BitField::clear(size_t bitindex)
322 {
323
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (bitindex < this->bitlen)
324 {
325 11 BitField::clearBit(this->impl, bitindex);
326 }
327 11 }
328 22 void BitField::set(size_t bitindex, bool_t value)
329 {
330
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
22 if (value)
331 {
332 11 this->set(bitindex);
333 }
334 else
335 {
336 11 this->clear(bitindex);
337 }
338 22 }
339
340 6 bool_t BitField::operator[](size_t bitindex) const noexcept
341 {
342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 GATE_DEBUG_ASSERT(bitindex < this->bitlen);
343 6 return BitField::isBitSet(this->impl, bitindex);
344 }
345
346
347
348 } // end of namespace gate
349