GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_arrays.cpp
Date: 2026-10-19 17:06:30
Exec Total Coverage
Lines: 104 130 80.0%
Functions: 37 43 86.0%
Branches: 11 28 39.3%

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/arrays.hpp"
30
31 namespace gate
32 {
33 418 GenericArray::GenericArray() noexcept
34 {
35 418 gate_array_create_empty(&this->impl);
36 418 }
37
38 ✗ GenericArray::GenericArray(GenericArray const& src) noexcept
39 {
40 ✗ gate_array_duplicate(&this->impl, &src.impl);
41 ✗ }
42 ✗ GenericArray::GenericArray(gate_array_t const& src) noexcept
43 {
44 ✗ gate_array_duplicate(&this->impl, &src);
45 ✗ }
46 ✗ GenericArray& GenericArray::operator=(GenericArray const& src) noexcept
47 {
48 ✗ gate_array_release(&this->impl);
49 ✗ gate_array_duplicate(&this->impl, &src.impl);
50 ✗ return *this;
51 }
52 834 GenericArray::~GenericArray() noexcept
53 {
54 417 gate_array_release(&this->impl);
55 417 }
56
57 #if defined(GATE_COMPILER_SUPPORTS_CPP_MOVEREFS)
58 1 GenericArray::GenericArray(GenericArray&& src) noexcept
59 1 : impl(src.impl)
60 {
61 1 gate_array_create_empty(&src.impl);
62 1 }
63 ✗ GenericArray& GenericArray::operator=(GenericArray&& src) noexcept
64 {
65 ✗ GenericArray tmp;
66 ✗ src.swap(tmp);
67 ✗ this->swap(tmp);
68 ✗ return *this;
69 }
70 #endif
71
72 85 void GenericArray::swap(GenericArray& other) noexcept
73 {
74 85 gate::swapRefsNoExcept(this->impl, other.impl);
75 85 }
76 1 gate_array_t const* GenericArray::c_impl() const noexcept
77 {
78 1 return &this->impl;
79 }
80 303 gate_array_t* GenericArray::c_impl() noexcept
81 {
82 303 return &this->impl;
83 }
84 23 bool_t GenericArray::empty() const noexcept
85 {
86 23 return this->length() == 0;
87 }
88 86 size_t GenericArray::length() const noexcept
89 {
90 86 return gate_array_length(&this->impl);
91 }
92 5 size_t GenericArray::size() const noexcept
93 {
94 5 return this->length();
95 }
96 2 bool_t GenericArray::contains(size_t index) const noexcept
97 {
98 2 return index < this->length();
99 }
100 1088 void const* GenericArray::getItemPtr(size_t index) const noexcept
101 {
102 1088 return gate_array_get(&this->impl, index);
103 }
104 2 size_t GenericArray::find(gate_comparer_t comparer, void const* compareWith, size_t startAt) const noexcept
105 {
106 2 return gate_array_find(&this->impl, comparer, compareWith, startAt);
107 }
108
109 1 GenericArray GenericArray::subset(size_t offset, size_t count) const
110 {
111 1 GenericArray arr;
112
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_array_subset(&arr.impl, &this->impl, offset, count))
113 {
114 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
115 }
116 1 return arr;
117 }
118 1 GenericArray GenericArray::copy() const
119 {
120 1 GenericArray arr;
121
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_array_copy(&arr.impl, &this->impl))
122 {
123 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
124 }
125 1 return arr;
126 }
127 295 void GenericArray::check_outofmem_nullptr(void const* ptr)
128 {
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 295 times.
295 if (NULL == ptr)
130 {
131 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
132 }
133 295 }
134
135
136
137 5 GenericArrayList::GenericArrayList() noexcept
138 {
139 5 gate_mem_clear(&impl, sizeof(impl));
140 5 }
141 168 GenericArrayList::GenericArrayList(size_t itemSize, void const* source, size_t sourceLength, gate_mem_copyctor_t cctor, gate_mem_dtor_t dtor)
142 168 : impl(gate_arraylist_create(itemSize, source, sourceLength, cctor, dtor))
143 {
144 168 check_outofmem_nullptr(this->impl.ptr);
145 168 }
146 7 GenericArrayList::GenericArrayList(gate_arraylist_t al)
147 7 : impl(al)
148 {
149 7 }
150 ✗ GenericArrayList::GenericArrayList(GenericArrayList const& src)
151 ✗ : impl(src.impl)
152 {
153 ✗ if (!gate_arraylist_is_null(this->impl))
154 {
155 ✗ gate_arraylist_retain(&this->impl);
156 }
157 ✗ }
158 1 GenericArrayList& GenericArrayList::operator=(GenericArrayList const& src)
159 {
160 1 gate_arraylist_release(&this->impl);
161 1 this->impl = src.impl;
162
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (!gate_arraylist_is_null(this->impl))
163 {
164 1 gate_arraylist_retain(&this->impl);
165 }
166 1 return *this;
167 }
168 360 GenericArrayList::~GenericArrayList() noexcept
169 {
170 180 gate_arraylist_release(&this->impl);
171 180 }
172 11 gate_arraylist_t& GenericArrayList::c_impl()
173 {
174 11 return this->impl;
175 }
176 1 gate_arraylist_t const& GenericArrayList::c_impl() const
177 {
178 1 return this->impl;
179 }
180 2 bool_t GenericArrayList::isNull() const noexcept
181 {
182 2 return gate_arraylist_is_null(this->impl);
183 }
184 8 void GenericArrayList::swap(GenericArrayList& that) noexcept
185 {
186 8 gate::swapRefsNoExcept(this->impl, that.impl);
187 8 }
188 1829 void GenericArrayList::check_outofmem_nullptr(void const* ptr)
189 {
190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1829 times.
1829 if (ptr == NULL)
191 {
192 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
193 }
194 1829 }
195 ✗ size_t GenericArrayList::itemSize() const noexcept
196 {
197 ✗ return gate_arraylist_itemsize(this->impl);
198 }
199 2071 size_t GenericArrayList::length() const noexcept
200 {
201 2071 return gate_arraylist_length(this->impl);
202 }
203 3 bool_t GenericArrayList::empty() const noexcept
204 {
205 3 return this->length() == 0;
206 }
207 1493 void* GenericArrayList::add(void const* ptrItem)
208 {
209 1493 return gate_arraylist_add(this->impl, ptrItem);
210 }
211 3 void* GenericArrayList::add(void const* ptrItem, size_t repeatCount)
212 {
213 3 return gate_arraylist_add_n(this->impl, ptrItem, repeatCount);
214 }
215 24 void* GenericArrayList::insertAt(size_t index, void const* ptrItem)
216 {
217 24 return gate_arraylist_insert(this->impl, index, ptrItem, 1);
218 }
219 1015 VoidResult GenericArrayList::removeAt(size_t index) noexcept
220 {
221 1015 result_t const res = gate_arraylist_remove(this->impl, index, 1);
222 1015 return makeResult(res);
223 }
224 1 void GenericArrayList::clear() noexcept
225 {
226 1 gate_arraylist_clear(this->impl);
227 1 }
228 1060 void* GenericArrayList::getItemPtr(size_t index) noexcept
229 {
230 1060 void* const ptr = gate_arraylist_get(this->impl, index);
231 1060 return ptr;
232 }
233 12 void const* GenericArrayList::getItemPtr(size_t index) const noexcept
234 {
235 12 void const* const ptr = gate_arraylist_get(this->impl, index);
236 12 return ptr;
237 }
238 4 bool_t GenericArrayList::contains(size_t index) const noexcept
239 {
240 4 return index < this->length();
241 }
242 3 GenericArrayList GenericArrayList::copy() const
243 {
244
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 gate_arraylist_t al_copy = gate_arraylist_copy(this->impl);
245
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 check_outofmem_nullptr(al_copy.ptr);
246 6 return GenericArrayList(al_copy);
247 }
248 141 GenericArray GenericArrayList::toArray() const
249 {
250 141 GenericArray ret;
251
1/2
✓ Branch 2 taken 141 times.
✗ Branch 3 not taken.
141 gate_array_t* ptr = gate_array_create(ret.c_impl(), this->impl);
252
1/2
✓ Branch 1 taken 141 times.
✗ Branch 2 not taken.
141 check_outofmem_nullptr(ptr);
253 141 return ret;
254 }
255
256 }
257