GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_blobs.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 138 151 91.4%
Functions: 39 40 97.5%
Branches: 31 62 50.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/blobs.hpp"
30 #include "gate/exceptions.hpp"
31 #include "gate/debugging.h"
32
33 namespace gate
34 {
35
36 10 Blob::Blob()
37 {
38 10 gate_blob_create_empty(&this->impl);
39 10 }
40 2 Blob::Blob(void const* data, size_t length)
41 {
42
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (NULL == gate_blob_create(&this->impl, data, length))
43 {
44 GATEXX_RAISE_ERROR(results::OutOfMemory);
45 }
46 2 }
47 2 Blob::Blob(gate_blob_t const& blob)
48 {
49
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (NULL == gate_blob_create_duplicate(&this->impl, &blob))
50 {
51 GATEXX_RAISE_ERROR(results::OutOfMemory);
52 }
53 2 }
54
55 3 Blob::Blob(Blob const& src)
56 {
57
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (NULL == gate_blob_create_duplicate(&this->impl, src.c_impl()))
58 {
59 GATEXX_RAISE_ERROR(results::OutOfMemory);
60 }
61 3 }
62 2 Blob& Blob::operator=(Blob const& src)
63 {
64
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (this != &src)
65 {
66
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 Blob that(src);
67 2 this->swap(that);
68 }
69 2 return *this;
70 }
71 34 Blob::~Blob() noexcept
72 {
73 17 gate_blob_release(&this->impl);
74 17 }
75
76 2 void Blob::swap(Blob& that) noexcept
77 {
78 2 gate::swapRefsNoExcept(this->impl, that.impl);
79 2 }
80
81
82 7 gate_blob_t const* Blob::c_impl() const noexcept
83 {
84 7 return &this->impl;
85 }
86
87 2 Blob Blob::createStatic(void const* data, size_t length)
88 {
89 2 Blob blob;
90
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 gate_blob_create_static(&blob.impl, data, length);
91 2 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 4 bool_t Blob::empty() const noexcept
146 {
147 4 return gate_blob_length(&this->impl) == 0;
148 }
149 8 size_t Blob::length() const noexcept
150 {
151 8 return gate_blob_length(&this->impl);
152 }
153 6 void const* Blob::data() const noexcept
154 {
155 6 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
192
193
194
195
196
197 28 bool_t BitField::isBitSet(void const* bitfield, size_t bitindex)
198 {
199 28 return gate_bit_is_set(bitfield, bitindex);
200 }
201 11 void BitField::setBit(void* bitfield, size_t bitindex)
202 {
203 11 gate_bit_set(bitfield, bitindex);
204 11 }
205 11 void BitField::clearBit(void* bitfield, size_t bitindex)
206 {
207 11 gate_bit_clear(bitfield, bitindex);
208 11 }
209
210 3 BitField::BitField(size_t bitCount)
211 3 : impl(NULL), bitlen(bitCount)
212 {
213
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (bitCount > 0)
214 {
215 1 size_t bytelen = (bitCount + 7) / 8;
216 1 impl = Mem::alloc(bytelen);
217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!impl)
218 {
219 GATEXX_RAISE_ERROR(results::OutOfMemory);
220 }
221 1 Mem::clear(impl, bytelen);
222 }
223 3 }
224
225 2 BitField::BitField(BitField const& src)
226 2 : impl(NULL), bitlen(src.bitlen)
227 {
228
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (src.bitlen > 0)
229 {
230 2 size_t bytelen = (src.bitlen + 7) / 8;
231 2 impl = Mem::alloc(bytelen);
232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!impl)
233 {
234 GATEXX_RAISE_ERROR(results::OutOfMemory);
235 }
236 2 Mem::copy(this->impl, src.impl, bytelen);
237 }
238 2 }
239 1 BitField& BitField::operator=(BitField const& src)
240 {
241
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this != &src)
242 {
243
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 BitField that(src);
244 1 this->swap(that);
245
246 }
247 1 return *this;
248 }
249 10 BitField::~BitField() noexcept
250 {
251
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if (this->impl)
252 {
253 3 Mem::dealloc(this->impl);
254 }
255 5 }
256
257 1 void BitField::swap(BitField& that) noexcept
258 {
259 1 gate::swapRefsNoExcept(this->impl, that.impl);
260 1 gate::swapRefsNoExcept(this->bitlen, that.bitlen);
261 1 }
262
263 1 size_t BitField::length() const noexcept
264 {
265 1 return this->bitlen;
266 }
267
268 void const* BitField::c_impl() const noexcept
269 {
270 return this->impl;
271 }
272
273 1 void* BitField::c_impl() noexcept
274 {
275 1 return this->impl;
276 }
277
278 22 bool_t BitField::get(size_t bitindex) const
279 {
280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (bitindex >= this->bitlen)
281 {
282 return false;
283 }
284 22 return BitField::isBitSet(this->impl, bitindex);
285 }
286 11 void BitField::set(size_t bitindex)
287 {
288
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (bitindex < this->bitlen)
289 {
290 11 BitField::setBit(this->impl, bitindex);
291 }
292 11 }
293 11 void BitField::clear(size_t bitindex)
294 {
295
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (bitindex < this->bitlen)
296 {
297 11 BitField::clearBit(this->impl, bitindex);
298 }
299 11 }
300 22 void BitField::set(size_t bitindex, bool_t value)
301 {
302
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
22 if (value)
303 {
304 11 this->set(bitindex);
305 }
306 else
307 {
308 11 this->clear(bitindex);
309 }
310 22 }
311
312 6 bool_t BitField::operator[](size_t bitindex) const noexcept
313 {
314 6 GATE_DEBUG_ASSERT(bitindex < this->bitlen);
315 6 return BitField::isBitSet(this->impl, bitindex);
316 }
317
318
319
320 } // end of namespace gate
321